@@ -27,15 +27,10 @@ class ClassDecl;
27
27
class ClassHierarchyAnalysis : public SILAnalysis {
28
28
public:
29
29
typedef SmallVector<ClassDecl *, 8 > ClassList;
30
- typedef SmallPtrSet<ClassDecl *, 32 > ClassSet;
31
- typedef SmallVector<NominalTypeDecl *, 8 > NominalTypeList;
32
- typedef llvm::DenseMap<ProtocolDecl *, NominalTypeList>
33
- ProtocolImplementations;
30
+ typedef llvm::DenseMap<ClassDecl *, ClassList> ClassListMap;
34
31
35
32
ClassHierarchyAnalysis (SILModule *Mod)
36
- : SILAnalysis(SILAnalysisKind::ClassHierarchy), M(Mod) {
37
- init ();
38
- }
33
+ : SILAnalysis(SILAnalysisKind::ClassHierarchy), M(Mod) {}
39
34
40
35
~ClassHierarchyAnalysis ();
41
36
@@ -65,7 +60,8 @@ class ClassHierarchyAnalysis : public SILAnalysis {
65
60
// / Returns a list of the known direct subclasses of a class \p C in
66
61
// / the current module.
67
62
const ClassList &getDirectSubClasses (ClassDecl *C) {
68
- return DirectSubclassesCache[C];
63
+ populateDirectSubclassesCacheIfNecessary ();
64
+ return (*DirectSubclassesCache)[C];
69
65
}
70
66
71
67
// / Returns a list of the known indirect subclasses of a class \p C in
@@ -81,7 +77,8 @@ class ClassHierarchyAnalysis : public SILAnalysis {
81
77
82
78
// / Returns true if the class is inherited by another class in this module.
83
79
bool hasKnownDirectSubclasses (ClassDecl *C) {
84
- return DirectSubclassesCache.count (C);
80
+ populateDirectSubclassesCacheIfNecessary ();
81
+ return DirectSubclassesCache->count (C);
85
82
}
86
83
87
84
// / Returns true if the class is indirectly inherited by another class
@@ -92,18 +89,19 @@ class ClassHierarchyAnalysis : public SILAnalysis {
92
89
}
93
90
94
91
private:
95
- // / Compute inheritance properties.
96
- void init ();
97
92
void getIndirectSubClasses (ClassDecl *Base,
98
93
ClassList &IndirectSubs);
99
94
// / The module
100
95
SILModule *M;
101
96
102
97
// / A cache that maps a class to all of its known direct subclasses.
103
- llvm::DenseMap<ClassDecl*, ClassList > DirectSubclassesCache;
98
+ llvm::Optional<ClassListMap > DirectSubclassesCache;
104
99
105
100
// / A cache that maps a class to all of its known indirect subclasses.
106
- llvm::DenseMap<ClassDecl*, ClassList> IndirectSubclassesCache;
101
+ ClassListMap IndirectSubclassesCache;
102
+
103
+ // / Populates `DirectSubclassesCache` if necessary.
104
+ void populateDirectSubclassesCacheIfNecessary ();
107
105
};
108
106
109
107
}
0 commit comments