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"
31 return mlir::failure();
36 return mlir::failure();
41static mlir::LogicalResult
43 omp::ConstructQueue::const_iterator item) {
44 mlir::LogicalResult res = mlir::success();
45 for (llvm::omp::Clause synth : item->synthesized) {
47 (llvm::Twine(
"OpenMP synthesized '") +
48 llvm::omp::getOpenMPClauseName(synth) +
49 "' clause from construct decomposition")
51 res = mlir::failure();
56static mlir::LogicalResult
60 mlir::omp::ParallelOperands &clauseOps) {
62 ce.
emitIf(clauseOps, llvm::omp::Directive::OMPD_parallel);
69 OMPPrivateClause, OMPReductionClause,
71 llvm::omp::Directive::OMPD_parallel);
79template <
typename TermOp>
80static mlir::LogicalResult
83 llvm::function_ref<mlir::LogicalResult()>
emitBody) {
85 mlir::OpBuilder::InsertionGuard guard(builder);
86 builder.setInsertionPointToEnd(&block);
89 mlir::LogicalResult res =
emitBody();
91 TermOp::create(builder, end);
95template <
typename DirectiveTy>
96static mlir::LogicalResult
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) {
109 if constexpr (!std::is_same_v<DirectiveTy, OMPParallelMasterDirective>) {
112 "OpenMP 'cancel' or 'cancellation point' inside a parallel "
114 return mlir::failure();
118 assert(!s.getTaskReductionRefExpr() &&
119 "reduction(task: ...) should already be rejected as NYI");
121 auto parallelOp = mlir::omp::ParallelOp::create(builder, begin, clauseOps);
123 parallelOp.setCombined(
true);
125 mlir::Block &block = parallelOp.getRegion().emplaceBlock();
133template <
typename DirectiveTy>
136 omp::ConstructQueue::const_iterator parallelItem, mlir::Location begin,
137 mlir::Location end, llvm::function_ref<mlir::LogicalResult()>
emitBody) {
139 return mlir::failure();
141 mlir::omp::ParallelOperands parallelOps;
144 parallelItem->clauses, parallelOps)))
145 return mlir::failure();
147 return emitParallelOp(cgf, s, queue, parallelItem, begin, end, parallelOps,
153 mlir::Location begin =
getLoc(s.getBeginLoc());
154 mlir::Location end =
getLoc(s.getEndLoc());
158 omp::ConstructQueue::const_iterator item = queue.begin();
161 *
this, s, queue, item, begin, end, [&]() -> mlir::LogicalResult {
182 const Stmt *preInit) {
183 if (
const auto *
declStmt = dyn_cast<DeclStmt>(preInit)) {
186 return mlir::success();
193 const Stmt *preInits) {
195 return mlir::success();
197 if (
const auto *compound = dyn_cast<CompoundStmt>(preInits)) {
198 for (
const Stmt *
stmt : compound->body())
200 return mlir::failure();
201 return mlir::success();
212 if (
const auto *
continueStmt = dyn_cast<ContinueStmt>(s))
223static mlir::LogicalResult
225 mlir::Value ub, mlir::Value
step,
const VarDecl *ivDecl,
226 const Expr *update) {
230 auto loopNestOp = mlir::omp::LoopNestOp::create(
231 builder, loc, 1, lb, ub,
step,
233 mlir::Block &block = loopNestOp.getRegion().emplaceBlock();
234 block.addArgument(lb.getType(), loc);
238 [&]() -> mlir::LogicalResult {
242 mlir::Value iv = block.getArgument(0);
243 Address ivAddr = cgf.getAddrOfLocalVar(ivDecl);
245 builder.createBuiltinIntCast(loc, iv, ivAddr.getElementType());
246 builder.createStore(loc, civVal, ivAddr);
247 cgf.emitIgnoredExpr(update);
249 if (!forStmt.getBody())
250 return mlir::success();
251 return cgf.emitStmt(forStmt.getBody(), true);
257static mlir::LogicalResult
261 mlir::omp::WsloopOperands &clauseOps) {
266 OMPLastprivateClause, OMPLinearClause, OMPNowaitClause,
268 OMPReductionClause, OMPScheduleClause>{},
269 llvm::omp::Directive::OMPD_for);
276 llvm::StringRef baseName,
280 unsigned uniquingCounter = 0;
282 (baseName +
".privatizer").str(),
283 [&](llvm::StringRef candidate) {
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));
303 mlir::omp::PrivateClauseOps &clauseOps) {
310 clauseOps.privateVars.push_back(moldAddr.
getPointer());
311 clauseOps.privateSyms.push_back(
312 mlir::FlatSymbolRefAttr::get(privatizer.getSymNameAttr()));
324 mlir::Location loc = cgf.
getLoc(s.getBeginLoc());
328 loc, mlir::cast<cir::IntType>(numIterations.getType()), 0);
329 return builder.
createSelect(loc, preCond, numIterations, zero);
334static mlir::LogicalResult
336 omp::ConstructQueue::const_iterator item) {
339 mlir::Location loc = cgf.
getLoc(s.getBeginLoc());
342 return mlir::failure();
344 mlir::omp::WsloopOperands clauseOps;
347 return mlir::failure();
349 const CapturedStmt *capturedStmt = s.getInnermostCapturedStmt();
353 "expected a for or range-based for loop");
355 "range-based for loop in an OpenMP loop directive");
356 return mlir::failure();
364 "continue in an OpenMP loop body");
365 return mlir::failure();
369 return mlir::failure();
380 counterShadows.reserve(s.
counters().size());
381 counterMolds.reserve(s.
counters().size());
382 for (
auto [counter, privateCounter] :
385 const auto *privateVd =
387 counterShadows.emplace_back(cgf, vd);
388 counterMolds.emplace_back(
393 auto cirIntType = mlir::cast<cir::IntType>(tripCountCir.getType());
400 auto wsloopOp = mlir::omp::WsloopOp::create(builder, loc, clauseOps);
401 mlir::Block *innerBlock =
new mlir::Block();
404 for (
auto &counterMold : counterMolds)
405 innerBlock->addArgument(counterMold.second.getPointer().getType(), loc);
406 wsloopOp.getRegion().push_back(innerBlock);
408 mlir::OpBuilder::InsertionGuard guard(builder);
409 builder.setInsertionPointToStart(innerBlock);
412 for (
unsigned idx = 0; idx < counterMolds.size(); ++idx) {
413 const VarDecl *vd = counterMolds[idx].first;
414 Address moldAddr = counterMolds[idx].second;
428 return mlir::failure();
433 "OpenMP OMPTaskyieldDirective");
434 return mlir::failure();
438 mlir::omp::BarrierOp::create(builder,
getLoc(s.getBeginLoc()));
439 assert(s.clauses().empty() &&
"omp barrier doesn't support clauses");
440 return mlir::success();
445 return mlir::failure();
450 return mlir::failure();
455 return mlir::failure();
460 return mlir::failure();
465 return mlir::failure();
470 return mlir::failure();
481 return mlir::failure();
486 return mlir::failure();
491 return mlir::failure();
496 return mlir::failure();
499 mlir::Location begin,
500 mlir::Location end,
const Stmt *body) {
503 auto masterOp = mlir::omp::MasterOp::create(builder, begin);
505 mlir::Block &block = masterOp.getRegion().emplaceBlock();
506 mlir::OpBuilder::InsertionGuard guard(builder);
507 builder.setInsertionPointToEnd(&block);
510 mlir::LogicalResult res = cgf.
emitStmt(body,
true);
511 mlir::omp::TerminatorOp::create(builder, end);
518 s.getAssociatedStmt());
524static mlir::omp::CriticalDeclareOp
526 llvm::StringRef name, mlir::Location loc) {
530 if (mlir::Operation *sym = mlir::SymbolTable::lookupSymbolIn(mod, name)) {
531 if (
auto declareOp = mlir::dyn_cast<mlir::omp::CriticalDeclareOp>(sym))
534 "OpenMP critical name that clashes with another symbol");
538 mlir::omp::CriticalDeclareOperands clauseOps;
539 clauseOps.symName = mlir::StringAttr::get(&cgf.
getMLIRContext(), name);
542 hint->getHint()->EvaluateKnownConstInt(cgf.
getContext()).getZExtValue();
547 if ((value & 0x3) == 0x3 || (value & 0xC) == 0xC) {
549 "OpenMP critical 'hint' combining conflicting sync hints");
552 clauseOps.hint = mlir::IntegerAttr::get(
556 mlir::OpBuilder modBuilder(mod.getBodyRegion());
557 return mlir::omp::CriticalDeclareOp::create(modBuilder, loc, clauseOps);
562 mlir::Location begin =
getLoc(s.getBeginLoc());
563 mlir::Location end =
getLoc(s.getEndLoc());
567 omp::ConstructQueue::const_iterator item = queue.begin();
570 return mlir::failure();
577 llvm::omp::Directive::OMPD_critical)))
578 return mlir::failure();
580 mlir::FlatSymbolRefAttr nameAttr;
584 return mlir::failure();
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);
595 mlir::LogicalResult res =
596 emitStmt(s.getAssociatedStmt(),
true);
597 mlir::omp::TerminatorOp::create(builder, end);
602 mlir::Location begin =
getLoc(s.getBeginLoc());
603 mlir::Location end =
getLoc(s.getEndLoc());
607 omp::ConstructQueue::const_iterator parallelItem = queue.begin();
608 assert(parallelItem->id == llvm::omp::OMPD_parallel &&
609 "expected 'parallel' to be the outermost directive");
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'");
622 "OpenMP OMPParallelForSimdDirective");
623 return mlir::failure();
627 mlir::Location begin =
getLoc(s.getBeginLoc());
628 mlir::Location end =
getLoc(s.getEndLoc());
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");
637 [[maybe_unused]] omp::ConstructQueue::const_iterator masterItem =
638 std::next(parallelItem);
639 assert(masterItem != queue.end() &&
640 masterItem->id == llvm::omp::OMPD_master &&
642 "expected 'master' to be the innermost leaf");
645 return mlir::failure();
647 mlir::omp::ParallelOperands clauseOps;
649 parallelItem->clauses, clauseOps)))
650 return mlir::failure();
653 *
this, s, queue, parallelItem, begin, end, clauseOps,
654 [&]() -> mlir::LogicalResult {
655 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_parallel);
662 "OpenMP OMPParallelSectionsDirective");
663 return mlir::failure();
668 return mlir::failure();
673 "OpenMP OMPTaskgroupDirective");
674 return mlir::failure();
679 return mlir::failure();
684 return mlir::failure();
689 return mlir::failure();
694 "OpenMP OMPOrderedStandaloneDirective");
695 return mlir::failure();
700 "OpenMP OMPOrderedBlockAssocDirective");
701 return mlir::failure();
706 return mlir::failure();
710static mlir::LogicalResult
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()) {
719 "OpenMP target capture of 'this' pointer");
720 res = mlir::failure();
723 if (capture.capturesVariableByCopy()) {
725 "OpenMP target capture by copy");
726 res = mlir::failure();
729 if (capture.capturesVariableArrayType()) {
732 "OpenMP target capture of variable-length array type");
733 res = mlir::failure();
736 if (capture.capturesVariable()) {
737 const VarDecl *vd = capture.getCapturedVar();
738 if (llvm::is_contained(mapSyms, vd))
742 "OpenMP target implicit by-ref capture");
743 res = mlir::failure();
749static mlir::LogicalResult
753 mlir::omp::TargetExtOperands &clauseOps,
756 ce.
emitMap(clauseOps, &mapSyms);
764 llvm::omp::Directive::OMPD_target);
767template <
typename DirectiveTy>
768static mlir::LogicalResult
771 omp::ConstructQueue::const_iterator item, mlir::Location begin,
772 mlir::Location end, mlir::omp::TargetExtOperands &clauseOps,
774 llvm::function_ref<mlir::LogicalResult()>
emitBody) {
778 return mlir::failure();
781 clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get(
784 auto targetOp = mlir::omp::TargetOp::create(builder, begin, clauseOps);
786 targetOp.setCombined(
true);
788 mlir::Block &block = targetOp.getRegion().emplaceBlock();
789 for (mlir::Value mapVar : clauseOps.mapVars)
790 block.addArgument(mapVar.getType(), begin);
793 for (
auto [idx, vd] : llvm::enumerate(mapSyms)) {
795 savedAddrs.push_back({vd, origAddr});
796 mlir::Value blockArg = block.getArgument(idx);
803 for (
auto &[vd, addr] : savedAddrs)
812template <
typename DirectiveTy>
815 omp::ConstructQueue::const_iterator targetItem, mlir::Location begin,
816 mlir::Location end, llvm::function_ref<mlir::LogicalResult()>
emitBody) {
818 return mlir::failure();
820 mlir::omp::TargetExtOperands targetOps;
824 targetItem->clauses, targetOps, mapSyms)))
825 return mlir::failure();
827 return emitTargetOp(cgf, s, queue, targetItem, begin, end, targetOps, mapSyms,
833 mlir::Location begin =
getLoc(s.getBeginLoc());
834 mlir::Location end =
getLoc(s.getEndLoc());
838 omp::ConstructQueue::const_iterator item = queue.begin();
841 *
this, s, queue, item, begin, end, [&]() -> mlir::LogicalResult {
842 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
850 return mlir::failure();
855 "OpenMP OMPCancellationPointDirective");
856 return mlir::failure();
861 return mlir::failure();
866 "OpenMP OMPTargetDataDirective");
867 return mlir::failure();
872 "OpenMP OMPTargetEnterDataDirective");
873 return mlir::failure();
878 "OpenMP OMPTargetExitDataDirective");
879 return mlir::failure();
883 mlir::Location begin =
getLoc(s.getBeginLoc());
884 mlir::Location end =
getLoc(s.getEndLoc());
888 omp::ConstructQueue::const_iterator targetItem = queue.begin();
889 assert(targetItem->id == llvm::omp::OMPD_target &&
890 "expected 'target' to be the outermost directive");
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'");
900 return emitParallel(*
this, s, queue, parallelItem, begin, end,
901 [&]() -> mlir::LogicalResult {
903 s.getCapturedStmt(llvm::omp::OMPD_parallel);
911 mlir::Location begin =
getLoc(s.getBeginLoc());
912 mlir::Location end =
getLoc(s.getEndLoc());
916 omp::ConstructQueue::const_iterator targetItem = queue.begin();
917 assert(targetItem->id == llvm::omp::OMPD_target &&
918 "expected 'target' to be the outermost directive");
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'");
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'");
943 return mlir::failure();
948 "OpenMP OMPTaskLoopSimdDirective");
949 return mlir::failure();
954 "OpenMP OMPMaskedTaskLoopDirective");
955 return mlir::failure();
960 "OpenMP OMPMaskedTaskLoopSimdDirective");
961 return mlir::failure();
966 "OpenMP OMPMasterTaskLoopDirective");
967 return mlir::failure();
972 "OpenMP OMPMasterTaskLoopSimdDirective");
973 return mlir::failure();
978 "OpenMP OMPParallelGenericLoopDirective");
979 return mlir::failure();
984 "OpenMP OMPParallelMaskedDirective");
985 return mlir::failure();
990 "OpenMP OMPParallelMaskedTaskLoopDirective");
991 return mlir::failure();
996 "OpenMP OMPParallelMaskedTaskLoopSimdDirective");
997 return mlir::failure();
1002 "OpenMP OMPParallelMasterTaskLoopDirective");
1003 return mlir::failure();
1008 "OpenMP OMPParallelMasterTaskLoopSimdDirective");
1009 return mlir::failure();
1014 "OpenMP OMPDistributeDirective");
1015 return mlir::failure();
1020 "OpenMP OMPDistributeParallelForDirective");
1021 return mlir::failure();
1026 "OpenMP OMPDistributeParallelForSimdDirective");
1027 return mlir::failure();
1032 "OpenMP OMPDistributeSimdDirective");
1033 return mlir::failure();
1038 "OpenMP OMPTargetParallelGenericLoopDirective");
1039 return mlir::failure();
1043 cgm.errorNYI(s.getSourceRange(),
"OpenMP OMPTargetGenericLoopDirective");
1044 return mlir::failure();
1049 "OpenMP OMPTargetParallelForSimdDirective");
1050 return mlir::failure();
1055 "OpenMP OMPTargetSimdDirective");
1056 return mlir::failure();
1061 "OpenMP OMPTargetTeamsGenericLoopDirective");
1062 return mlir::failure();
1067 "OpenMP OMPTargetUpdateDirective");
1068 return mlir::failure();
1073 "OpenMP OMPTeamsDistributeDirective");
1074 return mlir::failure();
1079 "OpenMP OMPTeamsDistributeSimdDirective");
1080 return mlir::failure();
1086 s.getSourceRange(),
"OpenMP OMPTeamsDistributeParallelForSimdDirective");
1087 return mlir::failure();
1092 "OpenMP OMPTeamsDistributeParallelForDirective");
1093 return mlir::failure();
1098 "OpenMP OMPTeamsGenericLoopDirective");
1099 return mlir::failure();
1104 "OpenMP OMPTargetTeamsDirective");
1105 return mlir::failure();
1110 "OpenMP OMPTargetTeamsDistributeDirective");
1111 return mlir::failure();
1118 "OpenMP OMPTargetTeamsDistributeParallelForDirective");
1119 return mlir::failure();
1126 "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective");
1127 return mlir::failure();
1132 "OpenMP OMPTargetTeamsDistributeSimdDirective");
1133 return mlir::failure();
1138 return mlir::failure();
1143 return mlir::failure();
1148 "OpenMP OMPGenericLoopDirective");
1149 return mlir::failure();
1154 return mlir::failure();
1159 return mlir::failure();
1164 "OpenMP OMPInterchangeDirective");
1165 return mlir::failure();
1170 return mlir::failure();
1175 return mlir::failure();
1180 return mlir::failure();
1185 return mlir::failure();
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 '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
mlir::Type getElementType() const
clang::CharUnits getAlignment() const
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)
CIRGenModule & getCIRGenModule()
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.
Stmt * getCapturedStmt()
Retrieve the statement being captured.
ContinueStmt - This represents a continue.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
ForStmt - This represents a 'for (init;cond;inc)' stmt.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
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.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Represents a variable declaration or definition.
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)
U cast(CodeGen::Address addr)
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.