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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jan 5 12:16:48 PST 2026


Author: Razvan Lupusoru
Date: 2026-01-05T20:16:43Z
New Revision: 735b1c284d6a3e838c08699944707ae8c303fa8f

URL: https://github.com/llvm/llvm-project/commit/735b1c284d6a3e838c08699944707ae8c303fa8f
DIFF: https://github.com/llvm/llvm-project/commit/735b1c284d6a3e838c08699944707ae8c303fa8f.diff

LOG: [flang][acc] Introduce interface for rematerializable ops (#174467)

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.

Added: 
    

Modified: 
    flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
    flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp
    mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
    mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
index d7f8f87ccb8bf..b017cb4733b6c 100644
--- a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
+++ b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h
@@ -77,6 +77,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..d7e9ae4ec85b9 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..3242f25c44399 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
@@ -10,6 +10,7 @@
 #define OPENACC_OPS_INTERFACES
 
 include "mlir/IR/OpBase.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
 
 def ComputeRegionOpInterface : OpInterface<"ComputeRegionOpInterface"> {
   let cppNamespace = "::mlir::acc";
@@ -100,4 +101,25 @@ 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).
+  }];
+
+  let verify = [{
+    if (!::mlir::isMemoryEffectFree($_op))
+      return $_op->emitOpError("must be memory effect free");
+    return ::mlir::success();
+  }];
+}
+
 #endif // OPENACC_OPS_INTERFACES


        


More information about the Mlir-commits mailing list