@@ -547,8 +547,9 @@ static void collectGlobalList(IRGenModule &IGM,
547
547
static llvm::GlobalVariable *
548
548
emitGlobalList (IRGenModule &IGM, ArrayRef<llvm::WeakTrackingVH> handles,
549
549
StringRef name, StringRef section,
550
- llvm::GlobalValue::LinkageTypes linkage, llvm::Type *eltTy,
551
- bool isConstant, bool asContiguousArray) {
550
+ llvm::GlobalValue::LinkageTypes linkage,
551
+ llvm::Type *eltTy,
552
+ bool isConstant) {
552
553
// Do nothing if the list is empty.
553
554
if (handles.empty ()) return nullptr ;
554
555
@@ -557,31 +558,6 @@ emitGlobalList(IRGenModule &IGM, ArrayRef<llvm::WeakTrackingVH> handles,
557
558
// so that the linker doesn't accidentally put padding in the list.
558
559
Alignment alignment = IGM.getPointerAlignment ();
559
560
560
- if (!asContiguousArray) {
561
- // Emit as individual globals, which is required for conditional runtime
562
- // records to work.
563
- for (auto &handle : handles) {
564
- llvm::Constant *elt = cast<llvm::Constant>(&*handle);
565
- auto eltName = name + " _" + elt->getName ();
566
- if (elt->getType () != eltTy)
567
- elt = llvm::ConstantExpr::getBitCast (elt, eltTy);
568
- auto var = new llvm::GlobalVariable (IGM.Module , eltTy, isConstant,
569
- linkage, elt, eltName);
570
- var->setSection (section);
571
- var->setAlignment (llvm::MaybeAlign (alignment.getValue ()));
572
- disableAddressSanitizer (IGM, var);
573
- if (llvm::GlobalValue::isLocalLinkage (linkage))
574
- IGM.addUsedGlobal (var);
575
-
576
- if (IGM.IRGen .Opts .ConditionalRuntimeRecords ) {
577
- // Allow dead-stripping `var` (the runtime record from the global list)
578
- // when `handle` / `elt` (the underlaying entity) is not referenced.
579
- IGM.appendLLVMUsedConditionalEntry (var, elt->stripPointerCasts ());
580
- }
581
- }
582
- return nullptr ;
583
- }
584
-
585
561
// We have an array of value handles, but we need an array of constants.
586
562
SmallVector<llvm::Constant*, 8 > elts;
587
563
elts.reserve (handles.size ());
@@ -1061,41 +1037,36 @@ void IRGenModule::emitGlobalLists() {
1061
1037
if (ObjCInterop) {
1062
1038
// Objective-C class references go in a variable with a meaningless
1063
1039
// name but a magic section.
1064
- emitGlobalList (
1065
- *this , ObjCClasses, " objc_classes" ,
1066
- GetObjCSectionName (" __objc_classlist" , " regular,no_dead_strip" ),
1067
- llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1068
- /* asContiguousArray*/ false );
1040
+ emitGlobalList (*this , ObjCClasses, " objc_classes" ,
1041
+ GetObjCSectionName (" __objc_classlist" ,
1042
+ " regular,no_dead_strip" ),
1043
+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, false );
1069
1044
1070
1045
// So do resilient class stubs.
1071
- emitGlobalList (
1072
- *this , ObjCClassStubs, " objc_class_stubs" ,
1073
- GetObjCSectionName (" __objc_stublist" , " regular,no_dead_strip" ),
1074
- llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1075
- /* asContiguousArray*/ true );
1046
+ emitGlobalList (*this , ObjCClassStubs, " objc_class_stubs" ,
1047
+ GetObjCSectionName (" __objc_stublist" ,
1048
+ " regular,no_dead_strip" ),
1049
+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, false );
1076
1050
1077
1051
// So do categories.
1078
- emitGlobalList (
1079
- *this , ObjCCategories, " objc_categories" ,
1080
- GetObjCSectionName (" __objc_catlist" , " regular,no_dead_strip" ),
1081
- llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1082
- /* asContiguousArray*/ true );
1052
+ emitGlobalList (*this , ObjCCategories, " objc_categories" ,
1053
+ GetObjCSectionName (" __objc_catlist" ,
1054
+ " regular,no_dead_strip" ),
1055
+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, false );
1083
1056
1084
1057
// And categories on class stubs.
1085
- emitGlobalList (
1086
- *this , ObjCCategoriesOnStubs, " objc_categories_stubs" ,
1087
- GetObjCSectionName (" __objc_catlist2" , " regular,no_dead_strip" ),
1088
- llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1089
- /* asContiguousArray*/ true );
1090
-
1091
- // Emit nonlazily realized class references in a second magic section to
1092
- // make sure they are realized by the Objective-C runtime before any
1093
- // instances are allocated.
1094
- emitGlobalList (
1095
- *this , ObjCNonLazyClasses, " objc_non_lazy_classes" ,
1096
- GetObjCSectionName (" __objc_nlclslist" , " regular,no_dead_strip" ),
1097
- llvm::GlobalValue::InternalLinkage, Int8PtrTy, /* isConstant*/ false ,
1098
- /* asContiguousArray*/ true );
1058
+ emitGlobalList (*this , ObjCCategoriesOnStubs, " objc_categories_stubs" ,
1059
+ GetObjCSectionName (" __objc_catlist2" ,
1060
+ " regular,no_dead_strip" ),
1061
+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, false );
1062
+
1063
+ // Emit nonlazily realized class references in a second magic section to make
1064
+ // sure they are realized by the Objective-C runtime before any instances
1065
+ // are allocated.
1066
+ emitGlobalList (*this , ObjCNonLazyClasses, " objc_non_lazy_classes" ,
1067
+ GetObjCSectionName (" __objc_nlclslist" ,
1068
+ " regular,no_dead_strip" ),
1069
+ llvm::GlobalValue::InternalLinkage, Int8PtrTy, false );
1099
1070
}
1100
1071
1101
1072
// @llvm.used
@@ -1105,15 +1076,15 @@ void IRGenModule::emitGlobalLists() {
1105
1076
emitGlobalList (*this , LLVMUsed, " llvm.used" , " llvm.metadata" ,
1106
1077
llvm::GlobalValue::AppendingLinkage,
1107
1078
Int8PtrTy,
1108
- /* isConstant */ false , /* asContiguousArray */ true );
1079
+ false );
1109
1080
1110
1081
// Collect llvm.compiler.used globals already in the module (coming
1111
1082
// from ClangCodeGen).
1112
1083
collectGlobalList (*this , LLVMCompilerUsed, " llvm.compiler.used" );
1113
1084
emitGlobalList (*this , LLVMCompilerUsed, " llvm.compiler.used" , " llvm.metadata" ,
1114
1085
llvm::GlobalValue::AppendingLinkage,
1115
1086
Int8PtrTy,
1116
- /* isConstant */ false , /* asContiguousArray */ true );
1087
+ false );
1117
1088
}
1118
1089
1119
1090
static bool hasCodeCoverageInstrumentation (SILFunction &f, SILModule &m) {
@@ -3738,34 +3709,39 @@ IRGenModule::emitDirectRelativeReference(llvm::Constant *target,
3738
3709
3739
3710
// / Expresses that `var` is removable (dead-strippable) when `dependsOn` is not
3740
3711
// / referenced.
3741
- void IRGenModule::appendLLVMUsedConditionalEntry (llvm::GlobalVariable *var,
3742
- llvm::Constant *dependsOn) {
3712
+ static void appendLLVMUsedConditionalEntry (IRGenModule &IGM,
3713
+ llvm::GlobalVariable *var,
3714
+ llvm::Constant *dependsOn) {
3743
3715
llvm::Metadata *metadata[] = {
3744
3716
// (1) which variable is being conditionalized, "target"
3745
3717
llvm::ConstantAsMetadata::get (var),
3746
3718
// (2) type, not relevant for a single-edge condition
3747
3719
llvm::ConstantAsMetadata::get (llvm::ConstantInt::get (
3748
- llvm::Type::getInt32Ty (Module.getContext ()), 0 )),
3720
+ llvm::Type::getInt32Ty (IGM. Module .getContext ()), 0 )),
3749
3721
// (3) the "edge" that holds the target alive, if it's missing the target
3750
3722
// is allowed to be removed
3751
- llvm::MDNode::get (Module.getContext (),
3723
+ llvm::MDNode::get (IGM. Module .getContext (),
3752
3724
{
3753
3725
llvm::ConstantAsMetadata::get (dependsOn),
3754
3726
}),
3755
3727
};
3756
3728
auto *usedConditional =
3757
- Module.getOrInsertNamedMetadata (" llvm.used.conditional" );
3758
- usedConditional->addOperand (llvm::MDNode::get (Module.getContext (), metadata));
3729
+ IGM.Module .getOrInsertNamedMetadata (" llvm.used.conditional" );
3730
+ usedConditional->addOperand (
3731
+ llvm::MDNode::get (IGM.Module .getContext (), metadata));
3759
3732
}
3760
3733
3761
3734
// / Expresses that `var` is removable (dead-strippable) when either the protocol
3762
3735
// / from `record` is not referenced or the type from `record` is not referenced.
3763
- void IRGenModule::appendLLVMUsedConditionalEntry (
3764
- llvm::GlobalVariable *var, const ProtocolConformance *conformance) {
3765
- auto *protocol = getAddrOfProtocolDescriptor (conformance->getProtocol ())
3766
- ->stripPointerCasts ();
3767
- auto *type = getAddrOfTypeContextDescriptor (
3768
- conformance->getType ()->getAnyNominal (), DontRequireMetadata)
3736
+ static void
3737
+ appendLLVMUsedConditionalEntry (IRGenModule &IGM, llvm::GlobalVariable *var,
3738
+ const ConformanceDescription &record) {
3739
+ auto *protocol =
3740
+ IGM.getAddrOfProtocolDescriptor (record.conformance ->getProtocol ())
3741
+ ->stripPointerCasts ();
3742
+ auto *type = IGM.getAddrOfTypeContextDescriptor (
3743
+ record.conformance ->getType ()->getAnyNominal (),
3744
+ DontRequireMetadata)
3769
3745
->stripPointerCasts ();
3770
3746
3771
3747
llvm::Metadata *metadata[] = {
@@ -3774,17 +3750,18 @@ void IRGenModule::appendLLVMUsedConditionalEntry(
3774
3750
// (2) type, "1" = if either edge is missing, the target is allowed to be
3775
3751
// removed.
3776
3752
llvm::ConstantAsMetadata::get (llvm::ConstantInt::get (
3777
- llvm::Type::getInt32Ty (Module.getContext ()), 1 )),
3753
+ llvm::Type::getInt32Ty (IGM. Module .getContext ()), 1 )),
3778
3754
// (3) list of edges
3779
- llvm::MDNode::get (Module.getContext (),
3755
+ llvm::MDNode::get (IGM. Module .getContext (),
3780
3756
{
3781
3757
llvm::ConstantAsMetadata::get (protocol),
3782
3758
llvm::ConstantAsMetadata::get (type),
3783
3759
}),
3784
3760
};
3785
3761
auto *usedConditional =
3786
- Module.getOrInsertNamedMetadata (" llvm.used.conditional" );
3787
- usedConditional->addOperand (llvm::MDNode::get (Module.getContext (), metadata));
3762
+ IGM.Module .getOrInsertNamedMetadata (" llvm.used.conditional" );
3763
+ usedConditional->addOperand (
3764
+ llvm::MDNode::get (IGM.Module .getContext (), metadata));
3788
3765
}
3789
3766
3790
3767
// / Emit the protocol descriptors list and return it (if asContiguousArray is
@@ -3866,7 +3843,7 @@ llvm::Constant *IRGenModule::emitSwiftProtocols(bool asContiguousArray) {
3866
3843
if (IRGen.Opts .ConditionalRuntimeRecords ) {
3867
3844
// Allow dead-stripping `var` (the protocol record) when the protocol
3868
3845
// (descriptorRef) is not referenced.
3869
- appendLLVMUsedConditionalEntry (var, descriptorRef.getValue ());
3846
+ appendLLVMUsedConditionalEntry (* this , var, descriptorRef.getValue ());
3870
3847
}
3871
3848
}
3872
3849
@@ -3960,7 +3937,7 @@ llvm::Constant *IRGenModule::emitProtocolConformances(bool asContiguousArray) {
3960
3937
if (IRGen.Opts .ConditionalRuntimeRecords ) {
3961
3938
// Allow dead-stripping `var` (the conformance record) when the protocol
3962
3939
// or type (from the conformance) is not referenced.
3963
- appendLLVMUsedConditionalEntry (var, record. conformance );
3940
+ appendLLVMUsedConditionalEntry (* this , var, record);
3964
3941
}
3965
3942
}
3966
3943
@@ -4075,7 +4052,7 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords(bool asContiguousArray) {
4075
4052
if (IRGen.Opts .ConditionalRuntimeRecords ) {
4076
4053
// Allow dead-stripping `var` (the type record) when the type (`ref`) is
4077
4054
// not referenced.
4078
- appendLLVMUsedConditionalEntry (var, ref.getValue ());
4055
+ appendLLVMUsedConditionalEntry (* this , var, ref.getValue ());
4079
4056
}
4080
4057
}
4081
4058
0 commit comments