mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
merge two identical functions and simplify things that are GOT specific
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75091 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e3ee6f1e1f
commit
b133a0aff7
@ -1319,18 +1319,9 @@ X86TargetLowering::NameDecorationForFORMAL_ARGUMENTS(SDValue Op) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// CallRequiresGOTInRegister - Check whether the call requires the GOT pointer
|
/// isUsingGOT - Return true if the target uses a GOT for PIC, and if we're in
|
||||||
/// in a register before calling.
|
/// PIC mode.
|
||||||
static bool CallRequiresGOTPtrInReg(const TargetMachine &TM) {
|
static bool isUsingGOT(const TargetMachine &TM) {
|
||||||
const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
|
|
||||||
|
|
||||||
return TM.getRelocationModel() == Reloc::PIC_ &&
|
|
||||||
Subtarget.isPICStyleGOT();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// CallRequiresFnAddressInReg - Check whether the call requires the function
|
|
||||||
/// address to be loaded in a register.
|
|
||||||
static bool CallRequiresFnAddressInReg(const TargetMachine &TM) {
|
|
||||||
const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
|
const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
|
||||||
return TM.getRelocationModel() == Reloc::PIC_ &&
|
return TM.getRelocationModel() == Reloc::PIC_ &&
|
||||||
Subtarget.isPICStyleGOT();
|
Subtarget.isPICStyleGOT();
|
||||||
@ -1802,25 +1793,27 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
|
|||||||
InFlag = Chain.getValue(1);
|
InFlag = Chain.getValue(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isUsingGOT(getTargetMachine())) {
|
||||||
// ELF / PIC requires GOT in the EBX register before function calls via PLT
|
// ELF / PIC requires GOT in the EBX register before function calls via PLT
|
||||||
// GOT pointer.
|
// GOT pointer.
|
||||||
if (!IsTailCall && CallRequiresGOTPtrInReg(getTargetMachine())) {
|
if (!IsTailCall) {
|
||||||
Chain = DAG.getCopyToReg(Chain, dl, X86::EBX,
|
Chain = DAG.getCopyToReg(Chain, dl, X86::EBX,
|
||||||
DAG.getNode(X86ISD::GlobalBaseReg,
|
DAG.getNode(X86ISD::GlobalBaseReg,
|
||||||
DebugLoc::getUnknownLoc(),
|
DebugLoc::getUnknownLoc(),
|
||||||
getPointerTy()),
|
getPointerTy()),
|
||||||
InFlag);
|
InFlag);
|
||||||
InFlag = Chain.getValue(1);
|
InFlag = Chain.getValue(1);
|
||||||
}
|
} else {
|
||||||
|
// If we are tail calling and generating PIC/GOT style code load the
|
||||||
|
// address of the callee into ECX. The value in ecx is used as target of
|
||||||
|
// the tail jump. This is done to circumvent the ebx/callee-saved problem
|
||||||
|
// for tail calls on PIC/GOT architectures. Normally we would just put the
|
||||||
|
// address of GOT into ebx and then call target@PLT. But for tail calls
|
||||||
|
// ebx would be restored (since ebx is callee saved) before jumping to the
|
||||||
|
// target@PLT.
|
||||||
|
|
||||||
// If we are tail calling and generating PIC/GOT style code load the address
|
// Note: The actual moving to ECX is done further down.
|
||||||
// of the callee into ecx. The value in ecx is used as target of the tail
|
|
||||||
// jump. This is done to circumvent the ebx/callee-saved problem for tail
|
|
||||||
// calls on PIC/GOT architectures. Normally we would just put the address of
|
|
||||||
// GOT into ebx and then call target@PLT. But for tail calls ebx would be
|
|
||||||
// restored (since ebx is callee saved) before jumping to the target@PLT.
|
|
||||||
if (IsTailCall && CallRequiresFnAddressInReg(getTargetMachine())) {
|
|
||||||
// Note: The actual moving to ecx is done further down.
|
|
||||||
GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
|
GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
|
||||||
if (G && !G->getGlobal()->hasHiddenVisibility() &&
|
if (G && !G->getGlobal()->hasHiddenVisibility() &&
|
||||||
!G->getGlobal()->hasProtectedVisibility())
|
!G->getGlobal()->hasProtectedVisibility())
|
||||||
@ -1828,6 +1821,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
|
|||||||
else if (isa<ExternalSymbolSDNode>(Callee))
|
else if (isa<ExternalSymbolSDNode>(Callee))
|
||||||
Callee = LowerExternalSymbol(Callee,DAG);
|
Callee = LowerExternalSymbol(Callee,DAG);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Is64Bit && isVarArg) {
|
if (Is64Bit && isVarArg) {
|
||||||
// From AMD64 ABI document:
|
// From AMD64 ABI document:
|
||||||
@ -1958,9 +1952,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
|
|||||||
RegsToPass[i].second.getValueType()));
|
RegsToPass[i].second.getValueType()));
|
||||||
|
|
||||||
// Add an implicit use GOT pointer in EBX.
|
// Add an implicit use GOT pointer in EBX.
|
||||||
if (!IsTailCall && !Is64Bit &&
|
if (!IsTailCall && isUsingGOT(getTargetMachine()))
|
||||||
getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
|
|
||||||
Subtarget->isPICStyleGOT())
|
|
||||||
Ops.push_back(DAG.getRegister(X86::EBX, getPointerTy()));
|
Ops.push_back(DAG.getRegister(X86::EBX, getPointerTy()));
|
||||||
|
|
||||||
// Add an implicit use of AL for x86 vararg functions.
|
// Add an implicit use of AL for x86 vararg functions.
|
||||||
@ -2080,7 +2072,7 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(CallSDNode *TheCall,
|
|||||||
SDValue Callee = TheCall->getCallee();
|
SDValue Callee = TheCall->getCallee();
|
||||||
// On x86/32Bit PIC/GOT tail calls are supported.
|
// On x86/32Bit PIC/GOT tail calls are supported.
|
||||||
if (getTargetMachine().getRelocationModel() != Reloc::PIC_ ||
|
if (getTargetMachine().getRelocationModel() != Reloc::PIC_ ||
|
||||||
!Subtarget->isPICStyleGOT()|| !Subtarget->is64Bit())
|
!Subtarget->isPICStyleGOT() || !Subtarget->is64Bit())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Can only do local tail calls (in same module, hidden or protected) on
|
// Can only do local tail calls (in same module, hidden or protected) on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user