Skip to content

Commit 0d7d0ac

Browse files
committed
Show basic block statement ranges in CFG output.
1 parent 1c172e1 commit 0d7d0ac

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
@@ -2448,3 +2448,17 @@ end
24482448
end
24492449
@test contains(str, "%1 = \e[31m%7")
24502450
end
2451+
2452+
@testset "IRCode: CFG display" begin
2453+
# get a cfg
2454+
function foo(i)
2455+
j = i+42
2456+
j == 1 ? 1 : 2
2457+
end
2458+
ir = only(Base.code_ircode(foo, (Int,)))[1]
2459+
cfg = ir.cfg
2460+
2461+
str = sprint(io->show(io, cfg))
2462+
@test contains(str, r"CFG with \d+ blocks")
2463+
@test contains(str, r"bb 1 \(stmt.+\) → bb.*")
2464+
end

0 commit comments

Comments
 (0)