Skip to content

Commit

Permalink
add support for EnterNode
Browse files Browse the repository at this point in the history
the EnterNode struct was added in JuliaLang/julia#52300
This commit adds support for ingesting and exporting CodeInfo with EnterNode
but still uses `Expr(:enter)` inside IRTools IR. We may want to switch
the representation to `IRTools.EnterNode` similarly to `IRTools.Slot` if
more fields are added to the `Core.EnterNode` struct.
  • Loading branch information
Pangoraw committed Dec 4, 2023
1 parent 6a9638c commit 11a4bc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/ir/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ end

function print_stmt(io::IO, ::Val{:enter}, ex)
print(io, "try #$(ex.args[1])")
if length(ex.args) >= 2
print(io, " with scope ", ex.args[2])
end
end

function print_stmt(io::IO, ::Val{:leave}, ex)
Expand Down
17 changes: 15 additions & 2 deletions src/ir/wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import Core.Compiler: IRCode, CFG, GotoIfNot, ReturnNode, StmtRange
import Core.Compiler: InstructionStream
end

@static if VERSION v"1.11.0-DEV.989"
isenter(ex) = ex isa Core.EnterNode
enter_catch_dest(ex) = ex.catch_dest
else
isenter(ex) = isexpr(ex, :enter)
enter_catch_dest(ex) = ex.args[1]
end

unvars(ex) = prewalk(x -> x isa Variable ? SSAValue(x.id) : x, ex)

function IRCode(ir::IR)
Expand All @@ -29,6 +37,9 @@ function IRCode(ir::IR)
for (v, st) in b
defs[v] = Variable(length(stmts)+1)
ex = varmap(x -> get(defs, x, x), st.expr) |> unvars
@static if VERSION v"1.11.0-DEV.989"
ex = isexpr(ex, :enter) ? Core.EnterNode(ex.args...) : ex
end
push!(stmts, ex)
push!(types, st.type)
push!(lines, st.line)
Expand Down Expand Up @@ -130,8 +141,10 @@ function IR(ci::CodeInfo, nargs::Integer; meta = nothing)
ex = ci.code[i]
if ex isa Core.NewvarNode
continue
elseif isexpr(ex, :enter)
_rename[Core.SSAValue(i)] = push!(ir, Expr(:enter, findfirst(==(ex.args[1]), bs)+1))
elseif isenter(ex)
enter_expr = Expr(:enter, findfirst(==(enter_catch_dest(ex)), bs)+1)
isdefined(ex, :scope) && push!(enter_expr.args, ex.scope)
_rename[Core.SSAValue(i)] = push!(ir, enter_expr)
elseif ex isa GotoNode
branch!(ir, findfirst(==(ex.label), bs)+1)
elseif isgotoifnot(ex)
Expand Down

0 comments on commit 11a4bc3

Please sign in to comment.