From 55615080470959f9d3decd6bef617d874dc4abb5 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Fri, 6 May 2022 18:43:10 +0900 Subject: [PATCH] type stronger `ir.meta::Vector{Expr}` (#45204) --- base/compiler/optimize.jl | 20 +++++++------------- base/compiler/ssair/ir.jl | 4 ++-- base/compiler/ssair/legacy.jl | 2 +- test/compiler/ssair.jl | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/base/compiler/optimize.jl b/base/compiler/optimize.jl index fd3e3fff493c3..195e8c39f9af0 100644 --- a/base/compiler/optimize.jl +++ b/base/compiler/optimize.jl @@ -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 @@ -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) @@ -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 diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl index 6de79ada5d0ed..2dd42e3a2ec7d 100644 --- a/base/compiler/ssair/ir.jl +++ b/base/compiler/ssair/ir.jl @@ -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) diff --git a/base/compiler/ssair/legacy.jl b/base/compiler/ssair/legacy.jl index 3d91646fa05f7..ffafa77d8fc58 100644 --- a/base/compiler/ssair/legacy.jl +++ b/base/compiler/ssair/legacy.jl @@ -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 diff --git a/test/compiler/ssair.jl b/test/compiler/ssair.jl index ffb48a9de38e9..0328d78652e6f 100644 --- a/test/compiler/ssair.jl +++ b/test/compiler/ssair.jl @@ -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