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();
211 return mlir::failure();
216 return mlir::failure();
223 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
224 for (
const auto &capture : cs->
captures()) {
225 if (capture.capturesThis()) {
227 "OpenMP target capture of 'this' pointer");
230 if (capture.capturesVariableByCopy()) {
232 "OpenMP target capture by copy");
235 if (capture.capturesVariableArrayType()) {
238 "OpenMP target capture of variable-length array type");
241 if (capture.capturesVariable()) {
242 const VarDecl *vd = capture.getCapturedVar();
243 if (llvm::is_contained(mapSyms, vd))
247 "OpenMP target implicit by-ref capture");
254static mlir::LogicalResult
256 mlir::omp::TargetOp targetOp,
259 mlir::Location begin, mlir::Location end) {
260 mlir::Block &block = targetOp.getRegion().emplaceBlock();
262 for (mlir::Value mapVar : mapVars)
263 block.addArgument(mapVar.getType(), begin);
265 mlir::OpBuilder::InsertionGuard guard(cgf.
getBuilder());
266 cgf.
getBuilder().setInsertionPointToEnd(&block);
272 for (
auto [idx, vd] : llvm::enumerate(mappedVarDecls)) {
274 savedAddrs.push_back({vd, origAddr});
275 mlir::Value blockArg = block.getArgument(idx);
279 const CapturedStmt *cs = s.getCapturedStmt(llvm::omp::OMPD_target);
280 mlir::LogicalResult res =
283 mlir::omp::TerminatorOp::create(cgf.
getBuilder(), end);
285 for (
auto &[vd, addr] : savedAddrs)
293 mlir::Location begin =
getLoc(s.getBeginLoc());
294 mlir::Location end =
getLoc(s.getEndLoc());
296 mlir::omp::TargetExtOperands clauseOps;
300 ce.
emitMap(clauseOps, &mapSyms);
308 llvm::omp::Directive::OMPD_target);
313 clauseOps.kernelType = mlir::omp::TargetExecModeAttr::get(
316 auto targetOp = mlir::omp::TargetOp::create(builder, begin, clauseOps);
324 return mlir::failure();
329 "OpenMP OMPCancellationPointDirective");
330 return mlir::failure();
335 return mlir::failure();
340 "OpenMP OMPTargetDataDirective");
341 return mlir::failure();
346 "OpenMP OMPTargetEnterDataDirective");
347 return mlir::failure();
352 "OpenMP OMPTargetExitDataDirective");
353 return mlir::failure();
358 "OpenMP OMPTargetParallelDirective");
359 return mlir::failure();
364 "OpenMP OMPTargetParallelForDirective");
365 return mlir::failure();
370 return mlir::failure();
375 "OpenMP OMPTaskLoopSimdDirective");
376 return mlir::failure();
381 "OpenMP OMPMaskedTaskLoopDirective");
382 return mlir::failure();
387 "OpenMP OMPMaskedTaskLoopSimdDirective");
388 return mlir::failure();
393 "OpenMP OMPMasterTaskLoopDirective");
394 return mlir::failure();
399 "OpenMP OMPMasterTaskLoopSimdDirective");
400 return mlir::failure();
405 "OpenMP OMPParallelGenericLoopDirective");
406 return mlir::failure();
409 const OMPParallelMaskedDirective &s) {
411 "OpenMP OMPParallelMaskedDirective");
412 return mlir::failure();
417 "OpenMP OMPParallelMaskedTaskLoopDirective");
418 return mlir::failure();
423 "OpenMP OMPParallelMaskedTaskLoopSimdDirective");
424 return mlir::failure();
429 "OpenMP OMPParallelMasterTaskLoopDirective");
430 return mlir::failure();
435 "OpenMP OMPParallelMasterTaskLoopSimdDirective");
436 return mlir::failure();
441 "OpenMP OMPDistributeDirective");
442 return mlir::failure();
447 "OpenMP OMPDistributeParallelForDirective");
448 return mlir::failure();
453 "OpenMP OMPDistributeParallelForSimdDirective");
454 return mlir::failure();
459 "OpenMP OMPDistributeSimdDirective");
460 return mlir::failure();
465 "OpenMP OMPTargetParallelGenericLoopDirective");
466 return mlir::failure();
471 "OpenMP OMPTargetParallelForSimdDirective");
472 return mlir::failure();
477 "OpenMP OMPTargetSimdDirective");
478 return mlir::failure();
483 "OpenMP OMPTargetTeamsGenericLoopDirective");
484 return mlir::failure();
489 "OpenMP OMPTargetUpdateDirective");
490 return mlir::failure();
495 "OpenMP OMPTeamsDistributeDirective");
496 return mlir::failure();
501 "OpenMP OMPTeamsDistributeSimdDirective");
502 return mlir::failure();
508 s.getSourceRange(),
"OpenMP OMPTeamsDistributeParallelForSimdDirective");
509 return mlir::failure();
514 "OpenMP OMPTeamsDistributeParallelForDirective");
515 return mlir::failure();
520 "OpenMP OMPTeamsGenericLoopDirective");
521 return mlir::failure();
526 "OpenMP OMPTargetTeamsDirective");
527 return mlir::failure();
532 "OpenMP OMPTargetTeamsDistributeDirective");
533 return mlir::failure();
540 "OpenMP OMPTargetTeamsDistributeParallelForDirective");
541 return mlir::failure();
548 "OpenMP OMPTargetTeamsDistributeParallelForSimdDirective");
549 return mlir::failure();
554 "OpenMP OMPTargetTeamsDistributeSimdDirective");
555 return mlir::failure();
560 return mlir::failure();
565 return mlir::failure();
570 "OpenMP OMPGenericLoopDirective");
571 return mlir::failure();
576 return mlir::failure();
581 return mlir::failure();
586 "OpenMP OMPInterchangeDirective");
587 return mlir::failure();
592 return mlir::failure();
597 return mlir::failure();
602 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 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 emitOMPOrderedDirective(const OMPOrderedDirective &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 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.
The JSON file list parser is used to communicate input to InstallAPI.
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
A type-only list of OpenMP clause AST node types.