LLVM  6.0.0svn
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"
19 #include "X86InstrInfo.h"
20 #include "X86MachineFunctionInfo.h"
21 #include "llvm/BinaryFormat/COFF.h"
26 #include "llvm/IR/DebugInfo.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Mangler.h"
29 #include "llvm/IR/Module.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/MC/MCAsmInfo.h"
32 #include "llvm/MC/MCCodeEmitter.h"
33 #include "llvm/MC/MCContext.h"
34 #include "llvm/MC/MCExpr.h"
35 #include "llvm/MC/MCSectionCOFF.h"
36 #include "llvm/MC/MCSectionMachO.h"
37 #include "llvm/MC/MCStreamer.h"
38 #include "llvm/MC/MCSymbol.h"
39 #include "llvm/Support/Debug.h"
42 using namespace llvm;
43 
45  std::unique_ptr<MCStreamer> Streamer)
46  : AsmPrinter(TM, std::move(Streamer)), SM(*this), FM(*this) {}
47 
48 //===----------------------------------------------------------------------===//
49 // Primitive Helper Functions.
50 //===----------------------------------------------------------------------===//
51 
52 /// runOnMachineFunction - Emit the function body.
53 ///
55  Subtarget = &MF.getSubtarget<X86Subtarget>();
56 
57  SMShadowTracker.startFunction(MF);
58  CodeEmitter.reset(TM.getTarget().createMCCodeEmitter(
59  *Subtarget->getInstrInfo(), *Subtarget->getRegisterInfo(),
60  MF.getContext()));
61 
62  EmitFPOData =
63  Subtarget->isTargetWin32() && MF.getMMI().getModule()->getCodeViewFlag();
64 
66 
67  if (Subtarget->isTargetCOFF()) {
68  bool Local = MF.getFunction()->hasLocalLinkage();
69  OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
70  OutStreamer->EmitCOFFSymbolStorageClass(
74  OutStreamer->EndCOFFSymbolDef();
75  }
76 
77  // Emit the rest of the function body.
79 
80  // Emit the XRay table for this function.
81  emitXRayTable();
82 
83  EmitFPOData = false;
84 
85  // We didn't modify anything.
86  return false;
87 }
88 
90  if (EmitFPOData) {
91  X86TargetStreamer *XTS =
92  static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
93  unsigned ParamsSize =
94  MF->getInfo<X86MachineFunctionInfo>()->getArgumentStackSize();
95  XTS->emitFPOProc(CurrentFnSym, ParamsSize);
96  }
97 }
98 
100  if (EmitFPOData) {
101  X86TargetStreamer *XTS =
102  static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
103  XTS->emitFPOEndProc();
104  }
105 }
106 
107 /// printSymbolOperand - Print a raw symbol reference operand. This handles
108 /// jump tables, constant pools, global address and external symbols, all of
109 /// which print to a label with various suffixes for relocation types etc.
111  raw_ostream &O) {
112  switch (MO.getType()) {
113  default: llvm_unreachable("unknown symbol type!");
115  P.GetCPISymbol(MO.getIndex())->print(O, P.MAI);
116  P.printOffset(MO.getOffset(), O);
117  break;
119  const GlobalValue *GV = MO.getGlobal();
120 
121  MCSymbol *GVSym;
124  GVSym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
125  else
126  GVSym = P.getSymbol(GV);
127 
128  // Handle dllimport linkage.
130  GVSym =
131  P.OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
132 
135  MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
137  P.MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
138  if (!StubSym.getPointer())
139  StubSym = MachineModuleInfoImpl::
140  StubValueTy(P.getSymbol(GV), !GV->hasInternalLinkage());
141  }
142 
143  // If the name begins with a dollar-sign, enclose it in parens. We do this
144  // to avoid having it look like an integer immediate to the assembler.
145  if (GVSym->getName()[0] != '$')
146  GVSym->print(O, P.MAI);
147  else {
148  O << '(';
149  GVSym->print(O, P.MAI);
150  O << ')';
151  }
152  P.printOffset(MO.getOffset(), O);
153  break;
154  }
155  }
156 
157  switch (MO.getTargetFlags()) {
158  default:
159  llvm_unreachable("Unknown target flag on GV operand");
160  case X86II::MO_NO_FLAG: // No flag.
161  break;
163  case X86II::MO_DLLIMPORT:
164  // These affect the name of the symbol, not any suffix.
165  break;
167  O << " + [.-";
168  P.MF->getPICBaseSymbol()->print(O, P.MAI);
169  O << ']';
170  break;
173  O << '-';
174  P.MF->getPICBaseSymbol()->print(O, P.MAI);
175  break;
176  case X86II::MO_TLSGD: O << "@TLSGD"; break;
177  case X86II::MO_TLSLD: O << "@TLSLD"; break;
178  case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
179  case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
180  case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
181  case X86II::MO_TPOFF: O << "@TPOFF"; break;
182  case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
183  case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
184  case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
185  case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
186  case X86II::MO_GOT: O << "@GOT"; break;
187  case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
188  case X86II::MO_PLT: O << "@PLT"; break;
189  case X86II::MO_TLVP: O << "@TLVP"; break;
191  O << "@TLVP" << '-';
192  P.MF->getPICBaseSymbol()->print(O, P.MAI);
193  break;
194  case X86II::MO_SECREL: O << "@SECREL32"; break;
195  }
196 }
197 
198 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
199  unsigned OpNo, raw_ostream &O,
200  const char *Modifier = nullptr, unsigned AsmVariant = 0);
201 
202 /// printPCRelImm - This is used to print an immediate value that ends up
203 /// being encoded as a pc-relative value. These print slightly differently, for
204 /// example, a $ is not emitted.
205 static void printPCRelImm(X86AsmPrinter &P, const MachineInstr *MI,
206  unsigned OpNo, raw_ostream &O) {
207  const MachineOperand &MO = MI->getOperand(OpNo);
208  switch (MO.getType()) {
209  default: llvm_unreachable("Unknown pcrel immediate operand");
211  // pc-relativeness was handled when computing the value in the reg.
212  printOperand(P, MI, OpNo, O);
213  return;
215  O << MO.getImm();
216  return;
218  printSymbolOperand(P, MO, O);
219  return;
220  }
221 }
222 
223 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
224  unsigned OpNo, raw_ostream &O, const char *Modifier,
225  unsigned AsmVariant) {
226  const MachineOperand &MO = MI->getOperand(OpNo);
227  switch (MO.getType()) {
228  default: llvm_unreachable("unknown operand type!");
230  // FIXME: Enumerating AsmVariant, so we can remove magic number.
231  if (AsmVariant == 0) O << '%';
232  unsigned Reg = MO.getReg();
233  if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
234  unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
235  (strcmp(Modifier+6,"32") == 0) ? 32 :
236  (strcmp(Modifier+6,"16") == 0) ? 16 : 8;
237  Reg = getX86SubSuperRegister(Reg, Size);
238  }
240  return;
241  }
242 
244  if (AsmVariant == 0) O << '$';
245  O << MO.getImm();
246  return;
247 
249  if (AsmVariant == 0) O << '$';
250  printSymbolOperand(P, MO, O);
251  break;
252  }
253  }
254 }
255 
257  unsigned Op, raw_ostream &O,
258  const char *Modifier = nullptr) {
259  const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
260  const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
261  const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
262 
263  // If we really don't want to print out (rip), don't.
264  bool HasBaseReg = BaseReg.getReg() != 0;
265  if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
266  BaseReg.getReg() == X86::RIP)
267  HasBaseReg = false;
268 
269  // HasParenPart - True if we will print out the () part of the mem ref.
270  bool HasParenPart = IndexReg.getReg() || HasBaseReg;
271 
272  switch (DispSpec.getType()) {
273  default:
274  llvm_unreachable("unknown operand type!");
276  int DispVal = DispSpec.getImm();
277  if (DispVal || !HasParenPart)
278  O << DispVal;
279  break;
280  }
283  printSymbolOperand(P, DispSpec, O);
284  }
285 
286  if (Modifier && strcmp(Modifier, "H") == 0)
287  O << "+8";
288 
289  if (HasParenPart) {
290  assert(IndexReg.getReg() != X86::ESP &&
291  "X86 doesn't allow scaling by ESP");
292 
293  O << '(';
294  if (HasBaseReg)
295  printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier);
296 
297  if (IndexReg.getReg()) {
298  O << ',';
299  printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier);
300  unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
301  if (ScaleVal != 1)
302  O << ',' << ScaleVal;
303  }
304  O << ')';
305  }
306 }
307 
308 static void printMemReference(X86AsmPrinter &P, const MachineInstr *MI,
309  unsigned Op, raw_ostream &O,
310  const char *Modifier = nullptr) {
311  assert(isMem(*MI, Op) && "Invalid memory reference!");
312  const MachineOperand &Segment = MI->getOperand(Op+X86::AddrSegmentReg);
313  if (Segment.getReg()) {
314  printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier);
315  O << ':';
316  }
317  printLeaMemReference(P, MI, Op, O, Modifier);
318 }
319 
321  unsigned Op, raw_ostream &O,
322  const char *Modifier = nullptr,
323  unsigned AsmVariant = 1) {
324  const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
325  unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
326  const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
327  const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
328  const MachineOperand &SegReg = MI->getOperand(Op+X86::AddrSegmentReg);
329 
330  // If this has a segment register, print it.
331  if (SegReg.getReg()) {
332  printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier, AsmVariant);
333  O << ':';
334  }
335 
336  O << '[';
337 
338  bool NeedPlus = false;
339  if (BaseReg.getReg()) {
340  printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier, AsmVariant);
341  NeedPlus = true;
342  }
343 
344  if (IndexReg.getReg()) {
345  if (NeedPlus) O << " + ";
346  if (ScaleVal != 1)
347  O << ScaleVal << '*';
348  printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier, AsmVariant);
349  NeedPlus = true;
350  }
351 
352  if (!DispSpec.isImm()) {
353  if (NeedPlus) O << " + ";
354  printOperand(P, MI, Op+X86::AddrDisp, O, Modifier, AsmVariant);
355  } else {
356  int64_t DispVal = DispSpec.getImm();
357  if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
358  if (NeedPlus) {
359  if (DispVal > 0)
360  O << " + ";
361  else {
362  O << " - ";
363  DispVal = -DispVal;
364  }
365  }
366  O << DispVal;
367  }
368  }
369  O << ']';
370 }
371 
373  char Mode, raw_ostream &O) {
374  unsigned Reg = MO.getReg();
375  switch (Mode) {
376  default: return true; // Unknown mode.
377  case 'b': // Print QImode register
378  Reg = getX86SubSuperRegister(Reg, 8);
379  break;
380  case 'h': // Print QImode high register
381  Reg = getX86SubSuperRegister(Reg, 8, true);
382  break;
383  case 'w': // Print HImode register
384  Reg = getX86SubSuperRegister(Reg, 16);
385  break;
386  case 'k': // Print SImode register
387  Reg = getX86SubSuperRegister(Reg, 32);
388  break;
389  case 'q':
390  // Print 64-bit register names if 64-bit integer registers are available.
391  // Otherwise, print 32-bit register names.
392  Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
393  break;
394  }
395 
396  O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
397  return false;
398 }
399 
400 /// PrintAsmOperand - Print out an operand for an inline asm expression.
401 ///
402 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
403  unsigned AsmVariant,
404  const char *ExtraCode, raw_ostream &O) {
405  // Does this asm operand have a single letter operand modifier?
406  if (ExtraCode && ExtraCode[0]) {
407  if (ExtraCode[1] != 0) return true; // Unknown modifier.
408 
409  const MachineOperand &MO = MI->getOperand(OpNo);
410 
411  switch (ExtraCode[0]) {
412  default:
413  // See if this is a generic print operand
414  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
415  case 'a': // This is an address. Currently only 'i' and 'r' are expected.
416  switch (MO.getType()) {
417  default:
418  return true;
420  O << MO.getImm();
421  return false;
425  llvm_unreachable("unexpected operand type!");
427  printSymbolOperand(*this, MO, O);
428  if (Subtarget->isPICStyleRIPRel())
429  O << "(%rip)";
430  return false;
432  O << '(';
433  printOperand(*this, MI, OpNo, O);
434  O << ')';
435  return false;
436  }
437 
438  case 'c': // Don't print "$" before a global var name or constant.
439  switch (MO.getType()) {
440  default:
441  printOperand(*this, MI, OpNo, O);
442  break;
444  O << MO.getImm();
445  break;
449  llvm_unreachable("unexpected operand type!");
451  printSymbolOperand(*this, MO, O);
452  break;
453  }
454  return false;
455 
456  case 'A': // Print '*' before a register (it must be a register)
457  if (MO.isReg()) {
458  O << '*';
459  printOperand(*this, MI, OpNo, O);
460  return false;
461  }
462  return true;
463 
464  case 'b': // Print QImode register
465  case 'h': // Print QImode high register
466  case 'w': // Print HImode register
467  case 'k': // Print SImode register
468  case 'q': // Print DImode register
469  if (MO.isReg())
470  return printAsmMRegister(*this, MO, ExtraCode[0], O);
471  printOperand(*this, MI, OpNo, O);
472  return false;
473 
474  case 'P': // This is the operand of a call, treat specially.
475  printPCRelImm(*this, MI, OpNo, O);
476  return false;
477 
478  case 'n': // Negate the immediate or print a '-' before the operand.
479  // Note: this is a temporary solution. It should be handled target
480  // independently as part of the 'MC' work.
481  if (MO.isImm()) {
482  O << -MO.getImm();
483  return false;
484  }
485  O << '-';
486  }
487  }
488 
489  printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr, AsmVariant);
490  return false;
491 }
492 
494  unsigned OpNo, unsigned AsmVariant,
495  const char *ExtraCode,
496  raw_ostream &O) {
497  if (AsmVariant) {
498  printIntelMemReference(*this, MI, OpNo, O);
499  return false;
500  }
501 
502  if (ExtraCode && ExtraCode[0]) {
503  if (ExtraCode[1] != 0) return true; // Unknown modifier.
504 
505  switch (ExtraCode[0]) {
506  default: return true; // Unknown modifier.
507  case 'b': // Print QImode register
508  case 'h': // Print QImode high register
509  case 'w': // Print HImode register
510  case 'k': // Print SImode register
511  case 'q': // Print SImode register
512  // These only apply to registers, ignore on mem.
513  break;
514  case 'H':
515  printMemReference(*this, MI, OpNo, O, "H");
516  return false;
517  case 'P': // Don't print @PLT, but do print as memory.
518  printMemReference(*this, MI, OpNo, O, "no-rip");
519  return false;
520  }
521  }
522  printMemReference(*this, MI, OpNo, O);
523  return false;
524 }
525 
527  const Triple &TT = TM.getTargetTriple();
528 
529  if (TT.isOSBinFormatMachO())
530  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
531 
532  if (TT.isOSBinFormatCOFF()) {
533  // Emit an absolute @feat.00 symbol. This appears to be some kind of
534  // compiler features bitfield read by link.exe.
535  if (TT.getArch() == Triple::x86) {
536  MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
537  OutStreamer->BeginCOFFSymbolDef(S);
538  OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
539  OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
540  OutStreamer->EndCOFFSymbolDef();
541  // According to the PE-COFF spec, the LSB of this value marks the object
542  // for "registered SEH". This means that all SEH handler entry points
543  // must be registered in .sxdata. Use of any unregistered handlers will
544  // cause the process to terminate immediately. LLVM does not know how to
545  // register any SEH handlers, so its object files should be safe.
546  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
547  OutStreamer->EmitAssignment(
548  S, MCConstantExpr::create(int64_t(1), MMI->getContext()));
549  }
550  }
551  OutStreamer->EmitSyntaxDirective();
552 
553  // If this is not inline asm and we're in 16-bit
554  // mode prefix assembly with .code16.
555  bool is16 = TT.getEnvironment() == Triple::CODE16;
556  if (M.getModuleInlineAsm().empty() && is16)
557  OutStreamer->EmitAssemblerFlag(MCAF_Code16);
558 }
559 
560 static void
563  // L_foo$stub:
564  OutStreamer.EmitLabel(StubLabel);
565  // .indirect_symbol _foo
566  OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
567 
568  if (MCSym.getInt())
569  // External to current translation unit.
570  OutStreamer.EmitIntValue(0, 4/*size*/);
571  else
572  // Internal to current translation unit.
573  //
574  // When we place the LSDA into the TEXT section, the type info
575  // pointers need to be indirect and pc-rel. We accomplish this by
576  // using NLPs; however, sometimes the types are local to the file.
577  // We need to fill in the value for the NLP in those cases.
578  OutStreamer.EmitValue(
579  MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
580  4 /*size*/);
581 }
582 
583 MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {
584  if (Subtarget->isTargetKnownWindowsMSVC()) {
585  const MachineConstantPoolEntry &CPE =
586  MF->getConstantPool()->getConstants()[CPID];
587  if (!CPE.isMachineConstantPoolEntry()) {
588  const DataLayout &DL = MF->getDataLayout();
589  SectionKind Kind = CPE.getSectionKind(&DL);
590  const Constant *C = CPE.Val.ConstVal;
591  unsigned Align = CPE.Alignment;
592  if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
593  getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
594  if (MCSymbol *Sym = S->getCOMDATSymbol()) {
595  if (Sym->isUndefined())
596  OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
597  return Sym;
598  }
599  }
600  }
601  }
602 
603  return AsmPrinter::GetCPISymbol(CPID);
604 }
605 
607  const Triple &TT = TM.getTargetTriple();
608 
609  if (TT.isOSBinFormatMachO()) {
610  // All darwin targets use mach-o.
611  MachineModuleInfoMachO &MMIMacho =
613 
614  // Output stubs for dynamically-linked functions.
616 
617  // Output stubs for external and common global variables.
618  Stubs = MMIMacho.GetGVStubList();
619  if (!Stubs.empty()) {
620  MCSection *TheSection = OutContext.getMachOSection(
621  "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
623  OutStreamer->SwitchSection(TheSection);
624 
625  for (auto &Stub : Stubs)
626  emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
627 
628  Stubs.clear();
629  OutStreamer->AddBlankLine();
630  }
631 
634 
635  // Funny Darwin hack: This flag tells the linker that no global symbols
636  // contain code that falls through to other global symbols (e.g. the obvious
637  // implementation of multiple entry points). If this doesn't occur, the
638  // linker can safely perform dead code stripping. Since LLVM never
639  // generates code that does this, it is always safe to set.
640  OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
641  }
642 
645  (TT.getArch() == Triple::x86_64) ? "_fltused" : "__fltused";
646  MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
647  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
648  }
649 
650  if (TT.isOSBinFormatCOFF()) {
651  const TargetLoweringObjectFileCOFF &TLOFCOFF =
652  static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
653 
654  std::string Flags;
655  raw_string_ostream FlagsOS(Flags);
656 
657  for (const auto &Function : M)
658  TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Function);
659  for (const auto &Global : M.globals())
660  TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Global);
661  for (const auto &Alias : M.aliases())
662  TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Alias);
663 
664  FlagsOS.flush();
665 
666  // Output collected flags.
667  if (!Flags.empty()) {
668  OutStreamer->SwitchSection(TLOFCOFF.getDrectveSection());
669  OutStreamer->EmitBytes(Flags);
670  }
671 
673  }
674 
675  if (TT.isOSBinFormatELF()) {
678  }
679 }
680 
681 //===----------------------------------------------------------------------===//
682 // Target Registry Stuff
683 //===----------------------------------------------------------------------===//
684 
685 // Force static initialization.
686 extern "C" void LLVMInitializeX86AsmPrinter() {
689 }
unsigned getTargetFlags() const
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
Definition: X86BaseInfo.h:225
uint64_t CallInst * C
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:205
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
Definition: X86Subtarget.h:412
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
SymbolListTy GetGVStubList()
Accessor methods to return the set of stubs in sorted order.
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition: MachO.h:132
static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO, char Mode, raw_ostream &O)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
void LLVMInitializeX86AsmPrinter()
bool hasLocalLinkage() const
Definition: GlobalValue.h:427
static const char * getRegisterName(unsigned RegNo)
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:92
SI Whole Quad Mode
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:305
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
PointerTy getPointer() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const override
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:133
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
Definition: X86BaseInfo.h:219
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:588
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:87
const X86InstrInfo * getInstrInfo() const override
Definition: X86Subtarget.h:370
AddrSegmentReg - The operand # of the segment in the memory operand.
Definition: X86BaseInfo.h:39
unsigned getReg() const
getReg - Returns the register number.
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - Emit the function body.
Address of indexed Jump Table for switch.
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:95
MachineModuleInfo & getMMI() const
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
Definition: X86BaseInfo.h:107
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:176
static void printSymbolOperand(X86AsmPrinter &P, const MachineOperand &MO, raw_ostream &O)
printSymbolOperand - Print a raw symbol reference operand.
bool isTargetKnownWindowsMSVC() const
Definition: X86Subtarget.h:567
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
union llvm::MachineConstantPoolEntry::@140 Val
The constant itself.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
This represents a section on Windows.
Definition: MCSectionCOFF.h:27
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MCContext & getContext() const
Definition: MCStreamer.h:234
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
Definition: X86BaseInfo.h:207
Definition: BitVector.h:920
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static void printPCRelImm(X86AsmPrinter &P, const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
printPCRelImm - This is used to print an immediate value that ends up being encoded as a pc-relative ...
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
bool isPICStyleRIPRel() const
Definition: X86Subtarget.h:596
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
No complex type; simple scalar variable.
Definition: COFF.h:257
bool isKnownWindowsMSVCEnvironment() const
Checks if the environment is MSVC.
Definition: Triple.h:530
Name of external global symbol.
Reg
All possible values of the reg field in the ModR/M byte.
static bool isMem(const MachineInstr &MI, unsigned Op)
Definition: X86InstrInfo.h:137
virtual bool emitFPOProc(const MCSymbol *ProcSym, unsigned ParamsSize, SMLoc L={})=0
void emitXRayTable()
Emit a table with all XRay instrumentation points.
void EmitFunctionBody()
This method emits the body and trailer for a function.
Definition: AsmPrinter.cpp:982
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:51
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:271
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
Definition: X86BaseInfo.h:92
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
IntType getInt() const
const MCContext & getContext() const
static void printLeaMemReference(X86AsmPrinter &P, const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=nullptr)
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
Definition: X86BaseInfo.h:151
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym)
This class is a data container for one entry in a MachineConstantPool.
static void printOperand(X86AsmPrinter &P, const MachineInstr *MI, unsigned OpNo, raw_ostream &O, const char *Modifier=nullptr, unsigned AsmVariant=0)
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, const MCRegisterInfo &MRI, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
PrintAsmOperand - Print out an operand for an inline asm expression.
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:88
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:202
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:123
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:98
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Definition: Module.cpp:460
MCContext & getContext() const
#define P(N)
Address of a global value.
Streaming machine code generation interface.
Definition: MCStreamer.h:169
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:105
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [...
Definition: X86BaseInfo.h:80
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:83
PointerIntPair - This class implements a pair of a pointer and small integer.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:593
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
Definition: X86BaseInfo.h:192
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
Definition: X86BaseInfo.h:213
This is an important base class in LLVM.
Definition: Constant.h:42
const GlobalValue * getGlobal() const
MO_TLSLDM - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:143
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: COFF.h:263
void EmitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:80
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:77
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
bool hasInternalLinkage() const
Definition: GlobalValue.h:425
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:50
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
A function that returns a base type.
Definition: COFF.h:259
const Triple & getTargetTriple() const
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
Definition: X86BaseInfo.h:184
Ty & getObjFileInfo()
Keep track of various per-function pieces of information for backends that would like to do so...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:598
const Target & getTarget() const
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:123
MCSection * getDrectveSection() const
void serializeToStackMapSection()
If there is any stack map data, create a stack map section and serialize the map info into it...
Definition: StackMaps.cpp:550
const std::vector< MachineConstantPoolEntry > & getConstants() const
const X86RegisterInfo * getRegisterInfo() const override
Definition: X86Subtarget.h:380
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
Definition: X86BaseInfo.h:168
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
unsigned Alignment
The required alignment for this entry.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:433
void serializeToFaultMapSection()
Definition: FaultMaps.cpp:50
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
void EmitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
static SectionKind getMetadata()
Definition: SectionKind.h:179
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:303
bool isTargetWin32() const
Definition: X86Subtarget.h:593
X86 target streamer implementing x86-only assembly directives.
int64_t getImm() const
unsigned getX86SubSuperRegister(unsigned, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
MCSymbol * GetCPISymbol(unsigned CPID) const override
Return the symbol for the specified constant pool entry.
static void printMemReference(X86AsmPrinter &P, const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=nullptr)
Representation of each machine instruction.
Definition: MachineInstr.h:59
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
Definition: X86BaseInfo.h:99
void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
MO_INDNTPOFF - On a symbol operand this indicates that the immediate is the absolute address of the G...
Definition: X86BaseInfo.h:160
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:121
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
static void printIntelMemReference(X86AsmPrinter &P, const MachineInstr *MI, unsigned Op, raw_ostream &O, const char *Modifier=nullptr, unsigned AsmVariant=1)
int64_t getOffset() const
Return the offset from the symbol in this operand.
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
SectionKind getSectionKind(const DataLayout *DL) const
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:123
bool isTargetCOFF() const
Definition: X86Subtarget.h:550
Target & getTheX86_32Target()
const Module * getModule() const
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
MO_PLT - On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol n...
Definition: X86BaseInfo.h:114
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition: Module.h:241
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:462
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MCSymbol * getPICBaseSymbol() const
getPICBaseSymbol - Return a function-local symbol to represent the PIC base.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:300
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:57
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
Definition: X86BaseInfo.h:85
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Address of indexed Constant in Constant Pool.
X86AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:295
Target & getTheX86_64Target()
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
This class can be derived from and used by targets to hold private target-specific information for ea...
const X86Subtarget & getSubtarget() const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:159
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
Definition: X86BaseInfo.h:197
virtual bool emitFPOEndProc(SMLoc L={})=0
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59