aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-05 23:19:24 +0000
committerChris Lattner <sabre@nondot.org>2007-02-05 23:19:24 +0000
commitae6eb5bfbe9a01f6c4c7cca7db8468ee57a5a243 (patch)
treec32eb21893e6ef99ccd5a29292ef900b1f89ab97
parent1e46ae47b1dfe2d8f59da9cac9cedb52390c50fe (diff)
downloadexternal_llvm-ae6eb5bfbe9a01f6c4c7cca7db8468ee57a5a243.zip
external_llvm-ae6eb5bfbe9a01f6c4c7cca7db8468ee57a5a243.tar.gz
external_llvm-ae6eb5bfbe9a01f6c4c7cca7db8468ee57a5a243.tar.bz2
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
-rw-r--r--include/llvm/Support/StableBasicBlockNumbering.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/include/llvm/Support/StableBasicBlockNumbering.h b/include/llvm/Support/StableBasicBlockNumbering.h
index 7780b02..3ba72ea 100644
--- a/include/llvm/Support/StableBasicBlockNumbering.h
+++ b/include/llvm/Support/StableBasicBlockNumbering.h
@@ -18,18 +18,13 @@
#define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
#include "llvm/Function.h"
-#include <map>
+#include "llvm/ADT/UniqueVector.h"
namespace llvm {
class StableBasicBlockNumbering {
- // BasicBlockNumbering - Holds a numbering of the basic blocks in the
- // function in a stable order that does not depend on their address.
- std::map<BasicBlock*, unsigned> BasicBlockNumbering;
-
- // NumberedBasicBlock - Holds the inverse mapping of BasicBlockNumbering.
- std::vector<BasicBlock*> NumberedBasicBlock;
+ // BBNumbering - Holds the numbering.
+ UniqueVector<BasicBlock*> BBNumbering;
public:
-
StableBasicBlockNumbering(Function *F = 0) {
if (F) compute(*F);
}
@@ -37,33 +32,27 @@ namespace llvm {
/// compute - If we have not computed a numbering for the function yet, do
/// so.
void compute(Function &F) {
- if (NumberedBasicBlock.empty()) {
- unsigned n = 0;
- for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I, ++n) {
- NumberedBasicBlock.push_back(I);
- BasicBlockNumbering[I] = n;
- }
+ if (BBNumbering.empty()) {
+ for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+ BBNumbering.insert(I);
}
}
/// getNumber - Return the ID number for the specified BasicBlock.
///
unsigned getNumber(BasicBlock *BB) const {
- std::map<BasicBlock*, unsigned>::const_iterator I =
- BasicBlockNumbering.find(BB);
- assert(I != BasicBlockNumbering.end() &&
- "Invalid basic block or numbering not computed!");
- return I->second;
+ unsigned Idx = BBNumbering.idFor(BB);
+ assert(Idx && "Invalid basic block or numbering not computed!");
+ return Idx-1;
}
/// getBlock - Return the BasicBlock corresponding to a particular ID.
///
BasicBlock *getBlock(unsigned N) const {
- assert(N < NumberedBasicBlock.size() &&
+ assert(N < BBNumbering.size() &&
"Block ID out of range or numbering not computed!");
- return NumberedBasicBlock[N];
+ return BBNumbering[N+1];
}
-
};
}