summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/ConstantProp.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-09-07 16:41:30 +0000
committerChris Lattner <sabre@nondot.org>2001-09-07 16:41:30 +0000
commit9b644cc62781d23d206f536f2656c235ab6d84aa (patch)
treec8f0b78330245538da53b831dbfd3be09d8a703c /lib/Transforms/Scalar/ConstantProp.cpp
parent311611079b3db0d59cc4f532a4a06e4f88268e95 (diff)
downloadllvm-9b644cc62781d23d206f536f2656c235ab6d84aa.tar.gz
llvm-9b644cc62781d23d206f536f2656c235ab6d84aa.tar.bz2
llvm-9b644cc62781d23d206f536f2656c235ab6d84aa.tar.xz
* Supoprt global constants
* Remove support for local constant pools * Eliminate constant pool merging method, which is no longer neccesary * Disable invalid optimization (todo: fix it) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@452 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ConstantProp.cpp')
-rw-r--r--lib/Transforms/Scalar/ConstantProp.cpp68
1 files changed, 13 insertions, 55 deletions
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index f6b76c9aa0..fdf58cb56d 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -29,45 +29,6 @@
#include "llvm/iTerminators.h"
#include "llvm/iOther.h"
#include "llvm/ConstPoolVals.h"
-#include "llvm/ConstantPool.h"
-
-// Merge identical constant values in the constant pool.
-//
-// TODO: We can do better than this simplistic N^2 algorithm...
-//
-bool opt::DoConstantPoolMerging(Method *M) {
- return DoConstantPoolMerging(M->getConstantPool());
-}
-
-bool opt::DoConstantPoolMerging(ConstantPool &CP) {
- bool Modified = false;
- for (ConstantPool::plane_iterator PI = CP.begin(); PI != CP.end(); ++PI) {
- for (ConstantPool::PlaneType::iterator I = (*PI)->begin();
- I != (*PI)->end(); ++I) {
- ConstPoolVal *C = *I;
-
- ConstantPool::PlaneType::iterator J = I;
- for (++J; J != (*PI)->end(); ++J) {
- if (C->equals(*J)) {
- Modified = true;
- // Okay we know that *I == *J. So now we need to make all uses of *I
- // point to *J.
- //
- C->replaceAllUsesWith(*J);
-
- (*PI)->remove(I); // Remove C from constant pool...
-
- if (C->hasName() && !(*J)->hasName()) // The merged constant inherits
- (*J)->setName(C->getName()); // the old name...
-
- delete C; // Delete the constant itself.
- break; // Break out of inner for loop
- }
- }
- }
- }
- return Modified;
-}
inline static bool
ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
@@ -77,10 +38,6 @@ ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
if (!ReplaceWith) return false; // Nothing new to change...
-
- // Add the new value to the constant pool...
- M->getConstantPool().insert(ReplaceWith);
-
// Replaces all of the uses of a variable with uses of the constant.
Op->replaceAllUsesWith(ReplaceWith);
@@ -88,7 +45,8 @@ ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
Op->getParent()->getInstList().remove(DI.getInstructionIterator());
// The new constant inherits the old name of the operator...
- if (Op->hasName()) ReplaceWith->setName(Op->getName());
+ if (Op->hasName())
+ ReplaceWith->setName(Op->getName(), M->getSymbolTableSure());
// Delete the operator now...
delete Op;
@@ -103,9 +61,6 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
opt::ConstantFoldBinaryInstruction(Op->getOpcode(), D1, D2);
if (!ReplaceWith) return false; // Nothing new to change...
- // Add the new value to the constant pool...
- M->getConstantPool().insert(ReplaceWith);
-
// Replaces all of the uses of a variable with uses of the constant.
Op->replaceAllUsesWith(ReplaceWith);
@@ -113,7 +68,8 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
Op->getParent()->getInstList().remove(DI.getInstructionIterator());
// The new constant inherits the old name of the operator...
- if (Op->hasName()) ReplaceWith->setName(Op->getName());
+ if (Op->hasName())
+ ReplaceWith->setName(Op->getName(), M->getSymbolTableSure());
// Delete the operator now...
delete Op;
@@ -151,7 +107,12 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
// unconditional branch.
BI->setUnconditionalDest(Destination);
return true;
- } else if (Dest2 == Dest1) { // Conditional branch to same location?
+ }
+#if 0
+ // FIXME: TODO: This doesn't work if the destination has PHI nodes with
+ // different incoming values on each branch!
+ //
+ else if (Dest2 == Dest1) { // Conditional branch to same location?
// This branch matches something like this:
// br bool %cond, label %Dest, label %Dest
// and changes it into: br label %Dest
@@ -164,6 +125,7 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
BI->setUnconditionalDest(Dest1);
return true;
}
+#endif
}
return false;
}
@@ -196,7 +158,8 @@ ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
PN->replaceAllUsesWith(V); // Replace all uses of this PHI
// Unlink from basic block
PN->getParent()->getInstList().remove(II.getInstructionIterator());
- if (PN->hasName()) V->setName(PN->getName()); // Inherit PHINode name
+ if (PN->hasName()) // Inherit PHINode name
+ V->setName(PN->getName(), M->getSymbolTableSure());
delete PN; // Finally, delete the node...
return true;
}
@@ -243,10 +206,5 @@ bool opt::DoConstantPropogation(Method *M) {
// Fold constants until we make no progress...
while (DoConstPropPass(M)) Modified = true;
- // Merge identical constants last: this is important because we may have just
- // introduced constants that already exist!
- //
- Modified |= DoConstantPoolMerging(M->getConstantPool());
-
return Modified;
}