summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-20 03:58:07 +0000
committerChris Lattner <sabre@nondot.org>2004-07-20 03:58:07 +0000
commitec67df0ed1c4ac2dc1eeea5e9b5429e05648cb62 (patch)
tree3e2ad6cd48cda54d770857e666bf23f83691aa7f
parente036ff8b32665de5293ba34ea38359a33b114531 (diff)
downloadbcm5719-llvm-ec67df0ed1c4ac2dc1eeea5e9b5429e05648cb62.tar.gz
bcm5719-llvm-ec67df0ed1c4ac2dc1eeea5e9b5429e05648cb62.zip
Ignore instructions that are in trivially dead functions. This allows us
to constify 14 globals instead of 4 in a trivial C++ testcase. llvm-svn: 15027
-rw-r--r--llvm/lib/Transforms/IPO/GlobalConstifier.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalConstifier.cpp b/llvm/lib/Transforms/IPO/GlobalConstifier.cpp
index 6f01f25f507..97518a34fab 100644
--- a/llvm/lib/Transforms/IPO/GlobalConstifier.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalConstifier.cpp
@@ -39,6 +39,16 @@ namespace {
Pass *llvm::createGlobalConstifierPass() { return new Constifier(); }
+/// A lot of global constants are stored only in trivially dead setter
+/// functions. Because we don't want to cycle between globaldce and this pass,
+/// just do a simple check to catch the common case.
+static bool ContainingFunctionIsTriviallyDead(Instruction *I) {
+ Function *F = I->getParent()->getParent();
+ if (!F->hasInternalLinkage()) return false;
+ F->removeDeadConstantUsers();
+ return F->use_empty();
+}
+
/// isStoredThrough - Return false if the specified pointer is provably never
/// stored through. If we can't tell, we must conservatively assume it might.
///
@@ -48,10 +58,13 @@ static bool isStoredThrough(Value *V) {
if (isStoredThrough(CE))
return true;
} else if (Instruction *I = dyn_cast<Instruction>(*UI)) {
- if (I->getOpcode() == Instruction::GetElementPtr) {
- if (isStoredThrough(I)) return true;
- } else if (!isa<LoadInst>(*UI) && !isa<SetCondInst>(*UI))
- return true; // Any other non-load instruction might store!
+ if (!ContainingFunctionIsTriviallyDead(I)) {
+ if (I->getOpcode() == Instruction::GetElementPtr) {
+ if (isStoredThrough(I)) return true;
+ } else if (!isa<LoadInst>(*UI) && !isa<SetCondInst>(*UI)) {
+ return true; // Any other non-load instruction might store!
+ }
+ }
} else {
// Otherwise must be a global or some other user.
return true;
OpenPOWER on IntegriCloud