diff options
author | Teresa Johnson <tejohnson@google.com> | 2018-02-05 15:44:27 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2018-02-05 15:44:27 +0000 |
commit | 5a95c477305d0f25be289461eb3277f97b84ab08 (patch) | |
tree | 7b195f05af6cd1ce615fac0ff8a20694c0e262ba /llvm/lib/Transforms | |
parent | 02947b71123a484bfebd060abd53bf4a65247a01 (diff) | |
download | bcm5719-llvm-5a95c477305d0f25be289461eb3277f97b84ab08.tar.gz bcm5719-llvm-5a95c477305d0f25be289461eb3277f97b84ab08.zip |
[ThinLTO] Convert dead alias to declarations
Summary:
This complements the fixes in r323633 and r324075 which drop the
definitions of dead functions and variables, respectively.
Fixes PR36208.
Reviewers: grimar, rafael
Subscribers: mehdi_amini, llvm-commits, inglorion
Differential Revision: https://reviews.llvm.org/D42856
llvm-svn: 324242
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 37c4c21578c..a5903e27a9d 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -613,7 +613,7 @@ llvm::EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, return std::error_code(); } -void llvm::convertToDeclaration(GlobalValue &GV) { +bool llvm::convertToDeclaration(GlobalValue &GV) { DEBUG(dbgs() << "Converting to a declaration: `" << GV.getName() << "\n"); if (Function *F = dyn_cast<Function>(&GV)) { F->deleteBody(); @@ -624,14 +624,24 @@ void llvm::convertToDeclaration(GlobalValue &GV) { V->setLinkage(GlobalValue::ExternalLinkage); V->clearMetadata(); V->setComdat(nullptr); - } 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. - // Support of dropping aliases is required for correct dead code - // elimination performed in thin LTO backends (see 'dropDeadSymbols'). - llvm_unreachable("Expected function or variable"); + } else { + GlobalValue *NewGV; + if (GV.getValueType()->isFunctionTy()) + NewGV = + Function::Create(cast<FunctionType>(GV.getValueType()), + GlobalValue::ExternalLinkage, "", GV.getParent()); + else + NewGV = + new GlobalVariable(*GV.getParent(), GV.getValueType(), + /*isConstant*/ false, GlobalValue::ExternalLinkage, + /*init*/ nullptr, "", + /*insertbefore*/ nullptr, GV.getThreadLocalMode(), + GV.getType()->getAddressSpace()); + NewGV->takeName(&GV); + GV.replaceAllUsesWith(NewGV); + return false; + } + return true; } /// Fixup WeakForLinker linkages in \p TheModule based on summary analysis. @@ -666,9 +676,13 @@ void llvm::thinLTOResolveWeakForLinkerModule( // interposable property and possibly get inlined. Simply drop // the definition in that case. if (GlobalValue::isAvailableExternallyLinkage(NewLinkage) && - GlobalValue::isInterposableLinkage(GV.getLinkage())) - convertToDeclaration(GV); - else { + GlobalValue::isInterposableLinkage(GV.getLinkage())) { + if (!convertToDeclaration(GV)) + // FIXME: Change this to collect replaced GVs and later erase + // them from the parent module once thinLTOResolveWeakForLinkerGUID is + // changed to enable this for aliases. + llvm_unreachable("Expected GV to be converted"); + } else { DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from " << GV.getLinkage() << " to " << NewLinkage << "\n"); GV.setLinkage(NewLinkage); |