@@ -2,27 +2,34 @@ module EAUtils
22
33export code_escapes, @code_escapes , __clear_cache!
44
5- const CC = Core. Compiler
5+ if ! @isdefined (Compiler)
6+ if Base. identify_package (" Compiler" ) === nothing
7+ import Base. Compiler: Compiler
8+ else
9+ import Compiler
10+ end
11+ end
12+
613using .. EscapeAnalysis
714const EA = EscapeAnalysis
815
916# AbstractInterpreter
1017# -------------------
1118
1219# imports
13- import . CC :
20+ import . Compiler :
1421 AbstractInterpreter, NativeInterpreter, WorldView, WorldRange, InferenceParams,
1522 OptimizationParams, get_world_counter, get_inference_cache, ipo_dataflow_analysis!
1623# usings
1724using Core:
1825 CodeInstance, MethodInstance, CodeInfo
19- using . CC :
26+ using . Compiler :
2027 InferenceResult, InferenceState, OptimizationState, IRCode
2128using . EA: analyze_escapes, ArgEscapeCache, ArgEscapeInfo, EscapeInfo, EscapeState
2229
2330struct EAToken end
2431
25- # when working outside of Core.Compiler ,
32+ # when working outside of CC ,
2633# cache entire escape state for later inspection and debugging
2734struct EscapeCacheInfo
2835 argescapes:: ArgEscapeCache
@@ -59,18 +66,18 @@ mutable struct EscapeAnalyzer <: AbstractInterpreter
5966 end
6067end
6168
62- CC . InferenceParams (interp:: EscapeAnalyzer ) = interp. inf_params
63- CC . OptimizationParams (interp:: EscapeAnalyzer ) = interp. opt_params
64- CC . get_inference_world (interp:: EscapeAnalyzer ) = interp. world
65- CC . get_inference_cache (interp:: EscapeAnalyzer ) = interp. inf_cache
66- CC . cache_owner (:: EscapeAnalyzer ) = EAToken ()
67- CC . get_escape_cache (interp:: EscapeAnalyzer ) = GetEscapeCache (interp)
69+ Compiler . InferenceParams (interp:: EscapeAnalyzer ) = interp. inf_params
70+ Compiler . OptimizationParams (interp:: EscapeAnalyzer ) = interp. opt_params
71+ Compiler . get_inference_world (interp:: EscapeAnalyzer ) = interp. world
72+ Compiler . get_inference_cache (interp:: EscapeAnalyzer ) = interp. inf_cache
73+ Compiler . cache_owner (:: EscapeAnalyzer ) = EAToken ()
74+ Compiler . get_escape_cache (interp:: EscapeAnalyzer ) = GetEscapeCache (interp)
6875
69- function CC . ipo_dataflow_analysis! (interp:: EscapeAnalyzer , opt:: OptimizationState ,
76+ function Compiler . ipo_dataflow_analysis! (interp:: EscapeAnalyzer , opt:: OptimizationState ,
7077 ir:: IRCode , caller:: InferenceResult )
7178 # run EA on all frames that have been optimized
7279 nargs = Int (opt. src. nargs)
73- 𝕃ₒ = CC . optimizer_lattice (interp)
80+ 𝕃ₒ = Compiler . optimizer_lattice (interp)
7481 get_escape_cache = GetEscapeCache (interp)
7582 estate = try
7683 analyze_escapes (ir, nargs, 𝕃ₒ, get_escape_cache)
@@ -82,19 +89,19 @@ function CC.ipo_dataflow_analysis!(interp::EscapeAnalyzer, opt::OptimizationStat
8289 end
8390 if caller. linfo === interp. entry_mi
8491 # return back the result
85- interp. result = EscapeResultForEntry (CC . copy (ir), estate, caller. linfo)
92+ interp. result = EscapeResultForEntry (Compiler . copy (ir), estate, caller. linfo)
8693 end
8794 record_escapes! (interp, caller, estate, ir)
8895
89- @invoke CC . ipo_dataflow_analysis! (interp:: AbstractInterpreter , opt:: OptimizationState ,
96+ @invoke Compiler . ipo_dataflow_analysis! (interp:: AbstractInterpreter , opt:: OptimizationState ,
9097 ir:: IRCode , caller:: InferenceResult )
9198end
9299
93100function record_escapes! (interp:: EscapeAnalyzer ,
94101 caller:: InferenceResult , estate:: EscapeState , ir:: IRCode )
95102 argescapes = ArgEscapeCache (estate)
96103 ecacheinfo = EscapeCacheInfo (argescapes, estate, ir)
97- return CC . stack_analysis_result! (caller, ecacheinfo)
104+ return Compiler . stack_analysis_result! (caller, ecacheinfo)
98105end
99106
100107struct GetEscapeCache
@@ -113,19 +120,19 @@ struct FailedAnalysis
113120 get_escape_cache:: GetEscapeCache
114121end
115122
116- function CC . finish! (interp:: EscapeAnalyzer , state:: InferenceState ; can_discard_trees:: Bool = CC . may_discard_trees (interp))
117- ecacheinfo = CC . traverse_analysis_results (state. result) do @nospecialize result
123+ function Compiler . finish! (interp:: EscapeAnalyzer , state:: InferenceState ; can_discard_trees:: Bool = Compiler . may_discard_trees (interp))
124+ ecacheinfo = Compiler . traverse_analysis_results (state. result) do @nospecialize result
118125 return result isa EscapeCacheInfo ? result : nothing
119126 end
120127 ecacheinfo isa EscapeCacheInfo && (interp. escape_cache. cache[state. linfo] = ecacheinfo)
121- return @invoke CC . finish! (interp:: AbstractInterpreter , state:: InferenceState ; can_discard_trees)
128+ return @invoke Compiler . finish! (interp:: AbstractInterpreter , state:: InferenceState ; can_discard_trees)
122129end
123130
124131# printing
125132# --------
126133
127134using Core: Argument, SSAValue
128- using . CC : widenconst, singleton_type
135+ using . Compiler : widenconst, singleton_type
129136
130137function get_name_color (x:: EscapeInfo , symbol:: Bool = false )
131138 getname (x) = string (nameof (x))
@@ -323,15 +330,15 @@ function code_escapes(@nospecialize(f), @nospecialize(types=Base.default_tt(f));
323330 debuginfo:: Symbol = :none )
324331 tt = Base. signature_type (f, types)
325332 match = Base. _which (tt; world, raise= true )
326- mi = Core . Compiler. specialize_method (match)
333+ mi = Compiler. specialize_method (match)
327334 return code_escapes (mi; world, debuginfo)
328335end
329336
330337function code_escapes (mi:: MethodInstance ;
331338 world:: UInt = get_world_counter (),
332339 interp:: EscapeAnalyzer = EscapeAnalyzer (world, GLOBAL_ESCAPE_CACHE; entry_mi= mi),
333340 debuginfo:: Symbol = :none )
334- frame = Core . Compiler. typeinf_frame (interp, mi, #= run_optimizer=# true )
341+ frame = Compiler. typeinf_frame (interp, mi, #= run_optimizer=# true )
335342 isdefined (interp, :result ) || error (" optimization didn't happen: maybe everything has been constant folded?" )
336343 slotnames = let src = frame. src
337344 src isa CodeInfo ? src. slotnames : nothing
@@ -357,7 +364,7 @@ Note that this version does not cache the analysis results.
357364function code_escapes (ir:: IRCode , nargs:: Int ;
358365 world:: UInt = get_world_counter (),
359366 interp:: AbstractInterpreter = EscapeAnalyzer (world, EscapeCache ()))
360- estate = analyze_escapes (ir, nargs, CC . optimizer_lattice (interp), CC . get_escape_cache (interp))
367+ estate = analyze_escapes (ir, nargs, Compiler . optimizer_lattice (interp), Compiler . get_escape_cache (interp))
361368 return EscapeResult (ir, estate) # return back the result
362369end
363370
0 commit comments