diff --git a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h index 67e0fdb38a704..a39d517412c07 100644 --- a/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h +++ b/flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h @@ -132,13 +132,23 @@ struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel< bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const; }; -struct ReductionInitOpFortranObjectViewModel +namespace detail { +void verifyFortranObjectViewResult(mlir::Operation *op, + mlir::OpResult resultView); +} + +/// External model for acc ops whose result is a zero-offset view of an operand. +template +struct AccFortranObjectViewModel : public fir::FortranObjectViewOpInterface::ExternalModel< - ReductionInitOpFortranObjectViewModel, mlir::acc::ReductionInitOp> { + AccFortranObjectViewModel, Op> { mlir::Value getViewSource(mlir::Operation *op, mlir::OpResult resultView) const; std::optional getViewOffset(mlir::Operation *op, - mlir::OpResult resultView) const; + mlir::OpResult resultView) const { + detail::verifyFortranObjectViewResult(op, resultView); + return 0; + } }; } // namespace fir::acc diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.cpp index e18166c7ca354..d7f29971777c5 100644 --- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.cpp +++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.cpp @@ -18,15 +18,25 @@ #include "flang/Optimizer/Support/InternalNames.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" +#include "mlir/Interfaces/ViewLikeInterface.h" #include "llvm/ADT/SmallSet.h" namespace fir::acc { +namespace detail { -mlir::Value ReductionInitOpFortranObjectViewModel::getViewSource( - mlir::Operation *op, mlir::OpResult resultView) const { +void verifyFortranObjectViewResult(mlir::Operation *op, + mlir::OpResult resultView) { assert(resultView.getOwner() == op && "result value must be the op's result"); - assert(op->getNumResults() == 1 && - "definition of acc.reduction_init changed"); + assert(op->getNumResults() == 1 && "only expected single-result"); +} + +} // namespace detail + +template <> +mlir::Value +AccFortranObjectViewModel::getViewSource( + mlir::Operation *op, mlir::OpResult resultView) const { + detail::verifyFortranObjectViewResult(op, resultView); auto iface = mlir::cast(op); llvm::SmallVector resultValues; iface.getPredecessorValues(mlir::RegionSuccessor::parent(), /*index=*/0, @@ -45,11 +55,12 @@ mlir::Value ReductionInitOpFortranObjectViewModel::getViewSource( return passThroughValue; } -std::optional -ReductionInitOpFortranObjectViewModel::getViewOffset( +template <> +mlir::Value +AccFortranObjectViewModel::getViewSource( mlir::Operation *op, mlir::OpResult resultView) const { - assert(resultView.getOwner() == op && "result value must be the op's result"); - return 0; + detail::verifyFortranObjectViewResult(op, resultView); + return mlir::cast(op).getViewSource(); } template <> diff --git a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp index 7808972033c22..070208d22ba05 100644 --- a/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp +++ b/flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp @@ -113,7 +113,9 @@ void registerOpenACCExtensions(mlir::DialectRegistry ®istry) { mlir::acc::SerialOp::attachInterface< OperationMoveModel>(*ctx); mlir::acc::ReductionInitOp::attachInterface< - fir::acc::ReductionInitOpFortranObjectViewModel>(*ctx); + fir::acc::AccFortranObjectViewModel>(*ctx); + mlir::acc::UnwrapPrivateOp::attachInterface< + fir::acc::AccFortranObjectViewModel>(*ctx); }); registerAttrsExtensions(registry);