mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Change MachineRelocation::DoesntNeedFnStub to NeedStub. This fields will be used
for non-function GV relocations that require function address stubs (e.g. Mac OS X in non-static mode). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45527 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9848ced5d0
commit
02aabbf96b
@ -64,7 +64,7 @@ class MachineRelocation {
|
||||
|
||||
unsigned TargetReloType : 6; // The target relocation ID.
|
||||
AddressType AddrType : 4; // The field of Target to use.
|
||||
bool DoesntNeedFnStub : 1; // True if we don't need a fn stub.
|
||||
bool NeedStub : 1; // True if this relocation requires a stub.
|
||||
bool GOTRelative : 1; // Should this relocation be relative to the GOT?
|
||||
|
||||
public:
|
||||
@ -79,7 +79,7 @@ public:
|
||||
///
|
||||
static MachineRelocation getGV(intptr_t offset, unsigned RelocationType,
|
||||
GlobalValue *GV, intptr_t cst = 0,
|
||||
bool DoesntNeedFunctionStub = 0,
|
||||
bool NeedStub = 0,
|
||||
bool GOTrelative = 0) {
|
||||
assert((RelocationType & ~63) == 0 && "Relocation type too large!");
|
||||
MachineRelocation Result;
|
||||
@ -87,7 +87,7 @@ public:
|
||||
Result.ConstantVal = cst;
|
||||
Result.TargetReloType = RelocationType;
|
||||
Result.AddrType = isGV;
|
||||
Result.DoesntNeedFnStub = DoesntNeedFunctionStub;
|
||||
Result.NeedStub = NeedStub;
|
||||
Result.GOTRelative = GOTrelative;
|
||||
Result.Target.GV = GV;
|
||||
return Result;
|
||||
@ -103,7 +103,7 @@ public:
|
||||
Result.ConstantVal = cst;
|
||||
Result.TargetReloType = RelocationType;
|
||||
Result.AddrType = isBB;
|
||||
Result.DoesntNeedFnStub = false;
|
||||
Result.NeedStub = false;
|
||||
Result.GOTRelative = false;
|
||||
Result.Target.MBB = MBB;
|
||||
return Result;
|
||||
@ -121,7 +121,7 @@ public:
|
||||
Result.ConstantVal = cst;
|
||||
Result.TargetReloType = RelocationType;
|
||||
Result.AddrType = isExtSym;
|
||||
Result.DoesntNeedFnStub = false;
|
||||
Result.NeedStub = false;
|
||||
Result.GOTRelative = GOTrelative;
|
||||
Result.Target.ExtSym = ES;
|
||||
return Result;
|
||||
@ -138,7 +138,7 @@ public:
|
||||
Result.ConstantVal = cst;
|
||||
Result.TargetReloType = RelocationType;
|
||||
Result.AddrType = isConstPool;
|
||||
Result.DoesntNeedFnStub = false;
|
||||
Result.NeedStub = false;
|
||||
Result.GOTRelative = false;
|
||||
Result.Target.Index = CPI;
|
||||
return Result;
|
||||
@ -155,7 +155,7 @@ public:
|
||||
Result.ConstantVal = cst;
|
||||
Result.TargetReloType = RelocationType;
|
||||
Result.AddrType = isJumpTable;
|
||||
Result.DoesntNeedFnStub = false;
|
||||
Result.NeedStub = false;
|
||||
Result.GOTRelative = false;
|
||||
Result.Target.Index = JTI;
|
||||
return Result;
|
||||
@ -223,13 +223,12 @@ public:
|
||||
return GOTRelative;
|
||||
}
|
||||
|
||||
/// doesntNeedFunctionStub - This function returns true if the JIT for this
|
||||
/// target is capable of directly handling the relocated instruction without
|
||||
/// using a stub function. It is always conservatively correct for this flag
|
||||
/// to be false, but targets can improve their compilation callback functions
|
||||
/// to handle more general cases if they want improved performance.
|
||||
bool doesntNeedFunctionStub() const {
|
||||
return DoesntNeedFnStub;
|
||||
/// doesntNeedStub - This function returns true if the JIT for this target
|
||||
/// target is capable of directly handling the relocated GlobalValue reference
|
||||
/// without using either a stub function or issuing an extra load to get the
|
||||
/// GV address.
|
||||
bool doesntNeedStub() const {
|
||||
return !NeedStub;
|
||||
}
|
||||
|
||||
/// getGlobalValue - If this is a global value reference, return the
|
||||
|
@ -444,12 +444,12 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
|
||||
ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
|
||||
|
||||
// If the target REALLY wants a stub for this function, emit it now.
|
||||
if (!MR.doesntNeedFunctionStub())
|
||||
if (!MR.doesntNeedStub())
|
||||
ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
|
||||
} else if (MR.isGlobalValue()) {
|
||||
ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
|
||||
BufferBegin+MR.getMachineCodeOffset(),
|
||||
MR.doesntNeedFunctionStub());
|
||||
MR.doesntNeedStub());
|
||||
} else if (MR.isBasicBlock()) {
|
||||
ResultPtr = (void*)getMachineBasicBlockAddress(MR.getBasicBlock());
|
||||
} else if (MR.isConstantPoolIndex()) {
|
||||
|
@ -196,7 +196,8 @@ int AlphaCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
|
||||
if (MO.isGlobalAddress())
|
||||
MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
|
||||
Reloc, MO.getGlobal(), Offset,
|
||||
false, useGOT));
|
||||
isa<Function>(MO.getGlobal()),
|
||||
useGOT));
|
||||
else if (MO.isExternalSymbol())
|
||||
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
||||
Reloc, MO.getSymbolName(),
|
||||
|
@ -189,7 +189,8 @@ int PPCCodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
|
||||
MachineRelocation R;
|
||||
if (MO.isGlobalAddress()) {
|
||||
R = MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
|
||||
MO.getGlobal(), 0);
|
||||
MO.getGlobal(),
|
||||
isa<Function>(MO.getGlobal()), 0);
|
||||
} else if (MO.isExternalSymbol()) {
|
||||
R = MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
||||
Reloc, MO.getSymbolName(), 0);
|
||||
|
@ -40,17 +40,20 @@ namespace {
|
||||
intptr_t PICBase;
|
||||
bool Is64BitMode;
|
||||
bool IsPIC;
|
||||
bool IsStatic;
|
||||
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),
|
||||
IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
|
||||
IsPIC(TM.getRelocationModel() == Reloc::PIC_),
|
||||
IsStatic(TM.getRelocationModel() == Reloc::Static) {}
|
||||
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),
|
||||
IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
|
||||
IsPIC(TM.getRelocationModel() == Reloc::PIC_),
|
||||
IsStatic(TM.getRelocationModel() == Reloc::Static) {}
|
||||
|
||||
bool runOnMachineFunction(MachineFunction &MF);
|
||||
|
||||
@ -64,13 +67,12 @@ namespace {
|
||||
void emitPCRelativeBlockAddress(MachineBasicBlock *MBB);
|
||||
void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
|
||||
int Disp = 0, intptr_t PCAdj = 0,
|
||||
bool DoesntNeedStub = false, bool isPIC = false);
|
||||
void emitExternalSymbolAddress(const char *ES, unsigned Reloc,
|
||||
bool isPIC = false);
|
||||
bool NeedStub = false);
|
||||
void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
|
||||
void emitConstPoolAddress(unsigned CPI, unsigned Reloc, int Disp = 0,
|
||||
intptr_t PCAdj = 0, bool isPIC = false);
|
||||
intptr_t PCAdj = 0);
|
||||
void emitJumpTableAddress(unsigned JTI, unsigned Reloc,
|
||||
intptr_t PCAdj = 0, bool isPIC = false);
|
||||
intptr_t PCAdj = 0);
|
||||
|
||||
void emitDisplacementField(const MachineOperand *RelocOp, int DispVal,
|
||||
intptr_t PCAdj = 0);
|
||||
@ -137,12 +139,11 @@ void Emitter::emitPCRelativeBlockAddress(MachineBasicBlock *MBB) {
|
||||
///
|
||||
void Emitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
|
||||
int Disp /* = 0 */, intptr_t PCAdj /* = 0 */,
|
||||
bool DoesntNeedStub /* = false */,
|
||||
bool isPIC /* = false */) {
|
||||
if (isPIC)
|
||||
bool NeedStub /* = false */) {
|
||||
if (Reloc == X86::reloc_picrel_word)
|
||||
PCAdj += PICBase;
|
||||
MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
|
||||
GV, PCAdj, DoesntNeedStub));
|
||||
GV, PCAdj, NeedStub));
|
||||
if (Reloc == X86::reloc_absolute_dword)
|
||||
MCE.emitWordLE(0);
|
||||
MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
|
||||
@ -151,9 +152,8 @@ void Emitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
|
||||
/// emitExternalSymbolAddress - Arrange for the address of an external symbol to
|
||||
/// be emitted to the current location in the function, and allow it to be PC
|
||||
/// relative.
|
||||
void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc,
|
||||
bool isPIC /* = false */) {
|
||||
intptr_t PCAdj = isPIC ? PICBase : 0;
|
||||
void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc) {
|
||||
intptr_t PCAdj = (Reloc == X86::reloc_picrel_word) ? PICBase : 0;
|
||||
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
||||
Reloc, ES, PCAdj));
|
||||
if (Reloc == X86::reloc_absolute_dword)
|
||||
@ -166,9 +166,8 @@ void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc,
|
||||
/// relative.
|
||||
void Emitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc,
|
||||
int Disp /* = 0 */,
|
||||
intptr_t PCAdj /* = 0 */,
|
||||
bool isPIC /* = false */) {
|
||||
if (isPIC)
|
||||
intptr_t PCAdj /* = 0 */) {
|
||||
if (Reloc == X86::reloc_picrel_word)
|
||||
PCAdj += PICBase;
|
||||
MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
|
||||
Reloc, CPI, PCAdj));
|
||||
@ -181,9 +180,8 @@ void Emitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc,
|
||||
/// be emitted to the current location in the function, and allow it to be PC
|
||||
/// relative.
|
||||
void Emitter::emitJumpTableAddress(unsigned JTI, unsigned Reloc,
|
||||
intptr_t PCAdj /* = 0 */,
|
||||
bool isPIC /* = false */) {
|
||||
if (isPIC)
|
||||
intptr_t PCAdj /* = 0 */) {
|
||||
if (Reloc == X86::reloc_picrel_word)
|
||||
PCAdj += PICBase;
|
||||
MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
|
||||
Reloc, JTI, PCAdj));
|
||||
@ -241,17 +239,18 @@ void Emitter::emitDisplacementField(const MachineOperand *RelocOp,
|
||||
// But it's probably not beneficial.
|
||||
// 89 05 00 00 00 00 mov %eax,0(%rip) # PC-relative
|
||||
// 89 04 25 00 00 00 00 mov %eax,0x0 # Absolute
|
||||
unsigned rt= Is64BitMode ? X86::reloc_pcrel_word
|
||||
unsigned rt = Is64BitMode ? X86::reloc_pcrel_word
|
||||
: (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
|
||||
bool NeedStub = !IsStatic || isa<Function>(RelocOp->getGlobal());
|
||||
emitGlobalAddress(RelocOp->getGlobal(), rt, RelocOp->getOffset(),
|
||||
PCAdj, false, IsPIC);
|
||||
PCAdj, NeedStub);
|
||||
} else if (RelocOp->isConstantPoolIndex()) {
|
||||
unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
|
||||
emitConstPoolAddress(RelocOp->getIndex(), rt,
|
||||
RelocOp->getOffset(), PCAdj, IsPIC);
|
||||
RelocOp->getOffset(), PCAdj);
|
||||
} else if (RelocOp->isJumpTableIndex()) {
|
||||
unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
|
||||
emitJumpTableAddress(RelocOp->getIndex(), rt, PCAdj, IsPIC);
|
||||
emitJumpTableAddress(RelocOp->getIndex(), rt, PCAdj);
|
||||
} else {
|
||||
assert(0 && "Unknown value to relocate!");
|
||||
}
|
||||
@ -602,14 +601,12 @@ void Emitter::emitInstruction(const MachineInstr &MI) {
|
||||
if (MO.isMachineBasicBlock()) {
|
||||
emitPCRelativeBlockAddress(MO.getMBB());
|
||||
} else if (MO.isGlobalAddress()) {
|
||||
bool NeedStub = Is64BitMode ||
|
||||
Opcode == X86::TAILJMPd ||
|
||||
Opcode == X86::TAILJMPr || Opcode == X86::TAILJMPm;
|
||||
bool NeedStub = !IsStatic ||
|
||||
(Is64BitMode && TM.getCodeModel() == CodeModel::Large);
|
||||
emitGlobalAddress(MO.getGlobal(), X86::reloc_pcrel_word,
|
||||
0, 0, !NeedStub, false);
|
||||
0, 0, NeedStub);
|
||||
} else if (MO.isExternalSymbol()) {
|
||||
emitExternalSymbolAddress(MO.getSymbolName(),
|
||||
X86::reloc_pcrel_word, false);
|
||||
emitExternalSymbolAddress(MO.getSymbolName(), X86::reloc_pcrel_word);
|
||||
} else if (MO.isImmediate()) {
|
||||
emitConstant(MO.getImm(), sizeOfImm(Desc));
|
||||
} else {
|
||||
@ -636,14 +633,15 @@ void Emitter::emitInstruction(const MachineInstr &MI) {
|
||||
: (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
|
||||
if (Opcode == X86::MOV64ri)
|
||||
rt = X86::reloc_absolute_dword; // FIXME: add X86II flag?
|
||||
if (MO1.isGlobalAddress())
|
||||
emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), false, IsPIC);
|
||||
else if (MO1.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO1.getSymbolName(), rt, IsPIC);
|
||||
if (MO1.isGlobalAddress()) {
|
||||
bool NeedStub = !IsStatic || isa<Function>(MO1.getGlobal());
|
||||
emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), 0, NeedStub);
|
||||
} else if (MO1.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO1.getSymbolName(), rt);
|
||||
else if (MO1.isConstantPoolIndex())
|
||||
emitConstPoolAddress(MO1.getIndex(), rt, IsPIC);
|
||||
emitConstPoolAddress(MO1.getIndex(), rt);
|
||||
else if (MO1.isJumpTableIndex())
|
||||
emitJumpTableAddress(MO1.getIndex(), rt, IsPIC);
|
||||
emitJumpTableAddress(MO1.getIndex(), rt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -705,14 +703,15 @@ void Emitter::emitInstruction(const MachineInstr &MI) {
|
||||
: (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
|
||||
if (Opcode == X86::MOV64ri32)
|
||||
rt = X86::reloc_absolute_word; // FIXME: add X86II flag?
|
||||
if (MO1.isGlobalAddress())
|
||||
emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), false, IsPIC);
|
||||
else if (MO1.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO1.getSymbolName(), rt, IsPIC);
|
||||
if (MO1.isGlobalAddress()) {
|
||||
bool NeedStub = !IsStatic || isa<Function>(MO1.getGlobal());
|
||||
emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), 0, NeedStub);
|
||||
} else if (MO1.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO1.getSymbolName(), rt);
|
||||
else if (MO1.isConstantPoolIndex())
|
||||
emitConstPoolAddress(MO1.getIndex(), rt, IsPIC);
|
||||
emitConstPoolAddress(MO1.getIndex(), rt);
|
||||
else if (MO1.isJumpTableIndex())
|
||||
emitJumpTableAddress(MO1.getIndex(), rt, IsPIC);
|
||||
emitJumpTableAddress(MO1.getIndex(), rt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -739,14 +738,15 @@ void Emitter::emitInstruction(const MachineInstr &MI) {
|
||||
: (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
|
||||
if (Opcode == X86::MOV64mi32)
|
||||
rt = X86::reloc_absolute_word; // FIXME: add X86II flag?
|
||||
if (MO.isGlobalAddress())
|
||||
emitGlobalAddress(MO.getGlobal(), rt, MO.getOffset(), false, IsPIC);
|
||||
else if (MO.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO.getSymbolName(), rt, IsPIC);
|
||||
if (MO.isGlobalAddress()) {
|
||||
bool NeedStub = !IsStatic || isa<Function>(MO.getGlobal());
|
||||
emitGlobalAddress(MO.getGlobal(), rt, MO.getOffset(), 0, NeedStub);
|
||||
} else if (MO.isExternalSymbol())
|
||||
emitExternalSymbolAddress(MO.getSymbolName(), rt);
|
||||
else if (MO.isConstantPoolIndex())
|
||||
emitConstPoolAddress(MO.getIndex(), rt, IsPIC);
|
||||
emitConstPoolAddress(MO.getIndex(), rt);
|
||||
else if (MO.isJumpTableIndex())
|
||||
emitJumpTableAddress(MO.getIndex(), rt, IsPIC);
|
||||
emitJumpTableAddress(MO.getIndex(), rt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user