Skip to content

Commit 38edc38

Browse files
committed
Show basic block statement ranges in CFG output.
1 parent dccf331 commit 38edc38

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

base/compiler/ssair/show.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ import Base: show_unquoted
1616
using Base: printstyled, with_output_color, prec_decl, @invoke
1717

1818
function Base.show(io::IO, cfg::CFG)
19+
print(io, "CFG with $(length(cfg.blocks)) blocks:")
1920
for (idx, block) in enumerate(cfg.blocks)
20-
print(io, idx, "\t=>\t")
21-
join(io, block.succs, ", ")
22-
println(io)
21+
print(io, "\n bb ", idx)
22+
if block.stmts.start == block.stmts.stop
23+
print(io, " (stmt ", block.stmts.start, ")")
24+
else
25+
print(io, " (stmts ", block.stmts.start, ":", block.stmts.stop, ")")
26+
end
27+
if !isempty(block.succs)
28+
print(io, " → bb ")
29+
join(io, block.succs, ", ")
30+
end
2331
end
2432
end
2533

test/show.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,3 +2485,17 @@ end
24852485
ir = Core.Compiler.complete(compact)
24862486
@test lines_shown(compact) == instructions + 1
24872487
end
2488+
2489+
@testset "IRCode: CFG display" begin
2490+
# get a cfg
2491+
function foo(i)
2492+
j = i+42
2493+
j == 1 ? 1 : 2
2494+
end
2495+
ir = only(Base.code_ircode(foo, (Int,)))[1]
2496+
cfg = ir.cfg
2497+
2498+
str = sprint(io->show(io, cfg))
2499+
@test contains(str, r"CFG with \d+ blocks")
2500+
@test contains(str, r"bb 1 \(stmt.+\) ⇨ bb.*")
2501+
end

0 commit comments

Comments
 (0)