diff options
author | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-02-26 21:46:54 +0000 |
commit | bd0ef77cde9c9e82f2b4ad33e4982c46274d6540 (patch) | |
tree | 0903b61112c9e6d336c8b623e235ede2f937f13c /lib/Transforms/Scalar/ConstantProp.cpp | |
parent | 3b2541424f771ae11c30675ce06da7b380780028 (diff) |
Change over to use new style pass mechanism, now passes only expose small
creation functions in their public header file, unless they can help it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1816 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ConstantProp.cpp')
-rw-r--r-- | lib/Transforms/Scalar/ConstantProp.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index 190bd4b919..fc4e3bf0e3 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -29,6 +29,7 @@ #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" +#include "llvm/Pass.h" #include "llvm/ConstantVals.h" inline static bool @@ -153,8 +154,7 @@ bool ConstantFoldTerminator(TerminatorInst *T) { // ConstantFoldInstruction - If an instruction references constants, try to fold // them together... // -bool ConstantPropogation::doConstantPropogation(BasicBlock *BB, - BasicBlock::iterator &II) { +bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &II) { Instruction *Inst = *II; if (isa<BinaryOperator>(Inst)) { Constant *D1 = dyn_cast<Constant>(Inst->getOperand(0)); @@ -200,7 +200,7 @@ static bool DoConstPropPass(Method *M) { for (Method::iterator BBI = M->begin(); BBI != M->end(); ++BBI) { BasicBlock *BB = *BBI; for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ) - if (ConstantPropogation::doConstantPropogation(BB, I)) + if (doConstantPropogation(BB, I)) SomethingChanged = true; else ++I; @@ -208,14 +208,20 @@ static bool DoConstPropPass(Method *M) { return SomethingChanged; } +namespace { + struct ConstantPropogation : public MethodPass { + inline bool runOnMethod(Method *M) { + bool Modified = false; -// returns whether or not the underlying method was modified -// -bool ConstantPropogation::doConstantPropogation(Method *M) { - bool Modified = false; - - // Fold constants until we make no progress... - while (DoConstPropPass(M)) Modified = true; + // Fold constants until we make no progress... + while (DoConstPropPass(M)) Modified = true; + + return Modified; + } + }; +} - return Modified; +Pass *createConstantPropogationPass() { + return new ConstantPropogation(); } + |