Skip to content

Commit 346bc52

Browse files
authored
Merge pull request #15667 from slavapestov/sil-cleanup
Remove unused and slow 'protocol implementations' analysis
2 parents 97a934c + 38817f7 commit 346bc52

File tree

6 files changed

+4
-124
lines changed

6 files changed

+4
-124
lines changed

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,6 @@ class SILModule {
493493
bool linkFunction(SILFunction *Fun,
494494
LinkingMode LinkAll = LinkingMode::LinkNormal);
495495

496-
/// Attempt to link a function by mangled name. Returns true if linking
497-
/// succeeded, false otherwise.
498-
///
499-
/// \return false if the linking failed.
500-
bool linkFunction(StringRef Name,
501-
LinkingMode LinkAll = LinkingMode::LinkNormal);
502-
503496
/// Check if a given function exists in any of the modules with a
504497
/// required linkage, i.e. it can be linked by linkFunction.
505498
///

include/swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
8080
return IndirectSubclassesCache[C];
8181
}
8282

83-
const NominalTypeList &getProtocolImplementations(ProtocolDecl *P) {
84-
return ProtocolImplementationsCache[P];
85-
}
86-
8783
/// Returns true if the class is inherited by another class in this module.
8884
bool hasKnownDirectSubclasses(ClassDecl *C) {
8985
return DirectSubclassesCache.count(C);
@@ -96,11 +92,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
9692
!IndirectSubclassesCache[C].empty();
9793
}
9894

99-
/// Returns true if the protocol is implemented by any class in this module.
100-
bool hasKnownImplementations(ProtocolDecl *C) {
101-
return ProtocolImplementationsCache.count(C);
102-
}
103-
10495
private:
10596
/// Compute inheritance properties.
10697
void init();
@@ -114,9 +105,6 @@ class ClassHierarchyAnalysis : public SILAnalysis {
114105

115106
/// A cache that maps a class to all of its known indirect subclasses.
116107
llvm::DenseMap<ClassDecl*, ClassList> IndirectSubclassesCache;
117-
118-
/// A cache that maps a protocol to all of its known implementations.
119-
ProtocolImplementations ProtocolImplementationsCache;
120108
};
121109

122110
}

lib/SIL/Linker.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,6 @@ bool SILLinkerVisitor::processFunction(SILFunction *F) {
5656
return true;
5757
}
5858

59-
/// Process Decl, recursively deserializing any thing Decl may reference.
60-
bool SILLinkerVisitor::processFunction(StringRef Name) {
61-
if (Mode == LinkingMode::LinkNone)
62-
return false;
63-
64-
// If F is a declaration, first deserialize it.
65-
auto *NewFn = Loader->lookupSILFunction(Name);
66-
67-
if (!NewFn || NewFn->isExternalDeclaration())
68-
return false;
69-
70-
++NumFuncLinked;
71-
72-
// Try to transitively deserialize everything referenced by NewFn.
73-
Worklist.push_back(NewFn);
74-
process();
75-
76-
// Since we successfully processed at least one function, return true.
77-
return true;
78-
}
79-
80-
/// Process Decl, recursively deserializing any thing Decl may reference.
81-
SILFunction *SILLinkerVisitor::lookupFunction(StringRef Name,
82-
SILLinkage Linkage) {
83-
84-
auto *NewFn = Loader->lookupSILFunction(Name, /* declarationOnly */ true,
85-
Linkage);
86-
87-
if (!NewFn)
88-
return nullptr;
89-
90-
assert(NewFn->isExternalDeclaration() &&
91-
"SIL function lookup should never read function bodies");
92-
93-
return NewFn;
94-
}
95-
96-
/// Process Decl, recursively deserializing any thing Decl may reference.
97-
bool SILLinkerVisitor::hasFunction(StringRef Name,
98-
Optional<SILLinkage> Linkage) {
99-
return Loader->hasSILFunction(Name, Linkage);
100-
}
101-
10259
/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
10360
/// transitively references.
10461
///

lib/SIL/Linker.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, bool> {
5050
/// Process F, recursively deserializing any thing F may reference.
5151
bool processFunction(SILFunction *F);
5252

53-
/// Process Name, recursively deserializing any thing function with name Name
54-
/// may reference.
55-
bool processFunction(StringRef Name);
56-
57-
/// Process Name, try to deserialize a declaration of a function with
58-
/// this Name.
59-
SILFunction *lookupFunction(StringRef Name, SILLinkage Linkage);
60-
61-
/// Process Name, try to check if there is a declaration of a function
62-
/// with this Name.
63-
bool hasFunction(StringRef Name, Optional<SILLinkage> Linkage = None);
64-
6553
/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
6654
/// transitively references.
6755
///

lib/SIL/SILModule.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@ bool SILModule::linkFunction(SILFunction *Fun, SILModule::LinkingMode Mode) {
476476
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Fun);
477477
}
478478

479-
bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
480-
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
481-
}
482-
483479
SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
484480
assert((Linkage == SILLinkage::Public ||
485481
Linkage == SILLinkage::PublicExternal) &&
@@ -502,14 +498,12 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
502498
}
503499

504500
if (!F) {
505-
SILLinkerVisitor Visitor(*this, getSILLoader(),
506-
SILModule::LinkingMode::LinkNormal);
507501
if (CurF) {
508502
// Perform this lookup only if a function with a given
509503
// name is present in the current module.
510504
// This is done to reduce the amount of IO from the
511505
// swift module file.
512-
if (!Visitor.hasFunction(Name, Linkage))
506+
if (!getSILLoader()->hasSILFunction(Name, Linkage))
513507
return nullptr;
514508
// The function in the current module will be changed.
515509
F = CurF;
@@ -519,7 +513,8 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
519513
// or if it is known to exist, perform a lookup.
520514
if (!F) {
521515
// Try to load the function from other modules.
522-
F = Visitor.lookupFunction(Name, Linkage);
516+
F = getSILLoader()->lookupSILFunction(Name, /*declarationOnly*/ true,
517+
Linkage);
523518
// Bail if nothing was found and we are not sure if
524519
// this function exists elsewhere.
525520
if (!F)
@@ -545,9 +540,7 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
545540
bool SILModule::hasFunction(StringRef Name) {
546541
if (lookUpFunction(Name))
547542
return true;
548-
SILLinkerVisitor Visitor(*this, getSILLoader(),
549-
SILModule::LinkingMode::LinkNormal);
550-
return Visitor.hasFunction(Name);
543+
return getSILLoader()->hasSILFunction(Name);
551544
}
552545

553546
void SILModule::linkAllFromCurrentModule() {

lib/SILOptimizer/Analysis/ClassHierarchyAnalysis.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,14 @@
1212

1313
#include "swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
1414
#include "swift/AST/ASTContext.h"
15-
#include "swift/AST/ASTWalker.h"
1615
#include "swift/AST/Module.h"
1716
#include "swift/SIL/SILInstruction.h"
1817
#include "swift/SIL/SILValue.h"
1918
#include "swift/SIL/SILModule.h"
2019

2120
using namespace swift;
2221

23-
namespace {
24-
/// A helper class to collect all nominal type declarations.
25-
class NominalTypeWalker: public ASTWalker {
26-
ClassHierarchyAnalysis::ProtocolImplementations &ProtocolImplementationsCache;
27-
public:
28-
NominalTypeWalker(ClassHierarchyAnalysis::ProtocolImplementations
29-
&ProtocolImplementationsCache)
30-
:ProtocolImplementationsCache(ProtocolImplementationsCache) {
31-
}
32-
33-
bool walkToDeclPre(Decl *D) override {
34-
auto *NTD = dyn_cast<NominalTypeDecl>(D);
35-
if (!NTD || !NTD->hasInterfaceType())
36-
return true;
37-
auto Protocols = NTD->getAllProtocols();
38-
// We are only interested in types implementing protocols.
39-
if (!Protocols.empty()) {
40-
for (auto &Protocol : Protocols) {
41-
auto &K = ProtocolImplementationsCache[Protocol];
42-
K.push_back(NTD);
43-
}
44-
}
45-
return true;
46-
}
47-
};
48-
} // end anonymous namespace
49-
5022
void ClassHierarchyAnalysis::init() {
51-
// Process all types implementing protocols.
52-
SmallVector<Decl *, 32> Decls;
53-
// TODO: It would be better if we could get all declarations
54-
// from a given module, not only the top-level ones.
55-
M->getSwiftModule()->getTopLevelDecls(Decls);
56-
57-
NominalTypeWalker Walker(ProtocolImplementationsCache);
58-
for (auto *D: Decls) {
59-
D->walk(Walker);
60-
}
61-
6223
// For each class declaration in our V-table list:
6324
for (auto &VT : M->getVTableList()) {
6425
ClassDecl *C = VT.getClass();

0 commit comments

Comments
 (0)