StableBasicBlockNumbering is conceptually just a wrapper around UniqueVector,

so we should actually use a UniqueVector to implement it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33935 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-02-05 23:19:24 +00:00
parent 1e46ae47b1
commit ae6eb5bfbe

View File

@ -18,18 +18,13 @@
#define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H #define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
#include "llvm/Function.h" #include "llvm/Function.h"
#include <map> #include "llvm/ADT/UniqueVector.h"
namespace llvm { namespace llvm {
class StableBasicBlockNumbering { class StableBasicBlockNumbering {
// BasicBlockNumbering - Holds a numbering of the basic blocks in the // BBNumbering - Holds the numbering.
// function in a stable order that does not depend on their address. UniqueVector<BasicBlock*> BBNumbering;
std::map<BasicBlock*, unsigned> BasicBlockNumbering;
// NumberedBasicBlock - Holds the inverse mapping of BasicBlockNumbering.
std::vector<BasicBlock*> NumberedBasicBlock;
public: public:
StableBasicBlockNumbering(Function *F = 0) { StableBasicBlockNumbering(Function *F = 0) {
if (F) compute(*F); if (F) compute(*F);
} }
@ -37,33 +32,27 @@ namespace llvm {
/// compute - If we have not computed a numbering for the function yet, do /// compute - If we have not computed a numbering for the function yet, do
/// so. /// so.
void compute(Function &F) { void compute(Function &F) {
if (NumberedBasicBlock.empty()) { if (BBNumbering.empty()) {
unsigned n = 0; for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I, ++n) { BBNumbering.insert(I);
NumberedBasicBlock.push_back(I);
BasicBlockNumbering[I] = n;
}
} }
} }
/// getNumber - Return the ID number for the specified BasicBlock. /// getNumber - Return the ID number for the specified BasicBlock.
/// ///
unsigned getNumber(BasicBlock *BB) const { unsigned getNumber(BasicBlock *BB) const {
std::map<BasicBlock*, unsigned>::const_iterator I = unsigned Idx = BBNumbering.idFor(BB);
BasicBlockNumbering.find(BB); assert(Idx && "Invalid basic block or numbering not computed!");
assert(I != BasicBlockNumbering.end() && return Idx-1;
"Invalid basic block or numbering not computed!");
return I->second;
} }
/// getBlock - Return the BasicBlock corresponding to a particular ID. /// getBlock - Return the BasicBlock corresponding to a particular ID.
/// ///
BasicBlock *getBlock(unsigned N) const { BasicBlock *getBlock(unsigned N) const {
assert(N < NumberedBasicBlock.size() && assert(N < BBNumbering.size() &&
"Block ID out of range or numbering not computed!"); "Block ID out of range or numbering not computed!");
return NumberedBasicBlock[N]; return BBNumbering[N+1];
} }
}; };
} }