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 | |
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')
-rw-r--r-- | lib/Transforms/Scalar/ADCE.cpp | 33 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ConstantProp.cpp | 28 | ||||
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 58 | ||||
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 25 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 39 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SymbolStripping.cpp | 27 |
7 files changed, 170 insertions, 60 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 91bed41f6c..14c68f410e 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -288,21 +288,24 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks, } } - - -// doADCE - Execute the Agressive Dead Code Elimination Algorithm -// -bool AgressiveDCE::runOnMethod(Method *M) { - return ADCE(M).doADCE( - getAnalysis<cfg::DominanceFrontier>(cfg::DominanceFrontier::PostDomID)); +namespace { + struct AgressiveDCE : public MethodPass { + // doADCE - Execute the Agressive Dead Code Elimination Algorithm + // + virtual bool runOnMethod(Method *M) { + return ADCE(M).doADCE( + getAnalysis<cfg::DominanceFrontier>(cfg::DominanceFrontier::PostDomID)); + } + // getAnalysisUsageInfo - We require post dominance frontiers (aka Control + // Dependence Graph) + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Requires.push_back(cfg::DominanceFrontier::PostDomID); + } + }; } - -// getAnalysisUsageInfo - We require post dominance frontiers (aka Control -// Dependence Graph) -// -void AgressiveDCE::getAnalysisUsageInfo(Pass::AnalysisSet &Requires, - Pass::AnalysisSet &Destroyed, - Pass::AnalysisSet &Provided) { - Requires.push_back(cfg::DominanceFrontier::PostDomID); +Pass *createAgressiveDCEPass() { + return new AgressiveDCE(); } 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(); } + diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 8f351a1431..491c957fb2 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -32,6 +32,7 @@ #include "llvm/iPHINode.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" +#include "llvm/Pass.h" #include "Support/STLExtras.h" #include <algorithm> @@ -40,8 +41,8 @@ // to point to the instruction that immediately succeeded the original // instruction. // -bool DeadCodeElimination::dceInstruction(BasicBlock::InstListType &BBIL, - BasicBlock::iterator &BBI) { +bool dceInstruction(BasicBlock::InstListType &BBIL, + BasicBlock::iterator &BBI) { // Look for un"used" definitions... if ((*BBI)->use_empty() && !(*BBI)->hasSideEffects() && !isa<TerminatorInst>(*BBI)) { @@ -55,15 +56,21 @@ static inline bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) { bool Changed = false; for (BasicBlock::InstListType::iterator DI = Vals.begin(); DI != Vals.end(); ) - if (DeadCodeElimination::dceInstruction(Vals, DI)) + if (dceInstruction(Vals, DI)) Changed = true; else ++DI; return Changed; } -bool DeadInstElimination::runOnBasicBlock(BasicBlock *BB) { - return RemoveUnusedDefs(BB->getInstList()); +struct DeadInstElimination : public BasicBlockPass { + virtual bool runOnBasicBlock(BasicBlock *BB) { + return RemoveUnusedDefs(BB->getInstList()); + } +}; + +Pass *createDeadInstEliminationPass() { + return new DeadInstElimination(); } // RemoveSingularPHIs - This removes PHI nodes from basic blocks that have only @@ -297,17 +304,11 @@ static bool DoDCEPass(Method *M) { return Changed; } - -// It is possible that we may require multiple passes over the code to fully -// eliminate dead code. Iterate until we are done. +// Remove unused global values - This removes unused global values of no +// possible value. This currently includes unused method prototypes and +// unitialized global variables. // -bool DeadCodeElimination::doDCE(Method *M) { - bool Changed = false; - while (DoDCEPass(M)) Changed = true; - return Changed; -} - -bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) { +static bool RemoveUnusedGlobalValues(Module *Mod) { bool Changed = false; for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) { @@ -338,3 +339,30 @@ bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) { return Changed; } + +namespace { + struct DeadCodeElimination : public MethodPass { + + // Pass Interface... + virtual bool doInitialization(Module *M) { + return RemoveUnusedGlobalValues(M); + } + + // It is possible that we may require multiple passes over the code to fully + // eliminate dead code. Iterate until we are done. + // + virtual bool runOnMethod(Method *M) { + bool Changed = false; + while (DoDCEPass(M)) Changed = true; + return Changed; + } + + virtual bool doFinalization(Module *M) { + return RemoveUnusedGlobalValues(M); + } + }; +} + +Pass *createDeadCodeEliminationPass() { + return new DeadCodeElimination(); +} diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 692fcacb7e..fcf49e171a 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -13,6 +13,7 @@ #include "llvm/Type.h" #include "llvm/BasicBlock.h" #include "llvm/ConstantVals.h" +#include "llvm/Pass.h" #include "llvm/Support/CFG.h" #include "Support/STLExtras.h" @@ -186,19 +187,29 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { return Changed; } -bool InductionVariableSimplify::doit(Method *M, cfg::LoopInfo &Loops) { +static bool doit(Method *M, cfg::LoopInfo &Loops) { // Induction Variables live in the header nodes of the loops of the method... return reduce_apply_bool(Loops.getTopLevelLoops().begin(), Loops.getTopLevelLoops().end(), std::bind1st(std::ptr_fun(TransformLoop), &Loops)); } -bool InductionVariableSimplify::runOnMethod(Method *M) { - return doit(M, getAnalysis<cfg::LoopInfo>()); + +namespace { + struct InductionVariableSimplify : public MethodPass { + virtual bool runOnMethod(Method *M) { + return doit(M, getAnalysis<cfg::LoopInfo>()); + } + + virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Required, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Required.push_back(cfg::LoopInfo::ID); + } + }; } -void InductionVariableSimplify::getAnalysisUsageInfo(Pass::AnalysisSet &Req, - Pass::AnalysisSet &Dest, - Pass::AnalysisSet &Prov) { - Req.push_back(cfg::LoopInfo::ID); +Pass *createIndVarSimplifyPass() { + return new InductionVariableSimplify(); } + 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(); +} diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index ada670deb8..447a3e1960 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -25,6 +25,7 @@ #include "llvm/iMemory.h" #include "llvm/iTerminators.h" #include "llvm/iOther.h" +#include "llvm/Pass.h" #include "llvm/Assembly/Writer.h" #include "Support/STLExtras.h" #include <algorithm> @@ -503,11 +504,18 @@ void SCCP::OperandChangedState(User *U) { UpdateInstruction(I); } +namespace { + // SCCPPass - Use Sparse Conditional Constant Propogation + // to prove whether a value is constant and whether blocks are used. + // + struct SCCPPass : public MethodPass { + inline bool runOnMethod(Method *M) { + SCCP S(M); + return S.doSCCP(); + } + }; +} -// DoSparseConditionalConstantProp - Use Sparse Conditional Constant Propogation -// to prove whether a value is constant and whether blocks are used. -// -bool SCCPPass::doSCCP(Method *M) { - SCCP S(M); - return S.doSCCP(); +Pass *createSCCPPass() { + return new SCCPPass(); } diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp index 12f8e918b3..8502082a15 100644 --- a/lib/Transforms/Scalar/SymbolStripping.cpp +++ b/lib/Transforms/Scalar/SymbolStripping.cpp @@ -18,6 +18,7 @@ #include "llvm/Module.h" #include "llvm/Method.h" #include "llvm/SymbolTable.h" +#include "llvm/Pass.h" static bool StripSymbolTable(SymbolTable *SymTab) { if (SymTab == 0) return false; // No symbol table? No problem. @@ -44,16 +45,38 @@ static bool StripSymbolTable(SymbolTable *SymTab) { // DoSymbolStripping - Remove all symbolic information from a method // -bool SymbolStripping::doSymbolStripping(Method *M) { +static bool doSymbolStripping(Method *M) { return StripSymbolTable(M->getSymbolTable()); } // doStripGlobalSymbols - Remove all symbolic information from all methods // in a module, and all module level symbols. (method names, etc...) // -bool FullSymbolStripping::doStripGlobalSymbols(Module *M) { +static bool doStripGlobalSymbols(Module *M) { // Remove all symbols from methods in this module... and then strip all of the // symbols in this module... // return StripSymbolTable(M->getSymbolTable()); } + +namespace { + struct SymbolStripping : public MethodPass { + virtual bool runOnMethod(Method *M) { + return doSymbolStripping(M); + } + }; + + struct FullSymbolStripping : public SymbolStripping { + virtual bool doInitialization(Module *M) { + return doStripGlobalSymbols(M); + } + }; +} + +Pass *createSymbolStrippingPass() { + return new SymbolStripping(); +} + +Pass *createFullSymbolStrippingPass() { + return new FullSymbolStripping(); +} |