[flang-commits] [flang] [flang] keep runtime allocator for pinned allocations (PR #207822)

via flang-commits flang-commits at lists.llvm.org
Mon Jul 6 12:49:15 PDT 2026


https://github.com/yebinchon updated https://github.com/llvm/llvm-project/pull/207822

>From e38390e4ca45aa58241448d7076f5c8bfd9c7366 Mon Sep 17 00:00:00 2001
From: Yebin Chon <ychon at nvidia.com>
Date: Mon, 6 Jul 2026 12:38:45 -0700
Subject: [PATCH 1/2] keep runtime allocator for pinned

---
 .../HLFIR/Transforms/SeparateAllocatableAssign.cpp        | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
index 0160ff7d75f76..cf56025d9be43 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
@@ -76,6 +76,14 @@ class SeparateAllocatableAssignConversion
     if (!fir::isBoxAddress(lhs.getType()))
       return rewriter.notifyMatchFailure(assign, "LHS is not a box address");
 
+    // If the LHS allocatable is backed by a non-default (CUF) allocator
+    // (pinned/device/managed/unified), its (re)allocation must go through the
+    // Fortran runtime so the allocator recorded in the descriptor is honored.
+    if (mlir::Operation *lhsDef = assign.getLhs().getDefiningOp())
+      if (cuf::getDataAttr(lhsDef))
+        return rewriter.notifyMatchFailure(
+            assign, "LHS uses a non-default allocator; keep runtime realloc");
+
     mlir::Location loc = assign->getLoc();
     fir::FirOpBuilder builder(rewriter, assign.getOperation());
     builder.setInsertionPoint(assign);

>From d437337164cb78743fb2557c0caa5f8afb2c058e Mon Sep 17 00:00:00 2001
From: Yebin Chon <ychon at nvidia.com>
Date: Mon, 6 Jul 2026 12:49:02 -0700
Subject: [PATCH 2/2] only for pinned

---
 .../HLFIR/Transforms/SeparateAllocatableAssign.cpp     | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
index cf56025d9be43..45806ccf1ea29 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SeparateAllocatableAssign.cpp
@@ -25,6 +25,7 @@
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/HLFIRTools.h"
 #include "flang/Optimizer/Builder/MutableBox.h"
+#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/HLFIR/HLFIROps.h"
 #include "flang/Optimizer/HLFIR/Passes.h"
@@ -76,13 +77,12 @@ class SeparateAllocatableAssignConversion
     if (!fir::isBoxAddress(lhs.getType()))
       return rewriter.notifyMatchFailure(assign, "LHS is not a box address");
 
-    // If the LHS allocatable is backed by a non-default (CUF) allocator
-    // (pinned/device/managed/unified), its (re)allocation must go through the
-    // Fortran runtime so the allocator recorded in the descriptor is honored.
+    // If the LHS allocatable is pinned, its (re)allocation must go through the
+    // flang runtime so the allocator recorded in the descriptor is honored.
     if (mlir::Operation *lhsDef = assign.getLhs().getDefiningOp())
-      if (cuf::getDataAttr(lhsDef))
+      if (cuf::hasDataAttr(lhsDef, cuf::DataAttribute::Pinned))
         return rewriter.notifyMatchFailure(
-            assign, "LHS uses a non-default allocator; keep runtime realloc");
+            assign, "LHS uses a pinned allocator; keep runtime realloc");
 
     mlir::Location loc = assign->getLoc();
     fir::FirOpBuilder builder(rewriter, assign.getOperation());



More information about the flang-commits mailing list