From 67eef630509013779b72bc32ce4d9e5ea9643bb0 Mon Sep 17 00:00:00 2001 From: Atmn Patel Date: Fri, 21 Nov 2025 12:54:11 -0800 Subject: [PATCH 1/2] [mlir][acc] Adds attr to acc.present to identify default clause origin The `acc.present` Op as generated by ACCImplicitData does not provide a way to differentiate between `acc.present` ops that are generated implicitly and the ones that are generated as result of an explicit `default(present)` clause in the source code. This differentiation would allow for better communication to the user on the decisions made by the compiler while managing data automatically between the host and the device. This commit adds this information as a discardable attribute on the `acc.present` op. Reviewers: @razvanlupusoru @vzakhari --- flang/test/Transforms/OpenACC/acc-implicit-data.fir | 8 ++++---- mlir/include/mlir/Dialect/OpenACC/OpenACC.h | 4 ++++ mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp | 2 ++ mlir/test/Dialect/OpenACC/acc-implicit-data.mlir | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/flang/test/Transforms/OpenACC/acc-implicit-data.fir b/flang/test/Transforms/OpenACC/acc-implicit-data.fir index 7f6a57cb4d8c6..f4c66ceb30f48 100644 --- a/flang/test/Transforms/OpenACC/acc-implicit-data.fir +++ b/flang/test/Transforms/OpenACC/acc-implicit-data.fir @@ -133,7 +133,7 @@ func.func @test_fir_derivedtype_in_parallel_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {implicit = true, name = "aggrvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "aggrvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "aggrvar"} // ----- @@ -147,7 +147,7 @@ func.func @test_fir_derivedtype_in_kernels_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {implicit = true, name = "aggrvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "aggrvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "aggrvar"} // ----- @@ -161,7 +161,7 @@ func.func @test_fir_array_in_parallel_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {implicit = true, name = "arrayvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "arrayvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "arrayvar"} // ----- @@ -175,7 +175,7 @@ func.func @test_fir_array_in_kernels_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {implicit = true, name = "arrayvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "arrayvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "arrayvar"} // ----- diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h index 05d2316711c8a..08e694ab72c93 100644 --- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h @@ -177,6 +177,10 @@ static constexpr StringLiteral getRoutineInfoAttrName() { return StringLiteral("acc.routine_info"); } +static constexpr StringLiteral getFromDefaultClauseAttrName() { + return StringLiteral("default"); +} + static constexpr StringLiteral getVarNameAttrName() { return VarNameAttr::name; } diff --git a/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp b/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp index 91262bd76ca31..cf90152603cb3 100644 --- a/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp +++ b/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp @@ -570,6 +570,8 @@ Operation *ACCImplicitData::generateDataClauseOpForCandidate( newDataOp = acc::PresentOp::create(builder, loc, var, /*structured=*/true, /*implicit=*/true, accSupport.getVariableName(var)); + newDataOp->setAttr(acc::getFromDefaultClauseAttrName(), + builder.getBoolAttr(true)); } else { auto copyinOp = acc::CopyinOp::create(builder, loc, var, diff --git a/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir b/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir index cf09c33ca5197..994e8dd0ccfe4 100644 --- a/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir +++ b/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir @@ -110,7 +110,7 @@ func.func @test_array_parallel_defaultpresent() { } // CHECK-LABEL: func.func @test_array_parallel_defaultpresent -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {implicit = true, name = ""} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {default = true, implicit = true, name = ""} // CHECK: acc.delete accPtr(%[[PRESENT]] : memref<10xf32>) {dataClause = #acc, implicit = true, name = ""} // ----- From 0e23bc2f181a256c08987e62276e153a10827cdf Mon Sep 17 00:00:00 2001 From: Atmn Patel Date: Sun, 23 Nov 2025 09:35:44 -0800 Subject: [PATCH 2/2] rename attr to acc.from_default, convert to unitattr --- flang/test/Transforms/OpenACC/acc-implicit-data.fir | 8 ++++---- mlir/include/mlir/Dialect/OpenACC/OpenACC.h | 2 +- mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp | 2 +- mlir/test/Dialect/OpenACC/acc-implicit-data.mlir | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/flang/test/Transforms/OpenACC/acc-implicit-data.fir b/flang/test/Transforms/OpenACC/acc-implicit-data.fir index f4c66ceb30f48..2d28c341d0d5e 100644 --- a/flang/test/Transforms/OpenACC/acc-implicit-data.fir +++ b/flang/test/Transforms/OpenACC/acc-implicit-data.fir @@ -133,7 +133,7 @@ func.func @test_fir_derivedtype_in_parallel_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "aggrvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {acc.from_default, implicit = true, name = "aggrvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "aggrvar"} // ----- @@ -147,7 +147,7 @@ func.func @test_fir_derivedtype_in_kernels_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "aggrvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {acc.from_default, implicit = true, name = "aggrvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "aggrvar"} // ----- @@ -161,7 +161,7 @@ func.func @test_fir_array_in_parallel_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "arrayvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {acc.from_default, implicit = true, name = "arrayvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "arrayvar"} // ----- @@ -175,7 +175,7 @@ func.func @test_fir_array_in_kernels_defaultpresent() { return } -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {default = true, implicit = true, name = "arrayvar"} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : !fir.ref>) -> !fir.ref> {acc.from_default, implicit = true, name = "arrayvar"} // CHECK: acc.delete accPtr(%[[PRESENT]] : !fir.ref>) {dataClause = #acc, implicit = true, name = "arrayvar"} // ----- diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h index 08e694ab72c93..601fc1a594768 100644 --- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h @@ -178,7 +178,7 @@ static constexpr StringLiteral getRoutineInfoAttrName() { } static constexpr StringLiteral getFromDefaultClauseAttrName() { - return StringLiteral("default"); + return StringLiteral("acc.from_default"); } static constexpr StringLiteral getVarNameAttrName() { diff --git a/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp b/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp index cf90152603cb3..7d729619b3f21 100644 --- a/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp +++ b/mlir/lib/Dialect/OpenACC/Transforms/ACCImplicitData.cpp @@ -571,7 +571,7 @@ Operation *ACCImplicitData::generateDataClauseOpForCandidate( /*structured=*/true, /*implicit=*/true, accSupport.getVariableName(var)); newDataOp->setAttr(acc::getFromDefaultClauseAttrName(), - builder.getBoolAttr(true)); + builder.getUnitAttr()); } else { auto copyinOp = acc::CopyinOp::create(builder, loc, var, diff --git a/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir b/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir index 994e8dd0ccfe4..06c1c3cadd4ba 100644 --- a/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir +++ b/mlir/test/Dialect/OpenACC/acc-implicit-data.mlir @@ -110,7 +110,7 @@ func.func @test_array_parallel_defaultpresent() { } // CHECK-LABEL: func.func @test_array_parallel_defaultpresent -// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {default = true, implicit = true, name = ""} +// CHECK: %[[PRESENT:.*]] = acc.present varPtr({{.*}} : memref<10xf32>) -> memref<10xf32> {acc.from_default, implicit = true, name = ""} // CHECK: acc.delete accPtr(%[[PRESENT]] : memref<10xf32>) {dataClause = #acc, implicit = true, name = ""} // -----