clang 24.0.0git
CIRGenStmtOpenMP.cpp
Go to the documentation of this file.
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"
17#include "mlir/Dialect/OpenMP/OpenMPDialect.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#include <type_traits>
25using namespace clang;
26using namespace clang::CIRGen;
27
28mlir::LogicalResult
30 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPScopeDirective");
31 return mlir::failure();
32}
33mlir::LogicalResult
35 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPErrorDirective");
36 return mlir::failure();
37}
38
39/// Report \p item's synthesized clauses as not-yet-implemented: having no AST
40/// node, they cannot go through the clause emitters.
41static mlir::LogicalResult
43 omp::ConstructQueue::const_iterator item) {
44 mlir::LogicalResult res = mlir::success();
45 for (llvm::omp::Clause synth : item->synthesized) {
46 cgf.getCIRGenModule().errorNYI(s.getSourceRange(),
47 (llvm::Twine("OpenMP synthesized '") +
48 llvm::omp::getOpenMPClauseName(synth) +
49 "' clause from construct decomposition")
50 .str());
51 res = mlir::failure();
52 }
53 return res;
54}
55
56static mlir::LogicalResult
58 CIRGenBuilderTy &builder, mlir::Location loc,
60 mlir::omp::ParallelOperands &clauseOps) {
61 OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses);
62 ce.emitIf(clauseOps, llvm::omp::Directive::OMPD_parallel);
63 ce.emitNumThreads(clauseOps);
64 ce.emitProcBind(clauseOps);
65 return ce.emitNYI</*supported=*/OMPIfClause, OMPNumThreadsClause,
66 OMPProcBindClause>(
68 OMPDefaultClause, OMPFirstprivateClause,
69 OMPPrivateClause, OMPReductionClause,
70 OMPSharedClause>{},
71 llvm::omp::Directive::OMPD_parallel);
72}
73
74/// Emits the contents of an OpenMP region op's \p block in a new lexical scope
75/// and terminates the block with a \p TermOp. The scope's cleanups (e.g.
76/// lifetime markers of locals declared in the region) are emitted before the
77/// terminator; destroying the scope instead would make it terminate the block
78/// with a cir.yield.
79template <typename TermOp>
80static mlir::LogicalResult
81emitOMPRegionBody(CIRGenFunction &cgf, mlir::Block &block, mlir::Location begin,
82 mlir::Location end,
83 llvm::function_ref<mlir::LogicalResult()> emitBody) {
84 CIRGenBuilderTy &builder = cgf.getBuilder();
85 mlir::OpBuilder::InsertionGuard guard(builder);
86 builder.setInsertionPointToEnd(&block);
87
88 CIRGenFunction::LexicalScope ls{cgf, begin, &block};
89 mlir::LogicalResult res = emitBody();
90 ls.forceCleanup();
91 TermOp::create(builder, end);
92 return res;
93}
94
95template <typename DirectiveTy>
96static mlir::LogicalResult
97emitParallelOp(CIRGenFunction &cgf, const DirectiveTy &s,
98 const omp::ConstructQueue &queue,
99 omp::ConstructQueue::const_iterator item, mlir::Location begin,
100 mlir::Location end, const mlir::omp::ParallelOperands &clauseOps,
101 llvm::function_ref<mlir::LogicalResult()> emitBody) {
102 CIRGenBuilderTy &builder = cgf.getBuilder();
103 CIRGenModule &cgm = cgf.getCIRGenModule();
104
105 // hasCancel() reports a nested cancel/cancellation point directive in the
106 // body, not a clause on `parallel`, so it can't be an emitParallelClauses()
107 // NYI check.
108 // OMPParallelMasterDirective does not expose a cancellation flag.
109 if constexpr (!std::is_same_v<DirectiveTy, OMPParallelMasterDirective>) {
110 if (s.hasCancel()) {
111 cgm.errorNYI(s.getBeginLoc(),
112 "OpenMP 'cancel' or 'cancellation point' inside a parallel "
113 "region");
114 return mlir::failure();
115 }
116 }
117 // Only set for reduction(task: ...), already rejected as NYI above.
118 assert(!s.getTaskReductionRefExpr() &&
119 "reduction(task: ...) should already be rejected as NYI");
120
121 auto parallelOp = mlir::omp::ParallelOp::create(builder, begin, clauseOps);
122 if (!omp::isLastItemInQueue(item, queue))
123 parallelOp.setCombined(true);
124
125 mlir::Block &block = parallelOp.getRegion().emplaceBlock();
126 return emitOMPRegionBody<mlir::omp::TerminatorOp>(cgf, block, begin, end,
127 emitBody);
128}
129
130/// Checks, emits clauses for, and emits an omp.parallel for the `parallel`
131/// directive at \p parallelItem, deferring to \p emitBody for the region's
132/// contents.
133template <typename DirectiveTy>
134static mlir::LogicalResult emitParallel(
135 CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue,
136 omp::ConstructQueue::const_iterator parallelItem, mlir::Location begin,
137 mlir::Location end, llvm::function_ref<mlir::LogicalResult()> emitBody) {
138 if (mlir::failed(checkSynthesizedClauses(cgf, s, parallelItem)))
139 return mlir::failure();
140
141 mlir::omp::ParallelOperands parallelOps;
142 if (mlir::failed(emitParallelClauses(cgf, cgf.getCIRGenModule(),
143 cgf.getBuilder(), begin,
144 parallelItem->clauses, parallelOps)))
145 return mlir::failure();
146
147 return emitParallelOp(cgf, s, queue, parallelItem, begin, end, parallelOps,
148 emitBody);
149}
150
151mlir::LogicalResult
152CIRGenFunction::emitOMPParallelDirective(const OMPParallelDirective &s) {
153 mlir::Location begin = getLoc(s.getBeginLoc());
154 mlir::Location end = getLoc(s.getEndLoc());
155
156 omp::ConstructQueue queue =
158 omp::ConstructQueue::const_iterator item = queue.begin();
159
160 return emitParallel(
161 *this, s, queue, item, begin, end, [&]() -> mlir::LogicalResult {
162 // emitStmt() rejects CapturedStmt directly; the
163 // parent construct must unwrap it, so emit the
164 // inner statement instead.
165 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_parallel);
166 return emitStmt(cs->getCapturedStmt(),
167 /*useCurrentScope=*/true);
168 });
169}
170
172 llvm::SaveAndRestore<bool> noLifetimeMarkers(shouldEmitLifetimeMarkers,
173 false);
174 emitVarDecl(d);
175}
176
177/// Emits a single Sema-generated pre-init statement for an OpenMP loop
178/// directive: a VarDecl's DeclStmt is lowered directly (it has no
179/// initializer CIRGenFunction::emitStmt can handle on its own), everything
180/// else goes through the general statement emitter.
181static mlir::LogicalResult emitLoopPreInit(CIRGenFunction &cgf,
182 const Stmt *preInit) {
183 if (const auto *declStmt = dyn_cast<DeclStmt>(preInit)) {
184 for (const Decl *d : declStmt->decls())
186 return mlir::success();
187 }
188 return cgf.emitStmt(preInit, /*useCurrentScope=*/true);
189}
190
191/// Emits the Sema-generated pre-init statements for an OpenMP loop directive.
192static mlir::LogicalResult emitLoopPreInits(CIRGenFunction &cgf,
193 const Stmt *preInits) {
194 if (!preInits)
195 return mlir::success();
196
197 if (const auto *compound = dyn_cast<CompoundStmt>(preInits)) {
198 for (const Stmt *stmt : compound->body())
199 if (emitLoopPreInit(cgf, stmt).failed())
200 return mlir::failure();
201 return mlir::success();
202 }
203
204 return emitLoopPreInit(cgf, preInits);
205}
206
207/// Returns the first `continue` in \p s that is not nested in an inner loop,
208/// i.e. one that targets the loop whose body is \p s.
209static const ContinueStmt *findLoopBodyContinue(const Stmt *s) {
211 return nullptr;
212 if (const auto *continueStmt = dyn_cast<ContinueStmt>(s))
213 return continueStmt;
214 for (const Stmt *child : s->children())
216 return continueStmt;
217 return nullptr;
218}
219
220/// Emits an omp.loop_nest that iterates a normalized `[0, tripCount)` range
221/// and recomputes the real induction variable each iteration using the given
222/// update expression.
223static mlir::LogicalResult
224emitOMPLoopNest(CIRGenFunction &cgf, const ForStmt &forStmt, mlir::Value lb,
225 mlir::Value ub, mlir::Value step, const VarDecl *ivDecl,
226 const Expr *update) {
227 CIRGenBuilderTy &builder = cgf.getBuilder();
228 mlir::Location loc = cgf.getLoc(forStmt.getSourceRange());
229
230 auto loopNestOp = mlir::omp::LoopNestOp::create(
231 builder, loc, /*collapse_num_loops=*/1, lb, ub, step,
232 /*loop_inclusive=*/false, /*tile_sizes=*/nullptr);
233 mlir::Block &block = loopNestOp.getRegion().emplaceBlock();
234 block.addArgument(lb.getType(), loc);
235
237 cgf, block, loc, cgf.getLoc(forStmt.getEndLoc()),
238 [&]() -> mlir::LogicalResult {
239 // Store the normalized counter block argument into the normalized
240 // loop variable's storage location, then let Sema's update expression
241 // recompute the real induction variable from it.
242 mlir::Value iv = block.getArgument(0);
243 Address ivAddr = cgf.getAddrOfLocalVar(ivDecl);
244 mlir::Value civVal =
245 builder.createBuiltinIntCast(loc, iv, ivAddr.getElementType());
246 builder.createStore(loc, civVal, ivAddr);
247 cgf.emitIgnoredExpr(update);
248
249 if (!forStmt.getBody())
250 return mlir::success();
251 return cgf.emitStmt(forStmt.getBody(), /*useCurrentScope=*/true);
252 });
253}
254
255/// Evaluates the clauses allowed on the `for` directive; none are supported
256/// yet, so every eligible clause is reported as NYI.
257static mlir::LogicalResult
259 CIRGenBuilderTy &builder, mlir::Location loc,
261 mlir::omp::WsloopOperands &clauseOps) {
262 OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses);
263 return ce.emitNYI</*supported=*/>(
264 /*nyi=*/OpenMPNYIClauseList<
265 OMPAllocateClause, OMPCollapseClause, OMPFirstprivateClause,
266 OMPLastprivateClause, OMPLinearClause, OMPNowaitClause,
267 OMPOrderClause, OMPOrderedClause, OMPPrivateClause,
268 OMPReductionClause, OMPScheduleClause>{},
269 llvm::omp::Directive::OMPD_for);
270}
271
272/// Creates a module-level `omp.private` op (a "privatizer") for a scalar
273/// of CIR type elemTy.
274static mlir::omp::PrivateClauseOp emitScalarPrivatizer(CIRGenModule &cgm,
275 mlir::Location loc,
276 llvm::StringRef baseName,
277 mlir::Type elemTy) {
278 // getGlobalValue() is an O(1) cache lookup, unlike
279 // mlir::SymbolTable::lookupSymbolIn()'s O(n) module scan.
280 unsigned uniquingCounter = 0;
281 llvm::SmallString<64> name = mlir::SymbolTable::generateSymbolName<64>(
282 (baseName + ".privatizer").str(),
283 [&](llvm::StringRef candidate) {
284 return cgm.getGlobalValue(candidate) != nullptr;
285 },
286 uniquingCounter);
287
288 mlir::ModuleOp mod = cgm.getModule();
289 mlir::OpBuilder b(mod.getContext());
290 b.setInsertionPointToEnd(mod.getBody());
291 auto privatizer = mlir::omp::PrivateClauseOp::create(
292 b, loc, mlir::TypeRange{}, b.getStringAttr(name),
293 mlir::TypeAttr::get(elemTy));
294 cgm.insertGlobalSymbol(privatizer);
295 return privatizer;
296}
297
298/// Registers a loop counter as predetermined-private on the associated loop
299/// wrapper op.
301 mlir::Location loc,
302 const VarDecl *privateVd,
303 mlir::omp::PrivateClauseOps &clauseOps) {
304 cgf.emitOMPNoLifetimeVarDecl(*privateVd);
305 Address moldAddr = cgf.getAddrOfLocalVar(privateVd);
306
307 mlir::omp::PrivateClauseOp privatizer = emitScalarPrivatizer(
308 cgm, loc, privateVd->getName(), moldAddr.getElementType());
309
310 clauseOps.privateVars.push_back(moldAddr.getPointer());
311 clauseOps.privateSyms.push_back(
312 mlir::FlatSymbolRefAttr::get(privatizer.getSymNameAttr()));
313 return moldAddr;
314}
315
316/// Emits the trip count of the loop associated with \p s: Sema's iteration
317/// count if the loop's precondition holds, and zero otherwise. The iteration
318/// count is only meaningful when the loop runs at least once; e.g. for
319/// `for (unsigned i = 10; i < 0; i += 2)` its arithmetic wraps to a positive
320/// value.
321static mlir::Value emitLoopTripCount(CIRGenFunction &cgf,
322 const OMPLoopDirective &s) {
323 CIRGenBuilderTy &builder = cgf.getBuilder();
324 mlir::Location loc = cgf.getLoc(s.getBeginLoc());
325 mlir::Value preCond = cgf.evaluateExprAsBool(s.getPreCond());
326 mlir::Value numIterations = cgf.emitScalarExpr(s.getNumIterations());
327 mlir::Value zero = builder.getConstInt(
328 loc, mlir::cast<cir::IntType>(numIterations.getType()), 0);
329 return builder.createSelect(loc, preCond, numIterations, zero);
330}
331
332/// Lowers an OMPLoopDirective's `for` directive to an omp.wsloop +
333/// omp.loop_nest.
334static mlir::LogicalResult
336 omp::ConstructQueue::const_iterator item) {
337 CIRGenBuilderTy &builder = cgf.getBuilder();
338 CIRGenModule &cgm = cgf.getCIRGenModule();
339 mlir::Location loc = cgf.getLoc(s.getBeginLoc());
340
341 if (mlir::failed(checkSynthesizedClauses(cgf, s, item)))
342 return mlir::failure();
343
344 mlir::omp::WsloopOperands clauseOps;
345 if (emitWsloopClauses(cgf, cgm, builder, loc, item->clauses, clauseOps)
346 .failed())
347 return mlir::failure();
348
349 const CapturedStmt *capturedStmt = s.getInnermostCapturedStmt();
350 const auto *forStmt = dyn_cast<ForStmt>(capturedStmt->getCapturedStmt());
351 if (!forStmt) {
352 assert(isa<CXXForRangeStmt>(capturedStmt->getCapturedStmt()) &&
353 "expected a for or range-based for loop");
354 cgm.errorNYI(capturedStmt->getCapturedStmt()->getSourceRange(),
355 "range-based for loop in an OpenMP loop directive");
356 return mlir::failure();
357 }
358
359 // A `continue` lowers to cir.continue, which must be nested in a CIR loop,
360 // and omp.loop_nest is not one.
361 if (const ContinueStmt *continueStmt =
362 findLoopBodyContinue(forStmt->getBody())) {
363 cgm.errorNYI(continueStmt->getSourceRange(),
364 "continue in an OpenMP loop body");
365 return mlir::failure();
366 }
367
368 if (emitLoopPreInits(cgf, s.getPreInits()).failed())
369 return mlir::failure();
370
371 // Allocate storage for Sema's normalized 0-based loop counter.
372 const auto *ivDecl =
374 cgf.emitOMPNoLifetimeVarDecl(*ivDecl);
375 // Each counter is rebound below to the loop wrapper's private block
376 // argument; these restore the counters' original addresses when this
377 // function returns, so code after the loop doesn't refer to the region.
380 counterShadows.reserve(s.counters().size());
381 counterMolds.reserve(s.counters().size());
382 for (auto [counter, privateCounter] :
383 llvm::zip_equal(s.counters(), s.private_counters())) {
384 const auto *vd = cast<VarDecl>(cast<DeclRefExpr>(counter)->getDecl());
385 const auto *privateVd =
386 cast<VarDecl>(cast<DeclRefExpr>(privateCounter)->getDecl());
387 counterShadows.emplace_back(cgf, vd);
388 counterMolds.emplace_back(
389 vd, emitLoopPrivateCounter(cgf, cgm, loc, privateVd, clauseOps));
390 }
391
392 mlir::Value tripCountCir = emitLoopTripCount(cgf, s);
393 auto cirIntType = mlir::cast<cir::IntType>(tripCountCir.getType());
394 mlir::Value zero = builder.createBuiltinIntCast(
395 loc, builder.getConstInt(loc, cirIntType, 0));
396 mlir::Value one = builder.createBuiltinIntCast(
397 loc, builder.getConstInt(loc, cirIntType, 1));
398 mlir::Value tripCount = builder.createBuiltinIntCast(loc, tripCountCir);
399
400 auto wsloopOp = mlir::omp::WsloopOp::create(builder, loc, clauseOps);
401 mlir::Block *innerBlock = new mlir::Block();
402 // Ensures the block arguments match BlockArgOpenMPOpInterface's expected
403 // order.
404 for (auto &counterMold : counterMolds)
405 innerBlock->addArgument(counterMold.second.getPointer().getType(), loc);
406 wsloopOp.getRegion().push_back(innerBlock);
407
408 mlir::OpBuilder::InsertionGuard guard(builder);
409 builder.setInsertionPointToStart(innerBlock);
410
411 // Bind each counter to its private block argument.
412 for (unsigned idx = 0; idx < counterMolds.size(); ++idx) {
413 const VarDecl *vd = counterMolds[idx].first;
414 Address moldAddr = counterMolds[idx].second;
415 Address privAddr(innerBlock->getArgument(idx), moldAddr.getElementType(),
416 moldAddr.getAlignment());
417 cgf.replaceAddrOfLocalVar(vd, privAddr);
418 cgf.symbolTable.insert(vd, privAddr.getPointer());
419 }
420
421 return emitOMPLoopNest(cgf, *forStmt, zero, tripCount, one, ivDecl,
422 s.updates()[0]);
423}
424
425mlir::LogicalResult
427 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskwaitDirective");
428 return mlir::failure();
429}
430mlir::LogicalResult
432 getCIRGenModule().errorNYI(s.getSourceRange(),
433 "OpenMP OMPTaskyieldDirective");
434 return mlir::failure();
435}
436mlir::LogicalResult
438 mlir::omp::BarrierOp::create(builder, getLoc(s.getBeginLoc()));
439 assert(s.clauses().empty() && "omp barrier doesn't support clauses");
440 return mlir::success();
441}
442mlir::LogicalResult
444 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMetaDirective");
445 return mlir::failure();
446}
447mlir::LogicalResult
448CIRGenFunction::emitOMPCanonicalLoop(const OMPCanonicalLoop &s) {
449 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCanonicalLoop");
450 return mlir::failure();
451}
452mlir::LogicalResult
454 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSimdDirective");
455 return mlir::failure();
456}
457mlir::LogicalResult
459 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTileDirective");
460 return mlir::failure();
461}
462mlir::LogicalResult
464 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPUnrollDirective");
465 return mlir::failure();
466}
467mlir::LogicalResult
469 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFuseDirective");
470 return mlir::failure();
471}
472mlir::LogicalResult
478mlir::LogicalResult
480 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPForSimdDirective");
481 return mlir::failure();
482}
483mlir::LogicalResult
485 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSectionsDirective");
486 return mlir::failure();
487}
488mlir::LogicalResult
490 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSectionDirective");
491 return mlir::failure();
492}
493mlir::LogicalResult
495 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSingleDirective");
496 return mlir::failure();
497}
498static mlir::LogicalResult emitMasterOp(CIRGenFunction &cgf,
499 mlir::Location begin,
500 mlir::Location end, const Stmt *body) {
501 CIRGenBuilderTy &builder = cgf.getBuilder();
502
503 auto masterOp = mlir::omp::MasterOp::create(builder, begin);
504
505 mlir::Block &block = masterOp.getRegion().emplaceBlock();
506 mlir::OpBuilder::InsertionGuard guard(builder);
507 builder.setInsertionPointToEnd(&block);
508
509 CIRGenFunction::LexicalScope ls{cgf, begin, builder.getInsertionBlock()};
510 mlir::LogicalResult res = cgf.emitStmt(body, /*useCurrentScope=*/true);
511 mlir::omp::TerminatorOp::create(builder, end);
512 return res;
513}
514
515mlir::LogicalResult
517 return emitMasterOp(*this, getLoc(s.getBeginLoc()), getLoc(s.getEndLoc()),
518 s.getAssociatedStmt());
519}
520
521/// Find or create the module-level declaration of the critical section \p name.
522/// Returns null, after emitting an error, if the name is already used by
523/// another symbol or the hint cannot be represented.
524static mlir::omp::CriticalDeclareOp
526 llvm::StringRef name, mlir::Location loc) {
527 CIRGenModule &cgm = cgf.getCIRGenModule();
528 mlir::ModuleOp mod = cgm.getModule();
529
530 if (mlir::Operation *sym = mlir::SymbolTable::lookupSymbolIn(mod, name)) {
531 if (auto declareOp = mlir::dyn_cast<mlir::omp::CriticalDeclareOp>(sym))
532 return declareOp;
533 cgm.errorNYI(s.getBeginLoc(),
534 "OpenMP critical name that clashes with another symbol");
535 return nullptr;
536 }
537
538 mlir::omp::CriticalDeclareOperands clauseOps;
539 clauseOps.symName = mlir::StringAttr::get(&cgf.getMLIRContext(), name);
540 if (const auto *hint = s.getSingleClause<OMPHintClause>()) {
541 uint64_t value =
542 hint->getHint()->EvaluateKnownConstInt(cgf.getContext()).getZExtValue();
543 // Sema accepts hints that combine uncontended (1) with contended (2), or
544 // nonspeculative (4) with speculative (8), but the omp dialect rejects
545 // them. OpenMP 5.0 [2.17.12] forbids these combinations, so Sema should
546 // diagnose them; once it does, this check can become an assertion.
547 if ((value & 0x3) == 0x3 || (value & 0xC) == 0xC) {
548 cgm.errorNYI(hint->getBeginLoc(),
549 "OpenMP critical 'hint' combining conflicting sync hints");
550 return nullptr;
551 }
552 clauseOps.hint = mlir::IntegerAttr::get(
553 mlir::IntegerType::get(&cgf.getMLIRContext(), 64), value);
554 }
555
556 mlir::OpBuilder modBuilder(mod.getBodyRegion());
557 return mlir::omp::CriticalDeclareOp::create(modBuilder, loc, clauseOps);
558}
559
560mlir::LogicalResult
562 mlir::Location begin = getLoc(s.getBeginLoc());
563 mlir::Location end = getLoc(s.getEndLoc());
564
565 omp::ConstructQueue queue =
567 omp::ConstructQueue::const_iterator item = queue.begin();
568
569 if (mlir::failed(checkSynthesizedClauses(*this, s, item)))
570 return mlir::failure();
571
572 OpenMPClauseEmitter ce(*this, getCIRGenModule(), builder, begin,
573 item->clauses);
574 // The hint is consumed when the named critical section is declared.
575 if (mlir::failed(ce.emitNYI</*supported=*/OMPHintClause>(
576 /*nyi=*/OpenMPNYIClauseList<>{},
577 llvm::omp::Directive::OMPD_critical)))
578 return mlir::failure();
579
580 mlir::FlatSymbolRefAttr nameAttr;
581 std::string name = s.getDirectiveName().getAsString();
582 if (!name.empty()) {
583 if (!getOrCreateCriticalDeclare(*this, s, name, begin))
584 return mlir::failure();
585 nameAttr = mlir::FlatSymbolRefAttr::get(&getMLIRContext(), name);
586 }
587
588 auto criticalOp = mlir::omp::CriticalOp::create(builder, begin, nameAttr);
589 mlir::Block &block = criticalOp.getRegion().emplaceBlock();
590 mlir::OpBuilder::InsertionGuard guard(builder);
591 builder.setInsertionPointToEnd(&block);
592
593 CIRGenFunction::LexicalScope ls{*this, begin, builder.getInsertionBlock()};
594
595 mlir::LogicalResult res =
596 emitStmt(s.getAssociatedStmt(), /*useCurrentScope=*/true);
597 mlir::omp::TerminatorOp::create(builder, end);
598 return res;
599}
600mlir::LogicalResult
602 mlir::Location begin = getLoc(s.getBeginLoc());
603 mlir::Location end = getLoc(s.getEndLoc());
604
605 omp::ConstructQueue queue =
607 omp::ConstructQueue::const_iterator parallelItem = queue.begin();
608 assert(parallelItem->id == llvm::omp::OMPD_parallel &&
609 "expected 'parallel' to be the outermost directive");
610
611 return emitParallel(
612 *this, s, queue, parallelItem, begin, end, [&]() -> mlir::LogicalResult {
613 omp::ConstructQueue::const_iterator forItem = std::next(parallelItem);
614 assert(forItem != queue.end() && forItem->id == llvm::omp::OMPD_for &&
615 "expected a 'for' directive nested in 'parallel'");
616 return emitOMPWorksharingLoop(*this, s, forItem);
617 });
618}
621 getCIRGenModule().errorNYI(s.getSourceRange(),
622 "OpenMP OMPParallelForSimdDirective");
623 return mlir::failure();
624}
627 mlir::Location begin = getLoc(s.getBeginLoc());
628 mlir::Location end = getLoc(s.getEndLoc());
629
630 omp::ConstructQueue queue =
632 omp::ConstructQueue::const_iterator parallelItem = queue.begin();
633 assert(parallelItem != queue.end() &&
634 parallelItem->id == llvm::omp::OMPD_parallel &&
635 "expected 'parallel' to be the outermost leaf");
636
637 [[maybe_unused]] omp::ConstructQueue::const_iterator masterItem =
638 std::next(parallelItem);
639 assert(masterItem != queue.end() &&
640 masterItem->id == llvm::omp::OMPD_master &&
641 omp::isLastItemInQueue(masterItem, queue) &&
642 "expected 'master' to be the innermost leaf");
643
644 if (mlir::failed(checkSynthesizedClauses(*this, s, parallelItem)))
645 return mlir::failure();
646
647 mlir::omp::ParallelOperands clauseOps;
648 if (mlir::failed(emitParallelClauses(*this, getCIRGenModule(), builder, begin,
649 parallelItem->clauses, clauseOps)))
650 return mlir::failure();
651
652 return emitParallelOp(
653 *this, s, queue, parallelItem, begin, end, clauseOps,
654 [&]() -> mlir::LogicalResult {
655 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_parallel);
656 return emitMasterOp(*this, begin, end, cs->getCapturedStmt());
657 });
658}
661 getCIRGenModule().errorNYI(s.getSourceRange(),
662 "OpenMP OMPParallelSectionsDirective");
663 return mlir::failure();
664}
665mlir::LogicalResult
667 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskDirective");
668 return mlir::failure();
669}
670mlir::LogicalResult
672 getCIRGenModule().errorNYI(s.getSourceRange(),
673 "OpenMP OMPTaskgroupDirective");
674 return mlir::failure();
675}
676mlir::LogicalResult
678 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFlushDirective");
679 return mlir::failure();
680}
681mlir::LogicalResult
683 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPDepobjDirective");
684 return mlir::failure();
685}
686mlir::LogicalResult
688 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPScanDirective");
689 return mlir::failure();
690}
693 getCIRGenModule().errorNYI(s.getSourceRange(),
694 "OpenMP OMPOrderedStandaloneDirective");
695 return mlir::failure();
696}
699 getCIRGenModule().errorNYI(s.getSourceRange(),
700 "OpenMP OMPOrderedBlockAssocDirective");
701 return mlir::failure();
702}
703mlir::LogicalResult
705 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPAtomicDirective");
706 return mlir::failure();
707}
708
709/// Check for unsupported implicit captures in a target region.
710static mlir::LogicalResult
712 const OMPExecutableDirective &s,
714 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
715 mlir::LogicalResult res = mlir::success();
716 for (const auto &capture : cs->captures()) {
717 if (capture.capturesThis()) {
718 cgf.getCIRGenModule().errorNYI(s.getBeginLoc(),
719 "OpenMP target capture of 'this' pointer");
720 res = mlir::failure();
721 continue;
722 }
723 if (capture.capturesVariableByCopy()) {
724 cgf.getCIRGenModule().errorNYI(s.getBeginLoc(),
725 "OpenMP target capture by copy");
726 res = mlir::failure();
727 continue;
728 }
729 if (capture.capturesVariableArrayType()) {
731 s.getBeginLoc(),
732 "OpenMP target capture of variable-length array type");
733 res = mlir::failure();
734 continue;
735 }
736 if (capture.capturesVariable()) {
737 const VarDecl *vd = capture.getCapturedVar();
738 if (llvm::is_contained(mapSyms, vd))
739 continue;
740
741 cgf.getCIRGenModule().errorNYI(s.getBeginLoc(),
742 "OpenMP target implicit by-ref capture");
743 res = mlir::failure();
744 }
745 }
746 return res;
747}
748
749static mlir::LogicalResult
751 CIRGenBuilderTy &builder, mlir::Location loc,
753 mlir::omp::TargetExtOperands &clauseOps,
755 OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses);
756 ce.emitMap(clauseOps, &mapSyms);
757 return ce.emitNYI</*supported=*/OMPMapClause>(
758 /*nyi=*/OpenMPNYIClauseList<
760 OMPDependClause, OMPDeviceClause, OMPFirstprivateClause,
761 OMPHasDeviceAddrClause, OMPIfClause, OMPInReductionClause,
762 OMPIsDevicePtrClause, OMPNowaitClause, OMPPrivateClause,
764 llvm::omp::Directive::OMPD_target);
765}
766
767template <typename DirectiveTy>
768static mlir::LogicalResult
769emitTargetOp(CIRGenFunction &cgf, const DirectiveTy &s,
770 const omp::ConstructQueue &queue,
771 omp::ConstructQueue::const_iterator item, mlir::Location begin,
772 mlir::Location end, mlir::omp::TargetExtOperands &clauseOps,
774 llvm::function_ref<mlir::LogicalResult()> emitBody) {
775 CIRGenBuilderTy &builder = cgf.getBuilder();
776
777 if (mlir::failed(emitOMPTargetImplicitCaptures(cgf, s, mapSyms)))
778 return mlir::failure();
779
780 // Use generic for now.
781 clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get(
782 &cgf.getMLIRContext(), mlir::omp::TargetExecMode::generic);
783
784 auto targetOp = mlir::omp::TargetOp::create(builder, begin, clauseOps);
785 if (!omp::isLastItemInQueue(item, queue))
786 targetOp.setCombined(true);
787
788 mlir::Block &block = targetOp.getRegion().emplaceBlock();
789 for (mlir::Value mapVar : clauseOps.mapVars)
790 block.addArgument(mapVar.getType(), begin);
791
793 for (auto [idx, vd] : llvm::enumerate(mapSyms)) {
794 Address origAddr = cgf.getAddrOfLocalVar(vd);
795 savedAddrs.push_back({vd, origAddr});
796 mlir::Value blockArg = block.getArgument(idx);
797 cgf.replaceAddrOfLocalVar(vd, Address(blockArg, origAddr.getAlignment()));
798 }
799
800 mlir::LogicalResult res = emitOMPRegionBody<mlir::omp::TerminatorOp>(
801 cgf, block, begin, end, emitBody);
802
803 for (auto &[vd, addr] : savedAddrs)
804 cgf.replaceAddrOfLocalVar(vd, addr);
805
806 return res;
807}
808
809/// Checks, emits clauses for, and emits an omp.target for the `target`
810/// directive at \p targetItem, deferring to \p emitBody for the region's
811/// contents.
812template <typename DirectiveTy>
813static mlir::LogicalResult emitTarget(
814 CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue,
815 omp::ConstructQueue::const_iterator targetItem, mlir::Location begin,
816 mlir::Location end, llvm::function_ref<mlir::LogicalResult()> emitBody) {
817 if (mlir::failed(checkSynthesizedClauses(cgf, s, targetItem)))
818 return mlir::failure();
819
820 mlir::omp::TargetExtOperands targetOps;
822 if (mlir::failed(emitTargetClauses(cgf, cgf.getCIRGenModule(),
823 cgf.getBuilder(), begin,
824 targetItem->clauses, targetOps, mapSyms)))
825 return mlir::failure();
826
827 return emitTargetOp(cgf, s, queue, targetItem, begin, end, targetOps, mapSyms,
828 emitBody);
829}
830
831mlir::LogicalResult
833 mlir::Location begin = getLoc(s.getBeginLoc());
834 mlir::Location end = getLoc(s.getEndLoc());
835
836 omp::ConstructQueue queue =
838 omp::ConstructQueue::const_iterator item = queue.begin();
839
840 return emitTarget(
841 *this, s, queue, item, begin, end, [&]() -> mlir::LogicalResult {
842 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
843 return emitStmt(cs->getCapturedStmt(),
844 /*useCurrentScope=*/true);
845 });
846}
847mlir::LogicalResult
849 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTeamsDirective");
850 return mlir::failure();
851}
854 getCIRGenModule().errorNYI(s.getSourceRange(),
855 "OpenMP OMPCancellationPointDirective");
856 return mlir::failure();
857}
858mlir::LogicalResult
860 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCancelDirective");
861 return mlir::failure();
862}
863mlir::LogicalResult
865 getCIRGenModule().errorNYI(s.getSourceRange(),
866 "OpenMP OMPTargetDataDirective");
867 return mlir::failure();
868}
871 getCIRGenModule().errorNYI(s.getSourceRange(),
872 "OpenMP OMPTargetEnterDataDirective");
873 return mlir::failure();
874}
877 getCIRGenModule().errorNYI(s.getSourceRange(),
878 "OpenMP OMPTargetExitDataDirective");
879 return mlir::failure();
880}
883 mlir::Location begin = getLoc(s.getBeginLoc());
884 mlir::Location end = getLoc(s.getEndLoc());
885
886 omp::ConstructQueue queue =
888 omp::ConstructQueue::const_iterator targetItem = queue.begin();
889 assert(targetItem->id == llvm::omp::OMPD_target &&
890 "expected 'target' to be the outermost directive");
891
892 return emitTarget(
893 *this, s, queue, targetItem, begin, end, [&]() -> mlir::LogicalResult {
894 omp::ConstructQueue::const_iterator parallelItem =
895 std::next(targetItem);
896 assert(parallelItem != queue.end() &&
897 parallelItem->id == llvm::omp::OMPD_parallel &&
898 "expected a 'parallel' directive nested in 'target'");
899
900 return emitParallel(*this, s, queue, parallelItem, begin, end,
901 [&]() -> mlir::LogicalResult {
902 const CapturedStmt *cs =
903 s.getCapturedStmt(llvm::omp::OMPD_parallel);
904 return emitStmt(cs->getCapturedStmt(),
905 /*useCurrentScope=*/true);
906 });
907 });
908}
911 mlir::Location begin = getLoc(s.getBeginLoc());
912 mlir::Location end = getLoc(s.getEndLoc());
913
914 omp::ConstructQueue queue =
916 omp::ConstructQueue::const_iterator targetItem = queue.begin();
917 assert(targetItem->id == llvm::omp::OMPD_target &&
918 "expected 'target' to be the outermost directive");
919
920 return emitTarget(
921 *this, s, queue, targetItem, begin, end, [&]() -> mlir::LogicalResult {
922 omp::ConstructQueue::const_iterator parallelItem =
923 std::next(targetItem);
924 assert(parallelItem != queue.end() &&
925 parallelItem->id == llvm::omp::OMPD_parallel &&
926 "expected a 'parallel' directive nested in 'target'");
927
928 return emitParallel(
929 *this, s, queue, parallelItem, begin, end,
930 [&]() -> mlir::LogicalResult {
931 omp::ConstructQueue::const_iterator forItem =
932 std::next(parallelItem);
933 assert(forItem != queue.end() &&
934 forItem->id == llvm::omp::OMPD_for &&
935 "expected a 'for' directive nested in 'parallel'");
936 return emitOMPWorksharingLoop(*this, s, forItem);
937 });
938 });
939}
940mlir::LogicalResult
942 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPTaskLoopDirective");
943 return mlir::failure();
944}
946 const OMPTaskLoopSimdDirective &s) {
947 getCIRGenModule().errorNYI(s.getSourceRange(),
948 "OpenMP OMPTaskLoopSimdDirective");
949 return mlir::failure();
950}
953 getCIRGenModule().errorNYI(s.getSourceRange(),
954 "OpenMP OMPMaskedTaskLoopDirective");
955 return mlir::failure();
956}
959 getCIRGenModule().errorNYI(s.getSourceRange(),
960 "OpenMP OMPMaskedTaskLoopSimdDirective");
961 return mlir::failure();
962}
965 getCIRGenModule().errorNYI(s.getSourceRange(),
966 "OpenMP OMPMasterTaskLoopDirective");
967 return mlir::failure();
968}
971 getCIRGenModule().errorNYI(s.getSourceRange(),
972 "OpenMP OMPMasterTaskLoopSimdDirective");
973 return mlir::failure();
974}
977 getCIRGenModule().errorNYI(s.getSourceRange(),
978 "OpenMP OMPParallelGenericLoopDirective");
979 return mlir::failure();
980}
983 getCIRGenModule().errorNYI(s.getSourceRange(),
984 "OpenMP OMPParallelMaskedDirective");
985 return mlir::failure();
986}
989 getCIRGenModule().errorNYI(s.getSourceRange(),
990 "OpenMP OMPParallelMaskedTaskLoopDirective");
991 return mlir::failure();
992}
995 getCIRGenModule().errorNYI(s.getSourceRange(),
996 "OpenMP OMPParallelMaskedTaskLoopSimdDirective");
997 return mlir::failure();
998}
1001 getCIRGenModule().errorNYI(s.getSourceRange(),
1002 "OpenMP OMPParallelMasterTaskLoopDirective");
1003 return mlir::failure();
1004}
1007 getCIRGenModule().errorNYI(s.getSourceRange(),
1008 "OpenMP OMPParallelMasterTaskLoopSimdDirective");
1009 return mlir::failure();
1010}
1011mlir::LogicalResult
1013 getCIRGenModule().errorNYI(s.getSourceRange(),
1014 "OpenMP OMPDistributeDirective");
1015 return mlir::failure();
1016}
1019 getCIRGenModule().errorNYI(s.getSourceRange(),
1020 "OpenMP OMPDistributeParallelForDirective");
1021 return mlir::failure();
1022}
1025 getCIRGenModule().errorNYI(s.getSourceRange(),
1026 "OpenMP OMPDistributeParallelForSimdDirective");
1027 return mlir::failure();
1028}
1030 const OMPDistributeSimdDirective &s) {
1031 getCIRGenModule().errorNYI(s.getSourceRange(),
1032 "OpenMP OMPDistributeSimdDirective");
1033 return mlir::failure();
1034}
1037 getCIRGenModule().errorNYI(s.getSourceRange(),
1038 "OpenMP OMPTargetParallelGenericLoopDirective");
1039 return mlir::failure();
1040}
1043 cgm.errorNYI(s.getSourceRange(), "OpenMP OMPTargetGenericLoopDirective");
1044 return mlir::failure();
1045}
1048 getCIRGenModule().errorNYI(s.getSourceRange(),
1049 "OpenMP OMPTargetParallelForSimdDirective");
1050 return mlir::failure();
1051}
1052mlir::LogicalResult
1054 getCIRGenModule().errorNYI(s.getSourceRange(),
1055 "OpenMP OMPTargetSimdDirective");
1056 return mlir::failure();
1057}
1060 getCIRGenModule().errorNYI(s.getSourceRange(),
1061 "OpenMP OMPTargetTeamsGenericLoopDirective");
1062 return mlir::failure();
1063}
1065 const OMPTargetUpdateDirective &s) {
1066 getCIRGenModule().errorNYI(s.getSourceRange(),
1067 "OpenMP OMPTargetUpdateDirective");
1068 return mlir::failure();
1069}
1071 const OMPTeamsDistributeDirective &s) {
1072 getCIRGenModule().errorNYI(s.getSourceRange(),
1073 "OpenMP OMPTeamsDistributeDirective");
1074 return mlir::failure();
1075}
1078 getCIRGenModule().errorNYI(s.getSourceRange(),
1079 "OpenMP OMPTeamsDistributeSimdDirective");
1080 return mlir::failure();
1081}
1082mlir::LogicalResult
1086 s.getSourceRange(), "OpenMP OMPTeamsDistributeParallelForSimdDirective");
1087 return mlir::failure();
1088}
1091 getCIRGenModule().errorNYI(s.getSourceRange(),
1092 "OpenMP OMPTeamsDistributeParallelForDirective");
1093 return mlir::failure();
1094}
1097 getCIRGenModule().errorNYI(s.getSourceRange(),
1098 "OpenMP OMPTeamsGenericLoopDirective");
1099 return mlir::failure();
1100}
1101mlir::LogicalResult
1103 getCIRGenModule().errorNYI(s.getSourceRange(),
1104 "OpenMP OMPTargetTeamsDirective");
1105 return mlir::failure();
1106}
1109 getCIRGenModule().errorNYI(s.getSourceRange(),
1110 "OpenMP OMPTargetTeamsDistributeDirective");
1111 return mlir::failure();
1112}
1113mlir::LogicalResult
1117 s.getSourceRange(),
1118 "OpenMP OMPTargetTeamsDistributeParallelForDirective");
1119 return mlir::failure();
1120}
1121mlir::LogicalResult
1125 s.getSourceRange(),
1126 "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective");
1127 return mlir::failure();
1128}
1131 getCIRGenModule().errorNYI(s.getSourceRange(),
1132 "OpenMP OMPTargetTeamsDistributeSimdDirective");
1133 return mlir::failure();
1134}
1135mlir::LogicalResult
1137 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPInteropDirective");
1138 return mlir::failure();
1139}
1140mlir::LogicalResult
1142 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPDispatchDirective");
1143 return mlir::failure();
1144}
1145mlir::LogicalResult
1147 getCIRGenModule().errorNYI(s.getSourceRange(),
1148 "OpenMP OMPGenericLoopDirective");
1149 return mlir::failure();
1150}
1151mlir::LogicalResult
1153 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPReverseDirective");
1154 return mlir::failure();
1155}
1156mlir::LogicalResult
1158 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSplitDirective");
1159 return mlir::failure();
1160}
1161mlir::LogicalResult
1163 getCIRGenModule().errorNYI(s.getSourceRange(),
1164 "OpenMP OMPInterchangeDirective");
1165 return mlir::failure();
1166}
1167mlir::LogicalResult
1169 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPFlattenDirective");
1170 return mlir::failure();
1171}
1172mlir::LogicalResult
1174 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPAssumeDirective");
1175 return mlir::failure();
1176}
1177mlir::LogicalResult
1179 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMaskedDirective");
1180 return mlir::failure();
1181}
1182mlir::LogicalResult
1184 getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPStripeDirective");
1185 return mlir::failure();
1186}
static void emitBody(CodeGenFunction &CGF, const Stmt *S, const Stmt *NextLoop, int MaxLevel, int Level=0)
static mlir::LogicalResult emitOMPRegionBody(CIRGenFunction &cgf, mlir::Block &block, mlir::Location begin, mlir::Location end, llvm::function_ref< mlir::LogicalResult()> emitBody)
Emits the contents of an OpenMP region op's block in a new lexical scope and terminates the block wit...
static mlir::LogicalResult emitOMPTargetImplicitCaptures(CIRGenFunction &cgf, const OMPExecutableDirective &s, llvm::ArrayRef< const VarDecl * > mapSyms)
Check for unsupported implicit captures in a target region.
static mlir::LogicalResult emitWsloopClauses(CIRGenFunction &cgf, CIRGenModule &cgm, CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< const OMPClause * > clauses, mlir::omp::WsloopOperands &clauseOps)
Evaluates the clauses allowed on the for directive; none are supported yet, so every eligible clause ...
static mlir::LogicalResult checkSynthesizedClauses(CIRGenFunction &cgf, const OMPExecutableDirective &s, omp::ConstructQueue::const_iterator item)
Report item's synthesized clauses as not-yet-implemented: having no AST node, they cannot go through ...
static mlir::LogicalResult emitLoopPreInits(CIRGenFunction &cgf, const Stmt *preInits)
Emits the Sema-generated pre-init statements for an OpenMP loop directive.
static mlir::LogicalResult emitTargetOp(CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, omp::ConstructQueue::const_iterator item, mlir::Location begin, mlir::Location end, mlir::omp::TargetExtOperands &clauseOps, llvm::ArrayRef< const VarDecl * > mapSyms, llvm::function_ref< mlir::LogicalResult()> emitBody)
static const ContinueStmt * findLoopBodyContinue(const Stmt *s)
Returns the first continue in s that is not nested in an inner loop, i.e.
static mlir::LogicalResult emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s, omp::ConstructQueue::const_iterator item)
Lowers an OMPLoopDirective's for directive to an omp.wsloop + omp.loop_nest.
static mlir::LogicalResult emitParallelOp(CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, omp::ConstructQueue::const_iterator item, mlir::Location begin, mlir::Location end, const mlir::omp::ParallelOperands &clauseOps, llvm::function_ref< mlir::LogicalResult()> emitBody)
static mlir::omp::CriticalDeclareOp getOrCreateCriticalDeclare(CIRGenFunction &cgf, const OMPCriticalDirective &s, llvm::StringRef name, mlir::Location loc)
Find or create the module-level declaration of the critical section name.
static mlir::LogicalResult emitOMPLoopNest(CIRGenFunction &cgf, const ForStmt &forStmt, mlir::Value lb, mlir::Value ub, mlir::Value step, const VarDecl *ivDecl, const Expr *update)
Emits an omp.loop_nest that iterates a normalized [0, tripCount) range and recomputes the real induct...
static mlir::Value emitLoopTripCount(CIRGenFunction &cgf, const OMPLoopDirective &s)
Emits the trip count of the loop associated with s: Sema's iteration count if the loop's precondition...
static Address emitLoopPrivateCounter(CIRGenFunction &cgf, CIRGenModule &cgm, mlir::Location loc, const VarDecl *privateVd, mlir::omp::PrivateClauseOps &clauseOps)
Registers a loop counter as predetermined-private on the associated loop wrapper op.
static mlir::LogicalResult emitParallelClauses(CIRGenFunction &cgf, CIRGenModule &cgm, CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< const OMPClause * > clauses, mlir::omp::ParallelOperands &clauseOps)
static mlir::LogicalResult emitParallel(CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, omp::ConstructQueue::const_iterator parallelItem, mlir::Location begin, mlir::Location end, llvm::function_ref< mlir::LogicalResult()> emitBody)
Checks, emits clauses for, and emits an omp.parallel for the parallel directive at parallelItem,...
static mlir::LogicalResult emitTarget(CIRGenFunction &cgf, const DirectiveTy &s, const omp::ConstructQueue &queue, omp::ConstructQueue::const_iterator targetItem, mlir::Location begin, mlir::Location end, llvm::function_ref< mlir::LogicalResult()> emitBody)
Checks, emits clauses for, and emits an omp.target for the target directive at targetItem,...
static mlir::LogicalResult emitTargetClauses(CIRGenFunction &cgf, CIRGenModule &cgm, CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< const OMPClause * > clauses, mlir::omp::TargetExtOperands &clauseOps, llvm::SmallVectorImpl< const VarDecl * > &mapSyms)
static mlir::LogicalResult emitMasterOp(CIRGenFunction &cgf, mlir::Location begin, mlir::Location end, const Stmt *body)
static mlir::LogicalResult emitLoopPreInit(CIRGenFunction &cgf, const Stmt *preInit)
Emits a single Sema-generated pre-init statement for an OpenMP loop directive: a VarDecl's DeclStmt i...
static mlir::omp::PrivateClauseOp emitScalarPrivatizer(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef baseName, mlir::Type elemTy)
Creates a module-level omp.private op (a "privatizer") for a scalar of CIR type elemTy.
This file defines OpenMP AST classes for clauses.
This file defines OpenMP AST classes for executable directives and clauses.
This represents 'pragma omp atomic' directive.
This represents 'pragma omp barrier' directive.
This represents 'pragma omp cancel' directive.
This represents 'pragma omp cancellation point' directive.
This represents clause 'copyin' in the 'pragma omp ...' directives.
This represents 'pragma omp critical' directive.
DeclarationNameInfo getDirectiveName() const
Return name of the directive.
This represents 'defaultmap' clause in the 'pragma omp ...' directive.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
This represents 'pragma omp depobj' directive.
This represents 'device' clause in the 'pragma omp ...' directive.
This represents 'pragma omp dispatch' directive.
This represents 'pragma omp distribute' directive.
This represents 'pragma omp distribute parallel for' composite directive.
This represents 'pragma omp distribute parallel for simd' composite directive.
This represents 'pragma omp distribute simd' composite directive.
This represents 'pragma omp error' directive.
Represents the 'pragma omp flatten' loop transformation directive.
This represents 'pragma omp flush' directive.
This represents 'pragma omp for' directive.
This represents 'pragma omp for simd' directive.
Represents the 'pragma omp fuse' loop transformation directive.
This represents 'pragma omp loop' directive.
This represents clause 'has_device_ptr' in the 'pragma omp ...' directives.
This represents 'hint' clause in the 'pragma omp ...' directive.
Represents the 'pragma omp interchange' loop transformation directive.
This represents 'pragma omp interop' directive.
This represents clause 'is_device_ptr' in the 'pragma omp ...' directives.
This is a common base class for loop directives ('omp simd', 'omp for', 'omp for simd' etc....
Expr * getPreCond() const
ArrayRef< Expr * > counters()
ArrayRef< Expr * > private_counters()
ArrayRef< Expr * > updates()
const Stmt * getPreInits() const
Expr * getIterationVariable() const
Expr * getNumIterations() const
This represents clause 'map' in the 'pragma omp ...' directives.
This represents 'pragma omp masked' directive.
This represents 'pragma omp masked taskloop' directive.
This represents 'pragma omp masked taskloop simd' directive.
This represents 'pragma omp master' directive.
This represents 'pragma omp master taskloop' directive.
This represents 'pragma omp master taskloop simd' directive.
This represents 'pragma omp metadirective' directive.
This represents 'order' clause in the 'pragma omp ...' directive.
This represents block-associated 'pragma omp ordered' directive.
This represents standalone 'pragma omp ordered' directive.
This represents 'pragma omp parallel for' directive.
This represents 'pragma omp parallel for simd' directive.
This represents 'pragma omp parallel loop' directive.
This represents 'pragma omp parallel masked' directive.
This represents 'pragma omp parallel masked taskloop' directive.
This represents 'pragma omp parallel masked taskloop simd' directive.
This represents 'pragma omp parallel master' directive.
This represents 'pragma omp parallel master taskloop' directive.
This represents 'pragma omp parallel master taskloop simd' directive.
This represents 'pragma omp parallel sections' directive.
Represents the 'pragma omp reverse' loop transformation directive.
This represents 'pragma omp scan' directive.
This represents 'pragma omp scope' directive.
This represents 'pragma omp section' directive.
This represents 'pragma omp sections' directive.
This represents 'pragma omp simd' directive.
This represents 'pragma omp single' directive.
Represents the 'pragma omp split' loop transformation directive.
This represents the 'pragma omp stripe' loop transformation directive.
This represents 'pragma omp target data' directive.
This represents 'pragma omp target' directive.
This represents 'pragma omp target enter data' directive.
This represents 'pragma omp target exit data' directive.
This represents 'pragma omp target loop' directive.
This represents 'pragma omp target parallel' directive.
This represents 'pragma omp target parallel for' directive.
This represents 'pragma omp target parallel for simd' directive.
This represents 'pragma omp target parallel loop' directive.
This represents 'pragma omp target simd' directive.
This represents 'pragma omp target teams' directive.
This represents 'pragma omp target teams distribute' combined directive.
This represents 'pragma omp target teams distribute parallel for' combined directive.
This represents 'pragma omp target teams distribute parallel for simd' combined directive.
This represents 'pragma omp target teams distribute simd' combined directive.
This represents 'pragma omp target teams loop' directive.
This represents 'pragma omp target update' directive.
This represents 'pragma omp task' directive.
This represents 'pragma omp taskloop' directive.
This represents 'pragma omp taskloop simd' directive.
This represents 'pragma omp taskgroup' directive.
This represents 'pragma omp taskwait' directive.
This represents 'pragma omp taskyield' directive.
This represents 'pragma omp teams' directive.
This represents 'pragma omp teams distribute' directive.
This represents 'pragma omp teams distribute parallel for' composite directive.
This represents 'pragma omp teams distribute parallel for simd' composite directive.
This represents 'pragma omp teams distribute simd' combined directive.
This represents 'pragma omp teams loop' directive.
This represents 'thread_limit' clause in the 'pragma omp ...' directive.
This represents the 'pragma omp tile' loop transformation directive.
This represents the 'pragma omp unroll' loop transformation directive.
This represents clause 'uses_allocators' in the 'pragma omp target'-based directives.
This represents 'ompx_bare' clause in the 'pragma omp target teams ...' directive.
mlir::Value createBuiltinIntCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
mlir::Value createSelect(mlir::Location loc, mlir::Value condition, mlir::Value trueValue, mlir::Value falseValue)
mlir::Value getPointer() const
Definition Address.h:98
mlir::Type getElementType() const
Definition Address.h:125
clang::CharUnits getAlignment() const
Definition Address.h:138
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
void forceCleanup(ArrayRef< mlir::Value * > valuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
mlir::LogicalResult emitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &s)
mlir::LogicalResult emitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPSimdDirective(const OMPSimdDirective &s)
mlir::LogicalResult emitOMPCriticalDirective(const OMPCriticalDirective &s)
mlir::LogicalResult emitOMPParallelMasterDirective(const OMPParallelMasterDirective &s)
mlir::LogicalResult emitOMPCancellationPointDirective(const OMPCancellationPointDirective &s)
mlir::LogicalResult emitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective &s)
mlir::LogicalResult emitOMPReverseDirective(const OMPReverseDirective &s)
const clang::LangOptions & getLangOpts() const
mlir::LogicalResult emitOMPTileDirective(const OMPTileDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDirective(const OMPTargetTeamsDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPBarrierDirective(const OMPBarrierDirective &s)
mlir::LogicalResult emitOMPTargetParallelDirective(const OMPTargetParallelDirective &s)
void replaceAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
mlir::LogicalResult emitOMPTargetDirective(const OMPTargetDirective &s)
void emitOMPNoLifetimeVarDecl(const VarDecl &d)
Emits a Sema-synthesized OpenMP helper variable (loop counter, iteration variable or pre-init capture...
mlir::Value evaluateExprAsBool(const clang::Expr *e)
Perform the usual unary conversions on the specified expression and compare the result against zero,...
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
mlir::LogicalResult emitOMPScopeDirective(const OMPScopeDirective &s)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::LogicalResult emitOMPDepobjDirective(const OMPDepobjDirective &s)
mlir::LogicalResult emitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPUnrollDirective(const OMPUnrollDirective &s)
mlir::LogicalResult emitOMPTaskDirective(const OMPTaskDirective &s)
mlir::LogicalResult emitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective &s)
mlir::LogicalResult emitOMPCanonicalLoop(const OMPCanonicalLoop &s)
mlir::LogicalResult emitOMPTeamsDirective(const OMPTeamsDirective &s)
mlir::LogicalResult emitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective &s)
mlir::LogicalResult emitOMPFuseDirective(const OMPFuseDirective &s)
mlir::LogicalResult emitOMPSectionDirective(const OMPSectionDirective &s)
mlir::LogicalResult emitOMPFlattenDirective(const OMPFlattenDirective &s)
mlir::LogicalResult emitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &s)
mlir::LogicalResult emitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPOrderedStandaloneDirective(const OMPOrderedStandaloneDirective &s)
mlir::LogicalResult emitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPTaskwaitDirective(const OMPTaskwaitDirective &s)
mlir::LogicalResult emitOMPFlushDirective(const OMPFlushDirective &s)
mlir::LogicalResult emitOMPGenericLoopDirective(const OMPGenericLoopDirective &s)
mlir::LogicalResult emitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &s)
mlir::LogicalResult emitOMPTargetGenericLoopDirective(const OMPTargetGenericLoopDirective &s)
mlir::LogicalResult emitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective &s)
mlir::LogicalResult emitOMPInterchangeDirective(const OMPInterchangeDirective &s)
mlir::LogicalResult emitOMPDispatchDirective(const OMPDispatchDirective &s)
mlir::LogicalResult emitOMPParallelDirective(const OMPParallelDirective &s)
mlir::LogicalResult emitOMPForSimdDirective(const OMPForSimdDirective &s)
mlir::LogicalResult emitOMPTaskLoopDirective(const OMPTaskLoopDirective &s)
void emitVarDecl(const clang::VarDecl &d)
This method handles emission of any variable declaration inside a function, including static vars etc...
mlir::LogicalResult emitOMPTargetDataDirective(const OMPTargetDataDirective &s)
mlir::LogicalResult emitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective &s)
mlir::LogicalResult emitOMPParallelMaskedDirective(const OMPParallelMaskedDirective &s)
mlir::LogicalResult emitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPAtomicDirective(const OMPAtomicDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPTaskgroupDirective(const OMPTaskgroupDirective &s)
mlir::LogicalResult emitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &s)
mlir::LogicalResult emitOMPInteropDirective(const OMPInteropDirective &s)
mlir::LogicalResult emitOMPErrorDirective(const OMPErrorDirective &s)
mlir::LogicalResult emitOMPSingleDirective(const OMPSingleDirective &s)
mlir::LogicalResult emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective &s)
mlir::LogicalResult emitOMPScanDirective(const OMPScanDirective &s)
mlir::LogicalResult emitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &s)
mlir::LogicalResult emitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective &s)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
mlir::LogicalResult emitOMPForDirective(const OMPForDirective &s)
mlir::LogicalResult emitOMPMasterDirective(const OMPMasterDirective &s)
mlir::LogicalResult emitOMPMetaDirective(const OMPMetaDirective &s)
mlir::LogicalResult emitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &s)
CIRGenBuilderTy & getBuilder()
mlir::LogicalResult emitOMPParallelGenericLoopDirective(const OMPParallelGenericLoopDirective &s)
mlir::LogicalResult emitOMPMaskedDirective(const OMPMaskedDirective &s)
mlir::LogicalResult emitOMPSplitDirective(const OMPSplitDirective &s)
mlir::MLIRContext & getMLIRContext()
mlir::LogicalResult emitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &s)
mlir::LogicalResult emitOMPOrderedBlockAssocDirective(const OMPOrderedBlockAssocDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective &s)
mlir::LogicalResult emitOMPParallelForDirective(const OMPParallelForDirective &s)
mlir::LogicalResult emitOMPSectionsDirective(const OMPSectionsDirective &s)
mlir::LogicalResult emitOMPDistributeDirective(const OMPDistributeDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective &s)
mlir::LogicalResult emitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective &s)
mlir::LogicalResult emitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective &s)
mlir::LogicalResult emitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &s)
clang::ASTContext & getContext() const
mlir::LogicalResult emitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective &s)
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
mlir::LogicalResult emitOMPCancelDirective(const OMPCancelDirective &s)
mlir::LogicalResult emitOMPStripeDirective(const OMPStripeDirective &s)
mlir::LogicalResult emitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective &s)
mlir::LogicalResult emitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &s)
mlir::LogicalResult emitOMPTargetSimdDirective(const OMPTargetSimdDirective &s)
mlir::LogicalResult emitOMPAssumeDirective(const OMPAssumeDirective &s)
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void insertGlobalSymbol(mlir::Operation *op)
mlir::Operation * getGlobalValue(llvm::StringRef ref)
mlir::ModuleOp getModule() const
Emits OpenMP clauses for a directive, writing results into the auto-generated ClauseOps from the OMP ...
mlir::LogicalResult emitNYI(OpenMPNYIClauseList< NYIClauses... > nyi, llvm::omp::Directive directive) const
Verify the clauses of a directive to make sure all legal cases are either implemented or give a NYI e...
bool emitMap(mlir::omp::MapClauseOps &result, llvm::SmallVectorImpl< const VarDecl * > *mapSyms=nullptr) const
Emit map clauses.
bool emitIf(mlir::omp::IfClauseOps &result, llvm::omp::Directive directiveName) const
bool emitProcBind(mlir::omp::ProcBindClauseOps &result) const
bool emitNumThreads(mlir::omp::NumThreadsClauseOps &result) const
This captures a statement into a function.
Definition Stmt.h:3950
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4054
capture_range captures()
Definition Stmt.h:4088
ContinueStmt - This represents a continue.
Definition Stmt.h:3132
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:114
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2899
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:303
This represents clause 'allocate' in the 'pragma omp ...' directives.
This represents 'collapse' clause in the 'pragma omp ...' directive.
This represents 'default' clause in the 'pragma omp ...' directive.
This represents 'if' clause in the 'pragma omp ...' directive.
This represents 'num_threads' clause in the 'pragma omp ...' directive.
Stmt - This represents one statement.
Definition Stmt.h:85
child_range children()
Definition Stmt.cpp:304
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
Represents a variable declaration or definition.
Definition Decl.h:934
bool isLastItemInQueue(ConstructQueue::const_iterator item, const ConstructQueue &queue)
llvm::SmallVector< LeafWithClauses > ConstructQueue
ConstructQueue buildConstructQueue(unsigned openmpVersion, const OMPExecutableDirective &s)
Given a potentially compound directive with a list of clauses that apply to it, break it up into indi...
const internal::VariadicDynCastAllOfMatcher< Stmt, ForStmt > forStmt
Matches for statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclStmt > declStmt
Matches declaration statements.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, ContinueStmt > continueStmt
Matches continue statements.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
U cast(CodeGen::Address addr)
Definition Address.h:327
float __ovld __cnfn step(float, float)
Returns 0.0 if x < edge, otherwise it returns 1.0.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
A type-only list of OpenMP clause AST node types.
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.