diff options
author | George Rimar <grimar@accesssoftek.com> | 2018-02-07 08:32:35 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2018-02-07 08:32:35 +0000 |
commit | 5f133dc99b42db10d342e7a8644507ff90c7f446 (patch) | |
tree | 0417a76c3cc1eb442e86aa22852a5ece98ed53f8 /llvm/lib/Transforms | |
parent | 2f70693e0854dfd6dc0a22fb932349872c4e8e52 (diff) | |
download | bcm5719-llvm-5f133dc99b42db10d342e7a8644507ff90c7f446.tar.gz bcm5719-llvm-5f133dc99b42db10d342e7a8644507ff90c7f446.zip |
[ThinLTO] - Simplify code in ThinLTOBitcodeWriter.
Recently introduced convertToDeclaration is very similar
to code used in filterModule function.
Patch reuses it to reduce duplication.
Differential revision: https://reviews.llvm.org/D42971
llvm-svn: 324455
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp index d2ce97abdd4..27ef6b3e4b4 100644 --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/FunctionAttrs.h" +#include "llvm/Transforms/IPO/FunctionImport.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/ModuleUtils.h" using namespace llvm; @@ -169,45 +170,18 @@ void simplifyExternals(Module &M) { } } -void filterModule( - Module *M, function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) { - for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end(); - I != E;) { - GlobalAlias *GA = &*I++; - if (ShouldKeepDefinition(GA)) - continue; - - GlobalObject *GO; - if (GA->getValueType()->isFunctionTy()) - GO = Function::Create(cast<FunctionType>(GA->getValueType()), - GlobalValue::ExternalLinkage, "", M); - else - GO = new GlobalVariable( - *M, GA->getValueType(), false, GlobalValue::ExternalLinkage, - nullptr, "", nullptr, - GA->getThreadLocalMode(), GA->getType()->getAddressSpace()); - GO->takeName(GA); - GA->replaceAllUsesWith(GO); - GA->eraseFromParent(); - } - - for (Function &F : *M) { - if (ShouldKeepDefinition(&F)) - continue; - - F.deleteBody(); - F.setComdat(nullptr); - F.clearMetadata(); - } - - for (GlobalVariable &GV : M->globals()) { +static void +filterModule(Module *M, + function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) { + auto I = M->global_values().begin(); + auto E = M->global_values().end(); + while (I != E) { + GlobalValue &GV = *I++; if (ShouldKeepDefinition(&GV)) continue; - - GV.setInitializer(nullptr); - GV.setLinkage(GlobalValue::ExternalLinkage); - GV.setComdat(nullptr); - GV.clearMetadata(); + if (convertToDeclaration(GV)) + continue; + GV.eraseFromParent(); } } |