Skip to content

Commit bacbf26

Browse files
authored
[flang] allow assumed-rank box in fir.alloca (#95947)
The alloca can be maximized with the maximum number or ranks, which is reasonable (15 currently as per the standard). Introducing a rank based dynamic allocation would complexify alloca hoisting and stack size analysis (this can be revisited if the standard changes to allow more ranks). No change is needed since this is already reflected in how the fir.box type is translated to LLVM.
1 parent 9cbedd9 commit bacbf26

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ mlir::LogicalResult fir::AllocaOp::verify() {
272272
mlir::Type outType = getType();
273273
if (!mlir::isa<fir::ReferenceType>(outType))
274274
return emitOpError("must be a !fir.ref type");
275-
if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType)))
276-
return emitOpError("cannot allocate !fir.box of unknown rank or type");
277275
return mlir::success();
278276
}
279277

flang/test/Fir/convert-to-llvm.fir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,20 @@ func.func @alloca_array_with_holes(%0 : index, %1 : index) -> !fir.ref<!fir.arra
12771277

12781278
// -----
12791279

1280+
// Test alloca of assumed-rank box
1281+
1282+
func.func @alloca_assumed_rank_box() -> !fir.ref<!fir.box<!fir.array<*:f32>>> {
1283+
%a = fir.alloca !fir.box<!fir.array<*:f32>>
1284+
return %a : !fir.ref<!fir.box<!fir.array<*:f32>>>
1285+
}
1286+
// CHECK-LABEL: llvm.func @alloca_assumed_rank_box
1287+
// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
1288+
// GENERIC: llvm.alloca %[[ONE]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<15 x array<3 x i64>>)> : (i64) -> !llvm.ptr
1289+
// AMDGPU: %[[AA:.*]] = llvm.alloca %[[ONE]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<15 x array<3 x i64>>)> : (i64) -> !llvm.ptr<5>
1290+
// AMDGPU: llvm.addrspacecast %[[AA]] : !llvm.ptr<5> to !llvm.ptr
1291+
1292+
// -----
1293+
12801294
// Test `fir.select_case` operation conversion with INTEGER.
12811295

12821296
func.func @select_case_integer(%arg0: !fir.ref<i32>) -> i32 {

0 commit comments

Comments
 (0)