forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass_pipeline_library.py
124 lines (101 loc) · 2.87 KB
/
pass_pipeline_library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import pass_pipeline as ppipe
import passes as p
def simplifycfg_silcombine_passlist():
return ppipe.PassList([
p.SimplifyCFG,
p.SILCombine,
p.SimplifyCFG,
])
def highlevel_loopopt_passlist():
return ppipe.PassList([
p.LowerAggregateInstrs,
p.SILCombine,
p.SROA,
p.Mem2Reg,
p.DCE,
p.SILCombine,
simplifycfg_silcombine_passlist(),
p.LoopRotate,
p.DCE,
p.CSE,
p.SILCombine,
p.SimplifyCFG,
p.ABCOpt,
p.DCE,
p.COWArrayOpts,
p.DCE,
p.SwiftArrayOpts,
])
def lowlevel_loopopt_passlist():
return ppipe.PassList([
p.LICM,
p.DCE,
p.CSE,
p.SILCombine,
p.SimplifyCFG,
])
def inliner_for_optlevel(optlevel):
if optlevel == 'high':
return p.EarlyInliner
elif optlevel == 'mid':
return p.PerfInliner
elif optlevel == 'low':
return p.LateInliner
else:
raise RuntimeError('Unknown opt level')
def ssapass_passlist(optlevel):
return ppipe.PassList([
simplifycfg_silcombine_passlist(),
p.AllocBoxToStack,
p.CopyForwarding,
p.LowerAggregateInstrs,
p.SILCombine,
p.SROA,
p.Mem2Reg,
p.PerformanceConstantPropagation,
p.DCE,
p.CSE,
p.SILCombine,
simplifycfg_silcombine_passlist(),
p.GlobalLoadStoreOpts,
# Need to add proper argument here
p.CodeMotion,
p.GlobalARCOpts,
p.SpeculativeDevirtualizer,
p.SILLinker,
inliner_for_optlevel(optlevel),
p.SimplifyCFG,
p.CodeMotion,
p.GlobalARCOpts,
])
def lower_passlist():
return ppipe.PassList([
p.DeadFunctionElimination,
p.DeadObjectElimination,
p.GlobalOpt,
p.CapturePropagation,
p.ClosureSpecializer,
p.SpeculativeDevirtualizer,
p.FunctionSignatureOpts,
])
def normal_passpipelines():
result = []
x = ppipe.PassPipeline('HighLevel', {'name': 'run_n_times', 'count': 2})
x.add_pass(ssapass_passlist('high'))
result.append(x)
x = ppipe.PassPipeline('EarlyLoopOpt', {'name': 'run_n_times', 'count': 1})
x.add_pass(highlevel_loopopt_passlist())
result.append(x)
x = ppipe.PassPipeline('MidLevelOpt', {'name': 'run_n_times', 'count': 2})
x.add_pass(ssapass_passlist('mid'))
result.append(x)
x = ppipe.PassPipeline('Lower', {'name': 'run_to_fixed_point'})
x.add_pass(lower_passlist())
result.append(x)
x = ppipe.PassPipeline('LowLevel', {'name': 'run_n_times', 'count': 1})
x.add_pass(ssapass_passlist('low'))
result.append(x)
x = ppipe.PassPipeline('LateLoopOpt', {'name': 'run_n_times', 'count': 1})
x.add_pass([lowlevel_loopopt_passlist(), p.DeadFunctionElimination])
result.append(x)
return result