summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/CodeGen/MachineCodeEmitter.h6
-rw-r--r--lib/CodeGen/ELFWriter.cpp2
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp6
-rw-r--r--lib/Target/PowerPC/PPCCodeEmitter.cpp16
-rw-r--r--lib/Target/X86/X86CodeEmitter.cpp15
5 files changed, 24 insertions, 21 deletions
diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h
index f63d6ed0f4..f05375fc5f 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 @@ public:
/// 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 69302a3605..780ba543cd 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -71,7 +71,7 @@ namespace llvm {
}
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 d20c7a2ebd..9a86377208 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -392,7 +392,7 @@ public:
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::initJumpTableInfo(MachineJumpTableInfo *MJTI) {
}
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 @@ void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI,
// 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 a01ae99df1..69bd830785 100644
--- a/lib/Target/PowerPC/PPCCodeEmitter.cpp
+++ b/lib/Target/PowerPC/PPCCodeEmitter.cpp
@@ -33,8 +33,8 @@ namespace {
// 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 @@ bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
"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 @@ bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
}
}
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 20e17d0dbf..ca6c78df5e 100644
--- a/lib/Target/X86/X86CodeEmitter.cpp
+++ b/lib/Target/X86/X86CodeEmitter.cpp
@@ -35,7 +35,7 @@ namespace {
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 @@ bool Emitter::runOnMachineFunction(MachineFunction &MF) {
// 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 @@ bool Emitter::runOnMachineFunction(MachineFunction &MF) {
}
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::emitPCRelativeValue(unsigned Address) {
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.