Skip to content

Commit b8ab825

Browse files
jumerckxPangoraw
andauthored
Fix Brutus example on nightly. (#75)
* add v17 to API.jl * linetable is stored in debuginfo field now * using internal IRShow method to get linenumber * I forgot the dialects! * small error * Update examples/brutus.jl Co-authored-by: Paul Berg <[email protected]> * Update examples/brutus.jl Co-authored-by: Paul Berg <[email protected]> * MLIR17: fix brutus example location info, update Pass.jl, update executionengine example --------- Co-authored-by: Paul Berg <[email protected]>
1 parent eb4aed0 commit b8ab825

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

examples/brutus.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ function code_mlir(f, types)
143143
for sidx in bb.stmts
144144
stmt = ir.stmts[sidx]
145145
inst = stmt[:inst]
146-
line = ir.linetable[stmt[:line]+1]
146+
line = @static if VERSION <= v"1.11"
147+
ir.linetable[stmt[:line]+1]
148+
else
149+
lineinfonode = Base.IRShow.buildLineInfoNode(ir.debuginfo, :var"n/a", sidx)
150+
if !isempty(lineinfonode)
151+
last(lineinfonode)
152+
else
153+
(; ((:file, :line) .=> Base.IRShow.debuginfo_firstline(ir.debuginfo))...)
154+
end
155+
end
147156

148157
if Meta.isexpr(inst, :call)
149158
val_type = stmt[:type]
@@ -186,7 +195,6 @@ function code_mlir(f, types)
186195
cond_br = cf.cond_br(cond, true_args, false_args; trueDest=other_dest, falseDest=dest, location)
187196
push!(current_block, cond_br)
188197
elseif inst isa ReturnNode
189-
line = ir.linetable[stmt[:line]+1]
190198
location = Location(string(line.file), line.line, 0)
191199
push!(current_block, func.return_([get_value(inst.val)]; location))
192200
elseif Meta.isexpr(inst, :code_coverage_effect)

src/API/API.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ end
1818

1919
# generate version-less API functions
2020
begin
21-
local ops = mapreduce(, [v14, v15, v16]) do mod
21+
local ops = mapreduce(, [v14, v15, v16, v17]) do mod
2222
filter(names(mod; all=true)) do name
2323
name [nameof(mod), :eval, :include] && !startswith(string(name), '#')
2424
end
2525
end
2626

2727
for op in ops
28-
container_mods = filter([v14, v15, v16]) do mod
28+
container_mods = filter([v14, v15, v16, v17]) do mod
2929
op in names(mod; all=true)
3030
end
3131
container_mods = map(container_mods) do mod

src/Dialects/Dialects.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
begin
1919
# list dialect operations
20-
local dialectops = mapreduce(mergewith!(), [v14, v15, v16]) do mod
20+
local dialectops = mapreduce(mergewith!(), [v14, v15, v16, v17]) do mod
2121
dialects = filter(names(mod; all=true)) do dialect
2222
dialect [nameof(mod), :eval, :include] && !startswith(string(dialect), '#')
2323
end
@@ -33,11 +33,11 @@ begin
3333
for (dialect, ops) in dialectops
3434
mod = @eval module $dialect
3535
using ...MLIR: MLIR_VERSION, MLIRException
36-
using ..Dialects: v14, v15, v16
36+
using ..Dialects: v14, v15, v16, v17
3737
end
3838

3939
for op in ops
40-
container_mods = filter([v14, v15, v16]) do mod
40+
container_mods = filter([v14, v15, v16, v17]) do mod
4141
dialect in names(mod; all=true) &&
4242
op in names(getproperty(mod, dialect); all=true)
4343
end

src/IR/Pass.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ end
6464
Run the provided `passManager` on the given `module`.
6565
"""
6666
function run!(pm::PassManager, mod::Module)
67-
status = LogicalResult(API.mlirPassManagerRun(pm, mod))
67+
status = if MLIR_VERSION[] >= v"17"
68+
LogicalResult(API.mlirPassManagerRunOnOp(pm, Operation(mod)))
69+
else
70+
LogicalResult(API.mlirPassManagerRun(pm, mod))
71+
end
6872
if isfailure(status)
6973
throw("failed to run pass manager on module")
7074
end

test/executionengine.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ function lowerModuleToLLVM(ctx, mod)
2424
op = "builtin.func"
2525
end
2626
opm = MLIR.API.mlirPassManagerGetNestedUnder(pm, op)
27-
if LLVM.version() >= v"15"
27+
if LLVM.version() >= v"17"
28+
MLIR.API.mlirPassManagerAddOwnedPass(
29+
pm, MLIR.API.mlirCreateConversionConvertFuncToLLVMPass()
30+
)
31+
elseif LLVM.version() >= v"15"
2832
MLIR.API.mlirPassManagerAddOwnedPass(
2933
pm, MLIR.API.mlirCreateConversionConvertFuncToLLVM()
3034
)
@@ -43,7 +47,12 @@ function lowerModuleToLLVM(ctx, mod)
4347
opm, MLIR.API.mlirCreateConversionConvertArithmeticToLLVM()
4448
)
4549
end
46-
status = MLIR.API.mlirPassManagerRun(pm, mod)
50+
status = if LLVM.version() >= v"17"
51+
op = MLIR.API.mlirModuleGetOperation(mod)
52+
MLIR.API.mlirPassManagerRunOnOp(pm, op)
53+
else
54+
MLIR.API.mlirPassManagerRun(pm, mod)
55+
end
4756
# undefined symbol: mlirLogicalResultIsFailure
4857
if status.value == 0
4958
error("Unexpected failure running pass failure")

0 commit comments

Comments
 (0)