move some classification logic around.  Now GVRequiresExtraLoad
is just a trivial wrapper around "ClassifyGlobalReference", which
stole a ton of logic from LowerGlobalAddress.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75237 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 28ee2c3..e3ffb29 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -4553,50 +4553,20 @@
                                       int64_t Offset,
                                       SelectionDAG &DAG) const {
   bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_;
-  bool ExtraLoadRequired =
-    Subtarget->GVRequiresExtraLoad(GV, getTargetMachine());
 
   // Create the TargetGlobalAddress node, folding in the constant
   // offset if it is legal.
+  unsigned char OpFlags =
+    Subtarget->ClassifyGlobalReference(GV, getTargetMachine());
+  bool ExtraLoadRequired = isGlobalStubReference(OpFlags);
+  
+  
   SDValue Result;
   if (!IsPIC && !ExtraLoadRequired && isInt32(Offset)) {
     // A direct static reference to a global.
     Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), Offset);
     Offset = 0;
   } else {
-    unsigned char OpFlags = 0;
-    
-    if (GV->hasDLLImportLinkage())
-      OpFlags = X86II::MO_DLLIMPORT;
-    else if (Subtarget->isPICStyleRIPRel()) {
-      if (ExtraLoadRequired)
-        OpFlags = X86II::MO_GOTPCREL;
-    } else if (Subtarget->isPICStyleGOT()) {
-      if (ExtraLoadRequired)
-        OpFlags = X86II::MO_GOT;
-      else
-        OpFlags = X86II::MO_GOTOFF;
-    } 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 (!ExtraLoadRequired) {
-        // 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 {
-        // 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);
   }