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