@@ -3943,32 +3943,14 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(CanType concreteType,
3943
3943
return cast<llvm::GlobalValue>(addr);
3944
3944
}
3945
3945
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
-
3965
3946
auto entity =
3966
3947
(isPrespecialized &&
3967
3948
!irgen::isCanonicalInitializableTypeMetadataStaticallyAddressable (
3968
3949
*this , concreteType))
3969
3950
? LinkEntity::forNoncanonicalSpecializedGenericTypeMetadata (
3970
3951
concreteType)
3971
- : LinkEntity::forTypeMetadata (concreteType, addrKind);
3952
+ : LinkEntity::forTypeMetadata (concreteType,
3953
+ TypeMetadataAddress::FullMetadata);
3972
3954
3973
3955
auto DbgTy = DebugTypeInfo::getMetadata (MetatypeType::get (concreteType),
3974
3956
entity.getDefaultDeclarationType (*this )->getPointerTo (),
@@ -3986,30 +3968,35 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(CanType concreteType,
3986
3968
if (link.isUsed ())
3987
3969
addUsedGlobal (var);
3988
3970
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.
3991
3977
addRuntimeResolvableType (nominal);
3992
3978
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;
3997
3983
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
+ }
4001
3989
4002
- llvm::Constant *addr = var;
4003
- // Do an adjustment if necessary.
4004
- if (adjustmentIndex) {
4005
- llvm::Constant *indices[] = {
3990
+ llvm::Constant *indices[] = {
4006
3991
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);
4012
3995
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);
4013
4000
return defineAlias (directEntity, addr);
4014
4001
}
4015
4002
@@ -4030,25 +4017,27 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
4030
4017
4031
4018
auto nominal = concreteType->getAnyNominal ();
4032
4019
4033
- llvm::Type *defaultVarTy;
4034
- unsigned adjustmentIndex;
4035
-
4036
4020
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.
4037
4024
bool fullMetadata =
4038
4025
foreign || (concreteType->getAnyGeneric () &&
4039
4026
concreteType->getAnyGeneric ()->isGenericContext ());
4040
4027
4041
- // Foreign classes reference the full metadata with a GEP.
4028
+ llvm::Type *defaultVarTy;
4029
+ unsigned adjustmentIndex;
4030
+
4042
4031
if (fullMetadata) {
4043
4032
defaultVarTy = FullTypeMetadataStructTy;
4044
4033
if (concreteType->getClassOrBoundGenericClass () && !foreign) {
4045
4034
adjustmentIndex = MetadataAdjustmentIndex::Class;
4046
4035
} else {
4047
4036
adjustmentIndex = MetadataAdjustmentIndex::ValueType;
4048
4037
}
4049
- // The symbol for other nominal type metadata is generated at the address
4050
- // point.
4051
4038
} else if (nominal) {
4039
+ // The symbol for native non-generic nominal type metadata is generated at
4040
+ // the aliased address point (see defineTypeMetadata() above).
4052
4041
assert (!nominal->hasClangNode ());
4053
4042
4054
4043
defaultVarTy = TypeMetadataStructTy;
@@ -4082,13 +4071,9 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
4082
4071
4083
4072
switch (canonicality) {
4084
4073
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);
4092
4077
break ;
4093
4078
case TypeMetadataCanonicality::Noncanonical:
4094
4079
entity =
0 commit comments