Skip to content

Commit c1b48a2

Browse files
authored
Merge pull request #14776 from xedin/rdar-26060144-improvements
[Metadata/IRGen] NFC: Couple of field metadata related improvements
2 parents 06243cb + 333f614 commit c1b48a2

File tree

5 files changed

+63
-56
lines changed

5 files changed

+63
-56
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ IRGenModule::getAddrOfParentContextDescriptor(DeclContext *from) {
809809
return getAddrOfLLVMVariableOrGOTEquivalent(
810810
LinkEntity::forNominalTypeDescriptor(nominal),
811811
Alignment(4),
812-
NominalTypeDescriptorTy,
812+
TypeContextDescriptorTy,
813813
shouldBeIndirect);
814814
}
815815
}
@@ -2495,8 +2495,8 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
24952495
// are represented by referencing the nominal type descriptor.
24962496
typeKind = TypeMetadataRecordKind::DirectNominalTypeDescriptor;
24972497
entity = LinkEntity::forNominalTypeDescriptor(nom);
2498-
defaultTy = IGM.NominalTypeDescriptorTy;
2499-
defaultPtrTy = IGM.NominalTypeDescriptorPtrTy;
2498+
defaultTy = IGM.TypeContextDescriptorTy;
2499+
defaultPtrTy = IGM.TypeContextDescriptorPtrTy;
25002500
}
25012501

25022502
return {typeKind, *entity, defaultTy, defaultPtrTy};
@@ -3305,7 +3305,7 @@ llvm::Constant *IRGenModule::getAddrOfTypeContextDescriptor(NominalTypeDecl *D,
33053305
auto entity = LinkEntity::forNominalTypeDescriptor(D);
33063306
return getAddrOfLLVMVariable(entity, Alignment(4),
33073307
definition,
3308-
NominalTypeDescriptorTy,
3308+
TypeContextDescriptorTy,
33093309
DebugTypeInfo());
33103310
}
33113311

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ IRGenModule::getAddrOfSharedContextDescriptor(LinkEntity entity,
30303030

30313031
return getAddrOfLLVMVariable(entity, Alignment(4),
30323032
definition,
3033-
NominalTypeDescriptorTy,
3033+
TypeContextDescriptorTy,
30343034
DebugTypeInfo());
30353035
}
30363036

lib/IRGen/IRGenModule.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,30 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
307307
ProtocolConformanceDescriptorPtrTy
308308
= ProtocolConformanceDescriptorTy->getPointerTo(DefaultAS);
309309

310-
NominalTypeDescriptorTy
310+
TypeContextDescriptorTy
311311
= llvm::StructType::create(LLVMContext, "swift.type_descriptor");
312-
NominalTypeDescriptorPtrTy
313-
= NominalTypeDescriptorTy->getPointerTo(DefaultAS);
312+
TypeContextDescriptorPtrTy
313+
= TypeContextDescriptorTy->getPointerTo(DefaultAS);
314314

315-
ClassNominalTypeDescriptorTy =
315+
ClassContextDescriptorTy =
316316
llvm::StructType::get(LLVMContext, {
317-
Int32Ty,
318-
Int32Ty,
319-
Int32Ty,
320-
Int32Ty,
321-
Int32Ty,
322-
Int32Ty,
323-
Int32Ty,
324-
Int32Ty,
325-
Int32Ty,
326-
Int16Ty,
327-
Int16Ty,
328-
Int32Ty,
317+
Int32Ty, // context flags
318+
Int32Ty, // parent
319+
Int32Ty, // name
320+
Int32Ty, // kind
321+
Int32Ty, // accessor function
322+
Int32Ty, // num fields
323+
Int32Ty, // field offset vector
324+
Int32Ty, // is_reflectable flag
325+
Int32Ty, // (Generics Descriptor) argument offset
326+
Int32Ty, // (Generics Descriptor) num params
327+
Int32Ty, // (Generics Descriptor) num requirements
328+
Int32Ty, // (Generics Descriptor) num key arguments
329+
Int32Ty, // (Generics Descriptor) num extra arguments
330+
Int32Ty, // (VTable Descriptor) offset
331+
Int32Ty, // (VTable Descriptor) size
332+
Int32Ty, // (Methods Descriptor) accessor
333+
Int32Ty, // (Methods Descriptor) flags
329334
}, /*packed=*/true);
330335

331336
MethodDescriptorStructTy

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ class IRGenModule {
530530
llvm::PointerType *ProtocolRecordPtrTy;
531531
llvm::StructType *ProtocolConformanceDescriptorTy;
532532
llvm::PointerType *ProtocolConformanceDescriptorPtrTy;
533-
llvm::StructType *NominalTypeDescriptorTy;
534-
llvm::PointerType *NominalTypeDescriptorPtrTy;
535-
llvm::StructType *ClassNominalTypeDescriptorTy;
533+
llvm::StructType *TypeContextDescriptorTy;
534+
llvm::PointerType *TypeContextDescriptorPtrTy;
535+
llvm::StructType *ClassContextDescriptorTy;
536536
llvm::StructType *MethodDescriptorStructTy; /// %swift.method_descriptor
537537
llvm::StructType *TypeMetadataRecordTy;
538538
llvm::PointerType *TypeMetadataRecordPtrTy;

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,6 @@ static Demangler getDemanglerForRuntimeTypeResolution() {
6464
return dem;
6565
}
6666

67-
template <typename T> struct DescriptorCacheEntry {
68-
private:
69-
std::string Name;
70-
const T *Description;
71-
72-
public:
73-
DescriptorCacheEntry(const llvm::StringRef name, const T *description)
74-
: Name(name.str()), Description(description) {}
75-
76-
const T *getDescription() { return Description; }
77-
78-
int compareWithKey(llvm::StringRef aName) const {
79-
return aName.compare(Name);
80-
}
81-
82-
template <class... Args>
83-
static size_t getExtraAllocationSize(Args &&... ignored) {
84-
return 0;
85-
}
86-
};
87-
8867
#pragma mark Nominal type descriptor cache
8968
// Type Metadata Cache.
9069

@@ -333,8 +312,30 @@ namespace {
333312
}
334313
};
335314

315+
struct ProtocolDescriptorCacheEntry {
316+
private:
317+
std::string Name;
318+
const ProtocolDescriptor *Description;
319+
320+
public:
321+
ProtocolDescriptorCacheEntry(const llvm::StringRef name,
322+
const ProtocolDescriptor *description)
323+
: Name(name.str()), Description(description) {}
324+
325+
const ProtocolDescriptor *getDescription() { return Description; }
326+
327+
int compareWithKey(llvm::StringRef aName) const {
328+
return aName.compare(Name);
329+
}
330+
331+
template <class... T>
332+
static size_t getExtraAllocationSize(T &&... ignored) {
333+
return 0;
334+
}
335+
};
336+
336337
struct ProtocolMetadataState {
337-
ConcurrentMap<DescriptorCacheEntry<ProtocolDescriptor>> ProtocolCache;
338+
ConcurrentMap<ProtocolDescriptorCacheEntry> ProtocolCache;
338339
std::vector<ProtocolSection> SectionsToScan;
339340
Mutex SectionsToScanLock;
340341

@@ -425,19 +426,22 @@ _findProtocolDescriptor(llvm::StringRef mangledName) {
425426

426427
#pragma mark Type field descriptor cache
427428
namespace {
428-
template <typename T> struct FieldDescriptorCacheEntry {
429+
struct FieldDescriptorCacheEntry {
429430
private:
430-
const Metadata *Base;
431-
const T *Description;
431+
const Metadata *Type;
432+
const FieldDescriptor *Description;
432433

433434
public:
434-
FieldDescriptorCacheEntry(const Metadata *Base, const T *description)
435-
: Base(Base), Description(description) {}
435+
FieldDescriptorCacheEntry(const Metadata *type,
436+
const FieldDescriptor *description)
437+
: Type(type), Description(description) {}
436438

437-
const T *getDescription() { return Description; }
439+
const FieldDescriptor *getDescription() { return Description; }
438440

439441
int compareWithKey(const Metadata *other) const {
440-
return Base == other;
442+
auto a = (uintptr_t)Type;
443+
auto b = (uintptr_t)other;
444+
return a == b ? 0 : (a < b ? -1 : 1);
441445
}
442446

443447
template <class... Args>
@@ -477,7 +481,7 @@ class DynamicFieldSection {
477481
};
478482

479483
struct FieldCacheState {
480-
ConcurrentMap<FieldDescriptorCacheEntry<FieldDescriptor>> FieldCache;
484+
ConcurrentMap<FieldDescriptorCacheEntry> FieldCache;
481485

482486
Mutex SectionsLock;
483487
std::vector<StaticFieldSection> StaticSections;
@@ -1122,12 +1126,10 @@ void swift::swift_getFieldAt(
11221126

11231127

11241128
// Fast path: If we already have field descriptor cached.
1125-
/*
11261129
if (auto Value = cache.FieldCache.find(base)) {
11271130
getFieldAt(*Value->getDescription());
11281131
return;
11291132
}
1130-
*/
11311133

11321134
ScopedLock guard(cache.SectionsLock);
11331135
// Otherwise let's try to find it in one of the sections.

0 commit comments

Comments
 (0)