/// JumpTableBase - A pointer to the first entry in the jump table.
///
void *JumpTableBase;
-
+
/// Resolver - This contains info about the currently resolved functions.
JITResolver Resolver;
public:
virtual intptr_t getConstantPoolEntryAddress(unsigned Entry) const;
virtual intptr_t getJumpTableEntryAddress(unsigned Entry) const;
-
+
virtual intptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
MBBLocations[MBB->getNumber()] && "MBB not emitted!");
// Store the offset of the basic block for this jump table slot in the
// memory we allocated for the jump table in 'initJumpTableInfo'
intptr_t Base = (intptr_t)SlotPtr;
- for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi)
- *SlotPtr++ = (intptr_t)getMachineBasicBlockAddress(MBBs[mi]) - Base;
+ for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi) {
+ intptr_t MBBAddr = getMachineBasicBlockAddress(MBBs[mi]);
+ *SlotPtr++ = TheJIT->getJITInfo().getPICJumpTableEntry(MBBAddr, Base);
+ }
}
} else {
assert(MJTI->getEntrySize() == sizeof(void*) && "Cross JIT'ing?");
#define DEBUG_TYPE "x86-emitter"
#include "X86InstrInfo.h"
+#include "X86JITInfo.h"
#include "X86Subtarget.h"
#include "X86TargetMachine.h"
#include "X86Relocations.h"
const TargetData *TD;
TargetMachine &TM;
MachineCodeEmitter &MCE;
- intptr_t PICBase;
+ intptr_t PICBaseOffset;
bool Is64BitMode;
bool IsPIC;
public:
static char ID;
explicit Emitter(TargetMachine &tm, MachineCodeEmitter &mce)
: MachineFunctionPass((intptr_t)&ID), II(0), TD(0), TM(tm),
- MCE(mce), PICBase(0), Is64BitMode(false),
+ MCE(mce), PICBaseOffset(0), Is64BitMode(false),
IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
Emitter(TargetMachine &tm, MachineCodeEmitter &mce,
const X86InstrInfo &ii, const TargetData &td, bool is64)
: MachineFunctionPass((intptr_t)&ID), II(&ii), TD(&td), TM(tm),
- MCE(mce), PICBase(0), Is64BitMode(is64),
+ MCE(mce), PICBaseOffset(0), Is64BitMode(is64),
IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
bool runOnMachineFunction(MachineFunction &MF);
bool isLazy /* = false */) {
intptr_t RelocCST = 0;
if (Reloc == X86::reloc_picrel_word)
- RelocCST = PICBase;
+ RelocCST = PICBaseOffset;
else if (Reloc == X86::reloc_pcrel_word)
RelocCST = PCAdj;
MachineRelocation MR = isLazy
/// be emitted to the current location in the function, and allow it to be PC
/// relative.
void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc) {
- intptr_t RelocCST = (Reloc == X86::reloc_picrel_word) ? PICBase : 0;
+ intptr_t RelocCST = (Reloc == X86::reloc_picrel_word) ? PICBaseOffset : 0;
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
Reloc, ES, RelocCST));
if (Reloc == X86::reloc_absolute_dword)
intptr_t PCAdj /* = 0 */) {
intptr_t RelocCST = 0;
if (Reloc == X86::reloc_picrel_word)
- RelocCST = PICBase;
+ RelocCST = PICBaseOffset;
else if (Reloc == X86::reloc_pcrel_word)
RelocCST = PCAdj;
MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
intptr_t PCAdj /* = 0 */) {
intptr_t RelocCST = 0;
if (Reloc == X86::reloc_picrel_word)
- RelocCST = PICBase;
+ RelocCST = PICBaseOffset;
else if (Reloc == X86::reloc_pcrel_word)
RelocCST = PCAdj;
MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
case X86::FP_REG_KILL:
break;
#endif
- case X86::MOVPC32r:
+ case X86::MOVPC32r: {
// This emits the "call" portion of this pseudo instruction.
MCE.emitByte(BaseOpcode);
emitConstant(0, sizeOfImm(Desc));
- PICBase = MCE.getCurrentPCOffset();
+ // Remember PIC base.
+ PICBaseOffset = MCE.getCurrentPCOffset();
+ X86JITInfo *JTI = dynamic_cast<X86JITInfo*>(TM.getJITInfo());
+ JTI->setPICBase(MCE.getCurrentPCValue());
break;
}
+ }
CurOp = NumOps;
break;
class X86JITInfo : public TargetJITInfo {
X86TargetMachine &TM;
+ intptr_t PICBase;
public:
X86JITInfo(X86TargetMachine &tm) : TM(tm) {useGOT = 0;}
/// address.
virtual void *emitFunctionStub(void *Fn, MachineCodeEmitter &MCE);
+ /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
+ /// specific basic block.
+ virtual intptr_t getPICJumpTableEntry(intptr_t BB, intptr_t JTBase);
+
/// getLazyResolverFunction - Expose the lazy resolver to the JIT.
virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
/// referenced global symbols.
virtual void relocate(void *Function, MachineRelocation *MR,
unsigned NumRelocs, unsigned char* GOTBase);
+
+ /// setPICBase / getPICBase - Getter / setter of PICBase, used to compute
+ /// PIC jumptable entry.
+ void setPICBase(intptr_t Base) { PICBase = Base; }
+ intptr_t getPICBase() const { return PICBase; }
};
}