mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-29 10:25:12 +00:00
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:
@@ -18,7 +18,7 @@
|
|||||||
#define LLVM_CODEGEN_MACHINECODEEMITTER_H
|
#define LLVM_CODEGEN_MACHINECODEEMITTER_H
|
||||||
|
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
#include <map>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
@@ -76,10 +76,10 @@ public:
|
|||||||
|
|
||||||
/// emitJumpTableInfo - This callback is invoked to output the jump tables
|
/// emitJumpTableInfo - This callback is invoked to output the jump tables
|
||||||
/// for the function. In addition to a pointer to the MachineJumpTableInfo,
|
/// 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.
|
/// addresses of the MBBs can be written to the jump tables.
|
||||||
virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
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
|
/// startFunctionStub - This callback is invoked when the JIT needs the
|
||||||
/// address of a function that has not been code generated yet. The StubSize
|
/// address of a function that has not been code generated yet. The StubSize
|
||||||
|
@@ -71,7 +71,7 @@ namespace llvm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
||||||
std::map<MachineBasicBlock*,uint64_t> &MBBM){
|
std::vector<uint64_t> &MBBM) {
|
||||||
assert(0 && "JT not implementated yet!");
|
assert(0 && "JT not implementated yet!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -392,7 +392,7 @@ public:
|
|||||||
void emitConstantPool(MachineConstantPool *MCP);
|
void emitConstantPool(MachineConstantPool *MCP);
|
||||||
void initJumpTableInfo(MachineJumpTableInfo *MJTI);
|
void initJumpTableInfo(MachineJumpTableInfo *MJTI);
|
||||||
virtual void emitJumpTableInfo(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 startFunctionStub(unsigned StubSize);
|
||||||
virtual void* finishFunctionStub(const Function *F);
|
virtual void* finishFunctionStub(const Function *F);
|
||||||
@@ -560,7 +560,7 @@ void JITEmitter::initJumpTableInfo(MachineJumpTableInfo *MJTI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JITEmitter::emitJumpTableInfo(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();
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
||||||
if (JT.empty() || JumpTableBase == 0) return;
|
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
|
// Store the address of the basic block for this jump table slot in the
|
||||||
// memory we allocated for the jump table in 'initJumpTableInfo'
|
// memory we allocated for the jump table in 'initJumpTableInfo'
|
||||||
for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi)
|
for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi)
|
||||||
*SlotPtr++ = (intptr_t)MBBM[MBBs[mi]];
|
*SlotPtr++ = (intptr_t)MBBM[MBBs[mi]->getNumber()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,8 +33,8 @@ namespace {
|
|||||||
|
|
||||||
// Tracks which instruction references which BasicBlock
|
// Tracks which instruction references which BasicBlock
|
||||||
std::vector<std::pair<MachineBasicBlock*, unsigned*> > BBRefs;
|
std::vector<std::pair<MachineBasicBlock*, unsigned*> > BBRefs;
|
||||||
// Tracks where each BasicBlock starts
|
// Tracks where each BasicBlock starts, indexes by BB number.
|
||||||
std::map<MachineBasicBlock*, uint64_t> BBLocations;
|
std::vector<uint64_t> BasicBlockAddrs;
|
||||||
|
|
||||||
/// getMachineOpValue - evaluates the MachineOperand of a given MachineInstr
|
/// 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!");
|
"JIT relocation model must be set to static or default!");
|
||||||
do {
|
do {
|
||||||
BBRefs.clear();
|
BBRefs.clear();
|
||||||
BBLocations.clear();
|
BasicBlockAddrs.clear();
|
||||||
|
|
||||||
MCE.startFunction(MF);
|
MCE.startFunction(MF);
|
||||||
for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB)
|
for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB)
|
||||||
emitBasicBlock(*BB);
|
emitBasicBlock(*BB);
|
||||||
MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BBLocations);
|
MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BasicBlockAddrs);
|
||||||
} while (MCE.finishFunction(MF));
|
} while (MCE.finishFunction(MF));
|
||||||
|
|
||||||
// Resolve branches to BasicBlocks for the entire function
|
// Resolve branches to BasicBlocks for the entire function
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
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;
|
unsigned *Ref = BBRefs[i].second;
|
||||||
DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
|
DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
|
||||||
<< "\n");
|
<< "\n");
|
||||||
@@ -115,13 +115,15 @@ bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BBRefs.clear();
|
BBRefs.clear();
|
||||||
BBLocations.clear();
|
BasicBlockAddrs.clear();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
|
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){
|
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){
|
||||||
MachineInstr &MI = *I;
|
MachineInstr &MI = *I;
|
||||||
unsigned Opcode = MI.getOpcode();
|
unsigned Opcode = MI.getOpcode();
|
||||||
|
@@ -35,7 +35,7 @@ namespace {
|
|||||||
class Emitter : public MachineFunctionPass {
|
class Emitter : public MachineFunctionPass {
|
||||||
const X86InstrInfo *II;
|
const X86InstrInfo *II;
|
||||||
MachineCodeEmitter &MCE;
|
MachineCodeEmitter &MCE;
|
||||||
std::map<MachineBasicBlock*, uint64_t> BasicBlockAddrs;
|
std::vector<uint64_t> BasicBlockAddrs;
|
||||||
std::vector<std::pair<MachineBasicBlock *, unsigned> > BBRefs;
|
std::vector<std::pair<MachineBasicBlock *, unsigned> > BBRefs;
|
||||||
public:
|
public:
|
||||||
explicit Emitter(MachineCodeEmitter &mce) : II(0), MCE(mce) {}
|
explicit Emitter(MachineCodeEmitter &mce) : II(0), MCE(mce) {}
|
||||||
@@ -93,7 +93,7 @@ bool Emitter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
|
|
||||||
// Resolve all forward branches now.
|
// Resolve all forward branches now.
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
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 Ref = BBRefs[i].second;
|
||||||
*((unsigned*)(intptr_t)Ref) = Location-Ref-4;
|
*((unsigned*)(intptr_t)Ref) = Location-Ref-4;
|
||||||
}
|
}
|
||||||
@@ -103,8 +103,9 @@ bool Emitter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Emitter::emitBasicBlock(MachineBasicBlock &MBB) {
|
void Emitter::emitBasicBlock(MachineBasicBlock &MBB) {
|
||||||
if (uint64_t Addr = MCE.getCurrentPCValue())
|
if (BasicBlockAddrs.size() <= (unsigned)MBB.getNumber())
|
||||||
BasicBlockAddrs[&MBB] = Addr;
|
BasicBlockAddrs.resize((MBB.getNumber()+1)*2);
|
||||||
|
BasicBlockAddrs[MBB.getNumber()] = MCE.getCurrentPCValue();
|
||||||
|
|
||||||
for (MachineBasicBlock::const_iterator I = MBB.begin(), E = MBB.end();
|
for (MachineBasicBlock::const_iterator I = MBB.begin(), E = MBB.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
@@ -125,9 +126,9 @@ void Emitter::emitPCRelativeValue(unsigned Address) {
|
|||||||
void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
|
void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
|
||||||
// If this is a backwards branch, we already know the address of the target,
|
// If this is a backwards branch, we already know the address of the target,
|
||||||
// so just emit the value.
|
// so just emit the value.
|
||||||
std::map<MachineBasicBlock*,uint64_t>::iterator I = BasicBlockAddrs.find(MBB);
|
unsigned MBBNo = MBB->getNumber();
|
||||||
if (I != BasicBlockAddrs.end()) {
|
if (MBBNo < BasicBlockAddrs.size() && BasicBlockAddrs[MBBNo]) {
|
||||||
emitPCRelativeValue(I->second);
|
emitPCRelativeValue(BasicBlockAddrs[MBBNo]);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, remember where this reference was and where it is to so we can
|
// Otherwise, remember where this reference was and where it is to so we can
|
||||||
// deal with it later.
|
// deal with it later.
|
||||||
|
Reference in New Issue
Block a user