@@ -144,14 +144,15 @@ const SLOT_USEDUNDEF = 32 # slot has uses that might raise UndefVarError
144144
145145# This statement is marked as @inbounds by user.
146146# Ff replaced by inlining, any contained boundschecks may be removed.
147- const IR_FLAG_INBOUNDS = 0x01 << 0
147+ const IR_FLAG_INBOUNDS = 0x01 << 0
148148# This statement is marked as @inline by user
149- const IR_FLAG_INLINE = 0x01 << 1
149+ const IR_FLAG_INLINE = 0x01 << 1
150150# This statement is marked as @noinline by user
151- const IR_FLAG_NOINLINE = 0x01 << 2
151+ const IR_FLAG_NOINLINE = 0x01 << 2
152+ const IR_FLAG_THROW_BLOCK = 0x01 << 3
152153# This statement may be removed if its result is unused. In particular it must
153154# thus be both pure and effect free.
154- const IR_FLAG_EFFECT_FREE = 0x01 << 4
155+ const IR_FLAG_EFFECT_FREE = 0x01 << 4
155156
156157# known to be always effect-free (in particular nothrow)
157158const _PURE_BUILTINS = Any[tuple, svec, === , typeof, nfields]
@@ -194,8 +195,9 @@ function isinlineable(m::Method, me::OptimizationState, params::OptimizationPara
194195 return inlineable
195196end
196197
197- is_stmt_inline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_INLINE != 0
198- is_stmt_noinline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_NOINLINE != 0
198+ is_stmt_inline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_INLINE ≠ 0
199+ is_stmt_noinline (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_NOINLINE ≠ 0
200+ is_stmt_throw_block (stmt_flag:: UInt8 ) = stmt_flag & IR_FLAG_THROW_BLOCK ≠ 0
199201
200202# These affect control flow within the function (so may not be removed
201203# if there is no usage within the function), but don't affect the purity
@@ -533,13 +535,12 @@ function statement_cost(ex::Expr, line::Int, src::Union{CodeInfo, IRCode}, sptyp
533535end
534536
535537function statement_or_branch_cost (@nospecialize (stmt), line:: Int , src:: Union{CodeInfo, IRCode} , sptypes:: Vector{Any} ,
536- slottypes:: Vector{Any} , union_penalties:: Bool , params:: OptimizationParams ,
537- throw_blocks:: Union{Nothing,BitSet} )
538+ slottypes:: Vector{Any} , union_penalties:: Bool , params:: OptimizationParams )
538539 thiscost = 0
539540 dst (tgt) = isa (src, IRCode) ? first (src. cfg. blocks[tgt]. stmts) : tgt
540541 if stmt isa Expr
541542 thiscost = statement_cost (stmt, line, src, sptypes, slottypes, union_penalties, params,
542- throw_blocks != = nothing && line in throw_blocks ):: Int
543+ is_stmt_throw_block ( isa (src, IRCode) ? src . stmts . flag[ line] : src . ssaflags[line]) ):: Int
543544 elseif stmt isa GotoNode
544545 # loops are generally always expensive
545546 # but assume that forward jumps are already counted for from
@@ -554,24 +555,22 @@ end
554555function inline_worthy (ir:: IRCode ,
555556 params:: OptimizationParams , union_penalties:: Bool = false , cost_threshold:: Integer = params. inline_cost_threshold)
556557 bodycost:: Int = 0
557- throw_blocks = params. unoptimize_throw_blocks ? find_throw_blocks (ir. stmts. inst, RefValue (ir)) : nothing
558558 for line = 1 : length (ir. stmts)
559559 stmt = ir. stmts[line][:inst ]
560- thiscost = statement_or_branch_cost (stmt, line, ir, ir. sptypes, ir. argtypes, union_penalties, params, throw_blocks )
560+ thiscost = statement_or_branch_cost (stmt, line, ir, ir. sptypes, ir. argtypes, union_penalties, params)
561561 bodycost = plus_saturate (bodycost, thiscost)
562562 bodycost > cost_threshold && return false
563563 end
564564 return true
565565end
566566
567567function statement_costs! (cost:: Vector{Int} , body:: Vector{Any} , src:: Union{CodeInfo, IRCode} , sptypes:: Vector{Any} , unionpenalties:: Bool , params:: OptimizationParams )
568- throw_blocks = params. unoptimize_throw_blocks ? find_throw_blocks (body) : nothing
569568 maxcost = 0
570569 for line = 1 : length (body)
571570 stmt = body[line]
572571 thiscost = statement_or_branch_cost (stmt, line, src, sptypes,
573572 src isa CodeInfo ? src. slottypes : src. argtypes,
574- unionpenalties, params, throw_blocks )
573+ unionpenalties, params)
575574 cost[line] = thiscost
576575 if thiscost > maxcost
577576 maxcost = thiscost
0 commit comments