[llvm-commits] CVS: llvm/lib/Transforms/IPO/GlobalConstifier.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Jul 19 20:58:17 PDT 2004
Changes in directory llvm/lib/Transforms/IPO:
GlobalConstifier.cpp updated: 1.4 -> 1.5
---
Log message:
Ignore instructions that are in trivially dead functions. This allows us
to constify 14 globals instead of 4 in a trivial C++ testcase.
---
Diffs of the changes: (+17 -4)
Index: llvm/lib/Transforms/IPO/GlobalConstifier.cpp
diff -u llvm/lib/Transforms/IPO/GlobalConstifier.cpp:1.4 llvm/lib/Transforms/IPO/GlobalConstifier.cpp:1.5
--- llvm/lib/Transforms/IPO/GlobalConstifier.cpp:1.4 Sun Jul 18 14:56:20 2004
+++ llvm/lib/Transforms/IPO/GlobalConstifier.cpp Mon Jul 19 22:58:07 2004
@@ -39,6 +39,16 @@
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 @@
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;
More information about the llvm-commits
mailing list