aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/ExtractGV.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
commitcfca06d7963fa0909f90483b42a6d7d194d01e08 (patch)
tree209fb2a2d68f8f277793fc8df46c753d31bc853b /llvm/lib/Transforms/IPO/ExtractGV.cpp
parent706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff)
Notes
Diffstat (limited to 'llvm/lib/Transforms/IPO/ExtractGV.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/ExtractGV.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/IPO/ExtractGV.cpp b/llvm/lib/Transforms/IPO/ExtractGV.cpp
index f77b528fc42d..b45766a8e783 100644
--- a/llvm/lib/Transforms/IPO/ExtractGV.cpp
+++ b/llvm/lib/Transforms/IPO/ExtractGV.cpp
@@ -54,6 +54,7 @@ namespace {
class GVExtractorPass : public ModulePass {
SetVector<GlobalValue *> Named;
bool deleteStuff;
+ bool keepConstInit;
public:
static char ID; // Pass identification, replacement for typeid
@@ -61,8 +62,9 @@ namespace {
/// Otherwise, it deletes as much of the module as possible, except for the
/// global values specified.
explicit GVExtractorPass(std::vector<GlobalValue*> &GVs,
- bool deleteS = true)
- : ModulePass(ID), Named(GVs.begin(), GVs.end()), deleteStuff(deleteS) {}
+ bool deleteS = true, bool keepConstInit = false)
+ : ModulePass(ID), Named(GVs.begin(), GVs.end()), deleteStuff(deleteS),
+ keepConstInit(keepConstInit) {}
bool runOnModule(Module &M) override {
if (skipModule(M))
@@ -83,7 +85,8 @@ namespace {
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
bool Delete =
- deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration();
+ deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration() &&
+ (!I->isConstant() || !keepConstInit);
if (!Delete) {
if (I->hasAvailableExternallyLinkage())
continue;
@@ -156,6 +159,6 @@ namespace {
}
ModulePass *llvm::createGVExtractionPass(std::vector<GlobalValue *> &GVs,
- bool deleteFn) {
- return new GVExtractorPass(GVs, deleteFn);
+ bool deleteFn, bool keepConstInit) {
+ return new GVExtractorPass(GVs, deleteFn, keepConstInit);
}