diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h --- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h @@ -78,6 +78,10 @@ return StringLiteral("acc.declare"); } +static constexpr StringLiteral getDeclareActionAttrName() { + return StringLiteral("acc.declare_action"); +} + } // namespace acc } // namespace mlir 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 @@ -135,6 +135,16 @@ let assemblyFormat = "`<` struct(params) `>`"; } +// Attribute to attach functions that perform the pre/post allocation actions or +// pre/post deallocation actions as described in section 2.13. +def DeclareActionAttr : OpenACC_Attr<"DeclareAction", "declare_action"> { + let parameters = (ins OptionalParameter<"SymbolRefAttr">:$preAlloc, + OptionalParameter<"SymbolRefAttr">:$postAlloc, + OptionalParameter<"SymbolRefAttr">:$preDealloc, + OptionalParameter<"SymbolRefAttr">:$postDealloc); + let assemblyFormat = "`<` struct(params) `>`"; +} + // Used for data specification in data clauses (2.7.1). // Either (or both) extent and upperbound must be specified. def OpenACC_DataBoundsOp : OpenACC_Op<"bounds", 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 @@ -1664,3 +1664,13 @@ // CHECK: acc.routine @acc_func_rout7 func(@acc_func) bind("acc_func_gpu_imp_gang") gang implicit // CHECK: acc.routine @acc_func_rout8 func(@acc_func) bind("acc_func_gpu_vector_nohost") vector nohost // CHECK: acc.routine @acc_func_rout9 func(@acc_func) bind("acc_func_gpu_gang_dim1") gang(dim = 1 : i32) + +// ----- + +func.func @acc_func() -> () { + "test.openacc_dummy_op"() {acc.declare_action = #acc.declare_action} : () -> () + return +} + +// CHECK-LABEL: func.func @acc_func +// CHECK: "test.openacc_dummy_op"() {acc.declare_action = #acc.declare_action}