@@ -48,16 +48,14 @@ struct CallerAnalysis::ApplySiteFinderVisitor
48
48
: SILInstructionVisitor<ApplySiteFinderVisitor, bool > {
49
49
CallerAnalysis *analysis;
50
50
SILFunction *callerFn;
51
- FunctionInfo &callerInfo;
52
51
53
52
#ifndef NDEBUG
54
53
SmallPtrSet<SILInstruction *, 8 > visitedCallSites;
55
54
SmallSetVector<SILInstruction *, 8 > callSitesThatMustBeVisited;
56
55
#endif
57
56
58
57
ApplySiteFinderVisitor (CallerAnalysis *analysis, SILFunction *callerFn)
59
- : analysis(analysis), callerFn(callerFn),
60
- callerInfo (analysis->unsafeGetFunctionInfo (callerFn)) {}
58
+ : analysis(analysis), callerFn(callerFn) {}
61
59
~ApplySiteFinderVisitor ();
62
60
63
61
bool visitSILInstruction (SILInstruction *) { return false ; }
@@ -120,14 +118,14 @@ bool CallerAnalysis::ApplySiteFinderVisitor::visitFunctionRefBaseInst(
120
118
FunctionRefBaseInst *fri) {
121
119
auto optResult = findLocalApplySites (fri);
122
120
auto *calleeFn = fri->getInitiallyReferencedFunction ();
123
- FunctionInfo &calleeInfo = analysis->unsafeGetFunctionInfo (calleeFn);
124
121
125
122
// First make an edge from our callerInfo to our calleeState for invalidation
126
123
// purposes.
127
- callerInfo .calleeStates .insert (calleeFn);
124
+ analysis-> getOrInsertFunctionInfo (callerFn) .calleeStates .insert (calleeFn);
128
125
129
126
// Then grab our callee state and update it with state for this caller.
130
- auto iter = calleeInfo.callerStates .insert ({callerFn, {}});
127
+ auto iter = analysis->getOrInsertFunctionInfo (calleeFn).callerStates .
128
+ insert ({callerFn, {}});
131
129
// If we succeeded in inserting a new value, put in an optimistic
132
130
// value for escaping.
133
131
if (iter.second ) {
@@ -222,6 +220,10 @@ const FunctionInfo &CallerAnalysis::getFunctionInfo(SILFunction *f) const {
222
220
// Recompute every function in the invalidated function list and empty the
223
221
// list.
224
222
auto &self = const_cast <CallerAnalysis &>(*this );
223
+ if (funcInfos.find (f) == funcInfos.end ()) {
224
+ (void )self.getOrInsertFunctionInfo (f);
225
+ self.recomputeFunctionList .insert (f);
226
+ }
225
227
self.processRecomputeFunctionList ();
226
228
return self.unsafeGetFunctionInfo (f);
227
229
}
@@ -262,11 +264,7 @@ void CallerAnalysis::processFunctionCallSites(SILFunction *callerFn) {
262
264
visitor.process ();
263
265
}
264
266
265
- void CallerAnalysis::invalidateAllInfo (SILFunction *f) {
266
- // Look up the callees that our caller refers to and invalidate any
267
- // values that point back at the caller.
268
- FunctionInfo &fInfo = unsafeGetFunctionInfo (f);
269
-
267
+ void CallerAnalysis::invalidateAllInfo (SILFunction *f, FunctionInfo &fInfo ) {
270
268
// Then we first eliminate any callees that we point at.
271
269
invalidateKnownCallees (f, fInfo );
272
270
@@ -303,9 +301,12 @@ void CallerAnalysis::invalidateKnownCallees(SILFunction *caller,
303
301
}
304
302
305
303
void CallerAnalysis::invalidateKnownCallees (SILFunction *caller) {
306
- // Look up the callees that our caller refers to and invalidate any
307
- // values that point back at the caller.
308
- invalidateKnownCallees (caller, unsafeGetFunctionInfo (caller));
304
+ auto iter = funcInfos.find (caller);
305
+ if (iter != funcInfos.end ()) {
306
+ // Look up the callees that our caller refers to and invalidate any
307
+ // values that point back at the caller.
308
+ invalidateKnownCallees (caller, iter->second );
309
+ }
309
310
}
310
311
311
312
void CallerAnalysis::verify (SILFunction *caller) const {
@@ -377,6 +378,17 @@ void CallerAnalysis::invalidate() {
377
378
}
378
379
}
379
380
381
+ void CallerAnalysis::notifyWillDeleteFunction (SILFunction *f) {
382
+ auto iter = funcInfos.find (f);
383
+ if (iter == funcInfos.end ())
384
+ return ;
385
+
386
+ invalidateAllInfo (f, iter->second );
387
+ recomputeFunctionList.remove (f);
388
+ // Now that we have invalidated all references to the function, delete it.
389
+ funcInfos.erase (iter);
390
+ }
391
+
380
392
// ===----------------------------------------------------------------------===//
381
393
// CallerAnalysis YAML Dumper
382
394
// ===----------------------------------------------------------------------===//
0 commit comments