@@ -97,11 +97,17 @@ class OpenACCClauseCIREmitter final
9797
9898 // Handle a clause affected by the 'device-type' to the point that they need
9999 // to have the attributes added in the correct/corresponding order, such as
100- // 'num_workers' or 'vector_length' on a compute construct.
101- mlir::ArrayAttr
102- handleDeviceTypeAffectedClause (mlir::ArrayAttr existingDeviceTypes,
103- mlir::Value argument,
104- mlir::MutableOperandRange &argCollection) {
100+ // 'num_workers' or 'vector_length' on a compute construct. For cases where we
101+ // don't have an expression 'argument' that needs to be added to an operand
102+ // and only care about the 'device-type' list, we can use this with 'argument'
103+ // as 'std::nullopt'. If 'argument' is NOT 'std::nullopt' (that is, has a
104+ // value), argCollection must also be non-null. For cases where we don't have
105+ // an argument that needs to be added to an additional one (such as asyncOnly)
106+ // we can use this with 'argument' as std::nullopt.
107+ mlir::ArrayAttr handleDeviceTypeAffectedClause (
108+ mlir::ArrayAttr existingDeviceTypes,
109+ std::optional<mlir::Value> argument = std::nullopt ,
110+ mlir::MutableOperandRange *argCollection = nullptr ) {
105111 llvm::SmallVector<mlir::Attribute> deviceTypes;
106112
107113 // Collect the 'existing' device-type attributes so we can re-create them
@@ -120,13 +126,19 @@ class OpenACCClauseCIREmitter final
120126 lastDeviceTypeClause->getArchitectures ()) {
121127 deviceTypes.push_back (mlir::acc::DeviceTypeAttr::get (
122128 builder.getContext (), decodeDeviceType (arch.getIdentifierInfo ())));
123- argCollection.append (argument);
129+ if (argument) {
130+ assert (argCollection);
131+ argCollection->append (*argument);
132+ }
124133 }
125134 } else {
126135 // Else, we just add a single for 'none'.
127136 deviceTypes.push_back (mlir::acc::DeviceTypeAttr::get (
128137 builder.getContext (), mlir::acc::DeviceType::None));
129- argCollection.append (argument);
138+ if (argument) {
139+ assert (argCollection);
140+ argCollection->append (*argument);
141+ }
130142 }
131143
132144 return mlir::ArrayAttr::get (builder.getContext (), deviceTypes);
@@ -205,7 +217,7 @@ class OpenACCClauseCIREmitter final
205217 mlir::MutableOperandRange range = operation.getNumWorkersMutable ();
206218 operation.setNumWorkersDeviceTypeAttr (handleDeviceTypeAffectedClause (
207219 operation.getNumWorkersDeviceTypeAttr (),
208- createIntExpr (clause.getIntExpr ()), range));
220+ createIntExpr (clause.getIntExpr ()), & range));
209221 } else if constexpr (isOneOfTypes<OpTy, SerialOp>) {
210222 llvm_unreachable (" num_workers not valid on serial" );
211223 } else {
@@ -218,14 +230,30 @@ class OpenACCClauseCIREmitter final
218230 mlir::MutableOperandRange range = operation.getVectorLengthMutable ();
219231 operation.setVectorLengthDeviceTypeAttr (handleDeviceTypeAffectedClause (
220232 operation.getVectorLengthDeviceTypeAttr (),
221- createIntExpr (clause.getIntExpr ()), range));
233+ createIntExpr (clause.getIntExpr ()), & range));
222234 } else if constexpr (isOneOfTypes<OpTy, SerialOp>) {
223235 llvm_unreachable (" vector_length not valid on serial" );
224236 } else {
225237 return clauseNotImplemented (clause);
226238 }
227239 }
228240
241+ void VisitAsyncClause (const OpenACCAsyncClause &clause) {
242+ if constexpr (isOneOfTypes<OpTy, ParallelOp, SerialOp, KernelsOp>) {
243+ if (!clause.hasIntExpr ()) {
244+ operation.setAsyncOnlyAttr (
245+ handleDeviceTypeAffectedClause (operation.getAsyncOnlyAttr ()));
246+ } else {
247+ mlir::MutableOperandRange range = operation.getAsyncOperandsMutable ();
248+ operation.setAsyncOperandsDeviceTypeAttr (handleDeviceTypeAffectedClause (
249+ operation.getAsyncOperandsDeviceTypeAttr (),
250+ createIntExpr (clause.getIntExpr ()), &range));
251+ }
252+ } else {
253+ return clauseNotImplemented (clause);
254+ }
255+ }
256+
229257 void VisitSelfClause (const OpenACCSelfClause &clause) {
230258 if constexpr (isOneOfTypes<OpTy, ParallelOp, SerialOp, KernelsOp>) {
231259 if (clause.isEmptySelfClause ()) {
0 commit comments