@@ -42,8 +42,21 @@ class SILPassManager {
42
42
// / A list of registered analysis.
43
43
llvm::SmallVector<SILAnalysis *, 16 > Analysis;
44
44
45
+ // / An entry in the FunctionWorkList.
46
+ struct WorklistEntry {
47
+ WorklistEntry (SILFunction *F) : F(F) { }
48
+
49
+ SILFunction *F;
50
+
51
+ // / The current position in the transform-list.
52
+ unsigned PipelineIdx = 0 ;
53
+
54
+ // / How many times the pipeline was restarted for the function.
55
+ unsigned NumRestarts = 0 ;
56
+ };
57
+
45
58
// / The worklist of functions to be processed by function passes.
46
- std::vector<SILFunction * > FunctionWorklist;
59
+ std::vector<WorklistEntry > FunctionWorklist;
47
60
48
61
// Name of the current optimization stage for diagnostics.
49
62
std::string StageName;
@@ -62,6 +75,13 @@ class SILPassManager {
62
75
// / A completed-passes mask for each function.
63
76
llvm::DenseMap<SILFunction *, CompletedPasses> CompletedPassesMap;
64
77
78
+ // / Stores for each function the number of levels of specializations it is
79
+ // / derived from an original function. E.g. if a function is a signature
80
+ // / optimized specialization of a generic specialiation, it has level 2.
81
+ // / This is used to avoid an infinite amount of functions pushed on the
82
+ // / worklist (e.g. caused by a bug in a specializing optimization).
83
+ llvm::DenseMap<SILFunction *, int > DerivationLevels;
84
+
65
85
// / Set to true when a pass invalidates an analysis.
66
86
bool CurrentPassHasInvalidated = false ;
67
87
@@ -96,13 +116,6 @@ class SILPassManager {
96
116
// / \brief Run one iteration of the optimization pipeline.
97
117
void runOneIteration ();
98
118
99
- // / \brief Add a function to the function pass worklist.
100
- void addFunctionToWorklist (SILFunction *F) {
101
- assert (F && F->isDefinition () && F->shouldOptimize () &&
102
- " Expected optimizable function definition!" );
103
- FunctionWorklist.push_back (F);
104
- }
105
-
106
119
// / \brief Restart the function pass pipeline on the same function
107
120
// / that is currently being processed.
108
121
void restartWithCurrentFunction (SILTransform *T);
@@ -124,11 +137,12 @@ class SILPassManager {
124
137
CompletedPassesMap.clear ();
125
138
}
126
139
127
- // / \brief Add the function to the function pass worklist.
128
- void notifyTransformationOfFunction (SILFunction *F) {
129
- addFunctionToWorklist (F);
130
- }
131
-
140
+ // / \brief Add the function \p F to the function pass worklist.
141
+ // / If not null, the function \p DerivedFrom is the function from which \p F
142
+ // / is derived. This is used to avoid an infinite amount of functions pushed
143
+ // / on the worklist (e.g. caused by a bug in a specializing optimization).
144
+ void addFunctionToWorklist (SILFunction *F, SILFunction *DerivedFrom);
145
+
132
146
// / \brief Iterate over all analysis and notify them of the function.
133
147
// / This function does not necessarily have to be newly created function. It
134
148
// / is the job of the analysis to make sure no extra work is done if the
@@ -211,9 +225,8 @@ class SILPassManager {
211
225
// / the module.
212
226
void runModulePass (SILModuleTransform *SMT);
213
227
214
- // / Run the passes in \p FuncTransforms on the function \p F.
215
- void runPassesOnFunction (PassList FuncTransforms, SILFunction *F,
216
- bool runToCompletion);
228
+ // / Run the pass \p SFT on the function \p F.
229
+ void runPassOnFunction (SILFunctionTransform *SFT, SILFunction *F);
217
230
218
231
// / Run the passes in \p FuncTransforms. Return true
219
232
// / if the pass manager requested to stop the execution
0 commit comments