diff options
author | Chris Lattner <sabre@nondot.org> | 2002-02-12 22:39:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-02-12 22:39:50 +0000 |
commit | 455889aa79e3463a4b0f2161e3d9d72a683268b6 (patch) | |
tree | af1cb8e20b69e33a7a744365fb6e15445abf81ed /lib/Transforms/Scalar | |
parent | cc179d3ab85fd19c3fd9586409c69d14fbb6c642 (diff) | |
download | external_llvm-455889aa79e3463a4b0f2161e3d9d72a683268b6.zip external_llvm-455889aa79e3463a4b0f2161e3d9d72a683268b6.tar.gz external_llvm-455889aa79e3463a4b0f2161e3d9d72a683268b6.tar.bz2 |
* Pull BasicBlock::pred_* and BasicBlock::succ_* out of BasicBlock.h and into
llvm/Support/CFG.h
* Make pred & succ iterators for intervals global functions
* Add #includes that are now neccesary because BasicBlock.h doesn't include
InstrTypes.h anymore
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1750 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r-- | lib/Transforms/Scalar/ADCE.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 37 | ||||
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InductionVars.cpp | 10 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 1 |
5 files changed, 32 insertions, 29 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 7f71cf1..91bed41 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -264,8 +264,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks, } // Recursively traverse successors of this basic block. - BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end(); - for (; SI != SE; ++SI) { + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) { BasicBlock *Succ = *SI; BasicBlock *Repl = fixupCFG(Succ, VisitedBlocks, AliveBlocks); if (Repl && Repl != Succ) { // We have to replace the successor @@ -278,8 +277,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks, BasicBlock *ReturnBB = 0; // Default to nothing live down here // Recursively traverse successors of this basic block. - BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end(); - for (; SI != SE; ++SI) { + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) { BasicBlock *RetBB = fixupCFG(*SI, VisitedBlocks, AliveBlocks); if (RetBB) { assert(ReturnBB == 0 && "One one live child allowed!"); diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 89cf45a..8f351a1 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -31,6 +31,7 @@ #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/Assembly/Writer.h" +#include "llvm/Support/CFG.h" #include "Support/STLExtras.h" #include <algorithm> @@ -73,15 +74,15 @@ bool DeadInstElimination::runOnBasicBlock(BasicBlock *BB) { // things in a basic block, if they are present. // static bool RemoveSingularPHIs(BasicBlock *BB) { - BasicBlock::pred_iterator PI(BB->pred_begin()); - if (PI == BB->pred_end() || ++PI != BB->pred_end()) + pred_iterator PI(pred_begin(BB)); + if (PI == pred_end(BB) || ++PI != pred_end(BB)) return false; // More than one predecessor... Instruction *I = BB->front(); if (!isa<PHINode>(I)) return false; // No PHI nodes //cerr << "Killing PHIs from " << BB; - //cerr << "Pred #0 = " << *BB->pred_begin(); + //cerr << "Pred #0 = " << *pred_begin(BB); //cerr << "Method == " << BB->getParent(); @@ -115,19 +116,19 @@ static void ReplaceUsesWithConstant(Instruction *I) { // Assumption: Succ is the single successor for BB. // static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { - assert(*BB->succ_begin() == Succ && "Succ is not successor of BB!"); + assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!"); assert(isa<PHINode>(Succ->front()) && "Only works on PHId BBs!"); // If there is more than one predecessor, and there are PHI nodes in // the successor, then we need to add incoming edges for the PHI nodes // - const std::vector<BasicBlock*> BBPreds(BB->pred_begin(), BB->pred_end()); + const std::vector<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB)); // Check to see if one of the predecessors of BB is already a predecessor of // Succ. If so, we cannot do the transformation! // - for (BasicBlock::pred_iterator PI = Succ->pred_begin(), PE = Succ->pred_end(); - PI != PE; ++PI) { + for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ); + PI != PE; ++PI) { if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) return true; } @@ -169,13 +170,13 @@ bool SimplifyCFG(Method::iterator &BBIt) { // Remove basic blocks that have no predecessors... which are unreachable. - if (BB->pred_begin() == BB->pred_end() && + if (pred_begin(BB) == pred_end(BB) && !BB->hasConstantReferences()) { //cerr << "Removing BB: \n" << BB; // Loop through all of our successors and make sure they know that one // of their predecessors is going away. - for_each(BB->succ_begin(), BB->succ_end(), + for_each(succ_begin(BB), succ_end(BB), std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB)); while (!BB->empty()) { @@ -196,10 +197,10 @@ bool SimplifyCFG(Method::iterator &BBIt) { // Check to see if this block has no instructions and only a single // successor. If so, replace block references with successor. - BasicBlock::succ_iterator SI(BB->succ_begin()); - if (SI != BB->succ_end() && ++SI == BB->succ_end()) { // One succ? + succ_iterator SI(succ_begin(BB)); + if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ? if (BB->front()->isTerminator()) { // Terminator is the only instruction! - BasicBlock *Succ = *BB->succ_begin(); // There is exactly one successor + BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor //cerr << "Killing Trivial BB: \n" << BB; if (Succ != BB) { // Arg, don't hurt infinite loops! @@ -227,16 +228,16 @@ bool SimplifyCFG(Method::iterator &BBIt) { // Merge basic blocks into their predecessor if there is only one pred, // and if there is only one successor of the predecessor. - BasicBlock::pred_iterator PI(BB->pred_begin()); - if (PI != BB->pred_end() && *PI != BB && // Not empty? Not same BB? - ++PI == BB->pred_end() && !BB->hasConstantReferences()) { - BasicBlock *Pred = *BB->pred_begin(); + pred_iterator PI(pred_begin(BB)); + if (PI != pred_end(BB) && *PI != BB && // Not empty? Not same BB? + ++PI == pred_end(BB) && !BB->hasConstantReferences()) { + BasicBlock *Pred = *pred_begin(BB); TerminatorInst *Term = Pred->getTerminator(); assert(Term != 0 && "malformed basic block without terminator!"); // Does the predecessor block only have a single successor? - BasicBlock::succ_iterator SI(Pred->succ_begin()); - if (++SI == Pred->succ_end()) { + succ_iterator SI(succ_begin(Pred)); + if (++SI == succ_end(Pred)) { //cerr << "Merging: " << BB << "into: " << Pred; // Delete the unconditianal branch from the predecessor... diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 59442ea..692fcac 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/Support/CFG.h" #include "Support/STLExtras.h" #if 0 @@ -87,8 +88,8 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { // Figure out which block is incoming and which is the backedge for the loop BasicBlock *Incoming, *BackEdgeBlock; - BasicBlock::pred_iterator PI = Header->pred_begin(); - assert(PI != Header->pred_end() && "Loop headers should have 2 preds!"); + pred_iterator PI = pred_begin(Header); + assert(PI != pred_end(Header) && "Loop headers should have 2 preds!"); if (Loop->contains(*PI)) { // First pred is back edge... BackEdgeBlock = *PI++; Incoming = *PI++; @@ -96,7 +97,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { Incoming = *PI++; BackEdgeBlock = *PI++; } - assert(PI == Header->pred_end() && "Loop headers should have 2 preds!"); + assert(PI == pred_end(Header) && "Loop headers should have 2 preds!"); // Add incoming values for the PHI node... PN->addIncoming(Constant::getNullConstant(Type::UIntTy), Incoming); diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index bc130f0..617c086 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -27,6 +27,8 @@ #include "llvm/iPHINode.h" #include "llvm/Method.h" #include "llvm/BasicBlock.h" +#include "llvm/InstrTypes.h" +#include "llvm/Support/CFG.h" #include "Support/STLExtras.h" #include <algorithm> #include <iostream> @@ -197,12 +199,12 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) { // Figure out which predecessors I have to play with... there should be // exactly two... one of which is a loop predecessor, and one of which is not. // - BasicBlock::pred_iterator PI = Header->pred_begin(); - assert(PI != Header->pred_end() && "Header node should have 2 preds!"); + pred_iterator PI = pred_begin(Header); + assert(PI != pred_end(Header) && "Header node should have 2 preds!"); BasicBlock *Pred1 = *PI; ++PI; - assert(PI != Header->pred_end() && "Header node should have 2 preds!"); + assert(PI != pred_end(Header) && "Header node should have 2 preds!"); BasicBlock *Pred2 = *PI; - assert(++PI == Header->pred_end() && "Header node should have 2 preds!"); + assert(++PI == pred_end(Header) && "Header node should have 2 preds!"); // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor if (Int->contains(Pred1)) std::swap(Pred1, Pred2); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 962ca97..3169250 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -18,6 +18,7 @@ #include "llvm/Transforms/Scalar/ConstantHandling.h" #include "llvm/Method.h" #include "llvm/iMemory.h" +#include "llvm/InstrTypes.h" #include "llvm/Support/InstIterator.h" #include "../TransformInternals.h" |