[Mlir-commits] [mlir] [mlir][llvm] Add zeroinitializer constant (PR #65508)

Tobias Gysi llvmlistbot at llvm.org
Wed Sep 6 12:25:12 PDT 2023


================
@@ -2292,3 +2292,132 @@ llvm.func @locally_streaming_func() attributes {arm_locally_streaming} {
 }
 
 // CHECK: attributes #[[ATTR]] = { "aarch64_pstate_sm_body" }
+
+// -----
+
+//
+// Zero-initialize operation.
+//
+
+llvm.mlir.global linkonce @zero_integer() : i32 {
+  %0 = llvm.mlir.zero : i32
+  llvm.return %0 : i32
+}
+// CHECK: @zero_integer = linkonce global i32 0
+
+llvm.mlir.global linkonce @zero_float() : f32 {
+  %0 = llvm.mlir.zero : f32
+  llvm.return %0 : f32
+}
+// CHECK: @zero_float = linkonce global float 0.000000e+00
+
+llvm.mlir.global linkonce @zero_array() : !llvm.array<5 x i32> {
+  %0 = llvm.mlir.zero : !llvm.array<5 x i32>
+  llvm.return %0 : !llvm.array<5 x i32>
+}
+// CHECK: @zero_array = linkonce global [5 x i32] zeroinitializer
+
+llvm.mlir.global linkonce @zero_struct() : !llvm.struct<(i32, f64, i8)> {
+  %0 = llvm.mlir.zero : !llvm.struct<(i32, f64, i8)>
+  llvm.return %0 : !llvm.struct<(i32, f64, i8)>
+}
+// CHECK: @zero_struct = linkonce global { i32, double, i8 } zeroinitializer
+
+llvm.mlir.global linkonce @zero_ptr() : !llvm.ptr<i32> {
----------------
gysit wrote:

Can you avoid typed pointers and instead always use opaque pointers (opaque pointers don't have an element type and look as follows:
```suggestion
llvm.mlir.global linkonce @zero_ptr() : !llvm.ptr {
```
LLVM does not have typed pointers anymore and MLIR is in a transition phase:
https://discourse.llvm.org/t/rfc-switching-the-llvm-dialect-and-dialect-lowerings-to-opaque-pointers/68179

We would thus like to avoid any new uses of typed pointers.

https://github.com/llvm/llvm-project/pull/65508


More information about the Mlir-commits mailing list