This patch introduces the acc.shutdown operation that represents an OpenACC shutdown directive.
Clauses are derived from the spec 2.14.2
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D88272
}
//===----------------------------------------------------------------------===//
+// 2.14.2. Shutdown
+//===----------------------------------------------------------------------===//
+
+def OpenACC_ShutdownOp : OpenACC_Op<"shutdown", [AttrSizedOperandSegments]> {
+ let summary = "shutdown operation";
+
+ let description = [{
+ The "acc.shutdown" operation represents the OpenACC shutdown executable
+ directive.
+
+ Example:
+
+ ```mlir
+ acc.shutdown
+ acc.shutdown device_num(%dev1 : i32)
+ ```
+ }];
+
+ let arguments = (ins Variadic<AnyInteger>:$deviceTypeOperands,
+ Optional<IntOrIndex>:$deviceNumOperand,
+ Optional<I1>:$ifCond);
+
+ let assemblyFormat = [{
+ ( `device_type` `(` $deviceTypeOperands^ `:` type($deviceTypeOperands) `)` )?
+ ( `device_num` `(` $deviceNumOperand^ `:` type($deviceNumOperand) `)` )?
+ ( `if` `(` $ifCond^ `)` )? attr-dict-with-keyword
+ }];
+}
+
+//===----------------------------------------------------------------------===//
// 2.14.4. Update Directive
//===----------------------------------------------------------------------===//
return llvm::None;
}
+static bool isComputeOperation(Operation *op) {
+ return isa<acc::ParallelOp>(op) || isa<acc::LoopOp>(op);
+}
+
//===----------------------------------------------------------------------===//
// ParallelOp
//===----------------------------------------------------------------------===//
static LogicalResult verify(acc::InitOp initOp) {
Operation *currOp = initOp;
while ((currOp = currOp->getParentOp())) {
- if (isa<acc::ParallelOp>(currOp) || isa<acc::LoopOp>(currOp))
+ if (isComputeOperation(currOp))
return initOp.emitOpError("cannot be nested in a compute operation");
}
return success();
}
//===----------------------------------------------------------------------===//
+// ShutdownOp
+//===----------------------------------------------------------------------===//
+
+static LogicalResult verify(acc::ShutdownOp op) {
+ Operation *currOp = op;
+ while ((currOp = currOp->getParentOp())) {
+ if (isComputeOperation(currOp))
+ return op.emitOpError("cannot be nested in a compute operation");
+ }
+ return success();
+}
+
+//===----------------------------------------------------------------------===//
// UpdateOp
//===----------------------------------------------------------------------===//
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s
// expected-error@+1 {{gang, worker or vector cannot appear with the seq attr}}
acc.loop gang {
acc.init
acc.yield
}
+
+// -----
+
+acc.parallel {
+// expected-error@+1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+ acc.shutdown
+ acc.yield
+}
+
+// -----
+
+acc.loop {
+// expected-error@+1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+ acc.shutdown
+ acc.yield
+}
+
+// -----
+
+acc.loop {
+ "some.op"() ({
+ // expected-error@+1 {{'acc.shutdown' op cannot be nested in a compute operation}}
+ acc.shutdown
+ }) : () -> ()
+ acc.yield
+}
// CHECK: acc.init device_num([[I32VALUE]] : i32)
// CHECK: acc.init device_num([[IDXVALUE]] : index)
// CHECK: acc.init if([[IFCOND]])
+
+// -----
+
+%i64Value = constant 1 : i64
+%i32Value = constant 1 : i32
+%i32Value2 = constant 2 : i32
+%idxValue = constant 1 : index
+%ifCond = constant true
+acc.shutdown
+acc.shutdown device_type(%i32Value : i32)
+acc.shutdown device_type(%i32Value, %i32Value2 : i32, i32)
+acc.shutdown device_num(%i64Value : i64)
+acc.shutdown device_num(%i32Value : i32)
+acc.shutdown device_num(%idxValue : index)
+acc.shutdown if(%ifCond)
+
+// CHECK: [[I64VALUE:%.*]] = constant 1 : i64
+// CHECK: [[I32VALUE:%.*]] = constant 1 : i32
+// CHECK: [[I32VALUE2:%.*]] = constant 2 : i32
+// CHECK: [[IDXVALUE:%.*]] = constant 1 : index
+// CHECK: [[IFCOND:%.*]] = constant true
+// CHECK: acc.shutdown
+// CHECK: acc.shutdown device_type([[I32VALUE]] : i32)
+// CHECK: acc.shutdown device_type([[I32VALUE]], [[I32VALUE2]] : i32, i32)
+// CHECK: acc.shutdown device_num([[I64VALUE]] : i64)
+// CHECK: acc.shutdown device_num([[I32VALUE]] : i32)
+// CHECK: acc.shutdown device_num([[IDXVALUE]] : index)
+// CHECK: acc.shutdown if([[IFCOND]])