[flang-commits] [flang] f0b701d - [acc][flang] Checking scalar like variables when there's storage operand to fir.declare (#163439)

via flang-commits flang-commits at lists.llvm.org
Tue Oct 14 17:53:20 PDT 2025


Author: Susan Tan (ス-ザン タン)
Date: 2025-10-14T20:53:16-04:00
New Revision: f0b701dfe4d786428a51b32b60bb7bf388140f0e

URL: https://github.com/llvm/llvm-project/commit/f0b701dfe4d786428a51b32b60bb7bf388140f0e
DIFF: https://github.com/llvm/llvm-project/commit/f0b701dfe4d786428a51b32b60bb7bf388140f0e.diff

LOG: [acc][flang] Checking scalar like variables when there's storage operand to fir.declare (#163439)

currently this variable 
```
%7 = fir.declare %6 storage(%4[0]) {uniq_name = "_QFEpi"} : (!fir.ref<f32>, !fir.ref<!fir.array<4xi8>>) -> !fir.ref<f32>
[2:19]
```
is categorized as a scalar type when it really should be an aggregate
type, because it is part of !fir.ref<!fir.array<4xi8>>

This MR adds a classification to capture the storage operand in
fir.declare.

Added: 
    flang/test/Fir/OpenACC/openacc-type-categories-declare-storage.mlir

Modified: 
    flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
index 41383fb8af9c1..9bf10b53108c0 100644
--- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
@@ -353,6 +353,14 @@ getBaseRef(mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
   // calculation op.
   mlir::Value baseRef =
       llvm::TypeSwitch<mlir::Operation *, mlir::Value>(op)
+          .Case<fir::DeclareOp>([&](auto op) {
+            // If this declare binds a view with an underlying storage operand,
+            // treat that storage as the base reference. Otherwise, fall back
+            // to the declared memref.
+            if (auto storage = op.getStorage())
+              return storage;
+            return mlir::Value(varPtr);
+          })
           .Case<hlfir::DesignateOp>([&](auto op) {
             // Get the base object.
             return op.getMemref();

diff  --git a/flang/test/Fir/OpenACC/openacc-type-categories-declare-storage.mlir b/flang/test/Fir/OpenACC/openacc-type-categories-declare-storage.mlir
new file mode 100644
index 0000000000000..fabfe4caf3924
--- /dev/null
+++ b/flang/test/Fir/OpenACC/openacc-type-categories-declare-storage.mlir
@@ -0,0 +1,24 @@
+// Use --mlir-disable-threading so that the diagnostic printing is serialized.
+// RUN: fir-opt %s -pass-pipeline='builtin.module(test-fir-openacc-interfaces)' -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s
+
+module {
+  // Build a scalar view via fir.declare with a storage operand into an array of i8
+  func.func @_QPdeclare_with_storage_is_nonscalar() {
+    %c0 = arith.constant 0 : index
+    %arr = fir.alloca !fir.array<4xi8>
+    %elem_i8 = fir.coordinate_of %arr, %c0 : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
+    %elem_f32 = fir.convert %elem_i8 : (!fir.ref<i8>) -> !fir.ref<f32>
+    %view = fir.declare %elem_f32 storage(%arr[0]) {uniq_name = "_QFpi"}
+      : (!fir.ref<f32>, !fir.ref<!fir.array<4xi8>>) -> !fir.ref<f32>
+    // Force interface query through an acc op that prints type category
+    %cp = acc.copyin varPtr(%view : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
+    acc.enter_data dataOperands(%cp : !fir.ref<f32>)
+    return
+  }
+
+  // CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
+  // CHECK: Pointer-like and Mappable: !fir.ref<f32>
+  // CHECK: Type category: array
+}
+
+


        


More information about the flang-commits mailing list