@@ -2044,6 +2044,7 @@ static void genCompositeDistributeParallelDoSimd(
2044
2044
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2045
2045
mlir::Location loc, const ConstructQueue &queue,
2046
2046
ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
2047
+ assert (std::distance (item, queue.end ()) == 4 && " Invalid leaf constructs" );
2047
2048
TODO (loc, " Composite DISTRIBUTE PARALLEL DO SIMD" );
2048
2049
}
2049
2050
@@ -2054,17 +2055,23 @@ static void genCompositeDistributeSimd(
2054
2055
ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
2055
2056
lower::StatementContext stmtCtx;
2056
2057
2058
+ assert (std::distance (item, queue.end ()) == 2 && " Invalid leaf constructs" );
2059
+ ConstructQueue::const_iterator distributeItem = item;
2060
+ ConstructQueue::const_iterator simdItem = std::next (distributeItem);
2061
+
2057
2062
// Clause processing.
2058
2063
mlir::omp::DistributeOperands distributeClauseOps;
2059
- genDistributeClauses (converter, semaCtx, stmtCtx, item ->clauses , loc ,
2060
- distributeClauseOps);
2064
+ genDistributeClauses (converter, semaCtx, stmtCtx, distributeItem ->clauses ,
2065
+ loc, distributeClauseOps);
2061
2066
2062
2067
mlir::omp::SimdOperands simdClauseOps;
2063
- genSimdClauses (converter, semaCtx, item ->clauses , loc, simdClauseOps);
2068
+ genSimdClauses (converter, semaCtx, simdItem ->clauses , loc, simdClauseOps);
2064
2069
2070
+ // Pass the innermost leaf construct's clauses because that's where COLLAPSE
2071
+ // is placed by construct decomposition.
2065
2072
mlir::omp::LoopNestOperands loopNestClauseOps;
2066
2073
llvm::SmallVector<const semantics::Symbol *> iv;
2067
- genLoopNestClauses (converter, semaCtx, eval, item ->clauses , loc,
2074
+ genLoopNestClauses (converter, semaCtx, eval, simdItem ->clauses , loc,
2068
2075
loopNestClauseOps, iv);
2069
2076
2070
2077
// Operation creation.
@@ -2086,7 +2093,7 @@ static void genCompositeDistributeSimd(
2086
2093
llvm::concat<mlir::BlockArgument>(distributeOp.getRegion ().getArguments (),
2087
2094
simdOp.getRegion ().getArguments ()));
2088
2095
2089
- genLoopNestOp (converter, symTable, semaCtx, eval, loc, queue, item ,
2096
+ genLoopNestOp (converter, symTable, semaCtx, eval, loc, queue, simdItem ,
2090
2097
loopNestClauseOps, iv, /* wrapperSyms=*/ {}, wrapperArgs,
2091
2098
llvm::omp::Directive::OMPD_distribute_simd, dsp);
2092
2099
}
@@ -2100,19 +2107,25 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
2100
2107
DataSharingProcessor &dsp) {
2101
2108
lower::StatementContext stmtCtx;
2102
2109
2110
+ assert (std::distance (item, queue.end ()) == 2 && " Invalid leaf constructs" );
2111
+ ConstructQueue::const_iterator doItem = item;
2112
+ ConstructQueue::const_iterator simdItem = std::next (doItem);
2113
+
2103
2114
// Clause processing.
2104
2115
mlir::omp::WsloopOperands wsloopClauseOps;
2105
2116
llvm::SmallVector<const semantics::Symbol *> wsloopReductionSyms;
2106
2117
llvm::SmallVector<mlir::Type> wsloopReductionTypes;
2107
- genWsloopClauses (converter, semaCtx, stmtCtx, item ->clauses , loc,
2118
+ genWsloopClauses (converter, semaCtx, stmtCtx, doItem ->clauses , loc,
2108
2119
wsloopClauseOps, wsloopReductionTypes, wsloopReductionSyms);
2109
2120
2110
2121
mlir::omp::SimdOperands simdClauseOps;
2111
- genSimdClauses (converter, semaCtx, item ->clauses , loc, simdClauseOps);
2122
+ genSimdClauses (converter, semaCtx, simdItem ->clauses , loc, simdClauseOps);
2112
2123
2124
+ // Pass the innermost leaf construct's clauses because that's where COLLAPSE
2125
+ // is placed by construct decomposition.
2113
2126
mlir::omp::LoopNestOperands loopNestClauseOps;
2114
2127
llvm::SmallVector<const semantics::Symbol *> iv;
2115
- genLoopNestClauses (converter, semaCtx, eval, item ->clauses , loc,
2128
+ genLoopNestClauses (converter, semaCtx, eval, simdItem ->clauses , loc,
2116
2129
loopNestClauseOps, iv);
2117
2130
2118
2131
// Operation creation.
@@ -2133,7 +2146,7 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
2133
2146
auto wrapperArgs = llvm::to_vector (llvm::concat<mlir::BlockArgument>(
2134
2147
wsloopOp.getRegion ().getArguments (), simdOp.getRegion ().getArguments ()));
2135
2148
2136
- genLoopNestOp (converter, symTable, semaCtx, eval, loc, queue, item ,
2149
+ genLoopNestOp (converter, symTable, semaCtx, eval, loc, queue, simdItem ,
2137
2150
loopNestClauseOps, iv, wsloopReductionSyms, wrapperArgs,
2138
2151
llvm::omp::Directive::OMPD_do_simd, dsp);
2139
2152
}
@@ -2143,13 +2156,44 @@ static void genCompositeTaskloopSimd(
2143
2156
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2144
2157
mlir::Location loc, const ConstructQueue &queue,
2145
2158
ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
2159
+ assert (std::distance (item, queue.end ()) == 2 && " Invalid leaf constructs" );
2146
2160
TODO (loc, " Composite TASKLOOP SIMD" );
2147
2161
}
2148
2162
2149
2163
// ===----------------------------------------------------------------------===//
2150
2164
// Dispatch
2151
2165
// ===----------------------------------------------------------------------===//
2152
2166
2167
+ static bool genOMPCompositeDispatch (
2168
+ lower::AbstractConverter &converter, lower::SymMap &symTable,
2169
+ semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2170
+ mlir::Location loc, const ConstructQueue &queue,
2171
+ ConstructQueue::const_iterator item, DataSharingProcessor &dsp) {
2172
+ using llvm::omp::Directive;
2173
+ using lower::omp::matchLeafSequence;
2174
+
2175
+ if (matchLeafSequence (item, queue, Directive::OMPD_distribute_parallel_do))
2176
+ genCompositeDistributeParallelDo (converter, symTable, semaCtx, eval, loc,
2177
+ queue, item, dsp);
2178
+ else if (matchLeafSequence (item, queue,
2179
+ Directive::OMPD_distribute_parallel_do_simd))
2180
+ genCompositeDistributeParallelDoSimd (converter, symTable, semaCtx, eval,
2181
+ loc, queue, item, dsp);
2182
+ else if (matchLeafSequence (item, queue, Directive::OMPD_distribute_simd))
2183
+ genCompositeDistributeSimd (converter, symTable, semaCtx, eval, loc, queue,
2184
+ item, dsp);
2185
+ else if (matchLeafSequence (item, queue, Directive::OMPD_do_simd))
2186
+ genCompositeDoSimd (converter, symTable, semaCtx, eval, loc, queue, item,
2187
+ dsp);
2188
+ else if (matchLeafSequence (item, queue, Directive::OMPD_taskloop_simd))
2189
+ genCompositeTaskloopSimd (converter, symTable, semaCtx, eval, loc, queue,
2190
+ item, dsp);
2191
+ else
2192
+ return false ;
2193
+
2194
+ return true ;
2195
+ }
2196
+
2153
2197
static void genOMPDispatch (lower::AbstractConverter &converter,
2154
2198
lower::SymMap &symTable,
2155
2199
semantics::SemanticsContext &semaCtx,
@@ -2163,10 +2207,18 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
2163
2207
llvm::omp::Association::Loop;
2164
2208
if (loopLeaf) {
2165
2209
symTable.pushScope ();
2210
+ // TODO: Use one DataSharingProcessor for each leaf of a composite
2211
+ // construct.
2166
2212
loopDsp.emplace (converter, semaCtx, item->clauses , eval,
2167
2213
/* shouldCollectPreDeterminedSymbols=*/ true ,
2168
2214
/* useDelayedPrivatization=*/ false , &symTable);
2169
2215
loopDsp->processStep1 ();
2216
+
2217
+ if (genOMPCompositeDispatch (converter, symTable, semaCtx, eval, loc, queue,
2218
+ item, *loopDsp)) {
2219
+ symTable.popScope ();
2220
+ return ;
2221
+ }
2170
2222
}
2171
2223
2172
2224
switch (llvm::omp::Directive dir = item->id ) {
@@ -2262,29 +2314,11 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
2262
2314
// that use this construct, add a single construct for now.
2263
2315
genSingleOp (converter, symTable, semaCtx, eval, loc, queue, item);
2264
2316
break ;
2265
-
2266
- // Composite constructs
2267
- case llvm::omp::Directive::OMPD_distribute_parallel_do:
2268
- genCompositeDistributeParallelDo (converter, symTable, semaCtx, eval, loc,
2269
- queue, item, *loopDsp);
2270
- break ;
2271
- case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
2272
- genCompositeDistributeParallelDoSimd (converter, symTable, semaCtx, eval,
2273
- loc, queue, item, *loopDsp);
2274
- break ;
2275
- case llvm::omp::Directive::OMPD_distribute_simd:
2276
- genCompositeDistributeSimd (converter, symTable, semaCtx, eval, loc, queue,
2277
- item, *loopDsp);
2278
- break ;
2279
- case llvm::omp::Directive::OMPD_do_simd:
2280
- genCompositeDoSimd (converter, symTable, semaCtx, eval, loc, queue, item,
2281
- *loopDsp);
2282
- break ;
2283
- case llvm::omp::Directive::OMPD_taskloop_simd:
2284
- genCompositeTaskloopSimd (converter, symTable, semaCtx, eval, loc, queue,
2285
- item, *loopDsp);
2286
- break ;
2287
2317
default :
2318
+ // Combined and composite constructs should have been split into a sequence
2319
+ // of leaf constructs when building the construct queue.
2320
+ assert (!llvm::omp::isLeafConstruct (dir) &&
2321
+ " Unexpected compound construct." );
2288
2322
break ;
2289
2323
}
2290
2324
0 commit comments