Skip to content

Commit bbb5dc4

Browse files
committed
[mlir][openacc] Add acc.data operation verifier
Add a basic verifier for the data operation following the restriction from the standard. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D88334
1 parent cc6d1f8 commit bbb5dc4

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ def OpenACC_DataOp : OpenACC_Op<"data",
212212
( `attach` `(` $attachOperands^ `:` type($attachOperands) `)` )?
213213
$region attr-dict-with-keyword
214214
}];
215-
216-
let verifier = ?;
217215
}
218216

219217
def OpenACC_TerminatorOp : OpenACC_Op<"terminator", [Terminator]> {

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,5 +634,20 @@ static LogicalResult verifyLoopOp(acc::LoopOp loopOp) {
634634
return success();
635635
}
636636

637+
//===----------------------------------------------------------------------===//
638+
// DataOp
639+
//===----------------------------------------------------------------------===//
640+
641+
static LogicalResult verify(acc::DataOp dataOp) {
642+
// 2.6.5. Data Construct restriction
643+
// At least one copy, copyin, copyout, create, no_create, present, deviceptr,
644+
// attach, or default clause must appear on a data construct.
645+
if (dataOp.getOperands().size() == 0 && !dataOp.defaultAttr())
646+
return dataOp.emitError("at least one operand or the default attribute "
647+
"must appear on the data operation");
648+
649+
return success();
650+
}
651+
637652
#define GET_OP_CLASSES
638653
#include "mlir/Dialect/OpenACC/OpenACCOps.cpp.inc"

mlir/test/Dialect/OpenACC/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ acc.loop {
6868
} attributes {auto_, seq}
6969

7070
// -----
71+
72+
// expected-error@+1 {{at least one operand or the default attribute must appear on the data operation}}
73+
acc.data {
74+
acc.yield
75+
}
76+
77+
// -----

mlir/test/Dialect/OpenACC/ops.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>)
485485
} attributes { defaultAttr = "none" }
486486
acc.data present(%a : memref<10xf32>) {
487487
} attributes { defaultAttr = "present" }
488+
acc.data {
489+
} attributes { defaultAttr = "none" }
488490
return
489491
}
490492

@@ -520,3 +522,5 @@ func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>)
520522
// CHECK-NEXT: } attributes {defaultAttr = "none"}
521523
// CHECK: acc.data present([[ARGA]] : memref<10xf32>) {
522524
// CHECK-NEXT: } attributes {defaultAttr = "present"}
525+
// CHECK: acc.data {
526+
// CHECK-NEXT: } attributes {defaultAttr = "none"}

0 commit comments

Comments
 (0)