Skip to content

Commit 8d6636d

Browse files
Regenerate MLIR Bindings (#708)
Co-authored-by: enzyme-ci-bot[bot] <78882869+enzyme-ci-bot[bot]@users.noreply.github.com>
1 parent a1fa03f commit 8d6636d

File tree

8 files changed

+864
-69
lines changed

8 files changed

+864
-69
lines changed

src/mlir/Dialects/EnzymeXLA.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ import ...IR:
1313
import ..Dialects: namedattribute, operandsegmentsizes
1414
import ...API
1515

16+
function scope(
17+
operands::Vector{Value}; results::Vector{IR.Type}, region::Region, location=Location()
18+
)
19+
op_ty_results = IR.Type[results...,]
20+
operands = Value[operands...,]
21+
owned_regions = Region[region,]
22+
successors = Block[]
23+
attributes = NamedAttribute[]
24+
25+
return create_operation(
26+
"enzymexla.scope",
27+
location;
28+
operands,
29+
owned_regions,
30+
successors,
31+
attributes,
32+
results=op_ty_results,
33+
result_inference=false,
34+
)
35+
end
36+
1637
function get_stream(; result::IR.Type, location=Location())
1738
op_ty_results = IR.Type[result,]
1839
operands = Value[]

src/mlir/Dialects/Func.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ function call_indirect(
3434
callee::Value,
3535
callee_operands::Vector{Value};
3636
results::Vector{IR.Type},
37+
arg_attrs=nothing,
38+
res_attrs=nothing,
3739
location=Location(),
3840
)
3941
op_ty_results = IR.Type[results...,]
4042
operands = Value[callee, callee_operands...]
4143
owned_regions = Region[]
4244
successors = Block[]
4345
attributes = NamedAttribute[]
46+
!isnothing(arg_attrs) && push!(attributes, namedattribute("arg_attrs", arg_attrs))
47+
!isnothing(res_attrs) && push!(attributes, namedattribute("res_attrs", res_attrs))
4448

4549
return create_operation(
4650
"func.call_indirect",
@@ -72,6 +76,8 @@ function call(
7276
operands::Vector{Value};
7377
result_0::Vector{IR.Type},
7478
callee,
79+
arg_attrs=nothing,
80+
res_attrs=nothing,
7581
no_inline=nothing,
7682
location=Location(),
7783
)
@@ -80,6 +86,8 @@ function call(
8086
owned_regions = Region[]
8187
successors = Block[]
8288
attributes = NamedAttribute[namedattribute("callee", callee),]
89+
!isnothing(arg_attrs) && push!(attributes, namedattribute("arg_attrs", arg_attrs))
90+
!isnothing(res_attrs) && push!(attributes, namedattribute("res_attrs", res_attrs))
8391
!isnothing(no_inline) && push!(attributes, namedattribute("no_inline", no_inline))
8492

8593
return create_operation(

src/mlir/Dialects/Llvm.jl

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ end
8484
"""
8585
`mlir_addressof`
8686
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
9090
allowed.
9191
9292
Examples:
@@ -104,10 +104,19 @@ func @foo() {
104104
105105
// The function address can be used for indirect calls.
106106
llvm.call %2() : !llvm.ptr, () -> ()
107+
108+
// Get the address of an aliased global.
109+
%3 = llvm.mlir.addressof @const_alias : !llvm.ptr
107110
}
108111
109112
// Define the global.
110113
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+
}
111120
```
112121
"""
113122
function mlir_addressof(; res::IR.Type, global_name, location=Location())
@@ -129,6 +138,81 @@ function mlir_addressof(; res::IR.Type, global_name, location=Location())
129138
)
130139
end
131140

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+
132216
function alloca(
133217
arraySize::Value;
134218
res::IR.Type,
@@ -414,6 +498,8 @@ function call(
414498
will_return=nothing,
415499
op_bundle_sizes,
416500
op_bundle_tags=nothing,
501+
arg_attrs=nothing,
502+
res_attrs=nothing,
417503
access_groups=nothing,
418504
alias_scopes=nothing,
419505
noalias_scopes=nothing,
@@ -447,6 +533,8 @@ function call(
447533
!isnothing(will_return) && push!(attributes, namedattribute("will_return", will_return))
448534
!isnothing(op_bundle_tags) &&
449535
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))
450538
!isnothing(access_groups) &&
451539
push!(attributes, namedattribute("access_groups", access_groups))
452540
!isnothing(alias_scopes) &&
@@ -1435,6 +1523,8 @@ function invoke(
14351523
result=nothing::Union{Nothing,IR.Type},
14361524
var_callee_type=nothing,
14371525
callee=nothing,
1526+
arg_attrs=nothing,
1527+
res_attrs=nothing,
14381528
branch_weights=nothing,
14391529
CConv=nothing,
14401530
op_bundle_sizes,
@@ -1466,6 +1556,8 @@ function invoke(
14661556
!isnothing(var_callee_type) &&
14671557
push!(attributes, namedattribute("var_callee_type", var_callee_type))
14681558
!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))
14691561
!isnothing(branch_weights) &&
14701562
push!(attributes, namedattribute("branch_weights", branch_weights))
14711563
!isnothing(CConv) && push!(attributes, namedattribute("CConv", CConv))

0 commit comments

Comments
 (0)