From ca1c47e8d4af399f006316d39b4c612c8a73babc Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 30 Sep 2022 10:01:29 +0200 Subject: [PATCH] Show basic block statement ranges in CFG output. --- base/compiler/ssair/show.jl | 14 +++++++++++--- test/show.jl | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/base/compiler/ssair/show.jl b/base/compiler/ssair/show.jl index b490713c3190d..5f3df8d83429d 100644 --- a/base/compiler/ssair/show.jl +++ b/base/compiler/ssair/show.jl @@ -16,10 +16,18 @@ import Base: show_unquoted using Base: printstyled, with_output_color, prec_decl, @invoke function Base.show(io::IO, cfg::CFG) + print(io, "CFG with $(length(cfg.blocks)) blocks:") for (idx, block) in enumerate(cfg.blocks) - print(io, idx, "\t=>\t") - join(io, block.succs, ", ") - println(io) + print(io, "\n bb ", idx) + if block.stmts.start == block.stmts.stop + print(io, " (stmt ", block.stmts.start, ")") + else + print(io, " (stmts ", block.stmts.start, ":", block.stmts.stop, ")") + end + if !isempty(block.succs) + print(io, " → bb ") + join(io, block.succs, ", ") + end end end diff --git a/test/show.jl b/test/show.jl index bdcfa3895f593..6cf5b35001f61 100644 --- a/test/show.jl +++ b/test/show.jl @@ -2516,3 +2516,17 @@ end ir = Core.Compiler.complete(compact) verify_display(ir) end + +@testset "IRCode: CFG display" begin + # get a cfg + function foo(i) + j = i+42 + j == 1 ? 1 : 2 + end + ir = only(Base.code_ircode(foo, (Int,)))[1] + cfg = ir.cfg + + str = sprint(io->show(io, cfg)) + @test contains(str, r"CFG with \d+ blocks") + @test contains(str, r"bb 1 \(stmt.+\) → bb.*") +end