Skip to content

Commit

Permalink
use ir.meta as a place for holding assume_bindings_static configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
aviatesk committed May 9, 2024
1 parent 1892913 commit 94d07a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
25 changes: 18 additions & 7 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ function new_expr_effect_flags(𝕃ₒ::AbstractLattice, args::Vector{Any}, src:
return (false, true, true)
end

assume_bindings_static(ir::IRCode) = ir.assume_bindings_static
assume_bindings_static(compact::IncrementalCompact) = assume_bindings_static(compact.ir)

"""
stmt_effect_flags(stmt, rt, src::Union{IRCode,IncrementalCompact}) ->
(consistent::Bool, removable::Bool, nothrow::Bool)
Expand Down Expand Up @@ -1247,19 +1244,18 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
renumber_cfg_stmts!(sv.cfg, blockchangemap)
end

meta = process_meta!(code)
meta = process_meta!(code, InferenceParams(sv.inlining.interp).assume_bindings_static)
strip_trailing_junk!(code, ssavaluetypes, ssaflags, di, sv.cfg, stmtinfo)
types = Any[]
stmts = InstructionStream(code, types, stmtinfo, codelocs, ssaflags)
# NOTE this `argtypes` contains types of slots yet: it will be modified to contain the
# types of call arguments only once `slot2reg` converts this `IRCode` to the SSA form
# and eliminates slots (see below)
argtypes = sv.slottypes
return IRCode(stmts, sv.cfg, di, argtypes, meta, sv.sptypes,
InferenceParams(sv.inlining.interp).assume_bindings_static)
return IRCode(stmts, sv.cfg, di, argtypes, meta, sv.sptypes)
end

function process_meta!(code::Vector{Any})
function process_meta!(code::Vector{Any}, assume_bindings_static::Bool)
meta = Expr[]
for i = 1:length(code)
stmt = code[i]
Expand All @@ -1268,9 +1264,24 @@ function process_meta!(code::Vector{Any})
code[i] = nothing
end
end
# Temporarily put the configurations of `AbstractInterpreter` that created this `IRCode`
# into `meta::Vector{Any}`, making it accessible for various optimization passes.
# The `replace_code_newstyle!` needs to filter out these temporary nodes inserted here.
pushfirst!(meta, Expr(:assume_bindings_static, assume_bindings_static))
return meta
end

function assume_bindings_static(ir::IRCode)
for node = ir.meta
node.head === :meta && break
if node.head === :assume_bindings_static
return node.args[1]::Bool
end
end
return false
end
assume_bindings_static(compact::IncrementalCompact) = assume_bindings_static(compact.ir)

function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
# need `ci` for the slot metadata, IR for the code
svdef = sv.linfo.def
Expand Down
10 changes: 4 additions & 6 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,15 @@ struct IRCode
cfg::CFG
new_nodes::NewNodeStream
meta::Vector{Expr}
assume_bindings_static::Bool # XXX propagate `interp::AbstractInterpreter` here?

function IRCode(stmts::InstructionStream, cfg::CFG, debuginfo::DebugInfoStream,
argtypes::Vector{Any}, meta::Vector{Expr}, sptypes::Vector{VarState},
assume_bindings_static::Bool=false)
return new(stmts, argtypes, sptypes, debuginfo, cfg, NewNodeStream(), meta, assume_bindings_static)
argtypes::Vector{Any}, meta::Vector{Expr}, sptypes::Vector{VarState})
return new(stmts, argtypes, sptypes, debuginfo, cfg, NewNodeStream(), meta)
end
function IRCode(ir::IRCode, stmts::InstructionStream, cfg::CFG, new_nodes::NewNodeStream)
di = ir.debuginfo
@assert di.codelocs === stmts.line
return new(stmts, ir.argtypes, ir.sptypes, di, cfg, new_nodes, ir.meta, ir.assume_bindings_static)
return new(stmts, ir.argtypes, ir.sptypes, di, cfg, new_nodes, ir.meta)
end
global function copy(ir::IRCode)
di = ir.debuginfo
Expand All @@ -447,7 +445,7 @@ struct IRCode
di.edges = copy(di.edges)
di.codelocs = stmts.line
return new(stmts, copy(ir.argtypes), copy(ir.sptypes), di, copy(ir.cfg),
copy(ir.new_nodes), copy(ir.meta), ir.assume_bindings_static)
copy(ir.new_nodes), copy(ir.meta))
end
end

Expand Down
1 change: 1 addition & 0 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode)
ssaflags = ci.ssaflags = stmts.flag
debuginfo = ir.debuginfo
for metanode in ir.meta
metanode.head === :meta || continue
push!(code, metanode)
push!(codelocs, 1, 0, 0)
push!(ssavaluetypes, Any)
Expand Down

0 comments on commit 94d07a6

Please sign in to comment.