Skip to content

Commit 94d07a6

Browse files
committed
use ir.meta as a place for holding assume_bindings_static configuration
1 parent 1892913 commit 94d07a6

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

base/compiler/optimize.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ function new_expr_effect_flags(𝕃ₒ::AbstractLattice, args::Vector{Any}, src:
288288
return (false, true, true)
289289
end
290290

291-
assume_bindings_static(ir::IRCode) = ir.assume_bindings_static
292-
assume_bindings_static(compact::IncrementalCompact) = assume_bindings_static(compact.ir)
293-
294291
"""
295292
stmt_effect_flags(stmt, rt, src::Union{IRCode,IncrementalCompact}) ->
296293
(consistent::Bool, removable::Bool, nothrow::Bool)
@@ -1247,19 +1244,18 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
12471244
renumber_cfg_stmts!(sv.cfg, blockchangemap)
12481245
end
12491246

1250-
meta = process_meta!(code)
1247+
meta = process_meta!(code, InferenceParams(sv.inlining.interp).assume_bindings_static)
12511248
strip_trailing_junk!(code, ssavaluetypes, ssaflags, di, sv.cfg, stmtinfo)
12521249
types = Any[]
12531250
stmts = InstructionStream(code, types, stmtinfo, codelocs, ssaflags)
12541251
# NOTE this `argtypes` contains types of slots yet: it will be modified to contain the
12551252
# types of call arguments only once `slot2reg` converts this `IRCode` to the SSA form
12561253
# and eliminates slots (see below)
12571254
argtypes = sv.slottypes
1258-
return IRCode(stmts, sv.cfg, di, argtypes, meta, sv.sptypes,
1259-
InferenceParams(sv.inlining.interp).assume_bindings_static)
1255+
return IRCode(stmts, sv.cfg, di, argtypes, meta, sv.sptypes)
12601256
end
12611257

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

1274+
function assume_bindings_static(ir::IRCode)
1275+
for node = ir.meta
1276+
node.head === :meta && break
1277+
if node.head === :assume_bindings_static
1278+
return node.args[1]::Bool
1279+
end
1280+
end
1281+
return false
1282+
end
1283+
assume_bindings_static(compact::IncrementalCompact) = assume_bindings_static(compact.ir)
1284+
12741285
function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
12751286
# need `ci` for the slot metadata, IR for the code
12761287
svdef = sv.linfo.def

base/compiler/ssair/ir.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,15 @@ struct IRCode
428428
cfg::CFG
429429
new_nodes::NewNodeStream
430430
meta::Vector{Expr}
431-
assume_bindings_static::Bool # XXX propagate `interp::AbstractInterpreter` here?
432431

433432
function IRCode(stmts::InstructionStream, cfg::CFG, debuginfo::DebugInfoStream,
434-
argtypes::Vector{Any}, meta::Vector{Expr}, sptypes::Vector{VarState},
435-
assume_bindings_static::Bool=false)
436-
return new(stmts, argtypes, sptypes, debuginfo, cfg, NewNodeStream(), meta, assume_bindings_static)
433+
argtypes::Vector{Any}, meta::Vector{Expr}, sptypes::Vector{VarState})
434+
return new(stmts, argtypes, sptypes, debuginfo, cfg, NewNodeStream(), meta)
437435
end
438436
function IRCode(ir::IRCode, stmts::InstructionStream, cfg::CFG, new_nodes::NewNodeStream)
439437
di = ir.debuginfo
440438
@assert di.codelocs === stmts.line
441-
return new(stmts, ir.argtypes, ir.sptypes, di, cfg, new_nodes, ir.meta, ir.assume_bindings_static)
439+
return new(stmts, ir.argtypes, ir.sptypes, di, cfg, new_nodes, ir.meta)
442440
end
443441
global function copy(ir::IRCode)
444442
di = ir.debuginfo
@@ -447,7 +445,7 @@ struct IRCode
447445
di.edges = copy(di.edges)
448446
di.codelocs = stmts.line
449447
return new(stmts, copy(ir.argtypes), copy(ir.sptypes), di, copy(ir.cfg),
450-
copy(ir.new_nodes), copy(ir.meta), ir.assume_bindings_static)
448+
copy(ir.new_nodes), copy(ir.meta))
451449
end
452450
end
453451

base/compiler/ssair/legacy.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode)
7676
ssaflags = ci.ssaflags = stmts.flag
7777
debuginfo = ir.debuginfo
7878
for metanode in ir.meta
79+
metanode.head === :meta || continue
7980
push!(code, metanode)
8081
push!(codelocs, 1, 0, 0)
8182
push!(ssavaluetypes, Any)

0 commit comments

Comments
 (0)