isPICStyleRIPRel() and friends are never true in -static mode.
authorChris Lattner <sabre@nondot.org>
Thu, 9 Jul 2009 04:24:46 +0000 (04:24 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 9 Jul 2009 04:24:46 +0000 (04:24 +0000)
Simplify code based on this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75099 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86TargetMachine.cpp

index 7c1ab401aa7c9fc27954294712bfb529e47f843d..fc77806f56e151bc2fa5d523fff186a1f1a16f59 100644 (file)
@@ -1319,14 +1319,6 @@ X86TargetLowering::NameDecorationForFORMAL_ARGUMENTS(SDValue Op) {
 }
 
 
-/// isUsingGOT - Return true if the target uses a GOT for PIC, and if we're in
-/// PIC mode.
-static bool isUsingGOT(const TargetMachine &TM) {
-  const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
-  return TM.getRelocationModel() == Reloc::PIC_ &&
-         Subtarget.isPICStyleGOT();
-}
-
 /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified
 /// by "Src" to address "Dst" with size and alignment information specified by
 /// the specific parameter attribute. The copy will be passed as a byval
@@ -1794,7 +1786,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
     }
 
   
-  if (isUsingGOT(getTargetMachine())) {
+  if (Subtarget->isPICStyleGOT()) {
     // ELF / PIC requires GOT in the EBX register before function calls via PLT
     // GOT pointer.
     if (!IsTailCall) {
@@ -1952,7 +1944,7 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) {
                                   RegsToPass[i].second.getValueType()));
 
   // Add an implicit use GOT pointer in EBX.
-  if (!IsTailCall && isUsingGOT(getTargetMachine()))
+  if (!IsTailCall && Subtarget->isPICStyleGOT())
     Ops.push_back(DAG.getRegister(X86::EBX, getPointerTy()));
 
   // Add an implicit use of AL for x86 vararg functions.
@@ -2069,12 +2061,12 @@ bool X86TargetLowering::IsEligibleForTailCallOptimization(CallSDNode *TheCall,
     unsigned CallerCC = MF.getFunction()->getCallingConv();
     unsigned CalleeCC= TheCall->getCallingConv();
     if (CalleeCC == CallingConv::Fast && CallerCC == CalleeCC) {
-      SDValue Callee = TheCall->getCallee();
       // On x86/32Bit PIC/GOT tail calls are supported.
       if (getTargetMachine().getRelocationModel() != Reloc::PIC_ ||
           !Subtarget->isPICStyleGOT() || !Subtarget->is64Bit())
         return true;
-
+      
+      SDValue Callee = TheCall->getCallee();
       // Can only do local tail calls (in same module, hidden or protected) on
       // x86_64 PIC/GOT at the moment.
       if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
@@ -4438,11 +4430,11 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
   if (Subtarget->is64Bit() &&
       getTargetMachine().getCodeModel() == CodeModel::Small) {
     WrapperKind = X86ISD::WrapperRIP;
-  } else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
-    if (Subtarget->isPICStyleStub())
-      OpFlag = X86II::MO_PIC_BASE_OFFSET;
-    else if (Subtarget->isPICStyleGOT())
-      OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleGOT()) {
+    OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleStub() &&
+             getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    OpFlag = X86II::MO_PIC_BASE_OFFSET;
   }
   
   SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(),
@@ -4471,11 +4463,11 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
   
   if (Subtarget->is64Bit()) {
     WrapperKind = X86ISD::WrapperRIP;
-  } else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
-    if (Subtarget->isPICStyleStub())
-      OpFlag = X86II::MO_PIC_BASE_OFFSET;
-    else if (Subtarget->isPICStyleGOT())
-      OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleGOT()) {
+    OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleStub() &&
+             getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    OpFlag = X86II::MO_PIC_BASE_OFFSET;
   }
   
   SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy(),
@@ -4504,11 +4496,11 @@ X86TargetLowering::LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) {
   unsigned WrapperKind = X86ISD::Wrapper;
   if (Subtarget->is64Bit()) {
     WrapperKind = X86ISD::WrapperRIP;
-  } else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
-    if (Subtarget->isPICStyleStub())
-      OpFlag = X86II::MO_PIC_BASE_OFFSET;
-    else if (Subtarget->isPICStyleGOT())
-      OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleGOT()) {
+    OpFlag = X86II::MO_GOTOFF;
+  } else if (Subtarget->isPICStyleStub() &&
+             getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    OpFlag = X86II::MO_PIC_BASE_OFFSET;
   }
   
   SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlag);
@@ -4550,12 +4542,10 @@ X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
     
     if (GV->hasDLLImportLinkage())
       OpFlags = X86II::MO_DLLIMPORT;
-    else if (Subtarget->isPICStyleRIPRel() &&
-             getTargetMachine().getRelocationModel() != Reloc::Static) {
+    else if (Subtarget->isPICStyleRIPRel()) {
       if (ExtraLoadRequired)
         OpFlags = X86II::MO_GOTPCREL;
-    } else if (Subtarget->isPICStyleGOT() &&
-               getTargetMachine().getRelocationModel() == Reloc::PIC_) {
+    } else if (Subtarget->isPICStyleGOT()) {
       if (ExtraLoadRequired)
         OpFlags = X86II::MO_GOT;
       else
index 9448f30878e2e6719d7ef13f2fecd4f39c2f262c..eb0cf93562e094e81ebb9c8ffbc426f856f953a9 100644 (file)
@@ -158,11 +158,14 @@ X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS,
       
   // ELF and X86-64 don't have a distinct DynamicNoPIC model.  DynamicNoPIC
   // is defined as a model for code which may be used in static or dynamic
-  // executables but not necessarily a shared library. On these systems we just
-  // compile in -static mode.
-  if (getRelocationModel() == Reloc::DynamicNoPIC &&
-      !Subtarget.isTargetDarwin())
-    setRelocationModel(Reloc::Static);
+  // executables but not necessarily a shared library. On X86-32 we just
+  // compile in -static mode, in x86-64 we use PIC.
+  if (getRelocationModel() == Reloc::DynamicNoPIC) {
+    if (is64Bit)
+      setRelocationModel(Reloc::PIC_);
+    else if (!Subtarget.isTargetDarwin())
+      setRelocationModel(Reloc::Static);
+  }
 
   // If we are on Darwin, disallow static relocation model in X86-64 mode, since
   // the Mach-O file format doesn't support it.