move handling of dllimport linkage in isel, not in asmprinter.
authorChris Lattner <sabre@nondot.org>
Thu, 9 Jul 2009 00:58:53 +0000 (00:58 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 9 Jul 2009 00:58:53 +0000 (00:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75086 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.h

index 6890f11443c45ca473fec6112c4d7763efe7263b..75d2cd96f8b7053d128dc6cf5ec541c805e88820 100644 (file)
@@ -351,10 +351,9 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
         O << Name;
       }
     } else {
-      if (GV->hasDLLImportLinkage()) {
-        assert(MO.getTargetFlags() == 0);
+      // Handle dllimport linkage.
+      if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
         O << "__imp_";
-      }
       O << Name;
       
       if (shouldPrintPLT(TM, Subtarget)) {
@@ -503,10 +502,9 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
         PrintPICBaseSymbol();
       }        
     } else {
-      if (GV->hasDLLImportLinkage()) {
+      // Handle dllimport linkage.
+      if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
         O << "__imp_";
-        assert(MO.getTargetFlags() == 0);
-      }
       O << Name;
     }
 
@@ -533,7 +531,8 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
   switch (MO.getTargetFlags()) {
   default:
     assert(0 && "Unknown target flag on GV operand");
-  case X86II::MO_NO_FLAG:
+  case X86II::MO_NO_FLAG:    // No flag.
+  case X86II::MO_DLLIMPORT:  // Prefix, not a suffix.
     break;
   case X86II::MO_GOT_ABSOLUTE_ADDRESS:
     O << " + [.-";
index 9d4df93c1b4686c319c6fa6b42382e03b5542245..ad8d6adde7ea87ba5cebf19e0b5e8b48389aee64 100644 (file)
@@ -244,11 +244,13 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
     decorateName(Name, GV);
 
     if (!isMemOp) O << "OFFSET ";
-    if (GV->hasDLLImportLinkage()) {
-      // FIXME: This should be fixed with full support of stdcall & fastcall
-      // CC's
+    
+    // Handle dllimport linkage.
+    // FIXME: This should be fixed with full support of stdcall & fastcall
+    // CC's
+    if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
       O << "__imp_";
-    }
+    
     O << Name;
     printOffset(MO.getOffset());
     return;
@@ -278,11 +280,11 @@ void X86IntelAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo){
     std::string Name = Mang->getValueName(GV);
     decorateName(Name, GV);
     
-    if (GV->hasDLLImportLinkage()) {
-      // FIXME: This should be fixed with full support of stdcall & fastcall
-      // CC's
+    // Handle dllimport linkage.
+    // FIXME: This should be fixed with full support of stdcall & fastcall
+    // CC's
+    if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
       O << "__imp_";
-    }
     O << Name;
     printOffset(MO.getOffset());
     return;
index 32f247df9773a32d997dac40f7cf4f6fa7612e69..3f6c759ea5f5fd62edec4752adbecfe377e17b04 100644 (file)
@@ -4547,13 +4547,16 @@ X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
   // offset if it is legal.
   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 (Subtarget->isPICStyleRIPRel() &&
-        getTargetMachine().getRelocationModel() != Reloc::Static) {
+    if (GV->hasDLLImportLinkage())
+      OpFlags = X86II::MO_DLLIMPORT;
+    else if (Subtarget->isPICStyleRIPRel() &&
+             getTargetMachine().getRelocationModel() != Reloc::Static) {
       if (ExtraLoadRequired)
         OpFlags = X86II::MO_GOTPCREL;
     } else if (Subtarget->isPICStyleGOT() &&
index 83f01945ea21ba9c698af67791baf427a49629f9..45f358470a0a6848f32887c6a6ce7c116d64cb4b 100644 (file)
@@ -149,6 +149,12 @@ namespace X86II {
     ///    SYMBOL_LABEL @NTPOFF
     MO_NTPOFF = 11,
     
+    /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the
+    /// reference is actually to the "__imp_FOO" symbol.  This is used for
+    /// dllimport linkage on windows.
+    MO_DLLIMPORT = 12,
+    
+    
     //===------------------------------------------------------------------===//
     // Instruction encodings.  These are the standard/most common forms for X86
     // instructions.