LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
X86AsmPrinter.cpp
Go to the documentation of this file.
1 //===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to X86 machine code.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "X86AsmPrinter.h"
17 #include "X86.h"
19 #include "X86MachineFunctionInfo.h"
20 #include "X86TargetMachine.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/Assembly/Writer.h"
26 #include "llvm/DebugInfo.h"
27 #include "llvm/IR/CallingConv.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Module.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/MC/MCAsmInfo.h"
32 #include "llvm/MC/MCContext.h"
33 #include "llvm/MC/MCExpr.h"
34 #include "llvm/MC/MCSectionMachO.h"
35 #include "llvm/MC/MCStreamer.h"
36 #include "llvm/MC/MCSymbol.h"
37 #include "llvm/Support/COFF.h"
38 #include "llvm/Support/Debug.h"
41 #include "llvm/Target/Mangler.h"
43 using namespace llvm;
44 
45 //===----------------------------------------------------------------------===//
46 // Primitive Helper Functions.
47 //===----------------------------------------------------------------------===//
48 
49 /// runOnMachineFunction - Emit the function body.
50 ///
53 
54  if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
55  bool Intrn = MF.getFunction()->hasInternalLinkage();
62  }
63 
64  // Have common code print out the function header with linkage info etc.
66 
67  // Emit the rest of the function body.
69 
70  // We didn't modify anything.
71  return false;
72 }
73 
74 /// printSymbolOperand - Print a raw symbol reference operand. This handles
75 /// jump tables, constant pools, global address and external symbols, all of
76 /// which print to a label with various suffixes for relocation types etc.
78  raw_ostream &O) {
79  switch (MO.getType()) {
80  default: llvm_unreachable("unknown symbol type!");
82  O << *GetJTISymbol(MO.getIndex());
83  break;
85  O << *GetCPISymbol(MO.getIndex());
86  printOffset(MO.getOffset(), O);
87  break;
89  const GlobalValue *GV = MO.getGlobal();
90 
91  MCSymbol *GVSym;
93  GVSym = GetSymbolWithGlobalValueBase(GV, "$stub");
94  else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
97  GVSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
98  else
99  GVSym = getSymbol(GV);
100 
101  // Handle dllimport linkage.
103  GVSym = OutContext.GetOrCreateSymbol(Twine("__imp_") + GVSym->getName());
104 
107  MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
109  MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
110  if (StubSym.getPointer() == 0)
111  StubSym = MachineModuleInfoImpl::
112  StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
114  MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
116  MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
117  if (StubSym.getPointer() == 0)
118  StubSym = MachineModuleInfoImpl::
119  StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
120  } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
121  MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
123  MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
124  if (StubSym.getPointer() == 0)
125  StubSym = MachineModuleInfoImpl::
126  StubValueTy(getSymbol(GV), !GV->hasInternalLinkage());
127  }
128 
129  // If the name begins with a dollar-sign, enclose it in parens. We do this
130  // to avoid having it look like an integer immediate to the assembler.
131  if (GVSym->getName()[0] != '$')
132  O << *GVSym;
133  else
134  O << '(' << *GVSym << ')';
135  printOffset(MO.getOffset(), O);
136  break;
137  }
139  const MCSymbol *SymToPrint;
141  SmallString<128> TempNameStr;
142  TempNameStr += StringRef(MO.getSymbolName());
143  TempNameStr += StringRef("$stub");
144 
145  MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
147  MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
148  if (StubSym.getPointer() == 0) {
149  TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());
150  StubSym = MachineModuleInfoImpl::
152  true);
153  }
154  SymToPrint = StubSym.getPointer();
155  } else {
156  SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName());
157  }
158 
159  // If the name begins with a dollar-sign, enclose it in parens. We do this
160  // to avoid having it look like an integer immediate to the assembler.
161  if (SymToPrint->getName()[0] != '$')
162  O << *SymToPrint;
163  else
164  O << '(' << *SymToPrint << '(';
165  break;
166  }
167  }
168 
169  switch (MO.getTargetFlags()) {
170  default:
171  llvm_unreachable("Unknown target flag on GV operand");
172  case X86II::MO_NO_FLAG: // No flag.
173  break;
175  case X86II::MO_DLLIMPORT:
177  // These affect the name of the symbol, not any suffix.
178  break;
180  O << " + [.-" << *MF->getPICBaseSymbol() << ']';
181  break;
185  O << '-' << *MF->getPICBaseSymbol();
186  break;
187  case X86II::MO_TLSGD: O << "@TLSGD"; break;
188  case X86II::MO_TLSLD: O << "@TLSLD"; break;
189  case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
190  case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
191  case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
192  case X86II::MO_TPOFF: O << "@TPOFF"; break;
193  case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
194  case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
195  case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
196  case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
197  case X86II::MO_GOT: O << "@GOT"; break;
198  case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
199  case X86II::MO_PLT: O << "@PLT"; break;
200  case X86II::MO_TLVP: O << "@TLVP"; break;
202  O << "@TLVP" << '-' << *MF->getPICBaseSymbol();
203  break;
204  case X86II::MO_SECREL: O << "@SECREL32"; break;
205  }
206 }
207 
208 /// printPCRelImm - This is used to print an immediate value that ends up
209 /// being encoded as a pc-relative value. These print slightly differently, for
210 /// example, a $ is not emitted.
211 void X86AsmPrinter::printPCRelImm(const MachineInstr *MI, unsigned OpNo,
212  raw_ostream &O) {
213  const MachineOperand &MO = MI->getOperand(OpNo);
214  switch (MO.getType()) {
215  default: llvm_unreachable("Unknown pcrel immediate operand");
217  // pc-relativeness was handled when computing the value in the reg.
218  printOperand(MI, OpNo, O);
219  return;
221  O << MO.getImm();
222  return;
224  O << *MO.getMBB()->getSymbol();
225  return;
228  printSymbolOperand(MO, O);
229  return;
230  }
231 }
232 
233 
234 void X86AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
235  raw_ostream &O, const char *Modifier,
236  unsigned AsmVariant) {
237  const MachineOperand &MO = MI->getOperand(OpNo);
238  switch (MO.getType()) {
239  default: llvm_unreachable("unknown operand type!");
241  // FIXME: Enumerating AsmVariant, so we can remove magic number.
242  if (AsmVariant == 0) O << '%';
243  unsigned Reg = MO.getReg();
244  if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
245  MVT::SimpleValueType VT = (strcmp(Modifier+6,"64") == 0) ?
246  MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
247  ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
248  Reg = getX86SubSuperRegister(Reg, VT);
249  }
251  return;
252  }
253 
255  if (AsmVariant == 0) O << '$';
256  O << MO.getImm();
257  return;
258 
263  if (AsmVariant == 0) O << '$';
264  printSymbolOperand(MO, O);
265  break;
266  }
267  }
268 }
269 
271  raw_ostream &O, const char *Modifier) {
272  const MachineOperand &BaseReg = MI->getOperand(Op);
273  const MachineOperand &IndexReg = MI->getOperand(Op+2);
274  const MachineOperand &DispSpec = MI->getOperand(Op+3);
275 
276  // If we really don't want to print out (rip), don't.
277  bool HasBaseReg = BaseReg.getReg() != 0;
278  if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
279  BaseReg.getReg() == X86::RIP)
280  HasBaseReg = false;
281 
282  // HasParenPart - True if we will print out the () part of the mem ref.
283  bool HasParenPart = IndexReg.getReg() || HasBaseReg;
284 
285  if (DispSpec.isImm()) {
286  int DispVal = DispSpec.getImm();
287  if (DispVal || !HasParenPart)
288  O << DispVal;
289  } else {
290  assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
291  DispSpec.isJTI() || DispSpec.isSymbol());
292  printSymbolOperand(MI->getOperand(Op+3), O);
293  }
294 
295  if (Modifier && strcmp(Modifier, "H") == 0)
296  O << "+8";
297 
298  if (HasParenPart) {
299  assert(IndexReg.getReg() != X86::ESP &&
300  "X86 doesn't allow scaling by ESP");
301 
302  O << '(';
303  if (HasBaseReg)
304  printOperand(MI, Op, O, Modifier);
305 
306  if (IndexReg.getReg()) {
307  O << ',';
308  printOperand(MI, Op+2, O, Modifier);
309  unsigned ScaleVal = MI->getOperand(Op+1).getImm();
310  if (ScaleVal != 1)
311  O << ',' << ScaleVal;
312  }
313  O << ')';
314  }
315 }
316 
318  raw_ostream &O, const char *Modifier) {
319  assert(isMem(MI, Op) && "Invalid memory reference!");
320  const MachineOperand &Segment = MI->getOperand(Op+4);
321  if (Segment.getReg()) {
322  printOperand(MI, Op+4, O, Modifier);
323  O << ':';
324  }
325  printLeaMemReference(MI, Op, O, Modifier);
326 }
327 
329  raw_ostream &O, const char *Modifier,
330  unsigned AsmVariant){
331  const MachineOperand &BaseReg = MI->getOperand(Op);
332  unsigned ScaleVal = MI->getOperand(Op+1).getImm();
333  const MachineOperand &IndexReg = MI->getOperand(Op+2);
334  const MachineOperand &DispSpec = MI->getOperand(Op+3);
335  const MachineOperand &SegReg = MI->getOperand(Op+4);
336 
337  // If this has a segment register, print it.
338  if (SegReg.getReg()) {
339  printOperand(MI, Op+4, O, Modifier, AsmVariant);
340  O << ':';
341  }
342 
343  O << '[';
344 
345  bool NeedPlus = false;
346  if (BaseReg.getReg()) {
347  printOperand(MI, Op, O, Modifier, AsmVariant);
348  NeedPlus = true;
349  }
350 
351  if (IndexReg.getReg()) {
352  if (NeedPlus) O << " + ";
353  if (ScaleVal != 1)
354  O << ScaleVal << '*';
355  printOperand(MI, Op+2, O, Modifier, AsmVariant);
356  NeedPlus = true;
357  }
358 
359  if (!DispSpec.isImm()) {
360  if (NeedPlus) O << " + ";
361  printOperand(MI, Op+3, O, Modifier, AsmVariant);
362  } else {
363  int64_t DispVal = DispSpec.getImm();
364  if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
365  if (NeedPlus) {
366  if (DispVal > 0)
367  O << " + ";
368  else {
369  O << " - ";
370  DispVal = -DispVal;
371  }
372  }
373  O << DispVal;
374  }
375  }
376  O << ']';
377 }
378 
380  raw_ostream &O) {
381  unsigned Reg = MO.getReg();
382  switch (Mode) {
383  default: return true; // Unknown mode.
384  case 'b': // Print QImode register
385  Reg = getX86SubSuperRegister(Reg, MVT::i8);
386  break;
387  case 'h': // Print QImode high register
388  Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
389  break;
390  case 'w': // Print HImode register
391  Reg = getX86SubSuperRegister(Reg, MVT::i16);
392  break;
393  case 'k': // Print SImode register
394  Reg = getX86SubSuperRegister(Reg, MVT::i32);
395  break;
396  case 'q': // Print DImode register
397  // FIXME: gcc will actually print e instead of r for 32-bit.
398  Reg = getX86SubSuperRegister(Reg, MVT::i64);
399  break;
400  }
401 
402  O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
403  return false;
404 }
405 
406 /// PrintAsmOperand - Print out an operand for an inline asm expression.
407 ///
408 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
409  unsigned AsmVariant,
410  const char *ExtraCode, raw_ostream &O) {
411  // Does this asm operand have a single letter operand modifier?
412  if (ExtraCode && ExtraCode[0]) {
413  if (ExtraCode[1] != 0) return true; // Unknown modifier.
414 
415  const MachineOperand &MO = MI->getOperand(OpNo);
416 
417  switch (ExtraCode[0]) {
418  default:
419  // See if this is a generic print operand
420  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
421  case 'a': // This is an address. Currently only 'i' and 'r' are expected.
422  if (MO.isImm()) {
423  O << MO.getImm();
424  return false;
425  }
426  if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) {
427  printSymbolOperand(MO, O);
428  if (Subtarget->isPICStyleRIPRel())
429  O << "(%rip)";
430  return false;
431  }
432  if (MO.isReg()) {
433  O << '(';
434  printOperand(MI, OpNo, O);
435  O << ')';
436  return false;
437  }
438  return true;
439 
440  case 'c': // Don't print "$" before a global var name or constant.
441  if (MO.isImm())
442  O << MO.getImm();
443  else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
444  printSymbolOperand(MO, O);
445  else
446  printOperand(MI, OpNo, O);
447  return false;
448 
449  case 'A': // Print '*' before a register (it must be a register)
450  if (MO.isReg()) {
451  O << '*';
452  printOperand(MI, OpNo, O);
453  return false;
454  }
455  return true;
456 
457  case 'b': // Print QImode register
458  case 'h': // Print QImode high register
459  case 'w': // Print HImode register
460  case 'k': // Print SImode register
461  case 'q': // Print DImode register
462  if (MO.isReg())
463  return printAsmMRegister(MO, ExtraCode[0], O);
464  printOperand(MI, OpNo, O);
465  return false;
466 
467  case 'P': // This is the operand of a call, treat specially.
468  printPCRelImm(MI, OpNo, O);
469  return false;
470 
471  case 'n': // Negate the immediate or print a '-' before the operand.
472  // Note: this is a temporary solution. It should be handled target
473  // independently as part of the 'MC' work.
474  if (MO.isImm()) {
475  O << -MO.getImm();
476  return false;
477  }
478  O << '-';
479  }
480  }
481 
482  printOperand(MI, OpNo, O, /*Modifier*/ 0, AsmVariant);
483  return false;
484 }
485 
487  unsigned OpNo, unsigned AsmVariant,
488  const char *ExtraCode,
489  raw_ostream &O) {
490  if (AsmVariant) {
491  printIntelMemReference(MI, OpNo, O);
492  return false;
493  }
494 
495  if (ExtraCode && ExtraCode[0]) {
496  if (ExtraCode[1] != 0) return true; // Unknown modifier.
497 
498  switch (ExtraCode[0]) {
499  default: return true; // Unknown modifier.
500  case 'b': // Print QImode register
501  case 'h': // Print QImode high register
502  case 'w': // Print HImode register
503  case 'k': // Print SImode register
504  case 'q': // Print SImode register
505  // These only apply to registers, ignore on mem.
506  break;
507  case 'H':
508  printMemReference(MI, OpNo, O, "H");
509  return false;
510  case 'P': // Don't print @PLT, but do print as memory.
511  printMemReference(MI, OpNo, O, "no-rip");
512  return false;
513  }
514  }
515  printMemReference(MI, OpNo, O);
516  return false;
517 }
518 
520  if (Subtarget->isTargetEnvMacho())
521  OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
522 
523  if (Subtarget->isTargetCOFF()) {
524  // Emit an absolute @feat.00 symbol. This appears to be some kind of
525  // compiler features bitfield read by link.exe.
526  if (!Subtarget->is64Bit()) {
527  MCSymbol *S = MMI->getContext().GetOrCreateSymbol(StringRef("@feat.00"));
532  // According to the PE-COFF spec, the LSB of this value marks the object
533  // for "registered SEH". This means that all SEH handler entry points
534  // must be registered in .sxdata. Use of any unregistered handlers will
535  // cause the process to terminate immediately. LLVM does not know how to
536  // register any SEH handlers, so its object files should be safe.
537  S->setAbsolute();
540  S, MCConstantExpr::Create(int64_t(1), MMI->getContext()));
541  }
542  }
543 }
544 
545 
547  if (Subtarget->isTargetEnvMacho()) {
548  // All darwin targets use mach-o.
549  MachineModuleInfoMachO &MMIMacho =
551 
552  // Output stubs for dynamically-linked functions.
554 
555  Stubs = MMIMacho.GetFnStubList();
556  if (!Stubs.empty()) {
557  const MCSection *TheSection =
558  OutContext.getMachOSection("__IMPORT", "__jump_table",
560  MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
561  MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
563  OutStreamer.SwitchSection(TheSection);
564 
565  for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
566  // L_foo$stub:
567  OutStreamer.EmitLabel(Stubs[i].first);
568  // .indirect_symbol _foo
569  OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(),
571  // hlt; hlt; hlt; hlt; hlt hlt = 0xf4.
572  const char HltInsts[] = "\xf4\xf4\xf4\xf4\xf4";
573  OutStreamer.EmitBytes(StringRef(HltInsts, 5));
574  }
575 
576  Stubs.clear();
578  }
579 
580  // Output stubs for external and common global variables.
581  Stubs = MMIMacho.GetGVStubList();
582  if (!Stubs.empty()) {
583  const MCSection *TheSection =
584  OutContext.getMachOSection("__IMPORT", "__pointers",
587  OutStreamer.SwitchSection(TheSection);
588 
589  for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
590  // L_foo$non_lazy_ptr:
591  OutStreamer.EmitLabel(Stubs[i].first);
592  // .indirect_symbol _foo
593  MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
596  // .long 0
597  if (MCSym.getInt())
598  // External to current translation unit.
599  OutStreamer.EmitIntValue(0, 4/*size*/);
600  else
601  // Internal to current translation unit.
602  //
603  // When we place the LSDA into the TEXT section, the type info
604  // pointers need to be indirect and pc-rel. We accomplish this by
605  // using NLPs. However, sometimes the types are local to the file. So
606  // we need to fill in the value for the NLP in those cases.
608  OutContext), 4/*size*/);
609  }
610  Stubs.clear();
612  }
613 
614  Stubs = MMIMacho.GetHiddenGVStubList();
615  if (!Stubs.empty()) {
616  OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
617  EmitAlignment(2);
618 
619  for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
620  // L_foo$non_lazy_ptr:
621  OutStreamer.EmitLabel(Stubs[i].first);
622  // .long _foo
624  Create(Stubs[i].second.getPointer(),
625  OutContext), 4/*size*/);
626  }
627  Stubs.clear();
629  }
630 
632 
633  // Funny Darwin hack: This flag tells the linker that no global symbols
634  // contain code that falls through to other global symbols (e.g. the obvious
635  // implementation of multiple entry points). If this doesn't occur, the
636  // linker can safely perform dead code stripping. Since LLVM never
637  // generates code that does this, it is always safe to set.
639  }
640 
641  if (Subtarget->isTargetWindows() && !Subtarget->isTargetCygMing() &&
643  StringRef SymbolName = Subtarget->is64Bit() ? "_fltused" : "__fltused";
644  MCSymbol *S = MMI->getContext().GetOrCreateSymbol(SymbolName);
646  }
647 
648  if (Subtarget->isTargetCOFF() && !Subtarget->isTargetEnvMacho()) {
649  X86COFFMachineModuleInfo &COFFMMI =
651 
652  // Emit type information for external functions
653  typedef X86COFFMachineModuleInfo::externals_iterator externals_iterator;
654  for (externals_iterator I = COFFMMI.externals_begin(),
655  E = COFFMMI.externals_end();
656  I != E; ++I) {
662  }
663 
664  // Necessary for dllexport support
665  std::vector<const MCSymbol*> DLLExportedFns, DLLExportedGlobals;
666 
667  const TargetLoweringObjectFileCOFF &TLOFCOFF =
668  static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
669 
670  for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
671  if (I->hasDLLExportLinkage())
672  DLLExportedFns.push_back(getSymbol(I));
673 
675  E = M.global_end(); I != E; ++I)
676  if (I->hasDLLExportLinkage())
677  DLLExportedGlobals.push_back(getSymbol(I));
678 
679  // Output linker support code for dllexported globals on windows.
680  if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) {
682  SmallString<128> name;
683  for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) {
684  if (Subtarget->isTargetWindows())
685  name = " /EXPORT:";
686  else
687  name = " -export:";
688  name += DLLExportedGlobals[i]->getName();
689  if (Subtarget->isTargetWindows())
690  name += ",DATA";
691  else
692  name += ",data";
693  OutStreamer.EmitBytes(name);
694  }
695 
696  for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) {
697  if (Subtarget->isTargetWindows())
698  name = " /EXPORT:";
699  else
700  name = " -export:";
701  name += DLLExportedFns[i]->getName();
702  OutStreamer.EmitBytes(name);
703  }
704  }
705  }
706 
707  if (Subtarget->isTargetELF()) {
708  const TargetLoweringObjectFileELF &TLOFELF =
709  static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
710 
712 
713  // Output stubs for external and common global variables.
715  if (!Stubs.empty()) {
717  const DataLayout *TD = TM.getDataLayout();
718 
719  for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
720  OutStreamer.EmitLabel(Stubs[i].first);
721  OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
722  TD->getPointerSize());
723  }
724  Stubs.clear();
725  }
726  }
727 }
728 
729 //===----------------------------------------------------------------------===//
730 // Target Registry Stuff
731 //===----------------------------------------------------------------------===//
732 
733 // Force static initialization.
734 extern "C" void LLVMInitializeX86AsmPrinter() {
737 }
int strcmp(const char *s1, const char *s2);
PointerIntPair< MCSymbol *, 1, bool > StubValueTy
void LLVMInitializeX86AsmPrinter()
const GlobalValue * getGlobal() const
static const char * getRegisterName(unsigned RegNo)
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
MachineBasicBlock * getMBB() const
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:215
bool isTargetCygMing() const
Definition: X86Subtarget.h:329
MCContext & OutContext
Definition: AsmPrinter.h:72
externals_iterator externals_begin() const
unsigned getPointerSize(unsigned AS=0) const
Definition: DataLayout.h:261
void setAbsolute()
setAbsolute - Mark the symbol as absolute.
Definition: MCSymbol.h:125
const MCSection * getDrectveSection() const
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:81
SymbolListTy GetFnStubList() const
Accessor methods to return the set of stubs in sorted order.
void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O, const char *Modifier=0, unsigned AsmVariant=0)
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:181
const char * getSymbolName() const
const Function * getFunction() const
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
SymbolListTy GetGVStubList() const
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)=0
MCSymbol * GetSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, bool ForcePrivate=true) const
Address of indexed Jump Table for switch.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) LLVM_OVERRIDE
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
MCSymbol * GetOrCreateSymbol(StringRef Name)
Definition: MCContext.cpp:118
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) LLVM_OVERRIDE
void printPCRelImm(const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
No complex type; simple scalar variable.
Definition: Support/COFF.h:203
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
#define llvm_unreachable(msg)
Target TheX86_64Target
bool hasInternalLinkage() const
Definition: GlobalValue.h:205
bool isReg() const
isReg - Tests if this is a MO_Register operand.
virtual void EmitBytes(StringRef Data)=0
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
GetJTISymbol - Return the symbol for the specified jump table entry.
void printSymbolOperand(const MachineOperand &MO, raw_ostream &O)
bool usesVAFloatArgument() const
global_iterator global_begin()
Definition: Module.h:521
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
void SwitchSection(const MCSection *Section, const MCExpr *Subsection=0)
Definition: MCStreamer.h:284
void EmitFunctionBody()
Definition: AsmPrinter.cpp:692
virtual void EmitEndOfAsmFile(Module &M) LLVM_OVERRIDE
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
Definition: X86Subtarget.h:240
bool isPICStyleRIPRel() const
Definition: X86Subtarget.h:348
MCStreamer & OutStreamer
Definition: AsmPrinter.h:78
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)=0
bool printAsmMRegister(const MachineOperand &MO, char Mode, raw_ostream &O)
int64_t getImm() const
virtual void EmitStartOfAsmFile(Module &M) LLVM_OVERRIDE
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Definition: MCStreamer.cpp:104
Address of indexed Constant in Constant Pool.
void EmitValue(const MCExpr *Value, unsigned Size)
Definition: MCStreamer.cpp:141
MachineModuleInfo * MMI
MMI - This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:84
SymbolListTy GetGVStubList() const
Accessor methods to return the set of stubs in sorted order.
virtual bool runOnMachineFunction(MachineFunction &F) LLVM_OVERRIDE
unsigned getX86SubSuperRegister(unsigned Reg, MVT::SimpleValueType VT, bool High)
externals_iterator externals_end() const
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)=0
EmitAssemblerFlag - Note in the output the specified Flag.
void printMemReference(const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=NULL)
unsigned getTargetFlags() const
void EmitFunctionHeader()
Definition: AsmPrinter.cpp:448
MCSymbol * CurrentFnSym
Definition: AsmPrinter.h:93
bool isTargetCOFF() const
Definition: X86Subtarget.h:330
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: Support/COFF.h:209
Target TheX86_32Target
TargetMachine & TM
Definition: AsmPrinter.h:62
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
EmitSymbolAttribute - Add the given Attribute to Symbol.
void printLeaMemReference(const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=NULL)
void printOffset(int64_t Offset, raw_ostream &OS) const
printOffset - This is just convenient handler for printing offsets.
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:49
A function that returns a base type.
Definition: Support/COFF.h:205
int64_t getOffset() const
IntType getInt() const
MCSymbol * getSymbol() const
void serializeToStackMapSection()
Definition: StackMaps.cpp:182
bool isTargetWindows() const
Definition: X86Subtarget.h:326
global_iterator global_end()
Definition: Module.h:523
PointerTy getPointer() const
virtual void EmitCOFFSymbolType(int Type)=0
MCSymbol * getPICBaseSymbol() const
virtual void EmitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:212
const MCContext & getContext() const
bool isTargetELF() const
Definition: X86Subtarget.h:318
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
static SectionKind getMetadata()
Definition: SectionKind.h:207
size_t strlen(const char *s);
virtual void EndCOFFSymbolDef()=0
EndCOFFSymbolDef - Marks the end of the symbol definition.
MachineOperandType getType() const
void SetupMachineFunction(MachineFunction &MF)
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:70
iterator end()
Definition: Module.h:533
.type _foo,
Definition: MCDirectives.h:30
virtual const DataLayout * getDataLayout() const
#define I(x, y, z)
Definition: MD5.cpp:54
void EmitAlignment(unsigned NumBits, const GlobalValue *GV=0) const
iterator begin()
Definition: Module.h:531
static bool isMem(const MachineInstr *MI, unsigned Op)
Definition: X86InstrInfo.h:123
void printIntelMemReference(const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=NULL, unsigned AsmVariant=1)
MCSymbol * GetCPISymbol(unsigned CPID) const
GetCPISymbol - Return the symbol for the specified constant pool entry.
unsigned getReg() const
getReg - Returns the register number.
const TargetLoweringObjectFile & getObjFileLowering() const
getObjFileLowering - Return information about object file lowering.
Definition: AsmPrinter.cpp:129
iterator end() const
Definition: StringRef.h:99
const MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K)
Definition: MCContext.cpp:215
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size)
Definition: MCStreamer.cpp:145
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
const MCSection * getDataRelSection() const
int strncmp(const char *s1, const char *s2, size_t n);
virtual void EmitCOFFSymbolStorageClass(int StorageClass)=0
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
SymbolListTy GetHiddenGVStubList() const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
MachineBasicBlock reference.
bool isTargetEnvMacho() const
Definition: X86Subtarget.h:334
Address of a global value.
Name of external global symbol.