Change the BasicBlockAddrs map to be a vector, indexed by MBB number.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28069 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h
index f63d6ed..f05375f 100644
--- a/include/llvm/CodeGen/MachineCodeEmitter.h
+++ b/include/llvm/CodeGen/MachineCodeEmitter.h
@@ -18,7 +18,7 @@
 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
 
 #include "llvm/Support/DataTypes.h"
-#include <map>
+#include <vector>
 
 namespace llvm {
 
@@ -76,10 +76,10 @@
   
   /// emitJumpTableInfo - This callback is invoked to output the jump tables
   /// for the function.  In addition to a pointer to the MachineJumpTableInfo,
-  /// this function also takes a map of MBBs to addresses, so that the final
+  /// this function also takes a map of MBB IDs to addresses, so that the final
   /// addresses of the MBBs can be written to the jump tables.
   virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
-                              std::map<MachineBasicBlock*,uint64_t> &MBBM) = 0;
+                                 std::vector<uint64_t> &MBBM) = 0;
   
   /// startFunctionStub - This callback is invoked when the JIT needs the
   /// address of a function that has not been code generated yet.  The StubSize
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index 69302a3..780ba54 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -71,7 +71,7 @@
     }
     
     virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
-                                   std::map<MachineBasicBlock*,uint64_t> &MBBM){
+                                   std::vector<uint64_t> &MBBM) {
       assert(0 && "JT not implementated yet!");
     }
 
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index d20c7a2..9a86377 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -392,7 +392,7 @@
     void emitConstantPool(MachineConstantPool *MCP);
     void initJumpTableInfo(MachineJumpTableInfo *MJTI);
     virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
-                                   std::map<MachineBasicBlock*,uint64_t> &MBBM);
+                                   std::vector<uint64_t> &MBBM);
     
     virtual void startFunctionStub(unsigned StubSize);
     virtual void* finishFunctionStub(const Function *F);
@@ -560,7 +560,7 @@
 }
 
 void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI,
-                                   std::map<MachineBasicBlock*,uint64_t> &MBBM){
+                                   std::vector<uint64_t> &MBBM) {
   const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
   if (JT.empty() || JumpTableBase == 0) return;
 
@@ -576,7 +576,7 @@
     // Store the address of the basic block for this jump table slot in the
     // memory we allocated for the jump table in 'initJumpTableInfo'
     for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi)
-      *SlotPtr++ = (intptr_t)MBBM[MBBs[mi]];
+      *SlotPtr++ = (intptr_t)MBBM[MBBs[mi]->getNumber()];
   }
 }
 
diff --git a/lib/Target/PowerPC/PPCCodeEmitter.cpp b/lib/Target/PowerPC/PPCCodeEmitter.cpp
index a01ae99..69bd830 100644
--- a/lib/Target/PowerPC/PPCCodeEmitter.cpp
+++ b/lib/Target/PowerPC/PPCCodeEmitter.cpp
@@ -33,8 +33,8 @@
 
     // Tracks which instruction references which BasicBlock
     std::vector<std::pair<MachineBasicBlock*, unsigned*> > BBRefs;
-    // Tracks where each BasicBlock starts
-    std::map<MachineBasicBlock*, uint64_t> BBLocations;
+    // Tracks where each BasicBlock starts, indexes by BB number.
+    std::vector<uint64_t> BasicBlockAddrs;
 
     /// getMachineOpValue - evaluates the MachineOperand of a given MachineInstr
     ///
@@ -87,17 +87,17 @@
          "JIT relocation model must be set to static or default!");
   do {
     BBRefs.clear();
-    BBLocations.clear();
+    BasicBlockAddrs.clear();
 
     MCE.startFunction(MF);
     for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB)
       emitBasicBlock(*BB);
-    MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BBLocations);
+    MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BasicBlockAddrs);
   } while (MCE.finishFunction(MF));
 
   // Resolve branches to BasicBlocks for the entire function
   for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
-    intptr_t Location = BBLocations[BBRefs[i].first];
+    intptr_t Location = BasicBlockAddrs[BBRefs[i].first->getNumber()];
     unsigned *Ref = BBRefs[i].second;
     DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
                     << "\n");
@@ -115,13 +115,15 @@
     }
   }
   BBRefs.clear();
-  BBLocations.clear();
+  BasicBlockAddrs.clear();
 
   return false;
 }
 
 void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
-  BBLocations[&MBB] = MCE.getCurrentPCValue();
+  if (BasicBlockAddrs.size() <= (unsigned)MBB.getNumber())
+    BasicBlockAddrs.resize((MBB.getNumber()+1)*2);
+  BasicBlockAddrs[MBB.getNumber()] = MCE.getCurrentPCValue();
   for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
     MachineInstr &MI = *I;
     unsigned Opcode = MI.getOpcode();
diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp
index 20e17d0..ca6c78d 100644
--- a/lib/Target/X86/X86CodeEmitter.cpp
+++ b/lib/Target/X86/X86CodeEmitter.cpp
@@ -35,7 +35,7 @@
   class Emitter : public MachineFunctionPass {
     const X86InstrInfo  *II;
     MachineCodeEmitter  &MCE;
-    std::map<MachineBasicBlock*, uint64_t> BasicBlockAddrs;
+    std::vector<uint64_t> BasicBlockAddrs;
     std::vector<std::pair<MachineBasicBlock *, unsigned> > BBRefs;
   public:
     explicit Emitter(MachineCodeEmitter &mce) : II(0), MCE(mce) {}
@@ -93,7 +93,7 @@
 
   // Resolve all forward branches now.
   for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
-    unsigned Location = BasicBlockAddrs[BBRefs[i].first];
+    unsigned Location = BasicBlockAddrs[BBRefs[i].first->getNumber()];
     unsigned Ref = BBRefs[i].second;
     *((unsigned*)(intptr_t)Ref) = Location-Ref-4;
   }
@@ -103,8 +103,9 @@
 }
 
 void Emitter::emitBasicBlock(MachineBasicBlock &MBB) {
-  if (uint64_t Addr = MCE.getCurrentPCValue())
-    BasicBlockAddrs[&MBB] = Addr;
+  if (BasicBlockAddrs.size() <= (unsigned)MBB.getNumber())
+    BasicBlockAddrs.resize((MBB.getNumber()+1)*2);
+  BasicBlockAddrs[MBB.getNumber()] = MCE.getCurrentPCValue();
 
   for (MachineBasicBlock::const_iterator I = MBB.begin(), E = MBB.end();
        I != E; ++I)
@@ -125,9 +126,9 @@
 void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
   // If this is a backwards branch, we already know the address of the target,
   // so just emit the value.
-  std::map<MachineBasicBlock*,uint64_t>::iterator I = BasicBlockAddrs.find(MBB);
-  if (I != BasicBlockAddrs.end()) {
-    emitPCRelativeValue(I->second);
+  unsigned MBBNo = MBB->getNumber();
+  if (MBBNo < BasicBlockAddrs.size() && BasicBlockAddrs[MBBNo]) {
+    emitPCRelativeValue(BasicBlockAddrs[MBBNo]);
   } else {
     // Otherwise, remember where this reference was and where it is to so we can
     // deal with it later.