From bd0ef77cde9c9e82f2b4ad33e4982c46274d6540 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 26 Feb 2002 21:46:54 +0000 Subject: 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 --- lib/Transforms/Scalar/ConstantProp.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'lib/Transforms/Scalar/ConstantProp.cpp') 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(Inst)) { Constant *D1 = dyn_cast(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(); } + -- cgit v1.2.3