Finegrainify namespacification
authorChris Lattner <sabre@nondot.org>
Fri, 30 Jan 2004 22:08:53 +0000 (22:08 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 30 Jan 2004 22:08:53 +0000 (22:08 +0000)
Implement LiveVariables::getIndexMachineBasicBlock

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11018 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveVariables.cpp

index bf78c53214cfe050790a8ccac8ced8a907b8648e..845af13a30b696268fb61ed8494f8c9110912ab8 100644 (file)
@@ -32,8 +32,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
-
-namespace llvm {
+using namespace llvm;
 
 static RegisterAnalysis<LiveVariables> X("livevars", "Live Variable Analysis");
 
@@ -41,6 +40,22 @@ const std::pair<MachineBasicBlock*, unsigned> &
 LiveVariables::getMachineBasicBlockInfo(MachineBasicBlock *MBB) const{
   return BBMap.find(MBB->getBasicBlock())->second;
 }
+  
+/// getIndexMachineBasicBlock() - Given a block index, return the
+/// MachineBasicBlock corresponding to it.
+MachineBasicBlock *LiveVariables::getIndexMachineBasicBlock(unsigned Idx) {
+  if (BBIdxMap.empty()) {
+    BBIdxMap.resize(BBMap.size());
+    for (std::map<const BasicBlock*, std::pair<MachineBasicBlock*, unsigned> >
+           ::iterator I = BBMap.begin(), E = BBMap.end(); I != E; ++I) {
+      assert(BBIdxMap.size() > I->second.second &&"Indices are not sequential");
+      assert(BBIdxMap[I->second.second] == 0 && "Multiple idx collision!");
+      BBIdxMap[I->second.second] = I->second.first;
+    }
+  }
+  assert(Idx < BBIdxMap.size() && "BB Index out of range!");
+  return BBIdxMap[Idx];
+}
 
 LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) {
   assert(RegIdx >= MRegisterInfo::FirstVirtualRegister &&
@@ -300,5 +315,3 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
   
   return false;
 }
-
-} // End llvm namespace