Skip to content

Commit

Permalink
type stronger ir.meta::Vector{Expr} (#45204)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored May 6, 2022
1 parent 3ee4bb1 commit 5561508
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
20 changes: 7 additions & 13 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
(; def, specTypes) = linfo

analyzed = nothing # `ConstAPI` if this call can use constant calling convention
force_noinline = _any(@nospecialize(x) -> isexpr(x, :meta) && x.args[1] === :noinline, ir.meta)
force_noinline = _any(x::Expr -> x.head === :meta && x.args[1] === :noinline, ir.meta)

# compute inlining and other related optimizations
result = caller.result
Expand Down Expand Up @@ -613,9 +613,9 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
end
renumber_ir_elements!(code, changemap, labelmap)

meta = Any[]
meta = Expr[]
for i = 1:length(code)
code[i] = remove_meta!(code[i], meta)
code[i] = process_meta!(meta, code[i])
end
strip_trailing_junk!(ci, code, stmtinfo)
cfg = compute_basic_blocks(code)
Expand All @@ -627,16 +627,10 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
return ir
end

function remove_meta!(@nospecialize(stmt), meta::Vector{Any})
if isa(stmt, Expr)
head = stmt.head
if head === :meta
args = stmt.args
if length(args) > 0
push!(meta, stmt)
end
return nothing
end
function process_meta!(meta::Vector{Expr}, @nospecialize stmt)
if isexpr(stmt, :meta) && length(stmt.args) 1
push!(meta, stmt)
return nothing
end
return stmt
end
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ struct IRCode
linetable::Vector{LineInfoNode}
cfg::CFG
new_nodes::NewNodeStream
meta::Vector{Any}
meta::Vector{Expr}

function IRCode(stmts::InstructionStream, cfg::CFG, linetable::Vector{LineInfoNode}, argtypes::Vector{Any}, meta::Vector{Any}, sptypes::Vector{Any})
function IRCode(stmts::InstructionStream, cfg::CFG, linetable::Vector{LineInfoNode}, argtypes::Vector{Any}, meta::Vector{Expr}, sptypes::Vector{Any})
return new(stmts, argtypes, sptypes, linetable, cfg, NewNodeStream(), meta)
end
function IRCode(ir::IRCode, stmts::InstructionStream, cfg::CFG, new_nodes::NewNodeStream)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function inflate_ir(ci::CodeInfo, sptypes::Vector{Any}, argtypes::Vector{Any})
ssavaluetypes isa Vector{Any} ? copy(ssavaluetypes) : Any[ Any for i = 1:(ssavaluetypes::Int) ]
end
stmts = InstructionStream(code, ssavaluetypes, Any[nothing for i = 1:nstmts], copy(ci.codelocs), copy(ci.ssaflags))
ir = IRCode(stmts, cfg, collect(LineInfoNode, ci.linetable), argtypes, Any[], sptypes)
ir = IRCode(stmts, cfg, collect(LineInfoNode, ci.linetable), argtypes, Expr[], sptypes)
return ir
end

Expand Down
2 changes: 1 addition & 1 deletion test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let cfg = CFG(BasicBlock[
make_bb([2, 3] , [] ),
], Int[])
insts = Compiler.InstructionStream([], [], Any[], Int32[], UInt8[])
code = Compiler.IRCode(insts, cfg, LineInfoNode[], [], [], [])
code = Compiler.IRCode(insts, cfg, LineInfoNode[], [], Expr[], [])
compact = Compiler.IncrementalCompact(code, true)
@test length(compact.result_bbs) == 4 && 0 in compact.result_bbs[3].preds
end
Expand Down

0 comments on commit 5561508

Please sign in to comment.