Skip to content

Commit f0b701d

Browse files
authored
[acc][flang] Checking scalar like variables when there's storage operand to fir.declare (llvm#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.
1 parent a848c1b commit f0b701d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ getBaseRef(mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
353353
// calculation op.
354354
mlir::Value baseRef =
355355
llvm::TypeSwitch<mlir::Operation *, mlir::Value>(op)
356+
.Case<fir::DeclareOp>([&](auto op) {
357+
// If this declare binds a view with an underlying storage operand,
358+
// treat that storage as the base reference. Otherwise, fall back
359+
// to the declared memref.
360+
if (auto storage = op.getStorage())
361+
return storage;
362+
return mlir::Value(varPtr);
363+
})
356364
.Case<hlfir::DesignateOp>([&](auto op) {
357365
// Get the base object.
358366
return op.getMemref();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Use --mlir-disable-threading so that the diagnostic printing is serialized.
2+
// RUN: fir-opt %s -pass-pipeline='builtin.module(test-fir-openacc-interfaces)' -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s
3+
4+
module {
5+
// Build a scalar view via fir.declare with a storage operand into an array of i8
6+
func.func @_QPdeclare_with_storage_is_nonscalar() {
7+
%c0 = arith.constant 0 : index
8+
%arr = fir.alloca !fir.array<4xi8>
9+
%elem_i8 = fir.coordinate_of %arr, %c0 : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
10+
%elem_f32 = fir.convert %elem_i8 : (!fir.ref<i8>) -> !fir.ref<f32>
11+
%view = fir.declare %elem_f32 storage(%arr[0]) {uniq_name = "_QFpi"}
12+
: (!fir.ref<f32>, !fir.ref<!fir.array<4xi8>>) -> !fir.ref<f32>
13+
// Force interface query through an acc op that prints type category
14+
%cp = acc.copyin varPtr(%view : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
15+
acc.enter_data dataOperands(%cp : !fir.ref<f32>)
16+
return
17+
}
18+
19+
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<f32>) -> !fir.ref<f32> {name = "pi", structured = false}
20+
// CHECK: Pointer-like and Mappable: !fir.ref<f32>
21+
// CHECK: Type category: array
22+
}
23+
24+

0 commit comments

Comments
 (0)