Skip to content

Commit

Permalink
add simple test cases for [post-]domination analysis (#46860)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Sep 22, 2022
1 parent 45623a8 commit ea9914e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Core.IR
const Compiler = Core.Compiler
using .Compiler: CFG, BasicBlock, NewSSAValue

include(normpath(@__DIR__, "irutils.jl"))

make_bb(preds, succs) = BasicBlock(Compiler.StmtRange(0, 0), preds, succs)

function make_ci(code)
Expand Down Expand Up @@ -417,3 +419,45 @@ let

test_userefs(body)
end

let ir = Base.code_ircode((Bool,Any)) do c, x
println(x, 1) #1
if c
println(x, 2) #2
else
println(x, 3) #3
end
println(x, 4) #4
end |> only |> first
# IR legality check
@test length(ir.cfg.blocks) == 4
for i = 1:4
@test any(ir.cfg.blocks[i].stmts) do j
inst = ir.stmts[j][:inst]
iscall((ir, println), inst) &&
inst.args[3] == i
end
end
# domination analysis
domtree = Core.Compiler.construct_domtree(ir.cfg.blocks)
@test Core.Compiler.dominates(domtree, 1, 2)
@test Core.Compiler.dominates(domtree, 1, 3)
@test Core.Compiler.dominates(domtree, 1, 4)
for i = 2:4
for j = 1:4
i == j && continue
@test !Core.Compiler.dominates(domtree, i, j)
end
end
# post domination analysis
post_domtree = Core.Compiler.construct_postdomtree(ir.cfg.blocks)
@test Core.Compiler.postdominates(post_domtree, 4, 1)
@test Core.Compiler.postdominates(post_domtree, 4, 2)
@test Core.Compiler.postdominates(post_domtree, 4, 3)
for i = 1:3
for j = 1:4
i == j && continue
@test !Core.Compiler.postdominates(post_domtree, i, j)
end
end
end

0 comments on commit ea9914e

Please sign in to comment.