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;
46 OMPPrivateClause, OMPReductionClause, OMPSharedClause>{},
47 llvm::omp::Directive::OMPD_parallel);
49 auto parallelOp = mlir::omp::ParallelOp::create(builder, begin, clauseOps);
52 mlir::Block &block = parallelOp.getRegion().emplaceBlock();
53 mlir::OpBuilder::InsertionGuard guardCase(builder);
54 builder.setInsertionPointToEnd(&block);
56 LexicalScope ls{*
this, begin, builder.getInsertionBlock()};
60 "OpenMP Parallel with Cancel");
61 if (s.getTaskReductionRefExpr())
63 "OpenMP Parallel with Task Reduction");
71 mlir::omp::TerminatorOp::create(builder, end);
79 return mlir::failure();
84 "OpenMP OMPTaskyieldDirective");
85 return mlir::failure();
89 mlir::omp::BarrierOp::create(builder,
getLoc(s.getBeginLoc()));
90 assert(s.clauses().empty() &&
"omp barrier doesn't support clauses");
91 return mlir::success();
96 return mlir::failure();
101 return mlir::failure();
106 return mlir::failure();
111 return mlir::failure();
116 return mlir::failure();
121 return mlir::failure();
126 return mlir::failure();
131 return mlir::failure();
136 return mlir::failure();
141 return mlir::failure();
146 return mlir::failure();
151 return mlir::failure();
156 return mlir::failure();
161 "OpenMP OMPParallelForDirective");
162 return mlir::failure();
165 const OMPParallelForSimdDirective &s) {
167 "OpenMP OMPParallelForSimdDirective");
168 return mlir::failure();
171 const OMPParallelMasterDirective &s) {
173 "OpenMP OMPParallelMasterDirective");
174 return mlir::failure();
177 const OMPParallelSectionsDirective &s) {
179 "OpenMP OMPParallelSectionsDirective");
180 return mlir::failure();
185 return mlir::failure();
190 "OpenMP OMPTaskgroupDirective");
191 return mlir::failure();
196 return mlir::failure();
201 return mlir::failure();
206 return mlir::failure();
209 const OMPOrderedStandaloneDirective &s) {
211 "OpenMP OMPOrderedStandaloneDirective");
212 return mlir::failure();
215 const OMPOrderedBlockAssocDirective &s) {
217 "OpenMP OMPOrderedBlockAssocDirective");
218 return mlir::failure();
223 return mlir::failure();
230 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
231 for (
const auto &capture : cs->
captures()) {
232 if (capture.capturesThis()) {
234 "OpenMP target capture of 'this' pointer");
237 if (capture.capturesVariableByCopy()) {
239 "OpenMP target capture by copy");
242 if (capture.capturesVariableArrayType()) {
245 "OpenMP target capture of variable-length array type");
248 if (capture.capturesVariable()) {
249 const VarDecl *vd = capture.getCapturedVar();
250 if (llvm::is_contained(mapSyms, vd))
254 "OpenMP target implicit by-ref capture");
261static mlir::LogicalResult
263 mlir::omp::TargetOp targetOp,
266 mlir::Location begin, mlir::Location end) {
267 mlir::Block &block = targetOp.getRegion().emplaceBlock();
269 for (mlir::Value mapVar : mapVars)
270 block.addArgument(mapVar.getType(), begin);
272 mlir::OpBuilder::InsertionGuard guard(cgf.
getBuilder());
273 cgf.
getBuilder().setInsertionPointToEnd(&block);
279 for (
auto [idx, vd] : llvm::enumerate(mappedVarDecls)) {
281 savedAddrs.push_back({vd, origAddr});
282 mlir::Value blockArg = block.getArgument(idx);
286 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
287 mlir::LogicalResult res =
290 mlir::omp::TerminatorOp::create(cgf.
getBuilder(), end);
292 for (
auto &[vd, addr] : savedAddrs)
300 mlir::Location begin =
getLoc(s.getBeginLoc());
301 mlir::Location end =
getLoc(s.getEndLoc());
303 mlir::omp::TargetExtOperands clauseOps;
307 ce.
emitMap(clauseOps, &mapSyms);
315 llvm::omp::Directive::OMPD_target);
320 clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get(
323 auto targetOp = mlir::omp::TargetOp::create(builder, begin, clauseOps);
331 return mlir::failure();
336 "OpenMP OMPCancellationPointDirective");
337 return mlir::failure();
342 return mlir::failure();
347 "OpenMP OMPTargetDataDirective");
348 return mlir::failure();
353 "OpenMP OMPTargetEnterDataDirective");
354 return mlir::failure();
359 "OpenMP OMPTargetExitDataDirective");
360 return mlir::failure();
365 "OpenMP OMPTargetParallelDirective");
366 return mlir::failure();
371 "OpenMP OMPTargetParallelForDirective");
372 return mlir::failure();
377 return mlir::failure();
382 "OpenMP OMPTaskLoopSimdDirective");
383 return mlir::failure();
388 "OpenMP OMPMaskedTaskLoopDirective");
389 return mlir::failure();
394 "OpenMP OMPMaskedTaskLoopSimdDirective");
395 return mlir::failure();
400 "OpenMP OMPMasterTaskLoopDirective");
401 return mlir::failure();
406 "OpenMP OMPMasterTaskLoopSimdDirective");
407 return mlir::failure();
412 "OpenMP OMPParallelGenericLoopDirective");
413 return mlir::failure();
416 const OMPParallelMaskedDirective &s) {
418 "OpenMP OMPParallelMaskedDirective");
419 return mlir::failure();
424 "OpenMP OMPParallelMaskedTaskLoopDirective");
425 return mlir::failure();
430 "OpenMP OMPParallelMaskedTaskLoopSimdDirective");
431 return mlir::failure();
436 "OpenMP OMPParallelMasterTaskLoopDirective");
437 return mlir::failure();
442 "OpenMP OMPParallelMasterTaskLoopSimdDirective");
443 return mlir::failure();
448 "OpenMP OMPDistributeDirective");
449 return mlir::failure();
454 "OpenMP OMPDistributeParallelForDirective");
455 return mlir::failure();
460 "OpenMP OMPDistributeParallelForSimdDirective");
461 return mlir::failure();
466 "OpenMP OMPDistributeSimdDirective");
467 return mlir::failure();
472 "OpenMP OMPTargetParallelGenericLoopDirective");
473 return mlir::failure();
478 "OpenMP OMPTargetParallelForSimdDirective");
479 return mlir::failure();
484 "OpenMP OMPTargetSimdDirective");
485 return mlir::failure();
490 "OpenMP OMPTargetTeamsGenericLoopDirective");
491 return mlir::failure();
496 "OpenMP OMPTargetUpdateDirective");
497 return mlir::failure();
502 "OpenMP OMPTeamsDistributeDirective");
503 return mlir::failure();
508 "OpenMP OMPTeamsDistributeSimdDirective");
509 return mlir::failure();
515 s.getSourceRange(),
"OpenMP OMPTeamsDistributeParallelForSimdDirective");
516 return mlir::failure();
521 "OpenMP OMPTeamsDistributeParallelForDirective");
522 return mlir::failure();
527 "OpenMP OMPTeamsGenericLoopDirective");
528 return mlir::failure();
533 "OpenMP OMPTargetTeamsDirective");
534 return mlir::failure();
539 "OpenMP OMPTargetTeamsDistributeDirective");
540 return mlir::failure();
547 "OpenMP OMPTargetTeamsDistributeParallelForDirective");
548 return mlir::failure();
555 "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective");
556 return mlir::failure();
561 "OpenMP OMPTargetTeamsDistributeSimdDirective");
562 return mlir::failure();
567 return mlir::failure();
572 return mlir::failure();
577 "OpenMP OMPGenericLoopDirective");
578 return mlir::failure();
583 return mlir::failure();
588 return mlir::failure();
593 "OpenMP OMPInterchangeDirective");
594 return mlir::failure();
599 return mlir::failure();
604 return mlir::failure();
609 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 cancel' directive.
This represents 'pragma omp cancellation point' directive.
This represents clause 'copyin' in the 'pragma omp ...' directives.
This represents 'defaultmap' clause in the 'pragma omp ...' directive.
This represents implicit clause 'depend' for the 'pragma omp task' 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 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 taskloop' directive.
This represents 'pragma omp master taskloop simd' directive.
This represents 'pragma omp parallel loop' directive.
This represents 'pragma omp parallel masked taskloop' directive.
This represents 'pragma omp parallel masked taskloop simd' directive.
This represents 'pragma omp parallel master taskloop' directive.
This represents 'pragma omp parallel master taskloop simd' directive.
Represents the 'pragma omp reverse' loop transformation directive.
This represents 'pragma omp scan' 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 taskloop' directive.
This represents 'pragma omp taskloop simd' 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 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.
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.