- Change "ExternalSymbolSDNode" to "SymbolSDNode".
- Add linkage to SymbolSDNode (default to external).
- Change ISD::ExternalSymbol to ISD::Symbol.
- Change ISD::TargetExternalSymbol to ISD::TargetSymbol

These changes pave the way to allowing SymbolSDNodes with non-external linkage.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56249 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp
index 2202177..4131903 100644
--- a/lib/Target/ARM/ARMISelLowering.cpp
+++ b/lib/Target/ARM/ARMISelLowering.cpp
@@ -531,9 +531,9 @@
     InFlag = Chain.getValue(1);
   }
 
-  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
-  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
-  // node so that legalize doesn't hack it.
+  // If the callee is a GlobalAddress/Symbol node (quite common, every direct
+  // call is) turn it into a TargetGlobalAddress/TargetSymbol node so that
+  // legalize doesn't hack it.
   bool isDirect = false;
   bool isARMFunc = false;
   bool isLocalARMFunc = false;
@@ -558,7 +558,7 @@
       Callee = DAG.getNode(ARMISD::PIC_ADD, getPointerTy(), Callee, PICLabel);
    } else
       Callee = DAG.getTargetGlobalAddress(GV, getPointerTy());
-  } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
+  } else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee)) {
     isDirect = true;
     bool isStub = Subtarget->isTargetDarwin() &&
                   getTargetMachine().getRelocationModel() != Reloc::Static;
@@ -574,7 +574,7 @@
       SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
       Callee = DAG.getNode(ARMISD::PIC_ADD, getPointerTy(), Callee, PICLabel);
     } else
-      Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy());
+      Callee = DAG.getTargetSymbol(Sym, getPointerTy(), S->getLinkage());
   }
 
   // FIXME: handle tail calls differently.
@@ -715,12 +715,11 @@
   return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
 }
 
-// ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as 
-// their target countpart wrapped in the ARMISD::Wrapper node. Suppose N is
-// one of the above mentioned nodes. It has to be wrapped because otherwise
-// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
-// be used to form addressing mode. These wrapped nodes will be selected
-// into MOVi.
+// ConstantPool, JumpTable, GlobalAddress, and Symbol are lowered as their
+// target countpart wrapped in the ARMISD::Wrapper node. Suppose N is one of the
+// above mentioned nodes. It has to be wrapped because otherwise Select(N)
+// returns N. So the raw TargetGlobalAddress nodes, etc. can only be used to
+// form addressing mode. These wrapped nodes will be selected into MOVi.
 static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
   MVT PtrVT = Op.getValueType();
   ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
@@ -760,7 +759,7 @@
   std::pair<SDValue, SDValue> CallResult =
     LowerCallTo(Chain, (const Type *) Type::Int32Ty, false, false, false,
                 CallingConv::C, false,
-                DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG);
+                DAG.getSymbol("__tls_get_addr", PtrVT), Args, DAG);
   return CallResult.first;
 }
 
diff --git a/lib/Target/Alpha/AlphaISelLowering.cpp b/lib/Target/Alpha/AlphaISelLowering.cpp
index 5b7d125..26bc70a 100644
--- a/lib/Target/Alpha/AlphaISelLowering.cpp
+++ b/lib/Target/Alpha/AlphaISelLowering.cpp
@@ -125,12 +125,11 @@
   setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
   setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
 
-  // We want to legalize GlobalAddress and ConstantPool and
-  // ExternalSymbols nodes into the appropriate instructions to
-  // materialize the address.
+  // We want to legalize GlobalAddress and ConstantPool and Symbols nodes into
+  // the appropriate instructions to materialize the address.
   setOperationAction(ISD::GlobalAddress,  MVT::i64, Custom);
   setOperationAction(ISD::ConstantPool,   MVT::i64, Custom);
-  setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
+  setOperationAction(ISD::Symbol, MVT::i64, Custom);
   setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
 
   setOperationAction(ISD::VASTART, MVT::Other, Custom);
@@ -491,13 +490,13 @@
       return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, 
                          DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i64));
   }
-  case ISD::ExternalSymbol: {
+  case ISD::Symbol: {
+    SymbolSDNode *S = cast<SymbolSDNode>(Op);
     return DAG.getNode(AlphaISD::RelLit, MVT::i64, 
-                       DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)
-                                                   ->getSymbol(), MVT::i64),
+                       DAG.getTargetSymbol(S->getSymbol(), MVT::i64,
+                                           S->getLinkage()),
                        DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i64));
   }
-
   case ISD::UREM:
   case ISD::SREM:
     //Expand only on constant case
@@ -526,7 +525,7 @@
       }
       SDValue Tmp1 = Op.getOperand(0),
         Tmp2 = Op.getOperand(1),
-        Addr = DAG.getExternalSymbol(opstr, MVT::i64);
+        Addr = DAG.getSymbol(opstr, MVT::i64);
       return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2);
     }
     break;
diff --git a/lib/Target/CellSPU/SPUISelLowering.cpp b/lib/Target/CellSPU/SPUISelLowering.cpp
index 384755d..b97f4c4 100644
--- a/lib/Target/CellSPU/SPUISelLowering.cpp
+++ b/lib/Target/CellSPU/SPUISelLowering.cpp
@@ -92,12 +92,12 @@
             || Opc == ISD::GlobalTLSAddress
             || Opc == ISD::JumpTable
             || Opc == ISD::ConstantPool
-            || Opc == ISD::ExternalSymbol
+            || Opc == ISD::Symbol
             || Opc == ISD::TargetGlobalAddress
             || Opc == ISD::TargetGlobalTLSAddress
             || Opc == ISD::TargetJumpTable
             || Opc == ISD::TargetConstantPool
-            || Opc == ISD::TargetExternalSymbol
+            || Opc == ISD::TargetSymbol
             || Opc == SPUISD::AFormAddr);
   }
 
@@ -1201,9 +1201,9 @@
   SmallVector<SDValue, 8> Ops;
   unsigned CallOpc = SPUISD::CALL;
 
-  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
-  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
-  // node so that legalize doesn't hack it.
+  // If the callee is a GlobalAddress/Symbol node (quite common, every direct
+  // call is) turn it into a TargetGlobalAddress/TargetSymbol node so that
+  // legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
     GlobalValue *GV = G->getGlobal();
     MVT CalleeVT = Callee.getValueType();
@@ -1229,8 +1229,9 @@
       // address pairs:
       Callee = DAG.getNode(SPUISD::IndirectAddr, PtrVT, GA, Zero);
     }
-  } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
-    Callee = DAG.getExternalSymbol(S->getSymbol(), Callee.getValueType());
+  } else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee))
+    Callee = DAG.getSymbol(S->getSymbol(), Callee.getValueType(),
+                           S->getLinkage());
   else if (SDNode *Dest = isLSAAddress(Callee, DAG)) {
     // If this is an absolute destination address that appears to be a legal
     // local store address, use the munged value.
diff --git a/lib/Target/IA64/IA64ISelDAGToDAG.cpp b/lib/Target/IA64/IA64ISelDAGToDAG.cpp
index f79496d..19ea472 100644
--- a/lib/Target/IA64/IA64ISelDAGToDAG.cpp
+++ b/lib/Target/IA64/IA64ISelDAGToDAG.cpp
@@ -329,7 +329,7 @@
       dyn_cast<GlobalAddressSDNode>(N->getOperand(1))) {
       CallOpcode = IA64::BRCALL_IPREL_GA;
       CallOperand = CurDAG->getTargetGlobalAddress(GASD->getGlobal(), MVT::i64);
-    } else if (isa<ExternalSymbolSDNode>(N->getOperand(1))) {
+    } else if (isa<SymbolSDNode>(N->getOperand(1))) {
       // FIXME: we currently NEED this case for correctness, to avoid
       // "non-pic code with imm reloc.n against dynamic symbol" errors
     CallOpcode = IA64::BRCALL_IPREL_ES;
@@ -448,9 +448,9 @@
   }
   
 /* XXX
-   case ISD::ExternalSymbol: {
-     SDValue EA = CurDAG->getTargetExternalSymbol(
-       cast<ExternalSymbolSDNode>(N)->getSymbol(),
+   case ISD::Symbol: {
+     SDValue EA = CurDAG->getTargetSymbol(
+       cast<SymbolSDNode>(N)->getSymbol(),
        MVT::i64);
      SDValue Tmp = CurDAG->getTargetNode(IA64::ADDL_EA, MVT::i64, 
                                            CurDAG->getRegister(IA64::r1,
diff --git a/lib/Target/Mips/MipsISelDAGToDAG.cpp b/lib/Target/Mips/MipsISelDAGToDAG.cpp
index a408a96..82c20f7 100644
--- a/lib/Target/Mips/MipsISelDAGToDAG.cpp
+++ b/lib/Target/Mips/MipsISelDAGToDAG.cpp
@@ -159,7 +159,7 @@
       return true;
     }
   } else {
-    if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
+    if ((Addr.getOpcode() == ISD::TargetSymbol ||
         Addr.getOpcode() == ISD::TargetGlobalAddress))
       return false;
   }    
@@ -354,7 +354,7 @@
         SDValue InFlag(0, 0);
 
         if ( (isa<GlobalAddressSDNode>(Callee)) ||
-             (isa<ExternalSymbolSDNode>(Callee)) )
+             (isa<SymbolSDNode>(Callee)) )
         {
           /// Direct call for global addresses and external symbols
           SDValue GPReg = CurDAG->getRegister(Mips::GP, MVT::i32);
diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp
index 557a105..b1fe262 100644
--- a/lib/Target/Mips/MipsISelLowering.cpp
+++ b/lib/Target/Mips/MipsISelLowering.cpp
@@ -684,14 +684,14 @@
     InFlag = Chain.getValue(1);
   }
 
-  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
-  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol 
-  // node so that legalize doesn't hack it. 
+  // If the callee is a GlobalAddress/Symbol node (quite common, every direct
+  // call is) turn it into a TargetGlobalAddress/TargetSymbol node so that
+  // legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) 
     Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
-  else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
-    Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
-
+  else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee))
+    Callee = DAG.getTargetSymbol(S->getSymbol(), getPointerTy(),
+                                 S->getLinkage());
 
   // MipsJmpLink = #chain, #target_address, #opt_in_flags...
   //             = Chain, Callee, Reg#1, Reg#2, ...  
diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp
index 1a891d9..6de90d9 100644
--- a/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -2462,13 +2462,14 @@
   SmallVector<SDValue, 8> Ops;
   unsigned CallOpc = isMachoABI? PPCISD::CALL_Macho : PPCISD::CALL_ELF;
   
-  // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
-  // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
-  // node so that legalize doesn't hack it.
+  // If the callee is a GlobalAddress/Symbol node (quite common, every direct
+  // call is) turn it into a TargetGlobalAddress/TargetSymbol node so that
+  // legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
     Callee = DAG.getTargetGlobalAddress(G->getGlobal(), Callee.getValueType());
-  else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
-    Callee = DAG.getTargetExternalSymbol(S->getSymbol(), Callee.getValueType());
+  else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee))
+    Callee = DAG.getTargetSymbol(S->getSymbol(), Callee.getValueType(),
+                                 S->getLinkage());
   else if (SDNode *Dest = isBLACompatibleAddress(Callee, DAG))
     // If this is an absolute destination address, use the munged value.
     Callee = SDValue(Dest, 0);
@@ -2593,7 +2594,7 @@
 
     assert(((TargetAddress.getOpcode() == ISD::Register &&
              cast<RegisterSDNode>(TargetAddress)->getReg() == PPC::CTR) ||
-            TargetAddress.getOpcode() == ISD::TargetExternalSymbol ||
+            TargetAddress.getOpcode() == ISD::TargetSymbol ||
             TargetAddress.getOpcode() == ISD::TargetGlobalAddress ||
             isa<ConstantSDNode>(TargetAddress)) &&
     "Expecting an global address, external symbol, absolute value or register");
@@ -3414,7 +3415,7 @@
 static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS,
                                         SDValue RHS, SelectionDAG &DAG) {
   unsigned OpNum = (PFEntry >> 26) & 0x0F;
-  unsigned LHSID  = (PFEntry >> 13) & ((1 << 13)-1);
+  unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1);
   unsigned RHSID = (PFEntry >>  0) & ((1 << 13)-1);
   
   enum {
diff --git a/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/lib/Target/Sparc/SparcISelDAGToDAG.cpp
index 4a3ca7f..ae11762 100644
--- a/lib/Target/Sparc/SparcISelDAGToDAG.cpp
+++ b/lib/Target/Sparc/SparcISelDAGToDAG.cpp
@@ -77,7 +77,7 @@
     Offset = CurDAG->getTargetConstant(0, MVT::i32);
     return true;
   }
-  if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
+  if (Addr.getOpcode() == ISD::TargetSymbol ||
       Addr.getOpcode() == ISD::TargetGlobalAddress)
     return false;  // direct calls.
   
@@ -114,7 +114,7 @@
 bool SparcDAGToDAGISel::SelectADDRrr(SDValue Op, SDValue Addr,
                                      SDValue &R1,  SDValue &R2) {
   if (Addr.getOpcode() == ISD::FrameIndex) return false;
-  if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
+  if (Addr.getOpcode() == ISD::TargetSymbol ||
       Addr.getOpcode() == ISD::TargetGlobalAddress)
     return false;  // direct calls.
   
diff --git a/lib/Target/Sparc/SparcISelLowering.cpp b/lib/Target/Sparc/SparcISelLowering.cpp
index d89b6d4..4584bf6 100644
--- a/lib/Target/Sparc/SparcISelLowering.cpp
+++ b/lib/Target/Sparc/SparcISelLowering.cpp
@@ -407,11 +407,11 @@
 
   // If the callee is a GlobalAddress node (quite common, every direct call is)
   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
-  // Likewise ExternalSymbol -> TargetExternalSymbol.
+  // Likewise Symbol -> TargetSymbol.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
     Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32);
-  else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
-    Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
+  else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee))
+    Callee = DAG.getTargetSymbol(S->getSymbol(), MVT::i32, S->getLinkage());
 
   std::vector<MVT> NodeTys;
   NodeTys.push_back(MVT::Other);   // Returns a chain
diff --git a/lib/Target/TargetSelectionDAG.td b/lib/Target/TargetSelectionDAG.td
index 230c956..a3088ba 100644
--- a/lib/Target/TargetSelectionDAG.td
+++ b/lib/Target/TargetSelectionDAG.td
@@ -265,10 +265,10 @@
                          "FrameIndexSDNode">;
 def tframeindex : SDNode<"ISD::TargetFrameIndex",     SDTPtrLeaf, [],
                          "FrameIndexSDNode">;
-def externalsym : SDNode<"ISD::ExternalSymbol",       SDTPtrLeaf, [],
-                         "ExternalSymbolSDNode">;
-def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
-                         "ExternalSymbolSDNode">;
+def externalsym : SDNode<"ISD::Symbol",               SDTPtrLeaf, [],
+                         "SymbolSDNode">;
+def texternalsym: SDNode<"ISD::TargetSymbol",         SDTPtrLeaf, [],
+                         "SymbolSDNode">;
 
 def add        : SDNode<"ISD::ADD"       , SDTIntBinOp   ,
                         [SDNPCommutative, SDNPAssociative]>;
diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp
index dedd890..e966467 100644
--- a/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -207,7 +207,7 @@
         Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32,
                                              AM.Align, AM.Disp);
       else if (AM.ES)
-        Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32);
+        Disp = CurDAG->getTargetSymbol(AM.ES, MVT::i32);
       else if (AM.JT != -1)
         Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32);
       else
@@ -835,7 +835,7 @@
         AM.isRIPRel = TM.getRelocationModel() != Reloc::Static &&
           Subtarget->isPICStyleRIPRel();
         return false;
-      } else if (ExternalSymbolSDNode *S =dyn_cast<ExternalSymbolSDNode>(N0)) {
+      } else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(N0)) {
         AM.ES = S->getSymbol();
         AM.isRIPRel = TM.getRelocationModel() != Reloc::Static &&
           Subtarget->isPICStyleRIPRel();
@@ -1292,7 +1292,7 @@
           N1.getOpcode() == ISD::Constant) {
         unsigned Offset = (unsigned)cast<ConstantSDNode>(N1)->getZExtValue();
         SDValue C(0, 0);
-        // TODO: handle ExternalSymbolSDNode.
+        // TODO: handle SymbolSDNode.
         if (GlobalAddressSDNode *G =
             dyn_cast<GlobalAddressSDNode>(N0.getOperand(0))) {
           C = CurDAG->getTargetGlobalAddress(G->getGlobal(), PtrVT,
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 3401a2c..8f7f4ab 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -268,12 +268,12 @@
   setOperationAction(ISD::GlobalTLSAddress, MVT::i32  , Custom);
   if (Subtarget->is64Bit())
     setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
-  setOperationAction(ISD::ExternalSymbol  , MVT::i32  , Custom);
+  setOperationAction(ISD::Symbol          , MVT::i32  , Custom);
   if (Subtarget->is64Bit()) {
     setOperationAction(ISD::ConstantPool  , MVT::i64  , Custom);
     setOperationAction(ISD::JumpTable     , MVT::i64  , Custom);
     setOperationAction(ISD::GlobalAddress , MVT::i64  , Custom);
-    setOperationAction(ISD::ExternalSymbol, MVT::i64  , Custom);
+    setOperationAction(ISD::Symbol        , MVT::i64  , Custom);
   }
   // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
   setOperationAction(ISD::SHL_PARTS       , MVT::i32  , Custom);
@@ -892,7 +892,7 @@
     assert(((TargetAddress.getOpcode() == ISD::Register &&
                (cast<RegisterSDNode>(TargetAddress)->getReg() == X86::ECX ||
                 cast<RegisterSDNode>(TargetAddress)->getReg() == X86::R9)) ||
-              TargetAddress.getOpcode() == ISD::TargetExternalSymbol ||
+              TargetAddress.getOpcode() == ISD::TargetSymbol ||
               TargetAddress.getOpcode() == ISD::TargetGlobalAddress) && 
              "Expecting an global address, external symbol, or register");
     assert(StackAdjustment.getOpcode() == ISD::Constant &&
@@ -1608,8 +1608,8 @@
     if (G &&  !G->getGlobal()->hasHiddenVisibility() &&
         !G->getGlobal()->hasProtectedVisibility())
       Callee =  LowerGlobalAddress(Callee, DAG);
-    else if (isa<ExternalSymbolSDNode>(Callee))
-      Callee = LowerExternalSymbol(Callee,DAG);
+    else if (isa<SymbolSDNode>(Callee))
+      Callee = LowerExternalSymbol(Callee, DAG);
   }
 
   if (Is64Bit && isVarArg) {
@@ -1697,8 +1697,9 @@
     if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(),
                                         getTargetMachine(), true))
       Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
-  } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
-    Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
+  } else if (SymbolSDNode *S = dyn_cast<SymbolSDNode>(Callee)) {
+    Callee = DAG.getTargetSymbol(S->getSymbol(), getPointerTy(),
+                                 S->getLinkage());
   } else if (IsTailCall) {
     unsigned Opc = Is64Bit ? X86::R9 : X86::ECX;
 
@@ -4286,12 +4287,11 @@
                      DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, AnyExt));
 }
 
-// ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as
-// their target countpart wrapped in the X86ISD::Wrapper node. Suppose N is
-// one of the above mentioned nodes. It has to be wrapped because otherwise
-// Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
-// be used to form addressing mode. These wrapped nodes will be selected
-// into MOV32ri.
+// ConstantPool, JumpTable, GlobalAddress, and Symbol are lowered as their
+// target countpart wrapped in the X86ISD::Wrapper node. Suppose N is one of the
+// above mentioned nodes. It has to be wrapped because otherwise Select(N)
+// returns N. So the raw TargetGlobalAddress nodes, etc. can only be used to
+// form addressing mode. These wrapped nodes will be selected into MOV32ri.
 SDValue
 X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
   ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
@@ -4362,8 +4362,7 @@
 
   NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
   SDValue Ops1[] = { Chain,
-                      DAG.getTargetExternalSymbol("___tls_get_addr",
-                                                  PtrVT),
+                      DAG.getTargetSymbol("___tls_get_addr", PtrVT),
                       DAG.getRegister(X86::EAX, PtrVT),
                       DAG.getRegister(X86::EBX, PtrVT),
                       InFlag };
@@ -4396,8 +4395,7 @@
 
   NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
   SDValue Ops1[] = { Chain,
-                      DAG.getTargetExternalSymbol("__tls_get_addr",
-                                                  PtrVT),
+                      DAG.getTargetSymbol("__tls_get_addr", PtrVT),
                       DAG.getRegister(X86::RDI, PtrVT),
                       InFlag };
   Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops1, 4);
@@ -4449,8 +4447,9 @@
 
 SDValue
 X86TargetLowering::LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) {
-  const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
-  SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy());
+  SymbolSDNode *Sym = cast<SymbolSDNode>(Op);
+  SDValue Result = DAG.getTargetSymbol(Sym->getSymbol(), getPointerTy(),
+                                       Sym->getLinkage());
   Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), Result);
   // With PIC, the address is actually $g + Offset.
   if (getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
@@ -5054,7 +5053,7 @@
 
   SDVTList  NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
   SDValue Ops[] = { Chain,
-                      DAG.getTargetExternalSymbol("_alloca", IntPtr),
+                      DAG.getTargetSymbol("_alloca", IntPtr),
                       DAG.getRegister(X86::EAX, IntPtr),
                       DAG.getRegister(X86StackPtr, SPTy),
                       Flag };
@@ -5104,7 +5103,7 @@
       Args.push_back(Entry);
       std::pair<SDValue,SDValue> CallResult =
         LowerCallTo(Chain, Type::VoidTy, false, false, false, CallingConv::C,
-                    false, DAG.getExternalSymbol(bzeroEntry, IntPtr),
+                    false, DAG.getSymbol(bzeroEntry, IntPtr),
                     Args, DAG);
       return CallResult.second;
     }
@@ -5977,7 +5976,7 @@
   case ISD::ConstantPool:       return LowerConstantPool(Op, DAG);
   case ISD::GlobalAddress:      return LowerGlobalAddress(Op, DAG);
   case ISD::GlobalTLSAddress:   return LowerGlobalTLSAddress(Op, DAG);
-  case ISD::ExternalSymbol:     return LowerExternalSymbol(Op, DAG);
+  case ISD::Symbol:             return LowerExternalSymbol(Op, DAG);
   case ISD::SHL_PARTS:
   case ISD::SRA_PARTS:
   case ISD::SRL_PARTS:          return LowerShift(Op, DAG);
diff --git a/lib/Target/X86/X86ISelLowering.h b/lib/Target/X86/X86ISelLowering.h
index 2212767..8982f11 100644
--- a/lib/Target/X86/X86ISelLowering.h
+++ b/lib/Target/X86/X86ISelLowering.h
@@ -145,8 +145,8 @@
       /// at function entry, used for PIC code.
       GlobalBaseReg,
 
-      /// Wrapper - A wrapper node for TargetConstantPool,
-      /// TargetExternalSymbol, and TargetGlobalAddress.
+      /// Wrapper - A wrapper node for TargetConstantPool, TargetSymbol, and
+      /// TargetGlobalAddress.
       Wrapper,
 
       /// WrapperRIP - Special wrapper used under X86-64 PIC mode for RIP
diff --git a/lib/Target/X86/X86Instr64bit.td b/lib/Target/X86/X86Instr64bit.td
index 88a8c08..c02e535 100644
--- a/lib/Target/X86/X86Instr64bit.td
+++ b/lib/Target/X86/X86Instr64bit.td
@@ -1192,7 +1192,7 @@
 // Non-Instruction Patterns
 //===----------------------------------------------------------------------===//
 
-// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
+// ConstantPool GlobalAddress, Symbol, and JumpTable
 def : Pat<(i64 (X86Wrapper tconstpool  :$dst)),
           (MOV64ri tconstpool  :$dst)>, Requires<[NotSmallCode]>;
 def : Pat<(i64 (X86Wrapper tjumptable  :$dst)),
diff --git a/lib/Target/X86/X86InstrInfo.td b/lib/Target/X86/X86InstrInfo.td
index 1b68dda..2f37cc1 100644
--- a/lib/Target/X86/X86InstrInfo.td
+++ b/lib/Target/X86/X86InstrInfo.td
@@ -2703,7 +2703,7 @@
 // Non-Instruction Patterns
 //===----------------------------------------------------------------------===//
 
-// ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
+// ConstantPool GlobalAddress, Symbol, and JumpTable
 def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
 def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;