X86AsmPrinter.cpp revision 142b531e024c7b814df74951b378b9e3e11d0d42
10dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
20e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
3b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//                     The LLVM Compiler Infrastructure
4b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
70e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
8b576c94c15af9a440f69d9d03c2afead7971118cJohn Criswell//===----------------------------------------------------------------------===//
9726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//
100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// This file contains a printer that converts from our internal representation
1114c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner// of machine-dependent LLVM code to X86 machine code.
12726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//
13726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//===----------------------------------------------------------------------===//
14726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86AsmPrinter.h"
167ac1609a3b81504d269bf967060241c309771f23Jim Grosbach#include "InstPrinter/X86ATTInstPrinter.h"
177ac1609a3b81504d269bf967060241c309771f23Jim Grosbach#include "InstPrinter/X86IntelInstPrinter.h"
180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86MCInstLower.h"
190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86.h"
200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86COFFMachineModuleInfo.h"
210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86MachineFunctionInfo.h"
220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86TargetMachine.h"
230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CallingConv.h"
240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/DerivedTypes.h"
250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Module.h"
260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Type.h"
271a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner#include "llvm/Analysis/DebugInfo.h"
280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Assembly/Writer.h"
29becd83e3f4eb996f8e43189ce482267b3b8351a8Bill Wendling#include "llvm/MC/MCAsmInfo.h"
300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCContext.h"
31beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner#include "llvm/MC/MCExpr.h"
320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCSectionMachO.h"
330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCStreamer.h"
340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCSymbol.h"
350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CodeGen/MachineJumpTableInfo.h"
360dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CodeGen/MachineModuleInfoImpls.h"
37362dd0bef5437f85586c046bc53287b6fbe9c099Anton Korobeynikov#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
389fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner#include "llvm/Support/COFF.h"
395c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel#include "llvm/Support/Debug.h"
400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Support/ErrorHandling.h"
414dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov#include "llvm/Target/Mangler.h"
420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Target/TargetOptions.h"
430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Target/TargetRegistry.h"
440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/ADT/SmallString.h"
450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerusing namespace llvm;
460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===//
480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Primitive Helper Functions.
490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===//
500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5114c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner/// runOnMachineFunction - Emit the function body.
520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner///
530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  SetupMachineFunction(MF);
550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
564dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov  if (Subtarget->isTargetCOFF()) {
57b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    bool Intrn = MF.getFunction()->hasInternalLinkage();
58b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
5922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach    OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC
609fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner                                              : COFF::IMAGE_SYM_CLASS_EXTERNAL);
619fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner    OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION
629fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner                                               << COFF::SCT_COMPLEX_TYPE_SHIFT);
63b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    OutStreamer.EndCOFFSymbolDef();
64b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner  }
654dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov
66b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner  // Have common code print out the function header with linkage info etc.
67b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner  EmitFunctionHeader();
684dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov
6914c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner  // Emit the rest of the function body.
7014c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner  EmitFunctionBody();
710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  // We didn't modify anything.
730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  return false;
740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// printSymbolOperand - Print a raw symbol reference operand.  This handles
770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// jump tables, constant pools, global address and external symbols, all of
780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// which print to a label with various suffixes for relocation types etc.
7988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printSymbolOperand(const MachineOperand &MO,
8088db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                       raw_ostream &O) {
810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (MO.getType()) {
820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  default: llvm_unreachable("unknown symbol type!");
830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_JumpTableIndex:
8464c2b244982046373c853e988b7395fdf0166cd8Chris Lattner    O << *GetJTISymbol(MO.getIndex());
850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_ConstantPoolIndex:
8764c2b244982046373c853e988b7395fdf0166cd8Chris Lattner    O << *GetCPISymbol(MO.getIndex());
880c08d092049c025c9ccf7143e39f39dc4e30d6b4Chris Lattner    printOffset(MO.getOffset(), O);
890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_GlobalAddress: {
910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    const GlobalValue *GV = MO.getGlobal();
9222854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
935957c84e09b177aecf8b430c33fd75a36575fb57Chris Lattner    MCSymbol *GVSym;
940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
957a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner      GVSym = GetSymbolWithGlobalValueBase(GV, "$stub");
960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner             MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner             MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
997a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner      GVSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
1004fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner    else
101deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner      GVSym = Mang->getSymbol(GV);
1024fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner
1030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // Handle dllimport linkage.
1040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
1054fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner      GVSym = OutContext.GetOrCreateSymbol(Twine("__imp_") + GVSym->getName());
10622854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
1070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
1080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
1097a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner      MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
11022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach      MachineModuleInfoImpl::StubValueTy &StubSym =
1110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
112cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      if (StubSym.getPointer() == 0)
113cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        StubSym = MachineModuleInfoImpl::
114deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner          StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
1150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
1167a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner      MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
117cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      MachineModuleInfoImpl::StubValueTy &StubSym =
1180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
119cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      if (StubSym.getPointer() == 0)
120cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        StubSym = MachineModuleInfoImpl::
121deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner          StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
1220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
1237a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner      MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
124cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      MachineModuleInfoImpl::StubValueTy &StubSym =
1250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
126cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      if (StubSym.getPointer() == 0)
127cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        StubSym = MachineModuleInfoImpl::
128deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner          StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
1290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
13022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
1310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // If the name begins with a dollar-sign, enclose it in parens.  We do this
1320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // to avoid having it look like an integer immediate to the assembler.
1334fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner    if (GVSym->getName()[0] != '$')
13410b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner      O << *GVSym;
13510b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner    else
13610b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner      O << '(' << *GVSym << ')';
1370c08d092049c025c9ccf7143e39f39dc4e30d6b4Chris Lattner    printOffset(MO.getOffset(), O);
1380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
1390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
1400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_ExternalSymbol: {
141ee9250bb4f88364511cfda9ae95ad787bff1a72cChris Lattner    const MCSymbol *SymToPrint;
1420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
1438570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner      SmallString<128> TempNameStr;
1448570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner      TempNameStr += StringRef(MO.getSymbolName());
1458570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner      TempNameStr += StringRef("$stub");
14622854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
147d269a6e460a71a6c5c361a26c56c91fdb9486f45Chris Lattner      MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
148cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      MachineModuleInfoImpl::StubValueTy &StubSym =
1490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
150cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      if (StubSym.getPointer() == 0) {
1514813035b726e7f0a3fd17bec437185fc72a50988Chris Lattner        TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());
152cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        StubSym = MachineModuleInfoImpl::
153cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling          StubValueTy(OutContext.GetOrCreateSymbol(TempNameStr.str()),
154cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling                      true);
1550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
156cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling      SymToPrint = StubSym.getPointer();
157ee9250bb4f88364511cfda9ae95ad787bff1a72cChris Lattner    } else {
1588570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner      SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName());
1590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
16022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
1610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // If the name begins with a dollar-sign, enclose it in parens.  We do this
1620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // to avoid having it look like an integer immediate to the assembler.
16322854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach    if (SymToPrint->getName()[0] != '$')
16410b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner      O << *SymToPrint;
16510b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner    else
16610b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner      O << '(' << *SymToPrint << '(';
1670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
1680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
1690dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
17022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
1710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (MO.getTargetFlags()) {
1720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  default:
1730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    llvm_unreachable("Unknown target flag on GV operand");
1740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_NO_FLAG:    // No flag.
1750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
1760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_DARWIN_NONLAZY:
1770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_DLLIMPORT:
1780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_DARWIN_STUB:
1790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // These affect the name of the symbol, not any suffix.
1800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
1810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_GOT_ABSOLUTE_ADDRESS:
182142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner    O << " + [.-" << *MF->getPICBaseSymbol() << ']';
18322854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach    break;
1840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_PIC_BASE_OFFSET:
1850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
1860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
187142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner    O << '-' << *MF->getPICBaseSymbol();
1880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
1890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_TLSGD:     O << "@TLSGD";     break;
1900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_GOTTPOFF:  O << "@GOTTPOFF";  break;
1910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
1920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_TPOFF:     O << "@TPOFF";     break;
1930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_NTPOFF:    O << "@NTPOFF";    break;
1940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_GOTPCREL:  O << "@GOTPCREL";  break;
1950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_GOT:       O << "@GOT";       break;
1960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_GOTOFF:    O << "@GOTOFF";    break;
1970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case X86II::MO_PLT:       O << "@PLT";       break;
19830ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher  case X86II::MO_TLVP:      O << "@TLVP";      break;
19930ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher  case X86II::MO_TLVP_PIC_BASE:
200142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner    O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
20130ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher    break;
2020dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
2040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// print_pcrel_imm - This is used to print an immediate value that ends up
2060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// being encoded as a pc-relative value.  These print slightly differently, for
2070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// example, a $ is not emitted.
20888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo,
20988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                    raw_ostream &O) {
2100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &MO = MI->getOperand(OpNo);
2110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (MO.getType()) {
2120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  default: llvm_unreachable("Unknown pcrel immediate operand");
213323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen  case MachineOperand::MO_Register:
214323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen    // pc-relativeness was handled when computing the value in the reg.
215323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen    printOperand(MI, OpNo, O);
216323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen    return;
2170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_Immediate:
2180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << MO.getImm();
2190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    return;
2200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_MachineBasicBlock:
2211b2eb0e8a6aaf034675b17be6d853cb1c666200fChris Lattner    O << *MO.getMBB()->getSymbol();
2220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    return;
2230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_GlobalAddress:
2240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_ExternalSymbol:
22588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner    printSymbolOperand(MO, O);
2260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    return;
2270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
2290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
23288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                 raw_ostream &O, const char *Modifier) {
2330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &MO = MI->getOperand(OpNo);
2340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (MO.getType()) {
2350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  default: llvm_unreachable("unknown operand type!");
2360dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_Register: {
2370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << '%';
2380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    unsigned Reg = MO.getReg();
2390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
2400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      EVT VT = (strcmp(Modifier+6,"64") == 0) ?
2410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
2420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner                    ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
2430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      Reg = getX86SubSuperRegister(Reg, VT);
2440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
2450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << X86ATTInstPrinter::getRegisterName(Reg);
2460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    return;
2470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_Immediate:
2500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << '$' << MO.getImm();
2510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    return;
2520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_JumpTableIndex:
2540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_ConstantPoolIndex:
25522854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach  case MachineOperand::MO_GlobalAddress:
2560dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case MachineOperand::MO_ExternalSymbol: {
2570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << '$';
25888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner    printSymbolOperand(MO, O);
2590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
2600dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
2630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
26488db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op,
26588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                               raw_ostream &O) {
2660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  unsigned char value = MI->getOperand(Op).getImm();
2670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  assert(value <= 7 && "Invalid ssecc argument!");
2680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (value) {
2690dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 0: O << "eq"; break;
2700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 1: O << "lt"; break;
2710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 2: O << "le"; break;
2720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 3: O << "unord"; break;
2730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 4: O << "neq"; break;
2740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 5: O << "nlt"; break;
2750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 6: O << "nle"; break;
2760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 7: O << "ord"; break;
2770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
2780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
2790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
28188db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                         raw_ostream &O, const char *Modifier) {
2820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &BaseReg  = MI->getOperand(Op);
2830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &IndexReg = MI->getOperand(Op+2);
2840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &DispSpec = MI->getOperand(Op+3);
2850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
2860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  // If we really don't want to print out (rip), don't.
2870dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  bool HasBaseReg = BaseReg.getReg() != 0;
2880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
2890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      BaseReg.getReg() == X86::RIP)
2900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    HasBaseReg = false;
29122854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
2920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  // HasParenPart - True if we will print out the () part of the mem ref.
2930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  bool HasParenPart = IndexReg.getReg() || HasBaseReg;
29422854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
2950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (DispSpec.isImm()) {
2960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    int DispVal = DispSpec.getImm();
2970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (DispVal || !HasParenPart)
2980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      O << DispVal;
2990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  } else {
3000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
3010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner           DispSpec.isJTI() || DispSpec.isSymbol());
30288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner    printSymbolOperand(MI->getOperand(Op+3), O);
3030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
3040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (HasParenPart) {
3060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    assert(IndexReg.getReg() != X86::ESP &&
3070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner           "X86 doesn't allow scaling by ESP");
3080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3090dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << '(';
3100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (HasBaseReg)
31188db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner      printOperand(MI, Op, O, Modifier);
3120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3130dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (IndexReg.getReg()) {
3140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      O << ',';
31588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner      printOperand(MI, Op+2, O, Modifier);
3160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      unsigned ScaleVal = MI->getOperand(Op+1).getImm();
3170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (ScaleVal != 1)
3180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << ',' << ScaleVal;
3190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
3200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << ')';
3210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
3220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
3230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
32588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                      raw_ostream &O, const char *Modifier) {
3260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  assert(isMem(MI, Op) && "Invalid memory reference!");
3270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  const MachineOperand &Segment = MI->getOperand(Op+4);
3280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (Segment.getReg()) {
32988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner    printOperand(MI, Op+4, O, Modifier);
3300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    O << ':';
3310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
33288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner  printLeaMemReference(MI, Op, O, Modifier);
3330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
3340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
33588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op,
33688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                  raw_ostream &O) {
337142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner  O << *MF->getPICBaseSymbol() << '\n';
338142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner  O << *MF->getPICBaseSymbol() << ':';
3390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
3400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
34188db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnerbool X86AsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode,
34288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner                                      raw_ostream &O) {
3430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  unsigned Reg = MO.getReg();
3440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  switch (Mode) {
3450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  default: return true;  // Unknown mode.
3460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 'b': // Print QImode register
3470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Reg = getX86SubSuperRegister(Reg, MVT::i8);
3480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
3490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 'h': // Print QImode high register
3500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
3510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
3520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 'w': // Print HImode register
3530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Reg = getX86SubSuperRegister(Reg, MVT::i16);
3540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
3550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 'k': // Print SImode register
3560dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Reg = getX86SubSuperRegister(Reg, MVT::i32);
3570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
3580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  case 'q': // Print DImode register
3590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Reg = getX86SubSuperRegister(Reg, MVT::i64);
3600dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    break;
3610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
3620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
3640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  return false;
3650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
3660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// PrintAsmOperand - Print out an operand for an inline asm expression.
3680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner///
3690dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
3700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner                                    unsigned AsmVariant,
371c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner                                    const char *ExtraCode, raw_ostream &O) {
3720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  // Does this asm operand have a single letter operand modifier?
3730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (ExtraCode && ExtraCode[0]) {
3740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (ExtraCode[1] != 0) return true; // Unknown modifier.
3750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    const MachineOperand &MO = MI->getOperand(OpNo);
37722854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
3780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    switch (ExtraCode[0]) {
3790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    default: return true;  // Unknown modifier.
3800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'a': // This is an address.  Currently only 'i' and 'r' are expected.
3810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isImm()) {
3820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << MO.getImm();
3830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        return false;
38422854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach      }
3850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) {
38688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        printSymbolOperand(MO, O);
387e2b448c20862ec3da494ef502cca0074c1301acbDale Johannesen        if (Subtarget->isPICStyleRIPRel())
388e2b448c20862ec3da494ef502cca0074c1301acbDale Johannesen          O << "(%rip)";
3890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        return false;
3900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
3910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isReg()) {
3920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << '(';
39388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        printOperand(MI, OpNo, O);
3940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << ')';
3950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        return false;
3960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
3970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return true;
3980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
3990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'c': // Don't print "$" before a global var name or constant.
4000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isImm())
4010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << MO.getImm();
4020dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
40388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        printSymbolOperand(MO, O);
4040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      else
40588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        printOperand(MI, OpNo, O);
4060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return false;
4070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'A': // Print '*' before a register (it must be a register)
4090dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isReg()) {
4100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << '*';
41188db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        printOperand(MI, OpNo, O);
4120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        return false;
4130dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
4140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return true;
4150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'b': // Print QImode register
4170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'h': // Print QImode high register
4180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'w': // Print HImode register
4190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'k': // Print SImode register
4200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'q': // Print DImode register
4210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isReg())
42288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner        return printAsmMRegister(MO, ExtraCode[0], O);
42388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner      printOperand(MI, OpNo, O);
4240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return false;
4250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'P': // This is the operand of a call, treat specially.
42788db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner      print_pcrel_imm(MI, OpNo, O);
4280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return false;
4290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'n':  // Negate the immediate or print a '-' before the operand.
4310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      // Note: this is a temporary solution. It should be handled target
4320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      // independently as part of the 'MC' work.
4330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      if (MO.isImm()) {
4340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        O << -MO.getImm();
4350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner        return false;
4360dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
4370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      O << '-';
4380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
4390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
4400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
44188db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner  printOperand(MI, OpNo, O);
4420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  return false;
4430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
4440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
4460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner                                          unsigned OpNo, unsigned AsmVariant,
447c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner                                          const char *ExtraCode,
448c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner                                          raw_ostream &O) {
4490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (ExtraCode && ExtraCode[0]) {
4500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (ExtraCode[1] != 0) return true; // Unknown modifier.
4510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    switch (ExtraCode[0]) {
4530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    default: return true;  // Unknown modifier.
4540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'b': // Print QImode register
4550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'h': // Print QImode high register
4560dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'w': // Print HImode register
4570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'k': // Print SImode register
4580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'q': // Print SImode register
4590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      // These only apply to registers, ignore on mem.
4600dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      break;
4610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    case 'P': // Don't print @PLT, but do print as memory.
46288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner      printMemReference(MI, OpNo, O, "no-rip");
4630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      return false;
4640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
4650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
46688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner  printMemReference(MI, OpNo, O);
4670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  return false;
4680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
4690dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4701bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattnervoid X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
4711bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner  if (Subtarget->isTargetDarwin())
4721bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner    OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
4731bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner}
4741bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner
4750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
4770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (Subtarget->isTargetDarwin()) {
4780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // All darwin targets use mach-o.
4790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    MachineModuleInfoMachO &MMIMacho =
4800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      MMI->getObjFileInfo<MachineModuleInfoMachO>();
48122854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
4820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // Output stubs for dynamically-linked functions.
4830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    MachineModuleInfoMachO::SymbolListTy Stubs;
4840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Stubs = MMIMacho.GetFnStubList();
4860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (!Stubs.empty()) {
48722854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach      const MCSection *TheSection =
48822772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner        OutContext.getMachOSection("__IMPORT", "__jump_table",
48922772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   MCSectionMachO::S_SYMBOL_STUBS |
49022772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
49122772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
49222772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   5, SectionKind::getMetadata());
4930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      OutStreamer.SwitchSection(TheSection);
4940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
4950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
496beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // L_foo$stub:
497beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        OutStreamer.EmitLabel(Stubs[i].first);
498beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        //   .indirect_symbol _foo
499cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(),
500cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling                                        MCSA_IndirectSymbol);
501beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // hlt; hlt; hlt; hlt; hlt     hlt = 0xf4 = -12.
502beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        const char HltInsts[] = { -12, -12, -12, -12, -12 };
503beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        OutStreamer.EmitBytes(StringRef(HltInsts, 5), 0/*addrspace*/);
5040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
50522854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
5060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      Stubs.clear();
507beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner      OutStreamer.AddBlankLine();
5080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
5090dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // Output stubs for external and common global variables.
5110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Stubs = MMIMacho.GetGVStubList();
5120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (!Stubs.empty()) {
51322854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach      const MCSection *TheSection =
51422772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner        OutContext.getMachOSection("__IMPORT", "__pointers",
51522772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
51622772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner                                   SectionKind::getMetadata());
5170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      OutStreamer.SwitchSection(TheSection);
5180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
520beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // L_foo$non_lazy_ptr:
521beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        OutStreamer.EmitLabel(Stubs[i].first);
522beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // .indirect_symbol _foo
523ec041eba384a5553b47295361fde15acc21d5607Bill Wendling        MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
524ec041eba384a5553b47295361fde15acc21d5607Bill Wendling        OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),
525cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling                                        MCSA_IndirectSymbol);
526beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // .long 0
527ec041eba384a5553b47295361fde15acc21d5607Bill Wendling        if (MCSym.getInt())
528ec041eba384a5553b47295361fde15acc21d5607Bill Wendling          // External to current translation unit.
529ec041eba384a5553b47295361fde15acc21d5607Bill Wendling          OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/);
530ec041eba384a5553b47295361fde15acc21d5607Bill Wendling        else
531ec041eba384a5553b47295361fde15acc21d5607Bill Wendling          // Internal to current translation unit.
532d93bf04a0733210c376a79bc30570a58516b330cBill Wendling          //
533d93bf04a0733210c376a79bc30570a58516b330cBill Wendling          // When we place the LSDA into the TEXT section, the type info
534d93bf04a0733210c376a79bc30570a58516b330cBill Wendling          // pointers need to be indirect and pc-rel. We accomplish this by
535d93bf04a0733210c376a79bc30570a58516b330cBill Wendling          // using NLPs.  However, sometimes the types are local to the file. So
536d93bf04a0733210c376a79bc30570a58516b330cBill Wendling          // we need to fill in the value for the NLP in those cases.
537ec041eba384a5553b47295361fde15acc21d5607Bill Wendling          OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(),
538ec041eba384a5553b47295361fde15acc21d5607Bill Wendling                                                        OutContext),
539ec041eba384a5553b47295361fde15acc21d5607Bill Wendling                                4/*size*/, 0/*addrspace*/);
5400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
5410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      Stubs.clear();
542beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner      OutStreamer.AddBlankLine();
5430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
5440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    Stubs = MMIMacho.GetHiddenGVStubList();
5460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    if (!Stubs.empty()) {
5470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
5480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      EmitAlignment(2);
5490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
551beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // L_foo$non_lazy_ptr:
552beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        OutStreamer.EmitLabel(Stubs[i].first);
553beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner        // .long _foo
554cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling        OutStreamer.EmitValue(MCSymbolRefExpr::
555cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling                              Create(Stubs[i].second.getPointer(),
556cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling                                     OutContext),
557beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner                              4/*size*/, 0/*addrspace*/);
5580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      }
5590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      Stubs.clear();
560beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner      OutStreamer.AddBlankLine();
5610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
5620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // Funny Darwin hack: This flag tells the linker that no global symbols
5640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // contain code that falls through to other global symbols (e.g. the obvious
5650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // implementation of multiple entry points).  If this doesn't occur, the
5660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // linker can safely perform dead code stripping.  Since LLVM never
5670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    // generates code that does this, it is always safe to set.
568a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner    OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
5694fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov  }
5700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
571a29aae7aca6d8b9a9e95238d7e4067d8c16b0079Chris Lattner  if (Subtarget->isTargetWindows() && !Subtarget->isTargetCygMing() &&
572a29aae7aca6d8b9a9e95238d7e4067d8c16b0079Chris Lattner      MMI->callsExternalVAFunctionWithFloatingPointArguments()) {
573c527407010fadcbca0bc394ada311f2122df2bc0Michael J. Spencer    StringRef SymbolName = Subtarget->is64Bit() ? "_fltused" : "__fltused";
574c527407010fadcbca0bc394ada311f2122df2bc0Michael J. Spencer    MCSymbol *S = MMI->getContext().GetOrCreateSymbol(SymbolName);
57584ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer    OutStreamer.EmitSymbolAttribute(S, MCSA_Global);
57684ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer  }
57784ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer
5784fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov  if (Subtarget->isTargetCOFF()) {
5794fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov    X86COFFMachineModuleInfo &COFFMMI =
5800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner      MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
5810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
5824fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov    // Emit type information for external functions
583b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    typedef X86COFFMachineModuleInfo::externals_iterator externals_iterator;
584b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner    for (externals_iterator I = COFFMMI.externals_begin(),
585b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner                            E = COFFMMI.externals_end();
586b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner                            I != E; ++I) {
587b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner      OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
5889fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner      OutStreamer.EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_EXTERNAL);
5899fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner      OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION
5909fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner                                               << COFF::SCT_COMPLEX_TYPE_SHIFT);
591b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner      OutStreamer.EndCOFFSymbolDef();
5920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
5934fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov
594071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    // Necessary for dllexport support
595071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    std::vector<const MCSymbol*> DLLExportedFns, DLLExportedGlobals;
596071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords
597071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    const TargetLoweringObjectFileCOFF &TLOFCOFF =
598071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords      static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
599071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords
600071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
601071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords      if (I->hasDLLExportLinkage())
602071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords        DLLExportedFns.push_back(Mang->getSymbol(I));
603071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords
604071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    for (Module::const_global_iterator I = M.global_begin(),
605071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords           E = M.global_end(); I != E; ++I)
606071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords      if (I->hasDLLExportLinkage())
607071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords        DLLExportedGlobals.push_back(Mang->getSymbol(I));
608071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords
609071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    // Output linker support code for dllexported globals on windows.
610071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords    if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) {
611071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords      OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());
612bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords      SmallString<128> name;
613bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords      for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) {
614bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        if (Subtarget->isTargetWindows())
615bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords          name = " /EXPORT:";
616bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        else
617bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords          name = " -export:";
618bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        name += DLLExportedGlobals[i]->getName();
619bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        if (Subtarget->isTargetWindows())
620bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords          name += ",DATA";
621bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        else
622bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        name += ",data";
623bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        OutStreamer.EmitBytes(name, 0);
624bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords      }
625bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords
626bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords      for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) {
627bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        if (Subtarget->isTargetWindows())
628bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords          name = " /EXPORT:";
629bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        else
630bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords          name = " -export:";
631bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        name += DLLExportedFns[i]->getName();
632bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords        OutStreamer.EmitBytes(name, 0);
633bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords      }
6340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner    }
6350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  }
6369184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov
6379184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov  if (Subtarget->isTargetELF()) {
6380d805c33d134d88169e3dc4a3272cff9a5713ce7Dan Gohman    const TargetLoweringObjectFileELF &TLOFELF =
6390d805c33d134d88169e3dc4a3272cff9a5713ce7Dan Gohman      static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
6409184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov
6419184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov    MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
6429184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov
6439184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov    // Output stubs for external and common global variables.
6449184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov    MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
6459184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov    if (!Stubs.empty()) {
6469184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov      OutStreamer.SwitchSection(TLOFELF.getDataRelSection());
6479184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov      const TargetData *TD = TM.getTargetData();
6489184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov
649c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner      for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
650c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner        OutStreamer.EmitLabel(Stubs[i].first);
651c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner        OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
652c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner                                    TD->getPointerSize(), 0);
653c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner      }
6549184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov      Stubs.clear();
6559184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov    }
6569184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov  }
6570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
6580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
65922854b777e37b07d65376bedeeab004f68d5ca5dJim GrosbachMachineLocation
6601a34c83cafbeee42886c7a45dd31892c0747682eChris LattnerX86AsmPrinter::getDebugValueLocation(const MachineInstr *MI) const {
6611a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  MachineLocation Location;
6621a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  assert (MI->getNumOperands() == 7 && "Invalid no. of machine operands!");
6631a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // Frame address.  Currently handles register +- offset only.
66422854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
6651a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  if (MI->getOperand(0).isReg() && MI->getOperand(3).isImm())
6661a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner    Location.set(MI->getOperand(0).getReg(), MI->getOperand(3).getImm());
6675c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel  else {
6685c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel    DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n");
6695c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel  }
6701a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  return Location;
6711a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner}
6721a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner
6731a34c83cafbeee42886c7a45dd31892c0747682eChris Lattnervoid X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
6741a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner                                           raw_ostream &O) {
6751a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // Only the target-dependent form of DBG_VALUE should get here.
6761a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // Referencing the offset and metadata as NOps-2 and NOps-1 is
6771a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // probably portable to other targets; frame pointer location is not.
6781a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  unsigned NOps = MI->getNumOperands();
6791a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  assert(NOps==7);
6801a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
6811a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // cast away const; DIetc do not take const operands for some reason.
6821a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata()));
6831a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  if (V.getContext().isSubprogram())
6841a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner    O << DISubprogram(V.getContext()).getDisplayName() << ":";
6851a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << V.getName();
6861a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << " <- ";
6871a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  // Frame address.  Currently handles register +- offset only.
68822854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach  O << '[';
6891a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg())
69022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach    printOperand(MI, 0, O);
6911a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  else
6921a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner    O << "undef";
6931a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << '+'; printOperand(MI, 3, O);
6941a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << ']';
6951a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  O << "+";
6961a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner  printOperand(MI, NOps-2, O);
6971a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner}
6981a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner
6991a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner
7000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
7010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===//
7020dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Target Registry Stuff
7030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===//
7040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
7050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerstatic MCInstPrinter *createX86MCInstPrinter(const Target &T,
7060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner                                             unsigned SyntaxVariant,
707d374087be5360a353a4239a155b1227057145f48Chris Lattner                                             const MCAsmInfo &MAI) {
7080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (SyntaxVariant == 0)
709d374087be5360a353a4239a155b1227057145f48Chris Lattner    return new X86ATTInstPrinter(MAI);
7100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  if (SyntaxVariant == 1)
711d374087be5360a353a4239a155b1227057145f48Chris Lattner    return new X86IntelInstPrinter(MAI);
7120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  return 0;
7130dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
7140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner
7150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Force static initialization.
71622854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbachextern "C" void LLVMInitializeX86AsmPrinter() {
7170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  RegisterAsmPrinter<X86AsmPrinter> X(TheX86_32Target);
7180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  RegisterAsmPrinter<X86AsmPrinter> Y(TheX86_64Target);
71922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach
7200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  TargetRegistry::RegisterMCInstPrinter(TheX86_32Target,createX86MCInstPrinter);
7210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner  TargetRegistry::RegisterMCInstPrinter(TheX86_64Target,createX86MCInstPrinter);
7220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner}
723