diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -1353,10 +1353,15 @@ Fortran::semantics::SemanticsContext &semanticsContext, Fortran::lower::StatementContext &stmtCtx, const Fortran::parser::AccClauseList &accClauseList) { - mlir::Value ifCond; + mlir::Value ifCond, async; llvm::SmallVector attachEntryOperands, createEntryOperands, copyEntryOperands, copyoutEntryOperands, dataClauseOperands; + // Async has an optional value but can be present with + // no value as well. When there is no value, the op has an attribute to + // represent the clause. + bool addAsyncAttr = false; + fir::FirOpBuilder &builder = converter.getFirOpBuilder(); // Lower clauses values mapped to operands. @@ -1444,11 +1449,14 @@ llvm::SmallVector operands; llvm::SmallVector operandSegments; addOperand(operands, operandSegments, ifCond); + addOperand(operands, operandSegments, async); addOperands(operands, operandSegments, dataClauseOperands); auto dataOp = createRegionOp( builder, currentLocation, operands, operandSegments); + dataOp.setAsyncAttr(addAsyncAttr); + auto insPt = builder.saveInsertionPoint(); builder.setInsertionPointAfter(dataOp); diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td --- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td @@ -865,6 +865,8 @@ let arguments = (ins Optional:$ifCond, + Optional:$async, + UnitAttr:$asyncAttr, Variadic:$dataClauseOperands, OptionalAttr:$defaultAttr); @@ -881,6 +883,7 @@ let assemblyFormat = [{ oilist( `if` `(` $ifCond `)` + | `async` `(` $async `:` type($async) `)` | `dataOperands` `(` $dataClauseOperands `:` type($dataClauseOperands) `)` ) $region attr-dict-with-keyword diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -867,6 +867,7 @@ Value DataOp::getDataOperand(unsigned i) { unsigned numOptional = getIfCond() ? 1 : 0; + numOptional += getAsync() ? 1 : 0; return getOperand(numOptional + i); } diff --git a/mlir/test/Dialect/OpenACC/ops.mlir b/mlir/test/Dialect/OpenACC/ops.mlir --- a/mlir/test/Dialect/OpenACC/ops.mlir +++ b/mlir/test/Dialect/OpenACC/ops.mlir @@ -814,6 +814,14 @@ acc.data { } attributes { defaultAttr = #acc } + + acc.data { + } attributes { defaultAttr = #acc, async } + + %a1 = arith.constant 1 : i64 + acc.data async(%a1 : i64) { + } attributes { defaultAttr = #acc, async } + return } @@ -913,6 +921,12 @@ // CHECK: acc.data { // CHECK-NEXT: } attributes {defaultAttr = #acc} +// CHECK: acc.data { +// CHECK-NEXT: } attributes {async, defaultAttr = #acc} + +// CHECK: acc.data async(%{{.*}} : i64) { +// CHECK-NEXT: } attributes {async, defaultAttr = #acc} + // ----- func.func @testupdateop(%a: memref, %b: memref, %c: memref) -> () {