16#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
19#include "llvm/Frontend/OpenMP/OMPConstants.h"
26 return mlir::failure();
31 return mlir::failure();
35 mlir::LogicalResult res = mlir::success();
36 mlir::Location begin =
getLoc(s.getBeginLoc());
37 mlir::Location end =
getLoc(s.getEndLoc());
39 mlir::omp::ParallelOperands clauseOps;
41 ce.
emitIf(clauseOps, llvm::omp::Directive::OMPD_parallel);
47 OMPReductionClause, OMPSharedClause>{},
48 llvm::omp::Directive::OMPD_parallel);
50 auto parallelOp = mlir::omp::ParallelOp::create(builder, begin, clauseOps);
53 mlir::Block &block = parallelOp.getRegion().emplaceBlock();
54 mlir::OpBuilder::InsertionGuard guardCase(builder);
55 builder.setInsertionPointToEnd(&block);
57 LexicalScope ls{*
this, begin, builder.getInsertionBlock()};
61 "OpenMP Parallel with Cancel");
62 if (s.getTaskReductionRefExpr())
64 "OpenMP Parallel with Task Reduction");
72 mlir::omp::TerminatorOp::create(builder, end);
80 return mlir::failure();
85 "OpenMP OMPTaskyieldDirective");
86 return mlir::failure();
90 mlir::omp::BarrierOp::create(builder,
getLoc(s.getBeginLoc()));
91 assert(s.clauses().empty() &&
"omp barrier doesn't support clauses");
92 return mlir::success();
97 return mlir::failure();
102 return mlir::failure();
107 return mlir::failure();
112 return mlir::failure();
117 return mlir::failure();
122 return mlir::failure();
127 return mlir::failure();
132 return mlir::failure();
137 return mlir::failure();
142 return mlir::failure();
147 return mlir::failure();
152 return mlir::failure();
157 return mlir::failure();
162 "OpenMP OMPParallelForDirective");
163 return mlir::failure();
168 "OpenMP OMPParallelForSimdDirective");
169 return mlir::failure();
174 "OpenMP OMPParallelMasterDirective");
175 return mlir::failure();
180 "OpenMP OMPParallelSectionsDirective");
181 return mlir::failure();
186 return mlir::failure();
191 "OpenMP OMPTaskgroupDirective");
192 return mlir::failure();
197 return mlir::failure();
202 return mlir::failure();
207 return mlir::failure();
212 "OpenMP OMPOrderedStandaloneDirective");
213 return mlir::failure();
218 "OpenMP OMPOrderedBlockAssocDirective");
219 return mlir::failure();
224 return mlir::failure();
231 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
232 for (
const auto &capture : cs->
captures()) {
233 if (capture.capturesThis()) {
235 "OpenMP target capture of 'this' pointer");
238 if (capture.capturesVariableByCopy()) {
240 "OpenMP target capture by copy");
243 if (capture.capturesVariableArrayType()) {
246 "OpenMP target capture of variable-length array type");
249 if (capture.capturesVariable()) {
250 const VarDecl *vd = capture.getCapturedVar();
251 if (llvm::is_contained(mapSyms, vd))
255 "OpenMP target implicit by-ref capture");
262static mlir::LogicalResult
264 mlir::omp::TargetOp targetOp,
267 mlir::Location begin, mlir::Location end) {
268 mlir::Block &block = targetOp.getRegion().emplaceBlock();
270 for (mlir::Value mapVar : mapVars)
271 block.addArgument(mapVar.getType(), begin);
273 mlir::OpBuilder::InsertionGuard guard(cgf.
getBuilder());
274 cgf.
getBuilder().setInsertionPointToEnd(&block);
280 for (
auto [idx, vd] : llvm::enumerate(mappedVarDecls)) {
282 savedAddrs.push_back({vd, origAddr});
283 mlir::Value blockArg = block.getArgument(idx);
287 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
288 mlir::LogicalResult res =
291 mlir::omp::TerminatorOp::create(cgf.
getBuilder(), end);
293 for (
auto &[vd, addr] : savedAddrs)
301 mlir::Location begin =
getLoc(s.getBeginLoc());
302 mlir::Location end =
getLoc(s.getEndLoc());
304 mlir::omp::TargetExtOperands clauseOps;
308 ce.
emitMap(clauseOps, &mapSyms);
316 llvm::omp::Directive::OMPD_target);
321 clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get(
324 auto targetOp = mlir::omp::TargetOp::create(builder, begin, clauseOps);
332 return mlir::failure();
337 "OpenMP OMPCancellationPointDirective");
338 return mlir::failure();
343 return mlir::failure();
348 "OpenMP OMPTargetDataDirective");
349 return mlir::failure();
354 "OpenMP OMPTargetEnterDataDirective");
355 return mlir::failure();
360 "OpenMP OMPTargetExitDataDirective");
361 return mlir::failure();
366 "OpenMP OMPTargetParallelDirective");
367 return mlir::failure();
372 "OpenMP OMPTargetParallelForDirective");
373 return mlir::failure();
378 return mlir::failure();
383 "OpenMP OMPTaskLoopSimdDirective");
384 return mlir::failure();
389 "OpenMP OMPMaskedTaskLoopDirective");
390 return mlir::failure();
395 "OpenMP OMPMaskedTaskLoopSimdDirective");
396 return mlir::failure();
401 "OpenMP OMPMasterTaskLoopDirective");
402 return mlir::failure();
407 "OpenMP OMPMasterTaskLoopSimdDirective");
408 return mlir::failure();
413 "OpenMP OMPParallelGenericLoopDirective");
414 return mlir::failure();
419 "OpenMP OMPParallelMaskedDirective");
420 return mlir::failure();
425 "OpenMP OMPParallelMaskedTaskLoopDirective");
426 return mlir::failure();
431 "OpenMP OMPParallelMaskedTaskLoopSimdDirective");
432 return mlir::failure();
437 "OpenMP OMPParallelMasterTaskLoopDirective");
438 return mlir::failure();
443 "OpenMP OMPParallelMasterTaskLoopSimdDirective");
444 return mlir::failure();
449 "OpenMP OMPDistributeDirective");
450 return mlir::failure();
455 "OpenMP OMPDistributeParallelForDirective");
456 return mlir::failure();
461 "OpenMP OMPDistributeParallelForSimdDirective");
462 return mlir::failure();
467 "OpenMP OMPDistributeSimdDirective");
468 return mlir::failure();
473 "OpenMP OMPTargetParallelGenericLoopDirective");
474 return mlir::failure();
479 "OpenMP OMPTargetParallelForSimdDirective");
480 return mlir::failure();
485 "OpenMP OMPTargetSimdDirective");
486 return mlir::failure();
491 "OpenMP OMPTargetTeamsGenericLoopDirective");
492 return mlir::failure();
497 "OpenMP OMPTargetUpdateDirective");
498 return mlir::failure();
503 "OpenMP OMPTeamsDistributeDirective");
504 return mlir::failure();
509 "OpenMP OMPTeamsDistributeSimdDirective");
510 return mlir::failure();
516 s.getSourceRange(),
"OpenMP OMPTeamsDistributeParallelForSimdDirective");
517 return mlir::failure();
522 "OpenMP OMPTeamsDistributeParallelForDirective");
523 return mlir::failure();
528 "OpenMP OMPTeamsGenericLoopDirective");
529 return mlir::failure();
534 "OpenMP OMPTargetTeamsDirective");
535 return mlir::failure();
540 "OpenMP OMPTargetTeamsDistributeDirective");
541 return mlir::failure();
548 "OpenMP OMPTargetTeamsDistributeParallelForDirective");
549 return mlir::failure();
556 "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective");
557 return mlir::failure();
562 "OpenMP OMPTargetTeamsDistributeSimdDirective");
563 return mlir::failure();
568 return mlir::failure();
573 return mlir::failure();
578 "OpenMP OMPGenericLoopDirective");
579 return mlir::failure();
584 return mlir::failure();
589 return mlir::failure();
594 "OpenMP OMPInterchangeDirective");
595 return mlir::failure();
600 return mlir::failure();
605 return mlir::failure();
610 return mlir::failure();
615 return mlir::failure();
static mlir::LogicalResult emitOMPTargetBody(CIRGenFunction &cgf, const OMPTargetDirective &s, mlir::omp::TargetOp targetOp, llvm::ArrayRef< mlir::Value > mapVars, llvm::ArrayRef< const VarDecl * > mappedVarDecls, mlir::Location begin, mlir::Location end)
Emit the body of an omp.target region, remapping mapped variables to the block arguments of the targe...
static void emitOMPTargetImplicitCaptures(CIRGenFunction &cgf, const OMPTargetDirective &s, llvm::ArrayRef< const VarDecl * > mapSyms)
Check for unsupported implicit captures in a target region.
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.
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.
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 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 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 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.
clang::CharUnits getAlignment() const
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)
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)
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 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)
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::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)
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)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
Emits OpenMP clauses for a directive, writing results into the auto-generated ClauseOps from the OMP ...
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
void 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 emitProcBind(mlir::omp::ProcBindClauseOps &result) const
This captures a statement into a function.
Stmt * getCapturedStmt()
Retrieve the statement being captured.
This represents clause 'allocate' in the 'pragma omp ...' directives.
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.
Represents a variable declaration or definition.
Top level wrappers for InstallAPI frontend operations.
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
A type-only list of OpenMP clause AST node types.