diff --git a/base/compiler/optimize.jl b/base/compiler/optimize.jl index d977b819ea20c..9328873bf7509 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -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) @@ -1247,7 +1244,7 @@ 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) @@ -1255,11 +1252,10 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState) # 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] @@ -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 diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl index 7a8d3c140e311..97def5a64c11a 100644 --- a/base/compiler/ssair/ir.jl +++ b/base/compiler/ssair/ir.jl @@ -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 @@ -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 diff --git a/base/compiler/ssair/legacy.jl b/base/compiler/ssair/legacy.jl index b45db03875801..fb7dee5169009 100644 --- a/base/compiler/ssair/legacy.jl +++ b/base/compiler/ssair/legacy.jl @@ -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)