LLVM  3.7.0
AsmPrinter.cpp
Go to the documentation of this file.
1 //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
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 implements the AsmPrinter class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "DwarfDebug.h"
16 #include "DwarfException.h"
17 #include "WinException.h"
18 #include "WinCodeViewLineTables.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/Statistic.h"
22 #include "llvm/CodeGen/Analysis.h"
31 #include "llvm/IR/DataLayout.h"
32 #include "llvm/IR/DebugInfo.h"
33 #include "llvm/IR/Mangler.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/IR/Operator.h"
36 #include "llvm/MC/MCAsmInfo.h"
37 #include "llvm/MC/MCContext.h"
38 #include "llvm/MC/MCExpr.h"
39 #include "llvm/MC/MCInst.h"
40 #include "llvm/MC/MCSection.h"
41 #include "llvm/MC/MCStreamer.h"
42 #include "llvm/MC/MCSymbolELF.h"
43 #include "llvm/MC/MCValue.h"
45 #include "llvm/Support/Format.h"
48 #include "llvm/Support/Timer.h"
55 using namespace llvm;
56 
57 #define DEBUG_TYPE "asm-printer"
58 
59 static const char *const DWARFGroupName = "DWARF Emission";
60 static const char *const DbgTimerName = "Debug Info Emission";
61 static const char *const EHTimerName = "DWARF Exception Writer";
62 static const char *const CodeViewLineTablesGroupName = "CodeView Line Tables";
63 
64 STATISTIC(EmittedInsts, "Number of machine instrs printed");
65 
66 char AsmPrinter::ID = 0;
67 
69 static gcp_map_type &getGCMap(void *&P) {
70  if (!P)
71  P = new gcp_map_type();
72  return *(gcp_map_type*)P;
73 }
74 
75 
76 /// getGVAlignmentLog2 - Return the alignment to use for the specified global
77 /// value in log2 form. This rounds up to the preferred alignment if possible
78 /// and legal.
79 static unsigned getGVAlignmentLog2(const GlobalValue *GV, const DataLayout &DL,
80  unsigned InBits = 0) {
81  unsigned NumBits = 0;
82  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
83  NumBits = DL.getPreferredAlignmentLog(GVar);
84 
85  // If InBits is specified, round it to it.
86  if (InBits > NumBits)
87  NumBits = InBits;
88 
89  // If the GV has a specified alignment, take it into account.
90  if (GV->getAlignment() == 0)
91  return NumBits;
92 
93  unsigned GVAlign = Log2_32(GV->getAlignment());
94 
95  // If the GVAlign is larger than NumBits, or if we are required to obey
96  // NumBits because the GV has an assigned section, obey it.
97  if (GVAlign > NumBits || GV->hasSection())
98  NumBits = GVAlign;
99  return NumBits;
100 }
101 
102 AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
103  : MachineFunctionPass(ID), TM(tm), MAI(tm.getMCAsmInfo()),
104  OutContext(Streamer->getContext()), OutStreamer(std::move(Streamer)),
105  LastMI(nullptr), LastFn(0), Counter(~0U) {
106  DD = nullptr;
107  MMI = nullptr;
108  LI = nullptr;
109  MF = nullptr;
110  CurExceptionSym = CurrentFnSym = CurrentFnSymForSize = nullptr;
111  CurrentFnBegin = nullptr;
112  CurrentFnEnd = nullptr;
113  GCMetadataPrinters = nullptr;
114  VerboseAsm = OutStreamer->isVerboseAsm();
115 }
116 
118  assert(!DD && Handlers.empty() && "Debug/EH info didn't get finalized");
119 
120  if (GCMetadataPrinters) {
121  gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
122 
123  delete &GCMap;
124  GCMetadataPrinters = nullptr;
125  }
126 }
127 
128 /// getFunctionNumber - Return a unique ID for the current function.
129 ///
131  return MF->getFunctionNumber();
132 }
133 
135  return *TM.getObjFileLowering();
136 }
137 
138 /// getDataLayout - Return information about data layout.
140  return *TM.getDataLayout();
141 }
142 
144  assert(MF && "getSubtargetInfo requires a valid MachineFunction!");
145  return MF->getSubtarget<MCSubtargetInfo>();
146 }
147 
150 }
151 
153  return TM.getTargetTriple().str();
154 }
155 
156 /// getCurrentSection() - Return the current section we are emitting to.
158  return OutStreamer->getCurrentSection().first;
159 }
160 
161 
162 
164  AU.setPreservesAll();
168  if (isVerbose())
170 }
171 
173  MMI = getAnalysisIfAvailable<MachineModuleInfo>();
174 
175  // Initialize TargetLoweringObjectFile.
177  .Initialize(OutContext, TM);
178 
179  OutStreamer->InitSections(false);
180 
181  Mang = new Mangler();
182 
183  // Emit the version-min deplyment target directive if needed.
184  //
185  // FIXME: If we end up with a collection of these sorts of Darwin-specific
186  // or ELF-specific things, it may make sense to have a platform helper class
187  // that will work with the target helper class. For now keep it here, as the
188  // alternative is duplicated code in each of the target asm printers that
189  // use the directive, where it would need the same conditionalization
190  // anyway.
191  Triple TT(getTargetTriple());
192  if (TT.isOSDarwin()) {
193  unsigned Major, Minor, Update;
194  TT.getOSVersion(Major, Minor, Update);
195  // If there is a version specified, Major will be non-zero.
196  if (Major)
197  OutStreamer->EmitVersionMin((TT.isMacOSX() ?
199  Major, Minor, Update);
200  }
201 
202  // Allow the target to emit any magic that it wants at the start of the file.
204 
205  // Very minimal debug info. It is ignored if we emit actual debug info. If we
206  // don't, this at least helps the user find where a global came from.
208  // .file "foo.c"
209  OutStreamer->EmitFileDirective(M.getModuleIdentifier());
210  }
211 
212  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
213  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
214  for (auto &I : *MI)
215  if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
216  MP->beginAssembly(M, *MI, *this);
217 
218  // Emit module-level inline asm if it exists.
219  if (!M.getModuleInlineAsm().empty()) {
220  // We're at the module level. Construct MCSubtarget from the default CPU
221  // and target triple.
222  std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
225  OutStreamer->AddComment("Start of file scope inline assembly");
226  OutStreamer->AddBlankLine();
227  EmitInlineAsm(M.getModuleInlineAsm()+"\n", *STI, TM.Options.MCOptions);
228  OutStreamer->AddComment("End of file scope inline assembly");
229  OutStreamer->AddBlankLine();
230  }
231 
233  bool skip_dwarf = false;
235  Handlers.push_back(HandlerInfo(new WinCodeViewLineTables(this),
236  DbgTimerName,
238  // FIXME: Don't emit DWARF debug info if there's at least one function
239  // with AddressSanitizer instrumentation.
240  // This is a band-aid fix for PR22032.
241  for (auto &F : M.functions()) {
242  if (F.hasFnAttribute(Attribute::SanitizeAddress)) {
243  skip_dwarf = true;
244  break;
245  }
246  }
247  }
248  if (!skip_dwarf) {
249  DD = new DwarfDebug(this, &M);
250  Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName));
251  }
252  }
253 
254  EHStreamer *ES = nullptr;
255  switch (MAI->getExceptionHandlingType()) {
257  break;
260  ES = new DwarfCFIException(this);
261  break;
263  ES = new ARMException(this);
264  break;
266  switch (MAI->getWinEHEncodingType()) {
267  default: llvm_unreachable("unsupported unwinding information encoding");
269  break;
272  ES = new WinException(this);
273  break;
274  }
275  break;
276  }
277  if (ES)
278  Handlers.push_back(HandlerInfo(ES, EHTimerName, DWARFGroupName));
279  return false;
280 }
281 
282 static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI) {
284  return false;
285 
286  return canBeOmittedFromSymbolTable(GV);
287 }
288 
289 void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
290  GlobalValue::LinkageTypes Linkage = GV->getLinkage();
291  switch (Linkage) {
297  if (MAI->hasWeakDefDirective()) {
298  // .globl _foo
299  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Global);
300 
301  if (!canBeHidden(GV, *MAI))
302  // .weak_definition _foo
303  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
304  else
305  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_WeakDefAutoPrivate);
306  } else if (MAI->hasLinkOnceDirective()) {
307  // .globl _foo
308  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Global);
309  //NOTE: linkonce is handled by the section the symbol was assigned to.
310  } else {
311  // .weak _foo
312  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Weak);
313  }
314  return;
316  // FIXME: appending linkage variables should go into a section of
317  // their name or something. For now, just emit them as external.
319  // If external or appending, declare as a global symbol.
320  // .globl _foo
321  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Global);
322  return;
325  return;
327  llvm_unreachable("Should never emit this");
329  llvm_unreachable("Don't know how to emit these");
330  }
331  llvm_unreachable("Unknown linkage type!");
332 }
333 
335  const GlobalValue *GV) const {
336  TM.getNameWithPrefix(Name, GV, *Mang);
337 }
338 
340  return TM.getSymbol(GV, *Mang);
341 }
342 
343 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
345  if (GV->hasInitializer()) {
346  // Check to see if this is a special global used by LLVM, if so, emit it.
347  if (EmitSpecialLLVMGlobal(GV))
348  return;
349 
350  // Skip the emission of global equivalents. The symbol can be emitted later
351  // on by emitGlobalGOTEquivs in case it turns out to be needed.
352  if (GlobalGOTEquivs.count(getSymbol(GV)))
353  return;
354 
355  if (isVerbose()) {
356  GV->printAsOperand(OutStreamer->GetCommentOS(),
357  /*PrintType=*/false, GV->getParent());
358  OutStreamer->GetCommentOS() << '\n';
359  }
360  }
361 
362  MCSymbol *GVSym = getSymbol(GV);
363  EmitVisibility(GVSym, GV->getVisibility(), !GV->isDeclaration());
364 
365  if (!GV->hasInitializer()) // External globals require no extra code.
366  return;
367 
368  GVSym->redefineIfPossible();
369  if (GVSym->isDefined() || GVSym->isVariable())
370  report_fatal_error("symbol '" + Twine(GVSym->getName()) +
371  "' is already defined");
372 
374  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_ELF_TypeObject);
375 
377 
378  const DataLayout *DL = TM.getDataLayout();
379  uint64_t Size = DL->getTypeAllocSize(GV->getType()->getElementType());
380 
381  // If the alignment is specified, we *must* obey it. Overaligning a global
382  // with a specified alignment is a prompt way to break globals emitted to
383  // sections and expected to be contiguous (e.g. ObjC metadata).
384  unsigned AlignLog = getGVAlignmentLog2(GV, *DL);
385 
386  for (const HandlerInfo &HI : Handlers) {
387  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName, TimePassesIsEnabled);
388  HI.Handler->setSymbolSize(GVSym, Size);
389  }
390 
391  // Handle common and BSS local symbols (.lcomm).
392  if (GVKind.isCommon() || GVKind.isBSSLocal()) {
393  if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
394  unsigned Align = 1 << AlignLog;
395 
396  // Handle common symbols.
397  if (GVKind.isCommon()) {
399  Align = 0;
400 
401  // .comm _foo, 42, 4
402  OutStreamer->EmitCommonSymbol(GVSym, Size, Align);
403  return;
404  }
405 
406  // Handle local BSS symbols.
408  MCSection *TheSection =
409  getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
410  // .zerofill __DATA, __bss, _foo, 400, 5
411  OutStreamer->EmitZerofill(TheSection, GVSym, Size, Align);
412  return;
413  }
414 
415  // Use .lcomm only if it supports user-specified alignment.
416  // Otherwise, while it would still be correct to use .lcomm in some
417  // cases (e.g. when Align == 1), the external assembler might enfore
418  // some -unknown- default alignment behavior, which could cause
419  // spurious differences between external and integrated assembler.
420  // Prefer to simply fall back to .local / .comm in this case.
422  // .lcomm _foo, 42
423  OutStreamer->EmitLocalCommonSymbol(GVSym, Size, Align);
424  return;
425  }
426 
427  if (!getObjFileLowering().getCommDirectiveSupportsAlignment())
428  Align = 0;
429 
430  // .local _foo
431  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Local);
432  // .comm _foo, 42, 4
433  OutStreamer->EmitCommonSymbol(GVSym, Size, Align);
434  return;
435  }
436 
437  MCSection *TheSection =
438  getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
439 
440  // Handle the zerofill directive on darwin, which is a special form of BSS
441  // emission.
442  if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
443  if (Size == 0) Size = 1; // zerofill of 0 bytes is undefined.
444 
445  // .globl _foo
446  OutStreamer->EmitSymbolAttribute(GVSym, MCSA_Global);
447  // .zerofill __DATA, __common, _foo, 400, 5
448  OutStreamer->EmitZerofill(TheSection, GVSym, Size, 1 << AlignLog);
449  return;
450  }
451 
452  // Handle thread local data for mach-o which requires us to output an
453  // additional structure of data and mangle the original symbol so that we
454  // can reference it later.
455  //
456  // TODO: This should become an "emit thread local global" method on TLOF.
457  // All of this macho specific stuff should be sunk down into TLOFMachO and
458  // stuff like "TLSExtraDataSection" should no longer be part of the parent
459  // TLOF class. This will also make it more obvious that stuff like
460  // MCStreamer::EmitTBSSSymbol is macho specific and only called from macho
461  // specific code.
462  if (GVKind.isThreadLocal() && MAI->hasMachoTBSSDirective()) {
463  // Emit the .tbss symbol
464  MCSymbol *MangSym =
465  OutContext.getOrCreateSymbol(GVSym->getName() + Twine("$tlv$init"));
466 
467  if (GVKind.isThreadBSS()) {
468  TheSection = getObjFileLowering().getTLSBSSSection();
469  OutStreamer->EmitTBSSSymbol(TheSection, MangSym, Size, 1 << AlignLog);
470  } else if (GVKind.isThreadData()) {
471  OutStreamer->SwitchSection(TheSection);
472 
473  EmitAlignment(AlignLog, GV);
474  OutStreamer->EmitLabel(MangSym);
475 
477  }
478 
479  OutStreamer->AddBlankLine();
480 
481  // Emit the variable struct for the runtime.
483 
484  OutStreamer->SwitchSection(TLVSect);
485  // Emit the linkage here.
486  EmitLinkage(GV, GVSym);
487  OutStreamer->EmitLabel(GVSym);
488 
489  // Three pointers in size:
490  // - __tlv_bootstrap - used to make sure support exists
491  // - spare pointer, used when mapped by the runtime
492  // - pointer to mangled symbol above with initializer
493  unsigned PtrSize = DL->getPointerTypeSize(GV->getType());
494  OutStreamer->EmitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"),
495  PtrSize);
496  OutStreamer->EmitIntValue(0, PtrSize);
497  OutStreamer->EmitSymbolValue(MangSym, PtrSize);
498 
499  OutStreamer->AddBlankLine();
500  return;
501  }
502 
503  OutStreamer->SwitchSection(TheSection);
504 
505  EmitLinkage(GV, GVSym);
506  EmitAlignment(AlignLog, GV);
507 
508  OutStreamer->EmitLabel(GVSym);
509 
511 
513  // .size foo, 42
514  OutStreamer->emitELFSize(cast<MCSymbolELF>(GVSym),
516 
517  OutStreamer->AddBlankLine();
518 }
519 
520 /// EmitFunctionHeader - This method emits the header for the current
521 /// function.
522 void AsmPrinter::EmitFunctionHeader() {
523  // Print out constants referenced by the function
525 
526  // Print the 'header' of function.
527  const Function *F = MF->getFunction();
528 
529  OutStreamer->SwitchSection(
530  getObjFileLowering().SectionForGlobal(F, *Mang, TM));
531  EmitVisibility(CurrentFnSym, F->getVisibility());
532 
533  EmitLinkage(F, CurrentFnSym);
534  if (MAI->hasFunctionAlignment())
536 
538  OutStreamer->EmitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
539 
540  if (isVerbose()) {
541  F->printAsOperand(OutStreamer->GetCommentOS(),
542  /*PrintType=*/false, F->getParent());
543  OutStreamer->GetCommentOS() << '\n';
544  }
545 
546  // Emit the prefix data.
547  if (F->hasPrefixData())
549 
550  // Emit the CurrentFnSym. This is a virtual function to allow targets to
551  // do their wild and crazy things as required.
553 
554  // If the function had address-taken blocks that got deleted, then we have
555  // references to the dangling symbols. Emit them at the start of the function
556  // so that we don't get references to undefined symbols.
557  std::vector<MCSymbol*> DeadBlockSyms;
558  MMI->takeDeletedSymbolsForFunction(F, DeadBlockSyms);
559  for (unsigned i = 0, e = DeadBlockSyms.size(); i != e; ++i) {
560  OutStreamer->AddComment("Address taken block that was later removed");
561  OutStreamer->EmitLabel(DeadBlockSyms[i]);
562  }
563 
564  if (CurrentFnBegin) {
565  if (MAI->useAssignmentForEHBegin()) {
567  OutStreamer->EmitLabel(CurPos);
568  OutStreamer->EmitAssignment(CurrentFnBegin,
570  } else {
571  OutStreamer->EmitLabel(CurrentFnBegin);
572  }
573  }
574 
575  // Emit pre-function debug and/or EH information.
576  for (const HandlerInfo &HI : Handlers) {
577  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName, TimePassesIsEnabled);
578  HI.Handler->beginFunction(MF);
579  }
580 
581  // Emit the prologue data.
582  if (F->hasPrologueData())
584 }
585 
586 /// EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
587 /// function. This can be overridden by targets as required to do custom stuff.
590 
591  // The function label could have already been emitted if two symbols end up
592  // conflicting due to asm renaming. Detect this and emit an error.
593  if (CurrentFnSym->isVariable())
595  "' is a protected alias");
596  if (CurrentFnSym->isDefined())
598  "' label emitted multiple times to assembly file");
599 
600  return OutStreamer->EmitLabel(CurrentFnSym);
601 }
602 
603 /// emitComments - Pretty-print comments for instructions.
604 static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
605  const MachineFunction *MF = MI.getParent()->getParent();
606  const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
607 
608  // Check for spills and reloads
609  int FI;
610 
611  const MachineFrameInfo *FrameInfo = MF->getFrameInfo();
612 
613  // We assume a single instruction only has a spill or reload, not
614  // both.
615  const MachineMemOperand *MMO;
616  if (TII->isLoadFromStackSlotPostFE(&MI, FI)) {
617  if (FrameInfo->isSpillSlotObjectIndex(FI)) {
618  MMO = *MI.memoperands_begin();
619  CommentOS << MMO->getSize() << "-byte Reload\n";
620  }
621  } else if (TII->hasLoadFromStackSlot(&MI, MMO, FI)) {
622  if (FrameInfo->isSpillSlotObjectIndex(FI))
623  CommentOS << MMO->getSize() << "-byte Folded Reload\n";
624  } else if (TII->isStoreToStackSlotPostFE(&MI, FI)) {
625  if (FrameInfo->isSpillSlotObjectIndex(FI)) {
626  MMO = *MI.memoperands_begin();
627  CommentOS << MMO->getSize() << "-byte Spill\n";
628  }
629  } else if (TII->hasStoreToStackSlot(&MI, MMO, FI)) {
630  if (FrameInfo->isSpillSlotObjectIndex(FI))
631  CommentOS << MMO->getSize() << "-byte Folded Spill\n";
632  }
633 
634  // Check for spill-induced copies
636  CommentOS << " Reload Reuse\n";
637 }
638 
639 /// emitImplicitDef - This method emits the specified machine instruction
640 /// that is an implicit def.
642  unsigned RegNo = MI->getOperand(0).getReg();
643  OutStreamer->AddComment(Twine("implicit-def: ") +
644  MMI->getContext().getRegisterInfo()->getName(RegNo));
645  OutStreamer->AddBlankLine();
646 }
647 
648 static void emitKill(const MachineInstr *MI, AsmPrinter &AP) {
649  std::string Str = "kill:";
650  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
651  const MachineOperand &Op = MI->getOperand(i);
652  assert(Op.isReg() && "KILL instruction must have only register operands");
653  Str += ' ';
654  Str += AP.MMI->getContext().getRegisterInfo()->getName(Op.getReg());
655  Str += (Op.isDef() ? "<def>" : "<kill>");
656  }
657  AP.OutStreamer->AddComment(Str);
658  AP.OutStreamer->AddBlankLine();
659 }
660 
661 /// emitDebugValueComment - This method handles the target-independent form
662 /// of DBG_VALUE, returning true if it was able to do so. A false return
663 /// means the target will need to handle MI in EmitInstruction.
665  // This code handles only the 4-operand target-independent form.
666  if (MI->getNumOperands() != 4)
667  return false;
668 
669  SmallString<128> Str;
670  raw_svector_ostream OS(Str);
671  OS << "DEBUG_VALUE: ";
672 
673  const DILocalVariable *V = MI->getDebugVariable();
674  if (auto *SP = dyn_cast<DISubprogram>(V->getScope())) {
675  StringRef Name = SP->getDisplayName();
676  if (!Name.empty())
677  OS << Name << ":";
678  }
679  OS << V->getName();
680 
681  const DIExpression *Expr = MI->getDebugExpression();
682  if (Expr->isBitPiece())
683  OS << " [bit_piece offset=" << Expr->getBitPieceOffset()
684  << " size=" << Expr->getBitPieceSize() << "]";
685  OS << " <- ";
686 
687  // The second operand is only an offset if it's an immediate.
688  bool Deref = MI->getOperand(0).isReg() && MI->getOperand(1).isImm();
689  int64_t Offset = Deref ? MI->getOperand(1).getImm() : 0;
690 
691  // Register or immediate value. Register 0 means undef.
692  if (MI->getOperand(0).isFPImm()) {
693  APFloat APF = APFloat(MI->getOperand(0).getFPImm()->getValueAPF());
694  if (MI->getOperand(0).getFPImm()->getType()->isFloatTy()) {
695  OS << (double)APF.convertToFloat();
696  } else if (MI->getOperand(0).getFPImm()->getType()->isDoubleTy()) {
697  OS << APF.convertToDouble();
698  } else {
699  // There is no good way to print long double. Convert a copy to
700  // double. Ah well, it's only a comment.
701  bool ignored;
703  &ignored);
704  OS << "(long double) " << APF.convertToDouble();
705  }
706  } else if (MI->getOperand(0).isImm()) {
707  OS << MI->getOperand(0).getImm();
708  } else if (MI->getOperand(0).isCImm()) {
709  MI->getOperand(0).getCImm()->getValue().print(OS, false /*isSigned*/);
710  } else {
711  unsigned Reg;
712  if (MI->getOperand(0).isReg()) {
713  Reg = MI->getOperand(0).getReg();
714  } else {
715  assert(MI->getOperand(0).isFI() && "Unknown operand type");
717  Offset += TFI->getFrameIndexReference(*AP.MF,
718  MI->getOperand(0).getIndex(), Reg);
719  Deref = true;
720  }
721  if (Reg == 0) {
722  // Suppress offset, it is not meaningful here.
723  OS << "undef";
724  // NOTE: Want this comment at start of line, don't emit with AddComment.
725  AP.OutStreamer->emitRawComment(OS.str());
726  return true;
727  }
728  if (Deref)
729  OS << '[';
730  OS << AP.MMI->getContext().getRegisterInfo()->getName(Reg);
731  }
732 
733  if (Deref)
734  OS << '+' << Offset << ']';
735 
736  // NOTE: Want this comment at start of line, don't emit with AddComment.
737  AP.OutStreamer->emitRawComment(OS.str());
738  return true;
739 }
740 
744  return CFI_M_EH;
745 
746  if (MMI->hasDebugInfo())
747  return CFI_M_Debug;
748 
749  return CFI_M_None;
750 }
751 
754 }
755 
757  ExceptionHandling ExceptionHandlingType = MAI->getExceptionHandlingType();
758  if (ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
759  ExceptionHandlingType != ExceptionHandling::ARM)
760  return;
761 
762  if (needsCFIMoves() == CFI_M_None)
763  return;
764 
765  const MachineModuleInfo &MMI = MF->getMMI();
766  const std::vector<MCCFIInstruction> &Instrs = MMI.getFrameInstructions();
767  unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
768  const MCCFIInstruction &CFI = Instrs[CFIIndex];
769  emitCFIInstruction(CFI);
770 }
771 
773  // The operands are the MCSymbol and the frame offset of the allocation.
774  MCSymbol *FrameAllocSym = MI.getOperand(0).getMCSymbol();
775  int FrameOffset = MI.getOperand(1).getImm();
776 
777  // Emit a symbol assignment.
778  OutStreamer->EmitAssignment(FrameAllocSym,
779  MCConstantExpr::create(FrameOffset, OutContext));
780 }
781 
782 /// EmitFunctionBody - This method emits the body and trailer for a
783 /// function.
785  EmitFunctionHeader();
786 
787  // Emit target-specific gunk before the function body.
789 
790  bool ShouldPrintDebugScopes = MMI->hasDebugInfo();
791 
792  // Print out code for the function.
793  bool HasAnyRealCode = false;
794  for (auto &MBB : *MF) {
795  // Print a label for the basic block.
796  EmitBasicBlockStart(MBB);
797  for (auto &MI : MBB) {
798 
799  // Print the assembly for the instruction.
800  if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
801  !MI.isDebugValue()) {
802  HasAnyRealCode = true;
803  ++EmittedInsts;
804  }
805 
806  if (ShouldPrintDebugScopes) {
807  for (const HandlerInfo &HI : Handlers) {
808  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName,
810  HI.Handler->beginInstruction(&MI);
811  }
812  }
813 
814  if (isVerbose())
815  emitComments(MI, OutStreamer->GetCommentOS());
816 
817  switch (MI.getOpcode()) {
820  break;
821 
824  break;
825 
828  OutStreamer->EmitLabel(MI.getOperand(0).getMCSymbol());
829  break;
831  EmitInlineAsm(&MI);
832  break;
834  if (isVerbose()) {
835  if (!emitDebugValueComment(&MI, *this))
837  }
838  break;
840  if (isVerbose()) emitImplicitDef(&MI);
841  break;
842  case TargetOpcode::KILL:
843  if (isVerbose()) emitKill(&MI, *this);
844  break;
845  default:
847  break;
848  }
849 
850  if (ShouldPrintDebugScopes) {
851  for (const HandlerInfo &HI : Handlers) {
852  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName,
854  HI.Handler->endInstruction();
855  }
856  }
857  }
858 
859  EmitBasicBlockEnd(MBB);
860  }
861 
862  // If the function is empty and the object file uses .subsections_via_symbols,
863  // then we need to emit *something* to the function body to prevent the
864  // labels from collapsing together. Just emit a noop.
865  if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)) {
866  MCInst Noop;
867  MF->getSubtarget().getInstrInfo()->getNoopForMachoTarget(Noop);
868  OutStreamer->AddComment("avoids zero-length function");
869 
870  // Targets can opt-out of emitting the noop here by leaving the opcode
871  // unspecified.
872  if (Noop.getOpcode())
873  OutStreamer->EmitInstruction(Noop, getSubtargetInfo());
874  }
875 
876  const Function *F = MF->getFunction();
877  for (const auto &BB : *F) {
878  if (!BB.hasAddressTaken())
879  continue;
880  MCSymbol *Sym = GetBlockAddressSymbol(&BB);
881  if (Sym->isDefined())
882  continue;
883  OutStreamer->AddComment("Address of block that was removed by CodeGen");
884  OutStreamer->EmitLabel(Sym);
885  }
886 
887  // Emit target-specific gunk after the function body.
889 
890  if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
892  // Create a symbol for the end of function.
893  CurrentFnEnd = createTempSymbol("func_end");
894  OutStreamer->EmitLabel(CurrentFnEnd);
895  }
896 
897  // If the target wants a .size directive for the size of the function, emit
898  // it.
900  // We can get the size as difference between the function label and the
901  // temp label.
902  const MCExpr *SizeExp = MCBinaryExpr::createSub(
903  MCSymbolRefExpr::create(CurrentFnEnd, OutContext),
905  if (auto Sym = dyn_cast<MCSymbolELF>(CurrentFnSym))
906  OutStreamer->emitELFSize(Sym, SizeExp);
907  }
908 
909  for (const HandlerInfo &HI : Handlers) {
910  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName, TimePassesIsEnabled);
911  HI.Handler->markFunctionEnd();
912  }
913 
914  // Print out jump tables referenced by the function.
916 
917  // Emit post-function debug and/or EH information.
918  for (const HandlerInfo &HI : Handlers) {
919  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName, TimePassesIsEnabled);
920  HI.Handler->endFunction(MF);
921  }
922  MMI->EndFunction();
923 
924  OutStreamer->AddBlankLine();
925 }
926 
927 /// \brief Compute the number of Global Variables that uses a Constant.
928 static unsigned getNumGlobalVariableUses(const Constant *C) {
929  if (!C)
930  return 0;
931 
932  if (isa<GlobalVariable>(C))
933  return 1;
934 
935  unsigned NumUses = 0;
936  for (auto *CU : C->users())
937  NumUses += getNumGlobalVariableUses(dyn_cast<Constant>(CU));
938 
939  return NumUses;
940 }
941 
942 /// \brief Only consider global GOT equivalents if at least one user is a
943 /// cstexpr inside an initializer of another global variables. Also, don't
944 /// handle cstexpr inside instructions. During global variable emission,
945 /// candidates are skipped and are emitted later in case at least one cstexpr
946 /// isn't replaced by a PC relative GOT entry access.
948  unsigned &NumGOTEquivUsers) {
949  // Global GOT equivalents are unnamed private globals with a constant
950  // pointer initializer to another global symbol. They must point to a
951  // GlobalVariable or Function, i.e., as GlobalValue.
952  if (!GV->hasUnnamedAddr() || !GV->hasInitializer() || !GV->isConstant() ||
954  return false;
955 
956  // To be a got equivalent, at least one of its users need to be a constant
957  // expression used by another global variable.
958  for (auto *U : GV->users())
959  NumGOTEquivUsers += getNumGlobalVariableUses(dyn_cast<Constant>(U));
960 
961  return NumGOTEquivUsers > 0;
962 }
963 
964 /// \brief Unnamed constant global variables solely contaning a pointer to
965 /// another globals variable is equivalent to a GOT table entry; it contains the
966 /// the address of another symbol. Optimize it and replace accesses to these
967 /// "GOT equivalents" by using the GOT entry for the final global instead.
968 /// Compute GOT equivalent candidates among all global variables to avoid
969 /// emitting them if possible later on, after it use is replaced by a GOT entry
970 /// access.
972  if (!getObjFileLowering().supportIndirectSymViaGOTPCRel())
973  return;
974 
975  for (const auto &G : M.globals()) {
976  unsigned NumGOTEquivUsers = 0;
977  if (!isGOTEquivalentCandidate(&G, NumGOTEquivUsers))
978  continue;
979 
980  const MCSymbol *GOTEquivSym = getSymbol(&G);
981  GlobalGOTEquivs[GOTEquivSym] = std::make_pair(&G, NumGOTEquivUsers);
982  }
983 }
984 
985 /// \brief Constant expressions using GOT equivalent globals may not be eligible
986 /// for PC relative GOT entry conversion, in such cases we need to emit such
987 /// globals we previously omitted in EmitGlobalVariable.
989  if (!getObjFileLowering().supportIndirectSymViaGOTPCRel())
990  return;
991 
993  for (auto &I : GlobalGOTEquivs) {
994  const GlobalVariable *GV = I.second.first;
995  unsigned Cnt = I.second.second;
996  if (Cnt)
997  FailedCandidates.push_back(GV);
998  }
999  GlobalGOTEquivs.clear();
1000 
1001  for (auto *GV : FailedCandidates)
1002  EmitGlobalVariable(GV);
1003 }
1004 
1006  // Set the MachineFunction to nullptr so that we can catch attempted
1007  // accesses to MF specific features at the module level and so that
1008  // we can conditionalize accesses based on whether or not it is nullptr.
1009  MF = nullptr;
1010 
1011  // Gather all GOT equivalent globals in the module. We really need two
1012  // passes over the globals: one to compute and another to avoid its emission
1013  // in EmitGlobalVariable, otherwise we would not be able to handle cases
1014  // where the got equivalent shows up before its use.
1016 
1017  // Emit global variables.
1018  for (const auto &G : M.globals())
1020 
1021  // Emit remaining GOT equivalent globals.
1023 
1024  // Emit visibility info for declarations
1025  for (const Function &F : M) {
1026  if (!F.isDeclarationForLinker())
1027  continue;
1030  continue;
1031 
1032  MCSymbol *Name = getSymbol(&F);
1033  EmitVisibility(Name, V, false);
1034  }
1035 
1037 
1038  // Emit module flags.
1040  M.getModuleFlagsMetadata(ModuleFlags);
1041  if (!ModuleFlags.empty())
1042  TLOF.emitModuleFlags(*OutStreamer, ModuleFlags, *Mang, TM);
1043 
1046 
1047  // Output stubs for external and common global variables.
1049  if (!Stubs.empty()) {
1050  OutStreamer->SwitchSection(TLOF.getDataRelSection());
1051  const DataLayout *DL = TM.getDataLayout();
1052 
1053  for (const auto &Stub : Stubs) {
1054  OutStreamer->EmitLabel(Stub.first);
1055  OutStreamer->EmitSymbolValue(Stub.second.getPointer(),
1056  DL->getPointerSize());
1057  }
1058  }
1059  }
1060 
1061  // Make sure we wrote out everything we need.
1062  OutStreamer->Flush();
1063 
1064  // Finalize debug and EH information.
1065  for (const HandlerInfo &HI : Handlers) {
1066  NamedRegionTimer T(HI.TimerName, HI.TimerGroupName,
1068  HI.Handler->endModule();
1069  delete HI.Handler;
1070  }
1071  Handlers.clear();
1072  DD = nullptr;
1073 
1074  // If the target wants to know about weak references, print them all.
1075  if (MAI->getWeakRefDirective()) {
1076  // FIXME: This is not lazy, it would be nice to only print weak references
1077  // to stuff that is actually used. Note that doing so would require targets
1078  // to notice uses in operands (due to constant exprs etc). This should
1079  // happen with the MC stuff eventually.
1080 
1081  // Print out module-level global variables here.
1082  for (const auto &G : M.globals()) {
1083  if (!G.hasExternalWeakLinkage())
1084  continue;
1085  OutStreamer->EmitSymbolAttribute(getSymbol(&G), MCSA_WeakReference);
1086  }
1087 
1088  for (const auto &F : M) {
1089  if (!F.hasExternalWeakLinkage())
1090  continue;
1091  OutStreamer->EmitSymbolAttribute(getSymbol(&F), MCSA_WeakReference);
1092  }
1093  }
1094 
1095  OutStreamer->AddBlankLine();
1096  for (const auto &Alias : M.aliases()) {
1097  MCSymbol *Name = getSymbol(&Alias);
1098 
1099  if (Alias.hasExternalLinkage() || !MAI->getWeakRefDirective())
1100  OutStreamer->EmitSymbolAttribute(Name, MCSA_Global);
1101  else if (Alias.hasWeakLinkage() || Alias.hasLinkOnceLinkage())
1102  OutStreamer->EmitSymbolAttribute(Name, MCSA_WeakReference);
1103  else
1104  assert(Alias.hasLocalLinkage() && "Invalid alias linkage");
1105 
1106  EmitVisibility(Name, Alias.getVisibility());
1107 
1108  // Emit the directives as assignments aka .set:
1109  OutStreamer->EmitAssignment(Name, lowerConstant(Alias.getAliasee()));
1110  }
1111 
1112  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
1113  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
1114  for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
1115  if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I))
1116  MP->finishAssembly(M, *MI, *this);
1117 
1118  // Emit llvm.ident metadata in an '.ident' directive.
1119  EmitModuleIdents(M);
1120 
1121  // Emit __morestack address if needed for indirect calls.
1122  if (MMI->usesMorestackAddr()) {
1123  MCSection *ReadOnlySection =
1125  /*C=*/nullptr);
1126  OutStreamer->SwitchSection(ReadOnlySection);
1127 
1128  MCSymbol *AddrSymbol =
1129  OutContext.getOrCreateSymbol(StringRef("__morestack_addr"));
1130  OutStreamer->EmitLabel(AddrSymbol);
1131 
1132  unsigned PtrSize = TM.getDataLayout()->getPointerSize(0);
1133  OutStreamer->EmitSymbolValue(GetExternalSymbolSymbol("__morestack"),
1134  PtrSize);
1135  }
1136 
1137  // If we don't have any trampolines, then we don't require stack memory
1138  // to be executable. Some targets have a directive to declare this.
1139  Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
1140  if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
1142  OutStreamer->SwitchSection(S);
1143 
1144  // Allow the target to emit any magic that it wants at the end of the file,
1145  // after everything else has gone out.
1146  EmitEndOfAsmFile(M);
1147 
1148  delete Mang; Mang = nullptr;
1149  MMI = nullptr;
1150 
1151  OutStreamer->Finish();
1152  OutStreamer->reset();
1153 
1154  return false;
1155 }
1156 
1158  if (!CurExceptionSym)
1159  CurExceptionSym = createTempSymbol("exception");
1160  return CurExceptionSym;
1161 }
1162 
1164  this->MF = &MF;
1165  // Get the function symbol.
1168  CurrentFnBegin = nullptr;
1169  CurExceptionSym = nullptr;
1170  bool NeedsLocalForSize = MAI->needsLocalForSize();
1171  if (!MMI->getLandingPads().empty() || MMI->hasDebugInfo() ||
1172  NeedsLocalForSize) {
1173  CurrentFnBegin = createTempSymbol("func_begin");
1174  if (NeedsLocalForSize)
1175  CurrentFnSymForSize = CurrentFnBegin;
1176  }
1177 
1178  if (isVerbose())
1179  LI = &getAnalysis<MachineLoopInfo>();
1180 }
1181 
1182 namespace {
1183 // Keep track the alignment, constpool entries per Section.
1184  struct SectionCPs {
1185  MCSection *S;
1186  unsigned Alignment;
1188  SectionCPs(MCSection *s, unsigned a) : S(s), Alignment(a) {}
1189  };
1190 }
1191 
1192 /// EmitConstantPool - Print to the current output stream assembly
1193 /// representations of the constants in the constant pool MCP. This is
1194 /// used to print out constants which have been "spilled to memory" by
1195 /// the code generator.
1196 ///
1198  const MachineConstantPool *MCP = MF->getConstantPool();
1199  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
1200  if (CP.empty()) return;
1201 
1202  // Calculate sections for constant pool entries. We collect entries to go into
1203  // the same section together to reduce amount of section switch statements.
1204  SmallVector<SectionCPs, 4> CPSections;
1205  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
1206  const MachineConstantPoolEntry &CPE = CP[i];
1207  unsigned Align = CPE.getAlignment();
1208 
1209  SectionKind Kind =
1211 
1212  const Constant *C = nullptr;
1213  if (!CPE.isMachineConstantPoolEntry())
1214  C = CPE.Val.ConstVal;
1215 
1217 
1218  // The number of sections are small, just do a linear search from the
1219  // last section to the first.
1220  bool Found = false;
1221  unsigned SecIdx = CPSections.size();
1222  while (SecIdx != 0) {
1223  if (CPSections[--SecIdx].S == S) {
1224  Found = true;
1225  break;
1226  }
1227  }
1228  if (!Found) {
1229  SecIdx = CPSections.size();
1230  CPSections.push_back(SectionCPs(S, Align));
1231  }
1232 
1233  if (Align > CPSections[SecIdx].Alignment)
1234  CPSections[SecIdx].Alignment = Align;
1235  CPSections[SecIdx].CPEs.push_back(i);
1236  }
1237 
1238  // Now print stuff into the calculated sections.
1239  const MCSection *CurSection = nullptr;
1240  unsigned Offset = 0;
1241  for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
1242  for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
1243  unsigned CPI = CPSections[i].CPEs[j];
1244  MCSymbol *Sym = GetCPISymbol(CPI);
1245  if (!Sym->isUndefined())
1246  continue;
1247 
1248  if (CurSection != CPSections[i].S) {
1249  OutStreamer->SwitchSection(CPSections[i].S);
1250  EmitAlignment(Log2_32(CPSections[i].Alignment));
1251  CurSection = CPSections[i].S;
1252  Offset = 0;
1253  }
1254 
1255  MachineConstantPoolEntry CPE = CP[CPI];
1256 
1257  // Emit inter-object padding for alignment.
1258  unsigned AlignMask = CPE.getAlignment() - 1;
1259  unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
1260  OutStreamer->EmitZeros(NewOffset - Offset);
1261 
1262  Type *Ty = CPE.getType();
1263  Offset = NewOffset +
1265 
1266  OutStreamer->EmitLabel(Sym);
1267  if (CPE.isMachineConstantPoolEntry())
1269  else
1271  }
1272  }
1273 }
1274 
1275 /// EmitJumpTableInfo - Print assembly representations of the jump tables used
1276 /// by the current function to the current output stream.
1277 ///
1279  const DataLayout *DL = MF->getTarget().getDataLayout();
1280  const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1281  if (!MJTI) return;
1282  if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_Inline) return;
1283  const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1284  if (JT.empty()) return;
1285 
1286  // Pick the directive to use to print the jump table entries, and switch to
1287  // the appropriate section.
1288  const Function *F = MF->getFunction();
1290  bool JTInDiffSection = !TLOF.shouldPutJumpTableInFunctionSection(
1292  *F);
1293  if (JTInDiffSection) {
1294  // Drop it in the readonly section.
1295  MCSection *ReadOnlySection = TLOF.getSectionForJumpTable(*F, *Mang, TM);
1296  OutStreamer->SwitchSection(ReadOnlySection);
1297  }
1298 
1300  MJTI->getEntryAlignment(*TM.getDataLayout())));
1301 
1302  // Jump tables in code sections are marked with a data_region directive
1303  // where that's supported.
1304  if (!JTInDiffSection)
1305  OutStreamer->EmitDataRegion(MCDR_DataRegionJT32);
1306 
1307  for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {
1308  const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1309 
1310  // If this jump table was deleted, ignore it.
1311  if (JTBBs.empty()) continue;
1312 
1313  // For the EK_LabelDifference32 entry, if using .set avoids a relocation,
1314  /// emit a .set directive for each unique entry.
1318  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
1319  const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF,JTI,OutContext);
1320  for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
1321  const MachineBasicBlock *MBB = JTBBs[ii];
1322  if (!EmittedSets.insert(MBB).second)
1323  continue;
1324 
1325  // .set LJTSet, LBB32-base
1326  const MCExpr *LHS =
1328  OutStreamer->EmitAssignment(GetJTSetSymbol(JTI, MBB->getNumber()),
1329  MCBinaryExpr::createSub(LHS, Base,
1330  OutContext));
1331  }
1332  }
1333 
1334  // On some targets (e.g. Darwin) we want to emit two consecutive labels
1335  // before each jump table. The first label is never referenced, but tells
1336  // the assembler and linker the extents of the jump table object. The
1337  // second label is actually referenced by the code.
1338  if (JTInDiffSection && DL->hasLinkerPrivateGlobalPrefix())
1339  // FIXME: This doesn't have to have any specific name, just any randomly
1340  // named and numbered 'l' label would work. Simplify GetJTISymbol.
1341  OutStreamer->EmitLabel(GetJTISymbol(JTI, true));
1342 
1343  OutStreamer->EmitLabel(GetJTISymbol(JTI));
1344 
1345  for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
1346  EmitJumpTableEntry(MJTI, JTBBs[ii], JTI);
1347  }
1348  if (!JTInDiffSection)
1349  OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
1350 }
1351 
1352 /// EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
1353 /// current stream.
1354 void AsmPrinter::EmitJumpTableEntry(const MachineJumpTableInfo *MJTI,
1355  const MachineBasicBlock *MBB,
1356  unsigned UID) const {
1357  assert(MBB && MBB->getNumber() >= 0 && "Invalid basic block");
1358  const MCExpr *Value = nullptr;
1359  switch (MJTI->getEntryKind()) {
1361  llvm_unreachable("Cannot emit EK_Inline jump table entry");
1364  MJTI, MBB, UID, OutContext);
1365  break;
1367  // EK_BlockAddress - Each entry is a plain address of block, e.g.:
1368  // .word LBB123
1369  Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
1370  break;
1372  // EK_GPRel32BlockAddress - Each entry is an address of block, encoded
1373  // with a relocation as gp-relative, e.g.:
1374  // .gprel32 LBB123
1375  MCSymbol *MBBSym = MBB->getSymbol();
1376  OutStreamer->EmitGPRel32Value(MCSymbolRefExpr::create(MBBSym, OutContext));
1377  return;
1378  }
1379 
1381  // EK_GPRel64BlockAddress - Each entry is an address of block, encoded
1382  // with a relocation as gp-relative, e.g.:
1383  // .gpdword LBB123
1384  MCSymbol *MBBSym = MBB->getSymbol();
1385  OutStreamer->EmitGPRel64Value(MCSymbolRefExpr::create(MBBSym, OutContext));
1386  return;
1387  }
1388 
1390  // Each entry is the address of the block minus the address of the jump
1391  // table. This is used for PIC jump tables where gprel32 is not supported.
1392  // e.g.:
1393  // .word LBB123 - LJTI1_2
1394  // If the .set directive avoids relocations, this is emitted as:
1395  // .set L4_5_set_123, LBB123 - LJTI1_2
1396  // .word L4_5_set_123
1398  Value = MCSymbolRefExpr::create(GetJTSetSymbol(UID, MBB->getNumber()),
1399  OutContext);
1400  break;
1401  }
1402  Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
1403  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
1404  const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext);
1405  Value = MCBinaryExpr::createSub(Value, Base, OutContext);
1406  break;
1407  }
1408  }
1409 
1410  assert(Value && "Unknown entry kind!");
1411 
1412  unsigned EntrySize =
1413  MJTI->getEntrySize(*TM.getDataLayout());
1414  OutStreamer->EmitValue(Value, EntrySize);
1415 }
1416 
1417 
1418 /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
1419 /// special global used by LLVM. If so, emit it and return true, otherwise
1420 /// do nothing and return false.
1422  if (GV->getName() == "llvm.used") {
1423  if (MAI->hasNoDeadStrip()) // No need to emit this at all.
1424  EmitLLVMUsedList(cast<ConstantArray>(GV->getInitializer()));
1425  return true;
1426  }
1427 
1428  // Ignore debug and non-emitted data. This handles llvm.compiler.used.
1429  if (StringRef(GV->getSection()) == "llvm.metadata" ||
1431  return true;
1432 
1433  if (!GV->hasAppendingLinkage()) return false;
1434 
1435  assert(GV->hasInitializer() && "Not a special LLVM global!");
1436 
1437  if (GV->getName() == "llvm.global_ctors") {
1438  EmitXXStructorList(GV->getInitializer(), /* isCtor */ true);
1439 
1440  if (TM.getRelocationModel() == Reloc::Static &&
1442  StringRef Sym(".constructors_used");
1443  OutStreamer->EmitSymbolAttribute(OutContext.getOrCreateSymbol(Sym),
1444  MCSA_Reference);
1445  }
1446  return true;
1447  }
1448 
1449  if (GV->getName() == "llvm.global_dtors") {
1450  EmitXXStructorList(GV->getInitializer(), /* isCtor */ false);
1451 
1452  if (TM.getRelocationModel() == Reloc::Static &&
1454  StringRef Sym(".destructors_used");
1455  OutStreamer->EmitSymbolAttribute(OutContext.getOrCreateSymbol(Sym),
1456  MCSA_Reference);
1457  }
1458  return true;
1459  }
1460 
1461  return false;
1462 }
1463 
1464 /// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
1465 /// global in the specified llvm.used list for which emitUsedDirectiveFor
1466 /// is true, as being used with this directive.
1467 void AsmPrinter::EmitLLVMUsedList(const ConstantArray *InitList) {
1468  // Should be an array of 'i8*'.
1469  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
1470  const GlobalValue *GV =
1472  if (GV)
1473  OutStreamer->EmitSymbolAttribute(getSymbol(GV), MCSA_NoDeadStrip);
1474  }
1475 }
1476 
1477 namespace {
1478 struct Structor {
1479  Structor() : Priority(0), Func(nullptr), ComdatKey(nullptr) {}
1480  int Priority;
1482  llvm::GlobalValue *ComdatKey;
1483 };
1484 } // end namespace
1485 
1486 /// EmitXXStructorList - Emit the ctor or dtor list taking into account the init
1487 /// priority.
1488 void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) {
1489  // Should be an array of '{ int, void ()* }' structs. The first value is the
1490  // init priority.
1491  if (!isa<ConstantArray>(List)) return;
1492 
1493  // Sanity check the structors list.
1494  const ConstantArray *InitList = dyn_cast<ConstantArray>(List);
1495  if (!InitList) return; // Not an array!
1496  StructType *ETy = dyn_cast<StructType>(InitList->getType()->getElementType());
1497  // FIXME: Only allow the 3-field form in LLVM 4.0.
1498  if (!ETy || ETy->getNumElements() < 2 || ETy->getNumElements() > 3)
1499  return; // Not an array of two or three elements!
1500  if (!isa<IntegerType>(ETy->getTypeAtIndex(0U)) ||
1501  !isa<PointerType>(ETy->getTypeAtIndex(1U))) return; // Not (int, ptr).
1502  if (ETy->getNumElements() == 3 && !isa<PointerType>(ETy->getTypeAtIndex(2U)))
1503  return; // Not (int, ptr, ptr).
1504 
1505  // Gather the structors in a form that's convenient for sorting by priority.
1506  SmallVector<Structor, 8> Structors;
1507  for (Value *O : InitList->operands()) {
1509  if (!CS) continue; // Malformed.
1510  if (CS->getOperand(1)->isNullValue())
1511  break; // Found a null terminator, skip the rest.
1512  ConstantInt *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
1513  if (!Priority) continue; // Malformed.
1514  Structors.push_back(Structor());
1515  Structor &S = Structors.back();
1516  S.Priority = Priority->getLimitedValue(65535);
1517  S.Func = CS->getOperand(1);
1518  if (ETy->getNumElements() == 3 && !CS->getOperand(2)->isNullValue())
1519  S.ComdatKey = dyn_cast<GlobalValue>(CS->getOperand(2)->stripPointerCasts());
1520  }
1521 
1522  // Emit the function pointers in the target-specific order
1523  const DataLayout *DL = TM.getDataLayout();
1524  unsigned Align = Log2_32(DL->getPointerPrefAlignment());
1525  std::stable_sort(Structors.begin(), Structors.end(),
1526  [](const Structor &L,
1527  const Structor &R) { return L.Priority < R.Priority; });
1528  for (Structor &S : Structors) {
1530  const MCSymbol *KeySym = nullptr;
1531  if (GlobalValue *GV = S.ComdatKey) {
1533  // If the associated variable is available_externally, some other TU
1534  // will provide its dynamic initializer.
1535  continue;
1536 
1537  KeySym = getSymbol(GV);
1538  }
1539  MCSection *OutputSection =
1540  (isCtor ? Obj.getStaticCtorSection(S.Priority, KeySym)
1541  : Obj.getStaticDtorSection(S.Priority, KeySym));
1542  OutStreamer->SwitchSection(OutputSection);
1543  if (OutStreamer->getCurrentSection() != OutStreamer->getPreviousSection())
1544  EmitAlignment(Align);
1545  EmitXXStructor(S.Func);
1546  }
1547 }
1548 
1549 void AsmPrinter::EmitModuleIdents(Module &M) {
1550  if (!MAI->hasIdentDirective())
1551  return;
1552 
1553  if (const NamedMDNode *NMD = M.getNamedMetadata("llvm.ident")) {
1554  for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1555  const MDNode *N = NMD->getOperand(i);
1556  assert(N->getNumOperands() == 1 &&
1557  "llvm.ident metadata entry can have only one operand");
1558  const MDString *S = cast<MDString>(N->getOperand(0));
1559  OutStreamer->EmitIdent(S->getString());
1560  }
1561  }
1562 }
1563 
1564 //===--------------------------------------------------------------------===//
1565 // Emission and print routines
1566 //
1567 
1568 /// EmitInt8 - Emit a byte directive and value.
1569 ///
1570 void AsmPrinter::EmitInt8(int Value) const {
1571  OutStreamer->EmitIntValue(Value, 1);
1572 }
1573 
1574 /// EmitInt16 - Emit a short directive and value.
1575 ///
1576 void AsmPrinter::EmitInt16(int Value) const {
1577  OutStreamer->EmitIntValue(Value, 2);
1578 }
1579 
1580 /// EmitInt32 - Emit a long directive and value.
1581 ///
1582 void AsmPrinter::EmitInt32(int Value) const {
1583  OutStreamer->EmitIntValue(Value, 4);
1584 }
1585 
1586 /// Emit something like ".long Hi-Lo" where the size in bytes of the directive
1587 /// is specified by Size and Hi/Lo specify the labels. This implicitly uses
1588 /// .set if it avoids relocations.
1590  unsigned Size) const {
1591  OutStreamer->emitAbsoluteSymbolDiff(Hi, Lo, Size);
1592 }
1593 
1594 /// EmitLabelPlusOffset - Emit something like ".long Label+Offset"
1595 /// where the size in bytes of the directive is specified by Size and Label
1596 /// specifies the label. This implicitly uses .set if it is available.
1597 void AsmPrinter::EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
1598  unsigned Size,
1599  bool IsSectionRelative) const {
1600  if (MAI->needsDwarfSectionOffsetDirective() && IsSectionRelative) {
1601  OutStreamer->EmitCOFFSecRel32(Label);
1602  return;
1603  }
1604 
1605  // Emit Label+Offset (or just Label if Offset is zero)
1606  const MCExpr *Expr = MCSymbolRefExpr::create(Label, OutContext);
1607  if (Offset)
1608  Expr = MCBinaryExpr::createAdd(
1609  Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
1610 
1611  OutStreamer->EmitValue(Expr, Size);
1612 }
1613 
1614 //===----------------------------------------------------------------------===//
1615 
1616 // EmitAlignment - Emit an alignment directive to the specified power of
1617 // two boundary. For example, if you pass in 3 here, you will get an 8
1618 // byte alignment. If a global value is specified, and if that global has
1619 // an explicit alignment requested, it will override the alignment request
1620 // if required for correctness.
1621 //
1622 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalObject *GV) const {
1623  if (GV)
1624  NumBits = getGVAlignmentLog2(GV, *TM.getDataLayout(),
1625  NumBits);
1626 
1627  if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
1628 
1629  assert(NumBits <
1630  static_cast<unsigned>(std::numeric_limits<unsigned>::digits) &&
1631  "undefined behavior");
1632  if (getCurrentSection()->getKind().isText())
1633  OutStreamer->EmitCodeAlignment(1u << NumBits);
1634  else
1635  OutStreamer->EmitValueToAlignment(1u << NumBits);
1636 }
1637 
1638 //===----------------------------------------------------------------------===//
1639 // Constant emission.
1640 //===----------------------------------------------------------------------===//
1641 
1643  MCContext &Ctx = OutContext;
1644 
1645  if (CV->isNullValue() || isa<UndefValue>(CV))
1646  return MCConstantExpr::create(0, Ctx);
1647 
1648  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
1649  return MCConstantExpr::create(CI->getZExtValue(), Ctx);
1650 
1651  if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
1652  return MCSymbolRefExpr::create(getSymbol(GV), Ctx);
1653 
1654  if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV))
1656 
1657  const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
1658  if (!CE) {
1659  llvm_unreachable("Unknown constant value to lower!");
1660  }
1661 
1662  if (const MCExpr *RelocExpr
1663  = getObjFileLowering().getExecutableRelativeSymbol(CE, *Mang, TM))
1664  return RelocExpr;
1665 
1666  switch (CE->getOpcode()) {
1667  default:
1668  // If the code isn't optimized, there may be outstanding folding
1669  // opportunities. Attempt to fold the expression using DataLayout as a
1670  // last resort before giving up.
1672  if (C != CE)
1673  return lowerConstant(C);
1674 
1675  // Otherwise report the problem to the user.
1676  {
1677  std::string S;
1678  raw_string_ostream OS(S);
1679  OS << "Unsupported expression in static initializer: ";
1680  CE->printAsOperand(OS, /*PrintType=*/false,
1681  !MF ? nullptr : MF->getFunction()->getParent());
1682  report_fatal_error(OS.str());
1683  }
1684  case Instruction::GetElementPtr: {
1685  const DataLayout &DL = *TM.getDataLayout();
1686 
1687  // Generate a symbolic expression for the byte address
1688  APInt OffsetAI(DL.getPointerTypeSizeInBits(CE->getType()), 0);
1689  cast<GEPOperator>(CE)->accumulateConstantOffset(DL, OffsetAI);
1690 
1691  const MCExpr *Base = lowerConstant(CE->getOperand(0));
1692  if (!OffsetAI)
1693  return Base;
1694 
1695  int64_t Offset = OffsetAI.getSExtValue();
1696  return MCBinaryExpr::createAdd(Base, MCConstantExpr::create(Offset, Ctx),
1697  Ctx);
1698  }
1699 
1700  case Instruction::Trunc:
1701  // We emit the value and depend on the assembler to truncate the generated
1702  // expression properly. This is important for differences between
1703  // blockaddress labels. Since the two labels are in the same function, it
1704  // is reasonable to treat their delta as a 32-bit value.
1705  // FALL THROUGH.
1706  case Instruction::BitCast:
1707  return lowerConstant(CE->getOperand(0));
1708 
1709  case Instruction::IntToPtr: {
1710  const DataLayout &DL = *TM.getDataLayout();
1711 
1712  // Handle casts to pointers by changing them into casts to the appropriate
1713  // integer type. This promotes constant folding and simplifies this code.
1714  Constant *Op = CE->getOperand(0);
1716  false/*ZExt*/);
1717  return lowerConstant(Op);
1718  }
1719 
1720  case Instruction::PtrToInt: {
1721  const DataLayout &DL = *TM.getDataLayout();
1722 
1723  // Support only foldable casts to/from pointers that can be eliminated by
1724  // changing the pointer to the appropriately sized integer type.
1725  Constant *Op = CE->getOperand(0);
1726  Type *Ty = CE->getType();
1727 
1728  const MCExpr *OpExpr = lowerConstant(Op);
1729 
1730  // We can emit the pointer value into this slot if the slot is an
1731  // integer slot equal to the size of the pointer.
1732  if (DL.getTypeAllocSize(Ty) == DL.getTypeAllocSize(Op->getType()))
1733  return OpExpr;
1734 
1735  // Otherwise the pointer is smaller than the resultant integer, mask off
1736  // the high bits so we are sure to get a proper truncation if the input is
1737  // a constant expr.
1738  unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType());
1739  const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx);
1740  return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx);
1741  }
1742 
1743  // The MC library also has a right-shift operator, but it isn't consistently
1744  // signed or unsigned between different targets.
1745  case Instruction::Add:
1746  case Instruction::Sub:
1747  case Instruction::Mul:
1748  case Instruction::SDiv:
1749  case Instruction::SRem:
1750  case Instruction::Shl:
1751  case Instruction::And:
1752  case Instruction::Or:
1753  case Instruction::Xor: {
1754  const MCExpr *LHS = lowerConstant(CE->getOperand(0));
1755  const MCExpr *RHS = lowerConstant(CE->getOperand(1));
1756  switch (CE->getOpcode()) {
1757  default: llvm_unreachable("Unknown binary operator constant cast expr");
1758  case Instruction::Add: return MCBinaryExpr::createAdd(LHS, RHS, Ctx);
1759  case Instruction::Sub: return MCBinaryExpr::createSub(LHS, RHS, Ctx);
1760  case Instruction::Mul: return MCBinaryExpr::createMul(LHS, RHS, Ctx);
1761  case Instruction::SDiv: return MCBinaryExpr::createDiv(LHS, RHS, Ctx);
1762  case Instruction::SRem: return MCBinaryExpr::createMod(LHS, RHS, Ctx);
1763  case Instruction::Shl: return MCBinaryExpr::createShl(LHS, RHS, Ctx);
1764  case Instruction::And: return MCBinaryExpr::createAnd(LHS, RHS, Ctx);
1765  case Instruction::Or: return MCBinaryExpr::createOr (LHS, RHS, Ctx);
1766  case Instruction::Xor: return MCBinaryExpr::createXor(LHS, RHS, Ctx);
1767  }
1768  }
1769  }
1770 }
1771 
1772 static void emitGlobalConstantImpl(const Constant *C, AsmPrinter &AP,
1773  const Constant *BaseCV = nullptr,
1774  uint64_t Offset = 0);
1775 
1776 /// isRepeatedByteSequence - Determine whether the given value is
1777 /// composed of a repeated sequence of identical bytes and return the
1778 /// byte value. If it is not a repeated sequence, return -1.
1781  assert(!Data.empty() && "Empty aggregates should be CAZ node");
1782  char C = Data[0];
1783  for (unsigned i = 1, e = Data.size(); i != e; ++i)
1784  if (Data[i] != C) return -1;
1785  return static_cast<uint8_t>(C); // Ensure 255 is not returned as -1.
1786 }
1787 
1788 
1789 /// isRepeatedByteSequence - Determine whether the given value is
1790 /// composed of a repeated sequence of identical bytes and return the
1791 /// byte value. If it is not a repeated sequence, return -1.
1792 static int isRepeatedByteSequence(const Value *V, TargetMachine &TM) {
1793  if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
1794  uint64_t Size = TM.getDataLayout()->getTypeAllocSizeInBits(V->getType());
1795  assert(Size % 8 == 0);
1796 
1797  // Extend the element to take zero padding into account.
1798  APInt Value = CI->getValue().zextOrSelf(Size);
1799  if (!Value.isSplat(8))
1800  return -1;
1801 
1802  return Value.zextOrTrunc(8).getZExtValue();
1803  }
1804  if (const ConstantArray *CA = dyn_cast<ConstantArray>(V)) {
1805  // Make sure all array elements are sequences of the same repeated
1806  // byte.
1807  assert(CA->getNumOperands() != 0 && "Should be a CAZ");
1808  Constant *Op0 = CA->getOperand(0);
1809  int Byte = isRepeatedByteSequence(Op0, TM);
1810  if (Byte == -1)
1811  return -1;
1812 
1813  // All array elements must be equal.
1814  for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i)
1815  if (CA->getOperand(i) != Op0)
1816  return -1;
1817  return Byte;
1818  }
1819 
1820  if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(V))
1821  return isRepeatedByteSequence(CDS);
1822 
1823  return -1;
1824 }
1825 
1827  AsmPrinter &AP){
1828 
1829  // See if we can aggregate this into a .fill, if so, emit it as such.
1830  int Value = isRepeatedByteSequence(CDS, AP.TM);
1831  if (Value != -1) {
1832  uint64_t Bytes =
1834  CDS->getType());
1835  // Don't emit a 1-byte object as a .fill.
1836  if (Bytes > 1)
1837  return AP.OutStreamer->EmitFill(Bytes, Value);
1838  }
1839 
1840  // If this can be emitted with .ascii/.asciz, emit it as such.
1841  if (CDS->isString())
1842  return AP.OutStreamer->EmitBytes(CDS->getAsString());
1843 
1844  // Otherwise, emit the values in successive locations.
1845  unsigned ElementByteSize = CDS->getElementByteSize();
1846  if (isa<IntegerType>(CDS->getElementType())) {
1847  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1848  if (AP.isVerbose())
1849  AP.OutStreamer->GetCommentOS() << format("0x%" PRIx64 "\n",
1850  CDS->getElementAsInteger(i));
1851  AP.OutStreamer->EmitIntValue(CDS->getElementAsInteger(i),
1852  ElementByteSize);
1853  }
1854  } else if (ElementByteSize == 4) {
1855  // FP Constants are printed as integer constants to avoid losing
1856  // precision.
1857  assert(CDS->getElementType()->isFloatTy());
1858  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1859  union {
1860  float F;
1861  uint32_t I;
1862  };
1863 
1864  F = CDS->getElementAsFloat(i);
1865  if (AP.isVerbose())
1866  AP.OutStreamer->GetCommentOS() << "float " << F << '\n';
1867  AP.OutStreamer->EmitIntValue(I, 4);
1868  }
1869  } else {
1870  assert(CDS->getElementType()->isDoubleTy());
1871  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1872  union {
1873  double F;
1874  uint64_t I;
1875  };
1876 
1877  F = CDS->getElementAsDouble(i);
1878  if (AP.isVerbose())
1879  AP.OutStreamer->GetCommentOS() << "double " << F << '\n';
1880  AP.OutStreamer->EmitIntValue(I, 8);
1881  }
1882  }
1883 
1884  const DataLayout &DL = *AP.TM.getDataLayout();
1885  unsigned Size = DL.getTypeAllocSize(CDS->getType());
1886  unsigned EmittedSize = DL.getTypeAllocSize(CDS->getType()->getElementType()) *
1887  CDS->getNumElements();
1888  if (unsigned Padding = Size - EmittedSize)
1889  AP.OutStreamer->EmitZeros(Padding);
1890 
1891 }
1892 
1894  const Constant *BaseCV, uint64_t Offset) {
1895  // See if we can aggregate some values. Make sure it can be
1896  // represented as a series of bytes of the constant value.
1897  int Value = isRepeatedByteSequence(CA, AP.TM);
1898  const DataLayout &DL = *AP.TM.getDataLayout();
1899 
1900  if (Value != -1) {
1901  uint64_t Bytes = DL.getTypeAllocSize(CA->getType());
1902  AP.OutStreamer->EmitFill(Bytes, Value);
1903  }
1904  else {
1905  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) {
1906  emitGlobalConstantImpl(CA->getOperand(i), AP, BaseCV, Offset);
1907  Offset += DL.getTypeAllocSize(CA->getOperand(i)->getType());
1908  }
1909  }
1910 }
1911 
1913  for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
1914  emitGlobalConstantImpl(CV->getOperand(i), AP);
1915 
1916  const DataLayout &DL = *AP.TM.getDataLayout();
1917  unsigned Size = DL.getTypeAllocSize(CV->getType());
1918  unsigned EmittedSize = DL.getTypeAllocSize(CV->getType()->getElementType()) *
1919  CV->getType()->getNumElements();
1920  if (unsigned Padding = Size - EmittedSize)
1921  AP.OutStreamer->EmitZeros(Padding);
1922 }
1923 
1925  const Constant *BaseCV, uint64_t Offset) {
1926  // Print the fields in successive locations. Pad to align if needed!
1927  const DataLayout *DL = AP.TM.getDataLayout();
1928  unsigned Size = DL->getTypeAllocSize(CS->getType());
1929  const StructLayout *Layout = DL->getStructLayout(CS->getType());
1930  uint64_t SizeSoFar = 0;
1931  for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
1932  const Constant *Field = CS->getOperand(i);
1933 
1934  // Print the actual field value.
1935  emitGlobalConstantImpl(Field, AP, BaseCV, Offset+SizeSoFar);
1936 
1937  // Check if padding is needed and insert one or more 0s.
1938  uint64_t FieldSize = DL->getTypeAllocSize(Field->getType());
1939  uint64_t PadSize = ((i == e-1 ? Size : Layout->getElementOffset(i+1))
1940  - Layout->getElementOffset(i)) - FieldSize;
1941  SizeSoFar += FieldSize + PadSize;
1942 
1943  // Insert padding - this may include padding to increase the size of the
1944  // current field up to the ABI size (if the struct is not packed) as well
1945  // as padding to ensure that the next field starts at the right offset.
1946  AP.OutStreamer->EmitZeros(PadSize);
1947  }
1948  assert(SizeSoFar == Layout->getSizeInBytes() &&
1949  "Layout of constant struct may be incorrect!");
1950 }
1951 
1952 static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
1953  APInt API = CFP->getValueAPF().bitcastToAPInt();
1954 
1955  // First print a comment with what we think the original floating-point value
1956  // should have been.
1957  if (AP.isVerbose()) {
1959  CFP->getValueAPF().toString(StrVal);
1960 
1961  if (CFP->getType())
1962  CFP->getType()->print(AP.OutStreamer->GetCommentOS());
1963  else
1964  AP.OutStreamer->GetCommentOS() << "Printing <null> Type";
1965  AP.OutStreamer->GetCommentOS() << ' ' << StrVal << '\n';
1966  }
1967 
1968  // Now iterate through the APInt chunks, emitting them in endian-correct
1969  // order, possibly with a smaller chunk at beginning/end (e.g. for x87 80-bit
1970  // floats).
1971  unsigned NumBytes = API.getBitWidth() / 8;
1972  unsigned TrailingBytes = NumBytes % sizeof(uint64_t);
1973  const uint64_t *p = API.getRawData();
1974 
1975  // PPC's long double has odd notions of endianness compared to how LLVM
1976  // handles it: p[0] goes first for *big* endian on PPC.
1977  if (AP.TM.getDataLayout()->isBigEndian() &&
1978  !CFP->getType()->isPPC_FP128Ty()) {
1979  int Chunk = API.getNumWords() - 1;
1980 
1981  if (TrailingBytes)
1982  AP.OutStreamer->EmitIntValue(p[Chunk--], TrailingBytes);
1983 
1984  for (; Chunk >= 0; --Chunk)
1985  AP.OutStreamer->EmitIntValue(p[Chunk], sizeof(uint64_t));
1986  } else {
1987  unsigned Chunk;
1988  for (Chunk = 0; Chunk < NumBytes / sizeof(uint64_t); ++Chunk)
1989  AP.OutStreamer->EmitIntValue(p[Chunk], sizeof(uint64_t));
1990 
1991  if (TrailingBytes)
1992  AP.OutStreamer->EmitIntValue(p[Chunk], TrailingBytes);
1993  }
1994 
1995  // Emit the tail padding for the long double.
1996  const DataLayout &DL = *AP.TM.getDataLayout();
1997  AP.OutStreamer->EmitZeros(DL.getTypeAllocSize(CFP->getType()) -
1998  DL.getTypeStoreSize(CFP->getType()));
1999 }
2000 
2002  const DataLayout *DL = AP.TM.getDataLayout();
2003  unsigned BitWidth = CI->getBitWidth();
2004 
2005  // Copy the value as we may massage the layout for constants whose bit width
2006  // is not a multiple of 64-bits.
2007  APInt Realigned(CI->getValue());
2008  uint64_t ExtraBits = 0;
2009  unsigned ExtraBitsSize = BitWidth & 63;
2010 
2011  if (ExtraBitsSize) {
2012  // The bit width of the data is not a multiple of 64-bits.
2013  // The extra bits are expected to be at the end of the chunk of the memory.
2014  // Little endian:
2015  // * Nothing to be done, just record the extra bits to emit.
2016  // Big endian:
2017  // * Record the extra bits to emit.
2018  // * Realign the raw data to emit the chunks of 64-bits.
2019  if (DL->isBigEndian()) {
2020  // Basically the structure of the raw data is a chunk of 64-bits cells:
2021  // 0 1 BitWidth / 64
2022  // [chunk1][chunk2] ... [chunkN].
2023  // The most significant chunk is chunkN and it should be emitted first.
2024  // However, due to the alignment issue chunkN contains useless bits.
2025  // Realign the chunks so that they contain only useless information:
2026  // ExtraBits 0 1 (BitWidth / 64) - 1
2027  // chu[nk1 chu][nk2 chu] ... [nkN-1 chunkN]
2028  ExtraBits = Realigned.getRawData()[0] &
2029  (((uint64_t)-1) >> (64 - ExtraBitsSize));
2030  Realigned = Realigned.lshr(ExtraBitsSize);
2031  } else
2032  ExtraBits = Realigned.getRawData()[BitWidth / 64];
2033  }
2034 
2035  // We don't expect assemblers to support integer data directives
2036  // for more than 64 bits, so we emit the data in at most 64-bit
2037  // quantities at a time.
2038  const uint64_t *RawData = Realigned.getRawData();
2039  for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
2040  uint64_t Val = DL->isBigEndian() ? RawData[e - i - 1] : RawData[i];
2041  AP.OutStreamer->EmitIntValue(Val, 8);
2042  }
2043 
2044  if (ExtraBitsSize) {
2045  // Emit the extra bits after the 64-bits chunks.
2046 
2047  // Emit a directive that fills the expected size.
2048  uint64_t Size = AP.TM.getDataLayout()->getTypeAllocSize(
2049  CI->getType());
2050  Size -= (BitWidth / 64) * 8;
2051  assert(Size && Size * 8 >= ExtraBitsSize &&
2052  (ExtraBits & (((uint64_t)-1) >> (64 - ExtraBitsSize)))
2053  == ExtraBits && "Directive too small for extra bits.");
2054  AP.OutStreamer->EmitIntValue(ExtraBits, Size);
2055  }
2056 }
2057 
2058 /// \brief Transform a not absolute MCExpr containing a reference to a GOT
2059 /// equivalent global, by a target specific GOT pc relative access to the
2060 /// final symbol.
2061 static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
2062  const Constant *BaseCst,
2063  uint64_t Offset) {
2064  // The global @foo below illustrates a global that uses a got equivalent.
2065  //
2066  // @bar = global i32 42
2067  // @gotequiv = private unnamed_addr constant i32* @bar
2068  // @foo = i32 trunc (i64 sub (i64 ptrtoint (i32** @gotequiv to i64),
2069  // i64 ptrtoint (i32* @foo to i64))
2070  // to i32)
2071  //
2072  // The cstexpr in @foo is converted into the MCExpr `ME`, where we actually
2073  // check whether @foo is suitable to use a GOTPCREL. `ME` is usually in the
2074  // form:
2075  //
2076  // foo = cstexpr, where
2077  // cstexpr := <gotequiv> - "." + <cst>
2078  // cstexpr := <gotequiv> - (<foo> - <offset from @foo base>) + <cst>
2079  //
2080  // After canonicalization by evaluateAsRelocatable `ME` turns into:
2081  //
2082  // cstexpr := <gotequiv> - <foo> + gotpcrelcst, where
2083  // gotpcrelcst := <offset from @foo base> + <cst>
2084  //
2085  MCValue MV;
2086  if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
2087  return;
2088  const MCSymbolRefExpr *SymA = MV.getSymA();
2089  if (!SymA)
2090  return;
2091 
2092  // Check that GOT equivalent symbol is cached.
2093  const MCSymbol *GOTEquivSym = &SymA->getSymbol();
2094  if (!AP.GlobalGOTEquivs.count(GOTEquivSym))
2095  return;
2096 
2097  const GlobalValue *BaseGV = dyn_cast<GlobalValue>(BaseCst);
2098  if (!BaseGV)
2099  return;
2100 
2101  // Check for a valid base symbol
2102  const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
2103  const MCSymbolRefExpr *SymB = MV.getSymB();
2104 
2105  if (!SymB || BaseSym != &SymB->getSymbol())
2106  return;
2107 
2108  // Make sure to match:
2109  //
2110  // gotpcrelcst := <offset from @foo base> + <cst>
2111  //
2112  // If gotpcrelcst is positive it means that we can safely fold the pc rel
2113  // displacement into the GOTPCREL. We can also can have an extra offset <cst>
2114  // if the target knows how to encode it.
2115  //
2116  int64_t GOTPCRelCst = Offset + MV.getConstant();
2117  if (GOTPCRelCst < 0)
2118  return;
2119  if (!AP.getObjFileLowering().supportGOTPCRelWithOffset() && GOTPCRelCst != 0)
2120  return;
2121 
2122  // Emit the GOT PC relative to replace the got equivalent global, i.e.:
2123  //
2124  // bar:
2125  // .long 42
2126  // gotequiv:
2127  // .quad bar
2128  // foo:
2129  // .long gotequiv - "." + <cst>
2130  //
2131  // is replaced by the target specific equivalent to:
2132  //
2133  // bar:
2134  // .long 42
2135  // foo:
2136  // .long bar@GOTPCREL+<gotpcrelcst>
2137  //
2138  AsmPrinter::GOTEquivUsePair Result = AP.GlobalGOTEquivs[GOTEquivSym];
2139  const GlobalVariable *GV = Result.first;
2140  int NumUses = (int)Result.second;
2141  const GlobalValue *FinalGV = dyn_cast<GlobalValue>(GV->getOperand(0));
2142  const MCSymbol *FinalSym = AP.getSymbol(FinalGV);
2144  FinalSym, MV, Offset, AP.MMI, *AP.OutStreamer);
2145 
2146  // Update GOT equivalent usage information
2147  --NumUses;
2148  if (NumUses >= 0)
2149  AP.GlobalGOTEquivs[GOTEquivSym] = std::make_pair(GV, NumUses);
2150 }
2151 
2152 static void emitGlobalConstantImpl(const Constant *CV, AsmPrinter &AP,
2153  const Constant *BaseCV, uint64_t Offset) {
2154  const DataLayout *DL = AP.TM.getDataLayout();
2155  uint64_t Size = DL->getTypeAllocSize(CV->getType());
2156 
2157  // Globals with sub-elements such as combinations of arrays and structs
2158  // are handled recursively by emitGlobalConstantImpl. Keep track of the
2159  // constant symbol base and the current position with BaseCV and Offset.
2160  if (!BaseCV && CV->hasOneUse())
2161  BaseCV = dyn_cast<Constant>(CV->user_back());
2162 
2163  if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(CV))
2164  return AP.OutStreamer->EmitZeros(Size);
2165 
2166  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
2167  switch (Size) {
2168  case 1:
2169  case 2:
2170  case 4:
2171  case 8:
2172  if (AP.isVerbose())
2173  AP.OutStreamer->GetCommentOS() << format("0x%" PRIx64 "\n",
2174  CI->getZExtValue());
2175  AP.OutStreamer->EmitIntValue(CI->getZExtValue(), Size);
2176  return;
2177  default:
2179  return;
2180  }
2181  }
2182 
2183  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
2184  return emitGlobalConstantFP(CFP, AP);
2185 
2186  if (isa<ConstantPointerNull>(CV)) {
2187  AP.OutStreamer->EmitIntValue(0, Size);
2188  return;
2189  }
2190 
2191  if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(CV))
2192  return emitGlobalConstantDataSequential(CDS, AP);
2193 
2194  if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
2195  return emitGlobalConstantArray(CVA, AP, BaseCV, Offset);
2196 
2197  if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV))
2198  return emitGlobalConstantStruct(CVS, AP, BaseCV, Offset);
2199 
2200  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
2201  // Look through bitcasts, which might not be able to be MCExpr'ized (e.g. of
2202  // vectors).
2203  if (CE->getOpcode() == Instruction::BitCast)
2204  return emitGlobalConstantImpl(CE->getOperand(0), AP);
2205 
2206  if (Size > 8) {
2207  // If the constant expression's size is greater than 64-bits, then we have
2208  // to emit the value in chunks. Try to constant fold the value and emit it
2209  // that way.
2210  Constant *New = ConstantFoldConstantExpression(CE, *DL);
2211  if (New && New != CE)
2212  return emitGlobalConstantImpl(New, AP);
2213  }
2214  }
2215 
2216  if (const ConstantVector *V = dyn_cast<ConstantVector>(CV))
2217  return emitGlobalConstantVector(V, AP);
2218 
2219  // Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it
2220  // thread the streamer with EmitValue.
2221  const MCExpr *ME = AP.lowerConstant(CV);
2222 
2223  // Since lowerConstant already folded and got rid of all IR pointer and
2224  // integer casts, detect GOT equivalent accesses by looking into the MCExpr
2225  // directly.
2227  handleIndirectSymViaGOTPCRel(AP, &ME, BaseCV, Offset);
2228 
2229  AP.OutStreamer->EmitValue(ME, Size);
2230 }
2231 
2232 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
2234  uint64_t Size =
2236  if (Size)
2237  emitGlobalConstantImpl(CV, *this);
2238  else if (MAI->hasSubsectionsViaSymbols()) {
2239  // If the global has zero size, emit a single byte so that two labels don't
2240  // look like they are at the same location.
2241  OutStreamer->EmitIntValue(0, 1);
2242  }
2243 }
2244 
2246  // Target doesn't support this yet!
2247  llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
2248 }
2249 
2250 void AsmPrinter::printOffset(int64_t Offset, raw_ostream &OS) const {
2251  if (Offset > 0)
2252  OS << '+' << Offset;
2253  else if (Offset < 0)
2254  OS << Offset;
2255 }
2256 
2257 //===----------------------------------------------------------------------===//
2258 // Symbol Lowering Routines.
2259 //===----------------------------------------------------------------------===//
2260 
2262  return OutContext.createTempSymbol(Name, true);
2263 }
2264 
2266  return MMI->getAddrLabelSymbol(BA->getBasicBlock());
2267 }
2268 
2270  return MMI->getAddrLabelSymbol(BB);
2271 }
2272 
2273 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
2274 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
2275  const DataLayout *DL = TM.getDataLayout();
2278  + "_" + Twine(CPID));
2279 }
2280 
2281 /// GetJTISymbol - Return the symbol for the specified jump table entry.
2282 MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
2283  return MF->getJTISymbol(JTID, OutContext, isLinkerPrivate);
2284 }
2285 
2286 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
2287 /// FIXME: privatize to AsmPrinter.
2288 MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const {
2289  const DataLayout *DL = TM.getDataLayout();
2292  Twine(UID) + "_set_" + Twine(MBBID));
2293 }
2294 
2296  StringRef Suffix) const {
2298  TM);
2299 }
2300 
2301 /// Return the MCSymbol for the specified ExternalSymbol.
2303  SmallString<60> NameStr;
2304  Mangler::getNameWithPrefix(NameStr, Sym, *TM.getDataLayout());
2305  return OutContext.getOrCreateSymbol(NameStr);
2306 }
2307 
2308 
2309 
2310 /// PrintParentLoopComment - Print comments about parent loops of this one.
2312  unsigned FunctionNumber) {
2313  if (!Loop) return;
2315  OS.indent(Loop->getLoopDepth()*2)
2316  << "Parent Loop BB" << FunctionNumber << "_"
2317  << Loop->getHeader()->getNumber()
2318  << " Depth=" << Loop->getLoopDepth() << '\n';
2319 }
2320 
2321 
2322 /// PrintChildLoopComment - Print comments about child loops within
2323 /// the loop for this basic block, with nesting.
2325  unsigned FunctionNumber) {
2326  // Add child loop information
2327  for (const MachineLoop *CL : *Loop) {
2328  OS.indent(CL->getLoopDepth()*2)
2329  << "Child Loop BB" << FunctionNumber << "_"
2330  << CL->getHeader()->getNumber() << " Depth " << CL->getLoopDepth()
2331  << '\n';
2332  PrintChildLoopComment(OS, CL, FunctionNumber);
2333  }
2334 }
2335 
2336 /// emitBasicBlockLoopComments - Pretty-print comments for basic blocks.
2338  const MachineLoopInfo *LI,
2339  const AsmPrinter &AP) {
2340  // Add loop depth information
2341  const MachineLoop *Loop = LI->getLoopFor(&MBB);
2342  if (!Loop) return;
2343 
2344  MachineBasicBlock *Header = Loop->getHeader();
2345  assert(Header && "No header for loop");
2346 
2347  // If this block is not a loop header, just print out what is the loop header
2348  // and return.
2349  if (Header != &MBB) {
2350  AP.OutStreamer->AddComment(" in Loop: Header=BB" +
2351  Twine(AP.getFunctionNumber())+"_" +
2352  Twine(Loop->getHeader()->getNumber())+
2353  " Depth="+Twine(Loop->getLoopDepth()));
2354  return;
2355  }
2356 
2357  // Otherwise, it is a loop header. Print out information about child and
2358  // parent loops.
2359  raw_ostream &OS = AP.OutStreamer->GetCommentOS();
2360 
2362 
2363  OS << "=>";
2364  OS.indent(Loop->getLoopDepth()*2-2);
2365 
2366  OS << "This ";
2367  if (Loop->empty())
2368  OS << "Inner ";
2369  OS << "Loop Header: Depth=" + Twine(Loop->getLoopDepth()) << '\n';
2370 
2371  PrintChildLoopComment(OS, Loop, AP.getFunctionNumber());
2372 }
2373 
2374 
2375 /// EmitBasicBlockStart - This method prints the label for the specified
2376 /// MachineBasicBlock, an alignment (if present) and a comment describing
2377 /// it if appropriate.
2379  // Emit an alignment directive for this block, if needed.
2380  if (unsigned Align = MBB.getAlignment())
2381  EmitAlignment(Align);
2382 
2383  // If the block has its address taken, emit any labels that were used to
2384  // reference the block. It is possible that there is more than one label
2385  // here, because multiple LLVM BB's may have been RAUW'd to this block after
2386  // the references were generated.
2387  if (MBB.hasAddressTaken()) {
2388  const BasicBlock *BB = MBB.getBasicBlock();
2389  if (isVerbose())
2390  OutStreamer->AddComment("Block address taken");
2391 
2392  for (MCSymbol *Sym : MMI->getAddrLabelSymbolToEmit(BB))
2393  OutStreamer->EmitLabel(Sym);
2394  }
2395 
2396  // Print some verbose block comments.
2397  if (isVerbose()) {
2398  if (const BasicBlock *BB = MBB.getBasicBlock())
2399  if (BB->hasName())
2400  OutStreamer->AddComment("%" + BB->getName());
2401  emitBasicBlockLoopComments(MBB, LI, *this);
2402  }
2403 
2404  // Print the main label for the block.
2405  if (MBB.pred_empty() || isBlockOnlyReachableByFallthrough(&MBB)) {
2406  if (isVerbose()) {
2407  // NOTE: Want this comment at start of line, don't emit with AddComment.
2408  OutStreamer->emitRawComment(" BB#" + Twine(MBB.getNumber()) + ":", false);
2409  }
2410  } else {
2411  OutStreamer->EmitLabel(MBB.getSymbol());
2412  }
2413 }
2414 
2415 void AsmPrinter::EmitVisibility(MCSymbol *Sym, unsigned Visibility,
2416  bool IsDefinition) const {
2417  MCSymbolAttr Attr = MCSA_Invalid;
2418 
2419  switch (Visibility) {
2420  default: break;
2422  if (IsDefinition)
2423  Attr = MAI->getHiddenVisibilityAttr();
2424  else
2426  break;
2428  Attr = MAI->getProtectedVisibilityAttr();
2429  break;
2430  }
2431 
2432  if (Attr != MCSA_Invalid)
2433  OutStreamer->EmitSymbolAttribute(Sym, Attr);
2434 }
2435 
2436 /// isBlockOnlyReachableByFallthough - Return true if the basic block has
2437 /// exactly one predecessor and the control transfer mechanism between
2438 /// the predecessor and this block is a fall-through.
2439 bool AsmPrinter::
2441  // If this is a landing pad, it isn't a fall through. If it has no preds,
2442  // then nothing falls through to it.
2443  if (MBB->isLandingPad() || MBB->pred_empty())
2444  return false;
2445 
2446  // If there isn't exactly one predecessor, it can't be a fall through.
2447  if (MBB->pred_size() > 1)
2448  return false;
2449 
2450  // The predecessor has to be immediately before this block.
2451  MachineBasicBlock *Pred = *MBB->pred_begin();
2452  if (!Pred->isLayoutSuccessor(MBB))
2453  return false;
2454 
2455  // If the block is completely empty, then it definitely does fall through.
2456  if (Pred->empty())
2457  return true;
2458 
2459  // Check the terminators in the previous blocks
2460  for (const auto &MI : Pred->terminators()) {
2461  // If it is not a simple branch, we are in a table somewhere.
2462  if (!MI.isBranch() || MI.isIndirectBranch())
2463  return false;
2464 
2465  // If we are the operands of one of the branches, this is not a fall
2466  // through. Note that targets with delay slots will usually bundle
2467  // terminators with the delay slot instruction.
2468  for (ConstMIBundleOperands OP(&MI); OP.isValid(); ++OP) {
2469  if (OP->isJTI())
2470  return false;
2471  if (OP->isMBB() && OP->getMBB() == MBB)
2472  return false;
2473  }
2474  }
2475 
2476  return true;
2477 }
2478 
2479 
2480 
2481 GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) {
2482  if (!S.usesMetadata())
2483  return nullptr;
2484 
2485  assert(!S.useStatepoints() && "statepoints do not currently support custom"
2486  " stackmap formats, please see the documentation for a description of"
2487  " the default format. If you really need a custom serialized format,"
2488  " please file a bug");
2489 
2490  gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
2491  gcp_map_type::iterator GCPI = GCMap.find(&S);
2492  if (GCPI != GCMap.end())
2493  return GCPI->second.get();
2494 
2495  const char *Name = S.getName().c_str();
2496 
2499  E = GCMetadataPrinterRegistry::end(); I != E; ++I)
2500  if (strcmp(Name, I->getName()) == 0) {
2501  std::unique_ptr<GCMetadataPrinter> GMP = I->instantiate();
2502  GMP->S = &S;
2503  auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP)));
2504  return IterBool.first->second.get();
2505  }
2506 
2507  report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name));
2508 }
2509 
2510 /// Pin vtable to this file.
2512 
virtual void EmitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:344
MachineConstantPoolValue * MachineCPVal
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
bool usesMetadata() const
If set, appropriate metadata tables must be emitted by the back-end (assembler, JIT, or otherwise).
Definition: GCStrategy.h:159
void push_back(const T &Elt)
Definition: SmallVector.h:222
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
virtual void EmitStartOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the start of their fi...
Definition: AsmPrinter.h:283
bool doesSupportDebugInformation() const
Definition: MCAsmInfo.h:507
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
bool useAssignmentForEHBegin() const
Definition: MCAsmInfo.h:448
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP)
LinkageTypes getLinkage() const
Definition: GlobalValue.h:289
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:140
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
unsigned getAlignment() const
getAlignment - Return the alignment (log2, not bytes) of the function.
virtual void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > Flags, Mangler &Mang, const TargetMachine &TM) const
Emit the module flags that the platform cares about.
static SectionKind getKindForGlobal(const GlobalValue *GV, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
SectionKind getSectionKind(const DataLayout *DL) const
StringRef getTargetCPU() const
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:46
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:139
virtual MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const
Constant * getPrologueData() const
Definition: Function.cpp:956
static void emitBasicBlockLoopComments(const MachineBasicBlock &MBB, const MachineLoopInfo *LI, const AsmPrinter &AP)
emitBasicBlockLoopComments - Pretty-print comments for basic blocks.
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1327
bool hasIdentDirective() const
Definition: MCAsmInfo.h:490
bool needsLocalForSize() const
Definition: MCAsmInfo.h:449
virtual bool hasStoreToStackSlot(const MachineInstr *MI, const MachineMemOperand *&MMO, int &FrameIndex) const
If the specified machine instruction has a store to a stack slot, return true along with the FrameInd...
const MCSymbol & getSymbol() const
Definition: MCExpr.h:328
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:83
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV, Mangler &Mang, bool MayAlwaysUsePrivate=false) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:339
MCTargetOptions MCOptions
Machine level options.
STATISTIC(NumFunctions,"Total number of functions")
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
static void Found()
.type _foo, STT_OBJECT # aka
Definition: MCDirectives.h:25
This represents an "assembler immediate".
Definition: MCValue.h:44
static bool isGOTEquivalentCandidate(const GlobalVariable *GV, unsigned &NumGOTEquivUsers)
Only consider global GOT equivalents if at least one user is a cstexpr inside an initializer of anoth...
Definition: AsmPrinter.cpp:947
WinEH::EncodingType getWinEHEncodingType() const
Definition: MCAsmInfo.h:512
static const fltSemantics IEEEdouble
Definition: APFloat.h:133
const ConstantFP * getFPImm() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
Not a valid directive.
Definition: MCDirectives.h:20
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
void redefineIfPossible()
Prepare this symbol to be redefined.
Definition: MCSymbol.h:233
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:139
bool doFinalization(Module &M) override
Shut down the asmprinter.
void EmitInt8(int Value) const
Emit a byte directive and value.
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:45
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:78
bool isBSSExtern() const
Definition: SectionKind.h:177
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
Definition: MachineInstr.h:249
bool canBeOmittedFromSymbolTable(const GlobalValue *GV)
void print(raw_ostream &OS, bool isSigned) const
Definition: APInt.cpp:2279
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:111
virtual bool hasLoadFromStackSlot(const MachineInstr *MI, const MachineMemOperand *&MMO, int &FrameIndex) const
If the specified machine instruction has a load from a stack slot, return true along with the FrameIn...
unsigned getNumOperands() const
Definition: User.h:138
Available for inspection, not emission.
Definition: GlobalValue.h:41
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:942
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
Definition: DataLayout.cpp:602
DWARF-like instruction based exceptions.
void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
void EmitJumpTableInfo()
Print assembly representations of the jump tables used by the current function to the current output ...
static int isRepeatedByteSequence(const ConstantDataSequential *V)
isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of iden...
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:207
static iterator end()
Definition: Registry.h:122
.ios_version_min
Definition: MCDirectives.h:64
bool hasAppendingLinkage() const
Definition: GlobalValue.h:277
EK_Inline - Jump table entries are emitted inline at their point of use.
unsigned getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
Definition: DataLayout.cpp:584
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:86
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
const char * getPrivateGlobalPrefix() const
Definition: DataLayout.h:281
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:48
Externally visible function.
Definition: GlobalValue.h:40
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:146
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:261
static const char *const DWARFGroupName
Definition: AsmPrinter.cpp:59
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:488
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...
virtual void EmitConstantPool()
Print to the current output stream assembly representations of the constants in the constant pool MCP...
LoopT * getParentLoop() const
Definition: LoopInfo.h:97
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:130
const std::string & str() const
Definition: Triple.h:306
bool hasPrologueData() const
Definition: Function.h:509
Metadata node.
Definition: Metadata.h:740
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:450
void EmitInt32(int Value) const
Emit a long directive and value.
F(f)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
setjmp/longjmp based exceptions
const char * getWeakRefDirective() const
Definition: MCAsmInfo.h:493
.macosx_version_min
Definition: MCDirectives.h:65
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:590
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
Definition: MCAsmInfo.h:484
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset...
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:143
static const MCBinaryExpr * createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:490
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
static void emitKill(const MachineInstr *MI, AsmPrinter &AP)
Definition: AsmPrinter.cpp:648
bool hasLinkOnceDirective() const
Definition: MCAsmInfo.h:498
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
Constant * ConstantFoldConstantExpression(const ConstantExpr *CE, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstantExpression - Attempt to fold the constant expression using the specified DataLayo...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:1015
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
Definition: Constants.h:1144
Tentative definitions.
Definition: GlobalValue.h:50
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:639
BlockT * getHeader() const
Definition: LoopInfo.h:96
virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, int &FrameIndex) const
Check for post-frame ptr elimination stack locations as well.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:334
static void emitGlobalConstantImpl(const Constant *C, AsmPrinter &AP, const Constant *BaseCV=nullptr, uint64_t Offset=0)
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Definition: DataLayout.h:398
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
bool hasMachoTBSSDirective() const
Definition: MCAsmInfo.h:432
const Triple & getTargetTriple() const
void print(raw_ostream &O) const
Definition: AsmWriter.cpp:3186
unsigned getPointerTypeSize(Type *Ty) const
Definition: DataLayout.h:340
MCSymbolAttr getHiddenVisibilityAttr() const
Definition: MCAsmInfo.h:500
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:394
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
BlockAddress - The address of a basic block.
Definition: Constants.h:802
static const MCBinaryExpr * createXor(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:518
AnalysisUsage & addRequired()
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:475
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP)
A tuple of MDNodes.
Definition: Metadata.h:1127
static iterator begin()
Definition: Registry.h:121
MachineMemOperand - A description of a memory reference used in the backend.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1674
bool getAsmPrinterFlag(CommentFlag Flag) const
Return whether an AsmPrinter flag is set.
Definition: MachineInstr.h:130
Emits exception handling directives.
Definition: EHStreamer.h:33
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasWeakDefDirective() const
Definition: MCAsmInfo.h:494
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
void takeDeletedSymbolsForFunction(const Function *F, std::vector< MCSymbol * > &Result)
takeDeletedSymbolsForFunction - If the specified function has had any references to address-taken blo...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual void EmitEndOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: AsmPrinter.h:287
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
const HexagonInstrInfo * TII
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Definition: DataLayout.cpp:551
unsigned getCFIIndex() const
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:106
bool hasSection() const
Definition: GlobalValue.h:175
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
virtual unsigned isStoreToStackSlotPostFE(const MachineInstr *MI, int &FrameIndex) const
Check for post-frame ptr elimination stack locations as well.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
NamedRegionTimer - This class is basically a combination of TimeRegion and Timer. ...
Definition: Timer.h:147
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:454
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
virtual TargetLoweringObjectFile * getObjFileLowering() const
iterator end() const
Definition: GCMetadata.h:197
Reg
All possible values of the reg field in the ModR/M byte.
iterator_range< iterator > terminators()
double getElementAsDouble(unsigned i) const
getElementAsDouble - If this is an sequential container of doubles, return the specified element as a...
Definition: Constants.cpp:2773
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:159
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasMachoZeroFillDirective() const
Definition: MCAsmInfo.h:431
bool doesSetDirectiveSuppressesReloc() const
Definition: MCAsmInfo.h:477
.local (ELF)
Definition: MCDirectives.h:35
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:154
bool hasDebugInfo() const
hasDebugInfo - Returns true if valid debug info is present.
static void emitGlobalConstantVector(const ConstantVector *CV, AsmPrinter &AP)
StringRef getName() const
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:242
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
#define G(x, y, z)
Definition: MD5.cpp:52
bool isSplat(unsigned SplatSizeInBits) const
Check if the APInt consists of a repeated bit pattern.
Definition: APInt.cpp:675
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
static const char *const CodeViewLineTablesGroupName
Definition: AsmPrinter.cpp:62
Context object for machine code objects.
Definition: MCContext.h:48
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:502
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AsmPrinter.cpp:163
ConstantExpr - a constant value that is initialized with an expression using other constant values...
Definition: Constants.h:852
void EmitFunctionBody()
This method emits the body and trailer for a function.
Definition: AsmPrinter.cpp:784
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS)
emitComments - Pretty-print comments for instructions.
Definition: AsmPrinter.cpp:604
Mangler * Mang
Name-mangler for global names.
Definition: AsmPrinter.h:93
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrSelf(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:1031
bool useStatepoints() const
Returns true if this strategy is expecting the use of gc.statepoints, and false otherwise.
Definition: GCStrategy.h:115
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:514
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: SmallVector.h:57
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition: Constants.h:557
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table...
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:3287
#define T
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:54
const std::string & getName() const
Return the name of the GC strategy.
Definition: GCStrategy.h:101
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:56
const MCSection * getCurrentSection() const
Return the current section we are emitting to.
Definition: AsmPrinter.cpp:157
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
Definition: Constants.h:219
void EmitInt16(int Value) const
Emit a short directive and value.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
EK_BlockAddress - Each entry is a plain address of block, e.g.
double convertToDouble() const
Definition: APFloat.cpp:3116
const std::vector< MCCFIInstruction > & getFrameInstructions() const
Returns a reference to a list of cfi instructions in the current function's prologue.
SequentialType * getType() const
getType - Specialize the getType() method to always return a SequentialType, which reduces the amount...
Definition: Constants.h:619
This class is a data container for one entry in a MachineConstantPool.
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)
getAddrLabelSymbolToEmit - Return the symbol to be used for the specified basic block when its addres...
virtual void emitImplicitDef(const MachineInstr *MI) const
Targets can override this to customize the output of IMPLICIT_DEF instructions in verbose mode...
Definition: AsmPrinter.cpp:641
static void emitGlobalConstantArray(const ConstantArray *CA, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
int64_t getImm() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:446
unsigned getNumElements() const
Return the number of elements in the Vector type.
Definition: DerivedTypes.h:432
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, Mangler &Mang, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
StringRef getTargetTriple() const
Return the target triple string.
Definition: AsmPrinter.cpp:152
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
Definition: Type.h:155
Type * getElementType() const
Definition: DerivedTypes.h:323
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
.reference (MachO)
Definition: MCDirectives.h:40
void emitGlobalGOTEquivs()
Constant expressions using GOT equivalent globals may not be eligible for PC relative GOT entry conve...
Definition: AsmPrinter.cpp:988
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:89
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME, const Constant *BaseCst, uint64_t Offset)
Transform a not absolute MCExpr containing a reference to a GOT equivalent global, by a target specific GOT pc relative access to the final symbol.
const BasicBlock * getBasicBlock() const
getBasicBlock - Return the LLVM basic block that this instance corresponded to originally.
static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI)
Definition: AsmPrinter.cpp:282
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
bool getCommDirectiveSupportsAlignment() const
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:120
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:111
TargetInstrInfo - Interface to description of machine instruction set.
uint64_t getElementOffset(unsigned Idx) const
Definition: DataLayout.h:491
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
DBG_VALUE - a mapping of the llvm.dbg.value intrinsic.
Definition: TargetOpcodes.h:69
ExternalWeak linkage description.
Definition: GlobalValue.h:49
IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
Definition: TargetOpcodes.h:52
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP)
emitDebugValueComment - This method handles the target-independent form of DBG_VALUE, returning true if it was able to do so.
Definition: AsmPrinter.cpp:664
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
getLoopFor - Return the inner most loop that BB lives in.
bool needsDwarfSectionOffsetDirective() const
Definition: MCAsmInfo.h:425
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
#define P(N)
.data_region jt32
Definition: MCDirectives.h:59
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:43
Instruction that records the offset of a local stack allocation passed to llvm.localescape.
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
std::pair< const GlobalVariable *, unsigned > GOTEquivUsePair
Map global GOT equivalent MCSymbols to GlobalVariables and keep track of its number of uses by other ...
Definition: AsmPrinter.h:107
Streaming machine code generation interface.
Definition: MCStreamer.h:157
virtual void EmitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
Definition: AsmPrinter.h:295
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:222
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
MCSymbolAttr getHiddenDeclarationVisibilityAttr() const
Definition: MCAsmInfo.h:501
iterator_range< iterator > functions()
Definition: Module.h:580
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:44
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:98
MCSymbolAttr getProtectedVisibilityAttr() const
Definition: MCAsmInfo.h:504
virtual const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Get the target specific PC relative GOT entry relocation.
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:74
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MCSection * SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: AsmPrinter.cpp:102
This is an important base class in LLVM.
Definition: Constant.h:41
uint64_t getElementByteSize() const
getElementByteSize - Return the size (in bytes) of each element in the array/vector.
Definition: Constants.cpp:2457
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1339
StringRef getAsString() const
getAsString - If this array is isString(), then this method returns the array as a StringRef...
Definition: Constants.h:645
bool isThreadData() const
Definition: SectionKind.h:169
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:273
StringRef getRawDataValues() const
getRawDataValues - Return the raw, underlying, bytes of this data.
Definition: Constants.cpp:2425
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
getAddrLabelSymbol - Return the symbol to be used for the specified basic block when its address is t...
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:143
MCSymbol * GetJTSetSymbol(unsigned UID, unsigned MBBID) const
Return the symbol for the specified jump table .set FIXME: privatize to AsmPrinter.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Definition: APInt.h:1895
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:233
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:264
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Definition: APInt.h:1900
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:498
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:70
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool hasFunctionAlignment() const
Definition: MCAsmInfo.h:487
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
Represent the analysis usage information of a pass.
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
Type * getTypeAtIndex(const Value *V)
getTypeAtIndex - Given an index value into the type, return the type of the element.
Definition: Type.cpp:634
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1273
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
Definition: APFloat.cpp:1972
static bool isDiscardableIfUnused(LinkageTypes Linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit...
Definition: GlobalValue.h:238
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:511
Value * getOperand(unsigned i) const
Definition: User.h:118
op_range operands()
Definition: User.h:191
static void PrintChildLoopComment(raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
PrintChildLoopComment - Print comments about child loops within the loop for this basic block...
DenseMap< GCStrategy *, std::unique_ptr< GCMetadataPrinter > > gcp_map_type
Definition: AsmPrinter.cpp:68
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
~AsmPrinter() override
Definition: AsmPrinter.cpp:117
Ty & getObjFileInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
ConstantVector - Constant Vector Declarations.
Definition: Constants.h:461
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
void emitFrameAlloc(const MachineInstr &MI)
Definition: AsmPrinter.cpp:772
virtual MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const
Given a constant with the SectionKind, return a section that it should be placed in.
.weak_reference (MachO)
Definition: MCDirectives.h:43
void computeGlobalGOTEquivs(Module &M)
Unnamed constant global variables solely contaning a pointer to another globals variable act like a g...
Definition: AsmPrinter.cpp:971
static const char *const EHTimerName
Definition: AsmPrinter.cpp:61
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol...
bool isBSSLocal() const
Definition: SectionKind.h:176
uint64_t getElementAsInteger(unsigned i) const
getElementAsInteger - If this is a sequential container of integers (of any size), return the specified element in the low bits of a uint64_t.
Definition: Constants.cpp:2723
bool isThreadBSS() const
Definition: SectionKind.h:168
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:52
Abstract base class for all machine specific constantpool value subclasses.
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
MCSymbol * getSymbol(const GlobalValue *GV, Mangler &Mang) const
virtual void markFunctionEnd()
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:480
bool isThreadLocal() const
Definition: SectionKind.h:164
Windows x64, Windows Itanium (IA-64)
static void PrintParentLoopComment(raw_ostream &OS, const MachineLoop *Loop, unsigned FunctionNumber)
PrintParentLoopComment - Print comments about parent loops of this one.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void EmitAlignment(unsigned NumBits, const GlobalObject *GO=nullptr) const
Emit an alignment directive to the specified power of two boundary.
unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global, returned in log form.
Definition: DataLayout.cpp:785
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Definition: Module.h:269
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
Definition: Triple.h:404
const char * getSection() const
Definition: GlobalObject.h:57
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:694
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:251
virtual const TargetFrameLowering * getFrameLowering() const
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:281
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:936
const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
Definition: MachineInstr.h:242
void emitCFIInstruction(const MachineInstr &MI)
Definition: AsmPrinter.cpp:756
ArrayType * getType() const
getType - Specialize the getType() method to always return an ArrayType, which reduces the amount of ...
Definition: Constants.h:380
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:299
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
SymbolListTy GetGVStubList()
Accessor methods to return the set of stubs in sorted order.
StringRef getTargetFeatureString() const
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
Definition: AsmPrinter.h:108
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:51
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:388
const MCContext & getContext() const
void EmitGlobalConstant(const Constant *CV)
Print a general LLVM constant to the .s file.
const DataLayout * getDataLayout() const
Deprecated in 3.7, will be removed in 3.8.
const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
virtual void EmitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
Definition: AsmPrinter.h:307
void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getOSVersion - Parse the version number from the OS name component of the triple, if present...
Definition: Triple.cpp:854
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:42
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
virtual const TargetLowering * getTargetLowering() const
virtual void EmitXXStructor(const Constant *CV)
Targets can override this to change how global constants that are part of a C++ static/global constru...
Definition: AsmPrinter.h:320
MCSection * getTLSExtraDataSection() const
Information about stack frame layout on the target.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:148
bool EmitSpecialLLVMGlobal(const GlobalVariable *GV)
Check to see if the specified global is a special global used by LLVM.
uint64_t getSizeInBytes() const
Definition: DataLayout.h:481
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:354
BasicBlock * getBasicBlock() const
Definition: Constants.h:829
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:458
virtual const MCExpr * getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI, MCContext &Ctx) const
This returns the relocation base for the given PIC jumptable, the same as getPICJumpTableRelocBase, but as an MCExpr.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCSymbol * createTempSymbol(const Twine &Name) const
MCSymbolAttr
Definition: MCDirectives.h:19
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:75
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
DWARF expression.
unsigned Log2_32(uint32_t Value)
Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero...
Definition: MathExtras.h:468
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
const ConstantInt * getCImm() const
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
unsigned getOpcode() const
Definition: MCInst.h:159
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB) const
Targets can override this to emit stuff at the start of a basic block.
Class for arbitrary precision integers.
Definition: APInt.h:73
ConstantArray - Constant Array Declarations.
Definition: Constants.h:356
bool hasInitializer() const
Definitions have initializers, declarations don't.
virtual void EmitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:291
MCSymbol * getCurExceptionSym()
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:39
bool hasSingleParameterDotFile() const
Definition: MCAsmInfo.h:489
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
void setPreservesAll()
Set by analyses that do not transform their input at all.
StructType * getType() const
getType() specialization - Reduce amount of casting...
Definition: Constants.h:440
iterator_range< user_iterator > users()
Definition: Value.h:300
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3084
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
KILL - This instruction is a noop that is used only to adjust the liveness of registers.
Definition: TargetOpcodes.h:35
FunctionNumber(functionNumber)
Definition: LLParser.cpp:2146
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Definition: APInt.h:1890
bool hasStaticCtorDtorReferenceInStaticMode() const
Definition: MCAsmInfo.h:433
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:227
Iterators for registry entries.
Definition: Registry.h:108
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
StringRef str()
Flushes the stream contents to the target vector and return a StringRef for the vector contents...
Representation of each machine instruction.
Definition: MachineInstr.h:51
iterator begin() const
begin/end - Iterators for used strategies.
Definition: GCMetadata.h:196
bool hasAddressTaken() const
hasAddressTaken - Test whether this block is potentially the target of an indirect branch...
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:185
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
Converts this value into a decimal string.
Definition: APFloat.cpp:3551
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:253
bool isLandingPad() const
isLandingPad - Returns true if the block is a landing pad.
bool hasNoDeadStrip() const
Definition: MCAsmInfo.h:491
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
Definition: AsmPrinter.cpp:172
GCStrategy describes a garbage collector algorithm's code generation requirements, and provides overridable hooks for those needs which cannot be abstractly described.
Definition: GCStrategy.h:78
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
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:573
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:111
bool hasLinkerPrivateGlobalPrefix() const
Definition: DataLayout.h:259
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:128
float getElementAsFloat(unsigned i) const
getElementAsFloat - If this is an sequential container of floats, return the specified element as a f...
Definition: Constants.cpp:2764
const std::vector< LandingPadInfo > & getLandingPads() const
getLandingPads - Return a reference to the landing pad info for the current function.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:108
.type _foo, STT_FUNC # aka
Definition: MCDirectives.h:23
virtual ~AsmPrinterHandler()
Pin vtable to this file.
static unsigned getNumGlobalVariableUses(const Constant *C)
Compute the number of Global Variables that uses a Constant.
Definition: AsmPrinter.cpp:928
AddressSanitizer is on.
Definition: Attributes.h:115
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
static void emitGlobalConstantStruct(const ConstantStruct *CS, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
bool hasOneUse() const
Return true if there is exactly one user of this value.
Definition: Value.h:311
virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
Definition: AsmPrinter.h:304
unsigned getNumElements() const
getNumElements - Return the number of elements in the array or vector.
Definition: Constants.cpp:2449
MCSymbol * getMCSymbol() const
MCSubtargetInfo - Generic base class for all target subtargets.
float convertToFloat() const
Definition: APFloat.cpp:3107
Collects and handles line tables information in a CodeView format.
static gcp_map_type & getGCMap(void *&P)
Definition: AsmPrinter.cpp:69
static const MCBinaryExpr * createMod(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:486
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
union llvm::MachineConstantPoolEntry::@30 Val
The constant itself.
bool isString() const
isString - This method returns true if this is an array of i8.
Definition: Constants.cpp:2792
bool hasPrefixData() const
Definition: Function.h:502
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:44
virtual const MCExpr * LowerCustomJumpTableEntry(const MachineJumpTableInfo *, const MachineBasicBlock *, unsigned, MCContext &) const
Rename collisions when linking (static functions).
Definition: GlobalValue.h:47
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
Definition: DataLayout.h:371
Constant * getPrefixData() const
Definition: Function.cpp:927
.weak_definition (MachO)
Definition: MCDirectives.h:42
static unsigned getGVAlignmentLog2(const GlobalValue *GV, const DataLayout &DL, unsigned InBits=0)
getGVAlignmentLog2 - Return the alignment to use for the specified global value in log2 form...
Definition: AsmPrinter.cpp:79
virtual void EmitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
Definition: AsmPrinter.cpp:588
bool isBitPiece() const
Return whether this is a piece of an aggregate variable.
bool isCommon() const
Definition: SectionKind.h:179
JTEntryKind getEntryKind() const
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:294
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
const APFloat & getValueAPF() const
Definition: Constants.h:270
CFIMoveType needsCFIMoves()
Definition: AsmPrinter.cpp:741
VectorType * getType() const
getType - Specialize the getType() method to always return a VectorType, which reduces the amount of ...
Definition: Constants.h:489
Type * getElementType() const
getElementType - Return the element type of the array/vector.
Definition: Constants.cpp:2421
unsigned getReg() const
getReg - Returns the register number.
bool use_empty() const
Definition: Value.h:275
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
Definition: MCAsmInfo.h:395
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:134
unsigned getAlignment() const
Definition: Globals.cpp:63
int64_t getConstant() const
Definition: MCValue.h:50
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465
virtual const TargetInstrInfo * getInstrInfo() const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:365
LLVM Value Representation.
Definition: Value.h:69
bool hasUnnamedAddr() const
Definition: GlobalValue.h:130
bool isKnownWindowsMSVCEnvironment() const
Definition: Triple.h:436
bool hasSubsectionsViaSymbols() const
Definition: MCAsmInfo.h:381
ExceptionHandling
Definition: MCAsmInfo.h:44
Windows CE ARM, PowerPC, SH3, SH4.
static const char *const DbgTimerName
Definition: AsmPrinter.cpp:60
bool hasWeakDefCanBeHiddenDirective() const
Definition: MCAsmInfo.h:495
uint64_t getBitPieceSize() const
Return the size of this piece in bits.
MCSection * getDataRelSection() const
uint64_t getBitPieceOffset() const
Return the offset of this piece in bits.
uint64_t getSize() const
getSize - Return the size in bytes of the memory reference.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
bool empty() const
Definition: LoopInfo.h:135
const Target & getTarget() const
Primary interface to the complete machine description for the target machine.
MCSymbol * CurrentFnSymForSize
The symbol used to represent the start of the current function for the purpose of calculating its siz...
Definition: AsmPrinter.h:103
GCMetadataPrinter - Emits GC metadata as assembly code.
const char * getName(unsigned RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
const std::vector< MachineConstantPoolEntry > & getConstants() const
iterator_range< global_iterator > globals()
Definition: Module.h:558
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:258
MachineModuleInfo & getMMI() const
A single uniqued string.
Definition: Metadata.h:508
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
No exception support.
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
Definition: IRReader.cpp:26
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:593
MCSection * getTLSBSSSection() const
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:290
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
isLayoutSuccessor - Return true if the specified MBB will be emitted immediately after this block...
bool hasDotTypeDotSizeDirective() const
Definition: MCAsmInfo.h:488
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:152
bool isBigEndian() const
Definition: DataLayout.h:218
unsigned getLoopDepth() const
getLoopDepth - Return the nesting level of this loop.
Definition: LoopInfo.h:89
static SectionKind getReadOnly()
Definition: SectionKind.h:208
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
void EndFunction()
EndFunction - Discard function meta information.
bool isDeclarationForLinker() const
Definition: GlobalValue.h:344
#define OP(n)
Definition: regex2.h:70
unsigned pred_size() const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150
.end_data_region
Definition: MCDirectives.h:60
User * user_back()
Definition: Value.h:298
MachineModuleInfo - This class contains meta information specific to a module.
This file describes how to lower LLVM code to machine code.
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
unsigned getAlignment() const
getAlignment - Return alignment of the basic block.
static void emitGlobalConstantDataSequential(const ConstantDataSequential *CDS, AsmPrinter &AP)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
Definition: MachineInstr.h:340
unsigned getNumWords() const
Get the number of words.
Definition: APInt.h:1280
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:521