Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/CthulhuBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const ArgTypes = Vector{Any}

using Base: get_world_counter

get_mi(ci::CodeInstance) = CC.get_ci_mi(ci)

Base.@kwdef mutable struct CthulhuConfig
enable_highlighter::Bool = false
highlighter::Cmd = `pygmentize -l`
asm_syntax::Symbol = :att
dead_code_elimination::Bool = true
pretty_ast::Bool = false
interruptexc::Bool = true
debuginfo::Symbol = :compact
Expand Down Expand Up @@ -57,9 +58,6 @@ end
code as stdin. Defaults to `$(CthulhuConfig().highlighter)`.
- `asm_syntax::Symbol`: Set the syntax of assembly code being used.
Defaults to `$(CthulhuConfig().asm_syntax)`.
- `dead_code_elimination::Bool`: Enable dead-code elimination for high-level Julia IR.
Defaults to `true`. DCE is known to be buggy and you may want to disable it if you
encounter errors. Please report such bugs with a MWE to Julia or Cthulhu.
- `pretty_ast::Bool`: Use a pretty printer for the ast dump. Defaults to `false`.
- `interruptexc::Bool`: Use <q>-key to quit or ascend. Defaults to `false`.
- `debuginfo::Symbol`: Initial state of "debuginfo" toggle. Defaults to `:compact`.
Expand Down Expand Up @@ -339,7 +337,7 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
(; src, rt, exct, infos, slottypes, codeinf, effects) = lookup_semiconcrete(interp, curs, override, optimize & !annotate_source)
else
if optimize && !annotate_source
codeinst = curs.ci
codeinst = get_ci(curs)
if codeinst.inferred === nothing
if isdefined(codeinst, :rettype_const)
# TODO use `codeinfo_for_const`
Expand All @@ -354,28 +352,30 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
println(iostream, "│ return ", Const(codeinst.rettype_const))
println(iostream)
end
mi = codeinst.def
mi = get_mi(codeinst)
@goto show_menu
else
@info """
Inference discarded the source for this call because of recursion:
Cthulhu nevertheless is trying to retrieve the source for further inspection.
"""
additional_descend(get_ci(curs))
break
ci = get_ci(curs)
if !haskey(interp.unopt, ci)
additional_descend(ci)
break
else
(; src, rt, exct, infos, slottypes, effects, codeinf) = lookup_unoptimized(interp, ci)
optimize = false
@goto lookup_complete
end
end
end
end
(; src, rt, exct, infos, slottypes, effects, codeinf) = lookup(interp, curs, optimize & !annotate_source)
end
@label lookup_complete
ci = get_ci(curs)
mi = ci.def
src = preprocess_ci!(src, mi, optimize & !annotate_source, CONFIG)
if (optimize & !annotate_source) || isa(src, IRCode) # optimization might have deleted some statements
infos = src.stmts.info
else
@assert length(src.code) == length(infos)
end
mi = get_mi(ci)
infkey = override isa InferenceResult ? override : ci
pc2excts = exception_type ? get_pc_exct(interp, infkey) : nothing
callsites, sourcenodes = find_callsites(interp, src, infos, ci, slottypes, optimize & !annotate_source, annotate_source, pc2excts)
Expand Down Expand Up @@ -507,7 +507,7 @@ function _descend(term::AbstractTerminal, interp::AbstractInterpreter, curs::Abs
Inference didn't analyze this call because it is a dynamic call:
Cthulhu nevertheless is trying to descend into it for further inspection.
"""
additional_descend(get_mi(info)::CodeInstance)
additional_descend(get_ci(info)::CodeInstance)
continue
elseif info isa RTCallInfo
@info """
Expand Down
11 changes: 0 additions & 11 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@ function add_callsites!(d::AbstractDict, visited_cis::AbstractSet, diagnostics::
callsites, src, rt = try
(; src, rt, infos, slottypes, effects, codeinf) = lookup(interp, ci, optimize & !annotate_source)

src = preprocess_ci!(src, mi, optimize & !annotate_source, CONFIG)
if (optimize & !annotate_source) || isa(src, IRCode) # optimization might have deleted some statements
infos = src.stmts.info
else
@assert length(src.code) == length(infos)
end

# We pass false as it doesn't affect callsites and skips fetching the method definition
# using CodeTracking which is slow
callsites, _ = find_callsites(interp, src, infos, ci, slottypes, optimize & !annotate_source, false)
Expand Down Expand Up @@ -429,10 +422,6 @@ end
function InteractiveUtils.code_typed(b::Bookmark; optimize::Bool=true)
(; interp, ci) = b
(; src, rt, codeinf) = lookup(interp, ci, optimize)
src = preprocess_ci!(src, ci.def, optimize, CONFIG)
if src isa IRCode
CC.replace_code_newstyle!(codeinf, src)
end
return codeinf => rt
end

Expand Down
2 changes: 0 additions & 2 deletions src/preferences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function save_config!(config::CthulhuConfig=CONFIG)
"enable_highlighter" => config.enable_highlighter,
"highlighter" => config.highlighter.exec,
"asm_syntax" => String(config.asm_syntax),
"dead_code_elimination" => config.dead_code_elimination,
"pretty_ast" => config.pretty_ast,
"debuginfo" => String(config.debuginfo),
"optimize" => config.optimize,
Expand All @@ -45,7 +44,6 @@ function read_config!(config::CthulhuConfig)
config.enable_highlighter = @load_preference("enable_highlighter", config.enable_highlighter)
config.highlighter = Cmd(@load_preference("highlighter", config.highlighter))
config.asm_syntax = Symbol(@load_preference("asm_syntax", config.asm_syntax))
config.dead_code_elimination = @load_preference("dead_code_elimination", config.dead_code_elimination)
config.pretty_ast = @load_preference("pretty_ast", config.pretty_ast)
config.debuginfo = Symbol(@load_preference("debuginfo", config.debuginfo))
config.optimize = @load_preference("optimize", config.optimize)
Expand Down
24 changes: 0 additions & 24 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,6 @@ function is_call_expr(x::Expr, optimize::Bool)
return isexpr(ignorelhs(x), :call)
end

function dce!(ir::IRCode)
ir = CC.compact!(ir, #=allow_cfg_transform=#true)
ir = CC.compact!(ir, #=allow_cfg_transform=#true)
return ir
end

function preprocess_ci!(ci::CodeInfo, mi::MethodInstance, optimize, config::CthulhuConfig)
if optimize && config.dead_code_elimination
argtypes = CC.matching_cache_argtypes(mi, nothing, false)[1]
ir = CC.inflate_ir(ci, sptypes_from_meth_instance(mi), argtypes)
ir = dce!(ir)
ci = CC.replace_code_newstyle!(ci, ir)
end
return ci
end

function preprocess_ci!(ir::IRCode, _::MethodInstance, optimize::Bool, config::CthulhuConfig)
if optimize && config.dead_code_elimination
ir = dce!(ir)
end
return ir
end

function callinfo(interp, sig, rt, max_methods=-1; world=get_world_counter())
methds = Base._methods_by_ftype(sig, max_methods, world)
methds isa Bool && return FailedCallInfo(sig, rt)
Expand Down Expand Up @@ -315,7 +292,6 @@ function find_caller_of(interp::AbstractInterpreter, callee::Union{MethodInstanc
locs = Tuple{Core.LineInfoNode,Int}[]
for optimize in (true, false)
(; src, rt, infos, slottypes) = lookup(interp′, codeinst, optimize)
src = preprocess_ci!(src, caller, optimize, CONFIG)
callsites, _ = find_callsites(interp′, src, infos, codeinst, slottypes, optimize)
callsites = allow_unspecialized ? filter(cs->maybe_callsite(cs, callee), callsites) :
filter(cs->is_callsite(cs, callee), callsites)
Expand Down
4 changes: 0 additions & 4 deletions test/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ function cthulhu_info(@nospecialize(f), @nospecialize(tt=());
(interp, codeinst) = Cthulhu.mkinterp(f, tt; interp)
(; src, rt, exct, infos, slottypes, effects) =
Cthulhu.lookup(interp, codeinst, optimize; allow_no_src=true)
if src !== nothing
config = Cthulhu.CthulhuConfig(; dead_code_elimination=true)
src = Cthulhu.preprocess_ci!(src, codeinst.def, optimize, config)
end
return (; interp, src, infos, codeinst, rt, exct, slottypes, effects)
end

Expand Down
Loading