Skip to content

Commit 4dd47a7

Browse files
vtjnashKristofferC
authored andcommitted
inference: remove code that relies upon inferring the output type
Recursing into inference may be unreliable during inference. (cherry picked from commit cb5a5bc)
1 parent 28ce0a4 commit 4dd47a7

File tree

5 files changed

+16
-49
lines changed

5 files changed

+16
-49
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function inline_into_block!(state::CFGInliningState, block::Int)
109109
new_range = state.first_bb+1:block
110110
l = length(state.new_cfg_blocks)
111111
state.bb_rename[new_range] = (l+1:l+length(new_range))
112-
append!(state.new_cfg_blocks, map(copy, state.cfg.blocks[new_range]))
112+
append!(state.new_cfg_blocks, (copy(block) for block in state.cfg.blocks[new_range]))
113113
push!(state.merged_orig_blocks, last(new_range))
114114
end
115115
state.first_bb = block

base/compiler/ssair/passes.jl

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,6 @@ function try_compute_fieldidx_expr(@nospecialize(typ), @nospecialize(use_expr))
2626
return try_compute_fieldidx(typ, field)
2727
end
2828

29-
function lift_defuse(cfg::CFG, ssa::SSADefUse)
30-
# We remove from `uses` any block where all uses are dominated
31-
# by a def. This prevents insertion of dead phi nodes at the top
32-
# of such a block if that block happens to be in a loop
33-
ordered = Tuple{Int, Int, Bool}[(x, block_for_inst(cfg, x), true) for x in ssa.uses]
34-
for x in ssa.defs
35-
push!(ordered, (x, block_for_inst(cfg, x), false))
36-
end
37-
ordered = sort(ordered, by=x->x[1])
38-
bb_defs = Int[]
39-
bb_uses = Int[]
40-
last_bb = last_def_bb = 0
41-
for (_, bb, is_use) in ordered
42-
if bb != last_bb && is_use
43-
push!(bb_uses, bb)
44-
end
45-
last_bb = bb
46-
if last_def_bb != bb && !is_use
47-
push!(bb_defs, bb)
48-
last_def_bb = bb
49-
end
50-
end
51-
SSADefUse(bb_uses, bb_defs, Int[])
52-
end
53-
5429
function find_curblock(domtree::DomTree, allblocks::Vector{Int}, curblock::Int)
5530
# TODO: This can be much faster by looking at current level and only
5631
# searching for those blocks in a sorted order
@@ -1205,12 +1180,12 @@ function cfg_simplify!(ir::IRCode)
12051180
# Compute (renamed) successors and predecessors given (renamed) block
12061181
function compute_succs(i)
12071182
orig_bb = follow_merged_succ(result_bbs[i])
1208-
return map(i -> bb_rename_succ[i], bbs[orig_bb].succs)
1183+
return Int[bb_rename_succ[i] for i in bbs[orig_bb].succs]
12091184
end
12101185
function compute_preds(i)
12111186
orig_bb = result_bbs[i]
12121187
preds = bbs[orig_bb].preds
1213-
return map(pred -> bb_rename_pred[pred], preds)
1188+
return Int[bb_rename_pred[pred] for pred in preds]
12141189
end
12151190

12161191
BasicBlock[

base/compiler/ssair/show.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ show_unquoted(io::IO, val::Argument, indent::Int, prec::Int) = show_unquoted(io,
7979

8080
show_unquoted(io::IO, stmt::PhiNode, indent::Int, ::Int) = show_unquoted_phinode(io, stmt, indent, "%")
8181
function show_unquoted_phinode(io::IO, stmt::PhiNode, indent::Int, prefix::String)
82-
args = map(1:length(stmt.edges)) do i
82+
args = String[let
8383
e = stmt.edges[i]
8484
v = !isassigned(stmt.values, i) ? "#undef" :
8585
sprint() do io′
8686
show_unquoted(io′, stmt.values[i], indent)
8787
end
88-
return "$prefix$e => $v"
89-
end
88+
"$prefix$e => $v"
89+
end for i in 1:length(stmt.edges)
90+
]
9091
print(io, "φ ", '(')
9192
join(io, args, ", ")
9293
print(io, ')')

base/compiler/ssair/slot2ssa.jl

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ function scan_entry!(result::Vector{SlotInfo}, idx::Int, @nospecialize(stmt))
3333
end
3434

3535

36-
function lift_defuse(cfg::CFG, defuse)
37-
map(defuse) do slot
38-
SlotInfo(
39-
Int[block_for_inst(cfg, x) for x in slot.defs],
40-
Int[block_for_inst(cfg, x) for x in slot.uses],
41-
slot.any_newvar
42-
)
43-
end
44-
end
45-
4636
function scan_slot_def_use(nargs::Int, ci::CodeInfo, code::Vector{Any})
4737
nslots = length(ci.slotflags)
4838
result = SlotInfo[SlotInfo() for i = 1:nslots]
@@ -523,7 +513,7 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
523513
return new_ir
524514
end
525515

526-
function compute_live_ins(cfg::CFG, defuse)
516+
function compute_live_ins(cfg::CFG, defuse #=::Union{SlotInfo,SSADefUse}=#)
527517
# We remove from `uses` any block where all uses are dominated
528518
# by a def. This prevents insertion of dead phi nodes at the top
529519
# of such a block if that block happens to be in a loop
@@ -585,8 +575,8 @@ function recompute_type(node::Union{PhiNode, PhiCNode}, ci::CodeInfo, ir::IRCode
585575
return new_typ
586576
end
587577

588-
function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, nargs::Int,
589-
slottypes::Vector{Any})
578+
function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree,
579+
defuses::Vector{SlotInfo}, nargs::Int, slottypes::Vector{Any})
590580
code = ir.stmts.inst
591581
cfg = ir.cfg
592582
left = Int[]
@@ -615,7 +605,7 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, narg
615605
for (_, exc) in catch_entry_blocks
616606
phicnodes[exc] = Vector{Tuple{SlotNumber, NewSSAValue, PhiCNode}}()
617607
end
618-
@timeit "idf" for (idx, slot) in Iterators.enumerate(defuse)
608+
@timeit "idf" for (idx, slot) in Iterators.enumerate(defuses)
619609
# No uses => no need for phi nodes
620610
isempty(slot.uses) && continue
621611
# TODO: Restore this optimization
@@ -670,9 +660,9 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, narg
670660
end
671661
# Perform SSA renaming
672662
initial_incoming_vals = Any[
673-
if 0 in defuse[x].defs
663+
if 0 in defuses[x].defs
674664
Argument(x)
675-
elseif !defuse[x].any_newvar
665+
elseif !defuses[x].any_newvar
676666
undef_token
677667
else
678668
SSAValue(-2)

src/gf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,15 @@ static void reset_mt_caches(jl_methtable_t *mt, void *env)
493493

494494

495495
jl_function_t *jl_typeinf_func = NULL;
496-
size_t jl_typeinf_world = 0;
496+
size_t jl_typeinf_world = 1;
497497

498498
JL_DLLEXPORT void jl_set_typeinf_func(jl_value_t *f)
499499
{
500+
size_t newfunc = jl_typeinf_world == 1 && jl_typeinf_func == NULL;
500501
jl_typeinf_func = (jl_function_t*)f;
501502
jl_typeinf_world = jl_get_tls_world_age();
502503
++jl_world_counter; // make type-inference the only thing in this world
503-
if (jl_typeinf_world == 0) {
504+
if (0 && newfunc) {
504505
// give type inference a chance to see all of these
505506
// TODO: also reinfer if max_world != ~(size_t)0
506507
jl_array_t *unspec = jl_alloc_vec_any(0);

0 commit comments

Comments
 (0)