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"
22 #include "llvm/BinaryFormat/ELF.h"
26 #include "llvm/IR/DerivedTypes.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  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  bool EmitPercent = true;
376 
377  if (!X86::GR8RegClass.contains(Reg) &&
378  !X86::GR16RegClass.contains(Reg) &&
379  !X86::GR32RegClass.contains(Reg) &&
380  !X86::GR64RegClass.contains(Reg))
381  return true;
382 
383  switch (Mode) {
384  default: return true; // Unknown mode.
385  case 'b': // Print QImode register
386  Reg = getX86SubSuperRegister(Reg, 8);
387  break;
388  case 'h': // Print QImode high register
389  Reg = getX86SubSuperRegister(Reg, 8, true);
390  break;
391  case 'w': // Print HImode register
392  Reg = getX86SubSuperRegister(Reg, 16);
393  break;
394  case 'k': // Print SImode register
395  Reg = getX86SubSuperRegister(Reg, 32);
396  break;
397  case 'V':
398  EmitPercent = false;
400  case 'q':
401  // Print 64-bit register names if 64-bit integer registers are available.
402  // Otherwise, print 32-bit register names.
403  Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
404  break;
405  }
406 
407  if (EmitPercent)
408  O << '%';
409 
411  return false;
412 }
413 
414 /// PrintAsmOperand - Print out an operand for an inline asm expression.
415 ///
416 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
417  unsigned AsmVariant,
418  const char *ExtraCode, raw_ostream &O) {
419  // Does this asm operand have a single letter operand modifier?
420  if (ExtraCode && ExtraCode[0]) {
421  if (ExtraCode[1] != 0) return true; // Unknown modifier.
422 
423  const MachineOperand &MO = MI->getOperand(OpNo);
424 
425  switch (ExtraCode[0]) {
426  default:
427  // See if this is a generic print operand
428  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
429  case 'a': // This is an address. Currently only 'i' and 'r' are expected.
430  switch (MO.getType()) {
431  default:
432  return true;
434  O << MO.getImm();
435  return false;
439  llvm_unreachable("unexpected operand type!");
441  printSymbolOperand(*this, MO, O);
442  if (Subtarget->isPICStyleRIPRel())
443  O << "(%rip)";
444  return false;
446  O << '(';
447  printOperand(*this, MI, OpNo, O);
448  O << ')';
449  return false;
450  }
451 
452  case 'c': // Don't print "$" before a global var name or constant.
453  switch (MO.getType()) {
454  default:
455  printOperand(*this, MI, OpNo, O);
456  break;
458  O << MO.getImm();
459  break;
463  llvm_unreachable("unexpected operand type!");
465  printSymbolOperand(*this, MO, O);
466  break;
467  }
468  return false;
469 
470  case 'A': // Print '*' before a register (it must be a register)
471  if (MO.isReg()) {
472  O << '*';
473  printOperand(*this, MI, OpNo, O);
474  return false;
475  }
476  return true;
477 
478  case 'b': // Print QImode register
479  case 'h': // Print QImode high register
480  case 'w': // Print HImode register
481  case 'k': // Print SImode register
482  case 'q': // Print DImode register
483  case 'V': // Print native register without '%'
484  if (MO.isReg())
485  return printAsmMRegister(*this, MO, ExtraCode[0], O);
486  printOperand(*this, MI, OpNo, O);
487  return false;
488 
489  case 'P': // This is the operand of a call, treat specially.
490  printPCRelImm(*this, MI, OpNo, O);
491  return false;
492 
493  case 'n': // Negate the immediate or print a '-' before the operand.
494  // Note: this is a temporary solution. It should be handled target
495  // independently as part of the 'MC' work.
496  if (MO.isImm()) {
497  O << -MO.getImm();
498  return false;
499  }
500  O << '-';
501  }
502  }
503 
504  printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr, AsmVariant);
505  return false;
506 }
507 
509  unsigned OpNo, unsigned AsmVariant,
510  const char *ExtraCode,
511  raw_ostream &O) {
512  if (AsmVariant) {
513  printIntelMemReference(*this, MI, OpNo, O);
514  return false;
515  }
516 
517  if (ExtraCode && ExtraCode[0]) {
518  if (ExtraCode[1] != 0) return true; // Unknown modifier.
519 
520  switch (ExtraCode[0]) {
521  default: return true; // Unknown modifier.
522  case 'b': // Print QImode register
523  case 'h': // Print QImode high register
524  case 'w': // Print HImode register
525  case 'k': // Print SImode register
526  case 'q': // Print SImode register
527  // These only apply to registers, ignore on mem.
528  break;
529  case 'H':
530  printMemReference(*this, MI, OpNo, O, "H");
531  return false;
532  case 'P': // Don't print @PLT, but do print as memory.
533  printMemReference(*this, MI, OpNo, O, "no-rip");
534  return false;
535  }
536  }
537  printMemReference(*this, MI, OpNo, O);
538  return false;
539 }
540 
542  const Triple &TT = TM.getTargetTriple();
543 
544  if (TT.isOSBinFormatELF()) {
545  // Assemble feature flags that may require creation of a note section.
546  unsigned FeatureFlagsAnd = 0;
547  if (M.getModuleFlag("cf-protection-branch"))
548  FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_IBT;
549  if (M.getModuleFlag("cf-protection-return"))
550  FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_SHSTK;
551 
552  if (FeatureFlagsAnd) {
553  // Emit a .note.gnu.property section with the flags.
554  if (!TT.isArch32Bit() && !TT.isArch64Bit())
555  llvm_unreachable("CFProtection used on invalid architecture!");
556  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
558  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
559  OutStreamer->SwitchSection(Nt);
560 
561  // Emitting note header.
562  int WordSize = TT.isArch64Bit() ? 8 : 4;
563  EmitAlignment(WordSize == 4 ? 2 : 3);
564  OutStreamer->EmitIntValue(4, 4 /*size*/); // data size for "GNU\0"
565  OutStreamer->EmitIntValue(8 + WordSize, 4 /*size*/); // Elf_Prop size
566  OutStreamer->EmitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4 /*size*/);
567  OutStreamer->EmitBytes(StringRef("GNU", 4)); // note name
568 
569  // Emitting an Elf_Prop for the CET properties.
571  OutStreamer->EmitIntValue(WordSize, 4); // data size
572  OutStreamer->EmitIntValue(FeatureFlagsAnd, WordSize); // data
573  EmitAlignment(WordSize == 4 ? 2 : 3); // padding
574 
575  OutStreamer->endSection(Nt);
576  OutStreamer->SwitchSection(Cur);
577  }
578  }
579 
580  if (TT.isOSBinFormatMachO())
581  OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
582 
583  if (TT.isOSBinFormatCOFF()) {
584  // Emit an absolute @feat.00 symbol. This appears to be some kind of
585  // compiler features bitfield read by link.exe.
586  if (TT.getArch() == Triple::x86) {
587  MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
588  OutStreamer->BeginCOFFSymbolDef(S);
589  OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
590  OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
591  OutStreamer->EndCOFFSymbolDef();
592  // According to the PE-COFF spec, the LSB of this value marks the object
593  // for "registered SEH". This means that all SEH handler entry points
594  // must be registered in .sxdata. Use of any unregistered handlers will
595  // cause the process to terminate immediately. LLVM does not know how to
596  // register any SEH handlers, so its object files should be safe.
597  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
598  OutStreamer->EmitAssignment(
599  S, MCConstantExpr::create(int64_t(1), MMI->getContext()));
600  }
601  }
602  OutStreamer->EmitSyntaxDirective();
603 
604  // If this is not inline asm and we're in 16-bit
605  // mode prefix assembly with .code16.
606  bool is16 = TT.getEnvironment() == Triple::CODE16;
607  if (M.getModuleInlineAsm().empty() && is16)
608  OutStreamer->EmitAssemblerFlag(MCAF_Code16);
609 }
610 
611 MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {
612  if (Subtarget->isTargetKnownWindowsMSVC()) {
613  const MachineConstantPoolEntry &CPE =
614  MF->getConstantPool()->getConstants()[CPID];
615  if (!CPE.isMachineConstantPoolEntry()) {
616  const DataLayout &DL = MF->getDataLayout();
617  SectionKind Kind = CPE.getSectionKind(&DL);
618  const Constant *C = CPE.Val.ConstVal;
619  unsigned Align = CPE.Alignment;
620  if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
621  getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
622  if (MCSymbol *Sym = S->getCOMDATSymbol()) {
623  if (Sym->isUndefined())
624  OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
625  return Sym;
626  }
627  }
628  }
629  }
630 
631  return AsmPrinter::GetCPISymbol(CPID);
632 }
633 
634 static void
637  // L_foo$stub:
638  OutStreamer.EmitLabel(StubLabel);
639  // .indirect_symbol _foo
640  OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
641 
642  if (MCSym.getInt())
643  // External to current translation unit.
644  OutStreamer.EmitIntValue(0, 4/*size*/);
645  else
646  // Internal to current translation unit.
647  //
648  // When we place the LSDA into the TEXT section, the type info
649  // pointers need to be indirect and pc-rel. We accomplish this by
650  // using NLPs; however, sometimes the types are local to the file.
651  // We need to fill in the value for the NLP in those cases.
652  OutStreamer.EmitValue(
653  MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
654  4 /*size*/);
655 }
656 
658 
659  MachineModuleInfoMachO &MMIMacho =
661 
662  // Output stubs for dynamically-linked functions.
664 
665  // Output stubs for external and common global variables.
666  Stubs = MMIMacho.GetGVStubList();
667  if (!Stubs.empty()) {
668  OutStreamer.SwitchSection(MMI->getContext().getMachOSection(
669  "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
671 
672  for (auto &Stub : Stubs)
673  emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
674 
675  Stubs.clear();
676  OutStreamer.AddBlankLine();
677  }
678 }
679 
681  const Triple &TT = TM.getTargetTriple();
682 
683  if (TT.isOSBinFormatMachO()) {
684  // Mach-O uses non-lazy symbol stubs to encode per-TU information into
685  // global table for symbol lookup.
687 
688  // Emit stack and fault map information.
691 
692  // This flag tells the linker that no global symbols contain code that fall
693  // through to other global symbols (e.g. an implementation of multiple entry
694  // points). If this doesn't occur, the linker can safely perform dead code
695  // stripping. Since LLVM never generates code that does this, it is always
696  // safe to set.
697  OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
698  return;
699  }
700 
703  (TT.getArch() == Triple::x86_64) ? "_fltused" : "__fltused";
704  MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
705  OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
706  return;
707  }
708 
709  if (TT.isOSBinFormatCOFF()) {
711  return;
712  }
713 
714  if (TT.isOSBinFormatELF()) {
717  return;
718  }
719 }
720 
721 //===----------------------------------------------------------------------===//
722 // Target Registry Stuff
723 //===----------------------------------------------------------------------===//
724 
725 // Force static initialization.
726 extern "C" void LLVMInitializeX86AsmPrinter() {
729 }
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:508
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:321
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
MO_TLSLD - On a symbol operand this indicates that the immediate is the offset of the GOT entry with ...
Definition: X86BaseInfo.h:136
virtual void AddBlankLine()
AddBlankLine - Emit a blank line to a .s file to pretty it up.
Definition: MCStreamer.h:324
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:588
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:467
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
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:724
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:250
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:753
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:530
Name of external global symbol.
static bool isMem(const MachineInstr &MI, unsigned Op)
Definition: X86InstrInfo.h:160
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:273
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:285
IntType getInt() const
const MCContext & getContext() const
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1249
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:112
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:143
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
static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer)
#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:593
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:302
AddrSegmentReg - The operand # of the segment in the memory operand.
Definition: X86BaseInfo.h:39
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
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:991
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 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
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: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: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:477
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:426
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:750
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:123
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...
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1245
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:124
bool isTargetCOFF() const
Definition: X86Subtarget.h:707
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:246
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())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:393
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:322
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
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
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:238
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:316
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:164
MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the reference is actually to the "__imp...
Definition: X86BaseInfo.h:200
This class contains meta information specific to a module.
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:60
A function that returns a base type.
Definition: COFF.h:262