@@ -2,27 +2,34 @@ module EAUtils
2
2
3
3
export code_escapes, @code_escapes , __clear_cache!
4
4
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
+
6
13
using .. EscapeAnalysis
7
14
const EA = EscapeAnalysis
8
15
9
16
# AbstractInterpreter
10
17
# -------------------
11
18
12
19
# imports
13
- import . CC :
20
+ import . Compiler :
14
21
AbstractInterpreter, NativeInterpreter, WorldView, WorldRange, InferenceParams,
15
22
OptimizationParams, get_world_counter, get_inference_cache, ipo_dataflow_analysis!
16
23
# usings
17
24
using Core:
18
25
CodeInstance, MethodInstance, CodeInfo
19
- using . CC :
26
+ using . Compiler :
20
27
InferenceResult, InferenceState, OptimizationState, IRCode
21
28
using . EA: analyze_escapes, ArgEscapeCache, ArgEscapeInfo, EscapeInfo, EscapeState
22
29
23
30
struct EAToken end
24
31
25
- # when working outside of Core.Compiler ,
32
+ # when working outside of CC ,
26
33
# cache entire escape state for later inspection and debugging
27
34
struct EscapeCacheInfo
28
35
argescapes:: ArgEscapeCache
@@ -59,18 +66,18 @@ mutable struct EscapeAnalyzer <: AbstractInterpreter
59
66
end
60
67
end
61
68
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)
68
75
69
- function CC . ipo_dataflow_analysis! (interp:: EscapeAnalyzer , opt:: OptimizationState ,
76
+ function Compiler . ipo_dataflow_analysis! (interp:: EscapeAnalyzer , opt:: OptimizationState ,
70
77
ir:: IRCode , caller:: InferenceResult )
71
78
# run EA on all frames that have been optimized
72
79
nargs = Int (opt. src. nargs)
73
- 𝕃ₒ = CC . optimizer_lattice (interp)
80
+ 𝕃ₒ = Compiler . optimizer_lattice (interp)
74
81
get_escape_cache = GetEscapeCache (interp)
75
82
estate = try
76
83
analyze_escapes (ir, nargs, 𝕃ₒ, get_escape_cache)
@@ -82,19 +89,19 @@ function CC.ipo_dataflow_analysis!(interp::EscapeAnalyzer, opt::OptimizationStat
82
89
end
83
90
if caller. linfo === interp. entry_mi
84
91
# return back the result
85
- interp. result = EscapeResultForEntry (CC . copy (ir), estate, caller. linfo)
92
+ interp. result = EscapeResultForEntry (Compiler . copy (ir), estate, caller. linfo)
86
93
end
87
94
record_escapes! (interp, caller, estate, ir)
88
95
89
- @invoke CC . ipo_dataflow_analysis! (interp:: AbstractInterpreter , opt:: OptimizationState ,
96
+ @invoke Compiler . ipo_dataflow_analysis! (interp:: AbstractInterpreter , opt:: OptimizationState ,
90
97
ir:: IRCode , caller:: InferenceResult )
91
98
end
92
99
93
100
function record_escapes! (interp:: EscapeAnalyzer ,
94
101
caller:: InferenceResult , estate:: EscapeState , ir:: IRCode )
95
102
argescapes = ArgEscapeCache (estate)
96
103
ecacheinfo = EscapeCacheInfo (argescapes, estate, ir)
97
- return CC . stack_analysis_result! (caller, ecacheinfo)
104
+ return Compiler . stack_analysis_result! (caller, ecacheinfo)
98
105
end
99
106
100
107
struct GetEscapeCache
@@ -113,19 +120,19 @@ struct FailedAnalysis
113
120
get_escape_cache:: GetEscapeCache
114
121
end
115
122
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
118
125
return result isa EscapeCacheInfo ? result : nothing
119
126
end
120
127
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)
122
129
end
123
130
124
131
# printing
125
132
# --------
126
133
127
134
using Core: Argument, SSAValue
128
- using . CC : widenconst, singleton_type
135
+ using . Compiler : widenconst, singleton_type
129
136
130
137
function get_name_color (x:: EscapeInfo , symbol:: Bool = false )
131
138
getname (x) = string (nameof (x))
@@ -323,15 +330,15 @@ function code_escapes(@nospecialize(f), @nospecialize(types=Base.default_tt(f));
323
330
debuginfo:: Symbol = :none )
324
331
tt = Base. signature_type (f, types)
325
332
match = Base. _which (tt; world, raise= true )
326
- mi = Core . Compiler. specialize_method (match)
333
+ mi = Compiler. specialize_method (match)
327
334
return code_escapes (mi; world, debuginfo)
328
335
end
329
336
330
337
function code_escapes (mi:: MethodInstance ;
331
338
world:: UInt = get_world_counter (),
332
339
interp:: EscapeAnalyzer = EscapeAnalyzer (world, GLOBAL_ESCAPE_CACHE; entry_mi= mi),
333
340
debuginfo:: Symbol = :none )
334
- frame = Core . Compiler. typeinf_frame (interp, mi, #= run_optimizer=# true )
341
+ frame = Compiler. typeinf_frame (interp, mi, #= run_optimizer=# true )
335
342
isdefined (interp, :result ) || error (" optimization didn't happen: maybe everything has been constant folded?" )
336
343
slotnames = let src = frame. src
337
344
src isa CodeInfo ? src. slotnames : nothing
@@ -357,7 +364,7 @@ Note that this version does not cache the analysis results.
357
364
function code_escapes (ir:: IRCode , nargs:: Int ;
358
365
world:: UInt = get_world_counter (),
359
366
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))
361
368
return EscapeResult (ir, estate) # return back the result
362
369
end
363
370
0 commit comments