Skip to content

Commit a7ff2d2

Browse files
committed
SIL: Refactor SILVTable::getImplementation() into getEntry()
This will allow IRGen to recover the entry kind when emitting class metadata.
1 parent cfcf653 commit a7ff2d2

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

include/swift/SIL/SILModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class SILModule {
150150
VTableListType vtables;
151151

152152
/// This is a cache of vtable entries for quick look-up
153-
llvm::DenseMap<std::pair<const SILVTable *, SILDeclRef>, SILFunction *>
153+
llvm::DenseMap<std::pair<const SILVTable *, SILDeclRef>, SILVTable::Entry>
154154
VTableEntryCache;
155155

156156
/// Lookup table for SIL witness tables from conformances.

include/swift/SIL/SILVTable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/SIL/SILFunction.h"
2727
#include "llvm/ADT/ilist_node.h"
2828
#include "llvm/ADT/ilist.h"
29+
#include "llvm/ADT/Optional.h"
2930
#include <algorithm>
3031

3132
namespace swift {
@@ -117,7 +118,7 @@ class SILVTable : public llvm::ilist_node<SILVTable>,
117118
ArrayRef<Entry> getEntries() const { return {Entries, NumEntries}; }
118119

119120
/// Look up the implementation function for the given method.
120-
SILFunction *getImplementation(SILModule &M, SILDeclRef method) const;
121+
Optional<Entry> getEntry(SILModule &M, SILDeclRef method) const;
121122

122123
/// Removes entries from the vtable.
123124
/// \p predicate Returns true if the passed entry should be removed.

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,9 +3195,8 @@ namespace {
31953195
void addMethod(SILDeclRef fn) {
31963196
// Find the vtable entry.
31973197
assert(VTable && "no vtable?!");
3198-
if (SILFunction *func =
3199-
VTable->getImplementation(IGM.getSILModule(), fn)) {
3200-
B.add(IGM.getAddrOfSILFunction(func, NotForDefinition));
3198+
if (auto entry = VTable->getEntry(IGM.getSILModule(), fn)) {
3199+
B.add(IGM.getAddrOfSILFunction(entry->Implementation, NotForDefinition));
32013200
} else {
32023201
// The method is removed by dead method elimination.
32033202
// It should be never called. We add a pointer to an error function.

lib/SIL/SILModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ lookUpFunctionInVTable(ClassDecl *Class, SILDeclRef Member) {
711711

712712
// Ok, we have a VTable. Try to lookup the SILFunction implementation from
713713
// the VTable.
714-
if (SILFunction *F = Vtbl->getImplementation(*this, Member))
715-
return F;
714+
if (auto E = Vtbl->getEntry(*this, Member))
715+
return E->Implementation;
716716

717717
// If we fail to lookup the SILFunction, again skip Class and attempt to
718718
// resolve the method in the VTable of the super class of Class if such a

lib/SIL/SILVTable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ SILVTable *SILVTable::create(SILModule &M, ClassDecl *Class,
3535
M.VTableMap[Class] = vt;
3636
// Update the Module's cache with new vtable + vtable entries:
3737
for (const Entry &entry : Entries) {
38-
M.VTableEntryCache.insert({{vt, entry.Method}, entry.Implementation});
38+
M.VTableEntryCache.insert({{vt, entry.Method}, entry});
3939
}
4040
return vt;
4141
}
4242

43-
SILFunction *
44-
SILVTable::getImplementation(SILModule &M, SILDeclRef method) const {
43+
Optional<SILVTable::Entry>
44+
SILVTable::getEntry(SILModule &M, SILDeclRef method) const {
4545
SILDeclRef m = method;
4646
do {
4747
auto entryIter = M.VTableEntryCache.find({this, m});
4848
if (entryIter != M.VTableEntryCache.end()) {
4949
return (*entryIter).second;
5050
}
5151
} while ((m = m.getOverridden()));
52-
return nullptr;
52+
return None;
5353
}
5454

5555
void SILVTable::removeFromVTableCache(Entry &entry) {

0 commit comments

Comments
 (0)