Skip to content

Commit

Permalink
[NewOptimizer] Hook up printing, print linetable
Browse files Browse the repository at this point in the history
This hooks up printing for the new IR and teaches it to print the
linetable. In printing a linetable, I tried to strike a balance
between verboseness (I think the old printing and our printing of LLVM IR
is significantly too verbose). There's a description of the idea in
show.jl
  • Loading branch information
Keno committed May 22, 2018
1 parent 0961ee3 commit 61b75ef
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 114 deletions.
2 changes: 1 addition & 1 deletion base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function just_construct_ssa(ci::CodeInfo, code::Vector{Any}, nargs::Int, linetab
@timeit "domtree 1" domtree = construct_domtree(cfg)
ir = let code = Any[nothing for _ = 1:length(code)]
argtypes = ci.slottypes[1:(nargs+1)]
IRCode(code, Any[], lines, flags, cfg, argtypes, mod, meta)
IRCode(code, Any[], lines, flags, cfg, linetable, argtypes, mod, meta)
end
@timeit "construct_ssa" ir = construct_ssa!(ci, code, ir, domtree, defuse_insts, nargs)
return ir
Expand Down
24 changes: 20 additions & 4 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,19 @@ struct IRCode
lines::Vector{Int}
flags::Vector{UInt8}
argtypes::Vector{Any}
linetable::Vector{LineInfoNode}
cfg::CFG
new_nodes::Vector{NewNode}
mod::Module
meta::Vector{Any}

function IRCode(stmts::Vector{Any}, types::Vector{Any}, lines::Vector{Int}, flags::Vector{UInt8},
cfg::CFG, argtypes::Vector{Any}, mod::Module, meta::Vector{Any})
return new(stmts, types, lines, flags, argtypes, cfg, NewNode[], mod, meta)
cfg::CFG, linetable::Vector{LineInfoNode}, argtypes::Vector{Any}, mod::Module, meta::Vector{Any})
return new(stmts, types, lines, flags, argtypes, linetable, cfg, NewNode[], mod, meta)
end
function IRCode(ir::IRCode, stmts::Vector{Any}, types::Vector{Any}, lines::Vector{Int}, flags::Vector{UInt8},
cfg::CFG, new_nodes::Vector{NewNode})
return new(stmts, types, lines, flags, ir.argtypes, cfg, new_nodes, ir.mod, ir.meta)
return new(stmts, types, lines, flags, ir.argtypes, ir.linetable, cfg, new_nodes, ir.mod, ir.meta)
end
end

Expand Down Expand Up @@ -336,7 +337,22 @@ iterate(it::UseRefIterator) = (it.use[1].op = 0; iterate(it, nothing))
end
end

function scan_ssa_use!(used, @nospecialize(stmt))
# This function is used from the show code, which may have a different
# `push!`/`used` type since it's in Base.
function scan_ssa_use!(push!, used, @nospecialize(stmt))
if isa(stmt, SSAValue)
push!(used, stmt.id)
end
for useref in userefs(stmt)
val = useref[]
if isa(val, SSAValue)
push!(used, val.id)
end
end
end

# Manually specialized copy of the above with push! === Compiler.push!
function scan_ssa_use!(used::IdSet, @nospecialize(stmt))
if isa(stmt, SSAValue)
push!(used, stmt.id)
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function inflate_ir(ci::CodeInfo)
code[i] = stmt
end
end
ir = IRCode(code, copy(ci.ssavaluetypes), copy(ci.codelocs), copy(ci.ssaflags), cfg, copy(ci.slottypes), ci.linetable[1].mod, Any[])
ir = IRCode(code, copy(ci.ssavaluetypes), copy(ci.codelocs), copy(ci.ssaflags), cfg, ci.linetable, copy(ci.slottypes), ci.linetable[1].mod, Any[])
return ir
end

Expand Down
Loading

0 comments on commit 61b75ef

Please sign in to comment.