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 +struct OutlineRematerializationModel + : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel< + OutlineRematerializationModel, 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 ®istry) { *ctx); fir::TypeDescOp::attachInterface< IndirectGlobalAccessModel>(*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>( + *ctx); + fir::ShapeShiftOp::attachInterface< + OutlineRematerializationModel>(*ctx); + fir::ShiftOp::attachInterface>( + *ctx); + fir::FieldIndexOp::attachInterface< + OutlineRematerializationModel>(*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