| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Emit OpenMP Stmt nodes as CIR code. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "CIRGenBuilder.h" |
| 14 | #include "CIRGenFunction.h" |
| 15 | #include "CIRGenOpenMPClause.h" |
| 16 | #include "CIRGenOpenMPConstructDecomposition.h" |
| 17 | #include "mlir/Dialect/OpenMP/OpenMPDialect.h" |
| 18 | #include "clang/AST/OpenMPClause.h" |
| 19 | #include "clang/AST/StmtOpenMP.h" |
| 20 | #include "llvm/ADT/STLFunctionalExtras.h" |
| 21 | #include "llvm/Frontend/OpenMP/OMP.h" |
| 22 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
| 23 | #include "llvm/Support/SaveAndRestore.h" |
| 24 | using namespace clang; |
| 25 | using namespace clang::CIRGen; |
| 26 | |
| 27 | mlir::LogicalResult |
| 28 | CIRGenFunction::emitOMPScopeDirective(const OMPScopeDirective &s) { |
| 29 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPScopeDirective" ); |
| 30 | return mlir::failure(); |
| 31 | } |
| 32 | mlir::LogicalResult |
| 33 | CIRGenFunction::emitOMPErrorDirective(const OMPErrorDirective &s) { |
| 34 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPErrorDirective" ); |
| 35 | return mlir::failure(); |
| 36 | } |
| 37 | |
| 38 | /// Report \p item's synthesized clauses as not-yet-implemented: having no AST |
| 39 | /// node, they cannot go through the clause emitters. |
| 40 | static mlir::LogicalResult |
| 41 | checkSynthesizedClauses(CIRGenFunction &cgf, const OMPExecutableDirective &s, |
| 42 | omp::ConstructQueue::const_iterator item) { |
| 43 | mlir::LogicalResult res = mlir::success(); |
| 44 | for (llvm::omp::Clause synth : item->synthesized) { |
| 45 | cgf.getCIRGenModule().errorNYI(s.getSourceRange(), |
| 46 | (llvm::Twine("OpenMP synthesized '" ) + |
| 47 | llvm::omp::getOpenMPClauseName(C: synth) + |
| 48 | "' clause from construct decomposition" ) |
| 49 | .str()); |
| 50 | res = mlir::failure(); |
| 51 | } |
| 52 | return res; |
| 53 | } |
| 54 | |
| 55 | static mlir::LogicalResult |
| 56 | emitParallelClauses(CIRGenFunction &cgf, CIRGenModule &cgm, |
| 57 | CIRGenBuilderTy &builder, mlir::Location loc, |
| 58 | llvm::ArrayRef<const OMPClause *> clauses, |
| 59 | mlir::omp::ParallelOperands &clauseOps) { |
| 60 | OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses); |
| 61 | ce.emitIf(result&: clauseOps, directiveName: llvm::omp::Directive::OMPD_parallel); |
| 62 | ce.emitNumThreads(result&: clauseOps); |
| 63 | ce.emitProcBind(result&: clauseOps); |
| 64 | return ce.emitNYI</*supported=*/OMPIfClause, OMPNumThreadsClause, |
| 65 | OMPProcBindClause>( |
| 66 | /*nyi=*/OpenMPNYIClauseList<OMPAllocateClause, OMPCopyinClause, |
| 67 | OMPDefaultClause, OMPFirstprivateClause, |
| 68 | OMPPrivateClause, OMPReductionClause, |
| 69 | OMPSharedClause>{}, |
| 70 | directive: llvm::omp::Directive::OMPD_parallel); |
| 71 | } |
| 72 | |
| 73 | /// Emits the contents of an OpenMP region op's \p block in a new lexical scope |
| 74 | /// and terminates the block with a \p TermOp. The scope's cleanups (e.g. |
| 75 | /// lifetime markers of locals declared in the region) are emitted before the |
| 76 | /// terminator; destroying the scope instead would make it terminate the block |
| 77 | /// with a cir.yield. |
| 78 | template <typename TermOp> |
| 79 | static mlir::LogicalResult |
| 80 | emitOMPRegionBody(CIRGenFunction &cgf, mlir::Block &block, mlir::Location begin, |
| 81 | mlir::Location end, |
| 82 | llvm::function_ref<mlir::LogicalResult()> emitBody) { |
| 83 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 84 | mlir::OpBuilder::InsertionGuard guard(builder); |
| 85 | builder.setInsertionPointToEnd(&block); |
| 86 | |
| 87 | CIRGenFunction::LexicalScope ls{cgf, begin, &block}; |
| 88 | mlir::LogicalResult res = emitBody(); |
| 89 | ls.forceCleanup(); |
| 90 | TermOp::create(builder, end); |
| 91 | return res; |
| 92 | } |
| 93 | |
| 94 | template <typename DirectiveTy> |
| 95 | static mlir::LogicalResult |
| 96 | emitParallelOp(CIRGenFunction &cgf, const DirectiveTy &s, |
| 97 | const omp::ConstructQueue &queue, |
| 98 | omp::ConstructQueue::const_iterator item, mlir::Location begin, |
| 99 | mlir::Location end, const mlir::omp::ParallelOperands &clauseOps, |
| 100 | llvm::function_ref<mlir::LogicalResult()> emitBody) { |
| 101 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 102 | CIRGenModule &cgm = cgf.getCIRGenModule(); |
| 103 | |
| 104 | // hasCancel() reports a nested cancel/cancellation point directive in the |
| 105 | // body, not a clause on `parallel`, so it can't be an emitParallelClauses() |
| 106 | // NYI check. |
| 107 | if (s.hasCancel()) { |
| 108 | cgm.errorNYI(s.getBeginLoc(), "OpenMP Parallel with Cancel" ); |
| 109 | return mlir::failure(); |
| 110 | } |
| 111 | // Only set for reduction(task: ...), already rejected as NYI above. |
| 112 | assert(!s.getTaskReductionRefExpr() && |
| 113 | "reduction(task: ...) should already be rejected as NYI" ); |
| 114 | |
| 115 | auto parallelOp = mlir::omp::ParallelOp::create(builder, location: begin, clauses: clauseOps); |
| 116 | if (!omp::isLastItemInQueue(item, queue)) |
| 117 | parallelOp.setCombined(true); |
| 118 | |
| 119 | mlir::Block &block = parallelOp.getRegion().emplaceBlock(); |
| 120 | return emitOMPRegionBody<mlir::omp::TerminatorOp>(cgf, block, begin, end, |
| 121 | emitBody); |
| 122 | } |
| 123 | |
| 124 | /// Checks, emits clauses for, and emits an omp.parallel for the `parallel` |
| 125 | /// directive at \p parallelItem, deferring to \p emitBody for the region's |
| 126 | /// contents. |
| 127 | template <typename DirectiveTy> |
| 128 | static mlir::LogicalResult emitParallel( |
| 129 | CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, |
| 130 | omp::ConstructQueue::const_iterator parallelItem, mlir::Location begin, |
| 131 | mlir::Location end, llvm::function_ref<mlir::LogicalResult()> emitBody) { |
| 132 | if (mlir::failed(Result: checkSynthesizedClauses(cgf, s, parallelItem))) |
| 133 | return mlir::failure(); |
| 134 | |
| 135 | mlir::omp::ParallelOperands parallelOps; |
| 136 | if (mlir::failed(Result: emitParallelClauses(cgf, cgm&: cgf.getCIRGenModule(), |
| 137 | builder&: cgf.getBuilder(), loc: begin, |
| 138 | clauses: parallelItem->clauses, clauseOps&: parallelOps))) |
| 139 | return mlir::failure(); |
| 140 | |
| 141 | return emitParallelOp(cgf, s, queue, parallelItem, begin, end, parallelOps, |
| 142 | emitBody); |
| 143 | } |
| 144 | |
| 145 | mlir::LogicalResult |
| 146 | CIRGenFunction::emitOMPParallelDirective(const OMPParallelDirective &s) { |
| 147 | mlir::Location begin = getLoc(srcLoc: s.getBeginLoc()); |
| 148 | mlir::Location end = getLoc(srcLoc: s.getEndLoc()); |
| 149 | |
| 150 | omp::ConstructQueue queue = |
| 151 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 152 | omp::ConstructQueue::const_iterator item = queue.begin(); |
| 153 | |
| 154 | return emitParallel( |
| 155 | cgf&: *this, s, queue, parallelItem: item, begin, end, emitBody: [&]() -> mlir::LogicalResult { |
| 156 | // emitStmt() rejects CapturedStmt directly; the |
| 157 | // parent construct must unwrap it, so emit the |
| 158 | // inner statement instead. |
| 159 | const CapturedStmt *cs = s.getCapturedStmt(RegionKind: llvm::omp::OMPD_parallel); |
| 160 | return emitStmt(s: cs->getCapturedStmt(), |
| 161 | /*useCurrentScope=*/true); |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | void CIRGenFunction::emitOMPNoLifetimeVarDecl(const VarDecl &d) { |
| 166 | llvm::SaveAndRestore<bool> noLifetimeMarkers(shouldEmitLifetimeMarkers, |
| 167 | false); |
| 168 | emitVarDecl(d); |
| 169 | } |
| 170 | |
| 171 | /// Emits a single Sema-generated pre-init statement for an OpenMP loop |
| 172 | /// directive: a VarDecl's DeclStmt is lowered directly (it has no |
| 173 | /// initializer CIRGenFunction::emitStmt can handle on its own), everything |
| 174 | /// else goes through the general statement emitter. |
| 175 | static mlir::LogicalResult emitLoopPreInit(CIRGenFunction &cgf, |
| 176 | const Stmt *preInit) { |
| 177 | if (const auto *declStmt = dyn_cast<DeclStmt>(Val: preInit)) { |
| 178 | for (const Decl *d : declStmt->decls()) |
| 179 | cgf.emitOMPNoLifetimeVarDecl(d: cast<VarDecl>(Val: *d)); |
| 180 | return mlir::success(); |
| 181 | } |
| 182 | return cgf.emitStmt(s: preInit, /*useCurrentScope=*/true); |
| 183 | } |
| 184 | |
| 185 | /// Emits the Sema-generated pre-init statements for an OpenMP loop directive. |
| 186 | static mlir::LogicalResult emitLoopPreInits(CIRGenFunction &cgf, |
| 187 | const Stmt *preInits) { |
| 188 | if (!preInits) |
| 189 | return mlir::success(); |
| 190 | |
| 191 | if (const auto *compound = dyn_cast<CompoundStmt>(Val: preInits)) { |
| 192 | for (const Stmt *stmt : compound->body()) |
| 193 | if (emitLoopPreInit(cgf, preInit: stmt).failed()) |
| 194 | return mlir::failure(); |
| 195 | return mlir::success(); |
| 196 | } |
| 197 | |
| 198 | return emitLoopPreInit(cgf, preInit: preInits); |
| 199 | } |
| 200 | |
| 201 | /// Returns the first `continue` in \p s that is not nested in an inner loop, |
| 202 | /// i.e. one that targets the loop whose body is \p s. |
| 203 | static const ContinueStmt *findLoopBodyContinue(const Stmt *s) { |
| 204 | if (!s || isa<ForStmt, WhileStmt, DoStmt, CXXForRangeStmt>(Val: s)) |
| 205 | return nullptr; |
| 206 | if (const auto *continueStmt = dyn_cast<ContinueStmt>(Val: s)) |
| 207 | return continueStmt; |
| 208 | for (const Stmt *child : s->children()) |
| 209 | if (const ContinueStmt *continueStmt = findLoopBodyContinue(s: child)) |
| 210 | return continueStmt; |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | /// Emits an omp.loop_nest that iterates a normalized `[0, tripCount)` range |
| 215 | /// and recomputes the real induction variable each iteration using the given |
| 216 | /// update expression. |
| 217 | static mlir::LogicalResult |
| 218 | emitOMPLoopNest(CIRGenFunction &cgf, const ForStmt &forStmt, mlir::Value lb, |
| 219 | mlir::Value ub, mlir::Value step, const VarDecl *ivDecl, |
| 220 | const Expr *update) { |
| 221 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 222 | mlir::Location loc = cgf.getLoc(srcLoc: forStmt.getSourceRange()); |
| 223 | |
| 224 | auto loopNestOp = mlir::omp::LoopNestOp::create( |
| 225 | builder, location: loc, /*collapse_num_loops=*/1, loop_lower_bounds: lb, loop_upper_bounds: ub, loop_steps: step, |
| 226 | /*loop_inclusive=*/false, /*tile_sizes=*/nullptr); |
| 227 | mlir::Block &block = loopNestOp.getRegion().emplaceBlock(); |
| 228 | block.addArgument(type: lb.getType(), loc); |
| 229 | |
| 230 | return emitOMPRegionBody<mlir::omp::YieldOp>( |
| 231 | cgf, block, begin: loc, end: cgf.getLoc(srcLoc: forStmt.getEndLoc()), |
| 232 | emitBody: [&]() -> mlir::LogicalResult { |
| 233 | // Store the normalized counter block argument into the normalized |
| 234 | // loop variable's storage location, then let Sema's update expression |
| 235 | // recompute the real induction variable from it. |
| 236 | mlir::Value iv = block.getArgument(i: 0); |
| 237 | Address ivAddr = cgf.getAddrOfLocalVar(vd: ivDecl); |
| 238 | mlir::Value civVal = |
| 239 | builder.createBuiltinIntCast(loc, src: iv, newTy: ivAddr.getElementType()); |
| 240 | builder.createStore(loc, val: civVal, dst: ivAddr); |
| 241 | cgf.emitIgnoredExpr(e: update); |
| 242 | |
| 243 | if (!forStmt.getBody()) |
| 244 | return mlir::success(); |
| 245 | return cgf.emitStmt(s: forStmt.getBody(), /*useCurrentScope=*/true); |
| 246 | }); |
| 247 | } |
| 248 | |
| 249 | /// Evaluates the clauses allowed on the `for` directive; none are supported |
| 250 | /// yet, so every eligible clause is reported as NYI. |
| 251 | static mlir::LogicalResult |
| 252 | emitWsloopClauses(CIRGenFunction &cgf, CIRGenModule &cgm, |
| 253 | CIRGenBuilderTy &builder, mlir::Location loc, |
| 254 | llvm::ArrayRef<const OMPClause *> clauses, |
| 255 | mlir::omp::WsloopOperands &clauseOps) { |
| 256 | OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses); |
| 257 | return ce.emitNYI</*supported=*/>( |
| 258 | /*nyi=*/OpenMPNYIClauseList< |
| 259 | OMPAllocateClause, OMPCollapseClause, OMPFirstprivateClause, |
| 260 | OMPLastprivateClause, OMPLinearClause, OMPNowaitClause, |
| 261 | OMPOrderClause, OMPOrderedClause, OMPPrivateClause, |
| 262 | OMPReductionClause, OMPScheduleClause>{}, |
| 263 | directive: llvm::omp::Directive::OMPD_for); |
| 264 | } |
| 265 | |
| 266 | /// Creates a module-level `omp.private` op (a "privatizer") for a scalar |
| 267 | /// of CIR type elemTy. |
| 268 | static mlir::omp::PrivateClauseOp emitScalarPrivatizer(CIRGenModule &cgm, |
| 269 | mlir::Location loc, |
| 270 | llvm::StringRef baseName, |
| 271 | mlir::Type elemTy) { |
| 272 | // getGlobalValue() is an O(1) cache lookup, unlike |
| 273 | // mlir::SymbolTable::lookupSymbolIn()'s O(n) module scan. |
| 274 | unsigned uniquingCounter = 0; |
| 275 | llvm::SmallString<64> name = mlir::SymbolTable::generateSymbolName<64>( |
| 276 | name: (baseName + ".privatizer" ).str(), |
| 277 | uniqueChecker: [&](llvm::StringRef candidate) { |
| 278 | return cgm.getGlobalValue(ref: candidate) != nullptr; |
| 279 | }, |
| 280 | uniquingCounter); |
| 281 | |
| 282 | mlir::ModuleOp mod = cgm.getModule(); |
| 283 | mlir::OpBuilder b(mod.getContext()); |
| 284 | b.setInsertionPointToEnd(mod.getBody()); |
| 285 | auto privatizer = mlir::omp::PrivateClauseOp::create( |
| 286 | builder&: b, location: loc, result: mlir::TypeRange{}, sym_name: b.getStringAttr(bytes: name), |
| 287 | type: mlir::TypeAttr::get(type: elemTy)); |
| 288 | cgm.insertGlobalSymbol(op: privatizer); |
| 289 | return privatizer; |
| 290 | } |
| 291 | |
| 292 | /// Registers a loop counter as predetermined-private on the associated loop |
| 293 | /// wrapper op. |
| 294 | static Address emitLoopPrivateCounter(CIRGenFunction &cgf, CIRGenModule &cgm, |
| 295 | mlir::Location loc, |
| 296 | const VarDecl *privateVd, |
| 297 | mlir::omp::PrivateClauseOps &clauseOps) { |
| 298 | cgf.emitOMPNoLifetimeVarDecl(d: *privateVd); |
| 299 | Address moldAddr = cgf.getAddrOfLocalVar(vd: privateVd); |
| 300 | |
| 301 | mlir::omp::PrivateClauseOp privatizer = emitScalarPrivatizer( |
| 302 | cgm, loc, baseName: privateVd->getName(), elemTy: moldAddr.getElementType()); |
| 303 | |
| 304 | clauseOps.privateVars.push_back(Elt: moldAddr.getPointer()); |
| 305 | clauseOps.privateSyms.push_back( |
| 306 | Elt: mlir::FlatSymbolRefAttr::get(value: privatizer.getSymNameAttr())); |
| 307 | return moldAddr; |
| 308 | } |
| 309 | |
| 310 | /// Emits the trip count of the loop associated with \p s: Sema's iteration |
| 311 | /// count if the loop's precondition holds, and zero otherwise. The iteration |
| 312 | /// count is only meaningful when the loop runs at least once; e.g. for |
| 313 | /// `for (unsigned i = 10; i < 0; i += 2)` its arithmetic wraps to a positive |
| 314 | /// value. |
| 315 | static mlir::Value emitLoopTripCount(CIRGenFunction &cgf, |
| 316 | const OMPLoopDirective &s) { |
| 317 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 318 | mlir::Location loc = cgf.getLoc(srcLoc: s.getBeginLoc()); |
| 319 | mlir::Value preCond = cgf.evaluateExprAsBool(e: s.getPreCond()); |
| 320 | mlir::Value numIterations = cgf.emitScalarExpr(e: s.getNumIterations()); |
| 321 | mlir::Value zero = builder.getConstInt( |
| 322 | loc, t: mlir::cast<cir::IntType>(Val: numIterations.getType()), c: 0); |
| 323 | return builder.createSelect(loc, condition: preCond, trueValue: numIterations, falseValue: zero); |
| 324 | } |
| 325 | |
| 326 | /// Lowers an OMPLoopDirective's `for` directive to an omp.wsloop + |
| 327 | /// omp.loop_nest. |
| 328 | static mlir::LogicalResult |
| 329 | emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s, |
| 330 | omp::ConstructQueue::const_iterator item) { |
| 331 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 332 | CIRGenModule &cgm = cgf.getCIRGenModule(); |
| 333 | mlir::Location loc = cgf.getLoc(srcLoc: s.getBeginLoc()); |
| 334 | |
| 335 | if (mlir::failed(Result: checkSynthesizedClauses(cgf, s, item))) |
| 336 | return mlir::failure(); |
| 337 | |
| 338 | mlir::omp::WsloopOperands clauseOps; |
| 339 | if (emitWsloopClauses(cgf, cgm, builder, loc, clauses: item->clauses, clauseOps) |
| 340 | .failed()) |
| 341 | return mlir::failure(); |
| 342 | |
| 343 | const CapturedStmt *capturedStmt = s.getInnermostCapturedStmt(); |
| 344 | const auto *forStmt = dyn_cast<ForStmt>(Val: capturedStmt->getCapturedStmt()); |
| 345 | if (!forStmt) { |
| 346 | assert(isa<CXXForRangeStmt>(capturedStmt->getCapturedStmt()) && |
| 347 | "expected a for or range-based for loop" ); |
| 348 | cgm.errorNYI(capturedStmt->getCapturedStmt()->getSourceRange(), |
| 349 | "range-based for loop in an OpenMP loop directive" ); |
| 350 | return mlir::failure(); |
| 351 | } |
| 352 | |
| 353 | // A `continue` lowers to cir.continue, which must be nested in a CIR loop, |
| 354 | // and omp.loop_nest is not one. |
| 355 | if (const ContinueStmt *continueStmt = |
| 356 | findLoopBodyContinue(s: forStmt->getBody())) { |
| 357 | cgm.errorNYI(continueStmt->getSourceRange(), |
| 358 | "continue in an OpenMP loop body" ); |
| 359 | return mlir::failure(); |
| 360 | } |
| 361 | |
| 362 | if (emitLoopPreInits(cgf, preInits: s.getPreInits()).failed()) |
| 363 | return mlir::failure(); |
| 364 | |
| 365 | // Allocate storage for Sema's normalized 0-based loop counter. |
| 366 | const auto *ivDecl = |
| 367 | cast<VarDecl>(Val: cast<DeclRefExpr>(Val: s.getIterationVariable())->getDecl()); |
| 368 | cgf.emitOMPNoLifetimeVarDecl(d: *ivDecl); |
| 369 | // Each counter is rebound below to the loop wrapper's private block |
| 370 | // argument; these restore the counters' original addresses when this |
| 371 | // function returns, so code after the loop doesn't refer to the region. |
| 372 | llvm::SmallVector<CIRGenFunction::DeclMapRevertingRAII, 4> counterShadows; |
| 373 | llvm::SmallVector<std::pair<const VarDecl *, Address>, 4> counterMolds; |
| 374 | counterShadows.reserve(N: s.counters().size()); |
| 375 | counterMolds.reserve(N: s.counters().size()); |
| 376 | for (auto [counter, privateCounter] : |
| 377 | llvm::zip_equal(t: s.counters(), u: s.private_counters())) { |
| 378 | const auto *vd = cast<VarDecl>(Val: cast<DeclRefExpr>(Val: counter)->getDecl()); |
| 379 | const auto *privateVd = |
| 380 | cast<VarDecl>(Val: cast<DeclRefExpr>(Val: privateCounter)->getDecl()); |
| 381 | counterShadows.emplace_back(Args&: cgf, Args&: vd); |
| 382 | counterMolds.emplace_back( |
| 383 | Args&: vd, Args: emitLoopPrivateCounter(cgf, cgm, loc, privateVd, clauseOps)); |
| 384 | } |
| 385 | |
| 386 | mlir::Value tripCountCir = emitLoopTripCount(cgf, s); |
| 387 | auto cirIntType = mlir::cast<cir::IntType>(Val: tripCountCir.getType()); |
| 388 | mlir::Value zero = builder.createBuiltinIntCast( |
| 389 | loc, src: builder.getConstInt(loc, t: cirIntType, c: 0)); |
| 390 | mlir::Value one = builder.createBuiltinIntCast( |
| 391 | loc, src: builder.getConstInt(loc, t: cirIntType, c: 1)); |
| 392 | mlir::Value tripCount = builder.createBuiltinIntCast(loc, src: tripCountCir); |
| 393 | |
| 394 | auto wsloopOp = mlir::omp::WsloopOp::create(builder, location: loc, clauses: clauseOps); |
| 395 | mlir::Block *innerBlock = new mlir::Block(); |
| 396 | // Ensures the block arguments match BlockArgOpenMPOpInterface's expected |
| 397 | // order. |
| 398 | for (auto &counterMold : counterMolds) |
| 399 | innerBlock->addArgument(type: counterMold.second.getPointer().getType(), loc); |
| 400 | wsloopOp.getRegion().push_back(block: innerBlock); |
| 401 | |
| 402 | mlir::OpBuilder::InsertionGuard guard(builder); |
| 403 | builder.setInsertionPointToStart(innerBlock); |
| 404 | |
| 405 | // Bind each counter to its private block argument. |
| 406 | for (unsigned idx = 0; idx < counterMolds.size(); ++idx) { |
| 407 | const VarDecl *vd = counterMolds[idx].first; |
| 408 | Address moldAddr = counterMolds[idx].second; |
| 409 | Address privAddr(innerBlock->getArgument(i: idx), moldAddr.getElementType(), |
| 410 | moldAddr.getAlignment()); |
| 411 | cgf.replaceAddrOfLocalVar(vd, addr: privAddr); |
| 412 | cgf.symbolTable.insert(Key: vd, Val: privAddr.getPointer()); |
| 413 | } |
| 414 | |
| 415 | return emitOMPLoopNest(cgf, forStmt: *forStmt, lb: zero, ub: tripCount, step: one, ivDecl, |
| 416 | update: s.updates()[0]); |
| 417 | } |
| 418 | |
| 419 | mlir::LogicalResult |
| 420 | CIRGenFunction::emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s) { |
| 421 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskwaitDirective" ); |
| 422 | return mlir::failure(); |
| 423 | } |
| 424 | mlir::LogicalResult |
| 425 | CIRGenFunction::emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s) { |
| 426 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 427 | "OpenMP OMPTaskyieldDirective" ); |
| 428 | return mlir::failure(); |
| 429 | } |
| 430 | mlir::LogicalResult |
| 431 | CIRGenFunction::emitOMPBarrierDirective(const OMPBarrierDirective &s) { |
| 432 | mlir::omp::BarrierOp::create(builder, location: getLoc(srcLoc: s.getBeginLoc())); |
| 433 | assert(s.clauses().empty() && "omp barrier doesn't support clauses" ); |
| 434 | return mlir::success(); |
| 435 | } |
| 436 | mlir::LogicalResult |
| 437 | CIRGenFunction::emitOMPMetaDirective(const OMPMetaDirective &s) { |
| 438 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMetaDirective" ); |
| 439 | return mlir::failure(); |
| 440 | } |
| 441 | mlir::LogicalResult |
| 442 | CIRGenFunction::emitOMPCanonicalLoop(const OMPCanonicalLoop &s) { |
| 443 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCanonicalLoop" ); |
| 444 | return mlir::failure(); |
| 445 | } |
| 446 | mlir::LogicalResult |
| 447 | CIRGenFunction::emitOMPSimdDirective(const OMPSimdDirective &s) { |
| 448 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSimdDirective" ); |
| 449 | return mlir::failure(); |
| 450 | } |
| 451 | mlir::LogicalResult |
| 452 | CIRGenFunction::emitOMPTileDirective(const OMPTileDirective &s) { |
| 453 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTileDirective" ); |
| 454 | return mlir::failure(); |
| 455 | } |
| 456 | mlir::LogicalResult |
| 457 | CIRGenFunction::emitOMPUnrollDirective(const OMPUnrollDirective &s) { |
| 458 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPUnrollDirective" ); |
| 459 | return mlir::failure(); |
| 460 | } |
| 461 | mlir::LogicalResult |
| 462 | CIRGenFunction::emitOMPFuseDirective(const OMPFuseDirective &s) { |
| 463 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFuseDirective" ); |
| 464 | return mlir::failure(); |
| 465 | } |
| 466 | mlir::LogicalResult |
| 467 | CIRGenFunction::emitOMPForDirective(const OMPForDirective &s) { |
| 468 | omp::ConstructQueue queue = |
| 469 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 470 | return emitOMPWorksharingLoop(cgf&: *this, s, item: queue.begin()); |
| 471 | } |
| 472 | mlir::LogicalResult |
| 473 | CIRGenFunction::emitOMPForSimdDirective(const OMPForSimdDirective &s) { |
| 474 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPForSimdDirective" ); |
| 475 | return mlir::failure(); |
| 476 | } |
| 477 | mlir::LogicalResult |
| 478 | CIRGenFunction::emitOMPSectionsDirective(const OMPSectionsDirective &s) { |
| 479 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSectionsDirective" ); |
| 480 | return mlir::failure(); |
| 481 | } |
| 482 | mlir::LogicalResult |
| 483 | CIRGenFunction::emitOMPSectionDirective(const OMPSectionDirective &s) { |
| 484 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSectionDirective" ); |
| 485 | return mlir::failure(); |
| 486 | } |
| 487 | mlir::LogicalResult |
| 488 | CIRGenFunction::emitOMPSingleDirective(const OMPSingleDirective &s) { |
| 489 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSingleDirective" ); |
| 490 | return mlir::failure(); |
| 491 | } |
| 492 | mlir::LogicalResult |
| 493 | CIRGenFunction::emitOMPMasterDirective(const OMPMasterDirective &s) { |
| 494 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMasterDirective" ); |
| 495 | return mlir::failure(); |
| 496 | } |
| 497 | mlir::LogicalResult |
| 498 | CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) { |
| 499 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCriticalDirective" ); |
| 500 | return mlir::failure(); |
| 501 | } |
| 502 | mlir::LogicalResult |
| 503 | CIRGenFunction::emitOMPParallelForDirective(const OMPParallelForDirective &s) { |
| 504 | mlir::Location begin = getLoc(srcLoc: s.getBeginLoc()); |
| 505 | mlir::Location end = getLoc(srcLoc: s.getEndLoc()); |
| 506 | |
| 507 | omp::ConstructQueue queue = |
| 508 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 509 | omp::ConstructQueue::const_iterator parallelItem = queue.begin(); |
| 510 | assert(parallelItem->id == llvm::omp::OMPD_parallel && |
| 511 | "expected 'parallel' to be the outermost directive" ); |
| 512 | |
| 513 | return emitParallel( |
| 514 | cgf&: *this, s, queue, parallelItem, begin, end, emitBody: [&]() -> mlir::LogicalResult { |
| 515 | omp::ConstructQueue::const_iterator forItem = std::next(x: parallelItem); |
| 516 | assert(forItem != queue.end() && forItem->id == llvm::omp::OMPD_for && |
| 517 | "expected a 'for' directive nested in 'parallel'" ); |
| 518 | return emitOMPWorksharingLoop(cgf&: *this, s, item: forItem); |
| 519 | }); |
| 520 | } |
| 521 | mlir::LogicalResult CIRGenFunction::emitOMPParallelForSimdDirective( |
| 522 | const OMPParallelForSimdDirective &s) { |
| 523 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 524 | "OpenMP OMPParallelForSimdDirective" ); |
| 525 | return mlir::failure(); |
| 526 | } |
| 527 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMasterDirective( |
| 528 | const OMPParallelMasterDirective &s) { |
| 529 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 530 | "OpenMP OMPParallelMasterDirective" ); |
| 531 | return mlir::failure(); |
| 532 | } |
| 533 | mlir::LogicalResult CIRGenFunction::emitOMPParallelSectionsDirective( |
| 534 | const OMPParallelSectionsDirective &s) { |
| 535 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 536 | "OpenMP OMPParallelSectionsDirective" ); |
| 537 | return mlir::failure(); |
| 538 | } |
| 539 | mlir::LogicalResult |
| 540 | CIRGenFunction::emitOMPTaskDirective(const OMPTaskDirective &s) { |
| 541 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskDirective" ); |
| 542 | return mlir::failure(); |
| 543 | } |
| 544 | mlir::LogicalResult |
| 545 | CIRGenFunction::emitOMPTaskgroupDirective(const OMPTaskgroupDirective &s) { |
| 546 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 547 | "OpenMP OMPTaskgroupDirective" ); |
| 548 | return mlir::failure(); |
| 549 | } |
| 550 | mlir::LogicalResult |
| 551 | CIRGenFunction::emitOMPFlushDirective(const OMPFlushDirective &s) { |
| 552 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFlushDirective" ); |
| 553 | return mlir::failure(); |
| 554 | } |
| 555 | mlir::LogicalResult |
| 556 | CIRGenFunction::emitOMPDepobjDirective(const OMPDepobjDirective &s) { |
| 557 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPDepobjDirective" ); |
| 558 | return mlir::failure(); |
| 559 | } |
| 560 | mlir::LogicalResult |
| 561 | CIRGenFunction::emitOMPScanDirective(const OMPScanDirective &s) { |
| 562 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPScanDirective" ); |
| 563 | return mlir::failure(); |
| 564 | } |
| 565 | mlir::LogicalResult CIRGenFunction::emitOMPOrderedStandaloneDirective( |
| 566 | const OMPOrderedStandaloneDirective &s) { |
| 567 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 568 | "OpenMP OMPOrderedStandaloneDirective" ); |
| 569 | return mlir::failure(); |
| 570 | } |
| 571 | mlir::LogicalResult CIRGenFunction::emitOMPOrderedBlockAssocDirective( |
| 572 | const OMPOrderedBlockAssocDirective &s) { |
| 573 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 574 | "OpenMP OMPOrderedBlockAssocDirective" ); |
| 575 | return mlir::failure(); |
| 576 | } |
| 577 | mlir::LogicalResult |
| 578 | CIRGenFunction::emitOMPAtomicDirective(const OMPAtomicDirective &s) { |
| 579 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPAtomicDirective" ); |
| 580 | return mlir::failure(); |
| 581 | } |
| 582 | |
| 583 | /// Check for unsupported implicit captures in a target region. |
| 584 | static mlir::LogicalResult |
| 585 | emitOMPTargetImplicitCaptures(CIRGenFunction &cgf, |
| 586 | const OMPExecutableDirective &s, |
| 587 | llvm::ArrayRef<const VarDecl *> mapSyms) { |
| 588 | const CapturedStmt *cs = s.getCapturedStmt(RegionKind: llvm::omp::OMPD_target); |
| 589 | mlir::LogicalResult res = mlir::success(); |
| 590 | for (const auto &capture : cs->captures()) { |
| 591 | if (capture.capturesThis()) { |
| 592 | cgf.getCIRGenModule().errorNYI(s.getBeginLoc(), |
| 593 | "OpenMP target capture of 'this' pointer" ); |
| 594 | res = mlir::failure(); |
| 595 | continue; |
| 596 | } |
| 597 | if (capture.capturesVariableByCopy()) { |
| 598 | cgf.getCIRGenModule().errorNYI(s.getBeginLoc(), |
| 599 | "OpenMP target capture by copy" ); |
| 600 | res = mlir::failure(); |
| 601 | continue; |
| 602 | } |
| 603 | if (capture.capturesVariableArrayType()) { |
| 604 | cgf.getCIRGenModule().errorNYI( |
| 605 | s.getBeginLoc(), |
| 606 | "OpenMP target capture of variable-length array type" ); |
| 607 | res = mlir::failure(); |
| 608 | continue; |
| 609 | } |
| 610 | if (capture.capturesVariable()) { |
| 611 | const VarDecl *vd = capture.getCapturedVar(); |
| 612 | if (llvm::is_contained(Range&: mapSyms, Element: vd)) |
| 613 | continue; |
| 614 | |
| 615 | cgf.getCIRGenModule().errorNYI(s.getBeginLoc(), |
| 616 | "OpenMP target implicit by-ref capture" ); |
| 617 | res = mlir::failure(); |
| 618 | } |
| 619 | } |
| 620 | return res; |
| 621 | } |
| 622 | |
| 623 | static mlir::LogicalResult |
| 624 | emitTargetClauses(CIRGenFunction &cgf, CIRGenModule &cgm, |
| 625 | CIRGenBuilderTy &builder, mlir::Location loc, |
| 626 | llvm::ArrayRef<const OMPClause *> clauses, |
| 627 | mlir::omp::TargetExtOperands &clauseOps, |
| 628 | llvm::SmallVectorImpl<const VarDecl *> &mapSyms) { |
| 629 | OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses); |
| 630 | ce.emitMap(result&: clauseOps, mapSyms: &mapSyms); |
| 631 | return ce.emitNYI</*supported=*/OMPMapClause>( |
| 632 | /*nyi=*/OpenMPNYIClauseList< |
| 633 | OMPAllocateClause, OMPDefaultClause, OMPDefaultmapClause, |
| 634 | OMPDependClause, OMPDeviceClause, OMPFirstprivateClause, |
| 635 | OMPHasDeviceAddrClause, OMPIfClause, OMPInReductionClause, |
| 636 | OMPIsDevicePtrClause, OMPNowaitClause, OMPPrivateClause, |
| 637 | OMPThreadLimitClause, OMPUsesAllocatorsClause, OMPXBareClause>{}, |
| 638 | directive: llvm::omp::Directive::OMPD_target); |
| 639 | } |
| 640 | |
| 641 | template <typename DirectiveTy> |
| 642 | static mlir::LogicalResult |
| 643 | emitTargetOp(CIRGenFunction &cgf, const DirectiveTy &s, |
| 644 | const omp::ConstructQueue &queue, |
| 645 | omp::ConstructQueue::const_iterator item, mlir::Location begin, |
| 646 | mlir::Location end, mlir::omp::TargetExtOperands &clauseOps, |
| 647 | llvm::ArrayRef<const VarDecl *> mapSyms, |
| 648 | llvm::function_ref<mlir::LogicalResult()> emitBody) { |
| 649 | CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 650 | |
| 651 | if (mlir::failed(Result: emitOMPTargetImplicitCaptures(cgf, s, mapSyms))) |
| 652 | return mlir::failure(); |
| 653 | |
| 654 | // Use generic for now. |
| 655 | clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get( |
| 656 | context: &cgf.getMLIRContext(), value: mlir::omp::TargetExecMode::generic); |
| 657 | |
| 658 | auto targetOp = mlir::omp::TargetOp::create(builder, location: begin, clauses: clauseOps); |
| 659 | if (!omp::isLastItemInQueue(item, queue)) |
| 660 | targetOp.setCombined(true); |
| 661 | |
| 662 | mlir::Block &block = targetOp.getRegion().emplaceBlock(); |
| 663 | for (mlir::Value mapVar : clauseOps.mapVars) |
| 664 | block.addArgument(type: mapVar.getType(), loc: begin); |
| 665 | |
| 666 | llvm::SmallVector<std::pair<const VarDecl *, Address>> savedAddrs; |
| 667 | for (auto [idx, vd] : llvm::enumerate(First&: mapSyms)) { |
| 668 | Address origAddr = cgf.getAddrOfLocalVar(vd); |
| 669 | savedAddrs.push_back(Elt: {vd, origAddr}); |
| 670 | mlir::Value blockArg = block.getArgument(i: idx); |
| 671 | cgf.replaceAddrOfLocalVar(vd, addr: Address(blockArg, origAddr.getAlignment())); |
| 672 | } |
| 673 | |
| 674 | mlir::LogicalResult res = emitOMPRegionBody<mlir::omp::TerminatorOp>( |
| 675 | cgf, block, begin, end, emitBody); |
| 676 | |
| 677 | for (auto &[vd, addr] : savedAddrs) |
| 678 | cgf.replaceAddrOfLocalVar(vd, addr); |
| 679 | |
| 680 | return res; |
| 681 | } |
| 682 | |
| 683 | /// Checks, emits clauses for, and emits an omp.target for the `target` |
| 684 | /// directive at \p targetItem, deferring to \p emitBody for the region's |
| 685 | /// contents. |
| 686 | template <typename DirectiveTy> |
| 687 | static mlir::LogicalResult emitTarget( |
| 688 | CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, |
| 689 | omp::ConstructQueue::const_iterator targetItem, mlir::Location begin, |
| 690 | mlir::Location end, llvm::function_ref<mlir::LogicalResult()> emitBody) { |
| 691 | if (mlir::failed(Result: checkSynthesizedClauses(cgf, s, targetItem))) |
| 692 | return mlir::failure(); |
| 693 | |
| 694 | mlir::omp::TargetExtOperands targetOps; |
| 695 | llvm::SmallVector<const VarDecl *> mapSyms; |
| 696 | if (mlir::failed(Result: emitTargetClauses(cgf, cgm&: cgf.getCIRGenModule(), |
| 697 | builder&: cgf.getBuilder(), loc: begin, |
| 698 | clauses: targetItem->clauses, clauseOps&: targetOps, mapSyms))) |
| 699 | return mlir::failure(); |
| 700 | |
| 701 | return emitTargetOp(cgf, s, queue, targetItem, begin, end, targetOps, mapSyms, |
| 702 | emitBody); |
| 703 | } |
| 704 | |
| 705 | mlir::LogicalResult |
| 706 | CIRGenFunction::emitOMPTargetDirective(const OMPTargetDirective &s) { |
| 707 | mlir::Location begin = getLoc(srcLoc: s.getBeginLoc()); |
| 708 | mlir::Location end = getLoc(srcLoc: s.getEndLoc()); |
| 709 | |
| 710 | omp::ConstructQueue queue = |
| 711 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 712 | omp::ConstructQueue::const_iterator item = queue.begin(); |
| 713 | |
| 714 | return emitTarget( |
| 715 | cgf&: *this, s, queue, targetItem: item, begin, end, emitBody: [&]() -> mlir::LogicalResult { |
| 716 | const CapturedStmt *cs = s.getCapturedStmt(RegionKind: llvm::omp::OMPD_target); |
| 717 | return emitStmt(s: cs->getCapturedStmt(), |
| 718 | /*useCurrentScope=*/true); |
| 719 | }); |
| 720 | } |
| 721 | mlir::LogicalResult |
| 722 | CIRGenFunction::emitOMPTeamsDirective(const OMPTeamsDirective &s) { |
| 723 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTeamsDirective" ); |
| 724 | return mlir::failure(); |
| 725 | } |
| 726 | mlir::LogicalResult CIRGenFunction::emitOMPCancellationPointDirective( |
| 727 | const OMPCancellationPointDirective &s) { |
| 728 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 729 | "OpenMP OMPCancellationPointDirective" ); |
| 730 | return mlir::failure(); |
| 731 | } |
| 732 | mlir::LogicalResult |
| 733 | CIRGenFunction::emitOMPCancelDirective(const OMPCancelDirective &s) { |
| 734 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCancelDirective" ); |
| 735 | return mlir::failure(); |
| 736 | } |
| 737 | mlir::LogicalResult |
| 738 | CIRGenFunction::emitOMPTargetDataDirective(const OMPTargetDataDirective &s) { |
| 739 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 740 | "OpenMP OMPTargetDataDirective" ); |
| 741 | return mlir::failure(); |
| 742 | } |
| 743 | mlir::LogicalResult CIRGenFunction::emitOMPTargetEnterDataDirective( |
| 744 | const OMPTargetEnterDataDirective &s) { |
| 745 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 746 | "OpenMP OMPTargetEnterDataDirective" ); |
| 747 | return mlir::failure(); |
| 748 | } |
| 749 | mlir::LogicalResult CIRGenFunction::emitOMPTargetExitDataDirective( |
| 750 | const OMPTargetExitDataDirective &s) { |
| 751 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 752 | "OpenMP OMPTargetExitDataDirective" ); |
| 753 | return mlir::failure(); |
| 754 | } |
| 755 | mlir::LogicalResult CIRGenFunction::emitOMPTargetParallelDirective( |
| 756 | const OMPTargetParallelDirective &s) { |
| 757 | mlir::Location begin = getLoc(srcLoc: s.getBeginLoc()); |
| 758 | mlir::Location end = getLoc(srcLoc: s.getEndLoc()); |
| 759 | |
| 760 | omp::ConstructQueue queue = |
| 761 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 762 | omp::ConstructQueue::const_iterator targetItem = queue.begin(); |
| 763 | assert(targetItem->id == llvm::omp::OMPD_target && |
| 764 | "expected 'target' to be the outermost directive" ); |
| 765 | |
| 766 | return emitTarget( |
| 767 | cgf&: *this, s, queue, targetItem, begin, end, emitBody: [&]() -> mlir::LogicalResult { |
| 768 | omp::ConstructQueue::const_iterator parallelItem = |
| 769 | std::next(x: targetItem); |
| 770 | assert(parallelItem != queue.end() && |
| 771 | parallelItem->id == llvm::omp::OMPD_parallel && |
| 772 | "expected a 'parallel' directive nested in 'target'" ); |
| 773 | |
| 774 | return emitParallel(cgf&: *this, s, queue, parallelItem, begin, end, |
| 775 | emitBody: [&]() -> mlir::LogicalResult { |
| 776 | const CapturedStmt *cs = |
| 777 | s.getCapturedStmt(RegionKind: llvm::omp::OMPD_parallel); |
| 778 | return emitStmt(s: cs->getCapturedStmt(), |
| 779 | /*useCurrentScope=*/true); |
| 780 | }); |
| 781 | }); |
| 782 | } |
| 783 | mlir::LogicalResult CIRGenFunction::emitOMPTargetParallelForDirective( |
| 784 | const OMPTargetParallelForDirective &s) { |
| 785 | mlir::Location begin = getLoc(srcLoc: s.getBeginLoc()); |
| 786 | mlir::Location end = getLoc(srcLoc: s.getEndLoc()); |
| 787 | |
| 788 | omp::ConstructQueue queue = |
| 789 | omp::buildConstructQueue(openmpVersion: getContext().getLangOpts().OpenMP, s); |
| 790 | omp::ConstructQueue::const_iterator targetItem = queue.begin(); |
| 791 | assert(targetItem->id == llvm::omp::OMPD_target && |
| 792 | "expected 'target' to be the outermost directive" ); |
| 793 | |
| 794 | return emitTarget( |
| 795 | cgf&: *this, s, queue, targetItem, begin, end, emitBody: [&]() -> mlir::LogicalResult { |
| 796 | omp::ConstructQueue::const_iterator parallelItem = |
| 797 | std::next(x: targetItem); |
| 798 | assert(parallelItem != queue.end() && |
| 799 | parallelItem->id == llvm::omp::OMPD_parallel && |
| 800 | "expected a 'parallel' directive nested in 'target'" ); |
| 801 | |
| 802 | return emitParallel( |
| 803 | cgf&: *this, s, queue, parallelItem, begin, end, |
| 804 | emitBody: [&]() -> mlir::LogicalResult { |
| 805 | omp::ConstructQueue::const_iterator forItem = |
| 806 | std::next(x: parallelItem); |
| 807 | assert(forItem != queue.end() && |
| 808 | forItem->id == llvm::omp::OMPD_for && |
| 809 | "expected a 'for' directive nested in 'parallel'" ); |
| 810 | return emitOMPWorksharingLoop(cgf&: *this, s, item: forItem); |
| 811 | }); |
| 812 | }); |
| 813 | } |
| 814 | mlir::LogicalResult |
| 815 | CIRGenFunction::emitOMPTaskLoopDirective(const OMPTaskLoopDirective &s) { |
| 816 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskLoopDirective" ); |
| 817 | return mlir::failure(); |
| 818 | } |
| 819 | mlir::LogicalResult CIRGenFunction::emitOMPTaskLoopSimdDirective( |
| 820 | const OMPTaskLoopSimdDirective &s) { |
| 821 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 822 | "OpenMP OMPTaskLoopSimdDirective" ); |
| 823 | return mlir::failure(); |
| 824 | } |
| 825 | mlir::LogicalResult CIRGenFunction::emitOMPMaskedTaskLoopDirective( |
| 826 | const OMPMaskedTaskLoopDirective &s) { |
| 827 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 828 | "OpenMP OMPMaskedTaskLoopDirective" ); |
| 829 | return mlir::failure(); |
| 830 | } |
| 831 | mlir::LogicalResult CIRGenFunction::emitOMPMaskedTaskLoopSimdDirective( |
| 832 | const OMPMaskedTaskLoopSimdDirective &s) { |
| 833 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 834 | "OpenMP OMPMaskedTaskLoopSimdDirective" ); |
| 835 | return mlir::failure(); |
| 836 | } |
| 837 | mlir::LogicalResult CIRGenFunction::emitOMPMasterTaskLoopDirective( |
| 838 | const OMPMasterTaskLoopDirective &s) { |
| 839 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 840 | "OpenMP OMPMasterTaskLoopDirective" ); |
| 841 | return mlir::failure(); |
| 842 | } |
| 843 | mlir::LogicalResult CIRGenFunction::emitOMPMasterTaskLoopSimdDirective( |
| 844 | const OMPMasterTaskLoopSimdDirective &s) { |
| 845 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 846 | "OpenMP OMPMasterTaskLoopSimdDirective" ); |
| 847 | return mlir::failure(); |
| 848 | } |
| 849 | mlir::LogicalResult CIRGenFunction::emitOMPParallelGenericLoopDirective( |
| 850 | const OMPParallelGenericLoopDirective &s) { |
| 851 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 852 | "OpenMP OMPParallelGenericLoopDirective" ); |
| 853 | return mlir::failure(); |
| 854 | } |
| 855 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMaskedDirective( |
| 856 | const OMPParallelMaskedDirective &s) { |
| 857 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 858 | "OpenMP OMPParallelMaskedDirective" ); |
| 859 | return mlir::failure(); |
| 860 | } |
| 861 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMaskedTaskLoopDirective( |
| 862 | const OMPParallelMaskedTaskLoopDirective &s) { |
| 863 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 864 | "OpenMP OMPParallelMaskedTaskLoopDirective" ); |
| 865 | return mlir::failure(); |
| 866 | } |
| 867 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMaskedTaskLoopSimdDirective( |
| 868 | const OMPParallelMaskedTaskLoopSimdDirective &s) { |
| 869 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 870 | "OpenMP OMPParallelMaskedTaskLoopSimdDirective" ); |
| 871 | return mlir::failure(); |
| 872 | } |
| 873 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMasterTaskLoopDirective( |
| 874 | const OMPParallelMasterTaskLoopDirective &s) { |
| 875 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 876 | "OpenMP OMPParallelMasterTaskLoopDirective" ); |
| 877 | return mlir::failure(); |
| 878 | } |
| 879 | mlir::LogicalResult CIRGenFunction::emitOMPParallelMasterTaskLoopSimdDirective( |
| 880 | const OMPParallelMasterTaskLoopSimdDirective &s) { |
| 881 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 882 | "OpenMP OMPParallelMasterTaskLoopSimdDirective" ); |
| 883 | return mlir::failure(); |
| 884 | } |
| 885 | mlir::LogicalResult |
| 886 | CIRGenFunction::emitOMPDistributeDirective(const OMPDistributeDirective &s) { |
| 887 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 888 | "OpenMP OMPDistributeDirective" ); |
| 889 | return mlir::failure(); |
| 890 | } |
| 891 | mlir::LogicalResult CIRGenFunction::emitOMPDistributeParallelForDirective( |
| 892 | const OMPDistributeParallelForDirective &s) { |
| 893 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 894 | "OpenMP OMPDistributeParallelForDirective" ); |
| 895 | return mlir::failure(); |
| 896 | } |
| 897 | mlir::LogicalResult CIRGenFunction::emitOMPDistributeParallelForSimdDirective( |
| 898 | const OMPDistributeParallelForSimdDirective &s) { |
| 899 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 900 | "OpenMP OMPDistributeParallelForSimdDirective" ); |
| 901 | return mlir::failure(); |
| 902 | } |
| 903 | mlir::LogicalResult CIRGenFunction::emitOMPDistributeSimdDirective( |
| 904 | const OMPDistributeSimdDirective &s) { |
| 905 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 906 | "OpenMP OMPDistributeSimdDirective" ); |
| 907 | return mlir::failure(); |
| 908 | } |
| 909 | mlir::LogicalResult CIRGenFunction::emitOMPTargetParallelGenericLoopDirective( |
| 910 | const OMPTargetParallelGenericLoopDirective &s) { |
| 911 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 912 | "OpenMP OMPTargetParallelGenericLoopDirective" ); |
| 913 | return mlir::failure(); |
| 914 | } |
| 915 | mlir::LogicalResult CIRGenFunction::emitOMPTargetGenericLoopDirective( |
| 916 | const OMPTargetGenericLoopDirective &s) { |
| 917 | cgm.errorNYI(s.getSourceRange(), "OpenMP OMPTargetGenericLoopDirective" ); |
| 918 | return mlir::failure(); |
| 919 | } |
| 920 | mlir::LogicalResult CIRGenFunction::emitOMPTargetParallelForSimdDirective( |
| 921 | const OMPTargetParallelForSimdDirective &s) { |
| 922 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 923 | "OpenMP OMPTargetParallelForSimdDirective" ); |
| 924 | return mlir::failure(); |
| 925 | } |
| 926 | mlir::LogicalResult |
| 927 | CIRGenFunction::emitOMPTargetSimdDirective(const OMPTargetSimdDirective &s) { |
| 928 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 929 | "OpenMP OMPTargetSimdDirective" ); |
| 930 | return mlir::failure(); |
| 931 | } |
| 932 | mlir::LogicalResult CIRGenFunction::emitOMPTargetTeamsGenericLoopDirective( |
| 933 | const OMPTargetTeamsGenericLoopDirective &s) { |
| 934 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 935 | "OpenMP OMPTargetTeamsGenericLoopDirective" ); |
| 936 | return mlir::failure(); |
| 937 | } |
| 938 | mlir::LogicalResult CIRGenFunction::emitOMPTargetUpdateDirective( |
| 939 | const OMPTargetUpdateDirective &s) { |
| 940 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 941 | "OpenMP OMPTargetUpdateDirective" ); |
| 942 | return mlir::failure(); |
| 943 | } |
| 944 | mlir::LogicalResult CIRGenFunction::emitOMPTeamsDistributeDirective( |
| 945 | const OMPTeamsDistributeDirective &s) { |
| 946 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 947 | "OpenMP OMPTeamsDistributeDirective" ); |
| 948 | return mlir::failure(); |
| 949 | } |
| 950 | mlir::LogicalResult CIRGenFunction::emitOMPTeamsDistributeSimdDirective( |
| 951 | const OMPTeamsDistributeSimdDirective &s) { |
| 952 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 953 | "OpenMP OMPTeamsDistributeSimdDirective" ); |
| 954 | return mlir::failure(); |
| 955 | } |
| 956 | mlir::LogicalResult |
| 957 | CIRGenFunction::emitOMPTeamsDistributeParallelForSimdDirective( |
| 958 | const OMPTeamsDistributeParallelForSimdDirective &s) { |
| 959 | getCIRGenModule().errorNYI( |
| 960 | s.getSourceRange(), "OpenMP OMPTeamsDistributeParallelForSimdDirective" ); |
| 961 | return mlir::failure(); |
| 962 | } |
| 963 | mlir::LogicalResult CIRGenFunction::emitOMPTeamsDistributeParallelForDirective( |
| 964 | const OMPTeamsDistributeParallelForDirective &s) { |
| 965 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 966 | "OpenMP OMPTeamsDistributeParallelForDirective" ); |
| 967 | return mlir::failure(); |
| 968 | } |
| 969 | mlir::LogicalResult CIRGenFunction::emitOMPTeamsGenericLoopDirective( |
| 970 | const OMPTeamsGenericLoopDirective &s) { |
| 971 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 972 | "OpenMP OMPTeamsGenericLoopDirective" ); |
| 973 | return mlir::failure(); |
| 974 | } |
| 975 | mlir::LogicalResult |
| 976 | CIRGenFunction::emitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &s) { |
| 977 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 978 | "OpenMP OMPTargetTeamsDirective" ); |
| 979 | return mlir::failure(); |
| 980 | } |
| 981 | mlir::LogicalResult CIRGenFunction::emitOMPTargetTeamsDistributeDirective( |
| 982 | const OMPTargetTeamsDistributeDirective &s) { |
| 983 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 984 | "OpenMP OMPTargetTeamsDistributeDirective" ); |
| 985 | return mlir::failure(); |
| 986 | } |
| 987 | mlir::LogicalResult |
| 988 | CIRGenFunction::emitOMPTargetTeamsDistributeParallelForDirective( |
| 989 | const OMPTargetTeamsDistributeParallelForDirective &s) { |
| 990 | getCIRGenModule().errorNYI( |
| 991 | s.getSourceRange(), |
| 992 | "OpenMP OMPTargetTeamsDistributeParallelForDirective" ); |
| 993 | return mlir::failure(); |
| 994 | } |
| 995 | mlir::LogicalResult |
| 996 | CIRGenFunction::emitOMPTargetTeamsDistributeParallelForSimdDirective( |
| 997 | const OMPTargetTeamsDistributeParallelForSimdDirective &s) { |
| 998 | getCIRGenModule().errorNYI( |
| 999 | s.getSourceRange(), |
| 1000 | "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective" ); |
| 1001 | return mlir::failure(); |
| 1002 | } |
| 1003 | mlir::LogicalResult CIRGenFunction::emitOMPTargetTeamsDistributeSimdDirective( |
| 1004 | const OMPTargetTeamsDistributeSimdDirective &s) { |
| 1005 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 1006 | "OpenMP OMPTargetTeamsDistributeSimdDirective" ); |
| 1007 | return mlir::failure(); |
| 1008 | } |
| 1009 | mlir::LogicalResult |
| 1010 | CIRGenFunction::emitOMPInteropDirective(const OMPInteropDirective &s) { |
| 1011 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPInteropDirective" ); |
| 1012 | return mlir::failure(); |
| 1013 | } |
| 1014 | mlir::LogicalResult |
| 1015 | CIRGenFunction::emitOMPDispatchDirective(const OMPDispatchDirective &s) { |
| 1016 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPDispatchDirective" ); |
| 1017 | return mlir::failure(); |
| 1018 | } |
| 1019 | mlir::LogicalResult |
| 1020 | CIRGenFunction::emitOMPGenericLoopDirective(const OMPGenericLoopDirective &s) { |
| 1021 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 1022 | "OpenMP OMPGenericLoopDirective" ); |
| 1023 | return mlir::failure(); |
| 1024 | } |
| 1025 | mlir::LogicalResult |
| 1026 | CIRGenFunction::emitOMPReverseDirective(const OMPReverseDirective &s) { |
| 1027 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPReverseDirective" ); |
| 1028 | return mlir::failure(); |
| 1029 | } |
| 1030 | mlir::LogicalResult |
| 1031 | CIRGenFunction::emitOMPSplitDirective(const OMPSplitDirective &s) { |
| 1032 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSplitDirective" ); |
| 1033 | return mlir::failure(); |
| 1034 | } |
| 1035 | mlir::LogicalResult |
| 1036 | CIRGenFunction::emitOMPInterchangeDirective(const OMPInterchangeDirective &s) { |
| 1037 | getCIRGenModule().errorNYI(s.getSourceRange(), |
| 1038 | "OpenMP OMPInterchangeDirective" ); |
| 1039 | return mlir::failure(); |
| 1040 | } |
| 1041 | mlir::LogicalResult |
| 1042 | CIRGenFunction::emitOMPFlattenDirective(const OMPFlattenDirective &s) { |
| 1043 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFlattenDirective" ); |
| 1044 | return mlir::failure(); |
| 1045 | } |
| 1046 | mlir::LogicalResult |
| 1047 | CIRGenFunction::emitOMPAssumeDirective(const OMPAssumeDirective &s) { |
| 1048 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPAssumeDirective" ); |
| 1049 | return mlir::failure(); |
| 1050 | } |
| 1051 | mlir::LogicalResult |
| 1052 | CIRGenFunction::emitOMPMaskedDirective(const OMPMaskedDirective &s) { |
| 1053 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMaskedDirective" ); |
| 1054 | return mlir::failure(); |
| 1055 | } |
| 1056 | mlir::LogicalResult |
| 1057 | CIRGenFunction::emitOMPStripeDirective(const OMPStripeDirective &s) { |
| 1058 | getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPStripeDirective" ); |
| 1059 | return mlir::failure(); |
| 1060 | } |
| 1061 | |