@@ -3943,32 +3943,14 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(CanType concreteType,
39433943 return cast<llvm::GlobalValue>(addr);
39443944 }
39453945
3946- // / For concrete metadata, we want to use the initializer on the
3947- // / "full metadata", and define the "direct" address point as an alias.
3948- TypeMetadataAddress addrKind;
3949- unsigned adjustmentIndex;
3950-
3951- auto nominal = concreteType->getAnyNominal ();
3952-
3953- // Native Swift class metadata has a destructor before the address point.
3954- // Foreign class metadata candidates do not, and neither does value type
3955- // metadata.
3956- if (nominal && isa<ClassDecl>(nominal) &&
3957- !requiresForeignTypeMetadata (nominal)) {
3958- addrKind = TypeMetadataAddress::FullMetadata;
3959- adjustmentIndex = MetadataAdjustmentIndex::Class;
3960- } else {
3961- addrKind = TypeMetadataAddress::FullMetadata;
3962- adjustmentIndex = MetadataAdjustmentIndex::ValueType;
3963- }
3964-
39653946 auto entity =
39663947 (isPrespecialized &&
39673948 !irgen::isCanonicalInitializableTypeMetadataStaticallyAddressable (
39683949 *this , concreteType))
39693950 ? LinkEntity::forNoncanonicalSpecializedGenericTypeMetadata (
39703951 concreteType)
3971- : LinkEntity::forTypeMetadata (concreteType, addrKind);
3952+ : LinkEntity::forTypeMetadata (concreteType,
3953+ TypeMetadataAddress::FullMetadata);
39723954
39733955 auto DbgTy = DebugTypeInfo::getMetadata (MetatypeType::get (concreteType),
39743956 entity.getDefaultDeclarationType (*this )->getPointerTo (),
@@ -3986,30 +3968,35 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(CanType concreteType,
39863968 if (link.isUsed ())
39873969 addUsedGlobal (var);
39883970
3989- // Keep type metadata around for all types.
3990- if (nominal)
3971+ // / For concrete metadata, we want to use the initializer on the
3972+ // / "full metadata", and define the "direct" address point as an alias.
3973+ unsigned adjustmentIndex = MetadataAdjustmentIndex::ValueType;
3974+
3975+ if (auto nominal = concreteType->getAnyNominal ()) {
3976+ // Keep type metadata around for all types.
39913977 addRuntimeResolvableType (nominal);
39923978
3993- // Don't define the alias for foreign type metadata or prespecialized generic
3994- // metadata, since neither is ABI.
3995- if ((nominal && requiresForeignTypeMetadata (nominal) ) || isPrespecialized)
3996- return var;
3979+ // Don't define the alias for foreign type metadata or prespecialized
3980+ // generic metadata, since neither is ABI.
3981+ if ( requiresForeignTypeMetadata (nominal) || isPrespecialized)
3982+ return var;
39973983
3998- // For concrete metadata, declare the alias to its address point.
3999- auto directEntity = LinkEntity::forTypeMetadata (concreteType,
4000- TypeMetadataAddress::AddressPoint);
3984+ // Native Swift class metadata has a destructor before the address point.
3985+ if (isa<ClassDecl>(nominal)) {
3986+ adjustmentIndex = MetadataAdjustmentIndex::Class;
3987+ }
3988+ }
40013989
4002- llvm::Constant *addr = var;
4003- // Do an adjustment if necessary.
4004- if (adjustmentIndex) {
4005- llvm::Constant *indices[] = {
3990+ llvm::Constant *indices[] = {
40063991 llvm::ConstantInt::get (Int32Ty, 0 ),
4007- llvm::ConstantInt::get (Int32Ty, adjustmentIndex)
4008- };
4009- addr = llvm::ConstantExpr::getInBoundsGetElementPtr (/* Ty=*/ nullptr ,
4010- addr, indices);
4011- }
3992+ llvm::ConstantInt::get (Int32Ty, adjustmentIndex)};
3993+ auto addr = llvm::ConstantExpr::getInBoundsGetElementPtr (/* Ty=*/ nullptr , var,
3994+ indices);
40123995 addr = llvm::ConstantExpr::getBitCast (addr, TypeMetadataPtrTy);
3996+
3997+ // For concrete metadata, declare the alias to its address point.
3998+ auto directEntity = LinkEntity::forTypeMetadata (
3999+ concreteType, TypeMetadataAddress::AddressPoint);
40134000 return defineAlias (directEntity, addr);
40144001}
40154002
@@ -4030,25 +4017,27 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
40304017
40314018 auto nominal = concreteType->getAnyNominal ();
40324019
4033- llvm::Type *defaultVarTy;
4034- unsigned adjustmentIndex;
4035-
40364020 bool foreign = nominal && requiresForeignTypeMetadata (nominal);
4021+
4022+ // Foreign classes and prespecialized generic types do not use an alias into
4023+ // the full metadata and therefore require a GEP.
40374024 bool fullMetadata =
40384025 foreign || (concreteType->getAnyGeneric () &&
40394026 concreteType->getAnyGeneric ()->isGenericContext ());
40404027
4041- // Foreign classes reference the full metadata with a GEP.
4028+ llvm::Type *defaultVarTy;
4029+ unsigned adjustmentIndex;
4030+
40424031 if (fullMetadata) {
40434032 defaultVarTy = FullTypeMetadataStructTy;
40444033 if (concreteType->getClassOrBoundGenericClass () && !foreign) {
40454034 adjustmentIndex = MetadataAdjustmentIndex::Class;
40464035 } else {
40474036 adjustmentIndex = MetadataAdjustmentIndex::ValueType;
40484037 }
4049- // The symbol for other nominal type metadata is generated at the address
4050- // point.
40514038 } else if (nominal) {
4039+ // The symbol for native non-generic nominal type metadata is generated at
4040+ // the aliased address point (see defineTypeMetadata() above).
40524041 assert (!nominal->hasClangNode ());
40534042
40544043 defaultVarTy = TypeMetadataStructTy;
@@ -4082,13 +4071,9 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
40824071
40834072 switch (canonicality) {
40844073 case TypeMetadataCanonicality::Canonical:
4085- if (fullMetadata) {
4086- entity = LinkEntity::forTypeMetadata (concreteType,
4087- TypeMetadataAddress::FullMetadata);
4088- } else {
4089- entity = LinkEntity::forTypeMetadata (concreteType,
4090- TypeMetadataAddress::AddressPoint);
4091- }
4074+ entity = LinkEntity::forTypeMetadata (
4075+ concreteType, fullMetadata ? TypeMetadataAddress::FullMetadata
4076+ : TypeMetadataAddress::AddressPoint);
40924077 break ;
40934078 case TypeMetadataCanonicality::Noncanonical:
40944079 entity =
0 commit comments