Skip to content

Commit 517ad06

Browse files
authored
compiler: Rename :inst -> :stmt (#50868)
As discussed in #49057, this renames the :inst field of `Instruction` to `:stmt` (`:inst` is still allowed for the moment to ease transition for out-of-tree users). I'm hoping to get through some more compiler datastructure cleanup in the 1.11 timeframe, but this is probably one of the larger ones in terms of number of lines affected.
1 parent cbd3c89 commit 517ad06

19 files changed

+566
-556
lines changed

base/compiler/optimize.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
618618
svdef = sv.linfo.def
619619
nargs = isa(svdef, Method) ? Int(svdef.nargs) : 0
620620
@timeit "domtree 1" domtree = construct_domtree(ir.cfg.blocks)
621-
defuse_insts = scan_slot_def_use(nargs, ci, ir.stmts.inst)
621+
defuse_insts = scan_slot_def_use(nargs, ci, ir.stmts.stmt)
622622
𝕃ₒ = optimizer_lattice(sv.inlining.interp)
623623
@timeit "construct_ssa" ir = construct_ssa!(ci, ir, domtree, defuse_insts, sv.slottypes, 𝕃ₒ) # consumes `ir`
624624
# NOTE now we have converted `ir` to the SSA form and eliminated slots
@@ -646,7 +646,7 @@ function statement_cost(ex::Expr, line::Int, src::Union{CodeInfo, IRCode}, sptyp
646646
if ftyp === IntrinsicFunction && farg isa SSAValue
647647
# if this comes from code that was already inlined into another function,
648648
# Consts have been widened. try to recover in simple cases.
649-
farg = isa(src, CodeInfo) ? src.code[farg.id] : src.stmts[farg.id][:inst]
649+
farg = isa(src, CodeInfo) ? src.code[farg.id] : src[farg][:stmt]
650650
if isa(farg, GlobalRef) || isa(farg, QuoteNode) || isa(farg, IntrinsicFunction) || isexpr(farg, :static_parameter)
651651
ftyp = argextype(farg, src, sptypes)
652652
end
@@ -741,7 +741,7 @@ function inline_cost(ir::IRCode, params::OptimizationParams,
741741
cost_threshold::Integer=params.inline_cost_threshold)::InlineCostType
742742
bodycost::Int = 0
743743
for line = 1:length(ir.stmts)
744-
stmt = ir.stmts[line][:inst]
744+
stmt = ir[SSAValue(line)][:stmt]
745745
thiscost = statement_or_branch_cost(stmt, line, ir, ir.sptypes, params)
746746
bodycost = plus_saturate(bodycost, thiscost)
747747
bodycost > cost_threshold && return MAX_INLINE_COST

base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ function analyze_escapes(ir::IRCode, nargs::Int, call_resolved::Bool, get_escape
671671
local anyupdate = false
672672

673673
for pc in nstmts:-1:1
674-
stmt = getinst(ir, pc)[:inst]
674+
stmt = getinst(ir, pc)[:stmt]
675675

676676
# collect escape information
677677
if isa(stmt, Expr)
@@ -784,7 +784,7 @@ function compute_frameinfo(ir::IRCode, call_resolved::Bool)
784784
end
785785
for idx in 1:nstmts+nnewnodes
786786
inst = getinst(ir, idx)
787-
stmt = inst[:inst]
787+
stmt = inst[:stmt]
788788
if !call_resolved
789789
# TODO don't call `check_effect_free!` in the inlinear
790790
check_effect_free!(ir, idx, stmt, inst[:type], 𝕃ₒ)

base/compiler/ssair/inlining.jl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
135135
last_block_idx = last(state.cfg.blocks[block].stmts)
136136
if false # TODO: ((idx+1) == last_block_idx && isa(ir[SSAValue(last_block_idx)], GotoNode))
137137
need_split = false
138-
post_bb_id = -ir[SSAValue(last_block_idx)][:inst].label
138+
post_bb_id = -ir[SSAValue(last_block_idx)][:stmt].label
139139
else
140140
post_bb_id = length(state.new_cfg_blocks) + length(inlinee_cfg.blocks) + (need_split_before ? 1 : 0)
141141
need_split = true #!(idx == last_block_idx)
@@ -196,7 +196,7 @@ function cfg_inline_item!(ir::IRCode, idx::Int, todo::InliningTodo, state::CFGIn
196196
for (old_block, new_block) in enumerate(bb_rename_range)
197197
if (length(state.new_cfg_blocks[new_block].succs) == 0)
198198
terminator_idx = last(inlinee_cfg.blocks[old_block].stmts)
199-
terminator = todo.ir[SSAValue(terminator_idx)][:inst]
199+
terminator = todo.ir[SSAValue(terminator_idx)][:stmt]
200200
if isa(terminator, ReturnNode) && isdefined(terminator, :val)
201201
any_edges = true
202202
push!(state.new_cfg_blocks[new_block].succs, post_bb_id)
@@ -556,7 +556,7 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int, argexprs::
556556
union_split::UnionSplit, boundscheck::Symbol,
557557
todo_bbs::Vector{Tuple{Int,Int}}, params::OptimizationParams)
558558
(; fully_covered, atype, cases, bbs) = union_split
559-
stmt, typ, line = compact.result[idx][:inst], compact.result[idx][:type], compact.result[idx][:line]
559+
stmt, typ, line = compact.result[idx][:stmt], compact.result[idx][:type], compact.result[idx][:line]
560560
join_bb = bbs[end]
561561
pn = PhiNode()
562562
local bb = compact.active_result_bb
@@ -605,9 +605,9 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int, argexprs::
605605
if isa(case, InliningTodo)
606606
val = ir_inline_item!(compact, idx, argexprs′, case, boundscheck, todo_bbs)
607607
elseif isa(case, InvokeCase)
608-
inst = Expr(:invoke, case.invoke, argexprs′...)
608+
invoke_stmt = Expr(:invoke, case.invoke, argexprs′...)
609609
flag = flags_for_effects(case.effects)
610-
val = insert_node_here!(compact, NewInstruction(inst, typ, case.info, line, flag))
610+
val = insert_node_here!(compact, NewInstruction(invoke_stmt, typ, case.info, line, flag))
611611
else
612612
case = case::ConstantCase
613613
val = case.val
@@ -993,7 +993,7 @@ function handle_single_case!(todo::Vector{Pair{Int,Any}},
993993
ir::IRCode, idx::Int, stmt::Expr, @nospecialize(case),
994994
isinvoke::Bool = false)
995995
if isa(case, ConstantCase)
996-
ir[SSAValue(idx)][:inst] = case.val
996+
ir[SSAValue(idx)][:stmt] = case.val
997997
elseif isa(case, InvokeCase)
998998
is_foldable_nothrow(case.effects) && inline_const_if_inlineable!(ir[SSAValue(idx)]) && return nothing
999999
isinvoke && rewrite_invoke_exprargs!(stmt)
@@ -1120,7 +1120,7 @@ function inline_apply!(todo::Vector{Pair{Int,Any}},
11201120
break
11211121
end
11221122
if nonempty_idx != 0
1123-
ir.stmts[idx][:inst] = stmt.args[nonempty_idx]
1123+
ir[SSAValue(idx)][:stmt] = stmt.args[nonempty_idx]
11241124
return nothing
11251125
end
11261126
end
@@ -1236,8 +1236,9 @@ end
12361236
# this method does not access the method table or otherwise process generic
12371237
# functions.
12381238
function process_simple!(todo::Vector{Pair{Int,Any}}, ir::IRCode, idx::Int, state::InliningState)
1239-
stmt = ir.stmts[idx][:inst]
1240-
rt = ir.stmts[idx][:type]
1239+
inst = ir[SSAValue(idx)]
1240+
stmt = inst[:stmt]
1241+
rt = inst[:type]
12411242
if !(stmt isa Expr)
12421243
check_effect_free!(ir, idx, stmt, rt, state)
12431244
return nothing
@@ -1247,7 +1248,7 @@ function process_simple!(todo::Vector{Pair{Int,Any}}, ir::IRCode, idx::Int, stat
12471248
if head === :splatnew
12481249
inline_splatnew!(ir, idx, stmt, rt, state)
12491250
elseif head === :new_opaque_closure
1250-
narrow_opaque_closure!(ir, stmt, ir.stmts[idx][:info], state)
1251+
narrow_opaque_closure!(ir, stmt, inst[:info], state)
12511252
elseif head === :invoke
12521253
sig = call_sig(ir, stmt)
12531254
sig === nothing && return nothing
@@ -1267,14 +1268,14 @@ function process_simple!(todo::Vector{Pair{Int,Any}}, ir::IRCode, idx::Int, stat
12671268
# Check if we match any of the early inliners
12681269
earlyres = early_inline_special_case(ir, stmt, rt, sig, state)
12691270
if isa(earlyres, SomeCase)
1270-
ir.stmts[idx][:inst] = earlyres.val
1271+
inst[:stmt] = earlyres.val
12711272
return nothing
12721273
end
12731274

12741275
if check_effect_free!(ir, idx, stmt, rt, state)
12751276
if sig.f === typeassert || (optimizer_lattice(state.interp), sig.ft, typeof(typeassert))
12761277
# typeassert is a no-op if effect free
1277-
ir.stmts[idx][:inst] = stmt.args[2]
1278+
inst[:stmt] = stmt.args[2]
12781279
return nothing
12791280
end
12801281
end
@@ -1288,7 +1289,7 @@ function process_simple!(todo::Vector{Pair{Int,Any}}, ir::IRCode, idx::Int, stat
12881289
# Special case inliners for regular functions
12891290
lateres = late_inline_special_case!(ir, idx, stmt, rt, sig, state)
12901291
if isa(lateres, SomeCase)
1291-
ir[SSAValue(idx)][:inst] = lateres.val
1292+
inst[:stmt] = lateres.val
12921293
check_effect_free!(ir, idx, lateres.val, rt, state)
12931294
return nothing
12941295
end
@@ -1576,7 +1577,7 @@ function handle_modifyfield!_call!(ir::IRCode, idx::Int, stmt::Expr, info::Modif
15761577
case === nothing && return nothing
15771578
stmt.head = :invoke_modify
15781579
pushfirst!(stmt.args, case.invoke)
1579-
ir.stmts[idx][:inst] = stmt
1580+
ir[SSAValue(idx)][:stmt] = stmt
15801581
return nothing
15811582
end
15821583

@@ -1636,7 +1637,7 @@ end
16361637
function inline_const_if_inlineable!(inst::Instruction)
16371638
rt = inst[:type]
16381639
if rt isa Const && is_inlineable_constant(rt.val)
1639-
inst[:inst] = quoted(rt.val)
1640+
inst[:stmt] = quoted(rt.val)
16401641
return true
16411642
end
16421643
inst[:flag] |= IR_FLAG_EFFECT_FREE | IR_FLAG_NOTHROW
@@ -1691,7 +1692,7 @@ end
16911692

16921693
function linear_inline_eligible(ir::IRCode)
16931694
length(ir.cfg.blocks) == 1 || return false
1694-
terminator = ir[SSAValue(last(ir.cfg.blocks[1].stmts))][:inst]
1695+
terminator = ir[SSAValue(last(ir.cfg.blocks[1].stmts))][:stmt]
16951696
isa(terminator, ReturnNode) || return false
16961697
isdefined(terminator, :val) || return false
16971698
return true

0 commit comments

Comments
 (0)