LLVM  9.0.0svn
X86AsmPrinter.cpp
Go to the documentation of this file.
1 //===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a printer that converts from our internal representation
10 // of machine-dependent LLVM code to X86 machine code.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "X86AsmPrinter.h"
18 #include "X86InstrInfo.h"
19 #include "X86MachineFunctionInfo.h"
20 #include "llvm/BinaryFormat/COFF.h"
21 #include "llvm/BinaryFormat/ELF.h"
25 #include "llvm/IR/DerivedTypes.h"
26 #include "llvm/IR/InlineAsm.h"
27 #include "llvm/IR/Mangler.h"
28 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Type.h"
30 #include "llvm/MC/MCCodeEmitter.h"
31 #include "llvm/MC/MCContext.h"
32 #include "llvm/MC/MCExpr.h"
33 #include "llvm/MC/MCSectionCOFF.h"
34 #include "llvm/MC/MCSectionELF.h"
35 #include "llvm/MC/MCSectionMachO.h"
36 #include "llvm/MC/MCStreamer.h"
37 #include "llvm/MC/MCSymbol.h"
38 #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  if (auto *XTS =
92  static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer()))
93  XTS->emitFPOProc(
96  }
97 }
98 
100  if (EmitFPOData) {
101  if (auto *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.
110 void X86AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
111  raw_ostream &O) {
112  switch (MO.getType()) {
113  default: llvm_unreachable("unknown symbol type!");
115  GetCPISymbol(MO.getIndex())->print(O, MAI);
116  printOffset(MO.getOffset(), O);
117  break;
119  const GlobalValue *GV = MO.getGlobal();
120 
121  MCSymbol *GVSym;
124  GVSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
125  else
126  GVSym = getSymbol(GV);
127 
128  // Handle dllimport linkage.
130  GVSym = OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
131  else if (MO.getTargetFlags() == X86II::MO_COFFSTUB)
132  GVSym =
133  OutContext.getOrCreateSymbol(Twine(".refptr.") + GVSym->getName());
134 
137  MCSymbol *Sym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
139  MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
140  if (!StubSym.getPointer())
142  !GV->hasInternalLinkage());
143  }
144 
145  // If the name begins with a dollar-sign, enclose it in parens. We do this
146  // to avoid having it look like an integer immediate to the assembler.
147  if (GVSym->getName()[0] != '$')
148  GVSym->print(O, MAI);
149  else {
150  O << '(';
151  GVSym->print(O, MAI);
152  O << ')';
153  }
154  printOffset(MO.getOffset(), O);
155  break;
156  }
157  }
158 
159  switch (MO.getTargetFlags()) {
160  default:
161  llvm_unreachable("Unknown target flag on GV operand");
162  case X86II::MO_NO_FLAG: // No flag.
163  break;
165  case X86II::MO_DLLIMPORT:
166  case X86II::MO_COFFSTUB:
167  // These affect the name of the symbol, not any suffix.
168  break;
170  O << " + [.-";
171  MF->getPICBaseSymbol()->print(O, MAI);
172  O << ']';
173  break;
176  O << '-';
177  MF->getPICBaseSymbol()->print(O, MAI);
178  break;
179  case X86II::MO_TLSGD: O << "@TLSGD"; break;
180  case X86II::MO_TLSLD: O << "@TLSLD"; break;
181  case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
182  case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
183  case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
184  case X86II::MO_TPOFF: O << "@TPOFF"; break;
185  case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
186  case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
187  case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
188  case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
189  case X86II::MO_GOT: O << "@GOT"; break;
190  case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
191  case X86II::MO_PLT: O << "@PLT"; break;
192  case X86II::MO_TLVP: O << "@TLVP"; break;
194  O << "@TLVP" << '-';
195  MF->getPICBaseSymbol()->print(O, MAI);
196  break;
197  case X86II::MO_SECREL: O << "@SECREL32"; break;
198  }
199 }
200 
201 void X86AsmPrinter::PrintOperand(const MachineInstr *MI, unsigned OpNo,
202  raw_ostream &O) {
203  const MachineOperand &MO = MI->getOperand(OpNo);
204  const bool IsATT = MI->getInlineAsmDialect() == InlineAsm::AD_ATT;
205  switch (MO.getType()) {
206  default: llvm_unreachable("unknown operand type!");
208  if (IsATT)
209  O << '%';
211  return;
212  }
213 
215  if (IsATT)
216  O << '$';
217  O << MO.getImm();
218  return;
219 
221  if (IsATT)
222  O << '$';
223  PrintSymbolOperand(MO, O);
224  break;
225  }
228  Sym->print(O, MAI);
229  break;
230  }
231  }
232 }
233 
234 /// PrintModifiedOperand - Print subregisters based on supplied modifier,
235 /// deferring to PrintOperand() if no modifier was supplied or if operand is not
236 /// a register.
237 void X86AsmPrinter::PrintModifiedOperand(const MachineInstr *MI, unsigned OpNo,
238  raw_ostream &O, const char *Modifier) {
239  const MachineOperand &MO = MI->getOperand(OpNo);
240  if (!Modifier || MO.getType() != MachineOperand::MO_Register)
241  return PrintOperand(MI, OpNo, O);
243  O << '%';
244  unsigned Reg = MO.getReg();
245  if (strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
246  unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
247  (strcmp(Modifier+6,"32") == 0) ? 32 :
248  (strcmp(Modifier+6,"16") == 0) ? 16 : 8;
249  Reg = getX86SubSuperRegister(Reg, Size);
250  }
252 }
253 
254 /// PrintPCRelImm - This is used to print an immediate value that ends up
255 /// being encoded as a pc-relative value. These print slightly differently, for
256 /// example, a $ is not emitted.
257 void X86AsmPrinter::PrintPCRelImm(const MachineInstr *MI, unsigned OpNo,
258  raw_ostream &O) {
259  const MachineOperand &MO = MI->getOperand(OpNo);
260  switch (MO.getType()) {
261  default: llvm_unreachable("Unknown pcrel immediate operand");
263  // pc-relativeness was handled when computing the value in the reg.
264  PrintOperand(MI, OpNo, O);
265  return;
267  O << MO.getImm();
268  return;
270  PrintSymbolOperand(MO, O);
271  return;
272  }
273 }
274 
275 void X86AsmPrinter::PrintLeaMemReference(const MachineInstr *MI, unsigned OpNo,
276  raw_ostream &O, const char *Modifier) {
277  const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
278  const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
279  const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
280 
281  // If we really don't want to print out (rip), don't.
282  bool HasBaseReg = BaseReg.getReg() != 0;
283  if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
284  BaseReg.getReg() == X86::RIP)
285  HasBaseReg = false;
286 
287  // HasParenPart - True if we will print out the () part of the mem ref.
288  bool HasParenPart = IndexReg.getReg() || HasBaseReg;
289 
290  switch (DispSpec.getType()) {
291  default:
292  llvm_unreachable("unknown operand type!");
294  int DispVal = DispSpec.getImm();
295  if (DispVal || !HasParenPart)
296  O << DispVal;
297  break;
298  }
301  PrintSymbolOperand(DispSpec, O);
302  }
303 
304  if (Modifier && strcmp(Modifier, "H") == 0)
305  O << "+8";
306 
307  if (HasParenPart) {
308  assert(IndexReg.getReg() != X86::ESP &&
309  "X86 doesn't allow scaling by ESP");
310 
311  O << '(';
312  if (HasBaseReg)
313  PrintModifiedOperand(MI, OpNo + X86::AddrBaseReg, O, Modifier);
314 
315  if (IndexReg.getReg()) {
316  O << ',';
317  PrintModifiedOperand(MI, OpNo + X86::AddrIndexReg, O, Modifier);
318  unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
319  if (ScaleVal != 1)
320  O << ',' << ScaleVal;
321  }
322  O << ')';
323  }
324 }
325 
326 void X86AsmPrinter::PrintMemReference(const MachineInstr *MI, unsigned OpNo,
327  raw_ostream &O, const char *Modifier) {
328  assert(isMem(*MI, OpNo) && "Invalid memory reference!");
329  const MachineOperand &Segment = MI->getOperand(OpNo + X86::AddrSegmentReg);
330  if (Segment.getReg()) {
331  PrintModifiedOperand(MI, OpNo + X86::AddrSegmentReg, O, Modifier);
332  O << ':';
333  }
334  PrintLeaMemReference(MI, OpNo, O, Modifier);
335 }
336 
337 void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
338  unsigned OpNo, raw_ostream &O) {
339  const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
340  unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
341  const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
342  const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
343  const MachineOperand &SegReg = MI->getOperand(OpNo + X86::AddrSegmentReg);
344 
345  // If this has a segment register, print it.
346  if (SegReg.getReg()) {
347  PrintOperand(MI, OpNo + X86::AddrSegmentReg, O);
348  O << ':';
349  }
350 
351  O << '[';
352 
353  bool NeedPlus = false;
354  if (BaseReg.getReg()) {
355  PrintOperand(MI, OpNo + X86::AddrBaseReg, O);
356  NeedPlus = true;
357  }
358 
359  if (IndexReg.getReg()) {
360  if (NeedPlus) O << " + ";
361  if (ScaleVal != 1)
362  O << ScaleVal << '*';
363  PrintOperand(MI, OpNo + X86::AddrIndexReg, O);
364  NeedPlus = true;
365  }
366 
367  if (!DispSpec.isImm()) {
368  if (NeedPlus) O << " + ";
369  PrintOperand(MI, OpNo + X86::AddrDisp, O);
370  } else {
371  int64_t DispVal = DispSpec.getImm();
372  if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
373  if (NeedPlus) {
374  if (DispVal > 0)
375  O << " + ";
376  else {
377  O << " - ";
378  DispVal = -DispVal;
379  }
380  }
381  O << DispVal;
382  }
383  }
384  O << ']';
385 }
386 
388  char Mode, raw_ostream &O) {
389  unsigned Reg = MO.getReg();
390  bool EmitPercent = true;
391 
392  if (!X86::GR8RegClass.contains(Reg) &&
393  !X86::GR16RegClass.contains(Reg) &&
394  !X86::GR32RegClass.contains(Reg) &&
395  !X86::GR64RegClass.contains(Reg))
396  return true;
397 
398  switch (Mode) {
399  default: return true; // Unknown mode.
400  case 'b': // Print QImode register
401  Reg = getX86SubSuperRegister(Reg, 8);
402  break;
403  case 'h': // Print QImode high register
404  Reg = getX86SubSuperRegister(Reg, 8, true);
405  break;
406  case 'w': // Print HImode register
407  Reg = getX86SubSuperRegister(Reg, 16);
408  break;
409  case 'k': // Print SImode register
410  Reg = getX86SubSuperRegister(Reg, 32);
411  break;
412  case 'V':
413  EmitPercent = false;
415  case 'q':
416  // Print 64-bit register names if 64-bit integer registers are available.
417  // Otherwise, print 32-bit register names.
418  Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
419  break;
420  }
421 
422  if (EmitPercent)
423  O << '%';
424 
426  return false;
427 }
428 
429 /// PrintAsmOperand - Print out an operand for an inline asm expression.
430 ///
431 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
432  const char *ExtraCode, raw_ostream &O) {
433  // Does this asm operand have a single letter operand modifier?
434  if (ExtraCode && ExtraCode[0]) {
435  if (ExtraCode[1] != 0) return true; // Unknown modifier.
436 
437  const MachineOperand &MO = MI->getOperand(OpNo);
438 
439  switch (ExtraCode[0]) {
440  default:
441  // See if this is a generic print operand
442  return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
443  case 'a': // This is an address. Currently only 'i' and 'r' are expected.
444  switch (MO.getType()) {
445  default:
446  return true;
448  O << MO.getImm();
449  return false;
453  llvm_unreachable("unexpected operand type!");
455  PrintSymbolOperand(MO, O);
456  if (Subtarget->isPICStyleRIPRel())
457  O << "(%rip)";
458  return false;
460  O << '(';
461  PrintOperand(MI, OpNo, O);
462  O << ')';
463  return false;
464  }
465 
466  case 'c': // Don't print "$" before a global var name or constant.
467  switch (MO.getType()) {
468  default:
469  PrintOperand(MI, OpNo, O);
470  break;
472  O << MO.getImm();
473  break;
477  llvm_unreachable("unexpected operand type!");
479  PrintSymbolOperand(MO, O);
480  break;
481  }
482  return false;
483 
484  case 'A': // Print '*' before a register (it must be a register)
485  if (MO.isReg()) {
486  O << '*';
487  PrintOperand(MI, OpNo, O);
488  return false;
489  }
490  return true;
491 
492  case 'b': // Print QImode register
493  case 'h': // Print QImode high register
494  case 'w': // Print HImode register
495  case 'k': // Print SImode register
496  case 'q': // Print DImode register
497  case 'V': // Print native register without '%'
498  if (MO.isReg())
499  return printAsmMRegister(*this, MO, ExtraCode[0], O);
500  PrintOperand(MI, OpNo, O);
501  return false;
502 
503  case 'P': // This is the operand of a call, treat specially.
504  PrintPCRelImm(MI, OpNo, O);
505  return false;
506 
507  case 'n': // Negate the immediate or print a '-' before the operand.
508  // Note: this is a temporary solution. It should be handled target
509  // independently as part of the 'MC' work.
510  if (MO.isImm()) {
511  O << -MO.getImm();
512  return false;
513  }
514  O << '-';
515  }
516  }
517 
518  PrintOperand(MI, OpNo, O);
519  return false;
520 }
521 
523  const char *ExtraCode,
524  raw_ostream &O) {
526  PrintIntelMemReference(MI, OpNo, O);
527  return false;
528  }
529 
530  if (ExtraCode && ExtraCode[0]) {
531  if (ExtraCode[1] != 0) return true; // Unknown modifier.
532 
533  switch (ExtraCode[0]) {
534  default: return true; // Unknown modifier.
535  case 'b': // Print QImode register
536  case 'h': // Print QImode high register
537  case 'w': // Print HImode register
538  case 'k': // Print SImode register
539  case 'q': // Print SImode register
540  // These only apply to registers, ignore on mem.
541  break;
542  case 'H':
543  PrintMemReference(MI, OpNo, O, "H");
544  return false;
545  case 'P': // Don't print @PLT, but do print as memory.
546  PrintMemReference(MI, OpNo, O, "no-rip");
547  return false;
548  }
549  }
550  PrintMemReference(MI, OpNo, O, nullptr);
551  return false;
552 }
553 
555  const Triple &TT = TM.getTargetTriple();
556 
557  if (TT.isOSBinFormatELF()) {
558  // Assemble feature flags that may require creation of a note section.
559  unsigned FeatureFlagsAnd = 0;
560  if (M.getModuleFlag("cf-protection-branch"))
561  FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_IBT;
562  if (M.getModuleFlag("cf-protection-return"))
563  FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_SHSTK;
564 
565  if (FeatureFlagsAnd) {
566  // Emit a .note.gnu.property section with the flags.
567  if (!TT.isArch32Bit() && !TT.isArch64Bit())
568  llvm_unreachable("CFProtection used on invalid architecture!");
569  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
571  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
572  OutStreamer->SwitchSection(Nt);
573 
574  // Emitting note header.
575  int WordSize = TT.isArch64Bit() ? 8 : 4;
576  EmitAlignment(WordSize == 4 ? 2 : 3);
577  OutStreamer->EmitIntValue(4, 4 /*size*/); // data size for "GNU\0"
578  OutStreamer->EmitIntValue(8 + WordSize, 4 /*size*/); // Elf_Prop size
579  OutStreamer->EmitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4 /*size*/);
580  OutStreamer->EmitBytes(StringRef("GNU", 4)); // note name
581 
582  // Emitting an Elf_Prop for the CET properties.
584  OutStreamer->EmitIntValue(4, 4); // data size
585  OutStreamer->EmitIntValue(FeatureFlagsAnd, 4); // data
586  EmitAlignment(WordSize == 4 ? 2 : 3); // padding
587 
588  OutStreamer->endSection(Nt);
589  OutStreamer->SwitchSection(Cur);
590  }
591  }
592 
593  if (TT.isOSBinFormatMachO())
594  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
595 
596  if (TT.isOSBinFormatCOFF()) {
597  // Emit an absolute @feat.00 symbol. This appears to be some kind of
598  // compiler features bitfield read by link.exe.
599  MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
600  OutStreamer->BeginCOFFSymbolDef(S);
601  OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
602  OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
603  OutStreamer->EndCOFFSymbolDef();
604  int64_t Feat00Flags = 0;
605 
606  if (TT.getArch() == Triple::x86) {
607  // According to the PE-COFF spec, the LSB of this value marks the object
608  // for "registered SEH". This means that all SEH handler entry points
609  // must be registered in .sxdata. Use of any unregistered handlers will
610  // cause the process to terminate immediately. LLVM does not know how to
611  // register any SEH handlers, so its object files should be safe.
612  Feat00Flags |= 1;
613  }
614 
615  if (M.getModuleFlag("cfguardtable"))
616  Feat00Flags |= 0x800; // Object is CFG-aware.
617 
618  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
619  OutStreamer->EmitAssignment(
620  S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));
621  }
622  OutStreamer->EmitSyntaxDirective();
623 
624  // If this is not inline asm and we're in 16-bit
625  // mode prefix assembly with .code16.
626  bool is16 = TT.getEnvironment() == Triple::CODE16;
627  if (M.getModuleInlineAsm().empty() && is16)
628  OutStreamer->EmitAssemblerFlag(MCAF_Code16);
629 }
630 
631 static void
634  // L_foo$stub:
635  OutStreamer.EmitLabel(StubLabel);
636  // .indirect_symbol _foo
637  OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
638 
639  if (MCSym.getInt())
640  // External to current translation unit.
641  OutStreamer.EmitIntValue(0, 4/*size*/);
642  else
643  // Internal to current translation unit.
644  //
645  // When we place the LSDA into the TEXT section, the type info
646  // pointers need to be indirect and pc-rel. We accomplish this by
647  // using NLPs; however, sometimes the types are local to the file.
648  // We need to fill in the value for the NLP in those cases.
649  OutStreamer.EmitValue(
650  MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
651  4 /*size*/);
652 }
653 
655 
656  MachineModuleInfoMachO &MMIMacho =
658 
659  // Output stubs for dynamically-linked functions.
661 
662  // Output stubs for external and common global variables.
663  Stubs = MMIMacho.GetGVStubList();
664  if (!Stubs.empty()) {
665  OutStreamer.SwitchSection(MMI->getContext().getMachOSection(
666  "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
668 
669  for (auto &Stub : Stubs)
670  emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
671 
672  Stubs.clear();
673  OutStreamer.AddBlankLine();
674  }
675 }
676 
678  const Triple &TT = TM.getTargetTriple();
679 
680  if (TT.isOSBinFormatMachO()) {
681  // Mach-O uses non-lazy symbol stubs to encode per-TU information into
682  // global table for symbol lookup.
684 
685  // Emit stack and fault map information.
686  emitStackMaps(SM);
688 
689  // This flag tells the linker that no global symbols contain code that fall
690  // through to other global symbols (e.g. an implementation of multiple entry
691  // points). If this doesn't occur, the linker can safely perform dead code
692  // stripping. Since LLVM never generates code that does this, it is always
693  // safe to set.
694  OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
695  } else if (TT.isOSBinFormatCOFF()) {
696  if (MMI->usesMSVCFloatingPoint()) {
697  // In Windows' libcmt.lib, there is a file which is linked in only if the
698  // symbol _fltused is referenced. Linking this in causes some
699  // side-effects:
700  //
701  // 1. For x86-32, it will set the x87 rounding mode to 53-bit instead of
702  // 64-bit mantissas at program start.
703  //
704  // 2. It links in support routines for floating-point in scanf and printf.
705  //
706  // MSVC emits an undefined reference to _fltused when there are any
707  // floating point operations in the program (including calls). A program
708  // that only has: `scanf("%f", &global_float);` may fail to trigger this,
709  // but oh well...that's a documented issue.
711  (TT.getArch() == Triple::x86) ? "__fltused" : "_fltused";
712  MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
713  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
714  return;
715  }
716  emitStackMaps(SM);
717  } else if (TT.isOSBinFormatELF()) {
718  emitStackMaps(SM);
720  }
721 }
722 
723 //===----------------------------------------------------------------------===//
724 // Target Registry Stuff
725 //===----------------------------------------------------------------------===//
726 
727 // Force static initialization.
728 extern "C" void LLVMInitializeX86AsmPrinter() {
731 }
unsigned getTargetFlags() const
MO_SECREL - On a symbol operand this indicates that the immediate is the offset from beginning of sec...
Definition: X86BaseInfo.h:265
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:213
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
Definition: X86Subtarget.h:527
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:131
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)
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:275
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:321
This class represents lattice values for constants.
Definition: AllocatorList.h:23
PointerTy getPointer() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:173
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:330
MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate is some TLS offset from the ...
Definition: X86BaseInfo.h:259
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:614
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:486
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.
unsigned Reg
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
PrintAsmOperand - Print out an operand for an inline asm expression.
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:147
MO_DTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry with...
Definition: X86BaseInfo.h:216
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
No complex type; simple scalar variable.
Definition: COFF.h:259
return AArch64::GPR64RegClass contains(Reg)
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MCContext & getContext() const
Definition: MCStreamer.h:250
MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates that the reference is actually...
Definition: X86BaseInfo.h:247
Definition: BitVector.h:937
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
bool isPICStyleRIPRel() const
Definition: X86Subtarget.h:783
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
Name of external global symbol.
static bool isMem(const MachineInstr &MI, unsigned Op)
Definition: X86InstrInfo.h:122
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:276
MO_GOT - On a symbol operand this indicates that the immediate is the offset to the GOT entry for the...
Definition: X86BaseInfo.h:132
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:291
IntType getInt() const
const MCContext & getContext() const
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1280
MO_GOTTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry wi...
Definition: X86BaseInfo.h:191
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)
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: COFF.h:265
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.
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:128
MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the reference is actually to the "...
Definition: X86BaseInfo.h:242
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:159
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:99
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Definition: Module.cpp:468
MCContext & getContext() const
AddrSegmentReg - The operand # of the segment in the memory operand.
Definition: X86BaseInfo.h:38
static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer)
#define P(N)
Address of a global value.
Streaming machine code generation interface.
Definition: MCStreamer.h:188
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:120
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:619
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:310
MO_GOTNTPOFF - On a symbol operand this indicates that the immediate is the offset of the GOT entry w...
Definition: X86BaseInfo.h:232
MO_TLVP - On a symbol operand this indicates that the immediate is some TLS offset.
Definition: X86BaseInfo.h:253
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
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:183
void EmitAlignment(unsigned NumBits, const GlobalObject *GV=nullptr) const
Emit an alignment directive to the specified power of two boundary.
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
Address of a basic block.
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
const Triple & getTargetTriple() const
MO_NTPOFF - On a symbol operand this indicates that the immediate is the negative thread-pointer offs...
Definition: X86BaseInfo.h:224
Ty & getObjFileInfo()
Keep track of various per-function pieces of information for backends that would like to do so...
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:624
const Target & getTarget() const
void emitStackMaps(StackMaps &SM)
Emit the stack maps.
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:43
MO_TLSGD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:163
const X86RegisterInfo * getRegisterInfo() const override
Definition: X86Subtarget.h:496
MO_TPOFF - On a symbol operand this indicates that the immediate is the thread-pointer offset for the...
Definition: X86BaseInfo.h:208
void EmitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
InlineAsm::AsmDialect getInlineAsmDialect() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:440
void serializeToFaultMapSection()
Definition: FaultMaps.cpp:49
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:178
EnvironmentType getEnvironment() const
getEnvironment - Get the parsed environment type of this triple.
Definition: Triple.h:309
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
bool isTargetWin32() const
Definition: X86Subtarget.h:780
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.
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
Representation of each machine instruction.
Definition: MachineInstr.h:63
MO_GOTOFF - On a symbol operand this indicates that the immediate is the offset to the location of th...
Definition: X86BaseInfo.h:139
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:200
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1276
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
bool usesMSVCFloatingPoint() const
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:128
bool isTargetCOFF() const
Definition: X86Subtarget.h:737
Target & getTheX86_32Target()
uint32_t Size
Definition: Profile.cpp:46
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:154
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition: Module.h:248
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:202
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:388
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:250
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:351
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the immediate should get the value of th...
Definition: X86BaseInfo.h:125
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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:413
Target & getTheX86_64Target()
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const X86Subtarget & getSubtarget() const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:163
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
Definition: X86BaseInfo.h:237
This class contains meta information specific to a module.
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:261