move reasoning about darwin $non_lazy_ptr stubs from asmprinter into
isel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75117 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 31b18b7..bb5829a 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -4551,14 +4551,14 @@
X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
int64_t Offset,
SelectionDAG &DAG) const {
- bool IsPic = getTargetMachine().getRelocationModel() == Reloc::PIC_;
+ bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
bool ExtraLoadRequired =
Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false);
// Create the TargetGlobalAddress node, folding in the constant
// offset if it is legal.
SDValue Result;
- if (!IsPic && !ExtraLoadRequired && isInt32(Offset)) {
+ if (!IsPIC && !ExtraLoadRequired && isInt32(Offset)) {
// A direct static reference to a global.
Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), Offset);
Offset = 0;
@@ -4575,9 +4575,29 @@
OpFlags = X86II::MO_GOT;
else
OpFlags = X86II::MO_GOTOFF;
- } else if (Subtarget->isPICStyleStub() &&
- getTargetMachine().getRelocationModel() == Reloc::PIC_) {
- OpFlags = X86II::MO_PIC_BASE_OFFSET;
+ } else if (Subtarget->isPICStyleStub()) {
+ // In darwin, we have multiple different stub types, and we have both PIC
+ // and -mdynamic-no-pic. Determine whether we have a stub reference
+ // and/or whether the reference is relative to the PIC base or not.
+
+ // Link-once, declaration, or Weakly-linked global variables need
+ // non-lazily-resolved stubs.
+ if (!GV->isDeclaration() && !GV->isWeakForLinker()) {
+ // Not a stub reference.
+ OpFlags = IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0;
+ } else if (!GV->hasHiddenVisibility()) {
+ // Non-hidden $non_lazy_ptr reference.
+ OpFlags = IsPIC ? X86II::MO_DARWIN_NONLAZY_PIC_BASE :
+ X86II::MO_DARWIN_NONLAZY;
+ } else if (!GV->isDeclaration() && !GV->hasCommonLinkage())
+ // Definition is definitely in the current linkage unit.
+ // Not a stub reference.
+ OpFlags = IsPIC ? X86II::MO_PIC_BASE_OFFSET : 0;
+ else {
+ // Hidden $non_lazy_ptr reference.
+ OpFlags = IsPIC ? X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE :
+ X86II::MO_DARWIN_HIDDEN_NONLAZY;
+ }
}
Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), 0, OpFlags);
@@ -4590,7 +4610,7 @@
Result = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), Result);
// With PIC, the address is actually $g + Offset.
- if (IsPic && !Subtarget->is64Bit()) {
+ if (IsPIC && !Subtarget->is64Bit()) {
Result = DAG.getNode(ISD::ADD, dl, getPointerTy(),
DAG.getNode(X86ISD::GlobalBaseReg, dl, getPointerTy()),
Result);