LLVM API Documentation

X86ATTAsmPrinter.cpp

Go to the documentation of this file.
00001 //===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly -----===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains a printer that converts from our internal representation
00011 // of machine-dependent LLVM code to AT&T format assembly
00012 // language. This printer is the output mechanism used by `llc'.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #define DEBUG_TYPE "asm-printer"
00017 #include "X86ATTAsmPrinter.h"
00018 #include "X86.h"
00019 #include "X86COFF.h"
00020 #include "X86MachineFunctionInfo.h"
00021 #include "X86TargetMachine.h"
00022 #include "X86TargetAsmInfo.h"
00023 #include "llvm/CallingConv.h"
00024 #include "llvm/DerivedTypes.h"
00025 #include "llvm/Module.h"
00026 #include "llvm/Type.h"
00027 #include "llvm/ADT/Statistic.h"
00028 #include "llvm/ADT/StringExtras.h"
00029 #include "llvm/Assembly/Writer.h"
00030 #include "llvm/MC/MCContext.h"
00031 #include "llvm/MC/MCInst.h"
00032 #include "llvm/MC/MCSectionMachO.h"
00033 #include "llvm/MC/MCStreamer.h"
00034 #include "llvm/CodeGen/DwarfWriter.h"
00035 #include "llvm/CodeGen/MachineJumpTableInfo.h"
00036 #include "llvm/Support/CommandLine.h"
00037 #include "llvm/Support/ErrorHandling.h"
00038 #include "llvm/Support/FormattedStream.h"
00039 #include "llvm/Support/Mangler.h"
00040 #include "llvm/Target/TargetAsmInfo.h"
00041 #include "llvm/Target/TargetLoweringObjectFile.h"
00042 #include "llvm/Target/TargetOptions.h"
00043 using namespace llvm;
00044 
00045 STATISTIC(EmittedInsts, "Number of machine instrs printed");
00046 
00047 static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
00048                                    cl::Hidden);
00049 
00050 //===----------------------------------------------------------------------===//
00051 // Primitive Helper Functions.
00052 //===----------------------------------------------------------------------===//
00053 
00054 void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
00055   // FIXME: the actual label generated doesn't matter here!  Just mangle in
00056   // something unique (the function number) with Private prefix.
00057   if (Subtarget->isTargetDarwin())
00058     O << "\"L" << getFunctionNumber() << "$pb\"";
00059   else {
00060     assert(Subtarget->isTargetELF() && "Don't know how to print PIC label!");
00061     O << ".Lllvm$" << getFunctionNumber() << ".$piclabel";
00062   }
00063 }
00064 
00065 MCSymbol *X86ATTAsmPrinter::GetPICBaseSymbol() {
00066   // FIXME: the actual label generated doesn't matter here!  Just mangle in
00067   // something unique (the function number) with Private prefix.
00068   std::string Name;
00069   
00070   if (Subtarget->isTargetDarwin()) {
00071     Name = "L" + utostr(getFunctionNumber())+"$pb";
00072   } else {
00073     assert(Subtarget->isTargetELF() && "Don't know how to print PIC label!");
00074     Name = ".Lllvm$" + utostr(getFunctionNumber())+".$piclabel";
00075   }     
00076   return OutContext.GetOrCreateSymbol(Name);
00077 }
00078 
00079 static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
00080                                                     const TargetData *TD) {
00081   X86MachineFunctionInfo Info;
00082   uint64_t Size = 0;
00083 
00084   switch (F->getCallingConv()) {
00085   case CallingConv::X86_StdCall:
00086     Info.setDecorationStyle(StdCall);
00087     break;
00088   case CallingConv::X86_FastCall:
00089     Info.setDecorationStyle(FastCall);
00090     break;
00091   default:
00092     return Info;
00093   }
00094 
00095   unsigned argNum = 1;
00096   for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
00097        AI != AE; ++AI, ++argNum) {
00098     const Type* Ty = AI->getType();
00099 
00100     // 'Dereference' type in case of byval parameter attribute
00101     if (F->paramHasAttr(argNum, Attribute::ByVal))
00102       Ty = cast<PointerType>(Ty)->getElementType();
00103 
00104     // Size should be aligned to DWORD boundary
00105     Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4;
00106   }
00107 
00108   // We're not supporting tooooo huge arguments :)
00109   Info.setBytesToPopOnReturn((unsigned int)Size);
00110   return Info;
00111 }
00112 
00113 /// DecorateCygMingName - Query FunctionInfoMap and use this information for
00114 /// various name decorations for Cygwin and MingW.
00115 void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
00116                                            const GlobalValue *GV) {
00117   assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw");
00118   
00119   const Function *F = dyn_cast<Function>(GV);
00120   if (!F) return;
00121 
00122   // Save function name for later type emission.
00123   if (F->isDeclaration())
00124     CygMingStubs.insert(Name);
00125   
00126   // We don't want to decorate non-stdcall or non-fastcall functions right now
00127   unsigned CC = F->getCallingConv();
00128   if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
00129     return;
00130 
00131 
00132   const X86MachineFunctionInfo *Info;
00133   
00134   FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
00135   if (info_item == FunctionInfoMap.end()) {
00136     // Calculate apropriate function info and populate map
00137     FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
00138     Info = &FunctionInfoMap[F];
00139   } else {
00140     Info = &info_item->second;
00141   }
00142 
00143   const FunctionType *FT = F->getFunctionType();
00144   switch (Info->getDecorationStyle()) {
00145   case None:
00146     break;
00147   case StdCall:
00148     // "Pure" variadic functions do not receive @0 suffix.
00149     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
00150         (FT->getNumParams() == 1 && F->hasStructRetAttr()))
00151       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
00152     break;
00153   case FastCall:
00154     // "Pure" variadic functions do not receive @0 suffix.
00155     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
00156         (FT->getNumParams() == 1 && F->hasStructRetAttr()))
00157       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
00158 
00159     if (Name[0] == '_') {
00160       Name[0] = '@';
00161     } else {
00162       Name = '@' + Name;
00163     }
00164     break;
00165   default:
00166     llvm_unreachable("Unsupported DecorationStyle");
00167   }
00168 }
00169 
00170 void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
00171   unsigned FnAlign = MF.getAlignment();
00172   const Function *F = MF.getFunction();
00173 
00174   if (Subtarget->isTargetCygMing())
00175     DecorateCygMingName(CurrentFnName, F);
00176 
00177   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
00178   EmitAlignment(FnAlign, F);
00179 
00180   switch (F->getLinkage()) {
00181   default: llvm_unreachable("Unknown linkage type!");
00182   case Function::InternalLinkage:  // Symbols default to internal.
00183   case Function::PrivateLinkage:
00184     break;
00185   case Function::DLLExportLinkage:
00186   case Function::ExternalLinkage:
00187     O << "\t.globl\t" << CurrentFnName << '\n';
00188     break;
00189   case Function::LinkerPrivateLinkage:
00190   case Function::LinkOnceAnyLinkage:
00191   case Function::LinkOnceODRLinkage:
00192   case Function::WeakAnyLinkage:
00193   case Function::WeakODRLinkage:
00194     if (Subtarget->isTargetDarwin()) {
00195       O << "\t.globl\t" << CurrentFnName << '\n';
00196       O << TAI->getWeakDefDirective() << CurrentFnName << '\n';
00197     } else if (Subtarget->isTargetCygMing()) {
00198       O << "\t.globl\t" << CurrentFnName << "\n"
00199            "\t.linkonce discard\n";
00200     } else {
00201       O << "\t.weak\t" << CurrentFnName << '\n';
00202     }
00203     break;
00204   }
00205 
00206   printVisibility(CurrentFnName, F->getVisibility());
00207 
00208   if (Subtarget->isTargetELF())
00209     O << "\t.type\t" << CurrentFnName << ",@function\n";
00210   else if (Subtarget->isTargetCygMing()) {
00211     O << "\t.def\t " << CurrentFnName
00212       << ";\t.scl\t" <<
00213       (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
00214       << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
00215       << ";\t.endef\n";
00216   }
00217 
00218   O << CurrentFnName << ':';
00219   if (VerboseAsm) {
00220     O.PadToColumn(TAI->getCommentColumn());
00221     O << TAI->getCommentString() << ' ';
00222     WriteAsOperand(O, F, /*PrintType=*/false, F->getParent());
00223   }
00224   O << '\n';
00225 
00226   // Add some workaround for linkonce linkage on Cygwin\MinGW
00227   if (Subtarget->isTargetCygMing() &&
00228       (F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
00229     O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
00230 }
00231 
00232 /// runOnMachineFunction - This uses the printMachineInstruction()
00233 /// method to print assembly for each instruction.
00234 ///
00235 bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
00236   const Function *F = MF.getFunction();
00237   this->MF = &MF;
00238   unsigned CC = F->getCallingConv();
00239 
00240   SetupMachineFunction(MF);
00241   O << "\n\n";
00242 
00243   // Populate function information map.  Actually, We don't want to populate
00244   // non-stdcall or non-fastcall functions' information right now.
00245   if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
00246     FunctionInfoMap[F] = *MF.getInfo<X86MachineFunctionInfo>();
00247 
00248   // Print out constants referenced by the function
00249   EmitConstantPool(MF.getConstantPool());
00250 
00251   if (F->hasDLLExportLinkage())
00252     DLLExportedFns.insert(Mang->getMangledName(F));
00253 
00254   // Print the 'header' of function
00255   emitFunctionHeader(MF);
00256 
00257   // Emit pre-function debug and/or EH information.
00258   if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
00259     DW->BeginFunction(&MF);
00260 
00261   // Print out code for the function.
00262   bool hasAnyRealCode = false;
00263   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
00264        I != E; ++I) {
00265     // Print a label for the basic block.
00266     if (!VerboseAsm && (I->pred_empty() || I->isOnlyReachableByFallthrough())) {
00267       // This is an entry block or a block that's only reachable via a
00268       // fallthrough edge. In non-VerboseAsm mode, don't print the label.
00269     } else {
00270       printBasicBlockLabel(I, true, true, VerboseAsm);
00271       O << '\n';
00272     }
00273     for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
00274          II != IE; ++II) {
00275       // Print the assembly for the instruction.
00276       if (!II->isLabel())
00277         hasAnyRealCode = true;
00278       printMachineInstruction(II);
00279     }
00280   }
00281 
00282   if (Subtarget->isTargetDarwin() && !hasAnyRealCode) {
00283     // If the function is empty, then we need to emit *something*. Otherwise,
00284     // the function's label might be associated with something that it wasn't
00285     // meant to be associated with. We emit a noop in this situation.
00286     // We are assuming inline asms are code.
00287     O << "\tnop\n";
00288   }
00289 
00290   if (TAI->hasDotTypeDotSizeDirective())
00291     O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
00292 
00293   // Emit post-function debug information.
00294   if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
00295     DW->EndFunction(&MF);
00296 
00297   // Print out jump tables referenced by the function.
00298   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
00299 
00300   // We didn't modify anything.
00301   return false;
00302 }
00303 
00304 /// printSymbolOperand - Print a raw symbol reference operand.  This handles
00305 /// jump tables, constant pools, global address and external symbols, all of
00306 /// which print to a label with various suffixes for relocation types etc.
00307 void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
00308   switch (MO.getType()) {
00309   default: llvm_unreachable("unknown symbol type!");
00310   case MachineOperand::MO_JumpTableIndex:
00311     O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
00312       << MO.getIndex();
00313     break;
00314   case MachineOperand::MO_ConstantPoolIndex:
00315     O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
00316       << MO.getIndex();
00317     printOffset(MO.getOffset());
00318     break;
00319   case MachineOperand::MO_GlobalAddress: {
00320     const GlobalValue *GV = MO.getGlobal();
00321     
00322     const char *Suffix = "";
00323     if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
00324       Suffix = "$stub";
00325     else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
00326              MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
00327              MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
00328              MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
00329       Suffix = "$non_lazy_ptr";
00330     
00331     std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
00332     if (Subtarget->isTargetCygMing())
00333       DecorateCygMingName(Name, GV);
00334     
00335     // Handle dllimport linkage.
00336     if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
00337       Name = "__imp_" + Name;
00338     
00339     if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
00340         MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
00341       GVStubs[Name] = Mang->getMangledName(GV);
00342     else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
00343              MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
00344       HiddenGVStubs[Name] = Mang->getMangledName(GV);
00345     else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
00346       FnStubs[Name] = Mang->getMangledName(GV);
00347     
00348     // If the name begins with a dollar-sign, enclose it in parens.  We do this
00349     // to avoid having it look like an integer immediate to the assembler.
00350     if (Name[0] == '$') 
00351       O << '(' << Name << ')';
00352     else
00353       O << Name;
00354     
00355     printOffset(MO.getOffset());
00356     break;
00357   }
00358   case MachineOperand::MO_ExternalSymbol: {
00359     std::string Name = Mang->makeNameProper(MO.getSymbolName());
00360     if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
00361       FnStubs[Name+"$stub"] = Name;
00362       Name += "$stub";
00363     }
00364     
00365     // If the name begins with a dollar-sign, enclose it in parens.  We do this
00366     // to avoid having it look like an integer immediate to the assembler.
00367     if (Name[0] == '$') 
00368       O << '(' << Name << ')';
00369     else
00370       O << Name;
00371     break;
00372   }
00373   }
00374   
00375   switch (MO.getTargetFlags()) {
00376   default:
00377     llvm_unreachable("Unknown target flag on GV operand");
00378   case X86II::MO_NO_FLAG:    // No flag.
00379     break;
00380   case X86II::MO_DARWIN_NONLAZY:
00381   case X86II::MO_DARWIN_HIDDEN_NONLAZY:
00382   case X86II::MO_DLLIMPORT:
00383   case X86II::MO_DARWIN_STUB:
00384     // These affect the name of the symbol, not any suffix.
00385     break;
00386   case X86II::MO_GOT_ABSOLUTE_ADDRESS:
00387     O << " + [.-";
00388     PrintPICBaseSymbol();
00389     O << ']';
00390     break;      
00391   case X86II::MO_PIC_BASE_OFFSET:
00392   case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
00393   case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
00394     O << '-';
00395     PrintPICBaseSymbol();
00396     break;
00397   case X86II::MO_TLSGD:     O << "@TLSGD";     break;
00398   case X86II::MO_GOTTPOFF:  O << "@GOTTPOFF";  break;
00399   case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
00400   case X86II::MO_TPOFF:     O << "@TPOFF";     break;
00401   case X86II::MO_NTPOFF:    O << "@NTPOFF";    break;
00402   case X86II::MO_GOTPCREL:  O << "@GOTPCREL";  break;
00403   case X86II::MO_GOT:       O << "@GOT";       break;
00404   case X86II::MO_GOTOFF:    O << "@GOTOFF";    break;
00405   case X86II::MO_PLT:       O << "@PLT";       break;
00406   }
00407 }
00408 
00409 /// print_pcrel_imm - This is used to print an immediate value that ends up
00410 /// being encoded as a pc-relative value.  These print slightly differently, for
00411 /// example, a $ is not emitted.
00412 void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
00413   const MachineOperand &MO = MI->getOperand(OpNo);
00414   switch (MO.getType()) {
00415   default: llvm_unreachable("Unknown pcrel immediate operand");
00416   case MachineOperand::MO_Immediate:
00417     O << MO.getImm();
00418     return;
00419   case MachineOperand::MO_MachineBasicBlock:
00420     printBasicBlockLabel(MO.getMBB(), false, false, false);
00421     return;
00422   case MachineOperand::MO_GlobalAddress:
00423   case MachineOperand::MO_ExternalSymbol:
00424     printSymbolOperand(MO);
00425     return;
00426   }
00427 }
00428 
00429 
00430 
00431 void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
00432                                     const char *Modifier) {
00433   const MachineOperand &MO = MI->getOperand(OpNo);
00434   switch (MO.getType()) {
00435   default: llvm_unreachable("unknown operand type!");
00436   case MachineOperand::MO_Register: {
00437     assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
00438            "Virtual registers should not make it this far!");
00439     O << '%';
00440     unsigned Reg = MO.getReg();
00441     if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
00442       EVT VT = (strcmp(Modifier+6,"64") == 0) ?
00443         MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
00444                     ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
00445       Reg = getX86SubSuperRegister(Reg, VT);
00446     }
00447     O << TRI->getAsmName(Reg);
00448     return;
00449   }
00450 
00451   case MachineOperand::MO_Immediate:
00452     O << '$' << MO.getImm();
00453     return;
00454 
00455   case MachineOperand::MO_JumpTableIndex:
00456   case MachineOperand::MO_ConstantPoolIndex:
00457   case MachineOperand::MO_GlobalAddress: 
00458   case MachineOperand::MO_ExternalSymbol: {
00459     O << '$';
00460     printSymbolOperand(MO);
00461     break;
00462   }
00463   }
00464 }
00465 
00466 void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
00467   unsigned char value = MI->getOperand(Op).getImm();
00468   assert(value <= 7 && "Invalid ssecc argument!");
00469   switch (value) {
00470   case 0: O << "eq"; break;
00471   case 1: O << "lt"; break;
00472   case 2: O << "le"; break;
00473   case 3: O << "unord"; break;
00474   case 4: O << "neq"; break;
00475   case 5: O << "nlt"; break;
00476   case 6: O << "nle"; break;
00477   case 7: O << "ord"; break;
00478   }
00479 }
00480 
00481 void X86ATTAsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
00482                                             const char *Modifier) {
00483   const MachineOperand &BaseReg  = MI->getOperand(Op);
00484   const MachineOperand &IndexReg = MI->getOperand(Op+2);
00485   const MachineOperand &DispSpec = MI->getOperand(Op+3);
00486 
00487   // If we really don't want to print out (rip), don't.
00488   bool HasBaseReg = BaseReg.getReg() != 0;
00489   if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
00490       BaseReg.getReg() == X86::RIP)
00491     HasBaseReg = false;
00492   
00493   // HasParenPart - True if we will print out the () part of the mem ref.
00494   bool HasParenPart = IndexReg.getReg() || HasBaseReg;
00495   
00496   if (DispSpec.isImm()) {
00497     int DispVal = DispSpec.getImm();
00498     if (DispVal || !HasParenPart)
00499       O << DispVal;
00500   } else {
00501     assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
00502            DispSpec.isJTI() || DispSpec.isSymbol());
00503     printSymbolOperand(MI->getOperand(Op+3));
00504   }
00505 
00506   if (HasParenPart) {
00507     assert(IndexReg.getReg() != X86::ESP &&
00508            "X86 doesn't allow scaling by ESP");
00509 
00510     O << '(';
00511     if (HasBaseReg)
00512       printOperand(MI, Op, Modifier);
00513 
00514     if (IndexReg.getReg()) {
00515       O << ',';
00516       printOperand(MI, Op+2, Modifier);
00517       unsigned ScaleVal = MI->getOperand(Op+1).getImm();
00518       if (ScaleVal != 1)
00519         O << ',' << ScaleVal;
00520     }
00521     O << ')';
00522   }
00523 }
00524 
00525 void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
00526                                          const char *Modifier) {
00527   assert(isMem(MI, Op) && "Invalid memory reference!");
00528   const MachineOperand &Segment = MI->getOperand(Op+4);
00529   if (Segment.getReg()) {
00530     printOperand(MI, Op+4, Modifier);
00531     O << ':';
00532   }
00533   printLeaMemReference(MI, Op, Modifier);
00534 }
00535 
00536 void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
00537                                            const MachineBasicBlock *MBB) const {
00538   if (!TAI->getSetDirective())
00539     return;
00540 
00541   // We don't need .set machinery if we have GOT-style relocations
00542   if (Subtarget->isPICStyleGOT())
00543     return;
00544 
00545   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
00546     << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
00547   printBasicBlockLabel(MBB, false, false, false);
00548   if (Subtarget->isPICStyleRIPRel())
00549     O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
00550       << '_' << uid << '\n';
00551   else {
00552     O << '-';
00553     PrintPICBaseSymbol();
00554     O << '\n';
00555   }
00556 }
00557 
00558 
00559 void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
00560   PrintPICBaseSymbol();
00561   O << '\n';
00562   PrintPICBaseSymbol();
00563   O << ':';
00564 }
00565 
00566 
00567 void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
00568                                               const MachineBasicBlock *MBB,
00569                                               unsigned uid) const {
00570   const char *JTEntryDirective = MJTI->getEntrySize() == 4 ?
00571     TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
00572 
00573   O << JTEntryDirective << ' ';
00574 
00575   if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStubPIC()) {
00576     O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
00577       << '_' << uid << "_set_" << MBB->getNumber();
00578   } else if (Subtarget->isPICStyleGOT()) {
00579     printBasicBlockLabel(MBB, false, false, false);
00580     O << "@GOTOFF";
00581   } else
00582     printBasicBlockLabel(MBB, false, false, false);
00583 }
00584 
00585 bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode) {
00586   unsigned Reg = MO.getReg();
00587   switch (Mode) {
00588   default: return true;  // Unknown mode.
00589   case 'b': // Print QImode register
00590     Reg = getX86SubSuperRegister(Reg, MVT::i8);
00591     break;
00592   case 'h': // Print QImode high register
00593     Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
00594     break;
00595   case 'w': // Print HImode register
00596     Reg = getX86SubSuperRegister(Reg, MVT::i16);
00597     break;
00598   case 'k': // Print SImode register
00599     Reg = getX86SubSuperRegister(Reg, MVT::i32);
00600     break;
00601   case 'q': // Print DImode register
00602     Reg = getX86SubSuperRegister(Reg, MVT::i64);
00603     break;
00604   }
00605 
00606   O << '%'<< TRI->getAsmName(Reg);
00607   return false;
00608 }
00609 
00610 /// PrintAsmOperand - Print out an operand for an inline asm expression.
00611 ///
00612 bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
00613                                        unsigned AsmVariant,
00614                                        const char *ExtraCode) {
00615   // Does this asm operand have a single letter operand modifier?
00616   if (ExtraCode && ExtraCode[0]) {
00617     if (ExtraCode[1] != 0) return true; // Unknown modifier.
00618 
00619     const MachineOperand &MO = MI->getOperand(OpNo);
00620     
00621     switch (ExtraCode[0]) {
00622     default: return true;  // Unknown modifier.
00623     case 'a': // This is an address.  Currently only 'i' and 'r' are expected.
00624       if (MO.isImm()) {
00625         O << MO.getImm();
00626         return false;
00627       } 
00628       if (MO.isReg()) {
00629         O << '(';
00630         printOperand(MI, OpNo);
00631         O << ')';
00632         return false;
00633       }
00634       return true;
00635 
00636     case 'c': // Don't print "$" before a global var name or constant.
00637       if (MO.isImm())
00638         O << MO.getImm();
00639       else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
00640         printSymbolOperand(MO);
00641       else
00642         printOperand(MI, OpNo);
00643       return false;
00644 
00645     case 'A': // Print '*' before a register (it must be a register)
00646       if (MO.isReg()) {
00647         O << '*';
00648         printOperand(MI, OpNo);
00649         return false;
00650       }
00651       return true;
00652 
00653     case 'b': // Print QImode register
00654     case 'h': // Print QImode high register
00655     case 'w': // Print HImode register
00656     case 'k': // Print SImode register
00657     case 'q': // Print DImode register
00658       if (MO.isReg())
00659         return printAsmMRegister(MO, ExtraCode[0]);
00660       printOperand(MI, OpNo);
00661       return false;
00662 
00663     case 'P': // This is the operand of a call, treat specially.
00664       print_pcrel_imm(MI, OpNo);
00665       return false;
00666 
00667     case 'n':  // Negate the immediate or print a '-' before the operand.
00668       // Note: this is a temporary solution. It should be handled target
00669       // independently as part of the 'MC' work.
00670       if (MO.isImm()) {
00671         O << -MO.getImm();
00672         return false;
00673       }
00674       O << '-';
00675     }
00676   }
00677 
00678   printOperand(MI, OpNo);
00679   return false;
00680 }
00681 
00682 bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
00683                                              unsigned OpNo,
00684                                              unsigned AsmVariant,
00685                                              const char *ExtraCode) {
00686   if (ExtraCode && ExtraCode[0]) {
00687     if (ExtraCode[1] != 0) return true; // Unknown modifier.
00688 
00689     switch (ExtraCode[0]) {
00690     default: return true;  // Unknown modifier.
00691     case 'b': // Print QImode register
00692     case 'h': // Print QImode high register
00693     case 'w': // Print HImode register
00694     case 'k': // Print SImode register
00695     case 'q': // Print SImode register
00696       // These only apply to registers, ignore on mem.
00697       break;
00698     case 'P': // Don't print @PLT, but do print as memory.
00699       printMemReference(MI, OpNo, "no-rip");
00700       return false;
00701     }
00702   }
00703   printMemReference(MI, OpNo);
00704   return false;
00705 }
00706 
00707 static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
00708   // Convert registers in the addr mode according to subreg64.
00709   for (unsigned i = 0; i != 4; ++i) {
00710     if (!MI->getOperand(i).isReg()) continue;
00711     
00712     unsigned Reg = MI->getOperand(i).getReg();
00713     if (Reg == 0) continue;
00714     
00715     MI->getOperand(i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
00716   }
00717 }
00718 
00719 /// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
00720 /// MCOperand.
00721 MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
00722   const GlobalValue *GV = MO.getGlobal();
00723   
00724   const char *Suffix = "";
00725   if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
00726     Suffix = "$stub";
00727   else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
00728            MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
00729            MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
00730            MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
00731     Suffix = "$non_lazy_ptr";
00732   
00733   std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
00734   if (Subtarget->isTargetCygMing())
00735     DecorateCygMingName(Name, GV);
00736   
00737   // Handle dllimport linkage.
00738   if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
00739     Name = "__imp_" + Name;
00740   
00741   if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
00742       MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
00743     GVStubs[Name] = Mang->getMangledName(GV);
00744   else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
00745            MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
00746     HiddenGVStubs[Name] = Mang->getMangledName(GV);
00747   else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
00748     FnStubs[Name] = Mang->getMangledName(GV);
00749   
00750   
00751   // Handle target operand flags.
00752   // FIXME: This should be common between external symbols, constant pool etc.
00753   MCSymbol *NegatedSymbol = 0;
00754   
00755   switch (MO.getTargetFlags()) {
00756   default:
00757     llvm_unreachable("Unknown target flag on GV operand");
00758   case X86II::MO_NO_FLAG:    // No flag.
00759     break;
00760   case X86II::MO_DARWIN_NONLAZY:
00761   case X86II::MO_DARWIN_HIDDEN_NONLAZY:
00762   case X86II::MO_DLLIMPORT:
00763   case X86II::MO_DARWIN_STUB:
00764     // These affect the name of the symbol, not any suffix.
00765     break;
00766   case X86II::MO_GOT_ABSOLUTE_ADDRESS:
00767     assert(0 && "Reloc mode unimp!");
00768     //O << " + [.-";
00769     //PrintPICBaseSymbol();
00770     //O << ']';
00771     break;      
00772   case X86II::MO_PIC_BASE_OFFSET:
00773   case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
00774   case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
00775     // Subtract the pic base.
00776     NegatedSymbol = GetPICBaseSymbol();
00777     break;
00778       
00779   // FIXME: These probably should be a modifier on the symbol or something??
00780   case X86II::MO_TLSGD:     Name += "@TLSGD";     break;
00781   case X86II::MO_GOTTPOFF:  Name += "@GOTTPOFF";  break;
00782   case X86II::MO_INDNTPOFF: Name += "@INDNTPOFF"; break;
00783   case X86II::MO_TPOFF:     Name += "@TPOFF";     break;
00784   case X86II::MO_NTPOFF:    Name += "@NTPOFF";    break;
00785   case X86II::MO_GOTPCREL:  Name += "@GOTPCREL";  break;
00786   case X86II::MO_GOT:       Name += "@GOT";       break;
00787   case X86II::MO_GOTOFF:    Name += "@GOTOFF";    break;
00788   case X86II::MO_PLT:       Name += "@PLT";       break;
00789   }
00790   
00791   // Create a symbol for the name.
00792   MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
00793   return MCOperand::CreateMCValue(MCValue::get(Sym, NegatedSymbol,
00794                                                MO.getOffset()));
00795 }
00796 
00797 MCOperand X86ATTAsmPrinter::
00798 LowerExternalSymbolOperand(const MachineOperand &MO){
00799   std::string Name = Mang->makeNameProper(MO.getSymbolName());
00800   if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
00801     FnStubs[Name+"$stub"] = Name;
00802     Name += "$stub";
00803   }
00804 
00805   MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
00806   return MCOperand::CreateMCValue(MCValue::get(Sym, 0, MO.getOffset()));
00807 }
00808 
00809 
00810 /// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
00811 /// AT&T syntax to the current output stream.
00812 ///
00813 void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
00814   ++EmittedInsts;
00815 
00816   if (!NewAsmPrinter) {
00817     // Call the autogenerated instruction printer routines.
00818     printInstruction(MI);
00819     return;
00820   }
00821   
00822   MCInst TmpInst;
00823 
00824   switch (MI->getOpcode()) {
00825   case TargetInstrInfo::DBG_LABEL:
00826   case TargetInstrInfo::EH_LABEL:
00827   case TargetInstrInfo::GC_LABEL:
00828     printLabel(MI);
00829     return;
00830   case TargetInstrInfo::INLINEASM:
00831     O << '\t';
00832     printInlineAsm(MI);
00833     return;
00834   case TargetInstrInfo::DECLARE:
00835     printDeclare(MI);
00836     return;
00837   case TargetInstrInfo::IMPLICIT_DEF:
00838     printImplicitDef(MI);
00839     return;
00840   case X86::MOVPC32r: {
00841     // This is a pseudo op for a two instruction sequence with a label, which
00842     // looks like:
00843     //     call "L1$pb"
00844     // "L1$pb":
00845     //     popl %esi
00846     
00847     // Emit the call.
00848     MCSymbol *PICBase = GetPICBaseSymbol();
00849     TmpInst.setOpcode(X86::CALLpcrel32);
00850     TmpInst.addOperand(MCOperand::CreateMCValue(MCValue::get(PICBase)));
00851     printInstruction(&TmpInst);
00852 
00853     // Emit the label.
00854     OutStreamer.EmitLabel(PICBase);
00855     
00856     // popl $reg
00857     TmpInst.setOpcode(X86::POP32r);
00858     TmpInst.getOperand(0) = MCOperand::CreateReg(MI->getOperand(0).getReg());
00859     printInstruction(&TmpInst);
00860     O << "OLD: ";
00861     // Call the autogenerated instruction printer routines.
00862     printInstruction(MI);
00863     return;
00864   }
00865   }
00866   
00867   O << "NEW: ";
00868   
00869   TmpInst.setOpcode(MI->getOpcode());
00870   
00871   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
00872     const MachineOperand &MO = MI->getOperand(i);
00873     
00874     MCOperand MCOp;
00875     switch (MO.getType()) {
00876     default:
00877       O.flush();
00878       errs() << "Cannot lower operand #" << i << " of :" << *MI;
00879       llvm_unreachable("Unimp");
00880     case MachineOperand::MO_Register:
00881       MCOp = MCOperand::CreateReg(MO.getReg());
00882       break;
00883     case MachineOperand::MO_Immediate:
00884       MCOp = MCOperand::CreateImm(MO.getImm());
00885       break;
00886     case MachineOperand::MO_MachineBasicBlock:
00887       MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(), 
00888                                        MO.getMBB()->getNumber());
00889       break;
00890     case MachineOperand::MO_GlobalAddress:
00891       MCOp = LowerGlobalAddressOperand(MO);
00892       break;
00893     case MachineOperand::MO_ExternalSymbol:
00894       MCOp = LowerExternalSymbolOperand(MO);
00895       break;
00896     }
00897     
00898     TmpInst.addOperand(MCOp);
00899   }
00900   
00901   switch (TmpInst.getOpcode()) {
00902   case X86::LEA64_32r:
00903     // Handle the 'subreg rewriting' for the lea64_32mem operand.
00904     lower_lea64_32mem(&TmpInst, 1);
00905     break;
00906   }
00907   
00908   // FIXME: Convert TmpInst.
00909   printInstruction(&TmpInst);
00910   O << "OLD: ";
00911   
00912   // Call the autogenerated instruction printer routines.
00913   printInstruction(MI);
00914 }
00915 
00916 void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
00917   const TargetData *TD = TM.getTargetData();
00918 
00919   if (!GVar->hasInitializer())
00920     return;   // External global require no code
00921 
00922   // Check to see if this is a special global used by LLVM, if so, emit it.
00923   if (EmitSpecialLLVMGlobal(GVar)) {
00924     if (Subtarget->isTargetDarwin() &&
00925         TM.getRelocationModel() == Reloc::Static) {
00926       if (GVar->getName() == "llvm.global_ctors")
00927         O << ".reference .constructors_used\n";
00928       else if (GVar->getName() == "llvm.global_dtors")
00929         O << ".reference .destructors_used\n";
00930     }
00931     return;
00932   }
00933 
00934   std::string name = Mang->getMangledName(GVar);
00935   Constant *C = GVar->getInitializer();
00936   const Type *Type = C->getType();
00937   unsigned Size = TD->getTypeAllocSize(Type);
00938   unsigned Align = TD->getPreferredAlignmentLog(GVar);
00939 
00940   printVisibility(name, GVar->getVisibility());
00941 
00942   if (Subtarget->isTargetELF())
00943     O << "\t.type\t" << name << ",@object\n";
00944 
00945   
00946   SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
00947   const MCSection *TheSection =
00948     getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
00949   OutStreamer.SwitchSection(TheSection);
00950 
00951   // FIXME: get this stuff from section kind flags.
00952   if (C->isNullValue() && !GVar->hasSection() &&
00953       // Don't put things that should go in the cstring section into "comm".
00954       !TheSection->getKind().isMergeableCString()) {
00955     if (GVar->hasExternalLinkage()) {
00956       if (const char *Directive = TAI->getZeroFillDirective()) {
00957         O << "\t.globl " << name << '\n';
00958         O << Directive << "__DATA, __common, " << name << ", "
00959           << Size << ", " << Align << '\n';
00960         return;
00961       }
00962     }
00963 
00964     if (!GVar->isThreadLocal() &&
00965         (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
00966       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
00967 
00968       if (TAI->getLCOMMDirective() != NULL) {
00969         if (GVar->hasLocalLinkage()) {
00970           O << TAI->getLCOMMDirective() << name << ',' << Size;
00971           if (Subtarget->isTargetDarwin())
00972             O << ',' << Align;
00973         } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
00974           O << "\t.globl " << name << '\n'
00975             << TAI->getWeakDefDirective() << name << '\n';
00976           EmitAlignment(Align, GVar);
00977           O << name << ":";
00978           if (VerboseAsm) {
00979             O.PadToColumn(TAI->getCommentColumn());
00980             O << TAI->getCommentString() << ' ';
00981             WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
00982           }
00983           O << '\n';
00984           EmitGlobalConstant(C);
00985           return;
00986         } else {
00987           O << TAI->getCOMMDirective()  << name << ',' << Size;
00988           if (TAI->getCOMMDirectiveTakesAlignment())
00989             O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
00990         }
00991       } else {
00992         if (!Subtarget->isTargetCygMing()) {
00993           if (GVar->hasLocalLinkage())
00994             O << "\t.local\t" << name << '\n';
00995         }
00996         O << TAI->getCOMMDirective()  << name << ',' << Size;
00997         if (TAI->getCOMMDirectiveTakesAlignment())
00998           O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
00999       }
01000       if (VerboseAsm) {
01001         O.PadToColumn(TAI->getCommentColumn());
01002         O << TAI->getCommentString() << ' ';
01003         WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
01004       }
01005       O << '\n';
01006       return;
01007     }
01008   }
01009 
01010   switch (GVar->getLinkage()) {
01011   case GlobalValue::CommonLinkage:
01012   case GlobalValue::LinkOnceAnyLinkage:
01013   case GlobalValue::LinkOnceODRLinkage:
01014   case GlobalValue::WeakAnyLinkage:
01015   case GlobalValue::WeakODRLinkage:
01016   case GlobalValue::LinkerPrivateLinkage:
01017     if (Subtarget->isTargetDarwin()) {
01018       O << "\t.globl " << name << '\n'
01019         << TAI->getWeakDefDirective() << name << '\n';
01020     } else if (Subtarget->isTargetCygMing()) {
01021       O << "\t.globl\t" << name << "\n"
01022            "\t.linkonce same_size\n";
01023     } else {
01024       O << "\t.weak\t" << name << '\n';
01025     }
01026     break;
01027   case GlobalValue::DLLExportLinkage:
01028   case GlobalValue::AppendingLinkage:
01029     // FIXME: appending linkage variables should go into a section of
01030     // their name or something.  For now, just emit them as external.
01031   case GlobalValue::ExternalLinkage:
01032     // If external or appending, declare as a global symbol
01033     O << "\t.globl " << name << '\n';
01034     // FALL THROUGH
01035   case GlobalValue::PrivateLinkage:
01036   case GlobalValue::InternalLinkage:
01037      break;
01038   default:
01039     llvm_unreachable("Unknown linkage type!");
01040   }
01041 
01042   EmitAlignment(Align, GVar);
01043   O << name << ":";
01044   if (VerboseAsm){
01045     O.PadToColumn(TAI->getCommentColumn());
01046     O << TAI->getCommentString() << ' ';
01047     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
01048   }
01049   O << '\n';
01050 
01051   EmitGlobalConstant(C);
01052 
01053   if (TAI->hasDotTypeDotSizeDirective())
01054     O << "\t.size\t" << name << ", " << Size << '\n';
01055 }
01056 
01057 bool X86ATTAsmPrinter::doFinalization(Module &M) {
01058   // Print out module-level global variables here.
01059   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
01060        I != E; ++I) {
01061     if (I->hasDLLExportLinkage())
01062       DLLExportedGVs.insert(Mang->getMangledName(I));
01063   }
01064 
01065   if (Subtarget->isTargetDarwin()) {
01066     // All darwin targets use mach-o.
01067     TargetLoweringObjectFileMachO &TLOFMacho = 
01068       static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
01069     
01070     // Add the (possibly multiple) personalities to the set of global value
01071     // stubs.  Only referenced functions get into the Personalities list.
01072     if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
01073       const std::vector<Function*> &Personalities = MMI->getPersonalities();
01074       for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
01075         if (Personalities[i])
01076           GVStubs[Mang->getMangledName(Personalities[i], "$non_lazy_ptr",
01077                                        true /*private label*/)] = 
01078             Mang->getMangledName(Personalities[i]);
01079       }
01080     }
01081 
01082     // Output stubs for dynamically-linked functions
01083     if (!FnStubs.empty()) {
01084       const MCSection *TheSection = 
01085         TLOFMacho.getMachOSection("__IMPORT", "__jump_table",
01086                                   MCSectionMachO::S_SYMBOL_STUBS |
01087                                   MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
01088                                   MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
01089                                   5, SectionKind::getMetadata());
01090       OutStreamer.SwitchSection(TheSection);
01091       for (StringMap<std::string>::iterator I = FnStubs.begin(),
01092            E = FnStubs.end(); I != E; ++I)
01093         O << I->getKeyData() << ":\n" << "\t.indirect_symbol " << I->second
01094           << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
01095       O << '\n';
01096     }
01097 
01098     // Output stubs for external and common global variables.
01099     if (!GVStubs.empty()) {
01100       const MCSection *TheSection = 
01101         TLOFMacho.getMachOSection("__IMPORT", "__pointers",
01102                                   MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
01103                                   SectionKind::getMetadata());
01104       OutStreamer.SwitchSection(TheSection);
01105       for (StringMap<std::string>::iterator I = GVStubs.begin(),
01106            E = GVStubs.end(); I != E; ++I)
01107         O << I->getKeyData() << ":\n\t.indirect_symbol "
01108           << I->second << "\n\t.long\t0\n";
01109     }
01110 
01111     if (!HiddenGVStubs.empty()) {
01112       OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
01113       EmitAlignment(2);
01114       for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
01115            E = HiddenGVStubs.end(); I != E; ++I)
01116         O << I->getKeyData() << ":\n" << TAI->getData32bitsDirective()
01117           << I->second << '\n';
01118     }
01119 
01120     // Funny Darwin hack: This flag tells the linker that no global symbols
01121     // contain code that falls through to other global symbols (e.g. the obvious
01122     // implementation of multiple entry points).  If this doesn't occur, the
01123     // linker can safely perform dead code stripping.  Since LLVM never
01124     // generates code that does this, it is always safe to set.
01125     O << "\t.subsections_via_symbols\n";
01126   } else if (Subtarget->isTargetCygMing()) {
01127     // Emit type information for external functions
01128     for (StringSet<>::iterator i = CygMingStubs.begin(), e = CygMingStubs.end();
01129          i != e; ++i) {
01130       O << "\t.def\t " << i->getKeyData()
01131         << ";\t.scl\t" << COFF::C_EXT
01132         << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
01133         << ";\t.endef\n";
01134     }
01135   }
01136   
01137   
01138   // Output linker support code for dllexported globals on windows.
01139   if (!DLLExportedGVs.empty() || !DLLExportedFns.empty()) {
01140     // dllexport symbols only exist on coff targets.
01141     TargetLoweringObjectFileCOFF &TLOFMacho = 
01142       static_cast<TargetLoweringObjectFileCOFF&>(getObjFileLowering());
01143     
01144     OutStreamer.SwitchSection(TLOFMacho.getCOFFSection(".section .drectve",true,
01145                                                  SectionKind::getMetadata()));
01146   
01147     for (StringSet<>::iterator i = DLLExportedGVs.begin(),
01148          e = DLLExportedGVs.end(); i != e; ++i)
01149       O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
01150   
01151     for (StringSet<>::iterator i = DLLExportedFns.begin(),
01152          e = DLLExportedFns.end();
01153          i != e; ++i)
01154       O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
01155   }
01156   
01157   // Do common shutdown.
01158   return AsmPrinter::doFinalization(M);
01159 }
01160 
01161 // Include the auto-generated portion of the assembly writer.
01162 #include "X86GenAsmWriter.inc"