27
27
28
28
namespace swift {
29
29
30
+ // / Limit the size of the rc identity cache. We keep a cache per function.
31
+ constexpr unsigned MaxRCIdentityCacheSize = 64 ;
32
+
30
33
class DominanceAnalysis ;
31
34
32
35
// / This class is a simple wrapper around an identity cache.
33
36
class RCIdentityFunctionInfo {
34
37
llvm::DenseSet<SILArgument *> VisitedArgs;
38
+ // RC identity cache.
39
+ llvm::DenseMap<SILValue, SILValue> RCCache;
35
40
DominanceAnalysis *DA;
36
41
37
42
// / This number is arbitrary and conservative. At some point if compile time
@@ -50,6 +55,15 @@ class RCIdentityFunctionInfo {
50
55
// / unchecked_trivial_bit_cast.
51
56
void getRCUsers (SILValue V, llvm::SmallVectorImpl<SILInstruction *> &Users);
52
57
58
+ void handleDeleteNotification (ValueBase *V) {
59
+ // Check the cache. If we don't find it, there is nothing to do.
60
+ auto Iter = RCCache.find (SILValue (V));
61
+ if (Iter == RCCache.end ())
62
+ return ;
63
+ // Then erase Iter from the cache.
64
+ RCCache.erase (Iter);
65
+ }
66
+
53
67
private:
54
68
SILValue getRCIdentityRootInner (SILValue V, unsigned RecursionDepth);
55
69
SILValue stripRCIdentityPreservingOps (SILValue V, unsigned RecursionDepth);
@@ -70,6 +84,18 @@ class RCIdentityAnalysis : public FunctionAnalysisBase<RCIdentityFunctionInfo> {
70
84
RCIdentityAnalysis (const RCIdentityAnalysis &) = delete ;
71
85
RCIdentityAnalysis &operator =(const RCIdentityAnalysis &) = delete ;
72
86
87
+ virtual void handleDeleteNotification (ValueBase *V) override {
88
+ // If the parent function of this instruction was just turned into an
89
+ // external declaration, bail. This happens during SILFunction destruction.
90
+ SILFunction *F = V->getParentBB ()->getParent ();
91
+ if (F->isExternalDeclaration ()) {
92
+ return ;
93
+ }
94
+ get (F)->handleDeleteNotification (V);
95
+ }
96
+
97
+ virtual bool needsNotifications () override { return true ; }
98
+
73
99
static bool classof (const SILAnalysis *S) {
74
100
return S->getKind () == AnalysisKind::RCIdentity;
75
101
}
0 commit comments