File: global.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (255 lines) | stat: -rw-r--r-- 9,268 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s

// CHECK: llvm.mlir.global external @default_external
llvm.mlir.global @default_external() : i64

// CHECK: llvm.mlir.global external constant @default_external_constant
llvm.mlir.global constant @default_external_constant(42) : i64

// CHECK: llvm.mlir.global internal @global(42 : i64) {addr_space = 0 : i32} : i64
llvm.mlir.global internal @global(42 : i64) : i64

// CHECK: llvm.mlir.global private @aligned_global(42 : i64) {addr_space = 0 : i32, aligned = 64 : i64} : i64
llvm.mlir.global private @aligned_global(42 : i64) {aligned = 64} : i64

// CHECK: llvm.mlir.global private constant @aligned_global_const(42 : i64) {addr_space = 0 : i32, aligned = 32 : i64} : i64
llvm.mlir.global private constant @aligned_global_const(42 : i64) {aligned = 32} : i64

// CHECK: llvm.mlir.global internal constant @constant(3.700000e+01 : f64) {addr_space = 0 : i32} : f32
llvm.mlir.global internal constant @constant(37.0) : f32

// CHECK: llvm.mlir.global internal constant @".string"("foobar")
llvm.mlir.global internal constant @".string"("foobar") : !llvm.array<6 x i8>

// CHECK: llvm.mlir.global internal @string_notype("1234567")
llvm.mlir.global internal @string_notype("1234567")

// CHECK: llvm.mlir.global internal @global_undef()
llvm.mlir.global internal @global_undef() : i64

// CHECK: llvm.mlir.global internal @global_mega_initializer() {addr_space = 0 : i32} : i64 {
// CHECK-NEXT:  %[[c:[0-9]+]] = llvm.mlir.constant(42 : i64) : i64
// CHECK-NEXT:  llvm.return %[[c]] : i64
// CHECK-NEXT: }
llvm.mlir.global internal @global_mega_initializer() : i64 {
  %c = llvm.mlir.constant(42 : i64) : i64
  llvm.return %c : i64
}

// Check different linkage types.
// CHECK: llvm.mlir.global private
llvm.mlir.global private @private() : i64
// CHECK: llvm.mlir.global internal
llvm.mlir.global internal @internal() : i64
// CHECK: llvm.mlir.global available_externally
llvm.mlir.global available_externally @available_externally() : i64
// CHECK: llvm.mlir.global linkonce
llvm.mlir.global linkonce @linkonce() : i64
// CHECK: llvm.mlir.global weak
llvm.mlir.global weak @weak() : i64
// CHECK: llvm.mlir.global common
llvm.mlir.global common @common() : i64
// CHECK: llvm.mlir.global appending
llvm.mlir.global appending @appending() : !llvm.array<2 x i64>
// CHECK: llvm.mlir.global extern_weak
llvm.mlir.global extern_weak @extern_weak() : i64
// CHECK: llvm.mlir.global linkonce_odr
llvm.mlir.global linkonce_odr @linkonce_odr() : i64
// CHECK: llvm.mlir.global weak_odr
llvm.mlir.global weak_odr @weak_odr() : i64
// CHECK: llvm.mlir.global external @has_thr_local(42 : i64) {addr_space = 0 : i32, thr_local} : i64
llvm.mlir.global external @has_thr_local(42 : i64) {thr_local} : i64
// CHECK: llvm.mlir.global external @has_dso_local(42 : i64) {addr_space = 0 : i32, dso_local} : i64
llvm.mlir.global external @has_dso_local(42 : i64) {dso_local} : i64
// CHECK: llvm.mlir.global external @has_addr_space(32 : i64) {addr_space = 3 : i32} : i64
llvm.mlir.global external @has_addr_space(32 : i64) {addr_space = 3: i32} : i64

// CHECK: llvm.comdat @__llvm_comdat
llvm.comdat @__llvm_comdat {
  // CHECK: llvm.comdat_selector @any any
  llvm.comdat_selector @any any
}
// CHECK: llvm.mlir.global external @any() comdat(@__llvm_comdat::@any) {addr_space = 1 : i32} : i64
llvm.mlir.global @any() comdat(@__llvm_comdat::@any) {addr_space = 1 : i32} : i64

// CHECK-LABEL: references
func.func @references() {
  // CHECK: llvm.mlir.addressof @".string" : !llvm.ptr
  %0 = llvm.mlir.addressof @".string" : !llvm.ptr

  // CHECK: llvm.mlir.addressof @global : !llvm.ptr
  %1 = llvm.mlir.addressof @global : !llvm.ptr

  // CHECK: llvm.mlir.addressof @has_addr_space : !llvm.ptr<3>
  %2 = llvm.mlir.addressof @has_addr_space : !llvm.ptr<3>

  llvm.return
}

// CHECK: llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) {addr_space = 0 : i32} : i64
llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) : i64

// CHECK: llvm.mlir.global private unnamed_addr constant @foo(42 : i64) {addr_space = 0 : i32} : i64
llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64

// CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {addr_space = 0 : i32, section = ".mysection"}
llvm.mlir.global internal constant @sectionvar("teststring")  {section = ".mysection"}: !llvm.array<10 x i8>

// CHECK: llvm.mlir.global internal thread_local constant @thread_local(42 : i32)
llvm.mlir.global internal thread_local constant @thread_local(42 : i32) : i32

// Visibility types.
// CHECK: llvm.mlir.global internal hidden constant @hidden(42 : i32)
llvm.mlir.global internal hidden constant @hidden(42 : i32) : i32

// CHECK: llvm.mlir.global internal protected unnamed_addr @protected(42 : i32)
llvm.mlir.global internal protected unnamed_addr @protected(42 : i32) : i32

// -----

// expected-error @+1 {{op requires attribute 'sym_name'}}
"llvm.mlir.global"() ({}) {linkage = #llvm.linkage<private>, type = i64, constant, global_type = i64, value = 42 : i64} : () -> ()

// -----

// expected-error @+1 {{requires attribute 'global_type'}}
"llvm.mlir.global"() ({}) {sym_name = "foo", constant, value = 42 : i64} : () -> ()

// -----

// expected-error @+1 {{expects type to be a valid element type for an LLVM pointer}}
llvm.mlir.global internal constant @constant(37.0) : !llvm.label

// -----

// expected-error @+1 {{'addr_space' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
"llvm.mlir.global"() ({}) {sym_name = "foo", global_type = i64, value = 42 : i64, addr_space = -1 : i32, linkage = #llvm.linkage<private>} : () -> ()

// -----

// expected-error @+1 {{'addr_space' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}}
"llvm.mlir.global"() ({}) {sym_name = "foo", global_type = i64, value = 42 : i64, addr_space = 1.0 : f32, linkage = #llvm.linkage<private>} : () -> ()

// -----

func.func @foo() {
  // expected-error @+1 {{must appear at the module level}}
  llvm.mlir.global internal @bar(42) : i32

  return
}

// -----

// expected-error @+1 {{requires an i8 array type of the length equal to that of the string}}
llvm.mlir.global internal constant @string("foobar") : !llvm.array<42 x i8>

// -----

// expected-error @+1 {{type can only be omitted for string globals}}
llvm.mlir.global internal @i64_needs_type(0: i64)

// -----

// expected-error @+1 {{expected zero or one type}}
llvm.mlir.global internal @more_than_one_type(0) : i64, i32

// -----

llvm.mlir.global internal @foo(0: i32) : i32

func.func @bar() {
  // expected-error @+1{{expected ':'}}
  llvm.mlir.addressof @foo
}

// -----

func.func @foo() {
  // The attribute parser will consume the first colon-type, so we put two of
  // them to trigger the attribute type mismatch error.
  // expected-error @+1 {{invalid kind of attribute specified}}
  llvm.mlir.addressof "foo" : i64 : !llvm.ptr
  llvm.return
}

// -----

func.func @foo() {
  // expected-error @+1 {{must reference a global defined by 'llvm.mlir.global'}}
  llvm.mlir.addressof @foo : !llvm.ptr
  llvm.return
}

// -----

// expected-error @+2 {{block with no terminator}}
llvm.mlir.global internal @g() : i64 {
  %c = llvm.mlir.constant(42 : i64) : i64
}

// -----

// expected-error @+1 {{'llvm.mlir.global' op initializer region type 'i64' does not match global type 'i32'}}
llvm.mlir.global internal @g() : i32 {
  %c = llvm.mlir.constant(42 : i64) : i64
  llvm.return %c : i64
}

// -----

// expected-error @+1 {{'llvm.mlir.global' op cannot have both initializer value and region}}
llvm.mlir.global internal @g(43 : i64) : i64 {
  %c = llvm.mlir.constant(42 : i64) : i64
  llvm.return %c : i64
}

// -----

llvm.mlir.global internal @g(32 : i64) {addr_space = 3: i32} : i64
func.func @mismatch_addr_space_implicit_global() {
  // expected-error @+1 {{pointer address space must match address space of the referenced global}}
  llvm.mlir.addressof @g : !llvm.ptr
  llvm.return
}

// -----

llvm.mlir.global internal @g(32 : i64) {addr_space = 3: i32} : i64

func.func @mismatch_addr_space() {
  // expected-error @+1 {{pointer address space must match address space of the referenced global}}
  llvm.mlir.addressof @g : !llvm.ptr<4>
  llvm.return
}

// -----

llvm.func @ctor() {
  llvm.return
}

// CHECK: llvm.mlir.global_ctors {ctors = [@ctor], priorities = [0 : i32]}
llvm.mlir.global_ctors { ctors = [@ctor], priorities = [0 : i32]}

// -----

llvm.func @dtor() {
  llvm.return
}

// CHECK: llvm.mlir.global_dtors {dtors = [@dtor], priorities = [0 : i32]}
llvm.mlir.global_dtors { dtors = [@dtor], priorities = [0 : i32]}

// -----

// CHECK: llvm.mlir.global external @target_ext() {addr_space = 0 : i32} : !llvm.target<"spirv.Image", i32, 0>
llvm.mlir.global @target_ext() : !llvm.target<"spirv.Image", i32, 0>

// CHECK: llvm.mlir.global external @target_ext_init(0 : i64) {addr_space = 0 : i32} : !llvm.target<"spirv.Image", i32, 0>
llvm.mlir.global @target_ext_init(0 : i64) : !llvm.target<"spirv.Image", i32, 0>

// -----

// expected-error @+1 {{expected zero value for global with target extension type}}
llvm.mlir.global @target_fail(1 : i64) : !llvm.target<"spirv.Image", i32, 0>