Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flang][acc] Attach FortranObjectViewOpInterface to acc.unwrap_private#201646

Merged
razvanlupusoru merged 1 commit into
llvm:mainfrom
razvanlupusoru:accunwrapprivatefortranview
Jun 4, 2026
Merged

[flang][acc] Attach FortranObjectViewOpInterface to acc.unwrap_private#201646
razvanlupusoru merged 1 commit into
llvm:mainfrom
razvanlupusoru:accunwrapprivatefortranview

Conversation

@razvanlupusoru
Copy link
Copy Markdown
Contributor

Since this operation is simply a zero-offset view, attach the FortranObjectViewOpInterface to allow FIR AA to walk this if needed.

Since this operation is simply a zero-offset view, attach the
FortranObjectViewOpInterface to allow FIR AA to walk this if needed.
@razvanlupusoru razvanlupusoru requested a review from vzakhari June 4, 2026 17:32
@llvmorg-github-actions llvmorg-github-actions Bot added flang Flang issues not falling into any other category flang:fir-hlfir openacc labels Jun 4, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented Jun 4, 2026

@llvm/pr-subscribers-openacc

@llvm/pr-subscribers-flang-fir-hlfir

Author: Razvan Lupusoru (razvanlupusoru)

Changes

Since 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:

  • (modified) flang/include/flang/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.h (+13-3)
  • (modified) flang/lib/Optimizer/OpenACC/Support/FIROpenACCOpsInterfaces.cpp (+19-8)
  • (modified) flang/lib/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.cpp (+3-1)
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 &registry) {
     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);

Copy link
Copy Markdown
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Razvan!

@razvanlupusoru razvanlupusoru enabled auto-merge (squash) June 4, 2026 17:39
@razvanlupusoru razvanlupusoru merged commit 2851820 into llvm:main Jun 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category openacc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants