[llvm-commits] CVS: llvm/include/llvm/Support/StableBasicBlockNumbering.h

Chris Lattner sabre at nondot.org
Mon Feb 5 15:19:42 PST 2007



Changes in directory llvm/include/llvm/Support:

StableBasicBlockNumbering.h updated: 1.2 -> 1.3
---
Log message:

StableBasicBlockNumbering is conceptually just a wrapper around UniqueVector,
so we should actually use a UniqueVector to implement it.


---
Diffs of the changes:  (+11 -22)

 StableBasicBlockNumbering.h |   33 +++++++++++----------------------
 1 files changed, 11 insertions(+), 22 deletions(-)


Index: llvm/include/llvm/Support/StableBasicBlockNumbering.h
diff -u llvm/include/llvm/Support/StableBasicBlockNumbering.h:1.2 llvm/include/llvm/Support/StableBasicBlockNumbering.h:1.3
--- llvm/include/llvm/Support/StableBasicBlockNumbering.h:1.2	Thu Apr 21 15:44:59 2005
+++ llvm/include/llvm/Support/StableBasicBlockNumbering.h	Mon Feb  5 17:19:24 2007
@@ -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 @@
     /// 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];
     }
-
   };
 }
 






More information about the llvm-commits mailing list