[Mlir-commits] [mlir] 356f417 - [mlir][llvm] Test LLVM IR global variable import separately (NFC).

Tobias Gysi llvmlistbot at llvm.org
Thu Nov 17 01:26:48 PST 2022


Author: Tobias Gysi
Date: 2022-11-17T10:26:15+01:00
New Revision: 356f41705d3be03c2f98f7b0f8d35d741c85e7fb

URL: https://github.com/llvm/llvm-project/commit/356f41705d3be03c2f98f7b0f8d35d741c85e7fb
DIFF: https://github.com/llvm/llvm-project/commit/356f41705d3be03c2f98f7b0f8d35d741c85e7fb.diff

LOG: [mlir][llvm] Test LLVM IR global variable import separately (NFC).

The revision moves tests related to LLVM IR global variable
import into a separate global-variables.ll file.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D137622

Added: 
    mlir/test/Target/LLVMIR/Import/global-variables.ll

Modified: 
    mlir/test/Target/LLVMIR/Import/basic.ll

Removed: 
    


################################################################################
diff  --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll
index 9c39f395521c5..32a7795757d00 100644
--- a/mlir/test/Target/LLVMIR/Import/basic.ll
+++ b/mlir/test/Target/LLVMIR/Import/basic.ll
@@ -3,115 +3,7 @@
 
 ; CHECK-DBG: #[[UNKNOWNLOC:.+]] = loc(unknown)
 
-%struct.t = type {}
-%struct.s = type { %struct.t, i64 }
-
-; CHECK: llvm.mlir.global external @g1() {addr_space = 0 : i32, alignment = 8 : i64} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)>
- at g1 = external global %struct.s, align 8
-; CHECK: llvm.mlir.global external @g2() {addr_space = 0 : i32, alignment = 8 : i64} : f64
- at g2 = external global double, align 8
-; CHECK: llvm.mlir.global internal @g3("string")
- at g3 = internal global [6 x i8] c"string"
-
-; CHECK: llvm.mlir.global external @g5() {addr_space = 0 : i32} : vector<8xi32>
- at g5 = external global <8 x i32>
-
-; CHECK: llvm.mlir.global private @alig32(42 : i64) {addr_space = 0 : i32, alignment = 32 : i64, dso_local} : i64
- at alig32 = private global i64 42, align 32
-
-; CHECK: llvm.mlir.global private @alig64(42 : i64) {addr_space = 0 : i32, alignment = 64 : i64, dso_local} : i64
- at alig64 = private global i64 42, align 64
-
- at g4 = external global i32, align 8
-; CHECK: llvm.mlir.global internal constant @int_gep() {addr_space = 0 : i32, dso_local} : !llvm.ptr<i32> {
-; CHECK:       %[[addr:[0-9]+]] = llvm.mlir.addressof @g4 : !llvm.ptr<i32>
-; CHECK:       %[[c2:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
-; CHECK-NEXT:  %[[gepinit:[0-9]+]] = llvm.getelementptr %[[addr]][%[[c2]]] : (!llvm.ptr<i32>, i32) -> !llvm.ptr<i32>
-; CHECK-NEXT:  llvm.return %[[gepinit]] : !llvm.ptr<i32>
-; CHECK-NEXT: }
- at int_gep = internal constant i32* getelementptr (i32, i32* @g4, i32 2)
-
-;
-; dso_local attribute
-;
-
-; CHECK: llvm.mlir.global external @dso_local_var() {addr_space = 0 : i32, dso_local} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)>
- at dso_local_var = external dso_local global %struct.s
-
-;
-; thread_local attribute
-;
-
-; CHECK: llvm.mlir.global external thread_local @thread_local_var() {addr_space = 0 : i32} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)>
- at thread_local_var = external thread_local global %struct.s
-
-;
-; addr_space attribute
-;
-
-; CHECK: llvm.mlir.global external @addr_space_var(0 : i32) {addr_space = 6 : i32} : i32
- at addr_space_var = addrspace(6) global i32 0
-
-;
-; Linkage attribute.
-;
-
-; CHECK: llvm.mlir.global private @private(42 : i32) {addr_space = 0 : i32, dso_local} : i32
- at private = private global i32 42
-; CHECK: llvm.mlir.global internal @internal(42 : i32) {addr_space = 0 : i32, dso_local} : i32
- at internal = internal global i32 42
-; CHECK: llvm.mlir.global available_externally @available_externally(42 : i32) {addr_space = 0 : i32}  : i32
- at available_externally = available_externally global i32 42
-; CHECK: llvm.mlir.global linkonce @linkonce(42 : i32) {addr_space = 0 : i32} : i32
- at linkonce = linkonce global i32 42
-; CHECK: llvm.mlir.global weak @weak(42 : i32) {addr_space = 0 : i32} : i32
- at weak = weak global i32 42
-; CHECK: llvm.mlir.global common @common(0 : i32) {addr_space = 0 : i32} : i32
- at common = common global i32 zeroinitializer
-; CHECK: llvm.mlir.global appending @appending(dense<[0, 1]> : tensor<2xi32>) {addr_space = 0 : i32} : !llvm.array<2 x i32>
- at appending = appending global [2 x i32] [i32 0, i32 1]
-; CHECK: llvm.mlir.global extern_weak @extern_weak() {addr_space = 0 : i32} : i32
- at extern_weak = extern_weak global i32
-; CHECK: llvm.mlir.global linkonce_odr @linkonce_odr(42 : i32) {addr_space = 0 : i32} : i32
- at linkonce_odr = linkonce_odr global i32 42
-; CHECK: llvm.mlir.global weak_odr @weak_odr(42 : i32) {addr_space = 0 : i32} : i32
- at weak_odr = weak_odr global i32 42
-; CHECK: llvm.mlir.global external @external() {addr_space = 0 : i32} : i32
- at external = external global i32
-
-;
-; UnnamedAddr attribute.
-;
-
-
-; CHECK: llvm.mlir.global private constant @no_unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64
- at no_unnamed_addr = private constant i64 42
-; CHECK: llvm.mlir.global private local_unnamed_addr constant @local_unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64
- at local_unnamed_addr = private local_unnamed_addr constant i64 42
-; CHECK: llvm.mlir.global private unnamed_addr constant @unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64
- at unnamed_addr = private unnamed_addr constant i64 42
-
-;
-; Section attribute
-;
-
-; CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {addr_space = 0 : i32, dso_local, section = ".mysection"}
- at sectionvar = internal constant [10 x i8] c"teststring", section ".mysection"
-
-;
-; Sequential constants.
-;
-
-; CHECK: llvm.mlir.global internal constant @vector_constant(dense<[1, 2]> : vector<2xi32>) {addr_space = 0 : i32, dso_local} : vector<2xi32>
- at vector_constant = internal constant <2 x i32> <i32 1, i32 2>
-; CHECK: llvm.mlir.global internal constant @array_constant(dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>) {addr_space = 0 : i32, dso_local} : !llvm.array<2 x f32>
- at array_constant = internal constant [2 x float] [float 1., float 2.]
-; CHECK: llvm.mlir.global internal constant @nested_array_constant(dense<[{{\[}}1, 2], [3, 4]]> : tensor<2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<2 x array<2 x i32>>
- at nested_array_constant = internal constant [2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]]
-; CHECK: llvm.mlir.global internal constant @nested_array_constant3(dense<[{{\[}}[1, 2], [3, 4]]]> : tensor<1x2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x array<2 x i32>>>
- at nested_array_constant3 = internal constant [1 x [2 x [2 x i32]]] [[2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]]]
-; CHECK: llvm.mlir.global internal constant @nested_array_vector(dense<[{{\[}}[1, 2], [3, 4]]]> : vector<1x2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x vector<2xi32>>>
- at nested_array_vector = internal constant [1 x [2 x <2 x i32>]] [[2 x <2 x i32>] [<2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 4>]]
+ at global = external global double, align 8
 
 ;
 ; Linkage on functions.
@@ -141,14 +33,14 @@ define internal dso_local i32 @f1(i64 %a) norecurse {
 entry:
 ; CHECK: %{{[0-9]+}} = llvm.inttoptr %arg0 : i64 to !llvm.ptr<i64>
   %aa = inttoptr i64 %a to i64*
-; CHECK-DBG: llvm.mlir.addressof @g2 : !llvm.ptr<f64> loc(#[[UNKNOWNLOC]])
-; %[[addrof:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm.ptr<f64>
-; %[[addrof2:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm.ptr<f64>
+; CHECK-DBG: llvm.mlir.addressof @global : !llvm.ptr<f64> loc(#[[UNKNOWNLOC]])
+; %[[addrof:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr<f64>
+; %[[addrof2:[0-9]+]] = llvm.mlir.addressof @global : !llvm.ptr<f64>
 ; %{{[0-9]+}} = llvm.inttoptr %arg0 : i64 to !llvm.ptr<i64>
 ; %{{[0-9]+}} = llvm.ptrtoint %[[addrof2]] : !llvm.ptr<f64> to i64
 ; %{{[0-9]+}} = llvm.getelementptr %[[addrof]][%3] : (!llvm.ptr<f64>, i32) -> !llvm.ptr<f64>
-  %bb = ptrtoint double* @g2 to i64
-  %cc = getelementptr double, double* @g2, i32 3
+  %bb = ptrtoint double* @global to i64
+  %cc = getelementptr double, double* @global, i32 3
 ; CHECK: %[[b:[0-9]+]] = llvm.trunc %arg0 : i64 to i32
 ; CHECK-DBG: llvm.trunc %arg0 : i64 to i32 loc(#[[UNKNOWNLOC]])
   %b = trunc i64 %a to i32

diff  --git a/mlir/test/Target/LLVMIR/Import/global-variables.ll b/mlir/test/Target/LLVMIR/Import/global-variables.ll
new file mode 100644
index 0000000000000..9f6b426f4e8e2
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/global-variables.ll
@@ -0,0 +1,176 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+%sub_struct = type {}
+%my_struct = type { %sub_struct, i64 }
+
+; CHECK:  llvm.mlir.global external @global_struct
+; CHECK-SAME:  {addr_space = 0 : i32, alignment = 8 : i64}
+; CHECK-SAME:  !llvm.struct<"my_struct", (struct<"sub_struct", ()>, i64)>
+ at global_struct = external global %my_struct, align 8
+
+; CHECK:  llvm.mlir.global external @global_float
+; CHECK-SAME:  {addr_space = 0 : i32, alignment = 8 : i64} : f64
+ at global_float = external global double, align 8
+
+; CHECK:  llvm.mlir.global external @global_int
+; CHECK-SAME:  {addr_space = 0 : i32, alignment = 8 : i64} : i32
+ at global_int = external global i32, align 8
+
+; CHECK:  llvm.mlir.global internal @global_string("hello world")
+ at global_string = internal global [11 x i8] c"hello world"
+
+; CHECK:  llvm.mlir.global external @global_vector
+; CHECK-SAME:  {addr_space = 0 : i32} : vector<8xi32>
+ at global_vector = external global <8 x i32>
+
+; CHECK: llvm.mlir.global internal constant @global_gep_const_expr
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.ptr<i32> {
+; CHECK:  %[[ADDR:[0-9]+]] = llvm.mlir.addressof @global_int : !llvm.ptr<i32>
+; CHECK:  %[[IDX:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32
+; CHECK:  %[[GEP:[0-9]+]] = llvm.getelementptr %[[ADDR]][%[[IDX]]] : (!llvm.ptr<i32>, i32) -> !llvm.ptr<i32>
+; CHECK:  llvm.return %[[GEP]] : !llvm.ptr<i32>
+; CHECK:  }
+ at global_gep_const_expr = internal constant i32* getelementptr (i32, i32* @global_int, i32 2)
+
+; // -----
+
+; alignment attribute.
+
+; CHECK:  llvm.mlir.global private @global_int_align_32
+; CHECK-SAME:  (42 : i64) {addr_space = 0 : i32, alignment = 32 : i64, dso_local} : i64
+ at global_int_align_32 = private global i64 42, align 32
+
+; CHECK:  llvm.mlir.global private @global_int_align_64
+; CHECK-SAME:  (42 : i64) {addr_space = 0 : i32, alignment = 64 : i64, dso_local} : i64
+ at global_int_align_64 = private global i64 42, align 64
+
+; // -----
+
+; dso_local attribute.
+
+%sub_struct = type {}
+%my_struct = type { %sub_struct, i64 }
+
+; CHECK:  llvm.mlir.global external @dso_local_var
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.struct<"my_struct", (struct<"sub_struct", ()>, i64)>
+ at dso_local_var = external dso_local global %my_struct
+
+; // -----
+
+; thread_local attribute.
+
+%sub_struct = type {}
+%my_struct = type { %sub_struct, i64 }
+
+; CHECK:  llvm.mlir.global external thread_local @thread_local_var
+; CHECK-SAME:  {addr_space = 0 : i32} : !llvm.struct<"my_struct", (struct<"sub_struct", ()>, i64)>
+ at thread_local_var = external thread_local global %my_struct
+
+; // -----
+
+; addr_space attribute.
+
+; CHECK:  llvm.mlir.global external @addr_space_var
+; CHECK-SAME:  (0 : i32) {addr_space = 6 : i32} : i32
+ at addr_space_var = addrspace(6) global i32 0
+
+; // -----
+
+; Linkage attributes.
+
+; CHECK:  llvm.mlir.global private @private
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32, dso_local} : i32
+ at private = private global i32 42
+
+; CHECK:  llvm.mlir.global internal @internal
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32, dso_local} : i32
+ at internal = internal global i32 42
+
+; CHECK:  llvm.mlir.global available_externally @available_externally
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32}  : i32
+ at available_externally = available_externally global i32 42
+
+; CHECK:  llvm.mlir.global linkonce @linkonce
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32} : i32
+ at linkonce = linkonce global i32 42
+
+; CHECK:  llvm.mlir.global weak @weak
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32} : i32
+ at weak = weak global i32 42
+
+; CHECK:  llvm.mlir.global common @common
+; CHECK-SAME:  (0 : i32) {addr_space = 0 : i32} : i32
+ at common = common global i32 zeroinitializer
+
+; CHECK:  llvm.mlir.global appending @appending
+; CHECK-SAME:  (dense<[0, 1]> : tensor<2xi32>) {addr_space = 0 : i32} : !llvm.array<2 x i32>
+ at appending = appending global [2 x i32] [i32 0, i32 1]
+
+; CHECK:  llvm.mlir.global extern_weak @extern_weak
+; CHECK-SAME:  {addr_space = 0 : i32} : i32
+ at extern_weak = extern_weak global i32
+
+; CHECK:  llvm.mlir.global linkonce_odr @linkonce_odr
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32} : i32
+ at linkonce_odr = linkonce_odr global i32 42
+
+; CHECK:  llvm.mlir.global weak_odr @weak_odr
+; CHECK-SAME:  (42 : i32) {addr_space = 0 : i32} : i32
+ at weak_odr = weak_odr global i32 42
+
+; CHECK:  llvm.mlir.global external @external
+; CHECK-SAME:  {addr_space = 0 : i32} : i32
+ at external = external global i32
+
+; // -----
+
+; local_unnamed_addr and unnamed_addr attributes.
+
+; CHECK:  llvm.mlir.global private constant @no_unnamed_addr
+; CHECK-SAME:  (42 : i64) {addr_space = 0 : i32, dso_local} : i64
+ at no_unnamed_addr = private constant i64 42
+
+; CHECK:  llvm.mlir.global private local_unnamed_addr constant @local_unnamed_addr
+; CHECK-SAME:  (42 : i64) {addr_space = 0 : i32, dso_local} : i64
+ at local_unnamed_addr = private local_unnamed_addr constant i64 42
+
+; CHECK:  llvm.mlir.global private unnamed_addr constant @unnamed_addr
+; CHECK-SAME:  (42 : i64) {addr_space = 0 : i32, dso_local} : i64
+ at unnamed_addr = private unnamed_addr constant i64 42
+
+; // -----
+
+; section attribute.
+
+; CHECK:  llvm.mlir.global internal constant @sectionvar("hello world")
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local, section = ".mysection"}
+ at sectionvar = internal constant [11 x i8] c"hello world", section ".mysection"
+
+; // -----
+
+; Sequential constants.
+
+; CHECK:  llvm.mlir.global internal constant @vector_constant
+; CHECK-SAME:  (dense<[1, 2]> : vector<2xi32>)
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : vector<2xi32>
+ at vector_constant = internal constant <2 x i32> <i32 1, i32 2>
+
+; CHECK:  llvm.mlir.global internal constant @array_constant
+; CHECK-SAME:  (dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>)
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.array<2 x f32>
+ at array_constant = internal constant [2 x float] [float 1., float 2.]
+
+; CHECK: llvm.mlir.global internal constant @nested_array_constant
+; CHECK-SAME:  (dense<[{{\[}}1, 2], [3, 4]]> : tensor<2x2xi32>)
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.array<2 x array<2 x i32>>
+ at nested_array_constant = internal constant [2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]]
+
+; CHECK: llvm.mlir.global internal constant @nested_array_constant3
+; CHECK-SAME:  (dense<[{{\[}}[1, 2], [3, 4]]]> : tensor<1x2x2xi32>)
+; CHECK-SAME:  {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x array<2 x i32>>>
+ at nested_array_constant3 = internal constant [1 x [2 x [2 x i32]]] [[2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]]]
+
+; CHECK: llvm.mlir.global internal constant @nested_array_vector
+; CHECK-SAME:  (dense<[{{\[}}[1, 2], [3, 4]]]> : vector<1x2x2xi32>)
+; CHECK-SAME:   {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x vector<2xi32>>>
+ at nested_array_vector = internal constant [1 x [2 x <2 x i32>]] [[2 x <2 x i32>] [<2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 4>]]


        


More information about the Mlir-commits mailing list