[llvm] r273595 - Refactor duplicated code. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 23 11:43:10 PDT 2016


Author: rafael
Date: Thu Jun 23 13:43:06 2016
New Revision: 273595

URL: http://llvm.org/viewvc/llvm-project?rev=273595&view=rev
Log:
Refactor duplicated code. NFC.

Modified:
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=273595&r1=273594&r2=273595&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Thu Jun 23 13:43:06 2016
@@ -4280,23 +4280,28 @@ PrepareCall(SelectionDAG &DAG, SDValue &
       needIndirectCall = false;
     }
 
+  // PC-relative references to external symbols should go through $stub, unless
+  // we're building with the leopard linker or later, which automatically
+  // synthesizes these stubs.
+  Reloc::Model RM = DAG.getTarget().getRelocationModel();
+  const Triple &TargetTriple = Subtarget.getTargetTriple();
+  bool OldMachOLinker =
+      TargetTriple.isMacOSX() && TargetTriple.isMacOSXVersionLT(10, 5);
+  const Module *Mod = DAG.getMachineFunction().getFunction()->getParent();
+  const GlobalValue *GV = nullptr;
+  if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
+    GV = G->getGlobal();
+  bool Local = shouldAssumeDSOLocal(RM, TargetTriple, *Mod, GV);
+  bool UsePlt =
+      !Local && (OldMachOLinker || (Subtarget.isTargetELF() && !isPPC64));
+
   if (isFunctionGlobalAddress(Callee)) {
     GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee);
     // A call to a TLS address is actually an indirect call to a
     // thread-specific pointer.
     unsigned OpFlags = 0;
-    Reloc::Model RM = DAG.getTarget().getRelocationModel();
-    const Triple &TargetTriple = Subtarget.getTargetTriple();
-    const GlobalValue *GV = G->getGlobal();
-    bool OldMachOLinker =
-        TargetTriple.isMacOSX() && TargetTriple.isMacOSXVersionLT(10, 5);
-    if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV) &&
-        (OldMachOLinker || (Subtarget.isTargetELF() && !isPPC64))) {
-      // PC-relative references to external symbols should go through $stub,
-      // unless we're building with the leopard linker or later, which
-      // automatically synthesizes these stubs.
+    if (UsePlt)
       OpFlags = PPCII::MO_PLT_OR_STUB;
-    }
 
     // If the callee is a GlobalAddress/ExternalSymbol node (quite common,
     // every direct call is) turn it into a TargetGlobalAddress /
@@ -4309,16 +4314,8 @@ PrepareCall(SelectionDAG &DAG, SDValue &
   if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
     unsigned char OpFlags = 0;
 
-    if ((DAG.getTarget().getRelocationModel() != Reloc::Static &&
-         (Subtarget.getTargetTriple().isMacOSX() &&
-          Subtarget.getTargetTriple().isMacOSXVersionLT(10, 5))) ||
-        (Subtarget.isTargetELF() && !isPPC64 &&
-         DAG.getTarget().getRelocationModel() == Reloc::PIC_)) {
-      // PC-relative references to external symbols should go through $stub,
-      // unless we're building with the leopard linker or later, which
-      // automatically synthesizes these stubs.
+    if (UsePlt)
       OpFlags = PPCII::MO_PLT_OR_STUB;
-    }
 
     Callee = DAG.getTargetExternalSymbol(S->getSymbol(), Callee.getValueType(),
                                          OpFlags);




More information about the llvm-commits mailing list