@@ -1083,6 +1083,24 @@ static bool IsPossiblyOverwrittenArgumentOfTailCall(SDOperand Op,
1083
1083
return false ;
1084
1084
}
1085
1085
1086
+ // / CallRequiresGOTInRegister - Check whether the call requires the GOT pointer
1087
+ // / in a register before calling.
1088
+ bool X86TargetLowering::CallRequiresGOTPtrInReg (bool Is64Bit, bool IsTailCall) {
1089
+ return !IsTailCall && !Is64Bit &&
1090
+ getTargetMachine ().getRelocationModel () == Reloc::PIC_ &&
1091
+ Subtarget->isPICStyleGOT ();
1092
+ }
1093
+
1094
+
1095
+ // / CallRequiresFnAddressInReg - Check whether the call requires the function
1096
+ // / address to be loaded in a register.
1097
+ bool
1098
+ X86TargetLowering::CallRequiresFnAddressInReg (bool Is64Bit, bool IsTailCall) {
1099
+ return !Is64Bit && IsTailCall &&
1100
+ getTargetMachine ().getRelocationModel () == Reloc::PIC_ &&
1101
+ Subtarget->isPICStyleGOT ();
1102
+ }
1103
+
1086
1104
// / CopyTailCallClobberedArgumentsToVRegs - Create virtual registers for all
1087
1105
// / arguments to force loading and guarantee that arguments sourcing from
1088
1106
// / incomming parameters are not overwriting each other.
@@ -1552,22 +1570,19 @@ SDOperand X86TargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) {
1552
1570
1553
1571
// ELF / PIC requires GOT in the EBX register before function calls via PLT
1554
1572
// GOT pointer.
1573
+ if (CallRequiresGOTPtrInReg (Is64Bit, IsTailCall)) {
1574
+ Chain = DAG.getCopyToReg (Chain, X86::EBX,
1575
+ DAG.getNode (X86ISD::GlobalBaseReg, getPointerTy ()),
1576
+ InFlag);
1577
+ InFlag = Chain.getValue (1 );
1578
+ }
1555
1579
// If we are tail calling and generating PIC/GOT style code load the address
1556
1580
// of the callee into ecx. The value in ecx is used as target of the tail
1557
1581
// jump. This is done to circumvent the ebx/callee-saved problem for tail
1558
1582
// calls on PIC/GOT architectures. Normally we would just put the address of
1559
1583
// GOT into ebx and then call target@PLT. But for tail callss ebx would be
1560
1584
// restored (since ebx is callee saved) before jumping to the target@PLT.
1561
- if (!IsTailCall && !Is64Bit &&
1562
- getTargetMachine ().getRelocationModel () == Reloc::PIC_ &&
1563
- Subtarget->isPICStyleGOT ()) {
1564
- Chain = DAG.getCopyToReg (Chain, X86::EBX,
1565
- DAG.getNode (X86ISD::GlobalBaseReg, getPointerTy ()),
1566
- InFlag);
1567
- InFlag = Chain.getValue (1 );
1568
- } else if (!Is64Bit && IsTailCall &&
1569
- getTargetMachine ().getRelocationModel () == Reloc::PIC_ &&
1570
- Subtarget->isPICStyleGOT () ) {
1585
+ if (CallRequiresFnAddressInReg (Is64Bit, IsTailCall)) {
1571
1586
// Note: The actual moving to ecx is done further down.
1572
1587
GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
1573
1588
if (G && !G->getGlobal ()->hasHiddenVisibility () &&
0 commit comments