Skip to content

Commit

Permalink
IRShow: label builtin / intrinsic / dynamic calls in code_typed
Browse files Browse the repository at this point in the history
This makes it much easier to spot dynamic dispatches:
```julia
3 ── %9  = (isa)(%4, @NamedTuple{x::Int64, y})::Bool
└───       goto JuliaLang#5 if not %9
4 ── %11 = π (%4, @NamedTuple{x::Int64, y})
└───       goto JuliaLang#6
5 ── %13 = (Tuple{Int64, Any})(%4)::Tuple{Int64, Any}
│    %14 = (getfield)(%13, 1)::Int64
│    %15 = (getfield)(%13, 2)::Any
│    %16 = %new(@NamedTuple{x::Int64, y}, %14, %15)::@NamedTuple{x::Int64, y}
```

is now:
```julia
3 ── %9  = builtin (isa)(%4, @NamedTuple{x::Int64, y})::Bool
└───       goto JuliaLang#5 if not %9
4 ── %11 = π (%4, @NamedTuple{x::Int64, y})
└───       goto JuliaLang#6
5 ── %13 = dynamic (Tuple{Int64, Any})(%4)::Tuple{Int64, Any}
│    %14 = builtin (getfield)(%13, 1)::Int64
│    %15 = builtin (getfield)(%13, 2)::Any
│    %16 = %new(@NamedTuple{x::Int64, y}, %14, %15)::@NamedTuple{x::Int64, y}
```
  • Loading branch information
topolarity committed Oct 7, 2024
1 parent d4987a3 commit 8c1d3e8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxleng
end
join(io, (print_arg(i) for i = 3:length(stmt.args)), ", ")
print(io, ")")
elseif isexpr(stmt, :call) && length(stmt.args) >= 1
arg1 = stmt.args[1]
if arg1 isa GlobalRef && isdefined(arg1.mod, arg1.name)
arg1 = getfield(arg1.mod, arg1.name)
end
if isa(arg1, Core.IntrinsicFunction)
print(io, "intrinsic ")
elseif isa(arg1, Core.Builtin)
print(io, "builtin ")
else
print(io, "dynamic ")
end
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0)
# given control flow information, we prefer to print these with the basic block #, instead of the ssa %
elseif isa(stmt, EnterNode)
print(io, "enter #", stmt.catch_dest, "")
Expand Down

0 comments on commit 8c1d3e8

Please sign in to comment.