diff options
author | jeanPerier <jperier@nvidia.com> | 2024-06-19 09:56:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-19 09:56:36 +0200 |
commit | bacbf26b4cb64dbf77819ff5a2b0f4c26d111c66 (patch) | |
tree | 9ea543cb7626b1fc7ee4cd52806c3a5a498ea8e7 | |
parent | 9cbedd925cba9e8ef76c50caa6d6ab4b0cc79c8f (diff) | |
download | llvm-bacbf26b4cb64dbf77819ff5a2b0f4c26d111c66.zip llvm-bacbf26b4cb64dbf77819ff5a2b0f4c26d111c66.tar.gz llvm-bacbf26b4cb64dbf77819ff5a2b0f4c26d111c66.tar.bz2 |
[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.
-rw-r--r-- | flang/lib/Optimizer/Dialect/FIROps.cpp | 2 | ||||
-rw-r--r-- | flang/test/Fir/convert-to-llvm.fir | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index ea8a975..6cf0dd2 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -272,8 +272,6 @@ mlir::LogicalResult fir::AllocaOp::verify() { mlir::Type outType = getType(); if (!mlir::isa<fir::ReferenceType>(outType)) return emitOpError("must be a !fir.ref type"); - if (fir::isa_unknown_size_box(fir::dyn_cast_ptrEleTy(outType))) - return emitOpError("cannot allocate !fir.box of unknown rank or type"); return mlir::success(); } diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir index d705967..857d5b2 100644 --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -1277,6 +1277,20 @@ func.func @alloca_array_with_holes(%0 : index, %1 : index) -> !fir.ref<!fir.arra // ----- +// Test alloca of assumed-rank box + +func.func @alloca_assumed_rank_box() -> !fir.ref<!fir.box<!fir.array<*:f32>>> { + %a = fir.alloca !fir.box<!fir.array<*:f32>> + return %a : !fir.ref<!fir.box<!fir.array<*:f32>>> +} +// CHECK-LABEL: llvm.func @alloca_assumed_rank_box +// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64 +// GENERIC: llvm.alloca %[[ONE]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<15 x array<3 x i64>>)> : (i64) -> !llvm.ptr +// 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> +// AMDGPU: llvm.addrspacecast %[[AA]] : !llvm.ptr<5> to !llvm.ptr + +// ----- + // Test `fir.select_case` operation conversion with INTEGER. func.func @select_case_integer(%arg0: !fir.ref<i32>) -> i32 { |