[flang][acc] Attach FortranObjectViewOpInterface to acc.unwrap_private#201646
Merged
razvanlupusoru merged 1 commit intoJun 4, 2026
Merged
Conversation
Since this operation is simply a zero-offset view, attach the FortranObjectViewOpInterface to allow FIR AA to walk this if needed.
|
@llvm/pr-subscribers-openacc @llvm/pr-subscribers-flang-fir-hlfir Author: Razvan Lupusoru (razvanlupusoru) ChangesSince this operation is simply a zero-offset view, attach the FortranObjectViewOpInterface to allow FIR AA to walk this if needed. Full diff: https://github.com/llvm/llvm-project/pull/201646.diff 3 Files Affected:
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 <typename Op>
+struct AccFortranObjectViewModel
: public fir::FortranObjectViewOpInterface::ExternalModel<
- ReductionInitOpFortranObjectViewModel, mlir::acc::ReductionInitOp> {
+ AccFortranObjectViewModel<Op>, Op> {
mlir::Value getViewSource(mlir::Operation *op,
mlir::OpResult resultView) const;
std::optional<std::int64_t> 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<mlir::acc::ReductionInitOp>::getViewSource(
+ mlir::Operation *op, mlir::OpResult resultView) const {
+ detail::verifyFortranObjectViewResult(op, resultView);
auto iface = mlir::cast<mlir::RegionBranchOpInterface>(op);
llvm::SmallVector<mlir::Value, 1> resultValues;
iface.getPredecessorValues(mlir::RegionSuccessor::parent(), /*index=*/0,
@@ -45,11 +55,12 @@ mlir::Value ReductionInitOpFortranObjectViewModel::getViewSource(
return passThroughValue;
}
-std::optional<std::int64_t>
-ReductionInitOpFortranObjectViewModel::getViewOffset(
+template <>
+mlir::Value
+AccFortranObjectViewModel<mlir::acc::UnwrapPrivateOp>::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<mlir::acc::UnwrapPrivateOp>(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<mlir::acc::SerialOp>>(*ctx);
mlir::acc::ReductionInitOp::attachInterface<
- fir::acc::ReductionInitOpFortranObjectViewModel>(*ctx);
+ fir::acc::AccFortranObjectViewModel<mlir::acc::ReductionInitOp>>(*ctx);
+ mlir::acc::UnwrapPrivateOp::attachInterface<
+ fir::acc::AccFortranObjectViewModel<mlir::acc::UnwrapPrivateOp>>(*ctx);
});
registerAttrsExtensions(registry);
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since this operation is simply a zero-offset view, attach the FortranObjectViewOpInterface to allow FIR AA to walk this if needed.