@@ -27,41 +27,68 @@ class OpenACCClauseCIREmitter final
2727 : public OpenACCClauseVisitor<OpenACCClauseCIREmitter> {
2828 CIRGenModule &cgm;
2929
30+ struct AttributeData {
31+ // Value of the 'default' attribute, added on 'data' and 'compute'/etc
32+ // constructs as a 'default-attr'.
33+ std::optional<ClauseDefaultValue> defaultVal = std::nullopt ;
34+ } attrData;
35+
3036 void clauseNotImplemented (const OpenACCClause &c) {
3137 cgm.errorNYI (c.getSourceRange (), " OpenACC Clause" , c.getClauseKind ());
3238 }
3339
3440public:
3541 OpenACCClauseCIREmitter (CIRGenModule &cgm) : cgm(cgm) {}
3642
37- #define VISIT_CLAUSE (CN ) \
38- void Visit##CN##Clause(const OpenACC##CN##Clause &clause) { \
39- clauseNotImplemented (clause); \
43+ void VisitClause (const OpenACCClause &clause) {
44+ clauseNotImplemented (clause);
45+ }
46+
47+ void VisitDefaultClause (const OpenACCDefaultClause &clause) {
48+ switch (clause.getDefaultClauseKind ()) {
49+ case OpenACCDefaultClauseKind::None:
50+ attrData.defaultVal = ClauseDefaultValue::None;
51+ break ;
52+ case OpenACCDefaultClauseKind::Present:
53+ attrData.defaultVal = ClauseDefaultValue::Present;
54+ break ;
55+ case OpenACCDefaultClauseKind::Invalid:
56+ break ;
57+ }
58+ }
59+
60+ // Apply any of the clauses that resulted in an 'attribute'.
61+ template <typename Op> void applyAttributes (Op &op) {
62+ if (attrData.defaultVal .has_value ())
63+ op.setDefaultAttr (*attrData.defaultVal );
4064 }
41- #include " clang/Basic/OpenACCClauses.def"
4265};
4366} // namespace
4467
4568template <typename Op, typename TermOp>
46- mlir::LogicalResult CIRGenFunction::emitOpenACCComputeOp (
69+ mlir::LogicalResult CIRGenFunction::emitOpenACCOpAssociatedStmt (
4770 mlir::Location start, mlir::Location end,
48- llvm::ArrayRef<const OpenACCClause *> clauses,
49- const Stmt *structuredBlock) {
71+ llvm::ArrayRef<const OpenACCClause *> clauses, const Stmt *associatedStmt) {
5072 mlir::LogicalResult res = mlir::success ();
5173
74+ llvm::SmallVector<mlir::Type> retTy;
75+ llvm::SmallVector<mlir::Value> operands;
76+
77+ // Clause-emitter must be here because it might modify operands.
5278 OpenACCClauseCIREmitter clauseEmitter (getCIRGenModule ());
5379 clauseEmitter.VisitClauseList (clauses);
5480
55- llvm::SmallVector<mlir::Type> retTy;
56- llvm::SmallVector<mlir::Value> operands;
5781 auto op = builder.create <Op>(start, retTy, operands);
5882
83+ // Apply the attributes derived from the clauses.
84+ clauseEmitter.applyAttributes (op);
85+
5986 mlir::Block &block = op.getRegion ().emplaceBlock ();
6087 mlir::OpBuilder::InsertionGuard guardCase (builder);
6188 builder.setInsertionPointToEnd (&block);
6289
6390 LexicalScope ls{*this , start, builder.getInsertionBlock ()};
64- res = emitStmt (structuredBlock , /* useCurrentScope=*/ true );
91+ res = emitStmt (associatedStmt , /* useCurrentScope=*/ true );
6592
6693 builder.create <TermOp>(end);
6794 return res;
@@ -74,19 +101,28 @@ CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
74101
75102 switch (s.getDirectiveKind ()) {
76103 case OpenACCDirectiveKind::Parallel:
77- return emitOpenACCComputeOp <ParallelOp, mlir::acc::YieldOp>(
104+ return emitOpenACCOpAssociatedStmt <ParallelOp, mlir::acc::YieldOp>(
78105 start, end, s.clauses (), s.getStructuredBlock ());
79106 case OpenACCDirectiveKind::Serial:
80- return emitOpenACCComputeOp <SerialOp, mlir::acc::YieldOp>(
107+ return emitOpenACCOpAssociatedStmt <SerialOp, mlir::acc::YieldOp>(
81108 start, end, s.clauses (), s.getStructuredBlock ());
82109 case OpenACCDirectiveKind::Kernels:
83- return emitOpenACCComputeOp <KernelsOp, mlir::acc::TerminatorOp>(
110+ return emitOpenACCOpAssociatedStmt <KernelsOp, mlir::acc::TerminatorOp>(
84111 start, end, s.clauses (), s.getStructuredBlock ());
85112 default :
86113 llvm_unreachable (" invalid compute construct kind" );
87114 }
88115}
89116
117+ mlir::LogicalResult
118+ CIRGenFunction::emitOpenACCDataConstruct (const OpenACCDataConstruct &s) {
119+ mlir::Location start = getLoc (s.getSourceRange ().getEnd ());
120+ mlir::Location end = getLoc (s.getSourceRange ().getEnd ());
121+
122+ return emitOpenACCOpAssociatedStmt<DataOp, mlir::acc::TerminatorOp>(
123+ start, end, s.clauses (), s.getStructuredBlock ());
124+ }
125+
90126mlir::LogicalResult
91127CIRGenFunction::emitOpenACCLoopConstruct (const OpenACCLoopConstruct &s) {
92128 getCIRGenModule ().errorNYI (s.getSourceRange (), " OpenACC Loop Construct" );
@@ -97,11 +133,6 @@ mlir::LogicalResult CIRGenFunction::emitOpenACCCombinedConstruct(
97133 getCIRGenModule ().errorNYI (s.getSourceRange (), " OpenACC Combined Construct" );
98134 return mlir::failure ();
99135}
100- mlir::LogicalResult
101- CIRGenFunction::emitOpenACCDataConstruct (const OpenACCDataConstruct &s) {
102- getCIRGenModule ().errorNYI (s.getSourceRange (), " OpenACC Data Construct" );
103- return mlir::failure ();
104- }
105136mlir::LogicalResult CIRGenFunction::emitOpenACCEnterDataConstruct (
106137 const OpenACCEnterDataConstruct &s) {
107138 getCIRGenModule ().errorNYI (s.getSourceRange (), " OpenACC EnterData Construct" );
0 commit comments