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
This commit is contained in:
Chris Lattner 2006-05-03 00:32:55 +00:00
parent 23118b649e
commit af1563fb62
5 changed files with 24 additions and 21 deletions

View File

@ -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

View File

@ -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!");
}

View File

@ -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()];
}
}

View File

@ -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();

View File

@ -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.