LLVM  7.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"
25 #include "llvm/IR/DerivedTypes.h"
26 #include "llvm/IR/Mangler.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/IR/Type.h"
29 #include "llvm/MC/MCCodeEmitter.h"
30 #include "llvm/MC/MCContext.h"
31 #include "llvm/MC/MCExpr.h"
32 #include "llvm/MC/MCSectionCOFF.h"
33 #include "llvm/MC/MCSectionMachO.h"
34 #include "llvm/MC/MCStreamer.h"
35 #include "llvm/MC/MCSymbol.h"
36 #include "llvm/Support/Debug.h"
40 using namespace llvm;
41 
43  std::unique_ptr<MCStreamer> Streamer)
44  : AsmPrinter(TM, std::move(Streamer)), SM(*this), FM(*this) {}
45 
46 //===----------------------------------------------------------------------===//
47 // Primitive Helper Functions.
48 //===----------------------------------------------------------------------===//
49 
50 /// runOnMachineFunction - Emit the function body.
51 ///
53  Subtarget = &MF.getSubtarget<X86Subtarget>();
54 
55  SMShadowTracker.startFunction(MF);
56  CodeEmitter.reset(TM.getTarget().createMCCodeEmitter(
57  *Subtarget->getInstrInfo(), *Subtarget->getRegisterInfo(),
58  MF.getContext()));
59 
60  EmitFPOData =
61  Subtarget->isTargetWin32() && MF.getMMI().getModule()->getCodeViewFlag();
62 
64 
65  if (Subtarget->isTargetCOFF()) {
66  bool Local = MF.getFunction().hasLocalLinkage();
67  OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
68  OutStreamer->EmitCOFFSymbolStorageClass(
72  OutStreamer->EndCOFFSymbolDef();
73  }
74 
75  // Emit the rest of the function body.
77 
78  // Emit the XRay table for this function.
79  emitXRayTable();
80 
81  EmitFPOData = false;
82 
83  // We didn't modify anything.
84  return false;
85 }
86 
88  if (EmitFPOData) {
89  X86TargetStreamer *XTS =
90  static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
91  unsigned ParamsSize =
92  MF->getInfo<X86MachineFunctionInfo>()->getArgumentStackSize();
93  XTS->emitFPOProc(CurrentFnSym, ParamsSize);
94  }
95 }
96 
98  if (EmitFPOData) {
99  X86TargetStreamer *XTS =
100  static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
101  XTS->emitFPOEndProc();
102  }
103 }
104 
105 /// printSymbolOperand - Print a raw symbol reference operand. This handles
106 /// jump tables, constant pools, global address and external symbols, all of
107 /// which print to a label with various suffixes for relocation types etc.
109  raw_ostream &O) {
110  switch (MO.getType()) {
111  default: llvm_unreachable("unknown symbol type!");
113  P.GetCPISymbol(MO.getIndex())->print(O, P.MAI);
114  P.printOffset(MO.getOffset(), O);
115  break;
117  const GlobalValue *GV = MO.getGlobal();
118 
119  MCSymbol *GVSym;
122  GVSym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
123  else
124  GVSym = P.getSymbol(GV);
125 
126  // Handle dllimport linkage.
128  GVSym =
129  P.OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
130 
133  MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
135  P.MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
136  if (!StubSym.getPointer())
137  StubSym = MachineModuleInfoImpl::
138  StubValueTy(P.getSymbol(GV), !GV->hasInternalLinkage());
139  }
140 
141  // If the name begins with a dollar-sign, enclose it in parens. We do this
142  // to avoid having it look like an integer immediate to the assembler.
143  if (GVSym->getName()[0] != '$')
144  GVSym->print(O, P.MAI);
145  else {
146  O << '(';
147  GVSym->print(O, P.MAI);
148  O << ')';
149  }
150  P.printOffset(MO.getOffset(), O);
151  break;
152  }
153  }
154 
155  switch (MO.getTargetFlags()) {
156  default:
157  llvm_unreachable("Unknown target flag on GV operand");
158  case X86II::MO_NO_FLAG: // No flag.
159  break;
161  case X86II::MO_DLLIMPORT:
162  // These affect the name of the symbol, not any suffix.
163  break;
165  O << " + [.-";
166  P.MF->getPICBaseSymbol()->print(O, P.MAI);
167  O << ']';
168  break;
171  O << '-';
172  P.MF->getPICBaseSymbol()->print(O, P.MAI);
173  break;
174  case X86II::MO_TLSGD: O << "@TLSGD"; break;
175  case X86II::MO_TLSLD: O << "@TLSLD"; break;
176  case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
177  case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
178  case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
179  case X86II::MO_TPOFF: O << "@TPOFF"; break;
180  case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
181  case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
182  case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
183  case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
184  case X86II::MO_GOT: O << "@GOT"; break;
185  case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
186  case X86II::MO_PLT: O << "@PLT"; break;
187  case X86II::MO_TLVP: O << "@TLVP"; break;
189  O << "@TLVP" << '-';
190  P.MF->getPICBaseSymbol()->print(O, P.MAI);
191  break;
192  case X86II::MO_SECREL: O << "@SECREL32"; break;
193  }
194 }
195 
196 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
197  unsigned OpNo, raw_ostream &O,
198  const char *Modifier = nullptr, unsigned AsmVariant = 0);
199 
200 /// printPCRelImm - This is used to print an immediate value that ends up
201 /// being encoded as a pc-relative value. These print slightly differently, for
202 /// example, a $ is not emitted.
203 static void printPCRelImm(X86AsmPrinter &P, const MachineInstr *MI,
204  unsigned OpNo, raw_ostream &O) {
205  const MachineOperand &MO = MI->getOperand(OpNo);
206  switch (MO.getType()) {
207  default: llvm_unreachable("Unknown pcrel immediate operand");
209  // pc-relativeness was handled when computing the value in the reg.
210  printOperand(P, MI, OpNo, O);
211  return;
213  O << MO.getImm();
214  return;
216  printSymbolOperand(P, MO, O);
217  return;
218  }
219 }
220 
221 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
222  unsigned OpNo, raw_ostream &O, const char *Modifier,
223  unsigned AsmVariant) {
224  const MachineOperand &MO = MI->getOperand(OpNo);
225  switch (MO.getType()) {
226  default: llvm_unreachable("unknown operand type!");
228  // FIXME: Enumerating AsmVariant, so we can remove magic number.
229  if (AsmVariant == 0) O << '%';
230  unsigned Reg = MO.getReg();
231  if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
232  unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
233  (strcmp(Modifier+6,"32") == 0) ? 32 :
234  (strcmp(Modifier+6,"16") == 0) ? 16 : 8;
235  Reg = getX86SubSuperRegister(Reg, Size);
236  }
238  return;
239  }
240 
242  if (AsmVariant == 0) O << '$';
243  O << MO.getImm();
244  return;
245 
247  if (AsmVariant == 0) O << '$';
248  printSymbolOperand(P, MO, O);
249  break;
250  }
251  }
252 }
253 
255  unsigned Op, raw_ostream &O,
256  const char *Modifier = nullptr) {
257  const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
258  const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
259  const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
260 
261  // If we really don't want to print out (rip), don't.
262  bool HasBaseReg = BaseReg.getReg() != 0;
263  if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
264  BaseReg.getReg() == X86::RIP)
265  HasBaseReg = false;
266 
267  // HasParenPart - True if we will print out the () part of the mem ref.
268  bool HasParenPart = IndexReg.getReg() || HasBaseReg;
269 
270  switch (DispSpec.getType()) {
271  default:
272  llvm_unreachable("unknown operand type!");
274  int DispVal = DispSpec.getImm();
275  if (DispVal || !HasParenPart)
276  O << DispVal;
277  break;
278  }
281  printSymbolOperand(P, DispSpec, O);
282  }
283 
284  if (Modifier && strcmp(Modifier, "H") == 0)
285  O << "+8";
286 
287  if (HasParenPart) {
288  assert(IndexReg.getReg() != X86::ESP &&
289  "X86 doesn't allow scaling by ESP");
290 
291  O << '(';
292  if (HasBaseReg)
293  printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier);
294 
295  if (IndexReg.getReg()) {
296  O << ',';
297  printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier);
298  unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
299  if (ScaleVal != 1)
300  O << ',' << ScaleVal;
301  }
302  O << ')';
303  }
304 }
305 
306 static void printMemReference(X86AsmPrinter &P, const MachineInstr *MI,
307  unsigned Op, raw_ostream &O,
308  const char *Modifier = nullptr) {
309  assert(isMem(*MI, Op) && "Invalid memory reference!");
310  const MachineOperand &Segment = MI->getOperand(Op+X86::AddrSegmentReg);
311  if (Segment.getReg()) {
312  printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier);
313  O << ':';
314  }
315  printLeaMemReference(P, MI, Op, O, Modifier);
316 }
317 
319  unsigned Op, raw_ostream &O,
320  const char *Modifier = nullptr,
321  unsigned AsmVariant = 1) {
322  const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
323  unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
324  const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
325  const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
326  const MachineOperand &SegReg = MI->getOperand(Op+X86::AddrSegmentReg);
327 
328  // If this has a segment register, print it.
329  if (SegReg.getReg()) {
330  printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier, AsmVariant);
331  O << ':';
332  }
333 
334  O << '[';
335 
336  bool NeedPlus = false;
337  if (BaseReg.getReg()) {
338  printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier, AsmVariant);
339  NeedPlus = true;
340  }
341 
342  if (IndexReg.getReg()) {
343  if (NeedPlus) O << " + ";
344  if (ScaleVal != 1)
345  O << ScaleVal << '*';
346  printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier, AsmVariant);
347  NeedPlus = true;
348  }
349 
350  if (!DispSpec.isImm()) {
351  if (NeedPlus) O << " + ";
352  printOperand(P, MI, Op+X86::AddrDisp, O, Modifier, AsmVariant);
353  } else {
354  int64_t DispVal = DispSpec.getImm();
355  if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
356  if (NeedPlus) {
357  if (DispVal > 0)
358  O << " + ";
359  else {
360  O << " - ";
361  DispVal = -DispVal;
362  }
363  }
364  O << DispVal;
365  }
366  }
367  O << ']';
368 }
369 
371  char Mode, raw_ostream &O) {
372  unsigned Reg = MO.getReg();
373  bool EmitPercent = true;
374 
375  if (!X86::GR8RegClass.contains(Reg) &&
376  !X86::GR16RegClass.contains(Reg) &&
377  !X86::GR32RegClass.contains(Reg) &&
378  !X86::GR64RegClass.contains(Reg))
379  return true;
380 
381  switch (Mode) {
382  default: return true; // Unknown mode.
383  case 'b': // Print QImode register
384  Reg = getX86SubSuperRegister(Reg, 8);
385  break;
386  case 'h': // Print QImode high register
387  Reg = getX86SubSuperRegister(Reg, 8, true);
388  break;
389  case 'w': // Print HImode register
390  Reg = getX86SubSuperRegister(Reg, 16);
391  break;
392  case 'k': // Print SImode register
393  Reg = getX86SubSuperRegister(Reg, 32);
394  break;
395  case 'V':
396  EmitPercent = false;
398  case 'q':
399  // Print 64-bit register names if 64-bit integer registers are available.
400  // Otherwise, print 32-bit register names.
401  Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
402  break;
403  }
404 
405  if (EmitPercent)
406  O << '%';
407 
409  return false;
410 }
411 
412 /// PrintAsmOperand - Print out an operand for an inline asm expression.
413 ///
414 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
415  unsigned AsmVariant,
416  const char *ExtraCode, raw_ostream &O) {
417  // Does this asm operand have a single letter operand modifier?
418  if (ExtraCode && ExtraCode[0]) {
419  if (ExtraCode[1] != 0) return true; // Unknown modifier.
420 
421  const MachineOperand &MO = MI->getOperand(OpNo);
422 
423  switch (ExtraCode[0]) {
424  default:
425  // See if this is a generic print operand
426  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
427  case 'a': // This is an address. Currently only 'i' and 'r' are expected.
428  switch (MO.getType()) {
429  default:
430  return true;
432  O << MO.getImm();
433  return false;
437  llvm_unreachable("unexpected operand type!");
439  printSymbolOperand(*this, MO, O);
440  if (Subtarget->isPICStyleRIPRel())
441  O << "(%rip)";
442  return false;
444  O << '(';
445  printOperand(*this, MI, OpNo, O);
446  O << ')';
447  return false;
448  }
449 
450  case 'c': // Don't print "$" before a global var name or constant.
451  switch (MO.getType()) {
452  default:
453  printOperand(*this, MI, OpNo, O);
454  break;
456  O << MO.getImm();
457  break;
461  llvm_unreachable("unexpected operand type!");
463  printSymbolOperand(*this, MO, O);
464  break;
465  }
466  return false;
467 
468  case 'A': // Print '*' before a register (it must be a register)
469  if (MO.isReg()) {
470  O << '*';
471  printOperand(*this, MI, OpNo, O);
472  return false;
473  }
474  return true;
475 
476  case 'b': // Print QImode register
477  case 'h': // Print QImode high register
478  case 'w': // Print HImode register
479  case 'k': // Print SImode register
480  case 'q': // Print DImode register
481  case 'V': // Print native register without '%'
482  if (MO.isReg())
483  return printAsmMRegister(*this, MO, ExtraCode[0], O);
484  printOperand(*this, MI, OpNo, O);
485  return false;
486 
487  case 'P': // This is the operand of a call, treat specially.
488  printPCRelImm(*this, MI, OpNo, O);
489  return false;
490 
491  case 'n': // Negate the immediate or print a '-' before the operand.
492  // Note: this is a temporary solution. It should be handled target
493  // independently as part of the 'MC' work.
494  if (MO.isImm()) {
495  O << -MO.getImm();
496  return false;
497  }
498  O << '-';
499  }
500  }
501 
502  printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr, AsmVariant);
503  return false;
504 }
505 
507  unsigned OpNo, unsigned AsmVariant,
508  const char *ExtraCode,
509  raw_ostream &O) {
510  if (AsmVariant) {
511  printIntelMemReference(*this, MI, OpNo, O);
512  return false;
513  }
514 
515  if (ExtraCode && ExtraCode[0]) {
516  if (ExtraCode[1] != 0) return true; // Unknown modifier.
517 
518  switch (ExtraCode[0]) {
519  default: return true; // Unknown modifier.
520  case 'b': // Print QImode register
521  case 'h': // Print QImode high register
522  case 'w': // Print HImode register
523  case 'k': // Print SImode register
524  case 'q': // Print SImode register
525  // These only apply to registers, ignore on mem.
526  break;
527  case 'H':
528  printMemReference(*this, MI, OpNo, O, "H");
529  return false;
530  case 'P': // Don't print @PLT, but do print as memory.
531  printMemReference(*this, MI, OpNo, O, "no-rip");
532  return false;
533  }
534  }
535  printMemReference(*this, MI, OpNo, O);
536  return false;
537 }
538 
540  const Triple &TT = TM.getTargetTriple();
541 
542  if (TT.isOSBinFormatMachO())
543  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
544 
545  if (TT.isOSBinFormatCOFF()) {
546  // Emit an absolute @feat.00 symbol. This appears to be some kind of
547  // compiler features bitfield read by link.exe.
548  if (TT.getArch() == Triple::x86) {
549  MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
550  OutStreamer->BeginCOFFSymbolDef(S);
551  OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
552  OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
553  OutStreamer->EndCOFFSymbolDef();
554  // According to the PE-COFF spec, the LSB of this value marks the object
555  // for "registered SEH". This means that all SEH handler entry points
556  // must be registered in .sxdata. Use of any unregistered handlers will
557  // cause the process to terminate immediately. LLVM does not know how to
558  // register any SEH handlers, so its object files should be safe.
559  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
560  OutStreamer->EmitAssignment(
561  S, MCConstantExpr::create(int64_t(1), MMI->getContext()));
562  }
563  }
564  OutStreamer->EmitSyntaxDirective();
565 
566  // If this is not inline asm and we're in 16-bit
567  // mode prefix assembly with .code16.
568  bool is16 = TT.getEnvironment() == Triple::CODE16;
569  if (M.getModuleInlineAsm().empty() && is16)
570  OutStreamer->EmitAssemblerFlag(MCAF_Code16);
571 }
572 
573 static void
576  // L_foo$stub:
577  OutStreamer.EmitLabel(StubLabel);
578  // .indirect_symbol _foo
579  OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
580 
581  if (MCSym.getInt())
582  // External to current translation unit.
583  OutStreamer.EmitIntValue(0, 4/*size*/);
584  else
585  // Internal to current translation unit.
586  //
587  // When we place the LSDA into the TEXT section, the type info
588  // pointers need to be indirect and pc-rel. We accomplish this by
589  // using NLPs; however, sometimes the types are local to the file.
590  // We need to fill in the value for the NLP in those cases.
591  OutStreamer.EmitValue(
592  MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
593  4 /*size*/);
594 }
595 
596 MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {
597  if (Subtarget->isTargetKnownWindowsMSVC()) {
598  const MachineConstantPoolEntry &CPE =
599  MF->getConstantPool()->getConstants()[CPID];
600  if (!CPE.isMachineConstantPoolEntry()) {
601  const DataLayout &DL = MF->getDataLayout();
602  SectionKind Kind = CPE.getSectionKind(&DL);
603  const Constant *C = CPE.Val.ConstVal;
604  unsigned Align = CPE.Alignment;
605  if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
606  getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
607  if (MCSymbol *Sym = S->getCOMDATSymbol()) {
608  if (Sym->isUndefined())
609  OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
610  return Sym;
611  }
612  }
613  }
614  }
615 
616  return AsmPrinter::GetCPISymbol(CPID);
617 }
618 
620  const Triple &TT = TM.getTargetTriple();
621 
622  if (TT.isOSBinFormatMachO()) {
623  // All darwin targets use mach-o.
624  MachineModuleInfoMachO &MMIMacho =
626 
627  // Output stubs for dynamically-linked functions.
629 
630  // Output stubs for external and common global variables.
631  Stubs = MMIMacho.GetGVStubList();
632  if (!Stubs.empty()) {
633  MCSection *TheSection = OutContext.getMachOSection(
634  "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
636  OutStreamer->SwitchSection(TheSection);
637 
638  for (auto &Stub : Stubs)
639  emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
640 
641  Stubs.clear();
642  OutStreamer->AddBlankLine();
643  }
644 
647 
648  // Funny Darwin hack: This flag tells the linker that no global symbols
649  // contain code that falls through to other global symbols (e.g. the obvious
650  // implementation of multiple entry points). If this doesn't occur, the
651  // linker can safely perform dead code stripping. Since LLVM never
652  // generates code that does this, it is always safe to set.
653  OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
654  }
655 
658  (TT.getArch() == Triple::x86_64) ? "_fltused" : "__fltused";
659  MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
660  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
661  }
662 
663  if (TT.isOSBinFormatCOFF()) {
665  }
666 
667  if (TT.isOSBinFormatELF()) {
670  }
671 }
672 
673 //===----------------------------------------------------------------------===//
674 // Target Registry Stuff
675 //===----------------------------------------------------------------------===//
676 
677 // Force static initialization.
678 extern "C" void LLVMInitializeX86AsmPrinter() {
681 }
unsigned getTargetFlags() const
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
Definition: X86BaseInfo.h:228
uint64_t CallInst * C
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:208
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:493
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
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:435
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:93
SI Whole Quad Mode
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:313
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
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:136
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
Definition: X86BaseInfo.h:222
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:586
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
const X86InstrInfo * getInstrInfo() const override
Definition: X86Subtarget.h:451
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.
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
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:110
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:179
static void printSymbolOperand(X86AsmPrinter &P, const MachineOperand &MO, raw_ostream &O)
printSymbolOperand - Print a raw symbol reference operand.
bool isTargetKnownWindowsMSVC() const
Definition: X86Subtarget.h:703
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
No complex type; simple scalar variable.
Definition: COFF.h:260
return AArch64::GPR64RegClass contains(Reg)
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:248
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
Definition: X86BaseInfo.h:210
Definition: BitVector.h:921
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:732
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isKnownWindowsMSVCEnvironment() const
Checks if the environment is MSVC.
Definition: Triple.h:528
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:156
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.
.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:272
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
Definition: X86BaseInfo.h:95
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:283
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:154
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)
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: COFF.h:266
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:111
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:205
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:142
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:99
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:183
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:112
MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a relocation of: SYMBOL_LABEL + [...
Definition: X86BaseInfo.h:83
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
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:591
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
Definition: X86BaseInfo.h:195
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
Definition: X86BaseInfo.h:216
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:146
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...
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:81
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
bool hasInternalLinkage() const
Definition: GlobalValue.h:433
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
const Triple & getTargetTriple() const
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
Definition: X86BaseInfo.h:187
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:596
const Target & getTarget() const
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
AddrSegmentReg - The operand # of the segment in the memory operand.
Definition: X86BaseInfo.h:39
#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:126
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:461
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
Definition: X86BaseInfo.h:171
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:427
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:301
bool isTargetWin32() const
Definition: X86Subtarget.h:729
X86 target streamer implementing x86-only assembly directives.
int64_t getImm() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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:60
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
Definition: X86BaseInfo.h:102
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:163
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:122
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:686
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:117
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 unsigned Kind
union llvm::MachineConstantPoolEntry::@144 Val
The constant itself.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:321
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:59
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
Definition: X86BaseInfo.h:88
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:298
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:200
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
A function that returns a base type.
Definition: COFF.h:262