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/InstructionCombining.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/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 3169250255..08cf74637e 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -19,6 +19,7 @@ #include "llvm/Method.h" #include "llvm/iMemory.h" #include "llvm/InstrTypes.h" +#include "llvm/Pass.h" #include "llvm/Support/InstIterator.h" #include "../TransformInternals.h" @@ -37,7 +38,15 @@ static Instruction *CombineBinOp(BinaryOperator *I) { LocalChange = false; Value *Op1 = I->getOperand(0); if (Constant *Op2 = dyn_cast<Constant>(I->getOperand(1))) { - if (I->getOpcode() == Instruction::Add) { + switch (I->getOpcode()) { + case Instruction::Add: + if (I->getType()->isIntegral() && cast<ConstantInt>(Op2)->equalsInt(0)){ + // Eliminate 'add int %X, 0' + I->replaceAllUsesWith(Op1); // FIXME: This breaks the worklist + LocalChange = true; + break; + } + if (Instruction *IOp1 = dyn_cast<Instruction>(Op1)) { if (IOp1->getOpcode() == Instruction::Add && isa<Constant>(IOp1->getOperand(1))) { @@ -54,10 +63,23 @@ static Instruction *CombineBinOp(BinaryOperator *I) { I->setOperand(0, IOp1->getOperand(0)); I->setOperand(1, Val); LocalChange = true; + break; } } } + break; + + case Instruction::Mul: + if (I->getType()->isIntegral() && cast<ConstantInt>(Op2)->equalsInt(1)){ + // Eliminate 'mul int %X, 1' + I->replaceAllUsesWith(Op1); // FIXME: This breaks the worklist + LocalChange = true; + break; + } + + default: + break; } } Changed |= LocalChange; @@ -110,7 +132,7 @@ static Instruction *CombineIndicies(MemAccessInst *MAI) { return 0; } -bool InstructionCombining::CombineInstruction(Instruction *I) { +static bool CombineInstruction(Instruction *I) { Instruction *Result = 0; if (BinaryOperator *BOP = dyn_cast<BinaryOperator>(I)) Result = CombineBinOp(BOP); @@ -125,8 +147,7 @@ bool InstructionCombining::CombineInstruction(Instruction *I) { return true; } - -bool InstructionCombining::doit(Method *M) { +static bool doInstCombining(Method *M) { // Start the worklist out with all of the instructions in the method in it. std::vector<Instruction*> WorkList(inst_begin(M), inst_end(M)); @@ -148,3 +169,13 @@ bool InstructionCombining::doit(Method *M) { return false; } + +namespace { + struct InstructionCombining : public MethodPass { + virtual bool runOnMethod(Method *M) { return doInstCombining(M); } + }; +} + +Pass *createInstructionCombiningPass() { + return new InstructionCombining(); +} |