84
84
"""
85
85
`mlir_addressof`
86
86
87
- Creates an SSA value containing a pointer to a global variable or constant
88
- defined by `llvm.mlir.global`. The global value can be defined after its
89
- first referenced. If the global value is a constant, storing into it is not
87
+ Creates an SSA value containing a pointer to a global value (function,
88
+ variable or alias). The global value can be defined after its first
89
+ referenced. If the global value is a constant, storing into it is not
90
90
allowed.
91
91
92
92
Examples:
@@ -104,10 +104,19 @@ func @foo() {
104
104
105
105
// The function address can be used for indirect calls.
106
106
llvm.call %2() : !llvm.ptr, () -> ()
107
+
108
+ // Get the address of an aliased global.
109
+ %3 = llvm.mlir.addressof @const_alias : !llvm.ptr
107
110
}
108
111
109
112
// Define the global.
110
113
llvm.mlir.global @const(42 : i32) : i32
114
+
115
+ // Define an alias.
116
+ llvm.mlir.alias @const_alias : i32 {
117
+ %0 = llvm.mlir.addressof @const : !llvm.ptr
118
+ llvm.return %0 : !llvm.ptr
119
+ }
111
120
```
112
121
"""
113
122
function mlir_addressof (; res:: IR.Type , global_name, location= Location ())
@@ -129,6 +138,81 @@ function mlir_addressof(; res::IR.Type, global_name, location=Location())
129
138
)
130
139
end
131
140
141
+ """
142
+ `mlir_alias`
143
+
144
+ `llvm.mlir.alias` is a top level operation that defines a global alias for
145
+ global variables and functions. The operation is always initialized by
146
+ using a initializer region which could be a direct map to another global
147
+ value or contain some address computation on top of it.
148
+
149
+ It uses a symbol for its value, which will be uniqued by the module
150
+ with respect to other symbols in it.
151
+
152
+ Similarly to functions and globals, they can also have a linkage attribute.
153
+ This attribute is placed between `llvm.mlir.alias` and the symbol name. If
154
+ the attribute is omitted, `external` linkage is assumed by default.
155
+
156
+ Examples:
157
+
158
+ ```mlir
159
+ // Global alias use @-identifiers.
160
+ llvm.mlir.alias external @foo_alias {addr_space = 0 : i32} : !llvm.ptr {
161
+ %0 = llvm.mlir.addressof @some_function : !llvm.ptr
162
+ llvm.return %0 : !llvm.ptr
163
+ }
164
+
165
+ // More complex initialization.
166
+ llvm.mlir.alias linkonce_odr hidden @glob
167
+ {addr_space = 0 : i32, dso_local} : !llvm.array<32 x i32> {
168
+ %0 = llvm.mlir.constant(1234 : i64) : i64
169
+ %1 = llvm.mlir.addressof @glob.private : !llvm.ptr
170
+ %2 = llvm.ptrtoint %1 : !llvm.ptr to i64
171
+ %3 = llvm.add %2, %0 : i64
172
+ %4 = llvm.inttoptr %3 : i64 to !llvm.ptr
173
+ llvm.return %4 : !llvm.ptr
174
+ }
175
+ ```
176
+ """
177
+ function mlir_alias (;
178
+ alias_type,
179
+ sym_name,
180
+ linkage,
181
+ dso_local= nothing ,
182
+ thread_local_= nothing ,
183
+ unnamed_addr= nothing ,
184
+ visibility_= nothing ,
185
+ initializer:: Region ,
186
+ location= Location (),
187
+ )
188
+ op_ty_results = IR. Type[]
189
+ operands = Value[]
190
+ owned_regions = Region[initializer,]
191
+ successors = Block[]
192
+ attributes = NamedAttribute[
193
+ namedattribute (" alias_type" , alias_type),
194
+ namedattribute (" sym_name" , sym_name),
195
+ namedattribute (" linkage" , linkage),
196
+ ]
197
+ ! isnothing (dso_local) && push! (attributes, namedattribute (" dso_local" , dso_local))
198
+ ! isnothing (thread_local_) &&
199
+ push! (attributes, namedattribute (" thread_local_" , thread_local_))
200
+ ! isnothing (unnamed_addr) &&
201
+ push! (attributes, namedattribute (" unnamed_addr" , unnamed_addr))
202
+ ! isnothing (visibility_) && push! (attributes, namedattribute (" visibility_" , visibility_))
203
+
204
+ return create_operation (
205
+ " llvm.mlir.alias" ,
206
+ location;
207
+ operands,
208
+ owned_regions,
209
+ successors,
210
+ attributes,
211
+ results= op_ty_results,
212
+ result_inference= false ,
213
+ )
214
+ end
215
+
132
216
function alloca (
133
217
arraySize:: Value ;
134
218
res:: IR.Type ,
@@ -414,6 +498,8 @@ function call(
414
498
will_return= nothing ,
415
499
op_bundle_sizes,
416
500
op_bundle_tags= nothing ,
501
+ arg_attrs= nothing ,
502
+ res_attrs= nothing ,
417
503
access_groups= nothing ,
418
504
alias_scopes= nothing ,
419
505
noalias_scopes= nothing ,
@@ -447,6 +533,8 @@ function call(
447
533
! isnothing (will_return) && push! (attributes, namedattribute (" will_return" , will_return))
448
534
! isnothing (op_bundle_tags) &&
449
535
push! (attributes, namedattribute (" op_bundle_tags" , op_bundle_tags))
536
+ ! isnothing (arg_attrs) && push! (attributes, namedattribute (" arg_attrs" , arg_attrs))
537
+ ! isnothing (res_attrs) && push! (attributes, namedattribute (" res_attrs" , res_attrs))
450
538
! isnothing (access_groups) &&
451
539
push! (attributes, namedattribute (" access_groups" , access_groups))
452
540
! isnothing (alias_scopes) &&
@@ -1435,6 +1523,8 @@ function invoke(
1435
1523
result= nothing :: Union{Nothing,IR.Type} ,
1436
1524
var_callee_type= nothing ,
1437
1525
callee= nothing ,
1526
+ arg_attrs= nothing ,
1527
+ res_attrs= nothing ,
1438
1528
branch_weights= nothing ,
1439
1529
CConv= nothing ,
1440
1530
op_bundle_sizes,
@@ -1466,6 +1556,8 @@ function invoke(
1466
1556
! isnothing (var_callee_type) &&
1467
1557
push! (attributes, namedattribute (" var_callee_type" , var_callee_type))
1468
1558
! isnothing (callee) && push! (attributes, namedattribute (" callee" , callee))
1559
+ ! isnothing (arg_attrs) && push! (attributes, namedattribute (" arg_attrs" , arg_attrs))
1560
+ ! isnothing (res_attrs) && push! (attributes, namedattribute (" res_attrs" , res_attrs))
1469
1561
! isnothing (branch_weights) &&
1470
1562
push! (attributes, namedattribute (" branch_weights" , branch_weights))
1471
1563
! isnothing (CConv) && push! (attributes, namedattribute (" CConv" , CConv))
0 commit comments