diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-01-29 08:03:30 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-01-29 08:03:30 +0000 |
commit | eaf5172ca6be291677f6f84cffae0c66656600a3 (patch) | |
tree | a4a2196f3b147192435ca6632a267cc7cd06c4d8 /llvm/lib/Transforms | |
parent | 62b62356fae9a66a7bdbf33d5790d7db39c9af5e (diff) | |
download | bcm5719-llvm-eaf5172ca6be291677f6f84cffae0c66656600a3.tar.gz bcm5719-llvm-eaf5172ca6be291677f6f84cffae0c66656600a3.zip |
[ThinLTO] - Stop internalizing and drop non-prevailing symbols.
Implementation marks non-prevailing symbols as not live in the summary.
Then them are dropped in backends.
Fixes https://bugs.llvm.org/show_bug.cgi?id=35938
Differential revision: https://reviews.llvm.org/D42107
llvm-svn: 323633
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index ed85c20051e..8dbee83bc3e 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -163,6 +163,9 @@ selectCallee(const ModuleSummaryIndex &Index, CalleeSummaryList, [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) { auto *GVSummary = SummaryPtr.get(); + if (!Index.isGlobalValueLive(GVSummary)) + return false; + // For SamplePGO, in computeImportForFunction the OriginalId // may have been used to locate the callee summary list (See // comment there). @@ -495,7 +498,8 @@ void llvm::ComputeCrossModuleImportForModuleFromIndex( void llvm::computeDeadSymbols( ModuleSummaryIndex &Index, - const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) { + const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, + function_ref<PrevailingType(GlobalValue::GUID)> isPrevailing) { assert(!Index.withGlobalValueDeadStripping()); if (!ComputeDead) return; @@ -524,7 +528,6 @@ void llvm::computeDeadSymbols( } // Make value live and add it to the worklist if it was not live before. - // FIXME: we should only make the prevailing copy live here auto visit = [&](ValueInfo VI) { // FIXME: If we knew which edges were created for indirect call profiles, // we could skip them here. Any that are live should be reached via @@ -540,6 +543,11 @@ void llvm::computeDeadSymbols( for (auto &S : VI.getSummaryList()) if (S->isLive()) return; + + // We do not keep live symbols that are known to be non-prevailing. + if (isPrevailing(VI.getGUID()) == PrevailingType::No) + return; + for (auto &S : VI.getSummaryList()) S->setLive(true); ++LiveSymbols; @@ -550,6 +558,8 @@ void llvm::computeDeadSymbols( auto VI = Worklist.pop_back_val(); for (auto &Summary : VI.getSummaryList()) { GlobalValueSummary *Base = Summary->getBaseObject(); + // Set base value live in case it is an alias. + Base->setLive(true); for (auto Ref : Base->refs()) visit(Ref); if (auto *FS = dyn_cast<FunctionSummary>(Base)) @@ -603,26 +613,26 @@ llvm::EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, return std::error_code(); } +void llvm::convertToDeclaration(GlobalValue &GV) { + DEBUG(dbgs() << "Converting to a declaration: `" << GV.getName() << "\n"); + if (Function *F = dyn_cast<Function>(&GV)) { + F->deleteBody(); + F->clearMetadata(); + } else if (GlobalVariable *V = dyn_cast<GlobalVariable>(&GV)) { + V->setInitializer(nullptr); + V->setLinkage(GlobalValue::ExternalLinkage); + V->clearMetadata(); + } else + // For now we don't resolve or drop aliases. Once we do we'll + // need to add support here for creating either a function or + // variable declaration, and return the new GlobalValue* for + // the caller to use. + llvm_unreachable("Expected function or variable"); +} + /// Fixup WeakForLinker linkages in \p TheModule based on summary analysis. void llvm::thinLTOResolveWeakForLinkerModule( Module &TheModule, const GVSummaryMapTy &DefinedGlobals) { - auto ConvertToDeclaration = [](GlobalValue &GV) { - DEBUG(dbgs() << "Converting to a declaration: `" << GV.getName() << "\n"); - if (Function *F = dyn_cast<Function>(&GV)) { - F->deleteBody(); - F->clearMetadata(); - } else if (GlobalVariable *V = dyn_cast<GlobalVariable>(&GV)) { - V->setInitializer(nullptr); - V->setLinkage(GlobalValue::ExternalLinkage); - V->clearMetadata(); - } else - // For now we don't resolve or drop aliases. Once we do we'll - // need to add support here for creating either a function or - // variable declaration, and return the new GlobalValue* for - // the caller to use. - llvm_unreachable("Expected function or variable"); - }; - auto updateLinkage = [&](GlobalValue &GV) { // See if the global summary analysis computed a new resolved linkage. const auto &GS = DefinedGlobals.find(GV.getGUID()); @@ -653,7 +663,7 @@ void llvm::thinLTOResolveWeakForLinkerModule( // the definition in that case. if (GlobalValue::isAvailableExternallyLinkage(NewLinkage) && GlobalValue::isInterposableLinkage(GV.getLinkage())) - ConvertToDeclaration(GV); + convertToDeclaration(GV); else { DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from " << GV.getLinkage() << " to " << NewLinkage << "\n"); |