mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
Resolve BB references with relocation.
llvm-svn: 29351
This commit is contained in:
parent
ca081a735e
commit
4ceeac4159
@ -83,26 +83,12 @@ namespace llvm {
|
|||||||
assert(NumRelocs == 0 && "This target does not have relocations!");
|
assert(NumRelocs == 0 && "This target does not have relocations!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// resolveBBRefs - Resolve branches to BasicBlocks for the JIT emitted
|
|
||||||
/// function.
|
|
||||||
virtual void resolveBBRefs(MachineCodeEmitter &MCE) {}
|
|
||||||
|
|
||||||
/// addBBRef - Add a BasicBlock reference to be resolved after the function
|
|
||||||
/// is emitted.
|
|
||||||
void addBBRef(MachineBasicBlock *BB, intptr_t PC) {
|
|
||||||
BBRefs.push_back(std::make_pair(BB, PC));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// needsGOT - Allows a target to specify that it would like the
|
/// needsGOT - Allows a target to specify that it would like the
|
||||||
// JIT to manage a GOT for it.
|
// JIT to manage a GOT for it.
|
||||||
bool needsGOT() const { return useGOT; }
|
bool needsGOT() const { return useGOT; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool useGOT;
|
bool useGOT;
|
||||||
|
|
||||||
// Tracks which instruction references which BasicBlock
|
|
||||||
std::vector<std::pair<MachineBasicBlock*, intptr_t> > BBRefs;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
|
@ -807,13 +807,13 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
|
|||||||
ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
|
ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
|
||||||
BufferBegin+MR.getMachineCodeOffset(),
|
BufferBegin+MR.getMachineCodeOffset(),
|
||||||
MR.doesntNeedFunctionStub());
|
MR.doesntNeedFunctionStub());
|
||||||
|
} else if (MR.isBasicBlock()) {
|
||||||
|
ResultPtr = (void*)getMachineBasicBlockAddress(MR.getBasicBlock());
|
||||||
} else if (MR.isConstantPoolIndex()){
|
} else if (MR.isConstantPoolIndex()){
|
||||||
assert(MR.isConstantPoolIndex());
|
|
||||||
ResultPtr=(void*)getConstantPoolEntryAddress(MR.getConstantPoolIndex());
|
ResultPtr=(void*)getConstantPoolEntryAddress(MR.getConstantPoolIndex());
|
||||||
} else {
|
} else {
|
||||||
assert(MR.isJumpTableIndex());
|
assert(MR.isJumpTableIndex());
|
||||||
ResultPtr=(void*)getJumpTableEntryAddress(MR.getJumpTableIndex());
|
ResultPtr=(void*)getJumpTableEntryAddress(MR.getJumpTableIndex());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MR.setResultPointer(ResultPtr);
|
MR.setResultPointer(ResultPtr);
|
||||||
@ -846,9 +846,6 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve BasicaBlock references.
|
|
||||||
TheJIT->getJITInfo().resolveBBRefs(*this);
|
|
||||||
|
|
||||||
// Invalidate the icache if necessary.
|
// Invalidate the icache if necessary.
|
||||||
synchronizeICache(FnStart, FnEnd-FnStart);
|
synchronizeICache(FnStart, FnEnd-FnStart);
|
||||||
|
|
||||||
|
@ -215,8 +215,9 @@ int AlphaCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
|
|||||||
Reloc, MO.getConstantPoolIndex(),
|
Reloc, MO.getConstantPoolIndex(),
|
||||||
Offset));
|
Offset));
|
||||||
} else if (MO.isMachineBasicBlock()) {
|
} else if (MO.isMachineBasicBlock()) {
|
||||||
TM.getJITInfo()->addBBRef(MO.getMachineBasicBlock(),
|
MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
|
||||||
MCE.getCurrentPCValue());
|
Alpha::reloc_bsr,
|
||||||
|
MO.getMachineBasicBlock()));
|
||||||
}else {
|
}else {
|
||||||
std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
|
std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
|
||||||
abort();
|
abort();
|
||||||
|
@ -304,19 +304,3 @@ void AlphaJITInfo::relocate(void *Function, MachineRelocation *MR,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaJITInfo::resolveBBRefs(MachineCodeEmitter &MCE) {
|
|
||||||
// Resolve all forward branches now...
|
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
|
||||||
unsigned* Location =
|
|
||||||
(unsigned*)MCE.getMachineBasicBlockAddress(BBRefs[i].first);
|
|
||||||
unsigned* Ref = (unsigned*)BBRefs[i].second;
|
|
||||||
intptr_t BranchTargetDisp =
|
|
||||||
(((unsigned char*)Location - (unsigned char*)Ref) >> 2) - 1;
|
|
||||||
DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
|
|
||||||
<< " Disp " << BranchTargetDisp
|
|
||||||
<< " using " << (BranchTargetDisp & ((1 << 22)-1)) << "\n");
|
|
||||||
*Ref |= (BranchTargetDisp & ((1 << 21)-1));
|
|
||||||
}
|
|
||||||
BBRefs.clear();
|
|
||||||
}
|
|
||||||
|
@ -46,8 +46,6 @@ namespace llvm {
|
|||||||
/// code.
|
/// code.
|
||||||
///
|
///
|
||||||
virtual void replaceMachineCodeForFunction(void *Old, void *New);
|
virtual void replaceMachineCodeForFunction(void *Old, void *New);
|
||||||
|
|
||||||
virtual void resolveBBRefs(MachineCodeEmitter &MCE);
|
|
||||||
private:
|
private:
|
||||||
static const unsigned GOToffset = 4096;
|
static const unsigned GOToffset = 4096;
|
||||||
|
|
||||||
|
@ -180,8 +180,16 @@ int PPCCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
|
|||||||
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
||||||
Reloc, MO.getSymbolName(), 0));
|
Reloc, MO.getSymbolName(), 0));
|
||||||
} else if (MO.isMachineBasicBlock()) {
|
} else if (MO.isMachineBasicBlock()) {
|
||||||
unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
|
unsigned Reloc = 0;
|
||||||
TM.getJITInfo()->addBBRef(MO.getMachineBasicBlock(), (intptr_t)CurrPC);
|
unsigned Opcode = MI.getOpcode();
|
||||||
|
if (Opcode == PPC::B || Opcode == PPC::BL || Opcode == PPC::BLA)
|
||||||
|
Reloc = PPC::reloc_pcrel_bx;
|
||||||
|
else
|
||||||
|
// BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
|
||||||
|
Reloc = PPC::reloc_pcrel_bcx;
|
||||||
|
MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
|
||||||
|
Reloc,
|
||||||
|
MO.getMachineBasicBlock()));
|
||||||
} else if (MO.isConstantPoolIndex() || MO.isJumpTableIndex()) {
|
} else if (MO.isConstantPoolIndex() || MO.isJumpTableIndex()) {
|
||||||
if (MO.isConstantPoolIndex())
|
if (MO.isConstantPoolIndex())
|
||||||
rv = MCE.getConstantPoolEntryAddress(MO.getConstantPoolIndex());
|
rv = MCE.getConstantPoolEntryAddress(MO.getConstantPoolIndex());
|
||||||
|
@ -206,6 +206,14 @@ void PPCJITInfo::relocate(void *Function, MachineRelocation *MR,
|
|||||||
"Relocation out of range!");
|
"Relocation out of range!");
|
||||||
*RelocPos |= (ResultPtr & ((1 << 24)-1)) << 2;
|
*RelocPos |= (ResultPtr & ((1 << 24)-1)) << 2;
|
||||||
break;
|
break;
|
||||||
|
case PPC::reloc_pcrel_bcx:
|
||||||
|
// PC-relative relocation for BLT,BLE,BEQ,BGE,BGT,BNE, or other
|
||||||
|
// bcx instructions.
|
||||||
|
ResultPtr = (ResultPtr-(intptr_t)RelocPos) >> 2;
|
||||||
|
assert(ResultPtr >= -(1 << 13) && ResultPtr < (1 << 13) &&
|
||||||
|
"Relocation out of range!");
|
||||||
|
*RelocPos |= (ResultPtr & ((1 << 14)-1)) << 2;
|
||||||
|
break;
|
||||||
case PPC::reloc_absolute_ptr_high: // Pointer relocations.
|
case PPC::reloc_absolute_ptr_high: // Pointer relocations.
|
||||||
case PPC::reloc_absolute_ptr_low:
|
case PPC::reloc_absolute_ptr_low:
|
||||||
case PPC::reloc_absolute_high: // high bits of ref -> low 16 of instr
|
case PPC::reloc_absolute_high: // high bits of ref -> low 16 of instr
|
||||||
@ -245,26 +253,3 @@ void PPCJITInfo::relocate(void *Function, MachineRelocation *MR,
|
|||||||
void PPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
|
void PPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
|
||||||
EmitBranchToAt(Old, New, false);
|
EmitBranchToAt(Old, New, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPCJITInfo::resolveBBRefs(MachineCodeEmitter &MCE) {
|
|
||||||
// Resolve branches to BasicBlocks for the entire function
|
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
|
||||||
intptr_t Location = MCE.getMachineBasicBlockAddress(BBRefs[i].first);
|
|
||||||
unsigned *Ref = (unsigned *)BBRefs[i].second;
|
|
||||||
DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location
|
|
||||||
<< "\n");
|
|
||||||
unsigned Instr = *Ref;
|
|
||||||
intptr_t BranchTargetDisp = (Location - (intptr_t)Ref) >> 2;
|
|
||||||
|
|
||||||
switch (Instr >> 26) {
|
|
||||||
default: assert(0 && "Unknown branch user!");
|
|
||||||
case 18: // This is B or BL
|
|
||||||
*Ref |= (BranchTargetDisp & ((1 << 24)-1)) << 2;
|
|
||||||
break;
|
|
||||||
case 16: // This is BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
|
|
||||||
*Ref |= (BranchTargetDisp & ((1 << 14)-1)) << 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BBRefs.clear();
|
|
||||||
}
|
|
||||||
|
@ -42,8 +42,6 @@ namespace llvm {
|
|||||||
/// code.
|
/// code.
|
||||||
///
|
///
|
||||||
virtual void replaceMachineCodeForFunction(void *Old, void *New);
|
virtual void replaceMachineCodeForFunction(void *Old, void *New);
|
||||||
|
|
||||||
virtual void resolveBBRefs(MachineCodeEmitter &MCE);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ namespace llvm {
|
|||||||
// reloc_pcrel_bx - PC relative relocation, for the b or bl instructions.
|
// reloc_pcrel_bx - PC relative relocation, for the b or bl instructions.
|
||||||
reloc_pcrel_bx,
|
reloc_pcrel_bx,
|
||||||
|
|
||||||
|
// reloc_pcrel_bcx - PC relative relocation, for BLT,BLE,BEQ,BGE,BGT,BNE,
|
||||||
|
// and other bcx instructions.
|
||||||
|
reloc_pcrel_bcx,
|
||||||
|
|
||||||
// reloc_absolute_high - Absolute relocation, for the loadhi instruction
|
// reloc_absolute_high - Absolute relocation, for the loadhi instruction
|
||||||
// (which is really addis). Add the high 16-bits of the specified global
|
// (which is really addis). Add the high 16-bits of the specified global
|
||||||
// address into the low 16-bits of the instruction.
|
// address into the low 16-bits of the instruction.
|
||||||
|
@ -111,7 +111,8 @@ void Emitter::emitPCRelativeValue(unsigned Address) {
|
|||||||
void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
|
void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
|
||||||
// Remember where this reference was and where it is to so we can
|
// Remember where this reference was and where it is to so we can
|
||||||
// deal with it later.
|
// deal with it later.
|
||||||
TM.getJITInfo()->addBBRef(MBB, MCE.getCurrentPCValue());
|
MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
|
||||||
|
X86::reloc_pcrel_word, MBB));
|
||||||
MCE.emitWordLE(0);
|
MCE.emitWordLE(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,13 +203,3 @@ void X86JITInfo::relocate(void *Function, MachineRelocation *MR,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void X86JITInfo::resolveBBRefs(MachineCodeEmitter &MCE) {
|
|
||||||
// Resolve all forward branches now.
|
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
|
||||||
unsigned Location = MCE.getMachineBasicBlockAddress(BBRefs[i].first);
|
|
||||||
intptr_t Ref = BBRefs[i].second;
|
|
||||||
*((unsigned*)Ref) = Location-Ref-4;
|
|
||||||
}
|
|
||||||
BBRefs.clear();
|
|
||||||
}
|
|
||||||
|
@ -51,8 +51,6 @@ namespace llvm {
|
|||||||
/// referenced global symbols.
|
/// referenced global symbols.
|
||||||
virtual void relocate(void *Function, MachineRelocation *MR,
|
virtual void relocate(void *Function, MachineRelocation *MR,
|
||||||
unsigned NumRelocs, unsigned char* GOTBase);
|
unsigned NumRelocs, unsigned char* GOTBase);
|
||||||
|
|
||||||
virtual void resolveBBRefs(MachineCodeEmitter &MCE);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user