@@ -234,16 +234,16 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM,
234
234
235
235
// Convert the PreservedSymbols map from "Name" based to "GUID" based.
236
236
static DenseSet<GlobalValue::GUID>
237
- computeGUIDPreservedSymbols (const StringSet<> &PreservedSymbols ,
238
- const Triple &TheTriple) {
239
- DenseSet<GlobalValue::GUID> GUIDPreservedSymbols (PreservedSymbols .size ());
240
- for (auto &Entry : PreservedSymbols ) {
237
+ convertSymbolNamesToGUID (const StringSet<> &NamedSymbols ,
238
+ const Triple &TheTriple) {
239
+ DenseSet<GlobalValue::GUID> GUIDSymbols (NamedSymbols .size ());
240
+ for (auto &Entry : NamedSymbols ) {
241
241
StringRef Name = Entry.first ();
242
242
if (TheTriple.isOSBinFormatMachO () && Name.size () > 0 && Name[0 ] == ' _' )
243
243
Name = Name.drop_front ();
244
- GUIDPreservedSymbols .insert (GlobalValue::getGUID (Name));
244
+ GUIDSymbols .insert (GlobalValue::getGUID (Name));
245
245
}
246
- return GUIDPreservedSymbols ;
246
+ return GUIDSymbols ;
247
247
}
248
248
249
249
std::unique_ptr<MemoryBuffer> codegenModule (Module &TheModule,
@@ -554,10 +554,7 @@ void ThinLTOCodeGenerator::preserveSymbol(StringRef Name) {
554
554
}
555
555
556
556
void ThinLTOCodeGenerator::crossReferenceSymbol (StringRef Name) {
557
- // FIXME: At the moment, we don't take advantage of this extra information,
558
- // we're conservatively considering cross-references as preserved.
559
- // CrossReferencedSymbols.insert(Name);
560
- PreservedSymbols.insert (Name);
557
+ CrossReferencedSymbols.insert (Name);
561
558
}
562
559
563
560
// TargetMachine factory
@@ -620,7 +617,7 @@ void ThinLTOCodeGenerator::promote(Module &TheModule,
620
617
Index.collectDefinedGVSummariesPerModule (ModuleToDefinedGVSummaries);
621
618
622
619
// Convert the preserved symbols set from string to GUID
623
- auto GUIDPreservedSymbols = computeGUIDPreservedSymbols (
620
+ auto GUIDPreservedSymbols = convertSymbolNamesToGUID (
624
621
PreservedSymbols, Triple (TheModule.getTargetTriple ()));
625
622
626
623
// Compute "dead" symbols, we don't want to import/export these!
@@ -641,11 +638,13 @@ void ThinLTOCodeGenerator::promote(Module &TheModule,
641
638
642
639
// Promote the exported values in the index, so that they are promoted
643
640
// in the module.
644
- auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
641
+ auto isExported = [&](StringRef ModuleIdentifier,
642
+ GlobalValue::GUID GUID) -> SummaryResolution {
645
643
const auto &ExportList = ExportLists.find (ModuleIdentifier);
646
- return (ExportList != ExportLists.end () &&
647
- ExportList->second .count (GUID)) ||
648
- GUIDPreservedSymbols.count (GUID);
644
+ if ((ExportList != ExportLists.end () && ExportList->second .count (GUID)) ||
645
+ GUIDPreservedSymbols.count (GUID))
646
+ return Exported;
647
+ return Internal;
649
648
};
650
649
thinLTOInternalizeAndPromoteInIndex (Index, isExported);
651
650
@@ -665,7 +664,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
665
664
Index.collectDefinedGVSummariesPerModule (ModuleToDefinedGVSummaries);
666
665
667
666
// Convert the preserved symbols set from string to GUID
668
- auto GUIDPreservedSymbols = computeGUIDPreservedSymbols (
667
+ auto GUIDPreservedSymbols = convertSymbolNamesToGUID (
669
668
PreservedSymbols, Triple (TheModule.getTargetTriple ()));
670
669
671
670
// Compute "dead" symbols, we don't want to import/export these!
@@ -739,7 +738,7 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
739
738
740
739
// Convert the preserved symbols set from string to GUID
741
740
auto GUIDPreservedSymbols =
742
- computeGUIDPreservedSymbols (PreservedSymbols, TMBuilder.TheTriple );
741
+ convertSymbolNamesToGUID (PreservedSymbols, TMBuilder.TheTriple );
743
742
744
743
// Collect for each module the list of function it defines (GUID -> Summary).
745
744
StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries (ModuleCount);
@@ -761,11 +760,13 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
761
760
return ;
762
761
763
762
// Internalization
764
- auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
763
+ auto isExported = [&](StringRef ModuleIdentifier,
764
+ GlobalValue::GUID GUID) -> SummaryResolution {
765
765
const auto &ExportList = ExportLists.find (ModuleIdentifier);
766
- return (ExportList != ExportLists.end () &&
767
- ExportList->second .count (GUID)) ||
768
- GUIDPreservedSymbols.count (GUID);
766
+ if ((ExportList != ExportLists.end () && ExportList->second .count (GUID)) ||
767
+ GUIDPreservedSymbols.count (GUID))
768
+ return Exported;
769
+ return Internal;
769
770
};
770
771
thinLTOInternalizeAndPromoteInIndex (Index, isExported);
771
772
thinLTOInternalizeModule (TheModule,
@@ -894,7 +895,9 @@ void ThinLTOCodeGenerator::run() {
894
895
// Convert the preserved symbols set from string to GUID, this is needed for
895
896
// computing the caching hash and the internalization.
896
897
auto GUIDPreservedSymbols =
897
- computeGUIDPreservedSymbols (PreservedSymbols, TMBuilder.TheTriple );
898
+ convertSymbolNamesToGUID (PreservedSymbols, TMBuilder.TheTriple );
899
+ auto GUIDCrossRefSymbols =
900
+ convertSymbolNamesToGUID (CrossReferencedSymbols, TMBuilder.TheTriple );
898
901
899
902
// Compute "dead" symbols, we don't want to import/export these!
900
903
auto DeadSymbols = computeDeadSymbols (*Index, GUIDPreservedSymbols);
@@ -916,11 +919,16 @@ void ThinLTOCodeGenerator::run() {
916
919
// impacts the caching.
917
920
resolveWeakForLinkerInIndex (*Index, ResolvedODR);
918
921
919
- auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
922
+ auto isExported = [&](StringRef ModuleIdentifier,
923
+ GlobalValue::GUID GUID) -> SummaryResolution {
924
+ if (GUIDPreservedSymbols.count (GUID))
925
+ return Exported;
926
+ if (GUIDCrossRefSymbols.count (GUID))
927
+ return Hidden;
920
928
const auto &ExportList = ExportLists.find (ModuleIdentifier);
921
- return (ExportList != ExportLists.end () &&
922
- ExportList-> second . count (GUID)) ||
923
- GUIDPreservedSymbols. count (GUID) ;
929
+ if (ExportList != ExportLists.end () && ExportList-> second . count (GUID))
930
+ return Hidden;
931
+ return Internal ;
924
932
};
925
933
926
934
// Use global summary-based analysis to identify symbols that can be
0 commit comments