X86AsmPrinter.cpp revision 0bcbd1df7a204e1e512f1a27066d725309de1b13
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" 160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86MCInstLower.h" 170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86.h" 180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86COFFMachineModuleInfo.h" 190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86MachineFunctionInfo.h" 200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "X86TargetMachine.h" 2179aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "InstPrinter/X86ATTInstPrinter.h" 220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CallingConv.h" 230bcbd1df7a204e1e512f1a27066d725309de1b13Bill Wendling#include "llvm/DebugInfo.h" 240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/DerivedTypes.h" 250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Module.h" 260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Type.h" 270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Assembly/Writer.h" 28becd83e3f4eb996f8e43189ce482267b3b8351a8Bill Wendling#include "llvm/MC/MCAsmInfo.h" 290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCContext.h" 30beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner#include "llvm/MC/MCExpr.h" 310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCSectionMachO.h" 320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCStreamer.h" 330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/MC/MCSymbol.h" 340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CodeGen/MachineJumpTableInfo.h" 350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/CodeGen/MachineModuleInfoImpls.h" 36362dd0bef5437f85586c046bc53287b6fbe9c099Anton Korobeynikov#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 373e74d6fdd248e20a280f1dff3da9a6c689c2c4c3Evan Cheng#include "llvm/Target/Mangler.h" 383e74d6fdd248e20a280f1dff3da9a6c689c2c4c3Evan Cheng#include "llvm/Target/TargetOptions.h" 399fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner#include "llvm/Support/COFF.h" 405c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel#include "llvm/Support/Debug.h" 410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/Support/ErrorHandling.h" 423e74d6fdd248e20a280f1dff3da9a6c689c2c4c3Evan Cheng#include "llvm/Support/TargetRegistry.h" 430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner#include "llvm/ADT/SmallString.h" 440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerusing namespace llvm; 450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===// 470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Primitive Helper Functions. 480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===// 490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5014c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner/// runOnMachineFunction - Emit the function body. 510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// 520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { 530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner SetupMachineFunction(MF); 540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 552bffee2ee725047137d2523e31db9ecc7b246cbbEvan Cheng if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) { 56b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner bool Intrn = MF.getFunction()->hasInternalLinkage(); 57b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner OutStreamer.BeginCOFFSymbolDef(CurrentFnSym); 5822854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC 599fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner : COFF::IMAGE_SYM_CLASS_EXTERNAL); 609fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION 619fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner << COFF::SCT_COMPLEX_TYPE_SHIFT); 62b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner OutStreamer.EndCOFFSymbolDef(); 63b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner } 644dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov 65b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner // Have common code print out the function header with linkage info etc. 66b11caedd6f36afc6518cf0ea9bbff6500fd77334Chris Lattner EmitFunctionHeader(); 674dd162f3945636cbe6123682619e994f75a62d00Anton Korobeynikov 6814c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner // Emit the rest of the function body. 6914c38ec2afeaf25c53a50c2c65116aca8c889401Chris Lattner EmitFunctionBody(); 700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // We didn't modify anything. 720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// printSymbolOperand - Print a raw symbol reference operand. This handles 760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// jump tables, constant pools, global address and external symbols, all of 770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// which print to a label with various suffixes for relocation types etc. 7888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printSymbolOperand(const MachineOperand &MO, 7988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O) { 800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (MO.getType()) { 810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: llvm_unreachable("unknown symbol type!"); 820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_JumpTableIndex: 8364c2b244982046373c853e988b7395fdf0166cd8Chris Lattner O << *GetJTISymbol(MO.getIndex()); 840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_ConstantPoolIndex: 8664c2b244982046373c853e988b7395fdf0166cd8Chris Lattner O << *GetCPISymbol(MO.getIndex()); 870c08d092049c025c9ccf7143e39f39dc4e30d6b4Chris Lattner printOffset(MO.getOffset(), O); 880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_GlobalAddress: { 900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const GlobalValue *GV = MO.getGlobal(); 9122854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 925957c84e09b177aecf8b430c33fd75a36575fb57Chris Lattner MCSymbol *GVSym; 930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) 947a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner GVSym = GetSymbolWithGlobalValueBase(GV, "$stub"); 950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || 960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE || 970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE) 987a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner GVSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); 994fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner else 100deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner GVSym = Mang->getSymbol(GV); 1014fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner 1020dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Handle dllimport linkage. 1030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) 1044fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner GVSym = OutContext.GetOrCreateSymbol(Twine("__imp_") + GVSym->getName()); 10522854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 1060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || 1070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { 1087a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); 10922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach MachineModuleInfoImpl::StubValueTy &StubSym = 1100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym); 111cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling if (StubSym.getPointer() == 0) 112cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling StubSym = MachineModuleInfoImpl:: 113deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); 1140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ 1157a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); 116cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling MachineModuleInfoImpl::StubValueTy &StubSym = 1170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym); 118cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling if (StubSym.getPointer() == 0) 119cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling StubSym = MachineModuleInfoImpl:: 120deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); 1210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { 1227a2ba94d03b43f41b54872dacd7b2250dde4c7bdChris Lattner MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); 123cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling MachineModuleInfoImpl::StubValueTy &StubSym = 1240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); 125cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling if (StubSym.getPointer() == 0) 126cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling StubSym = MachineModuleInfoImpl:: 127deb0cba1bad5a46bbecb75666e415c3dee9c89ebChris Lattner StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage()); 1280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 12922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 1300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // If the name begins with a dollar-sign, enclose it in parens. We do this 1310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // to avoid having it look like an integer immediate to the assembler. 1324fb69f40bee04a415a92bca2a8ed4a8e72cf980dChris Lattner if (GVSym->getName()[0] != '$') 13310b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner O << *GVSym; 13410b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner else 13510b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner O << '(' << *GVSym << ')'; 1360c08d092049c025c9ccf7143e39f39dc4e30d6b4Chris Lattner printOffset(MO.getOffset(), O); 1370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 1380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 1390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_ExternalSymbol: { 140ee9250bb4f88364511cfda9ae95ad787bff1a72cChris Lattner const MCSymbol *SymToPrint; 1410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { 1428570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner SmallString<128> TempNameStr; 1438570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner TempNameStr += StringRef(MO.getSymbolName()); 1448570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner TempNameStr += StringRef("$stub"); 14522854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 146d269a6e460a71a6c5c361a26c56c91fdb9486f45Chris Lattner MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); 147cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling MachineModuleInfoImpl::StubValueTy &StubSym = 1480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); 149cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling if (StubSym.getPointer() == 0) { 1504813035b726e7f0a3fd17bec437185fc72a50988Chris Lattner TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end()); 151cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling StubSym = MachineModuleInfoImpl:: 152cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling StubValueTy(OutContext.GetOrCreateSymbol(TempNameStr.str()), 153cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling true); 1540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 155cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling SymToPrint = StubSym.getPointer(); 156ee9250bb4f88364511cfda9ae95ad787bff1a72cChris Lattner } else { 1578570f594adc8e0795d0c5fd3e531790f6fac1821Chris Lattner SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName()); 1580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 15922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 1600dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // If the name begins with a dollar-sign, enclose it in parens. We do this 1610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // to avoid having it look like an integer immediate to the assembler. 16222854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach if (SymToPrint->getName()[0] != '$') 16310b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner O << *SymToPrint; 16410b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner else 16510b318bcb39218d2ed525e4862c854bc8d1baf63Chris Lattner O << '(' << *SymToPrint << '('; 1660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 1670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 1680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 16922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 1700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (MO.getTargetFlags()) { 1710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: 1720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner llvm_unreachable("Unknown target flag on GV operand"); 1730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_NO_FLAG: // No flag. 1740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 1750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_DARWIN_NONLAZY: 1760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_DLLIMPORT: 1770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_DARWIN_STUB: 1780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // These affect the name of the symbol, not any suffix. 1790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 1800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_GOT_ABSOLUTE_ADDRESS: 181142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner O << " + [.-" << *MF->getPICBaseSymbol() << ']'; 18222854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach break; 1830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_PIC_BASE_OFFSET: 1840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_DARWIN_NONLAZY_PIC_BASE: 1850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: 186142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner O << '-' << *MF->getPICBaseSymbol(); 1870dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 1880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_TLSGD: O << "@TLSGD"; break; 189f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg case X86II::MO_TLSLD: O << "@TLSLD"; break; 190f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg case X86II::MO_TLSLDM: O << "@TLSLDM"; break; 1910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break; 1920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break; 1930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_TPOFF: O << "@TPOFF"; break; 194f0234fcbc9be9798c10dedc3e3c134b7afbc6511Hans Wennborg case X86II::MO_DTPOFF: O << "@DTPOFF"; break; 1950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_NTPOFF: O << "@NTPOFF"; break; 196228756c744a1f877f7150c8fc91e074ff58c9d66Hans Wennborg case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break; 1970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break; 1980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_GOT: O << "@GOT"; break; 1990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_GOTOFF: O << "@GOTOFF"; break; 2000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case X86II::MO_PLT: O << "@PLT"; break; 20130ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher case X86II::MO_TLVP: O << "@TLVP"; break; 20230ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher case X86II::MO_TLVP_PIC_BASE: 203142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner O << "@TLVP" << '-' << *MF->getPICBaseSymbol(); 20430ef0e5658b0b8b04437f73f74162d5d72923f29Eric Christopher break; 205d4a19b6a72d19a6f90b676aac37118664b7b7a84Anton Korobeynikov case X86II::MO_SECREL: O << "@SECREL"; break; 2060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 2080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 2090dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// print_pcrel_imm - This is used to print an immediate value that ends up 2100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// being encoded as a pc-relative value. These print slightly differently, for 2110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// example, a $ is not emitted. 21288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo, 21388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O) { 2140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &MO = MI->getOperand(OpNo); 2150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (MO.getType()) { 2160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: llvm_unreachable("Unknown pcrel immediate operand"); 217323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen case MachineOperand::MO_Register: 218323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen // pc-relativeness was handled when computing the value in the reg. 219323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen printOperand(MI, OpNo, O); 220323200d9057af3b653de0cceb71ae10933e09b4cDale Johannesen return; 2210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_Immediate: 2220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << MO.getImm(); 2230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return; 2240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_MachineBasicBlock: 2251b2eb0e8a6aaf034675b17be6d853cb1c666200fChris Lattner O << *MO.getMBB()->getSymbol(); 2260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return; 2270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_GlobalAddress: 2280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_ExternalSymbol: 22988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printSymbolOperand(MO, O); 2300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return; 2310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 2330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 2340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 2350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, 23688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O, const char *Modifier) { 2370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &MO = MI->getOperand(OpNo); 2380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (MO.getType()) { 2390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: llvm_unreachable("unknown operand type!"); 2400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_Register: { 2410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '%'; 2420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned Reg = MO.getReg(); 2430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) { 2440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner EVT VT = (strcmp(Modifier+6,"64") == 0) ? 2450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 : 2460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8)); 2470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, VT); 2480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << X86ATTInstPrinter::getRegisterName(Reg); 2500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return; 2510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 2530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_Immediate: 2540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '$' << MO.getImm(); 2550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return; 2560dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 2570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_JumpTableIndex: 2580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_ConstantPoolIndex: 25922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach case MachineOperand::MO_GlobalAddress: 2600dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case MachineOperand::MO_ExternalSymbol: { 2610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '$'; 26288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printSymbolOperand(MO, O); 2630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 2640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 2660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 2670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 26888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op, 26988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O) { 2700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned char value = MI->getOperand(Op).getImm(); 2710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (value) { 272769bbfd951018f9b36f3d2f0d70a23d81f2d3287Craig Topper default: llvm_unreachable("Invalid ssecc argument!"); 273f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0: O << "eq"; break; 274f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 1: O << "lt"; break; 275f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 2: O << "le"; break; 276f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 3: O << "unord"; break; 277f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 4: O << "neq"; break; 278f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 5: O << "nlt"; break; 279f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 6: O << "nle"; break; 280f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 7: O << "ord"; break; 281f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 8: O << "eq_uq"; break; 282f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 9: O << "nge"; break; 283f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xa: O << "ngt"; break; 284f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xb: O << "false"; break; 285f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xc: O << "neq_oq"; break; 286f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xd: O << "ge"; break; 287f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xe: O << "gt"; break; 288f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0xf: O << "true"; break; 289f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x10: O << "eq_os"; break; 290f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x11: O << "lt_oq"; break; 291f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x12: O << "le_oq"; break; 292f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x13: O << "unord_s"; break; 293f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x14: O << "neq_us"; break; 294f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x15: O << "nlt_uq"; break; 295f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x16: O << "nle_uq"; break; 296f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x17: O << "ord_s"; break; 297f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x18: O << "eq_us"; break; 298f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x19: O << "nge_uq"; break; 299f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1a: O << "ngt_uq"; break; 300f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1b: O << "false_os"; break; 301f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1c: O << "neq_os"; break; 302f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1d: O << "ge_oq"; break; 303f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1e: O << "gt_oq"; break; 304f602040c4900d89bbf55478420769e36604588fbElena Demikhovsky case 0x1f: O << "true_us"; break; 3050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 3060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 3070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3080dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op, 30988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O, const char *Modifier) { 3100dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &BaseReg = MI->getOperand(Op); 3110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &IndexReg = MI->getOperand(Op+2); 3120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &DispSpec = MI->getOperand(Op+3); 3130dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // If we really don't want to print out (rip), don't. 3150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner bool HasBaseReg = BaseReg.getReg() != 0; 3160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") && 3170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner BaseReg.getReg() == X86::RIP) 3180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner HasBaseReg = false; 31922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 3200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // HasParenPart - True if we will print out the () part of the mem ref. 3210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner bool HasParenPart = IndexReg.getReg() || HasBaseReg; 32222854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 3230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (DispSpec.isImm()) { 3240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner int DispVal = DispSpec.getImm(); 3250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (DispVal || !HasParenPart) 3260dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << DispVal; 3270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } else { 3280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner assert(DispSpec.isGlobal() || DispSpec.isCPI() || 3290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner DispSpec.isJTI() || DispSpec.isSymbol()); 33088db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printSymbolOperand(MI->getOperand(Op+3), O); 3310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 3320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 33303277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola if (Modifier && strcmp(Modifier, "H") == 0) 33403277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola O << "+8"; 33503277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola 3360dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (HasParenPart) { 3370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner assert(IndexReg.getReg() != X86::ESP && 3380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner "X86 doesn't allow scaling by ESP"); 3390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '('; 3410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (HasBaseReg) 34288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, Op, O, Modifier); 3430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (IndexReg.getReg()) { 3450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << ','; 34688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, Op+2, O, Modifier); 3470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned ScaleVal = MI->getOperand(Op+1).getImm(); 3480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (ScaleVal != 1) 3490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << ',' << ScaleVal; 3500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 3510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << ')'; 3520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 3530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 3540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, 35688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O, const char *Modifier) { 3570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner assert(isMem(MI, Op) && "Invalid memory reference!"); 3580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &Segment = MI->getOperand(Op+4); 3590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (Segment.getReg()) { 36088db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, Op+4, O, Modifier); 3610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << ':'; 3620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 36388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printLeaMemReference(MI, Op, O, Modifier); 3640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 3650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 36688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnervoid X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op, 36788db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O) { 368142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner O << *MF->getPICBaseSymbol() << '\n'; 369142b531e024c7b814df74951b378b9e3e11d0d42Chris Lattner O << *MF->getPICBaseSymbol() << ':'; 3700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 3710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 37288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattnerbool X86AsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode, 37388db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner raw_ostream &O) { 3740dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned Reg = MO.getReg(); 3750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (Mode) { 3760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: return true; // Unknown mode. 3770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'b': // Print QImode register 3780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, MVT::i8); 3790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 3800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'h': // Print QImode high register 3810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, MVT::i8, true); 3820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 3830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'w': // Print HImode register 3840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, MVT::i16); 3850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 3860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'k': // Print SImode register 3870dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, MVT::i32); 3880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 3890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'q': // Print DImode register 3900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Reg = getX86SubSuperRegister(Reg, MVT::i64); 3910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 3920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 3930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '%' << X86ATTInstPrinter::getRegisterName(Reg); 3950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 3960dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 3970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 3980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// PrintAsmOperand - Print out an operand for an inline asm expression. 3990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner/// 4000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 4010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned AsmVariant, 402c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner const char *ExtraCode, raw_ostream &O) { 4030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Does this asm operand have a single letter operand modifier? 4040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (ExtraCode && ExtraCode[0]) { 4050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (ExtraCode[1] != 0) return true; // Unknown modifier. 4060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4070dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner const MachineOperand &MO = MI->getOperand(OpNo); 40822854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 4090dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (ExtraCode[0]) { 4100518fca843ff87d069ecb07fc00d306c1f587d58Jack Carter default: 4110518fca843ff87d069ecb07fc00d306c1f587d58Jack Carter // See if this is a generic print operand 4120518fca843ff87d069ecb07fc00d306c1f587d58Jack Carter return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O); 4130dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'a': // This is an address. Currently only 'i' and 'r' are expected. 4140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isImm()) { 4150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << MO.getImm(); 4160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 41722854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach } 4180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) { 41988db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printSymbolOperand(MO, O); 420e2b448c20862ec3da494ef502cca0074c1301acbDale Johannesen if (Subtarget->isPICStyleRIPRel()) 421e2b448c20862ec3da494ef502cca0074c1301acbDale Johannesen O << "(%rip)"; 4220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4230dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4240dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isReg()) { 4250dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '('; 42688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, OpNo, O); 4270dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << ')'; 4280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return true; 4310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4320dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'c': // Don't print "$" before a global var name or constant. 4330dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isImm()) 4340dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << MO.getImm(); 4350dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) 43688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printSymbolOperand(MO, O); 4370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner else 43888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, OpNo, O); 4390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'A': // Print '*' before a register (it must be a register) 4420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isReg()) { 4430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '*'; 44488db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, OpNo, O); 4450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return true; 4480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4490dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'b': // Print QImode register 4500dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'h': // Print QImode high register 4510dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'w': // Print HImode register 4520dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'k': // Print SImode register 4530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'q': // Print DImode register 4540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isReg()) 45588db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner return printAsmMRegister(MO, ExtraCode[0], O); 45688db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, OpNo, O); 4570dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4580dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4590dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'P': // This is the operand of a call, treat specially. 46088db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner print_pcrel_imm(MI, OpNo, O); 4610dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4620dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4630dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'n': // Negate the immediate or print a '-' before the operand. 4640dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Note: this is a temporary solution. It should be handled target 4650dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // independently as part of the 'MC' work. 4660dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (MO.isImm()) { 4670dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << -MO.getImm(); 4680dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4690dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner O << '-'; 4710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4720dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 4730dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 47488db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printOperand(MI, OpNo, O); 4750dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 4760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 4770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4780dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnerbool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, 4790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner unsigned OpNo, unsigned AsmVariant, 480c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner const char *ExtraCode, 481c75c028a15a13786eee585aa634b4faf694dd00aChris Lattner raw_ostream &O) { 4820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (ExtraCode && ExtraCode[0]) { 4830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (ExtraCode[1] != 0) return true; // Unknown modifier. 4840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 4850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner switch (ExtraCode[0]) { 4860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner default: return true; // Unknown modifier. 4870dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'b': // Print QImode register 4880dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'h': // Print QImode high register 4890dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'w': // Print HImode register 4900dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'k': // Print SImode register 4910dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'q': // Print SImode register 4920dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // These only apply to registers, ignore on mem. 4930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner break; 49403277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola case 'H': 49503277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola printMemReference(MI, OpNo, O, "H"); 49603277e7fb4d12f0d15dc2c97787fc89ecdaecf94Rafael Espindola return false; 4970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner case 'P': // Don't print @PLT, but do print as memory. 49888db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printMemReference(MI, OpNo, O, "no-rip"); 4990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 5000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 50288db786712bd1e7b1dd829e02ef960f0828a8becChris Lattner printMemReference(MI, OpNo, O); 5030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner return false; 5040dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 5050dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5061bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattnervoid X86AsmPrinter::EmitStartOfAsmFile(Module &M) { 5072bffee2ee725047137d2523e31db9ecc7b246cbbEvan Cheng if (Subtarget->isTargetEnvMacho()) 5081bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner OutStreamer.SwitchSection(getObjFileLowering().getTextSection()); 5091bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner} 5101bd1e6db1d5ae9ae0f07bef5db355e8a1cf5d5b4Chris Lattner 5110dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5120dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattnervoid X86AsmPrinter::EmitEndOfAsmFile(Module &M) { 5132bffee2ee725047137d2523e31db9ecc7b246cbbEvan Cheng if (Subtarget->isTargetEnvMacho()) { 5140dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // All darwin targets use mach-o. 5150dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MachineModuleInfoMachO &MMIMacho = 5160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<MachineModuleInfoMachO>(); 51722854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 5180dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Output stubs for dynamically-linked functions. 5190dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MachineModuleInfoMachO::SymbolListTy Stubs; 5200dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5210dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs = MMIMacho.GetFnStubList(); 5220dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (!Stubs.empty()) { 52322854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach const MCSection *TheSection = 52422772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner OutContext.getMachOSection("__IMPORT", "__jump_table", 52522772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner MCSectionMachO::S_SYMBOL_STUBS | 52622772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE | 52722772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 52822772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner 5, SectionKind::getMetadata()); 5290dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner OutStreamer.SwitchSection(TheSection); 5300dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5310dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { 532beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // L_foo$stub: 533beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.EmitLabel(Stubs[i].first); 534beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // .indirect_symbol _foo 535cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(), 536cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling MCSA_IndirectSymbol); 537cda2a146d1fcf3f499a1aa535377fb332e918bd5Jeffrey Yasskin // hlt; hlt; hlt; hlt; hlt hlt = 0xf4. 538cda2a146d1fcf3f499a1aa535377fb332e918bd5Jeffrey Yasskin const char HltInsts[] = "\xf4\xf4\xf4\xf4\xf4"; 539beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.EmitBytes(StringRef(HltInsts, 5), 0/*addrspace*/); 5400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 54122854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 5420dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs.clear(); 543beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.AddBlankLine(); 5440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5460dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Output stubs for external and common global variables. 5470dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs = MMIMacho.GetGVStubList(); 5480dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (!Stubs.empty()) { 54922854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach const MCSection *TheSection = 55022772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner OutContext.getMachOSection("__IMPORT", "__pointers", 55122772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, 55222772214de79aa1c5ca38c4fb1da137d8fb30a05Chris Lattner SectionKind::getMetadata()); 5530dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner OutStreamer.SwitchSection(TheSection); 5540dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5550dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { 556beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // L_foo$non_lazy_ptr: 557beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.EmitLabel(Stubs[i].first); 558beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // .indirect_symbol _foo 559ec041eba384a5553b47295361fde15acc21d5607Bill Wendling MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second; 560ec041eba384a5553b47295361fde15acc21d5607Bill Wendling OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), 561cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling MCSA_IndirectSymbol); 562beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // .long 0 563ec041eba384a5553b47295361fde15acc21d5607Bill Wendling if (MCSym.getInt()) 564ec041eba384a5553b47295361fde15acc21d5607Bill Wendling // External to current translation unit. 565ec041eba384a5553b47295361fde15acc21d5607Bill Wendling OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); 566ec041eba384a5553b47295361fde15acc21d5607Bill Wendling else 567ec041eba384a5553b47295361fde15acc21d5607Bill Wendling // Internal to current translation unit. 568d93bf04a0733210c376a79bc30570a58516b330cBill Wendling // 569d93bf04a0733210c376a79bc30570a58516b330cBill Wendling // When we place the LSDA into the TEXT section, the type info 570d93bf04a0733210c376a79bc30570a58516b330cBill Wendling // pointers need to be indirect and pc-rel. We accomplish this by 571d93bf04a0733210c376a79bc30570a58516b330cBill Wendling // using NLPs. However, sometimes the types are local to the file. So 572d93bf04a0733210c376a79bc30570a58516b330cBill Wendling // we need to fill in the value for the NLP in those cases. 573ec041eba384a5553b47295361fde15acc21d5607Bill Wendling OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(), 574ec041eba384a5553b47295361fde15acc21d5607Bill Wendling OutContext), 575ec041eba384a5553b47295361fde15acc21d5607Bill Wendling 4/*size*/, 0/*addrspace*/); 5760dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5770dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs.clear(); 578beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.AddBlankLine(); 5790dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5800dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5810dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs = MMIMacho.GetHiddenGVStubList(); 5820dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner if (!Stubs.empty()) { 5830dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); 5840dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner EmitAlignment(2); 5850dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5860dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { 587beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // L_foo$non_lazy_ptr: 588beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.EmitLabel(Stubs[i].first); 589beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner // .long _foo 590cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling OutStreamer.EmitValue(MCSymbolRefExpr:: 591cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling Create(Stubs[i].second.getPointer(), 592cebae36f57456fe6b0e13726acd1e0250654f02dBill Wendling OutContext), 593beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner 4/*size*/, 0/*addrspace*/); 5940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5950dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner Stubs.clear(); 596beb42691b1b58664e99cdc61cb5f4900298b432aChris Lattner OutStreamer.AddBlankLine(); 5970dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 5980dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 5990dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // Funny Darwin hack: This flag tells the linker that no global symbols 6000dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // contain code that falls through to other global symbols (e.g. the obvious 6010dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // implementation of multiple entry points). If this doesn't occur, the 6020dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // linker can safely perform dead code stripping. Since LLVM never 6030dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner // generates code that does this, it is always safe to set. 604a5ad93a10a5435f21090b09edb6b3a7e44967648Chris Lattner OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); 6054fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov } 6060dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 607a29aae7aca6d8b9a9e95238d7e4067d8c16b0079Chris Lattner if (Subtarget->isTargetWindows() && !Subtarget->isTargetCygMing() && 608c9c137b463b953fbf8942f655d67f6dc1a0f7965Michael J. Spencer MMI->usesVAFloatArgument()) { 609c527407010fadcbca0bc394ada311f2122df2bc0Michael J. Spencer StringRef SymbolName = Subtarget->is64Bit() ? "_fltused" : "__fltused"; 610c527407010fadcbca0bc394ada311f2122df2bc0Michael J. Spencer MCSymbol *S = MMI->getContext().GetOrCreateSymbol(SymbolName); 61184ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer OutStreamer.EmitSymbolAttribute(S, MCSA_Global); 61284ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer } 61384ac4d5a2a8fd0e6f95ec46088c0ca7bb63423acMichael J. Spencer 6142bffee2ee725047137d2523e31db9ecc7b246cbbEvan Cheng if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) { 6154fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov X86COFFMachineModuleInfo &COFFMMI = 6160dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner MMI->getObjFileInfo<X86COFFMachineModuleInfo>(); 6170dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 6184fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov // Emit type information for external functions 619b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner typedef X86COFFMachineModuleInfo::externals_iterator externals_iterator; 620b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner for (externals_iterator I = COFFMMI.externals_begin(), 621b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner E = COFFMMI.externals_end(); 622b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner I != E; ++I) { 623b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner OutStreamer.BeginCOFFSymbolDef(CurrentFnSym); 6249fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner OutStreamer.EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_EXTERNAL); 6259fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner OutStreamer.EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION 6269fe2c6704582a6730f4fc99dd85e214b23f3494bChris Lattner << COFF::SCT_COMPLEX_TYPE_SHIFT); 627b54b9ddaaf2d258767d360583642ed1b91075fc9Chris Lattner OutStreamer.EndCOFFSymbolDef(); 6280dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 6294fac9470c4d2e1055bd086f953a1938bde4961ecAnton Korobeynikov 630071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords // Necessary for dllexport support 631071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords std::vector<const MCSymbol*> DLLExportedFns, DLLExportedGlobals; 632071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords 633071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords const TargetLoweringObjectFileCOFF &TLOFCOFF = 634071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering()); 635071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords 636071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) 637071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords if (I->hasDLLExportLinkage()) 638071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords DLLExportedFns.push_back(Mang->getSymbol(I)); 639071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords 640071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords for (Module::const_global_iterator I = M.global_begin(), 641071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords E = M.global_end(); I != E; ++I) 642071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords if (I->hasDLLExportLinkage()) 643071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords DLLExportedGlobals.push_back(Mang->getSymbol(I)); 644071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords 645071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords // Output linker support code for dllexported globals on windows. 646071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) { 647071de920a0811a908be46953624867a82f2b22d8Nathan Jeffords OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection()); 648bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords SmallString<128> name; 649bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) { 650bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords if (Subtarget->isTargetWindows()) 651bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name = " /EXPORT:"; 652bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords else 653bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name = " -export:"; 654bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name += DLLExportedGlobals[i]->getName(); 655bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords if (Subtarget->isTargetWindows()) 656bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name += ",DATA"; 657bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords else 658bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name += ",data"; 659bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords OutStreamer.EmitBytes(name, 0); 660bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords } 661bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords 662bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) { 663bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords if (Subtarget->isTargetWindows()) 664bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name = " /EXPORT:"; 665bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords else 666bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name = " -export:"; 667bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords name += DLLExportedFns[i]->getName(); 668bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords OutStreamer.EmitBytes(name, 0); 669bb59732d1887091c4c2f6e1d65c74fdf4777b555Nathan Jeffords } 6700dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 6710dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner } 6729184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov 6739184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov if (Subtarget->isTargetELF()) { 6740d805c33d134d88169e3dc4a3272cff9a5713ce7Dan Gohman const TargetLoweringObjectFileELF &TLOFELF = 6750d805c33d134d88169e3dc4a3272cff9a5713ce7Dan Gohman static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering()); 6769184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov 6779184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>(); 6789184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov 6799184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov // Output stubs for external and common global variables. 6809184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList(); 6819184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov if (!Stubs.empty()) { 6829184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov OutStreamer.SwitchSection(TLOFELF.getDataRelSection()); 6839184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov const TargetData *TD = TM.getTargetData(); 6849184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov 685c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { 686c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner OutStreamer.EmitLabel(Stubs[i].first); 687c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(), 688c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner TD->getPointerSize(), 0); 689c82d9c4e5cfa856b8f23f595645f5e1ed7415747Chris Lattner } 6909184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov Stubs.clear(); 6919184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov } 6929184b25fa543a900463215c11635c2c014ddb623Anton Korobeynikov } 6930dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 6940dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 69522854b777e37b07d65376bedeeab004f68d5ca5dJim GrosbachMachineLocation 6961a34c83cafbeee42886c7a45dd31892c0747682eChris LattnerX86AsmPrinter::getDebugValueLocation(const MachineInstr *MI) const { 6971a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner MachineLocation Location; 6981a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner assert (MI->getNumOperands() == 7 && "Invalid no. of machine operands!"); 6991a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // Frame address. Currently handles register +- offset only. 70022854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach 7011a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner if (MI->getOperand(0).isReg() && MI->getOperand(3).isImm()) 7021a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner Location.set(MI->getOperand(0).getReg(), MI->getOperand(3).getImm()); 7035c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel else { 7045c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n"); 7055c1d941f00a3cdb4bdcefa95b4ff34ae8922cf15Devang Patel } 7061a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner return Location; 7071a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner} 7081a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner 7091a34c83cafbeee42886c7a45dd31892c0747682eChris Lattnervoid X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI, 7101a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner raw_ostream &O) { 7111a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // Only the target-dependent form of DBG_VALUE should get here. 7121a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // Referencing the offset and metadata as NOps-2 and NOps-1 is 7131a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // probably portable to other targets; frame pointer location is not. 7141a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner unsigned NOps = MI->getNumOperands(); 7151a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner assert(NOps==7); 7161a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: "; 7171a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // cast away const; DIetc do not take const operands for some reason. 7181a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata())); 7191a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner if (V.getContext().isSubprogram()) 7201a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << DISubprogram(V.getContext()).getDisplayName() << ":"; 7211a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << V.getName(); 7221a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << " <- "; 7231a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner // Frame address. Currently handles register +- offset only. 72422854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach O << '['; 7251a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg()) 72622854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbach printOperand(MI, 0, O); 7271a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner else 7281a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << "undef"; 7291a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << '+'; printOperand(MI, 3, O); 7301a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << ']'; 7311a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner O << "+"; 7321a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner printOperand(MI, NOps-2, O); 7331a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner} 7341a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner 7351a34c83cafbeee42886c7a45dd31892c0747682eChris Lattner 7360dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 7370dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===// 7380dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Target Registry Stuff 7390dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner//===----------------------------------------------------------------------===// 7400dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner 7410dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner// Force static initialization. 74222854b777e37b07d65376bedeeab004f68d5ca5dJim Grosbachextern "C" void LLVMInitializeX86AsmPrinter() { 7430dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner RegisterAsmPrinter<X86AsmPrinter> X(TheX86_32Target); 7440dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner RegisterAsmPrinter<X86AsmPrinter> Y(TheX86_64Target); 7450dc32ea0ef14c7e7f88edb12763a7828052a7fbdChris Lattner} 746