Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ir: Add IR_FLAG_UNUSED #54300

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,11 @@ struct RTEffects
end

function abstract_call(interp::AbstractInterpreter, arginfo::ArgInfo, sv::InferenceState)
si = StmtInfo(!call_result_unused(sv, sv.currpc))
unused = call_result_unused(sv, sv.currpc)
if unused
add_curr_ssaflag!(sv, IR_FLAG_UNUSED)
end
si = StmtInfo(!unused)
call = abstract_call(interp, arginfo, si, sv)
sv.stmt_info[sv.currpc] = call.info
return call
Expand Down
4 changes: 3 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ const IR_FLAG_NOUB = one(UInt32) << 9
const IR_FLAG_EFIIMO = one(UInt32) << 10
# This statement is :inaccessiblememonly == INACCESSIBLEMEM_OR_ARGMEMONLY
const IR_FLAG_INACCESSIBLEMEM_OR_ARGMEM = one(UInt32) << 11
# This statement has no users and may be deleted if flags get refined to IR_FLAGS_REMOVABLE
const IR_FLAG_UNUSED = one(UInt32) << 12

const NUM_IR_FLAGS = 12 # sync with julia.h
const NUM_IR_FLAGS = 13 # sync with julia.h

const IR_FLAGS_EFFECTS =
IR_FLAG_CONSISTENT | IR_FLAG_EFFECT_FREE | IR_FLAG_NOTHROW | IR_FLAG_TERMINATES | IR_FLAG_NOUB
Expand Down
5 changes: 4 additions & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,10 @@ function maybe_erase_unused!(callback::Function, compact::IncrementalCompact, id
stmt = inst[:stmt]
stmt === nothing && return false
inst[:type] === Bottom && return false
has_flag(inst, IR_FLAGS_REMOVABLE) || return false
if !has_flag(inst, IR_FLAGS_REMOVABLE)
add_flag!(inst, IR_FLAG_UNUSED)
return false
end
foreachssa(stmt) do val::SSAValue
if compact.used_ssas[val.id] == 1
if val.id < idx || in_worklist
Expand Down
7 changes: 7 additions & 0 deletions base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ function reprocess_instruction!(interp::AbstractInterpreter, inst::Instruction,
rt = argextype(stmt, irsv.ir)
end
if rt !== nothing
if has_flag(inst, IR_FLAG_UNUSED)
# Don't bother checking the type if we know it's unused
if has_flag(inst, IR_FLAGS_REMOVABLE)
inst[:stmt] = nothing
end
return false
end
if isa(rt, Const)
inst[:type] = rt
if is_inlineable_constant(rt.val) && has_flag(inst, IR_FLAGS_REMOVABLE)
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ typedef union __jl_purity_overrides_t {
} _jl_purity_overrides_t;

#define NUM_EFFECTS_OVERRIDES 9
#define NUM_IR_FLAGS 12
#define NUM_IR_FLAGS 13

// This type describes a single function body
typedef struct _jl_code_info_t {
Expand Down