Change to use the StableBasicBlockNumbering class

llvm-svn: 14247
This commit is contained in:
Chris Lattner 2004-06-19 08:42:40 +00:00
parent d31410d824
commit 4db0f8260a
1 changed files with 7 additions and 15 deletions

View File

@ -24,6 +24,7 @@
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/Constant.h" #include "llvm/Constant.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/StableBasicBlockNumbering.h"
#include "Support/StringExtras.h" #include "Support/StringExtras.h"
using namespace llvm; using namespace llvm;
@ -131,12 +132,9 @@ namespace {
// Visited - The set of basic blocks the renamer has already visited. // Visited - The set of basic blocks the renamer has already visited.
std::set<BasicBlock*> Visited; std::set<BasicBlock*> Visited;
// BasicBlockNumbering - Holds a numbering of the basic blocks in the // BBNumbers - Contains a stable numbering of basic blocks to avoid
// function in a stable order that does not depend on their address. // non-determinstic behavior.
std::map<BasicBlock*, unsigned> BasicBlockNumbering; StableBasicBlockNumbering BBNumbers;
// NumberedBasicBlock - Holds the inverse mapping of BasicBlockNumbering.
std::vector<BasicBlock*> NumberedBasicBlock;
public: public:
PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt, PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt,
@ -288,13 +286,7 @@ void PromoteMem2Reg::run() {
// If we haven't computed a numbering for the BB's in the function, do so // If we haven't computed a numbering for the BB's in the function, do so
// now. // now.
if (NumberedBasicBlock.empty()) { BBNumbers.compute(F);
unsigned n = 0;
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I, ++n) {
NumberedBasicBlock.push_back(I);
BasicBlockNumbering[I] = n;
}
}
// Compute the locations where PhiNodes need to be inserted. Look at the // Compute the locations where PhiNodes need to be inserted. Look at the
// dominance frontier of EACH basic-block we have a write in. // dominance frontier of EACH basic-block we have a write in.
@ -318,13 +310,13 @@ void PromoteMem2Reg::run() {
// processing blocks in order of the occurance in the function. // processing blocks in order of the occurance in the function.
for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end(); for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
P != PE; ++P) P != PE; ++P)
DFBlocks.push_back(BasicBlockNumbering[*P]); DFBlocks.push_back(BBNumbers.getNumber(*P));
// Sort by which the block ordering in the function. // Sort by which the block ordering in the function.
std::sort(DFBlocks.begin(), DFBlocks.end()); std::sort(DFBlocks.begin(), DFBlocks.end());
for (unsigned i = 0, e = DFBlocks.size(); i != e; ++i) { for (unsigned i = 0, e = DFBlocks.size(); i != e; ++i) {
BasicBlock *BB = NumberedBasicBlock[DFBlocks[i]]; BasicBlock *BB = BBNumbers.getBlock(DFBlocks[i]);
if (QueuePhiNode(BB, AllocaNum, CurrentVersion, InsertedPHINodes)) if (QueuePhiNode(BB, AllocaNum, CurrentVersion, InsertedPHINodes))
DefiningBlocks.push_back(BB); DefiningBlocks.push_back(BB);
} }