summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp52
1 files changed, 12 insertions, 40 deletions
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index d2ce97abdd4..7cc1e06964b 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,46 +170,17 @@ 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()) {
- if (ShouldKeepDefinition(&GV))
- continue;
-
- GV.setInitializer(nullptr);
- GV.setLinkage(GlobalValue::ExternalLinkage);
- GV.setComdat(nullptr);
- GV.clearMetadata();
- }
+static void
+filterModule(Module *M,
+ function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
+ std::vector<GlobalValue *> V;
+ for (GlobalValue &GV : M->global_values())
+ if (!ShouldKeepDefinition(&GV))
+ V.push_back(&GV);
+
+ for (GlobalValue *GV : V)
+ if (!convertToDeclaration(*GV))
+ GV->eraseFromParent();
}
void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
OpenPOWER on IntegriCloud