From 8c1d3e82fc48cc298b8453755b6d3a99fc660154 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Mon, 7 Oct 2024 18:40:32 -0400 Subject: [PATCH] IRShow: label builtin / intrinsic / dynamic calls in `code_typed` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it much easier to spot dynamic dispatches: ```julia 3 ── %9 = (isa)(%4, @NamedTuple{x::Int64, y})::Bool └─── goto #5 if not %9 4 ── %11 = π (%4, @NamedTuple{x::Int64, y}) └─── goto #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 #5 if not %9 4 ── %11 = π (%4, @NamedTuple{x::Int64, y}) └─── goto #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} ``` --- base/compiler/ssair/show.jl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/base/compiler/ssair/show.jl b/base/compiler/ssair/show.jl index 7d936a1688aba0..d777ced7b5ba42 100644 --- a/base/compiler/ssair/show.jl +++ b/base/compiler/ssair/show.jl @@ -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, "")