Skip to content

Remove TypedSlot annotation in compiler #50299

Closed
@Keno

Description

@Keno

The annotate_slot_load! function here:

function annotate_slot_load!(interp::AbstractInterpreter, undefs::Vector{Bool}, idx::Int, sv::InferenceState, @nospecialize x)
if isa(x, SlotNumber)
id = slot_id(x)
pc = find_dominating_assignment(id, idx, sv)
if pc === nothing
block = block_for_inst(sv.cfg, idx)
state = sv.bb_vartables[block]::VarTable
vt = state[id]
undefs[id] |= vt.undef
typ = widenslotwrapper(ignorelimited(vt.typ))
else
typ = sv.ssavaluetypes[pc]
@assert typ !== NOT_FOUND "active slot in unreached region"
end
# add type annotations where needed
if !(typeinf_lattice(interp), sv.slottypes[id], typ)
return TypedSlot(id, typ)
end
return x
elseif isa(x, Expr)
head = x.head
i0 = 1
if is_meta_expr_head(head) || head === :const
return x
end
if head === :(=) || head === :method
i0 = 2
end
for i = i0:length(x.args)
x.args[i] = annotate_slot_load!(interp, undefs, idx, sv, x.args[i])
end
return x
elseif isa(x, ReturnNode) && isdefined(x, :val)
return ReturnNode(annotate_slot_load!(interp, undefs, idx, sv, x.val))
elseif isa(x, GotoIfNot)
return GotoIfNot(annotate_slot_load!(interp, undefs, idx, sv, x.cond), x.dest)
end
return x
end

Shows up prominently in profiles, but the work it does is mostly redundant with SSA construction and it is algorithmically much slower.

Currently, the only thing we're using the TypedSlot annotation that this function inserts for is PiNodes. These days, this information is stored in the bb_vartables:

bb_vartables::Vector{Union{Nothing,VarTable}} # nothing if not analyzed yet

Rather than doing the TypedSlot insertion, we could pass down the bb_vartables through OptimizerState into the ssa construction code and use it for PiNode insertion directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:optimizerOptimization passes (mostly in base/compiler/ssair/)good first issueIndicates a good issue for first-time contributors to Julia

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions