@@ -1018,14 +1018,16 @@ function optimize(interp::AbstractInterpreter, opt::OptimizationState, caller::I
10181018 return finish (interp, opt, ir, caller)
10191019end
10201020
1021- macro pass (name, expr)
1021+ const ALL_PASS_NAMES = String[]
1022+ macro pass (name:: String , expr)
10221023 optimize_until = esc (:optimize_until )
10231024 stage = esc (:__stage__ )
1024- macrocall = :(@timeit $ ( esc ( name)) $ (esc (expr)))
1025+ macrocall = :(@timeit $ name $ (esc (expr)))
10251026 macrocall. args[2 ] = __source__ # `@timeit` may want to use it
1027+ push! (ALL_PASS_NAMES, name)
10261028 quote
10271029 $ macrocall
1028- matchpass ($ optimize_until, ($ stage += 1 ), $ ( esc ( name)) ) && $ (esc (:(@goto __done__)))
1030+ matchpass ($ optimize_until, ($ stage += 1 ), $ name) && $ (esc (:(@goto __done__)))
10291031 end
10301032end
10311033
@@ -1036,8 +1038,12 @@ matchpass(::Nothing, _, _) = false
10361038function run_passes_ipo_safe (
10371039 ci:: CodeInfo ,
10381040 sv:: OptimizationState ,
1039- optimize_until = nothing , # run all passes by default
1041+ optimize_until:: Union{Nothing, Int, String} = nothing , # run all passes by default
10401042)
1043+ if optimize_until isa String && ! (optimize_until in ALL_PASS_NAMES)
1044+ error (" invalid `optimize_until` argument, no such optimization pass" )
1045+ end
1046+
10411047 __stage__ = 0 # used by @pass
10421048 # NOTE: The pass name MUST be unique for `optimize_until::String` to work
10431049 @pass " convert" ir = convert_to_ircode (ci, sv)
0 commit comments