diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 5d6d93a3141..63278bd713c 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -125,6 +125,9 @@ private: llvm::DenseMap WitnessTableLookupCache; + /// Lookup table for SIL vtables from class decls. + llvm::DenseMap VTableLookupTable; + /// This is a cache of intrinsic Function declarations to numeric ID mappings. llvm::DenseMap IntrinsicIDCache; @@ -314,6 +317,9 @@ public: std::pair> lookUpWitnessTable(const ProtocolConformance *C); + /// Look up the VTable mapped to the given ClassDecl. Returns null on failure. + SILVTable *lookUpVTable(const ClassDecl *C); + // Given a protocol conformance, attempt to create a witness table declaration // for it. SILWitnessTable * diff --git a/lib/SIL/SILModule.cpp b/lib/SIL/SILModule.cpp index 7f2c67e94bb..ee2d284c850 100644 --- a/lib/SIL/SILModule.cpp +++ b/lib/SIL/SILModule.cpp @@ -479,3 +479,11 @@ void SILModule::linkAllWitnessTables() { void SILModule::linkAllVTables() { SILLoader->getAllVTables(); } + +SILVTable *SILModule::lookUpVTable(const ClassDecl *C) { + auto R = VTableLookupTable.find(C); + if (R == VTableLookupTable.end()) + return nullptr; + + return R->second; +} diff --git a/lib/SIL/SILVTable.cpp b/lib/SIL/SILVTable.cpp index 51ccc94ec71..af46b3332dc 100644 --- a/lib/SIL/SILVTable.cpp +++ b/lib/SIL/SILVTable.cpp @@ -32,6 +32,7 @@ SILVTable *SILVTable::create(SILModule &M, ClassDecl *Class, alignof(SILVTable)); SILVTable *vt = ::new (buf) SILVTable(Class, Entries); M.vtables.push_back(vt); + M.VTableLookupTable[Class] = vt; return vt; }