@@ -157,24 +157,39 @@ class AnalysisPreserver {
157
157
158
158
// / An abstract base class that implements the boiler plate of caching and
159
159
// / invalidating analysis for specific functions.
160
- template <typename AnalysisTy>
160
+ // /
161
+ // / The usage expectation is that the derived function analysis will inherit
162
+ // / from FunctionAnalysisBase and pass in as a template argument the
163
+ // / "FunctionInfoTy" struct as a template argument. The FunctionInfoTy struct
164
+ // / should represent all of the information that the analysis should store about
165
+ // / an individual function. As a toy example:
166
+ // /
167
+ // / ```
168
+ // / struct TriviallyDeadAnalysisFunctionInfo {
169
+ // / bool isTriviallyDead;
170
+ // / };
171
+ // /
172
+ // / class TriviallyDeadAnalysis
173
+ // / : public FunctionAnalysisBase<TriviallyDeadAnalysisFunctionInfo> { ... }
174
+ // / ```
175
+ template <typename FunctionInfoTy>
161
176
class FunctionAnalysisBase : public SILAnalysis {
162
177
protected:
163
- using StorageTy = llvm::DenseMap<SILFunction *, AnalysisTy *>;
178
+ using StorageTy = llvm::DenseMap<SILFunction *, FunctionInfoTy *>;
164
179
165
180
// / Maps functions to their analysis provider.
166
181
StorageTy storage;
167
182
168
- // / Construct a new empty analysis for a specific function \p F.
169
- virtual AnalysisTy *newFunctionAnalysis (SILFunction *f) = 0;
183
+ // / Construct a new empty function info for a specific function \p F.
184
+ virtual FunctionInfoTy *newFunctionAnalysis (SILFunction *f) = 0;
170
185
171
186
// / Return True if the analysis should be invalidated given trait \K is
172
187
// / preserved.
173
188
virtual bool shouldInvalidate (SILAnalysis::InvalidationKind k) = 0;
174
189
175
190
// / A stub function that verifies the specific AnalysisTy \p A. This is
176
191
// / meant to be overridden by subclasses.
177
- virtual void verify (AnalysisTy *A ) const {}
192
+ virtual void verify (FunctionInfoTy *funcInfo ) const {}
178
193
179
194
void deleteAllAnalysisProviders () {
180
195
for (auto iter : storage)
@@ -183,21 +198,21 @@ class FunctionAnalysisBase : public SILAnalysis {
183
198
}
184
199
185
200
public:
186
- // / Returns true if we have an analysis for a specific function \p F without
187
- // / actually constructing it .
188
- bool hasAnalysis (SILFunction *f) const { return storage.count (f); }
201
+ // / Returns true if we have data for a specific function \p F without actually
202
+ // / attempting to construct the function info .
203
+ bool hasFunctionInfo (SILFunction *f) const { return storage.count (f); }
189
204
190
205
// / Attempt to lookup up the information that the analysis has for the given
191
206
// / function. Returns nullptr upon failure.
192
- NullablePtr<AnalysisTy > maybeGet (SILFunction *f) {
207
+ NullablePtr<FunctionInfoTy > maybeGet (SILFunction *f) {
193
208
auto iter = storage.find (f);
194
209
if (iter == storage.end ())
195
210
return nullptr ;
196
211
return iter->second ;
197
212
}
198
213
199
- // / Returns an analysis provider for a specific function \p F.
200
- AnalysisTy *get (SILFunction *f) {
214
+ // / Returns a function info structure for a specific function \p F.
215
+ FunctionInfoTy *get (SILFunction *f) {
201
216
// Check that the analysis can handle this function.
202
217
verifyFunction (f);
203
218
@@ -212,7 +227,7 @@ class FunctionAnalysisBase : public SILAnalysis {
212
227
deleteAllAnalysisProviders ();
213
228
}
214
229
215
- // / Helper function to remove the analysis data for a function.
230
+ // / Helper function to remove the function info for a specific function.
216
231
void invalidateFunction (SILFunction *f) {
217
232
auto &it = storage.FindAndConstruct (f);
218
233
if (!it.second )
@@ -244,14 +259,15 @@ class FunctionAnalysisBase : public SILAnalysis {
244
259
virtual ~FunctionAnalysisBase () {
245
260
deleteAllAnalysisProviders ();
246
261
}
262
+
247
263
FunctionAnalysisBase (SILAnalysisKind k) : SILAnalysis(k), storage() {}
248
264
FunctionAnalysisBase (const FunctionAnalysisBase &) = delete ;
249
265
FunctionAnalysisBase &operator =(const FunctionAnalysisBase &) = delete ;
250
266
251
267
// / Verify all of the AnalysisTy for all functions.
252
268
// /
253
- // / This is not meant to be overridden by subclasses. See "void
254
- // / verify(AnalysisTy *A)" .
269
+ // / This is not meant to be overridden by subclasses. Instead please override
270
+ // / void FunctionAnalysisBase:: verify(FunctionInfoTy *fInfo) .
255
271
virtual void verify () const override final {
256
272
for (auto iter : storage) {
257
273
if (!iter.second )
@@ -260,11 +276,11 @@ class FunctionAnalysisBase : public SILAnalysis {
260
276
}
261
277
}
262
278
263
- // / Verify the AnalysisTy that we have stored for the specific function \p
279
+ // / Verify the FunctionInfoTy that we have stored for the specific function \p
264
280
// / F.
265
281
// /
266
- // / This is not meant to be overridden by subclasses. See "void
267
- // / verify(AnalysisTy *analysis)" .
282
+ // / This is not meant to be overridden by subclasses. Instead, please
283
+ // / override: void FunctionAnalysisBase:: verify(FunctionInfoTy *fInfo) .
268
284
virtual void verify (SILFunction *f) const override final {
269
285
auto iter = storage.find (f);
270
286
if (iter == storage.end ())
0 commit comments