[Mlir-commits] [flang] [mlir] [flang][acc] Introduce interface for rematerializable ops (PR #174467)

Razvan Lupusoru llvmlistbot at llvm.org
Mon Jan 5 11:23:14 PST 2026


https://github.com/razvanlupusoru updated https://github.com/llvm/llvm-project/pull/174467

>From 5dcad73147c133063d3dcb0ac41261fbc443bcbe Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Mon, 5 Jan 2026 11:17:06 -0800
Subject: [PATCH 1/3] [flang][acc] Introduce interface for rematerializable ops

During the outlining process when offloading acc regions, the body
of the compute kernel is separated from its original location and
live-in values are handled in various ways including becoming
function arguments.

However, some operations are purely synthetic and only make sense
when included with another operation (usually such operations exist
to simplify IR design). Bounds and shapes are examples where during
outlining they should be recreated inside to capture the full
information.

Therefore, introduce a new operation interface named
OutlineRematerializationOpInterface meant to be attached to such
operations. It is currently expected that all such operations are
memory effect free to ensure there are no considerations needed
when moving or cloning them into outlined regions.

The interface is attached to the following operations:
- acc.bounds (directly in TableGen)
- fir.shape (via external model)
- fir.shape_shift (via external model)
- fir.shift (via external model)
- fir.field_index (via external model)

The pass that will use this interface and associated testing
will follow in another pull request.
---
 .../OpenACC/Support/FIROpenACCOpsInterfaces.h     | 13 +++++++++++++
 .../OpenACC/Support/RegisterOpenACCExtensions.cpp | 12 ++++++++++++
 mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td   |  3 ++-
 .../mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td  | 15 +++++++++++++++
 4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
index d7f8f87ccb8bf..28e110bb913ca 100644
--- a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
+++ b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
@@ -18,7 +18,11 @@
 namespace fir {
 class AddrOfOp;
 class DeclareOp;
+class FieldIndexOp;
 class GlobalOp;
+class ShapeOp;
+class ShapeShiftOp;
+class ShiftOp;
 } // namespace fir
 
 namespace hlfir {
@@ -77,6 +81,15 @@ struct IndirectGlobalAccessModel
                             mlir::SymbolTable *symbolTable) const;
 };
 
+/// External model for OutlineRematerializationOpInterface.
+/// This interface marks operations that are candidates for rematerialization
+/// during outlining. These operations produce synthetic types or values
+/// that cannot be passed as arguments to outlined regions.
+template <typename Op>
+struct OutlineRematerializationModel
+    : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
+          OutlineRematerializationModel<Op>, Op> {};
+
 } // namespace fir::acc
 
 #endif // FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
diff --git a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
index acd1d01ef1e87..60be72d8a7103 100644
--- a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
@@ -61,6 +61,18 @@ void registerOpenACCExtensions(mlir::DialectRegistry &registry) {
         *ctx);
     fir::TypeDescOp::attachInterface<
         IndirectGlobalAccessModel<fir::TypeDescOp>>(*ctx);
+
+    // Attach OutlineRematerializationOpInterface to FIR operations that
+    // produce synthetic types (shapes, field indices) which cannot be passed
+    // as arguments to outlined regions and must be rematerialized inside.
+    fir::ShapeOp::attachInterface<
+        OutlineRematerializationModel<fir::ShapeOp>>(*ctx);
+    fir::ShapeShiftOp::attachInterface<
+        OutlineRematerializationModel<fir::ShapeShiftOp>>(*ctx);
+    fir::ShiftOp::attachInterface<
+        OutlineRematerializationModel<fir::ShiftOp>>(*ctx);
+    fir::FieldIndexOp::attachInterface<
+        OutlineRematerializationModel<fir::FieldIndexOp>>(*ctx);
   });
 
   // Register HLFIR operation interfaces
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 2375104eadb85..73ca362c6dc3d 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -471,7 +471,8 @@ def OpenACC_VarNameAttr : OpenACC_Attr<"VarName", "var_name"> {
 // 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",
-    [AttrSizedOperandSegments, NoMemoryEffect]> {
+    [AttrSizedOperandSegments, NoMemoryEffect,
+     OutlineRematerializationOpInterface]> {
   let summary = "Represents normalized bounds information for acc data clause.";
 
   let description = [{
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
index d958006d58bad..bef228fd5769a 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
@@ -100,4 +100,19 @@ def IndirectGlobalAccessOpInterface : OpInterface<"IndirectGlobalAccessOpInterfa
   ];
 }
 
+def OutlineRematerializationOpInterface : OpInterface<"OutlineRematerializationOpInterface"> {
+  let cppNamespace = "::mlir::acc";
+
+  let description = [{
+    An interface for operations that are candidates for rematerialization
+    during outlining. These operations produce synthetic types or values
+    that cannot be passed as arguments to outlined regions and must be
+    rematerialized inside the region instead.
+
+    Operations implementing this interface are expected to be memory effect
+    free. Their results are typically used for type construction or providing
+    metadata (such as shape information for arrays).
+  }];
+}
+
 #endif // OPENACC_OPS_INTERFACES

>From 1c204e989aec0cd6d9e116944be0ed4d6e628c8c Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Mon, 5 Jan 2026 11:22:32 -0800
Subject: [PATCH 2/3] Remove unneeded forward declarations

---
 .../flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
index 28e110bb913ca..b017cb4733b6c 100644
--- a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
+++ b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
@@ -18,11 +18,7 @@
 namespace fir {
 class AddrOfOp;
 class DeclareOp;
-class FieldIndexOp;
 class GlobalOp;
-class ShapeOp;
-class ShapeShiftOp;
-class ShiftOp;
 } // namespace fir
 
 namespace hlfir {

>From 1c89ee506a152426b0c992a17dd9ef031d569049 Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Mon, 5 Jan 2026 11:22:58 -0800
Subject: [PATCH 3/3] Fix format

---
 .../OpenACC/Support/RegisterOpenACCExtensions.cpp         | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
index 60be72d8a7103..d7e9ae4ec85b9 100644
--- a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
@@ -65,12 +65,12 @@ void registerOpenACCExtensions(mlir::DialectRegistry &registry) {
     // Attach OutlineRematerializationOpInterface to FIR operations that
     // produce synthetic types (shapes, field indices) which cannot be passed
     // as arguments to outlined regions and must be rematerialized inside.
-    fir::ShapeOp::attachInterface<
-        OutlineRematerializationModel<fir::ShapeOp>>(*ctx);
+    fir::ShapeOp::attachInterface<OutlineRematerializationModel<fir::ShapeOp>>(
+        *ctx);
     fir::ShapeShiftOp::attachInterface<
         OutlineRematerializationModel<fir::ShapeShiftOp>>(*ctx);
-    fir::ShiftOp::attachInterface<
-        OutlineRematerializationModel<fir::ShiftOp>>(*ctx);
+    fir::ShiftOp::attachInterface<OutlineRematerializationModel<fir::ShiftOp>>(
+        *ctx);
     fir::FieldIndexOp::attachInterface<
         OutlineRematerializationModel<fir::FieldIndexOp>>(*ctx);
   });



More information about the Mlir-commits mailing list