Skip to content

Commit

Permalink
[mlir][openacc] Add async attribute and optional operand
Browse files Browse the repository at this point in the history
OpenACC 3.2 allowed the async clause to the data construct. This patch
adds a unit attribute and an optional operand to the data operation to model
the data clause in a similar way it was added to other data operation.
The attribute models the presence of the clause without any argument. When
an argument is provided it is placed in the async operand.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D154111
  • Loading branch information
clementval committed Jun 30, 2023
1 parent 905c9c2 commit ecc7adc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,10 +1353,15 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::StatementContext &stmtCtx,
const Fortran::parser::AccClauseList &accClauseList) {
mlir::Value ifCond;
mlir::Value ifCond, async;
llvm::SmallVector<mlir::Value> 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.
Expand Down Expand Up @@ -1444,11 +1449,14 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Value> operands;
llvm::SmallVector<int32_t> operandSegments;
addOperand(operands, operandSegments, ifCond);
addOperand(operands, operandSegments, async);
addOperands(operands, operandSegments, dataClauseOperands);

auto dataOp = createRegionOp<mlir::acc::DataOp, mlir::acc::TerminatorOp>(
builder, currentLocation, operands, operandSegments);

dataOp.setAsyncAttr(addAsyncAttr);

auto insPt = builder.saveInsertionPoint();
builder.setInsertionPointAfter(dataOp);

Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ def OpenACC_DataOp : OpenACC_Op<"data",


let arguments = (ins Optional<I1>:$ifCond,
Optional<IntOrIndex>:$async,
UnitAttr:$asyncAttr,
Variadic<OpenACC_PointerLikeTypeInterface>:$dataClauseOperands,
OptionalAttr<DefaultValueAttr>:$defaultAttr);

Expand All @@ -881,6 +883,7 @@ def OpenACC_DataOp : OpenACC_Op<"data",
let assemblyFormat = [{
oilist(
`if` `(` $ifCond `)`
| `async` `(` $async `:` type($async) `)`
| `dataOperands` `(` $dataClauseOperands `:` type($dataClauseOperands) `)`
)
$region attr-dict-with-keyword
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ unsigned DataOp::getNumDataOperands() { return getDataClauseOperands().size(); }

Value DataOp::getDataOperand(unsigned i) {
unsigned numOptional = getIfCond() ? 1 : 0;
numOptional += getAsync() ? 1 : 0;
return getOperand(numOptional + i);
}

Expand Down
14 changes: 14 additions & 0 deletions mlir/test/Dialect/OpenACC/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,14 @@ func.func @testdataop(%a: memref<f32>, %b: memref<f32>, %c: memref<f32>) -> () {

acc.data {
} attributes { defaultAttr = #acc<defaultvalue none> }

acc.data {
} attributes { defaultAttr = #acc<defaultvalue none>, async }

%a1 = arith.constant 1 : i64
acc.data async(%a1 : i64) {
} attributes { defaultAttr = #acc<defaultvalue none>, async }

return
}

Expand Down Expand Up @@ -913,6 +921,12 @@ func.func @testdataop(%a: memref<f32>, %b: memref<f32>, %c: memref<f32>) -> () {
// CHECK: acc.data {
// CHECK-NEXT: } attributes {defaultAttr = #acc<defaultvalue none>}

// CHECK: acc.data {
// CHECK-NEXT: } attributes {async, defaultAttr = #acc<defaultvalue none>}

// CHECK: acc.data async(%{{.*}} : i64) {
// CHECK-NEXT: } attributes {async, defaultAttr = #acc<defaultvalue none>}

// -----

func.func @testupdateop(%a: memref<f32>, %b: memref<f32>, %c: memref<f32>) -> () {
Expand Down

0 comments on commit ecc7adc

Please sign in to comment.