[PATCH] D115797: [Flang][NFC] Add test with shape for allocmem and freemem
Kiran Chandramohan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 16 05:36:00 PST 2021
kiranchandramohan updated this revision to Diff 394835.
kiranchandramohan added a comment.
Minor changes to address review comments.
Pass the dimensions as arguments instead of loading them.
Use index types to avoid conversion.
trim the allocmem/free operations of attributes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115797/new/
https://reviews.llvm.org/D115797
Files:
flang/test/Fir/convert-to-llvm.fir
Index: flang/test/Fir/convert-to-llvm.fir
===================================================================
--- flang/test/Fir/convert-to-llvm.fir
+++ flang/test/Fir/convert-to-llvm.fir
@@ -202,6 +202,43 @@
// CHECK: llvm.call @free([[B2]])
// CHECK: llvm.return
+
+func @test_with_shape(%ncols: index, %nrows: index) {
+ %1 = fir.allocmem !fir.array<?x?xf32>, %ncols, %nrows
+ fir.freemem %1 : !fir.heap<!fir.array<?x?xf32>>
+ return
+}
+
+// CHECK-LABEL: llvm.func @test_with_shape
+// CHECK-SAME: %[[NCOLS:.*]]: i64, %[[NROWS:.*]]: i64
+// CHECK: %[[FOUR:.*]] = llvm.mlir.constant(4 : i64) : i64
+// CHECK: %[[DIM1_SIZE:.*]] = llvm.mul %[[FOUR]], %[[NCOLS]] : i64
+// CHECK: %[[TOTAL_SIZE:.*]] = llvm.mul %[[DIM1_SIZE]], %[[NROWS]] : i64
+// CHECK: %[[MEM:.*]] = llvm.call @malloc(%[[TOTAL_SIZE]])
+// CHECK: %[[B1:.*]] = llvm.bitcast %[[MEM]] : !llvm.ptr<i8> to !llvm.ptr<f32>
+// CHECK: %[[B2:.*]] = llvm.bitcast %[[B1]] : !llvm.ptr<f32> to !llvm.ptr<i8>
+// CHECK: llvm.call @free(%[[B2]]) : (!llvm.ptr<i8>) -> ()
+// CHECK: llvm.return
+// CHECK: }
+
+func @test_string_with_shape(%len: index, %nelems: index) {
+ %1 = fir.allocmem !fir.array<?x!fir.char<1,?>>(%len : index), %nelems
+ fir.freemem %1 : !fir.heap<!fir.array<?x!fir.char<1,?>>>
+ return
+}
+
+// CHECK-LABEL: llvm.func @test_string_with_shape
+// CHECK-SAME: %[[LEN:.*]]: i64, %[[NELEMS:.*]]: i64)
+// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
+// CHECK: %[[LEN_SIZE:.*]] = llvm.mul %[[ONE]], %[[LEN]] : i64
+// CHECK: %[[TOTAL_SIZE:.*]] = llvm.mul %[[LEN_SIZE]], %[[NELEMS]] : i64
+// CHECK: %[[MEM:.*]] = llvm.call @malloc(%[[TOTAL_SIZE]])
+// CHECK: %[[B1:.*]] = llvm.bitcast %[[MEM]] : !llvm.ptr<i8> to !llvm.ptr<i8>
+// CHECK: %[[B2:.*]] = llvm.bitcast %[[B1]] : !llvm.ptr<i8> to !llvm.ptr<i8>
+// CHECK: llvm.call @free(%[[B2]]) : (!llvm.ptr<i8>) -> ()
+// CHECK: llvm.return
+// CHECK: }
+
// -----
// Verify that fir.unreachable is transformed to llvm.unreachable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115797.394835.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/adda78f5/attachment-0001.bin>
More information about the llvm-commits
mailing list