summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/FunctionImport.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2018-03-02 23:40:08 +0000
committerChandler Carruth <chandlerc@gmail.com>2018-03-02 23:40:08 +0000
commita4619d9944c7e54c421582c7dc592ae051d8bf51 (patch)
tree972ffb5b5cb34231ee60cf68d4acc028eee71bcb /llvm/lib/Transforms/IPO/FunctionImport.cpp
parentdbf75c9c79910f8b99b2a273d886d8db3ff9b93e (diff)
downloadbcm5719-llvm-a4619d9944c7e54c421582c7dc592ae051d8bf51.tar.gz
bcm5719-llvm-a4619d9944c7e54c421582c7dc592ae051d8bf51.zip
[ThinLTO] Revert r325320: Import global variables
This caused some links to fail with ThinLTO due to missing symbols as well as causing some binaries to have failures at runtime. We're working with the author to get a test case, but want to get the tree green again. Further, it appears to introduce a data race. While the test usage of threads was disabled in r325361 & r325362, that isn't an acceptable fix. I've reverted both of these as well. This code needs to be thread safe. Test cases for this are already on the original commit thread. llvm-svn: 326638
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionImport.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/FunctionImport.cpp96
1 files changed, 12 insertions, 84 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index aade726994f..b68058cbeea 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -61,7 +61,6 @@ using namespace llvm;
#define DEBUG_TYPE "function-import"
STATISTIC(NumImportedFunctions, "Number of functions imported");
-STATISTIC(NumImportedGlobalVars, "Number of global variables imported");
STATISTIC(NumImportedModules, "Number of modules imported from");
STATISTIC(NumDeadSymbols, "Number of dead stripped symbols in index");
STATISTIC(NumLiveSymbols, "Number of live symbols in index");
@@ -239,33 +238,6 @@ updateValueInfoForIndirectCalls(const ModuleSummaryIndex &Index, ValueInfo VI) {
return Index.getValueInfo(GUID);
}
-static void computeImportForReferencedGlobals(
- const FunctionSummary &Summary, const GVSummaryMapTy &DefinedGVSummaries,
- FunctionImporter::ImportMapTy &ImportList,
- StringMap<FunctionImporter::ExportSetTy> *ExportLists) {
- for (auto &VI : Summary.refs()) {
- if (DefinedGVSummaries.count(VI.getGUID())) {
- DEBUG(dbgs() << "Ref ignored! Target already in destination module.\n");
- continue;
- }
-
- DEBUG(dbgs() << " ref -> " << VI.getGUID() << "\n");
-
- for (auto &RefSummary : VI.getSummaryList())
- if (RefSummary->getSummaryKind() == GlobalValueSummary::GlobalVarKind &&
- // Don't try to import regular LTO summaries added to dummy module.
- !RefSummary->modulePath().empty() &&
- !GlobalValue::isInterposableLinkage(RefSummary->linkage()) &&
- // For now we don't import global variables which have outgoing
- // refs. Otherwise we have to promote referenced vars/functions.
- RefSummary->refs().empty()) {
- ImportList[RefSummary->modulePath()][VI.getGUID()] = 1;
- if (ExportLists)
- (*ExportLists)[RefSummary->modulePath()].insert(VI.getGUID());
- }
- }
-}
-
/// Compute the list of functions to import for a given caller. Mark these
/// imported functions and the symbols they reference in their source module as
/// exported from their source module.
@@ -275,8 +247,6 @@ static void computeImportForFunction(
SmallVectorImpl<EdgeInfo> &Worklist,
FunctionImporter::ImportMapTy &ImportList,
StringMap<FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
- computeImportForReferencedGlobals(Summary, DefinedGVSummaries, ImportList,
- ExportLists);
for (auto &Edge : Summary.calls()) {
ValueInfo VI = Edge.first;
DEBUG(dbgs() << " edge -> " << VI.getGUID() << " Threshold:" << Threshold
@@ -419,34 +389,6 @@ static void ComputeImportForModule(
}
}
-#ifndef NDEBUG
-static bool isGlobalVarSummary(const ModuleSummaryIndex &Index,
- GlobalValue::GUID G) {
- if (const auto &VI = Index.getValueInfo(G)) {
- auto SL = VI.getSummaryList();
- if (!SL.empty())
- return SL[0]->getSummaryKind() == GlobalValueSummary::GlobalVarKind;
- }
- return false;
-}
-
-static GlobalValue::GUID getGUID(GlobalValue::GUID G) { return G; }
-
-static GlobalValue::GUID
-getGUID(const std::pair<const GlobalValue::GUID, unsigned> &P) {
- return P.first;
-}
-
-template <class T>
-unsigned numGlobalVarSummaries(const ModuleSummaryIndex &Index, T &Cont) {
- unsigned NumGVS = 0;
- for (auto &V : Cont)
- if (isGlobalVarSummary(Index, getGUID(V)))
- ++NumGVS;
- return NumGVS;
-}
-#endif
-
/// Compute all the import and export for every module using the Index.
void llvm::ComputeCrossModuleImport(
const ModuleSummaryIndex &Index,
@@ -484,17 +426,12 @@ void llvm::ComputeCrossModuleImport(
for (auto &ModuleImports : ImportLists) {
auto ModName = ModuleImports.first();
auto &Exports = ExportLists[ModName];
- unsigned NumGVS = numGlobalVarSummaries(Index, Exports);
- DEBUG(dbgs() << "* Module " << ModName << " exports "
- << Exports.size() - NumGVS << " functions and " << NumGVS
- << " vars. Imports from "
- << ModuleImports.second.size() << " modules.\n");
+ DEBUG(dbgs() << "* Module " << ModName << " exports " << Exports.size()
+ << " functions. Imports from " << ModuleImports.second.size()
+ << " modules.\n");
for (auto &Src : ModuleImports.second) {
auto SrcModName = Src.first();
- unsigned NumGVSPerMod = numGlobalVarSummaries(Index, Src.second);
- DEBUG(dbgs() << " - " << Src.second.size() - NumGVSPerMod
- << " functions imported from " << SrcModName << "\n");
- DEBUG(dbgs() << " - " << NumGVSPerMod << " global vars imported from "
+ DEBUG(dbgs() << " - " << Src.second.size() << " functions imported from "
<< SrcModName << "\n");
}
}
@@ -502,17 +439,13 @@ void llvm::ComputeCrossModuleImport(
}
#ifndef NDEBUG
-static void dumpImportListForModule(const ModuleSummaryIndex &Index,
- StringRef ModulePath,
+static void dumpImportListForModule(StringRef ModulePath,
FunctionImporter::ImportMapTy &ImportList) {
DEBUG(dbgs() << "* Module " << ModulePath << " imports from "
<< ImportList.size() << " modules.\n");
for (auto &Src : ImportList) {
auto SrcModName = Src.first();
- unsigned NumGVSPerMod = numGlobalVarSummaries(Index, Src.second);
- DEBUG(dbgs() << " - " << Src.second.size() - NumGVSPerMod
- << " functions imported from " << SrcModName << "\n");
- DEBUG(dbgs() << " - " << NumGVSPerMod << " vars imported from "
+ DEBUG(dbgs() << " - " << Src.second.size() << " functions imported from "
<< SrcModName << "\n");
}
}
@@ -532,7 +465,7 @@ void llvm::ComputeCrossModuleImportForModule(
ComputeImportForModule(FunctionSummaryMap, Index, ImportList);
#ifndef NDEBUG
- dumpImportListForModule(Index, ModulePath, ImportList);
+ dumpImportListForModule(ModulePath, ImportList);
#endif
}
@@ -559,7 +492,7 @@ void llvm::ComputeCrossModuleImportForModuleFromIndex(
ImportList[Summary->modulePath()][GUID] = 1;
}
#ifndef NDEBUG
- dumpImportListForModule(Index, ModulePath, ImportList);
+ dumpImportListForModule(ModulePath, ImportList);
#endif
}
@@ -837,7 +770,7 @@ Expected<bool> FunctionImporter::importFunctions(
Module &DestModule, const FunctionImporter::ImportMapTy &ImportList) {
DEBUG(dbgs() << "Starting import for Module "
<< DestModule.getModuleIdentifier() << "\n");
- unsigned ImportedCount = 0, ImportedGVCount = 0;
+ unsigned ImportedCount = 0;
IRMover Mover(DestModule);
// Do the actual import of functions now, one Module at a time
@@ -897,7 +830,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (Import) {
if (Error Err = GV.materialize())
return std::move(Err);
- ImportedGVCount += GlobalsToImport.insert(&GV);
+ GlobalsToImport.insert(&GV);
}
}
for (GlobalAlias &GA : SrcModule->aliases()) {
@@ -954,14 +887,9 @@ Expected<bool> FunctionImporter::importFunctions(
NumImportedModules++;
}
- NumImportedFunctions += (ImportedCount - ImportedGVCount);
- NumImportedGlobalVars += ImportedGVCount;
+ NumImportedFunctions += ImportedCount;
- DEBUG(dbgs() << "Imported " << ImportedCount - ImportedGVCount
- << " functions for Module " << DestModule.getModuleIdentifier()
- << "\n");
- DEBUG(dbgs() << "Imported " << ImportedGVCount
- << " global variables for Module "
+ DEBUG(dbgs() << "Imported " << ImportedCount << " functions for Module "
<< DestModule.getModuleIdentifier() << "\n");
return ImportedCount;
}
OpenPOWER on IntegriCloud