LLVM  14.0.0git
AsmPrinter.cpp
Go to the documentation of this file.
1 //===- AsmPrinter.cpp - Common AsmPrinter code ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the AsmPrinter class.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "CodeViewDebug.h"
15 #include "DwarfDebug.h"
16 #include "DwarfException.h"
17 #include "PseudoProbePrinter.h"
18 #include "WasmException.h"
19 #include "WinCFGuard.h"
20 #include "WinException.h"
21 #include "llvm/ADT/APFloat.h"
22 #include "llvm/ADT/APInt.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/Statistic.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/ADT/Triple.h"
31 #include "llvm/ADT/Twine.h"
36 #include "llvm/BinaryFormat/COFF.h"
38 #include "llvm/BinaryFormat/ELF.h"
56 #include "llvm/CodeGen/StackMaps.h"
62 #include "llvm/Config/config.h"
63 #include "llvm/IR/BasicBlock.h"
64 #include "llvm/IR/Comdat.h"
65 #include "llvm/IR/Constant.h"
66 #include "llvm/IR/Constants.h"
67 #include "llvm/IR/DataLayout.h"
69 #include "llvm/IR/DerivedTypes.h"
70 #include "llvm/IR/Function.h"
71 #include "llvm/IR/GCStrategy.h"
72 #include "llvm/IR/GlobalAlias.h"
73 #include "llvm/IR/GlobalIFunc.h"
75 #include "llvm/IR/GlobalObject.h"
76 #include "llvm/IR/GlobalValue.h"
77 #include "llvm/IR/GlobalVariable.h"
78 #include "llvm/IR/Instruction.h"
79 #include "llvm/IR/Mangler.h"
80 #include "llvm/IR/Metadata.h"
81 #include "llvm/IR/Module.h"
82 #include "llvm/IR/Operator.h"
83 #include "llvm/IR/PseudoProbe.h"
84 #include "llvm/IR/Type.h"
85 #include "llvm/IR/Value.h"
86 #include "llvm/MC/MCAsmInfo.h"
87 #include "llvm/MC/MCContext.h"
88 #include "llvm/MC/MCDirectives.h"
89 #include "llvm/MC/MCDwarf.h"
90 #include "llvm/MC/MCExpr.h"
91 #include "llvm/MC/MCInst.h"
92 #include "llvm/MC/MCSection.h"
93 #include "llvm/MC/MCSectionCOFF.h"
94 #include "llvm/MC/MCSectionELF.h"
95 #include "llvm/MC/MCSectionMachO.h"
96 #include "llvm/MC/MCSectionXCOFF.h"
97 #include "llvm/MC/MCStreamer.h"
99 #include "llvm/MC/MCSymbol.h"
100 #include "llvm/MC/MCSymbolELF.h"
101 #include "llvm/MC/MCSymbolXCOFF.h"
102 #include "llvm/MC/MCTargetOptions.h"
103 #include "llvm/MC/MCValue.h"
104 #include "llvm/MC/SectionKind.h"
105 #include "llvm/Pass.h"
106 #include "llvm/Remarks/Remark.h"
110 #include "llvm/Support/Casting.h"
112 #include "llvm/Support/Compiler.h"
114 #include "llvm/Support/FileSystem.h"
115 #include "llvm/Support/Format.h"
116 #include "llvm/Support/MathExtras.h"
117 #include "llvm/Support/Path.h"
119 #include "llvm/Support/Timer.h"
124 #include <algorithm>
125 #include <cassert>
126 #include <cinttypes>
127 #include <cstdint>
128 #include <iterator>
129 #include <limits>
130 #include <memory>
131 #include <string>
132 #include <utility>
133 #include <vector>
134 
135 using namespace llvm;
136 
137 #define DEBUG_TYPE "asm-printer"
138 
139 // FIXME: this option currently only applies to DWARF, and not CodeView, tables
140 static cl::opt<bool>
141  DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
142  cl::desc("Disable debug info printing"));
143 
144 const char DWARFGroupName[] = "dwarf";
145 const char DWARFGroupDescription[] = "DWARF Emission";
146 const char DbgTimerName[] = "emit";
147 const char DbgTimerDescription[] = "Debug Info Emission";
148 const char EHTimerName[] = "write_exception";
149 const char EHTimerDescription[] = "DWARF Exception Writer";
150 const char CFGuardName[] = "Control Flow Guard";
151 const char CFGuardDescription[] = "Control Flow Guard";
152 const char CodeViewLineTablesGroupName[] = "linetables";
153 const char CodeViewLineTablesGroupDescription[] = "CodeView Line Tables";
154 const char PPTimerName[] = "emit";
155 const char PPTimerDescription[] = "Pseudo Probe Emission";
156 const char PPGroupName[] = "pseudo probe";
157 const char PPGroupDescription[] = "Pseudo Probe Emission";
158 
159 STATISTIC(EmittedInsts, "Number of machine instrs printed");
160 
161 char AsmPrinter::ID = 0;
162 
164 
165 static gcp_map_type &getGCMap(void *&P) {
166  if (!P)
167  P = new gcp_map_type();
168  return *(gcp_map_type*)P;
169 }
170 
171 /// getGVAlignment - Return the alignment to use for the specified global
172 /// value. This rounds up to the preferred alignment if possible and legal.
174  Align InAlign) {
175  Align Alignment;
176  if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
177  Alignment = DL.getPreferredAlign(GVar);
178 
179  // If InAlign is specified, round it to it.
180  if (InAlign > Alignment)
181  Alignment = InAlign;
182 
183  // If the GV has a specified alignment, take it into account.
184  const MaybeAlign GVAlign(GV->getAlignment());
185  if (!GVAlign)
186  return Alignment;
187 
188  assert(GVAlign && "GVAlign must be set");
189 
190  // If the GVAlign is larger than NumBits, or if we are required to obey
191  // NumBits because the GV has an assigned section, obey it.
192  if (*GVAlign > Alignment || GV->hasSection())
193  Alignment = *GVAlign;
194  return Alignment;
195 }
196 
197 AsmPrinter::AsmPrinter(TargetMachine &tm, std::unique_ptr<MCStreamer> Streamer)
198  : MachineFunctionPass(ID), TM(tm), MAI(tm.getMCAsmInfo()),
199  OutContext(Streamer->getContext()), OutStreamer(std::move(Streamer)) {
200  VerboseAsm = OutStreamer->isVerboseAsm();
201 }
202 
204  assert(!DD && Handlers.size() == NumUserHandlers &&
205  "Debug/EH info didn't get finalized");
206 
207  if (GCMetadataPrinters) {
208  gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
209 
210  delete &GCMap;
211  GCMetadataPrinters = nullptr;
212  }
213 }
214 
216  return TM.isPositionIndependent();
217 }
218 
219 /// getFunctionNumber - Return a unique ID for the current function.
221  return MF->getFunctionNumber();
222 }
223 
225  return *TM.getObjFileLowering();
226 }
227 
229  return MMI->getModule()->getDataLayout();
230 }
231 
232 // Do not use the cached DataLayout because some client use it without a Module
233 // (dsymutil, llvm-dwarfdump).
234 unsigned AsmPrinter::getPointerSize() const {
235  return TM.getPointerSize(0); // FIXME: Default address space
236 }
237 
239  assert(MF && "getSubtargetInfo requires a valid MachineFunction!");
240  return MF->getSubtarget<MCSubtargetInfo>();
241 }
242 
244  S.emitInstruction(Inst, getSubtargetInfo());
245 }
246 
248  if (DD) {
249  assert(OutStreamer->hasRawTextSupport() &&
250  "Expected assembly output mode.");
251  (void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
252  }
253 }
254 
255 /// getCurrentSection() - Return the current section we are emitting to.
257  return OutStreamer->getCurrentSectionOnly();
258 }
259 
261  AU.setPreservesAll();
265 }
266 
268  auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
269  MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
270 
271  // Initialize TargetLoweringObjectFile.
273  .Initialize(OutContext, TM);
274 
276  .getModuleMetadata(M);
277 
278  OutStreamer->initSections(false, *TM.getMCSubtargetInfo());
279 
282 
283  // Emit the version-min deployment target directive if needed.
284  //
285  // FIXME: If we end up with a collection of these sorts of Darwin-specific
286  // or ELF-specific things, it may make sense to have a platform helper class
287  // that will work with the target helper class. For now keep it here, as the
288  // alternative is duplicated code in each of the target asm printers that
289  // use the directive, where it would need the same conditionalization
290  // anyway.
291  const Triple &Target = TM.getTargetTriple();
292  OutStreamer->emitVersionForTarget(Target, M.getSDKVersion());
293 
294  // Allow the target to emit any magic that it wants at the start of the file.
296 
297  // Very minimal debug info. It is ignored if we emit actual debug info. If we
298  // don't, this at least helps the user find where a global came from.
300  // .file "foo.c"
301 
302  SmallString<128> FileName;
304  FileName = llvm::sys::path::filename(M.getSourceFileName());
305  else
306  FileName = M.getSourceFileName();
307  if (MAI->hasFourStringsDotFile()) {
308 #ifdef PACKAGE_VENDOR
309  const char VerStr[] =
310  PACKAGE_VENDOR " " PACKAGE_NAME " version " PACKAGE_VERSION;
311 #else
312  const char VerStr[] = PACKAGE_NAME " version " PACKAGE_VERSION;
313 #endif
314  // TODO: Add timestamp and description.
315  OutStreamer->emitFileDirective(FileName, VerStr, "", "");
316  } else {
317  OutStreamer->emitFileDirective(FileName);
318  }
319  }
320 
321  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
322  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
323  for (auto &I : *MI)
324  if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
325  MP->beginAssembly(M, *MI, *this);
326 
327  // Emit module-level inline asm if it exists.
328  if (!M.getModuleInlineAsm().empty()) {
329  OutStreamer->AddComment("Start of file scope inline assembly");
330  OutStreamer->AddBlankLine();
331  emitInlineAsm(M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
333  OutStreamer->AddComment("End of file scope inline assembly");
334  OutStreamer->AddBlankLine();
335  }
336 
338  bool EmitCodeView = M.getCodeViewFlag();
339  if (EmitCodeView && TM.getTargetTriple().isOSWindows()) {
340  Handlers.emplace_back(std::make_unique<CodeViewDebug>(this),
344  }
345  if (!EmitCodeView || M.getDwarfVersion()) {
347  DD = new DwarfDebug(this);
348  Handlers.emplace_back(std::unique_ptr<DwarfDebug>(DD), DbgTimerName,
351  }
352  }
353  }
354 
355  if (M.getNamedMetadata(PseudoProbeDescMetadataName)) {
356  PP = new PseudoProbeHandler(this);
357  Handlers.emplace_back(std::unique_ptr<PseudoProbeHandler>(PP), PPTimerName,
359  }
360 
361  switch (MAI->getExceptionHandlingType()) {
363  // We may want to emit CFI for debug.
368  for (auto &F : M.getFunctionList()) {
370  ModuleCFISection = getFunctionCFISectionType(F);
371  // If any function needsUnwindTableEntry(), it needs .eh_frame and hence
372  // the module needs .eh_frame. If we have found that case, we are done.
373  if (ModuleCFISection == CFISection::EH)
374  break;
375  }
377  ModuleCFISection != CFISection::EH);
378  break;
379  default:
380  break;
381  }
382 
383  EHStreamer *ES = nullptr;
384  switch (MAI->getExceptionHandlingType()) {
386  if (!needsCFIForDebug())
387  break;
391  ES = new DwarfCFIException(this);
392  break;
394  ES = new ARMException(this);
395  break;
397  switch (MAI->getWinEHEncodingType()) {
398  default: llvm_unreachable("unsupported unwinding information encoding");
400  break;
403  ES = new WinException(this);
404  break;
405  }
406  break;
408  ES = new WasmException(this);
409  break;
411  ES = new AIXException(this);
412  break;
413  }
414  if (ES)
415  Handlers.emplace_back(std::unique_ptr<EHStreamer>(ES), EHTimerName,
418 
419  // Emit tables for any value of cfguard flag (i.e. cfguard=1 or cfguard=2).
420  if (mdconst::extract_or_null<ConstantInt>(M.getModuleFlag("cfguard")))
421  Handlers.emplace_back(std::make_unique<WinCFGuard>(this), CFGuardName,
424 
425  for (const HandlerInfo &HI : Handlers) {
426  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
427  HI.TimerGroupDescription, TimePassesIsEnabled);
428  HI.Handler->beginModule(&M);
429  }
430 
431  return false;
432 }
433 
434 static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI) {
436  return false;
437 
438  return GV->canBeOmittedFromSymbolTable();
439 }
440 
441 void AsmPrinter::emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
443  switch (Linkage) {
449  if (MAI->hasWeakDefDirective()) {
450  // .globl _foo
451  OutStreamer->emitSymbolAttribute(GVSym, MCSA_Global);
452 
453  if (!canBeHidden(GV, *MAI))
454  // .weak_definition _foo
455  OutStreamer->emitSymbolAttribute(GVSym, MCSA_WeakDefinition);
456  else
457  OutStreamer->emitSymbolAttribute(GVSym, MCSA_WeakDefAutoPrivate);
458  } else if (MAI->avoidWeakIfComdat() && GV->hasComdat()) {
459  // .globl _foo
460  OutStreamer->emitSymbolAttribute(GVSym, MCSA_Global);
461  //NOTE: linkonce is handled by the section the symbol was assigned to.
462  } else {
463  // .weak _foo
464  OutStreamer->emitSymbolAttribute(GVSym, MCSA_Weak);
465  }
466  return;
468  OutStreamer->emitSymbolAttribute(GVSym, MCSA_Global);
469  return;
472  return;
476  llvm_unreachable("Should never emit this");
477  }
478  llvm_unreachable("Unknown linkage type!");
479 }
480 
482  const GlobalValue *GV) const {
483  TM.getNameWithPrefix(Name, GV, getObjFileLowering().getMangler());
484 }
485 
487  return TM.getSymbol(GV);
488 }
489 
491  // On ELF, use .Lfoo$local if GV is a non-interposable GlobalObject with an
492  // exact definion (intersection of GlobalValue::hasExactDefinition() and
493  // !isInterposable()). These linkages include: external, appending, internal,
494  // private. It may be profitable to use a local alias for external. The
495  // assembler would otherwise be conservative and assume a global default
496  // visibility symbol can be interposable, even if the code generator already
497  // assumed it.
499  const Module &M = *GV.getParent();
501  M.getPIELevel() == PIELevel::Default && GV.isDSOLocal())
502  return getSymbolWithGlobalValueBase(&GV, "$local");
503  }
504  return TM.getSymbol(&GV);
505 }
506 
507 /// EmitGlobalVariable - Emit the specified global variable to the .s file.
509  bool IsEmuTLSVar = TM.useEmulatedTLS() && GV->isThreadLocal();
510  assert(!(IsEmuTLSVar && GV->hasCommonLinkage()) &&
511  "No emulated TLS variables in the common section");
512 
513  // Never emit TLS variable xyz in emulated TLS model.
514  // The initialization value is in __emutls_t.xyz instead of xyz.
515  if (IsEmuTLSVar)
516  return;
517 
518  if (GV->hasInitializer()) {
519  // Check to see if this is a special global used by LLVM, if so, emit it.
520  if (emitSpecialLLVMGlobal(GV))
521  return;
522 
523  // Skip the emission of global equivalents. The symbol can be emitted later
524  // on by emitGlobalGOTEquivs in case it turns out to be needed.
525  if (GlobalGOTEquivs.count(getSymbol(GV)))
526  return;
527 
528  if (isVerbose()) {
529  // When printing the control variable __emutls_v.*,
530  // we don't need to print the original TLS variable name.
531  GV->printAsOperand(OutStreamer->GetCommentOS(),
532  /*PrintType=*/false, GV->getParent());
533  OutStreamer->GetCommentOS() << '\n';
534  }
535  }
536 
537  MCSymbol *GVSym = getSymbol(GV);
538  MCSymbol *EmittedSym = GVSym;
539 
540  // getOrCreateEmuTLSControlSym only creates the symbol with name and default
541  // attributes.
542  // GV's or GVSym's attributes will be used for the EmittedSym.
543  emitVisibility(EmittedSym, GV->getVisibility(), !GV->isDeclaration());
544 
545  if (!GV->hasInitializer()) // External globals require no extra code.
546  return;
547 
548  GVSym->redefineIfPossible();
549  if (GVSym->isDefined() || GVSym->isVariable())
550  OutContext.reportError(SMLoc(), "symbol '" + Twine(GVSym->getName()) +
551  "' is already defined");
552 
554  OutStreamer->emitSymbolAttribute(EmittedSym, MCSA_ELF_TypeObject);
555 
557 
558  const DataLayout &DL = GV->getParent()->getDataLayout();
559  uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
560 
561  // If the alignment is specified, we *must* obey it. Overaligning a global
562  // with a specified alignment is a prompt way to break globals emitted to
563  // sections and expected to be contiguous (e.g. ObjC metadata).
564  const Align Alignment = getGVAlignment(GV, DL);
565 
566  for (const HandlerInfo &HI : Handlers) {
567  NamedRegionTimer T(HI.TimerName, HI.TimerDescription,
568  HI.TimerGroupName, HI.TimerGroupDescription,
570  HI.Handler->setSymbolSize(GVSym, Size);
571  }
572 
573  // Handle common symbols
574  if (GVKind.isCommon()) {
575  if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
576  // .comm _foo, 42, 4
577  const bool SupportsAlignment =
579  OutStreamer->emitCommonSymbol(GVSym, Size,
580  SupportsAlignment ? Alignment.value() : 0);
581  return;
582  }
583 
584  // Determine to which section this global should be emitted.
585  MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
586 
587  // If we have a bss global going to a section that supports the
588  // zerofill directive, do so here.
589  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective() &&
590  TheSection->isVirtualSection()) {
591  if (Size == 0)
592  Size = 1; // zerofill of 0 bytes is undefined.
593  emitLinkage(GV, GVSym);
594  // .zerofill __DATA, __bss, _foo, 400, 5
595  OutStreamer->emitZerofill(TheSection, GVSym, Size, Alignment.value());
596  return;
597  }
598 
599  // If this is a BSS local symbol and we are emitting in the BSS
600  // section use .lcomm/.comm directive.
601  if (GVKind.isBSSLocal() &&
602  getObjFileLowering().getBSSSection() == TheSection) {
603  if (Size == 0)
604  Size = 1; // .comm Foo, 0 is undefined, avoid it.
605 
606  // Use .lcomm only if it supports user-specified alignment.
607  // Otherwise, while it would still be correct to use .lcomm in some
608  // cases (e.g. when Align == 1), the external assembler might enfore
609  // some -unknown- default alignment behavior, which could cause
610  // spurious differences between external and integrated assembler.
611  // Prefer to simply fall back to .local / .comm in this case.
613  // .lcomm _foo, 42
614  OutStreamer->emitLocalCommonSymbol(GVSym, Size, Alignment.value());
615  return;
616  }
617 
618  // .local _foo
619  OutStreamer->emitSymbolAttribute(GVSym, MCSA_Local);
620  // .comm _foo, 42, 4
621  const bool SupportsAlignment =
623  OutStreamer->emitCommonSymbol(GVSym, Size,
624  SupportsAlignment ? Alignment.value() : 0);
625  return;
626  }
627 
628  // Handle thread local data for mach-o which requires us to output an
629  // additional structure of data and mangle the original symbol so that we
630  // can reference it later.
631  //
632  // TODO: This should become an "emit thread local global" method on TLOF.
633  // All of this macho specific stuff should be sunk down into TLOFMachO and
634  // stuff like "TLSExtraDataSection" should no longer be part of the parent
635  // TLOF class. This will also make it more obvious that stuff like
636  // MCStreamer::EmitTBSSSymbol is macho specific and only called from macho
637  // specific code.
638  if (GVKind.isThreadLocal() && MAI->hasMachoTBSSDirective()) {
639  // Emit the .tbss symbol
640  MCSymbol *MangSym =
641  OutContext.getOrCreateSymbol(GVSym->getName() + Twine("$tlv$init"));
642 
643  if (GVKind.isThreadBSS()) {
644  TheSection = getObjFileLowering().getTLSBSSSection();
645  OutStreamer->emitTBSSSymbol(TheSection, MangSym, Size, Alignment.value());
646  } else if (GVKind.isThreadData()) {
647  OutStreamer->SwitchSection(TheSection);
648 
649  emitAlignment(Alignment, GV);
650  OutStreamer->emitLabel(MangSym);
651 
653  GV->getInitializer());
654  }
655 
656  OutStreamer->AddBlankLine();
657 
658  // Emit the variable struct for the runtime.
660 
661  OutStreamer->SwitchSection(TLVSect);
662  // Emit the linkage here.
663  emitLinkage(GV, GVSym);
664  OutStreamer->emitLabel(GVSym);
665 
666  // Three pointers in size:
667  // - __tlv_bootstrap - used to make sure support exists
668  // - spare pointer, used when mapped by the runtime
669  // - pointer to mangled symbol above with initializer
670  unsigned PtrSize = DL.getPointerTypeSize(GV->getType());
671  OutStreamer->emitSymbolValue(GetExternalSymbolSymbol("_tlv_bootstrap"),
672  PtrSize);
673  OutStreamer->emitIntValue(0, PtrSize);
674  OutStreamer->emitSymbolValue(MangSym, PtrSize);
675 
676  OutStreamer->AddBlankLine();
677  return;
678  }
679 
680  MCSymbol *EmittedInitSym = GVSym;
681 
682  OutStreamer->SwitchSection(TheSection);
683 
684  emitLinkage(GV, EmittedInitSym);
685  emitAlignment(Alignment, GV);
686 
687  OutStreamer->emitLabel(EmittedInitSym);
688  MCSymbol *LocalAlias = getSymbolPreferLocal(*GV);
689  if (LocalAlias != EmittedInitSym)
690  OutStreamer->emitLabel(LocalAlias);
691 
693 
695  // .size foo, 42
696  OutStreamer->emitELFSize(EmittedInitSym,
698 
699  OutStreamer->AddBlankLine();
700 }
701 
702 /// Emit the directive and value for debug thread local expression
703 ///
704 /// \p Value - The value to emit.
705 /// \p Size - The size of the integer (in bytes) to emit.
706 void AsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
707  OutStreamer->emitValue(Value, Size);
708 }
709 
710 void AsmPrinter::emitFunctionHeaderComment() {}
711 
712 /// EmitFunctionHeader - This method emits the header for the current
713 /// function.
714 void AsmPrinter::emitFunctionHeader() {
715  const Function &F = MF->getFunction();
716 
717  if (isVerbose())
718  OutStreamer->GetCommentOS()
719  << "-- Begin function "
720  << GlobalValue::dropLLVMManglingEscape(F.getName()) << '\n';
721 
722  // Print out constants referenced by the function
724 
725  // Print the 'header' of function.
726  // If basic block sections are desired, explicitly request a unique section
727  // for this function's entry block.
728  if (MF->front().isBeginSection())
729  MF->setSection(getObjFileLowering().getUniqueSectionForFunction(F, TM));
730  else
731  MF->setSection(getObjFileLowering().SectionForGlobal(&F, TM));
732  OutStreamer->SwitchSection(MF->getSection());
733 
735  emitVisibility(CurrentFnSym, F.getVisibility());
736 
739 
741  if (MAI->hasFunctionAlignment())
743 
745  OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
746 
747  if (F.hasFnAttribute(Attribute::Cold))
748  OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_Cold);
749 
750  if (isVerbose()) {
751  F.printAsOperand(OutStreamer->GetCommentOS(),
752  /*PrintType=*/false, F.getParent());
753  emitFunctionHeaderComment();
754  OutStreamer->GetCommentOS() << '\n';
755  }
756 
757  // Emit the prefix data.
758  if (F.hasPrefixData()) {
759  if (MAI->hasSubsectionsViaSymbols()) {
760  // Preserving prefix data on platforms which use subsections-via-symbols
761  // is a bit tricky. Here we introduce a symbol for the prefix data
762  // and use the .alt_entry attribute to mark the function's real entry point
763  // as an alternative entry point to the prefix-data symbol.
765  OutStreamer->emitLabel(PrefixSym);
766 
767  emitGlobalConstant(F.getParent()->getDataLayout(), F.getPrefixData());
768 
769  // Emit an .alt_entry directive for the actual function symbol.
770  OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_AltEntry);
771  } else {
772  emitGlobalConstant(F.getParent()->getDataLayout(), F.getPrefixData());
773  }
774  }
775 
776  // Emit M NOPs for -fpatchable-function-entry=N,M where M>0. We arbitrarily
777  // place prefix data before NOPs.
778  unsigned PatchableFunctionPrefix = 0;
779  unsigned PatchableFunctionEntry = 0;
780  (void)F.getFnAttribute("patchable-function-prefix")
781  .getValueAsString()
782  .getAsInteger(10, PatchableFunctionPrefix);
783  (void)F.getFnAttribute("patchable-function-entry")
784  .getValueAsString()
785  .getAsInteger(10, PatchableFunctionEntry);
786  if (PatchableFunctionPrefix) {
790  emitNops(PatchableFunctionPrefix);
791  } else if (PatchableFunctionEntry) {
792  // May be reassigned when emitting the body, to reference the label after
793  // the initial BTI (AArch64) or endbr32/endbr64 (x86).
795  }
796 
797  // Emit the function descriptor. This is a virtual function to allow targets
798  // to emit their specific function descriptor. Right now it is only used by
799  // the AIX target. The PowerPC 64-bit V1 ELF target also uses function
800  // descriptors and should be converted to use this hook as well.
803 
804  // Emit the CurrentFnSym. This is a virtual function to allow targets to do
805  // their wild and crazy things as required.
807 
808  // If the function had address-taken blocks that got deleted, then we have
809  // references to the dangling symbols. Emit them at the start of the function
810  // so that we don't get references to undefined symbols.
811  std::vector<MCSymbol*> DeadBlockSyms;
812  MMI->takeDeletedSymbolsForFunction(&F, DeadBlockSyms);
813  for (unsigned i = 0, e = DeadBlockSyms.size(); i != e; ++i) {
814  OutStreamer->AddComment("Address taken block that was later removed");
815  OutStreamer->emitLabel(DeadBlockSyms[i]);
816  }
817 
818  if (CurrentFnBegin) {
819  if (MAI->useAssignmentForEHBegin()) {
821  OutStreamer->emitLabel(CurPos);
822  OutStreamer->emitAssignment(CurrentFnBegin,
824  } else {
825  OutStreamer->emitLabel(CurrentFnBegin);
826  }
827  }
828 
829  // Emit pre-function debug and/or EH information.
830  for (const HandlerInfo &HI : Handlers) {
831  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
832  HI.TimerGroupDescription, TimePassesIsEnabled);
833  HI.Handler->beginFunction(MF);
834  }
835 
836  // Emit the prologue data.
837  if (F.hasPrologueData())
838  emitGlobalConstant(F.getParent()->getDataLayout(), F.getPrologueData());
839 }
840 
841 /// EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
842 /// function. This can be overridden by targets as required to do custom stuff.
845 
846  // The function label could have already been emitted if two symbols end up
847  // conflicting due to asm renaming. Detect this and emit an error.
848  if (CurrentFnSym->isVariable())
850  "' is a protected alias");
851 
852  OutStreamer->emitLabel(CurrentFnSym);
853 
856  if (Sym != CurrentFnSym)
857  OutStreamer->emitLabel(Sym);
858  }
859 }
860 
861 /// emitComments - Pretty-print comments for instructions.
862 static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
863  const MachineFunction *MF = MI.getMF();
864  const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
865 
866  // Check for spills and reloads
867 
868  // We assume a single instruction only has a spill or reload, not
869  // both.
871  if ((Size = MI.getRestoreSize(TII))) {
872  CommentOS << *Size << "-byte Reload\n";
873  } else if ((Size = MI.getFoldedRestoreSize(TII))) {
874  if (*Size) {
875  if (*Size == unsigned(MemoryLocation::UnknownSize))
876  CommentOS << "Unknown-size Folded Reload\n";
877  else
878  CommentOS << *Size << "-byte Folded Reload\n";
879  }
880  } else if ((Size = MI.getSpillSize(TII))) {
881  CommentOS << *Size << "-byte Spill\n";
882  } else if ((Size = MI.getFoldedSpillSize(TII))) {
883  if (*Size) {
884  if (*Size == unsigned(MemoryLocation::UnknownSize))
885  CommentOS << "Unknown-size Folded Spill\n";
886  else
887  CommentOS << *Size << "-byte Folded Spill\n";
888  }
889  }
890 
891  // Check for spill-induced copies
892  if (MI.getAsmPrinterFlag(MachineInstr::ReloadReuse))
893  CommentOS << " Reload Reuse\n";
894 }
895 
896 /// emitImplicitDef - This method emits the specified machine instruction
897 /// that is an implicit def.
899  Register RegNo = MI->getOperand(0).getReg();
900 
901  SmallString<128> Str;
902  raw_svector_ostream OS(Str);
903  OS << "implicit-def: "
904  << printReg(RegNo, MF->getSubtarget().getRegisterInfo());
905 
906  OutStreamer->AddComment(OS.str());
907  OutStreamer->AddBlankLine();
908 }
909 
910 static void emitKill(const MachineInstr *MI, AsmPrinter &AP) {
911  std::string Str;
912  raw_string_ostream OS(Str);
913  OS << "kill:";
914  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
915  const MachineOperand &Op = MI->getOperand(i);
916  assert(Op.isReg() && "KILL instruction must have only register operands");
917  OS << ' ' << (Op.isDef() ? "def " : "killed ")
918  << printReg(Op.getReg(), AP.MF->getSubtarget().getRegisterInfo());
919  }
920  AP.OutStreamer->AddComment(OS.str());
921  AP.OutStreamer->AddBlankLine();
922 }
923 
924 /// emitDebugValueComment - This method handles the target-independent form
925 /// of DBG_VALUE, returning true if it was able to do so. A false return
926 /// means the target will need to handle MI in EmitInstruction.
928  // This code handles only the 4-operand target-independent form.
929  if (MI->isNonListDebugValue() && MI->getNumOperands() != 4)
930  return false;
931 
932  SmallString<128> Str;
933  raw_svector_ostream OS(Str);
934  OS << "DEBUG_VALUE: ";
935 
936  const DILocalVariable *V = MI->getDebugVariable();
937  if (auto *SP = dyn_cast<DISubprogram>(V->getScope())) {
938  StringRef Name = SP->getName();
939  if (!Name.empty())
940  OS << Name << ":";
941  }
942  OS << V->getName();
943  OS << " <- ";
944 
945  const DIExpression *Expr = MI->getDebugExpression();
946  if (Expr->getNumElements()) {
947  OS << '[';
948  ListSeparator LS;
949  for (auto Op : Expr->expr_ops()) {
950  OS << LS << dwarf::OperationEncodingString(Op.getOp());
951  for (unsigned I = 0; I < Op.getNumArgs(); ++I)
952  OS << ' ' << Op.getArg(I);
953  }
954  OS << "] ";
955  }
956 
957  // Register or immediate value. Register 0 means undef.
958  for (const MachineOperand &Op : MI->debug_operands()) {
959  if (&Op != MI->debug_operands().begin())
960  OS << ", ";
961  switch (Op.getType()) {
963  APFloat APF = APFloat(Op.getFPImm()->getValueAPF());
964  Type *ImmTy = Op.getFPImm()->getType();
965  if (ImmTy->isBFloatTy() || ImmTy->isHalfTy() || ImmTy->isFloatTy() ||
966  ImmTy->isDoubleTy()) {
967  OS << APF.convertToDouble();
968  } else {
969  // There is no good way to print long double. Convert a copy to
970  // double. Ah well, it's only a comment.
971  bool ignored;
973  &ignored);
974  OS << "(long double) " << APF.convertToDouble();
975  }
976  break;
977  }
979  OS << Op.getImm();
980  break;
981  }
983  Op.getCImm()->getValue().print(OS, false /*isSigned*/);
984  break;
985  }
987  OS << "!target-index(" << Op.getIndex() << "," << Op.getOffset() << ")";
988  // NOTE: Want this comment at start of line, don't emit with AddComment.
989  AP.OutStreamer->emitRawComment(OS.str());
990  break;
991  }
994  Register Reg;
996  if (Op.isReg()) {
997  Reg = Op.getReg();
998  } else {
999  const TargetFrameLowering *TFI =
1001  Offset = TFI->getFrameIndexReference(*AP.MF, Op.getIndex(), Reg);
1002  }
1003  if (!Reg) {
1004  // Suppress offset, it is not meaningful here.
1005  OS << "undef";
1006  break;
1007  }
1008  // The second operand is only an offset if it's an immediate.
1009  if (MI->isIndirectDebugValue())
1010  Offset = StackOffset::getFixed(MI->getDebugOffset().getImm());
1011  if (Offset)
1012  OS << '[';
1013  OS << printReg(Reg, AP.MF->getSubtarget().getRegisterInfo());
1014  if (Offset)
1015  OS << '+' << Offset->getFixed() << ']';
1016  break;
1017  }
1018  default:
1019  llvm_unreachable("Unknown operand type");
1020  }
1021  }
1022 
1023  // NOTE: Want this comment at start of line, don't emit with AddComment.
1024  AP.OutStreamer->emitRawComment(OS.str());
1025  return true;
1026 }
1027 
1028 /// This method handles the target-independent form of DBG_LABEL, returning
1029 /// true if it was able to do so. A false return means the target will need
1030 /// to handle MI in EmitInstruction.
1032  if (MI->getNumOperands() != 1)
1033  return false;
1034 
1035  SmallString<128> Str;
1036  raw_svector_ostream OS(Str);
1037  OS << "DEBUG_LABEL: ";
1038 
1039  const DILabel *V = MI->getDebugLabel();
1040  if (auto *SP = dyn_cast<DISubprogram>(
1042  StringRef Name = SP->getName();
1043  if (!Name.empty())
1044  OS << Name << ":";
1045  }
1046  OS << V->getName();
1047 
1048  // NOTE: Want this comment at start of line, don't emit with AddComment.
1049  AP.OutStreamer->emitRawComment(OS.str());
1050  return true;
1051 }
1052 
1055  // Ignore functions that won't get emitted.
1056  if (F.isDeclarationForLinker())
1057  return CFISection::None;
1058 
1060  F.needsUnwindTableEntry())
1061  return CFISection::EH;
1062 
1064  return CFISection::Debug;
1065 
1066  return CFISection::None;
1067 }
1068 
1072 }
1073 
1076 }
1077 
1080  MAI->doesUseCFIForDebug() && ModuleCFISection == CFISection::Debug;
1081 }
1082 
1084  ExceptionHandling ExceptionHandlingType = MAI->getExceptionHandlingType();
1085  if (!needsCFIForDebug() &&
1086  ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
1087  ExceptionHandlingType != ExceptionHandling::ARM)
1088  return;
1089 
1091  return;
1092 
1093  // If there is no "real" instruction following this CFI instruction, skip
1094  // emitting it; it would be beyond the end of the function's FDE range.
1095  auto *MBB = MI.getParent();
1096  auto I = std::next(MI.getIterator());
1097  while (I != MBB->end() && I->isTransient())
1098  ++I;
1099  if (I == MBB->instr_end() &&
1101  return;
1102 
1103  const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions();
1104  unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
1105  const MCCFIInstruction &CFI = Instrs[CFIIndex];
1106  emitCFIInstruction(CFI);
1107 }
1108 
1110  // The operands are the MCSymbol and the frame offset of the allocation.
1111  MCSymbol *FrameAllocSym = MI.getOperand(0).getMCSymbol();
1112  int FrameOffset = MI.getOperand(1).getImm();
1113 
1114  // Emit a symbol assignment.
1115  OutStreamer->emitAssignment(FrameAllocSym,
1116  MCConstantExpr::create(FrameOffset, OutContext));
1117 }
1118 
1119 /// Returns the BB metadata to be emitted in the .llvm_bb_addr_map section for a
1120 /// given basic block. This can be used to capture more precise profile
1121 /// information. We use the last 4 bits (LSBs) to encode the following
1122 /// information:
1123 /// * (1): set if return block (ret or tail call).
1124 /// * (2): set if ends with a tail call.
1125 /// * (3): set if exception handling (EH) landing pad.
1126 /// * (4): set if the block can fall through to its next.
1127 /// The remaining bits are zero.
1128 static unsigned getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
1130  return ((unsigned)MBB.isReturnBlock()) |
1131  ((!MBB.empty() && TII->isTailCall(MBB.back())) << 1) |
1132  (MBB.isEHPad() << 2) |
1133  (const_cast<MachineBasicBlock &>(MBB).canFallThrough() << 3);
1134 }
1135 
1137  MCSection *BBAddrMapSection =
1139  assert(BBAddrMapSection && ".llvm_bb_addr_map section is not initialized.");
1140 
1141  const MCSymbol *FunctionSymbol = getFunctionBegin();
1142 
1143  OutStreamer->PushSection();
1144  OutStreamer->SwitchSection(BBAddrMapSection);
1145  OutStreamer->emitSymbolValue(FunctionSymbol, getPointerSize());
1146  // Emit the total number of basic blocks in this function.
1147  OutStreamer->emitULEB128IntValue(MF.size());
1148  // Emit BB Information for each basic block in the funciton.
1149  for (const MachineBasicBlock &MBB : MF) {
1150  const MCSymbol *MBBSymbol =
1151  MBB.isEntryBlock() ? FunctionSymbol : MBB.getSymbol();
1152  // Emit the basic block offset.
1153  emitLabelDifferenceAsULEB128(MBBSymbol, FunctionSymbol);
1154  // Emit the basic block size. When BBs have alignments, their size cannot
1155  // always be computed from their offsets.
1157  OutStreamer->emitULEB128IntValue(getBBAddrMapMetadata(MBB));
1158  }
1159  OutStreamer->PopSection();
1160 }
1161 
1163  auto GUID = MI.getOperand(0).getImm();
1164  auto Index = MI.getOperand(1).getImm();
1165  auto Type = MI.getOperand(2).getImm();
1166  auto Attr = MI.getOperand(3).getImm();
1167  DILocation *DebugLoc = MI.getDebugLoc();
1168  PP->emitPseudoProbe(GUID, Index, Type, Attr, DebugLoc);
1169 }
1170 
1173  return;
1174 
1175  MCSection *StackSizeSection =
1177  if (!StackSizeSection)
1178  return;
1179 
1180  const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
1181  // Don't emit functions with dynamic stack allocations.
1182  if (FrameInfo.hasVarSizedObjects())
1183  return;
1184 
1185  OutStreamer->PushSection();
1186  OutStreamer->SwitchSection(StackSizeSection);
1187 
1188  const MCSymbol *FunctionSymbol = getFunctionBegin();
1189  uint64_t StackSize = FrameInfo.getStackSize();
1190  OutStreamer->emitSymbolValue(FunctionSymbol, TM.getProgramPointerSize());
1191  OutStreamer->emitULEB128IntValue(StackSize);
1192 
1193  OutStreamer->PopSection();
1194 }
1195 
1197  const std::string &OutputFilename = MF.getTarget().Options.StackUsageOutput;
1198 
1199  // OutputFilename empty implies -fstack-usage is not passed.
1200  if (OutputFilename.empty())
1201  return;
1202 
1203  const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
1204  uint64_t StackSize = FrameInfo.getStackSize();
1205 
1206  if (StackUsageStream == nullptr) {
1207  std::error_code EC;
1208  StackUsageStream =
1209  std::make_unique<raw_fd_ostream>(OutputFilename, EC, sys::fs::OF_Text);
1210  if (EC) {
1211  errs() << "Could not open file: " << EC.message();
1212  return;
1213  }
1214  }
1215 
1216  *StackUsageStream << MF.getFunction().getParent()->getName();
1217  if (const DISubprogram *DSP = MF.getFunction().getSubprogram())
1218  *StackUsageStream << ':' << DSP->getLine();
1219 
1220  *StackUsageStream << ':' << MF.getName() << '\t' << StackSize << '\t';
1221  if (FrameInfo.hasVarSizedObjects())
1222  *StackUsageStream << "dynamic\n";
1223  else
1224  *StackUsageStream << "static\n";
1225 }
1226 
1228  MachineModuleInfo &MMI = MF.getMMI();
1229  if (!MF.getLandingPads().empty() || MF.hasEHFunclets() || MMI.hasDebugInfo())
1230  return true;
1231 
1232  // We might emit an EH table that uses function begin and end labels even if
1233  // we don't have any landingpads.
1234  if (!MF.getFunction().hasPersonalityFn())
1235  return false;
1236  return !isNoOpWithoutInvoke(
1238 }
1239 
1240 /// EmitFunctionBody - This method emits the body and trailer for a
1241 /// function.
1243  emitFunctionHeader();
1244 
1245  // Emit target-specific gunk before the function body.
1247 
1248  if (isVerbose()) {
1249  // Get MachineDominatorTree or compute it on the fly if it's unavailable
1250  MDT = getAnalysisIfAvailable<MachineDominatorTree>();
1251  if (!MDT) {
1252  OwnedMDT = std::make_unique<MachineDominatorTree>();
1253  OwnedMDT->getBase().recalculate(*MF);
1254  MDT = OwnedMDT.get();
1255  }
1256 
1257  // Get MachineLoopInfo or compute it on the fly if it's unavailable
1258  MLI = getAnalysisIfAvailable<MachineLoopInfo>();
1259  if (!MLI) {
1260  OwnedMLI = std::make_unique<MachineLoopInfo>();
1261  OwnedMLI->getBase().analyze(MDT->getBase());
1262  MLI = OwnedMLI.get();
1263  }
1264  }
1265 
1266  // Print out code for the function.
1267  bool HasAnyRealCode = false;
1268  int NumInstsInFunction = 0;
1269 
1270  bool CanDoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
1271  for (auto &MBB : *MF) {
1272  // Print a label for the basic block.
1274  DenseMap<StringRef, unsigned> MnemonicCounts;
1275  for (auto &MI : MBB) {
1276  // Print the assembly for the instruction.
1277  if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
1278  !MI.isDebugInstr()) {
1279  HasAnyRealCode = true;
1280  ++NumInstsInFunction;
1281  }
1282 
1283  // If there is a pre-instruction symbol, emit a label for it here.
1284  if (MCSymbol *S = MI.getPreInstrSymbol())
1285  OutStreamer->emitLabel(S);
1286 
1287  for (const HandlerInfo &HI : Handlers) {
1288  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1289  HI.TimerGroupDescription, TimePassesIsEnabled);
1290  HI.Handler->beginInstruction(&MI);
1291  }
1292 
1293  if (isVerbose())
1294  emitComments(MI, OutStreamer->GetCommentOS());
1295 
1296  switch (MI.getOpcode()) {
1297  case TargetOpcode::CFI_INSTRUCTION:
1299  break;
1300  case TargetOpcode::LOCAL_ESCAPE:
1301  emitFrameAlloc(MI);
1302  break;
1305  case TargetOpcode::GC_LABEL:
1306  OutStreamer->emitLabel(MI.getOperand(0).getMCSymbol());
1307  break;
1310  emitInlineAsm(&MI);
1311  break;
1312  case TargetOpcode::DBG_VALUE:
1313  case TargetOpcode::DBG_VALUE_LIST:
1314  if (isVerbose()) {
1315  if (!emitDebugValueComment(&MI, *this))
1316  emitInstruction(&MI);
1317  }
1318  break;
1319  case TargetOpcode::DBG_INSTR_REF:
1320  // This instruction reference will have been resolved to a machine
1321  // location, and a nearby DBG_VALUE created. We can safely ignore
1322  // the instruction reference.
1323  break;
1324  case TargetOpcode::DBG_PHI:
1325  // This instruction is only used to label a program point, it's purely
1326  // meta information.
1327  break;
1328  case TargetOpcode::DBG_LABEL:
1329  if (isVerbose()) {
1330  if (!emitDebugLabelComment(&MI, *this))
1331  emitInstruction(&MI);
1332  }
1333  break;
1334  case TargetOpcode::IMPLICIT_DEF:
1335  if (isVerbose()) emitImplicitDef(&MI);
1336  break;
1337  case TargetOpcode::KILL:
1338  if (isVerbose()) emitKill(&MI, *this);
1339  break;
1342  break;
1344  if (isVerbose())
1345  OutStreamer->emitRawComment("ARITH_FENCE");
1346  break;
1347  default:
1348  emitInstruction(&MI);
1349  if (CanDoExtraAnalysis) {
1350  MCInst MCI;
1351  MCI.setOpcode(MI.getOpcode());
1352  auto Name = OutStreamer->getMnemonic(MCI);
1353  auto I = MnemonicCounts.insert({Name, 0u});
1354  I.first->second++;
1355  }
1356  break;
1357  }
1358 
1359  // If there is a post-instruction symbol, emit a label for it here.
1360  if (MCSymbol *S = MI.getPostInstrSymbol())
1361  OutStreamer->emitLabel(S);
1362 
1363  for (const HandlerInfo &HI : Handlers) {
1364  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1365  HI.TimerGroupDescription, TimePassesIsEnabled);
1366  HI.Handler->endInstruction();
1367  }
1368  }
1369 
1370  // We must emit temporary symbol for the end of this basic block, if either
1371  // we have BBLabels enabled or if this basic blocks marks the end of a
1372  // section.
1373  if (MF->hasBBLabels() ||
1375  OutStreamer->emitLabel(MBB.getEndSymbol());
1376 
1377  if (MBB.isEndSection()) {
1378  // The size directive for the section containing the entry block is
1379  // handled separately by the function section.
1380  if (!MBB.sameSection(&MF->front())) {
1382  // Emit the size directive for the basic block section.
1383  const MCExpr *SizeExp = MCBinaryExpr::createSub(
1385  MCSymbolRefExpr::create(CurrentSectionBeginSym, OutContext),
1386  OutContext);
1387  OutStreamer->emitELFSize(CurrentSectionBeginSym, SizeExp);
1388  }
1390  MBBSectionRange{CurrentSectionBeginSym, MBB.getEndSymbol()};
1391  }
1392  }
1394 
1395  if (CanDoExtraAnalysis) {
1396  // Skip empty blocks.
1397  if (MBB.empty())
1398  continue;
1399 
1400  MachineOptimizationRemarkAnalysis R(DEBUG_TYPE, "InstructionMix",
1401  MBB.begin()->getDebugLoc(), &MBB);
1402 
1403  // Generate instruction mix remark. First, sort counts in descending order
1404  // by count and name.
1406  for (auto &KV : MnemonicCounts)
1407  MnemonicVec.emplace_back(KV.first, KV.second);
1408 
1409  sort(MnemonicVec, [](const std::pair<StringRef, unsigned> &A,
1410  const std::pair<StringRef, unsigned> &B) {
1411  if (A.second > B.second)
1412  return true;
1413  if (A.second == B.second)
1414  return StringRef(A.first) < StringRef(B.first);
1415  return false;
1416  });
1417  R << "BasicBlock: " << ore::NV("BasicBlock", MBB.getName()) << "\n";
1418  for (auto &KV : MnemonicVec) {
1419  auto Name = (Twine("INST_") + KV.first.trim()).str();
1420  R << KV.first << ": " << ore::NV(Name, KV.second) << "\n";
1421  }
1422  ORE->emit(R);
1423  }
1424  }
1425 
1426  EmittedInsts += NumInstsInFunction;
1427  MachineOptimizationRemarkAnalysis R(DEBUG_TYPE, "InstructionCount",
1429  &MF->front());
1430  R << ore::NV("NumInstructions", NumInstsInFunction)
1431  << " instructions in function";
1432  ORE->emit(R);
1433 
1434  // If the function is empty and the object file uses .subsections_via_symbols,
1435  // then we need to emit *something* to the function body to prevent the
1436  // labels from collapsing together. Just emit a noop.
1437  // Similarly, don't emit empty functions on Windows either. It can lead to
1438  // duplicate entries (two functions with the same RVA) in the Guard CF Table
1439  // after linking, causing the kernel not to load the binary:
1440  // https://developercommunity.visualstudio.com/content/problem/45366/vc-linker-creates-invalid-dll-with-clang-cl.html
1441  // FIXME: Hide this behind some API in e.g. MCAsmInfo or MCTargetStreamer.
1442  const Triple &TT = TM.getTargetTriple();
1443  if (!HasAnyRealCode && (MAI->hasSubsectionsViaSymbols() ||
1444  (TT.isOSWindows() && TT.isOSBinFormatCOFF()))) {
1445  MCInst Noop = MF->getSubtarget().getInstrInfo()->getNop();
1446 
1447  // Targets can opt-out of emitting the noop here by leaving the opcode
1448  // unspecified.
1449  if (Noop.getOpcode()) {
1450  OutStreamer->AddComment("avoids zero-length function");
1451  emitNops(1);
1452  }
1453  }
1454 
1455  // Switch to the original section in case basic block sections was used.
1456  OutStreamer->SwitchSection(MF->getSection());
1457 
1458  const Function &F = MF->getFunction();
1459  for (const auto &BB : F) {
1460  if (!BB.hasAddressTaken())
1461  continue;
1463  if (Sym->isDefined())
1464  continue;
1465  OutStreamer->AddComment("Address of block that was removed by CodeGen");
1466  OutStreamer->emitLabel(Sym);
1467  }
1468 
1469  // Emit target-specific gunk after the function body.
1471 
1474  // Create a symbol for the end of function.
1475  CurrentFnEnd = createTempSymbol("func_end");
1476  OutStreamer->emitLabel(CurrentFnEnd);
1477  }
1478 
1479  // If the target wants a .size directive for the size of the function, emit
1480  // it.
1482  // We can get the size as difference between the function label and the
1483  // temp label.
1484  const MCExpr *SizeExp = MCBinaryExpr::createSub(
1485  MCSymbolRefExpr::create(CurrentFnEnd, OutContext),
1487  OutStreamer->emitELFSize(CurrentFnSym, SizeExp);
1488  }
1489 
1490  for (const HandlerInfo &HI : Handlers) {
1491  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1492  HI.TimerGroupDescription, TimePassesIsEnabled);
1493  HI.Handler->markFunctionEnd();
1494  }
1495 
1497  MBBSectionRange{CurrentFnBegin, CurrentFnEnd};
1498 
1499  // Print out jump tables referenced by the function.
1501 
1502  // Emit post-function debug and/or EH information.
1503  for (const HandlerInfo &HI : Handlers) {
1504  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1505  HI.TimerGroupDescription, TimePassesIsEnabled);
1506  HI.Handler->endFunction(MF);
1507  }
1508 
1509  // Emit section containing BB address offsets and their metadata, when
1510  // BB labels are requested for this function. Skip empty functions.
1511  if (MF->hasBBLabels() && HasAnyRealCode)
1513 
1514  // Emit section containing stack size metadata.
1516 
1517  // Emit .su file containing function stack size information.
1518  emitStackUsage(*MF);
1519 
1521 
1522  if (isVerbose())
1523  OutStreamer->GetCommentOS() << "-- End function\n";
1524 
1525  OutStreamer->AddBlankLine();
1526 }
1527 
1528 /// Compute the number of Global Variables that uses a Constant.
1529 static unsigned getNumGlobalVariableUses(const Constant *C) {
1530  if (!C)
1531  return 0;
1532 
1533  if (isa<GlobalVariable>(C))
1534  return 1;
1535 
1536  unsigned NumUses = 0;
1537  for (auto *CU : C->users())
1538  NumUses += getNumGlobalVariableUses(dyn_cast<Constant>(CU));
1539 
1540  return NumUses;
1541 }
1542 
1543 /// Only consider global GOT equivalents if at least one user is a
1544 /// cstexpr inside an initializer of another global variables. Also, don't
1545 /// handle cstexpr inside instructions. During global variable emission,
1546 /// candidates are skipped and are emitted later in case at least one cstexpr
1547 /// isn't replaced by a PC relative GOT entry access.
1549  unsigned &NumGOTEquivUsers) {
1550  // Global GOT equivalents are unnamed private globals with a constant
1551  // pointer initializer to another global symbol. They must point to a
1552  // GlobalVariable or Function, i.e., as GlobalValue.
1553  if (!GV->hasGlobalUnnamedAddr() || !GV->hasInitializer() ||
1554  !GV->isConstant() || !GV->isDiscardableIfUnused() ||
1555  !isa<GlobalValue>(GV->getOperand(0)))
1556  return false;
1557 
1558  // To be a got equivalent, at least one of its users need to be a constant
1559  // expression used by another global variable.
1560  for (auto *U : GV->users())
1561  NumGOTEquivUsers += getNumGlobalVariableUses(dyn_cast<Constant>(U));
1562 
1563  return NumGOTEquivUsers > 0;
1564 }
1565 
1566 /// Unnamed constant global variables solely contaning a pointer to
1567 /// another globals variable is equivalent to a GOT table entry; it contains the
1568 /// the address of another symbol. Optimize it and replace accesses to these
1569 /// "GOT equivalents" by using the GOT entry for the final global instead.
1570 /// Compute GOT equivalent candidates among all global variables to avoid
1571 /// emitting them if possible later on, after it use is replaced by a GOT entry
1572 /// access.
1574  if (!getObjFileLowering().supportIndirectSymViaGOTPCRel())
1575  return;
1576 
1577  for (const auto &G : M.globals()) {
1578  unsigned NumGOTEquivUsers = 0;
1579  if (!isGOTEquivalentCandidate(&G, NumGOTEquivUsers))
1580  continue;
1581 
1582  const MCSymbol *GOTEquivSym = getSymbol(&G);
1583  GlobalGOTEquivs[GOTEquivSym] = std::make_pair(&G, NumGOTEquivUsers);
1584  }
1585 }
1586 
1587 /// Constant expressions using GOT equivalent globals may not be eligible
1588 /// for PC relative GOT entry conversion, in such cases we need to emit such
1589 /// globals we previously omitted in EmitGlobalVariable.
1591  if (!getObjFileLowering().supportIndirectSymViaGOTPCRel())
1592  return;
1593 
1594  SmallVector<const GlobalVariable *, 8> FailedCandidates;
1595  for (auto &I : GlobalGOTEquivs) {
1596  const GlobalVariable *GV = I.second.first;
1597  unsigned Cnt = I.second.second;
1598  if (Cnt)
1599  FailedCandidates.push_back(GV);
1600  }
1601  GlobalGOTEquivs.clear();
1602 
1603  for (auto *GV : FailedCandidates)
1604  emitGlobalVariable(GV);
1605 }
1606 
1607 void AsmPrinter::emitGlobalIndirectSymbol(Module &M,
1608  const GlobalIndirectSymbol& GIS) {
1609  MCSymbol *Name = getSymbol(&GIS);
1610  bool IsFunction = GIS.getValueType()->isFunctionTy();
1611  // Treat bitcasts of functions as functions also. This is important at least
1612  // on WebAssembly where object and function addresses can't alias each other.
1613  if (!IsFunction)
1614  if (auto *CE = dyn_cast<ConstantExpr>(GIS.getIndirectSymbol()))
1615  if (CE->getOpcode() == Instruction::BitCast)
1616  IsFunction =
1617  CE->getOperand(0)->getType()->getPointerElementType()->isFunctionTy();
1618 
1619  // AIX's assembly directive `.set` is not usable for aliasing purpose,
1620  // so AIX has to use the extra-label-at-definition strategy. At this
1621  // point, all the extra label is emitted, we just have to emit linkage for
1622  // those labels.
1624  assert(!isa<GlobalIFunc>(GIS) && "IFunc is not supported on AIX.");
1626  "Visibility should be handled with emitLinkage() on AIX.");
1627  emitLinkage(&GIS, Name);
1628  // If it's a function, also emit linkage for aliases of function entry
1629  // point.
1630  if (IsFunction)
1631  emitLinkage(&GIS,
1632  getObjFileLowering().getFunctionEntryPointSymbol(&GIS, TM));
1633  return;
1634  }
1635 
1636  if (GIS.hasExternalLinkage() || !MAI->getWeakRefDirective())
1637  OutStreamer->emitSymbolAttribute(Name, MCSA_Global);
1638  else if (GIS.hasWeakLinkage() || GIS.hasLinkOnceLinkage())
1639  OutStreamer->emitSymbolAttribute(Name, MCSA_WeakReference);
1640  else
1641  assert(GIS.hasLocalLinkage() && "Invalid alias or ifunc linkage");
1642 
1643  // Set the symbol type to function if the alias has a function type.
1644  // This affects codegen when the aliasee is not a function.
1645  if (IsFunction)
1646  OutStreamer->emitSymbolAttribute(Name, isa<GlobalIFunc>(GIS)
1649 
1651 
1652  const MCExpr *Expr = lowerConstant(GIS.getIndirectSymbol());
1653 
1654  if (isa<GlobalAlias>(&GIS) && MAI->hasAltEntry() && isa<MCBinaryExpr>(Expr))
1655  OutStreamer->emitSymbolAttribute(Name, MCSA_AltEntry);
1656 
1657  // Emit the directives as assignments aka .set:
1658  OutStreamer->emitAssignment(Name, Expr);
1659  MCSymbol *LocalAlias = getSymbolPreferLocal(GIS);
1660  if (LocalAlias != Name)
1661  OutStreamer->emitAssignment(LocalAlias, Expr);
1662 
1663  if (auto *GA = dyn_cast<GlobalAlias>(&GIS)) {
1664  // If the aliasee does not correspond to a symbol in the output, i.e. the
1665  // alias is not of an object or the aliased object is private, then set the
1666  // size of the alias symbol from the type of the alias. We don't do this in
1667  // other situations as the alias and aliasee having differing types but same
1668  // size may be intentional.
1669  const GlobalObject *BaseObject = GA->getBaseObject();
1670  if (MAI->hasDotTypeDotSizeDirective() && GA->getValueType()->isSized() &&
1671  (!BaseObject || BaseObject->hasPrivateLinkage())) {
1672  const DataLayout &DL = M.getDataLayout();
1673  uint64_t Size = DL.getTypeAllocSize(GA->getValueType());
1675  }
1676  }
1677 }
1678 
1680  if (!RS.needsSection())
1681  return;
1682 
1683  remarks::RemarkSerializer &RemarkSerializer = RS.getSerializer();
1684 
1685  Optional<SmallString<128>> Filename;
1686  if (Optional<StringRef> FilenameRef = RS.getFilename()) {
1687  Filename = *FilenameRef;
1688  sys::fs::make_absolute(*Filename);
1689  assert(!Filename->empty() && "The filename can't be empty.");
1690  }
1691 
1692  std::string Buf;
1693  raw_string_ostream OS(Buf);
1694  std::unique_ptr<remarks::MetaSerializer> MetaSerializer =
1695  Filename ? RemarkSerializer.metaSerializer(OS, Filename->str())
1696  : RemarkSerializer.metaSerializer(OS);
1697  MetaSerializer->emit();
1698 
1699  // Switch to the remarks section.
1700  MCSection *RemarksSection =
1702  OutStreamer->SwitchSection(RemarksSection);
1703 
1704  OutStreamer->emitBinaryData(OS.str());
1705 }
1706 
1708  // Set the MachineFunction to nullptr so that we can catch attempted
1709  // accesses to MF specific features at the module level and so that
1710  // we can conditionalize accesses based on whether or not it is nullptr.
1711  MF = nullptr;
1712 
1713  // Gather all GOT equivalent globals in the module. We really need two
1714  // passes over the globals: one to compute and another to avoid its emission
1715  // in EmitGlobalVariable, otherwise we would not be able to handle cases
1716  // where the got equivalent shows up before its use.
1718 
1719  // Emit global variables.
1720  for (const auto &G : M.globals())
1722 
1723  // Emit remaining GOT equivalent globals.
1725 
1727 
1728  // Emit linkage(XCOFF) and visibility info for declarations
1729  for (const Function &F : M) {
1730  if (!F.isDeclarationForLinker())
1731  continue;
1732 
1733  MCSymbol *Name = getSymbol(&F);
1734  // Function getSymbol gives us the function descriptor symbol for XCOFF.
1735 
1737  GlobalValue::VisibilityTypes V = F.getVisibility();
1739  continue;
1740 
1741  emitVisibility(Name, V, false);
1742  continue;
1743  }
1744 
1745  if (F.isIntrinsic())
1746  continue;
1747 
1748  // Handle the XCOFF case.
1749  // Variable `Name` is the function descriptor symbol (see above). Get the
1750  // function entry point symbol.
1751  MCSymbol *FnEntryPointSym = TLOF.getFunctionEntryPointSymbol(&F, TM);
1752  // Emit linkage for the function entry point.
1753  emitLinkage(&F, FnEntryPointSym);
1754 
1755  // Emit linkage for the function descriptor.
1756  emitLinkage(&F, Name);
1757  }
1758 
1759  // Emit the remarks section contents.
1760  // FIXME: Figure out when is the safest time to emit this section. It should
1761  // not come after debug info.
1762  if (remarks::RemarkStreamer *RS = M.getContext().getMainRemarkStreamer())
1763  emitRemarksSection(*RS);
1764 
1766 
1769 
1770  // Output stubs for external and common global variables.
1772  if (!Stubs.empty()) {
1773  OutStreamer->SwitchSection(TLOF.getDataSection());
1774  const DataLayout &DL = M.getDataLayout();
1775 
1776  emitAlignment(Align(DL.getPointerSize()));
1777  for (const auto &Stub : Stubs) {
1778  OutStreamer->emitLabel(Stub.first);
1779  OutStreamer->emitSymbolValue(Stub.second.getPointer(),
1780  DL.getPointerSize());
1781  }
1782  }
1783  }
1784 
1786  MachineModuleInfoCOFF &MMICOFF =
1788 
1789  // Output stubs for external and common global variables.
1791  if (!Stubs.empty()) {
1792  const DataLayout &DL = M.getDataLayout();
1793 
1794  for (const auto &Stub : Stubs) {
1795  SmallString<256> SectionName = StringRef(".rdata$");
1796  SectionName += Stub.first->getName();
1797  OutStreamer->SwitchSection(OutContext.getCOFFSection(
1798  SectionName,
1801  SectionKind::getReadOnly(), Stub.first->getName(),
1803  emitAlignment(Align(DL.getPointerSize()));
1804  OutStreamer->emitSymbolAttribute(Stub.first, MCSA_Global);
1805  OutStreamer->emitLabel(Stub.first);
1806  OutStreamer->emitSymbolValue(Stub.second.getPointer(),
1807  DL.getPointerSize());
1808  }
1809  }
1810  }
1811 
1812  // This needs to happen before emitting debug information since that can end
1813  // arbitrary sections.
1814  if (auto *TS = OutStreamer->getTargetStreamer())
1815  TS->emitConstantPools();
1816 
1817  // Finalize debug and EH information.
1818  for (const HandlerInfo &HI : Handlers) {
1819  NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
1820  HI.TimerGroupDescription, TimePassesIsEnabled);
1821  HI.Handler->endModule();
1822  }
1823 
1824  // This deletes all the ephemeral handlers that AsmPrinter added, while
1825  // keeping all the user-added handlers alive until the AsmPrinter is
1826  // destroyed.
1827  Handlers.erase(Handlers.begin() + NumUserHandlers, Handlers.end());
1828  DD = nullptr;
1829 
1830  // If the target wants to know about weak references, print them all.
1831  if (MAI->getWeakRefDirective()) {
1832  // FIXME: This is not lazy, it would be nice to only print weak references
1833  // to stuff that is actually used. Note that doing so would require targets
1834  // to notice uses in operands (due to constant exprs etc). This should
1835  // happen with the MC stuff eventually.
1836 
1837  // Print out module-level global objects here.
1838  for (const auto &GO : M.global_objects()) {
1839  if (!GO.hasExternalWeakLinkage())
1840  continue;
1841  OutStreamer->emitSymbolAttribute(getSymbol(&GO), MCSA_WeakReference);
1842  }
1843  }
1844 
1845  // Print aliases in topological order, that is, for each alias a = b,
1846  // b must be printed before a.
1847  // This is because on some targets (e.g. PowerPC) linker expects aliases in
1848  // such an order to generate correct TOC information.
1851  for (const auto &Alias : M.aliases()) {
1852  for (const GlobalAlias *Cur = &Alias; Cur;
1853  Cur = dyn_cast<GlobalAlias>(Cur->getAliasee())) {
1854  if (!AliasVisited.insert(Cur).second)
1855  break;
1856  AliasStack.push_back(Cur);
1857  }
1858  for (const GlobalAlias *AncestorAlias : llvm::reverse(AliasStack))
1859  emitGlobalIndirectSymbol(M, *AncestorAlias);
1860  AliasStack.clear();
1861  }
1862  for (const auto &IFunc : M.ifuncs())
1863  emitGlobalIndirectSymbol(M, IFunc);
1864 
1865  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
1866  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
1867  for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
1868  if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I))
1869  MP->finishAssembly(M, *MI, *this);
1870 
1871  // Emit llvm.ident metadata in an '.ident' directive.
1872  emitModuleIdents(M);
1873 
1874  // Emit bytes for llvm.commandline metadata.
1875  emitModuleCommandLines(M);
1876 
1877  // Emit __morestack address if needed for indirect calls.
1878  if (MMI->usesMorestackAddr()) {
1879  Align Alignment(1);
1880  MCSection *ReadOnlySection = getObjFileLowering().getSectionForConstant(
1882  /*C=*/nullptr, Alignment);
1883  OutStreamer->SwitchSection(ReadOnlySection);
1884 
1885  MCSymbol *AddrSymbol =
1886  OutContext.getOrCreateSymbol(StringRef("__morestack_addr"));
1887  OutStreamer->emitLabel(AddrSymbol);
1888 
1889  unsigned PtrSize = MAI->getCodePointerSize();
1890  OutStreamer->emitSymbolValue(GetExternalSymbolSymbol("__morestack"),
1891  PtrSize);
1892  }
1893 
1894  // Emit .note.GNU-split-stack and .note.GNU-no-split-stack sections if
1895  // split-stack is used.
1897  OutStreamer->SwitchSection(
1898  OutContext.getELFSection(".note.GNU-split-stack", ELF::SHT_PROGBITS, 0));
1899  if (MMI->hasNosplitStack())
1900  OutStreamer->SwitchSection(
1901  OutContext.getELFSection(".note.GNU-no-split-stack", ELF::SHT_PROGBITS, 0));
1902  }
1903 
1904  // If we don't have any trampolines, then we don't require stack memory
1905  // to be executable. Some targets have a directive to declare this.
1906  Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
1907  if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
1909  OutStreamer->SwitchSection(S);
1910 
1911  if (TM.Options.EmitAddrsig) {
1912  // Emit address-significance attributes for all globals.
1913  OutStreamer->emitAddrsig();
1914  for (const GlobalValue &GV : M.global_values()) {
1915  if (!GV.use_empty() && !GV.isTransitiveUsedByMetadataOnly() &&
1916  !GV.isThreadLocal() && !GV.hasDLLImportStorageClass() &&
1917  !GV.getName().startswith("llvm.") && !GV.hasAtLeastLocalUnnamedAddr())
1918  OutStreamer->emitAddrsigSym(getSymbol(&GV));
1919  }
1920  }
1921 
1922  // Emit symbol partition specifications (ELF only).
1924  unsigned UniqueID = 0;
1925  for (const GlobalValue &GV : M.global_values()) {
1926  if (!GV.hasPartition() || GV.isDeclarationForLinker() ||
1927  GV.getVisibility() != GlobalValue::DefaultVisibility)
1928  continue;
1929 
1930  OutStreamer->SwitchSection(
1931  OutContext.getELFSection(".llvm_sympart", ELF::SHT_LLVM_SYMPART, 0, 0,
1932  "", false, ++UniqueID, nullptr));
1933  OutStreamer->emitBytes(GV.getPartition());
1934  OutStreamer->emitZeros(1);
1935  OutStreamer->emitValue(
1937  MAI->getCodePointerSize());
1938  }
1939  }
1940 
1941  // Allow the target to emit any magic that it wants at the end of the file,
1942  // after everything else has gone out.
1944 
1945  MMI = nullptr;
1946 
1947  OutStreamer->Finish();
1948  OutStreamer->reset();
1949  OwnedMLI.reset();
1950  OwnedMDT.reset();
1951 
1952  return false;
1953 }
1954 
1956  auto Res = MBBSectionExceptionSyms.try_emplace(MBB.getSectionIDNum());
1957  if (Res.second)
1958  Res.first->second = createTempSymbol("exception");
1959  return Res.first->second;
1960 }
1961 
1963  this->MF = &MF;
1964  const Function &F = MF.getFunction();
1965 
1966  // Get the function symbol.
1967  if (!MAI->needsFunctionDescriptors()) {
1969  } else {
1971  "Only AIX uses the function descriptor hooks.");
1972  // AIX is unique here in that the name of the symbol emitted for the
1973  // function body does not have the same name as the source function's
1974  // C-linkage name.
1975  assert(CurrentFnDescSym && "The function descriptor symbol needs to be"
1976  " initalized first.");
1977 
1978  // Get the function entry point symbol.
1980  }
1981 
1983  CurrentFnBegin = nullptr;
1984  CurrentSectionBeginSym = nullptr;
1985  MBBSectionRanges.clear();
1986  MBBSectionExceptionSyms.clear();
1987  bool NeedsLocalForSize = MAI->needsLocalForSize();
1988  if (F.hasFnAttribute("patchable-function-entry") ||
1989  F.hasFnAttribute("function-instrument") ||
1990  F.hasFnAttribute("xray-instruction-threshold") ||
1991  needFuncLabelsForEHOrDebugInfo(MF) || NeedsLocalForSize ||
1993  CurrentFnBegin = createTempSymbol("func_begin");
1994  if (NeedsLocalForSize)
1996  }
1997 
1998  ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
1999 }
2000 
2001 namespace {
2002 
2003 // Keep track the alignment, constpool entries per Section.
2004  struct SectionCPs {
2005  MCSection *S;
2006  Align Alignment;
2008 
2009  SectionCPs(MCSection *s, Align a) : S(s), Alignment(a) {}
2010  };
2011 
2012 } // end anonymous namespace
2013 
2014 /// EmitConstantPool - Print to the current output stream assembly
2015 /// representations of the constants in the constant pool MCP. This is
2016 /// used to print out constants which have been "spilled to memory" by
2017 /// the code generator.
2019  const MachineConstantPool *MCP = MF->getConstantPool();
2020  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
2021  if (CP.empty()) return;
2022 
2023  // Calculate sections for constant pool entries. We collect entries to go into
2024  // the same section together to reduce amount of section switch statements.
2025  SmallVector<SectionCPs, 4> CPSections;
2026  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
2027  const MachineConstantPoolEntry &CPE = CP[i];
2028  Align Alignment = CPE.getAlign();
2029 
2030  SectionKind Kind = CPE.getSectionKind(&getDataLayout());
2031 
2032  const Constant *C = nullptr;
2033  if (!CPE.isMachineConstantPoolEntry())
2034  C = CPE.Val.ConstVal;
2035 
2037  getDataLayout(), Kind, C, Alignment);
2038 
2039  // The number of sections are small, just do a linear search from the
2040  // last section to the first.
2041  bool Found = false;
2042  unsigned SecIdx = CPSections.size();
2043  while (SecIdx != 0) {
2044  if (CPSections[--SecIdx].S == S) {
2045  Found = true;
2046  break;
2047  }
2048  }
2049  if (!Found) {
2050  SecIdx = CPSections.size();
2051  CPSections.push_back(SectionCPs(S, Alignment));
2052  }
2053 
2054  if (Alignment > CPSections[SecIdx].Alignment)
2055  CPSections[SecIdx].Alignment = Alignment;
2056  CPSections[SecIdx].CPEs.push_back(i);
2057  }
2058 
2059  // Now print stuff into the calculated sections.
2060  const MCSection *CurSection = nullptr;
2061  unsigned Offset = 0;
2062  for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
2063  for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
2064  unsigned CPI = CPSections[i].CPEs[j];
2065  MCSymbol *Sym = GetCPISymbol(CPI);
2066  if (!Sym->isUndefined())
2067  continue;
2068 
2069  if (CurSection != CPSections[i].S) {
2070  OutStreamer->SwitchSection(CPSections[i].S);
2071  emitAlignment(Align(CPSections[i].Alignment));
2072  CurSection = CPSections[i].S;
2073  Offset = 0;
2074  }
2075 
2076  MachineConstantPoolEntry CPE = CP[CPI];
2077 
2078  // Emit inter-object padding for alignment.
2079  unsigned NewOffset = alignTo(Offset, CPE.getAlign());
2080  OutStreamer->emitZeros(NewOffset - Offset);
2081 
2082  Offset = NewOffset + CPE.getSizeInBytes(getDataLayout());
2083 
2084  OutStreamer->emitLabel(Sym);
2085  if (CPE.isMachineConstantPoolEntry())
2087  else
2089  }
2090  }
2091 }
2092 
2093 // Print assembly representations of the jump tables used by the current
2094 // function.
2096  const DataLayout &DL = MF->getDataLayout();
2097  const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
2098  if (!MJTI) return;
2099  if (MJTI->getEntryKind() == MachineJumpTableInfo::EK_Inline) return;
2100  const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
2101  if (JT.empty()) return;
2102 
2103  // Pick the directive to use to print the jump table entries, and switch to
2104  // the appropriate section.
2105  const Function &F = MF->getFunction();
2107  bool JTInDiffSection = !TLOF.shouldPutJumpTableInFunctionSection(
2109  F);
2110  if (JTInDiffSection) {
2111  // Drop it in the readonly section.
2112  MCSection *ReadOnlySection = TLOF.getSectionForJumpTable(F, TM);
2113  OutStreamer->SwitchSection(ReadOnlySection);
2114  }
2115 
2117 
2118  // Jump tables in code sections are marked with a data_region directive
2119  // where that's supported.
2120  if (!JTInDiffSection)
2121  OutStreamer->emitDataRegion(MCDR_DataRegionJT32);
2122 
2123  for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {
2124  const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
2125 
2126  // If this jump table was deleted, ignore it.
2127  if (JTBBs.empty()) continue;
2128 
2129  // For the EK_LabelDifference32 entry, if using .set avoids a relocation,
2130  /// emit a .set directive for each unique entry.
2134  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
2136  for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
2137  const MachineBasicBlock *MBB = JTBBs[ii];
2138  if (!EmittedSets.insert(MBB).second)
2139  continue;
2140 
2141  // .set LJTSet, LBB32-base
2142  const MCExpr *LHS =
2144  OutStreamer->emitAssignment(GetJTSetSymbol(JTI, MBB->getNumber()),
2146  OutContext));
2147  }
2148  }
2149 
2150  // On some targets (e.g. Darwin) we want to emit two consecutive labels
2151  // before each jump table. The first label is never referenced, but tells
2152  // the assembler and linker the extents of the jump table object. The
2153  // second label is actually referenced by the code.
2154  if (JTInDiffSection && DL.hasLinkerPrivateGlobalPrefix())
2155  // FIXME: This doesn't have to have any specific name, just any randomly
2156  // named and numbered local label started with 'l' would work. Simplify
2157  // GetJTISymbol.
2158  OutStreamer->emitLabel(GetJTISymbol(JTI, true));
2159 
2160  MCSymbol* JTISymbol = GetJTISymbol(JTI);
2161  OutStreamer->emitLabel(JTISymbol);
2162 
2163  for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
2164  emitJumpTableEntry(MJTI, JTBBs[ii], JTI);
2165  }
2166  if (!JTInDiffSection)
2167  OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
2168 }
2169 
2170 /// EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
2171 /// current stream.
2172 void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
2173  const MachineBasicBlock *MBB,
2174  unsigned UID) const {
2175  assert(MBB && MBB->getNumber() >= 0 && "Invalid basic block");
2176  const MCExpr *Value = nullptr;
2177  switch (MJTI->getEntryKind()) {
2179  llvm_unreachable("Cannot emit EK_Inline jump table entry");
2182  MJTI, MBB, UID, OutContext);
2183  break;
2185  // EK_BlockAddress - Each entry is a plain address of block, e.g.:
2186  // .word LBB123
2188  break;
2190  // EK_GPRel32BlockAddress - Each entry is an address of block, encoded
2191  // with a relocation as gp-relative, e.g.:
2192  // .gprel32 LBB123
2193  MCSymbol *MBBSym = MBB->getSymbol();
2194  OutStreamer->emitGPRel32Value(MCSymbolRefExpr::create(MBBSym, OutContext));
2195  return;
2196  }
2197 
2199  // EK_GPRel64BlockAddress - Each entry is an address of block, encoded
2200  // with a relocation as gp-relative, e.g.:
2201  // .gpdword LBB123
2202  MCSymbol *MBBSym = MBB->getSymbol();
2203  OutStreamer->emitGPRel64Value(MCSymbolRefExpr::create(MBBSym, OutContext));
2204  return;
2205  }
2206 
2208  // Each entry is the address of the block minus the address of the jump
2209  // table. This is used for PIC jump tables where gprel32 is not supported.
2210  // e.g.:
2211  // .word LBB123 - LJTI1_2
2212  // If the .set directive avoids relocations, this is emitted as:
2213  // .set L4_5_set_123, LBB123 - LJTI1_2
2214  // .word L4_5_set_123
2217  OutContext);
2218  break;
2219  }
2221  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
2222  const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr(MF, UID, OutContext);
2224  break;
2225  }
2226  }
2227 
2228  assert(Value && "Unknown entry kind!");
2229 
2230  unsigned EntrySize = MJTI->getEntrySize(getDataLayout());
2231  OutStreamer->emitValue(Value, EntrySize);
2232 }
2233 
2234 /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
2235 /// special global used by LLVM. If so, emit it and return true, otherwise
2236 /// do nothing and return false.
2238  if (GV->getName() == "llvm.used") {
2239  if (MAI->hasNoDeadStrip()) // No need to emit this at all.
2240  emitLLVMUsedList(cast<ConstantArray>(GV->getInitializer()));
2241  return true;
2242  }
2243 
2244  // Ignore debug and non-emitted data. This handles llvm.compiler.used.
2245  if (GV->getSection() == "llvm.metadata" ||
2247  return true;
2248 
2249  if (!GV->hasAppendingLinkage()) return false;
2250 
2251  assert(GV->hasInitializer() && "Not a special LLVM global!");
2252 
2253  if (GV->getName() == "llvm.global_ctors") {
2255  /* isCtor */ true);
2256 
2257  return true;
2258  }
2259 
2260  if (GV->getName() == "llvm.global_dtors") {
2262  /* isCtor */ false);
2263 
2264  return true;
2265  }
2266 
2267  report_fatal_error("unknown special variable");
2268 }
2269 
2270 /// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
2271 /// global in the specified llvm.used list.
2272 void AsmPrinter::emitLLVMUsedList(const ConstantArray *InitList) {
2273  // Should be an array of 'i8*'.
2274  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
2275  const GlobalValue *GV =
2276  dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
2277  if (GV)
2278  OutStreamer->emitSymbolAttribute(getSymbol(GV), MCSA_NoDeadStrip);
2279  }
2280 }
2281 
2283  const Constant *List,
2284  SmallVector<Structor, 8> &Structors) {
2285  // Should be an array of '{ i32, void ()*, i8* }' structs. The first value is
2286  // the init priority.
2287  if (!isa<ConstantArray>(List))
2288  return;
2289 
2290  // Gather the structors in a form that's convenient for sorting by priority.
2291  for (Value *O : cast<ConstantArray>(List)->operands()) {
2292  auto *CS = cast<ConstantStruct>(O);
2293  if (CS->getOperand(1)->isNullValue())
2294  break; // Found a null terminator, skip the rest.
2295  ConstantInt *Priority = dyn_cast<ConstantInt>(CS->getOperand(0));
2296  if (!Priority)
2297  continue; // Malformed.
2298  Structors.push_back(Structor());
2299  Structor &S = Structors.back();
2300  S.Priority = Priority->getLimitedValue(65535);
2301  S.Func = CS->getOperand(1);
2302  if (!CS->getOperand(2)->isNullValue()) {
2303  if (TM.getTargetTriple().isOSAIX())
2305  "associated data of XXStructor list is not yet supported on AIX");
2306  S.ComdatKey =
2307  dyn_cast<GlobalValue>(CS->getOperand(2)->stripPointerCasts());
2308  }
2309  }
2310 
2311  // Emit the function pointers in the target-specific order
2312  llvm::stable_sort(Structors, [](const Structor &L, const Structor &R) {
2313  return L.Priority < R.Priority;
2314  });
2315 }
2316 
2317 /// EmitXXStructorList - Emit the ctor or dtor list taking into account the init
2318 /// priority.
2320  bool IsCtor) {
2321  SmallVector<Structor, 8> Structors;
2322  preprocessXXStructorList(DL, List, Structors);
2323  if (Structors.empty())
2324  return;
2325 
2326  // Emit the structors in reverse order if we are using the .ctor/.dtor
2327  // initialization scheme.
2328  if (!TM.Options.UseInitArray)
2329  std::reverse(Structors.begin(), Structors.end());
2330 
2331  const Align Align = DL.getPointerPrefAlignment();
2332  for (Structor &S : Structors) {
2334  const MCSymbol *KeySym = nullptr;
2335  if (GlobalValue *GV = S.ComdatKey) {
2336  if (GV->isDeclarationForLinker())
2337  // If the associated variable is not defined in this module
2338  // (it might be available_externally, or have been an
2339  // available_externally definition that was dropped by the
2340  // EliminateAvailableExternally pass), some other TU
2341  // will provide its dynamic initializer.
2342  continue;
2343 
2344  KeySym = getSymbol(GV);
2345  }
2346 
2347  MCSection *OutputSection =
2348  (IsCtor ? Obj.getStaticCtorSection(S.Priority, KeySym)
2349  : Obj.getStaticDtorSection(S.Priority, KeySym));
2350  OutStreamer->SwitchSection(OutputSection);
2351  if (OutStreamer->getCurrentSection() != OutStreamer->getPreviousSection())
2353  emitXXStructor(DL, S.Func);
2354  }
2355 }
2356 
2357 void AsmPrinter::emitModuleIdents(Module &M) {
2358  if (!MAI->hasIdentDirective())
2359  return;
2360 
2361  if (const NamedMDNode *NMD = M.getNamedMetadata("llvm.ident")) {
2362  for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
2363  const MDNode *N = NMD->getOperand(i);
2364  assert(N->getNumOperands() == 1 &&
2365  "llvm.ident metadata entry can have only one operand");
2366  const MDString *S = cast<MDString>(N->getOperand(0));
2367  OutStreamer->emitIdent(S->getString());
2368  }
2369  }
2370 }
2371 
2372 void AsmPrinter::emitModuleCommandLines(Module &M) {
2374  if (!CommandLine)
2375  return;
2376 
2377  const NamedMDNode *NMD = M.getNamedMetadata("llvm.commandline");
2378  if (!NMD || !NMD->getNumOperands())
2379  return;
2380 
2381  OutStreamer->PushSection();
2382  OutStreamer->SwitchSection(CommandLine);
2383  OutStreamer->emitZeros(1);
2384  for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
2385  const MDNode *N = NMD->getOperand(i);
2386  assert(N->getNumOperands() == 1 &&
2387  "llvm.commandline metadata entry can have only one operand");
2388  const MDString *S = cast<MDString>(N->getOperand(0));
2389  OutStreamer->emitBytes(S->getString());
2390  OutStreamer->emitZeros(1);
2391  }
2392  OutStreamer->PopSection();
2393 }
2394 
2395 //===--------------------------------------------------------------------===//
2396 // Emission and print routines
2397 //
2398 
2399 /// Emit a byte directive and value.
2400 ///
2401 void AsmPrinter::emitInt8(int Value) const { OutStreamer->emitInt8(Value); }
2402 
2403 /// Emit a short directive and value.
2404 void AsmPrinter::emitInt16(int Value) const { OutStreamer->emitInt16(Value); }
2405 
2406 /// Emit a long directive and value.
2407 void AsmPrinter::emitInt32(int Value) const { OutStreamer->emitInt32(Value); }
2408 
2409 /// Emit a long long directive and value.
2411  OutStreamer->emitInt64(Value);
2412 }
2413 
2414 /// Emit something like ".long Hi-Lo" where the size in bytes of the directive
2415 /// is specified by Size and Hi/Lo specify the labels. This implicitly uses
2416 /// .set if it avoids relocations.
2418  unsigned Size) const {
2419  OutStreamer->emitAbsoluteSymbolDiff(Hi, Lo, Size);
2420 }
2421 
2422 /// EmitLabelPlusOffset - Emit something like ".long Label+Offset"
2423 /// where the size in bytes of the directive is specified by Size and Label
2424 /// specifies the label. This implicitly uses .set if it is available.
2426  unsigned Size,
2427  bool IsSectionRelative) const {
2428  if (MAI->needsDwarfSectionOffsetDirective() && IsSectionRelative) {
2429  OutStreamer->EmitCOFFSecRel32(Label, Offset);
2430  if (Size > 4)
2431  OutStreamer->emitZeros(Size - 4);
2432  return;
2433  }
2434 
2435  // Emit Label+Offset (or just Label if Offset is zero)
2436  const MCExpr *Expr = MCSymbolRefExpr::create(Label, OutContext);
2437  if (Offset)
2438  Expr = MCBinaryExpr::createAdd(
2440 
2441  OutStreamer->emitValue(Expr, Size);
2442 }
2443 
2444 //===----------------------------------------------------------------------===//
2445 
2446 // EmitAlignment - Emit an alignment directive to the specified power of
2447 // two boundary. If a global value is specified, and if that global has
2448 // an explicit alignment requested, it will override the alignment request
2449 // if required for correctness.
2450 void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV) const {
2451  if (GV)
2452  Alignment = getGVAlignment(GV, GV->getParent()->getDataLayout(), Alignment);
2453 
2454  if (Alignment == Align(1))
2455  return; // 1-byte aligned: no need to emit alignment.
2456 
2457  if (getCurrentSection()->getKind().isText()) {
2458  const MCSubtargetInfo *STI = nullptr;
2459  if (this->MF)
2460  STI = &getSubtargetInfo();
2461  else
2462  STI = TM.getMCSubtargetInfo();
2463  OutStreamer->emitCodeAlignment(Alignment.value(), STI);
2464  } else
2465  OutStreamer->emitValueToAlignment(Alignment.value());
2466 }
2467 
2468 //===----------------------------------------------------------------------===//
2469 // Constant emission.
2470 //===----------------------------------------------------------------------===//
2471 
2473  MCContext &Ctx = OutContext;
2474 
2475  if (CV->isNullValue() || isa<UndefValue>(CV))
2476  return MCConstantExpr::create(0, Ctx);
2477 
2478  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
2479  return MCConstantExpr::create(CI->getZExtValue(), Ctx);
2480 
2481  if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
2482  return MCSymbolRefExpr::create(getSymbol(GV), Ctx);
2483 
2484  if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV))
2486 
2487  if (const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV))
2489 
2490  const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
2491  if (!CE) {
2492  llvm_unreachable("Unknown constant value to lower!");
2493  }
2494 
2495  switch (CE->getOpcode()) {
2496  case Instruction::AddrSpaceCast: {
2497  const Constant *Op = CE->getOperand(0);
2498  unsigned DstAS = CE->getType()->getPointerAddressSpace();
2499  unsigned SrcAS = Op->getType()->getPointerAddressSpace();
2500  if (TM.isNoopAddrSpaceCast(SrcAS, DstAS))
2501  return lowerConstant(Op);
2502 
2503  // Fallthrough to error.
2505  }
2506  default: {
2507  // If the code isn't optimized, there may be outstanding folding
2508  // opportunities. Attempt to fold the expression using DataLayout as a
2509  // last resort before giving up.
2511  if (C != CE)
2512  return lowerConstant(C);
2513 
2514  // Otherwise report the problem to the user.
2515  std::string S;
2516  raw_string_ostream OS(S);
2517  OS << "Unsupported expression in static initializer: ";
2518  CE->printAsOperand(OS, /*PrintType=*/false,
2519  !MF ? nullptr : MF->getFunction().getParent());
2520  report_fatal_error(OS.str());
2521  }
2522  case Instruction::GetElementPtr: {
2523  // Generate a symbolic expression for the byte address
2524  APInt OffsetAI(getDataLayout().getPointerTypeSizeInBits(CE->getType()), 0);
2525  cast<GEPOperator>(CE)->accumulateConstantOffset(getDataLayout(), OffsetAI);
2526 
2527  const MCExpr *Base = lowerConstant(CE->getOperand(0));
2528  if (!OffsetAI)
2529  return Base;
2530 
2531  int64_t Offset = OffsetAI.getSExtValue();
2533  Ctx);
2534  }
2535 
2536  case Instruction::Trunc:
2537  // We emit the value and depend on the assembler to truncate the generated
2538  // expression properly. This is important for differences between
2539  // blockaddress labels. Since the two labels are in the same function, it
2540  // is reasonable to treat their delta as a 32-bit value.
2542  case Instruction::BitCast:
2543  return lowerConstant(CE->getOperand(0));
2544 
2545  case Instruction::IntToPtr: {
2546  const DataLayout &DL = getDataLayout();
2547 
2548  // Handle casts to pointers by changing them into casts to the appropriate
2549  // integer type. This promotes constant folding and simplifies this code.
2550  Constant *Op = CE->getOperand(0);
2551  Op = ConstantExpr::getIntegerCast(Op, DL.getIntPtrType(CV->getType()),
2552  false/*ZExt*/);
2553  return lowerConstant(Op);
2554  }
2555 
2556  case Instruction::PtrToInt: {
2557  const DataLayout &DL = getDataLayout();
2558 
2559  // Support only foldable casts to/from pointers that can be eliminated by
2560  // changing the pointer to the appropriately sized integer type.
2561  Constant *Op = CE->getOperand(0);
2562  Type *Ty = CE->getType();
2563 
2564  const MCExpr *OpExpr = lowerConstant(Op);
2565 
2566  // We can emit the pointer value into this slot if the slot is an
2567  // integer slot equal to the size of the pointer.
2568  //
2569  // If the pointer is larger than the resultant integer, then
2570  // as with Trunc just depend on the assembler to truncate it.
2571  if (DL.getTypeAllocSize(Ty).getFixedSize() <=
2572  DL.getTypeAllocSize(Op->getType()).getFixedSize())
2573  return OpExpr;
2574 
2575  // Otherwise the pointer is smaller than the resultant integer, mask off
2576  // the high bits so we are sure to get a proper truncation if the input is
2577  // a constant expr.
2578  unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType());
2579  const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx);
2580  return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx);
2581  }
2582 
2583  case Instruction::Sub: {
2584  GlobalValue *LHSGV;
2585  APInt LHSOffset;
2586  DSOLocalEquivalent *DSOEquiv;
2587  if (IsConstantOffsetFromGlobal(CE->getOperand(0), LHSGV, LHSOffset,
2588  getDataLayout(), &DSOEquiv)) {
2589  GlobalValue *RHSGV;
2590  APInt RHSOffset;
2591  if (IsConstantOffsetFromGlobal(CE->getOperand(1), RHSGV, RHSOffset,
2592  getDataLayout())) {
2593  const MCExpr *RelocExpr =
2594  getObjFileLowering().lowerRelativeReference(LHSGV, RHSGV, TM);
2595  if (!RelocExpr) {
2596  const MCExpr *LHSExpr =
2597  MCSymbolRefExpr::create(getSymbol(LHSGV), Ctx);
2598  if (DSOEquiv &&
2599  getObjFileLowering().supportDSOLocalEquivalentLowering())
2600  LHSExpr =
2602  RelocExpr = MCBinaryExpr::createSub(
2603  LHSExpr, MCSymbolRefExpr::create(getSymbol(RHSGV), Ctx), Ctx);
2604  }
2605  int64_t Addend = (LHSOffset - RHSOffset).getSExtValue();
2606  if (Addend != 0)
2607  RelocExpr = MCBinaryExpr::createAdd(
2608  RelocExpr, MCConstantExpr::create(Addend, Ctx), Ctx);
2609  return RelocExpr;
2610  }
2611  }
2612  }
2613  // else fallthrough
2615 
2616  // The MC library also has a right-shift operator, but it isn't consistently
2617  // signed or unsigned between different targets.
2618  case Instruction::Add:
2619  case Instruction::Mul:
2620  case Instruction::SDiv:
2621  case Instruction::SRem:
2622  case Instruction::Shl:
2623  case Instruction::And:
2624  case Instruction::Or:
2625  case Instruction::Xor: {
2626  const MCExpr *LHS = lowerConstant(CE->getOperand(0));
2627  const MCExpr *RHS = lowerConstant(CE->getOperand(1));
2628  switch (CE->getOpcode()) {
2629  default: llvm_unreachable("Unknown binary operator constant cast expr");
2630  case Instruction::Add: return MCBinaryExpr::createAdd(LHS, RHS, Ctx);
2631  case Instruction::Sub: return MCBinaryExpr::createSub(LHS, RHS, Ctx);
2632  case Instruction::Mul: return MCBinaryExpr::createMul(LHS, RHS, Ctx);
2633  case Instruction::SDiv: return MCBinaryExpr::createDiv(LHS, RHS, Ctx);
2634  case Instruction::SRem: return MCBinaryExpr::createMod(LHS, RHS, Ctx);
2635  case Instruction::Shl: return MCBinaryExpr::createShl(LHS, RHS, Ctx);
2636  case Instruction::And: return MCBinaryExpr::createAnd(LHS, RHS, Ctx);
2637  case Instruction::Or: return MCBinaryExpr::createOr (LHS, RHS, Ctx);
2638  case Instruction::Xor: return MCBinaryExpr::createXor(LHS, RHS, Ctx);
2639  }
2640  }
2641  }
2642 }
2643 
2644 static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
2645  AsmPrinter &AP,
2646  const Constant *BaseCV = nullptr,
2647  uint64_t Offset = 0);
2648 
2649 static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP);
2650 static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP);
2651 
2652 /// isRepeatedByteSequence - Determine whether the given value is
2653 /// composed of a repeated sequence of identical bytes and return the
2654 /// byte value. If it is not a repeated sequence, return -1.
2657  assert(!Data.empty() && "Empty aggregates should be CAZ node");
2658  char C = Data[0];
2659  for (unsigned i = 1, e = Data.size(); i != e; ++i)
2660  if (Data[i] != C) return -1;
2661  return static_cast<uint8_t>(C); // Ensure 255 is not returned as -1.
2662 }
2663 
2664 /// isRepeatedByteSequence - Determine whether the given value is
2665 /// composed of a repeated sequence of identical bytes and return the
2666 /// byte value. If it is not a repeated sequence, return -1.
2667 static int isRepeatedByteSequence(const Value *V, const DataLayout &DL) {
2668  if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
2669  uint64_t Size = DL.getTypeAllocSizeInBits(V->getType());
2670  assert(Size % 8 == 0);
2671 
2672  // Extend the element to take zero padding into account.
2673  APInt Value = CI->getValue().zextOrSelf(Size);
2674  if (!Value.isSplat(8))
2675  return -1;
2676 
2677  return Value.zextOrTrunc(8).getZExtValue();
2678  }
2679  if (const ConstantArray *CA = dyn_cast<ConstantArray>(V)) {
2680  // Make sure all array elements are sequences of the same repeated
2681  // byte.
2682  assert(CA->getNumOperands() != 0 && "Should be a CAZ");
2683  Constant *Op0 = CA->getOperand(0);
2684  int Byte = isRepeatedByteSequence(Op0, DL);
2685  if (Byte == -1)
2686  return -1;
2687 
2688  // All array elements must be equal.
2689  for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i)
2690  if (CA->getOperand(i) != Op0)
2691  return -1;
2692  return Byte;
2693  }
2694 
2695  if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(V))
2696  return isRepeatedByteSequence(CDS);
2697 
2698  return -1;
2699 }
2700 
2702  const ConstantDataSequential *CDS,
2703  AsmPrinter &AP) {
2704  // See if we can aggregate this into a .fill, if so, emit it as such.
2705  int Value = isRepeatedByteSequence(CDS, DL);
2706  if (Value != -1) {
2707  uint64_t Bytes = DL.getTypeAllocSize(CDS->getType());
2708  // Don't emit a 1-byte object as a .fill.
2709  if (Bytes > 1)
2710  return AP.OutStreamer->emitFill(Bytes, Value);
2711  }
2712 
2713  // If this can be emitted with .ascii/.asciz, emit it as such.
2714  if (CDS->isString())
2715  return AP.OutStreamer->emitBytes(CDS->getAsString());
2716 
2717  // Otherwise, emit the values in successive locations.
2718  unsigned ElementByteSize = CDS->getElementByteSize();
2719  if (isa<IntegerType>(CDS->getElementType())) {
2720  for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
2721  if (AP.isVerbose())
2722  AP.OutStreamer->GetCommentOS() << format("0x%" PRIx64 "\n",
2723  CDS->getElementAsInteger(i));
2724  AP.OutStreamer->emitIntValue(CDS->getElementAsInteger(i),
2725  ElementByteSize);
2726  }
2727  } else {
2728  Type *ET = CDS->getElementType();
2729  for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I)
2731  }
2732 
2733  unsigned Size = DL.getTypeAllocSize(CDS->getType());
2734  unsigned EmittedSize =
2735  DL.getTypeAllocSize(CDS->getElementType()) * CDS->getNumElements();
2736  assert(EmittedSize <= Size && "Size cannot be less than EmittedSize!");
2737  if (unsigned Padding = Size - EmittedSize)
2738  AP.OutStreamer->emitZeros(Padding);
2739 }
2740 
2742  const ConstantArray *CA, AsmPrinter &AP,
2743  const Constant *BaseCV, uint64_t Offset) {
2744  // See if we can aggregate some values. Make sure it can be
2745  // represented as a series of bytes of the constant value.
2746  int Value = isRepeatedByteSequence(CA, DL);
2747 
2748  if (Value != -1) {
2749  uint64_t Bytes = DL.getTypeAllocSize(CA->getType());
2750  AP.OutStreamer->emitFill(Bytes, Value);
2751  }
2752  else {
2753  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) {
2754  emitGlobalConstantImpl(DL, CA->getOperand(i), AP, BaseCV, Offset);
2755  Offset += DL.getTypeAllocSize(CA->getOperand(i)->getType());
2756  }
2757  }
2758 }
2759 
2761  const ConstantVector *CV, AsmPrinter &AP) {
2762  for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
2764 
2765  unsigned Size = DL.getTypeAllocSize(CV->getType());
2766  unsigned EmittedSize = DL.getTypeAllocSize(CV->getType()->getElementType()) *
2767  CV->getType()->getNumElements();
2768  if (unsigned Padding = Size - EmittedSize)
2769  AP.OutStreamer->emitZeros(Padding);
2770 }
2771 
2773  const ConstantStruct *CS, AsmPrinter &AP,
2774  const Constant *BaseCV, uint64_t Offset) {
2775  // Print the fields in successive locations. Pad to align if needed!
2776  unsigned Size = DL.getTypeAllocSize(CS->getType());
2777  const StructLayout *Layout = DL.getStructLayout(CS->getType());
2778  uint64_t SizeSoFar = 0;
2779  for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
2780  const Constant *Field = CS->getOperand(i);
2781 
2782  // Print the actual field value.
2783  emitGlobalConstantImpl(DL, Field, AP, BaseCV, Offset + SizeSoFar);
2784 
2785  // Check if padding is needed and insert one or more 0s.
2786  uint64_t FieldSize = DL.getTypeAllocSize(Field->getType());
2787  uint64_t PadSize = ((i == e-1 ? Size : Layout->getElementOffset(i+1))
2788  - Layout->getElementOffset(i)) - FieldSize;
2789  SizeSoFar += FieldSize + PadSize;
2790 
2791  // Insert padding - this may include padding to increase the size of the
2792  // current field up to the ABI size (if the struct is not packed) as well
2793  // as padding to ensure that the next field starts at the right offset.
2794  AP.OutStreamer->emitZeros(PadSize);
2795  }
2796  assert(SizeSoFar == Layout->getSizeInBytes() &&
2797  "Layout of constant struct may be incorrect!");
2798 }
2799 
2800 static void emitGlobalConstantFP(APFloat APF, Type *ET, AsmPrinter &AP) {
2801  assert(ET && "Unknown float type");
2802  APInt API = APF.bitcastToAPInt();
2803 
2804  // First print a comment with what we think the original floating-point value
2805  // should have been.
2806  if (AP.isVerbose()) {
2808  APF.toString(StrVal);
2809  ET->print(AP.OutStreamer->GetCommentOS());
2810  AP.OutStreamer->GetCommentOS() << ' ' << StrVal << '\n';
2811  }
2812 
2813  // Now iterate through the APInt chunks, emitting them in endian-correct
2814  // order, possibly with a smaller chunk at beginning/end (e.g. for x87 80-bit
2815  // floats).
2816  unsigned NumBytes = API.getBitWidth() / 8;
2817  unsigned TrailingBytes = NumBytes % sizeof(uint64_t);
2818  const uint64_t *p = API.getRawData();
2819 
2820  // PPC's long double has odd notions of endianness compared to how LLVM
2821  // handles it: p[0] goes first for *big* endian on PPC.
2822  if (AP.getDataLayout().isBigEndian() && !ET->isPPC_FP128Ty()) {
2823  int Chunk = API.getNumWords() - 1;
2824 
2825  if (TrailingBytes)
2826  AP.OutStreamer->emitIntValueInHexWithPadding(p[Chunk--], TrailingBytes);
2827 
2828  for (; Chunk >= 0; --Chunk)
2829  AP.OutStreamer->emitIntValueInHexWithPadding(p[Chunk], sizeof(uint64_t));
2830  } else {
2831  unsigned Chunk;
2832  for (Chunk = 0; Chunk < NumBytes / sizeof(uint64_t); ++Chunk)
2833  AP.OutStreamer->emitIntValueInHexWithPadding(p[Chunk], sizeof(uint64_t));
2834 
2835  if (TrailingBytes)
2836  AP.OutStreamer->emitIntValueInHexWithPadding(p[Chunk], TrailingBytes);
2837  }
2838 
2839  // Emit the tail padding for the long double.
2840  const DataLayout &DL = AP.getDataLayout();
2841  AP.OutStreamer->emitZeros(DL.getTypeAllocSize(ET) - DL.getTypeStoreSize(ET));
2842 }
2843 
2844 static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP) {
2845  emitGlobalConstantFP(CFP->getValueAPF(), CFP->getType(), AP);
2846 }
2847 
2849  const DataLayout &DL = AP.getDataLayout();
2850  unsigned BitWidth = CI->getBitWidth();
2851 
2852  // Copy the value as we may massage the layout for constants whose bit width
2853  // is not a multiple of 64-bits.
2854  APInt Realigned(CI->getValue());
2855  uint64_t ExtraBits = 0;
2856  unsigned ExtraBitsSize = BitWidth & 63;
2857 
2858  if (ExtraBitsSize) {
2859  // The bit width of the data is not a multiple of 64-bits.
2860  // The extra bits are expected to be at the end of the chunk of the memory.
2861  // Little endian:
2862  // * Nothing to be done, just record the extra bits to emit.
2863  // Big endian:
2864  // * Record the extra bits to emit.
2865  // * Realign the raw data to emit the chunks of 64-bits.
2866  if (DL.isBigEndian()) {
2867  // Basically the structure of the raw data is a chunk of 64-bits cells:
2868  // 0 1 BitWidth / 64
2869  // [chunk1][chunk2] ... [chunkN].
2870  // The most significant chunk is chunkN and it should be emitted first.
2871  // However, due to the alignment issue chunkN contains useless bits.
2872  // Realign the chunks so that they contain only useful information:
2873  // ExtraBits 0 1 (BitWidth / 64) - 1
2874  // chu[nk1 chu][nk2 chu] ... [nkN-1 chunkN]
2875  ExtraBitsSize = alignTo(ExtraBitsSize, 8);
2876  ExtraBits = Realigned.getRawData()[0] &
2877  (((uint64_t)-1) >> (64 - ExtraBitsSize));
2878  Realigned.lshrInPlace(ExtraBitsSize);
2879  } else
2880  ExtraBits = Realigned.getRawData()[BitWidth / 64];
2881  }
2882 
2883  // We don't expect assemblers to support integer data directives
2884  // for more than 64 bits, so we emit the data in at most 64-bit
2885  // quantities at a time.
2886  const uint64_t *RawData = Realigned.getRawData();
2887  for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
2888  uint64_t Val = DL.isBigEndian() ? RawData[e - i - 1] : RawData[i];
2889  AP.OutStreamer->emitIntValue(Val, 8);
2890  }
2891 
2892  if (ExtraBitsSize) {
2893  // Emit the extra bits after the 64-bits chunks.
2894 
2895  // Emit a directive that fills the expected size.
2897  Size -= (BitWidth / 64) * 8;
2898  assert(Size && Size * 8 >= ExtraBitsSize &&
2899  (ExtraBits & (((uint64_t)-1) >> (64 - ExtraBitsSize)))
2900  == ExtraBits && "Directive too small for extra bits.");
2901  AP.OutStreamer->emitIntValue(ExtraBits, Size);
2902  }
2903 }
2904 
2905 /// Transform a not absolute MCExpr containing a reference to a GOT
2906 /// equivalent global, by a target specific GOT pc relative access to the
2907 /// final symbol.
2908 static void handleIndirectSymViaGOTPCRel(AsmPrinter &AP, const MCExpr **ME,
2909  const Constant *BaseCst,
2910  uint64_t Offset) {
2911  // The global @foo below illustrates a global that uses a got equivalent.
2912  //
2913  // @bar = global i32 42
2914  // @gotequiv = private unnamed_addr constant i32* @bar
2915  // @foo = i32 trunc (i64 sub (i64 ptrtoint (i32** @gotequiv to i64),
2916  // i64 ptrtoint (i32* @foo to i64))
2917  // to i32)
2918  //
2919  // The cstexpr in @foo is converted into the MCExpr `ME`, where we actually
2920  // check whether @foo is suitable to use a GOTPCREL. `ME` is usually in the
2921  // form:
2922  //
2923  // foo = cstexpr, where
2924  // cstexpr := <gotequiv> - "." + <cst>
2925  // cstexpr := <gotequiv> - (<foo> - <offset from @foo base>) + <cst>
2926  //
2927  // After canonicalization by evaluateAsRelocatable `ME` turns into:
2928  //
2929  // cstexpr := <gotequiv> - <foo> + gotpcrelcst, where
2930  // gotpcrelcst := <offset from @foo base> + <cst>
2931  MCValue MV;
2932  if (!(*ME)->evaluateAsRelocatable(MV, nullptr, nullptr) || MV.isAbsolute())
2933  return;
2934  const MCSymbolRefExpr *SymA = MV.getSymA();
2935  if (!SymA)
2936  return;
2937 
2938  // Check that GOT equivalent symbol is cached.
2939  const MCSymbol *GOTEquivSym = &SymA->getSymbol();
2940  if (!AP.GlobalGOTEquivs.count(GOTEquivSym))
2941  return;
2942 
2943  const GlobalValue *BaseGV = dyn_cast_or_null<GlobalValue>(BaseCst);
2944  if (!BaseGV)
2945  return;
2946 
2947  // Check for a valid base symbol
2948  const MCSymbol *BaseSym = AP.getSymbol(BaseGV);
2949  const MCSymbolRefExpr *SymB = MV.getSymB();
2950 
2951  if (!SymB || BaseSym != &SymB->getSymbol())
2952  return;
2953 
2954  // Make sure to match:
2955  //
2956  // gotpcrelcst := <offset from @foo base> + <cst>
2957  //
2958  // If gotpcrelcst is positive it means that we can safely fold the pc rel
2959  // displacement into the GOTPCREL. We can also can have an extra offset <cst>
2960  // if the target knows how to encode it.
2961  int64_t GOTPCRelCst = Offset + MV.getConstant();
2962  if (GOTPCRelCst < 0)
2963  return;
2964  if (!AP.getObjFileLowering().supportGOTPCRelWithOffset() && GOTPCRelCst != 0)
2965  return;
2966 
2967  // Emit the GOT PC relative to replace the got equivalent global, i.e.:
2968  //
2969  // bar:
2970  // .long 42
2971  // gotequiv:
2972  // .quad bar
2973  // foo:
2974  // .long gotequiv - "." + <cst>
2975  //
2976  // is replaced by the target specific equivalent to:
2977  //
2978  // bar:
2979  // .long 42
2980  // foo:
2981  // .long bar@GOTPCREL+<gotpcrelcst>
2982  AsmPrinter::GOTEquivUsePair Result = AP.GlobalGOTEquivs[GOTEquivSym];
2983  const GlobalVariable *GV = Result.first;
2984  int NumUses = (int)Result.second;
2985  const GlobalValue *FinalGV = dyn_cast<GlobalValue>(GV->getOperand(0));
2986  const MCSymbol *FinalSym = AP.getSymbol(FinalGV);
2988  FinalGV, FinalSym, MV, Offset, AP.MMI, *AP.OutStreamer);
2989 
2990  // Update GOT equivalent usage information
2991  --NumUses;
2992  if (NumUses >= 0)
2993  AP.GlobalGOTEquivs[GOTEquivSym] = std::make_pair(GV, NumUses);
2994 }
2995 
2996 static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
2997  AsmPrinter &AP, const Constant *BaseCV,
2998  uint64_t Offset) {
2999  uint64_t Size = DL.getTypeAllocSize(CV->getType());
3000 
3001  // Globals with sub-elements such as combinations of arrays and structs
3002  // are handled recursively by emitGlobalConstantImpl. Keep track of the
3003  // constant symbol base and the current position with BaseCV and Offset.
3004  if (!BaseCV && CV->hasOneUse())
3005  BaseCV = dyn_cast<Constant>(CV->user_back());
3006 
3007  if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(CV))
3008  return AP.OutStreamer->emitZeros(Size);
3009 
3010  if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
3011  const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType());
3012 
3013  if (StoreSize <= 8) {
3014  if (AP.isVerbose())
3015  AP.OutStreamer->GetCommentOS() << format("0x%" PRIx64 "\n",
3016  CI->getZExtValue());
3017  AP.OutStreamer->emitIntValue(CI->getZExtValue(), StoreSize);
3018  } else {
3020  }
3021 
3022  // Emit tail padding if needed
3023  if (Size != StoreSize)
3024  AP.OutStreamer->emitZeros(Size - StoreSize);
3025 
3026  return;
3027  }
3028 
3029  if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
3030  return emitGlobalConstantFP(CFP, AP);
3031 
3032  if (isa<ConstantPointerNull>(CV)) {
3033  AP.OutStreamer->emitIntValue(0, Size);
3034  return;
3035  }
3036 
3037  if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(CV))
3038  return emitGlobalConstantDataSequential(DL, CDS, AP);
3039 
3040  if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
3041  return emitGlobalConstantArray(DL, CVA, AP, BaseCV, Offset);
3042 
3043  if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV))
3044  return emitGlobalConstantStruct(DL, CVS, AP, BaseCV, Offset);
3045 
3046  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
3047  // Look through bitcasts, which might not be able to be MCExpr'ized (e.g. of
3048  // vectors).
3049  if (CE->getOpcode() == Instruction::BitCast)
3050  return emitGlobalConstantImpl(DL, CE->getOperand(0), AP);
3051 
3052  if (Size > 8) {
3053  // If the constant expression's size is greater than 64-bits, then we have
3054  // to emit the value in chunks. Try to constant fold the value and emit it
3055  // that way.
3056  Constant *New = ConstantFoldConstant(CE, DL);
3057  if (New != CE)
3058  return emitGlobalConstantImpl(DL, New, AP);
3059  }
3060  }
3061 
3062  if (const ConstantVector *V = dyn_cast<ConstantVector>(CV))
3063  return emitGlobalConstantVector(DL, V, AP);
3064 
3065  // Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it
3066  // thread the streamer with EmitValue.
3067  const MCExpr *ME = AP.lowerConstant(CV);
3068 
3069  // Since lowerConstant already folded and got rid of all IR pointer and
3070  // integer casts, detect GOT equivalent accesses by looking into the MCExpr
3071  // directly.
3073  handleIndirectSymViaGOTPCRel(AP, &ME, BaseCV, Offset);
3074 
3075  AP.OutStreamer->emitValue(ME, Size);
3076 }
3077 
3078 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
3080  uint64_t Size = DL.getTypeAllocSize(CV->getType());
3081  if (Size)
3082  emitGlobalConstantImpl(DL, CV, *this);
3083  else if (MAI->hasSubsectionsViaSymbols()) {
3084  // If the global has zero size, emit a single byte so that two labels don't
3085  // look like they are at the same location.
3086  OutStreamer->emitIntValue(0, 1);
3087  }
3088 }
3089 
3091  // Target doesn't support this yet!
3092  llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
3093 }
3094 
3095 void AsmPrinter::printOffset(int64_t Offset, raw_ostream &OS) const {
3096  if (Offset > 0)
3097  OS << '+' << Offset;
3098  else if (Offset < 0)
3099  OS << Offset;
3100 }
3101 
3102 void AsmPrinter::emitNops(unsigned N) {
3104  for (; N; --N)
3106 }
3107 
3108 //===----------------------------------------------------------------------===//
3109 // Symbol Lowering Routines.
3110 //===----------------------------------------------------------------------===//
3111 
3113  return OutContext.createTempSymbol(Name, true);
3114 }
3115 
3117  return MMI->getAddrLabelSymbol(BA->getBasicBlock());
3118 }
3119 
3121  return MMI->getAddrLabelSymbol(BB);
3122 }
3123 
3124 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
3125 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
3126  if (getSubtargetInfo().getTargetTriple().isWindowsMSVCEnvironment()) {
3127  const MachineConstantPoolEntry &CPE =
3128  MF->getConstantPool()->getConstants()[CPID];
3129  if (!CPE.isMachineConstantPoolEntry()) {
3130  const DataLayout &DL = MF->getDataLayout();
3131  SectionKind Kind = CPE.getSectionKind(&DL);
3132  const Constant *C = CPE.Val.ConstVal;
3133  Align Alignment = CPE.Alignment;
3134  if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
3135  getObjFileLowering().getSectionForConstant(DL, Kind, C,
3136  Alignment))) {
3137  if (MCSymbol *Sym = S->getCOMDATSymbol()) {
3138  if (Sym->isUndefined())
3139  OutStreamer->emitSymbolAttribute(Sym, MCSA_Global);
3140  return Sym;
3141  }
3142  }
3143  }
3144  }
3145 
3146  const DataLayout &DL = getDataLayout();
3147  return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
3148  "CPI" + Twine(getFunctionNumber()) + "_" +
3149  Twine(CPID));
3150 }
3151 
3152 /// GetJTISymbol - Return the symbol for the specified jump table entry.
3153 MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
3154  return MF->getJTISymbol(JTID, OutContext, isLinkerPrivate);
3155 }
3156 
3157 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
3158 /// FIXME: privatize to AsmPrinter.
3159 MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const {
3160  const DataLayout &DL = getDataLayout();
3161  return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
3162  Twine(getFunctionNumber()) + "_" +
3163  Twine(UID) + "_set_" + Twine(MBBID));
3164 }
3165 
3167  StringRef Suffix) const {
3168  return getObjFileLowering().getSymbolWithGlobalValueBase(GV, Suffix, TM);
3169 }
3170 
3171 /// Return the MCSymbol for the specified ExternalSymbol.
3173  SmallString<60> NameStr;
3174  Mangler::getNameWithPrefix(NameStr, Sym, getDataLayout());
3175  return OutContext.getOrCreateSymbol(NameStr);
3176 }
3177 
3178 /// PrintParentLoopComment - Print comments about parent loops of this one.
3180  unsigned FunctionNumber) {
3181  if (!Loop) return;
3182  PrintParentLoopComment(OS, Loop->getParentLoop(), FunctionNumber);
3183  OS.indent(Loop->getLoopDepth()*2)
3184  << "Parent Loop BB" << FunctionNumber << "_"
3185  << Loop->getHeader()->getNumber()
3186  << " Depth=" << Loop->getLoopDepth() << '\n';
3187 }
3188 
3189 /// PrintChildLoopComment - Print comments about child loops within
3190 /// the loop for this basic block, with nesting.
3192  unsigned FunctionNumber) {
3193  // Add child loop information
3194  for (const MachineLoop *CL : *Loop) {
3195  OS.indent(CL->getLoopDepth()*2)
3196  << "Child Loop BB" << FunctionNumber << "_"
3197  << CL->getHeader()->getNumber() << " Depth " << CL->getLoopDepth()
3198  << '\n';
3199  PrintChildLoopComment(OS, CL, FunctionNumber);
3200  }
3201 }
3202 
3203 /// emitBasicBlockLoopComments - Pretty-print comments for basic blocks.
3205  const MachineLoopInfo *LI,
3206  const AsmPrinter &AP) {
3207  // Add loop depth information
3208  const MachineLoop *Loop = LI->getLoopFor(&MBB);
3209  if (!Loop) return;
3210 
3211  MachineBasicBlock *Header = Loop->getHeader();
3212  assert(Header && "No header for loop");
3213 
3214  // If this block is not a loop header, just print out what is the loop header
3215  // and return.
3216  if (Header != &MBB) {
3217  AP.OutStreamer->AddComment(" in Loop: Header=BB" +
3218  Twine(AP.getFunctionNumber())+"_" +
3219  Twine(Loop->getHeader()->getNumber())+
3220  " Depth="+Twine(Loop->getLoopDepth()));
3221  return;
3222  }
3223 
3224  // Otherwise, it is a loop header. Print out information about child and
3225  // parent loops.
3226  raw_ostream &OS = AP.OutStreamer->GetCommentOS();
3227 
3229 
3230  OS << "=>";
3231  OS.indent(Loop->getLoopDepth()*2-2);
3232 
3233  OS << "This ";
3234  if (Loop->isInnermost())
3235  OS << "Inner ";
3236  OS << "Loop Header: Depth=" + Twine(Loop->getLoopDepth()) << '\n';
3237 
3239 }
3240 
3241 /// emitBasicBlockStart - This method prints the label for the specified
3242 /// MachineBasicBlock, an alignment (if present) and a comment describing
3243 /// it if appropriate.
3245  // End the previous funclet and start a new one.
3246  if (MBB.isEHFuncletEntry()) {
3247  for (const HandlerInfo &HI : Handlers) {
3248  HI.Handler->endFunclet();
3249  HI.Handler->beginFunclet(MBB);
3250  }
3251  }
3252 
3253  // Emit an alignment directive for this block, if needed.
3254  const Align Alignment = MBB.getAlignment();
3255  if (Alignment != Align(1))
3256  emitAlignment(Alignment);
3257 
3258  // Switch to a new section if this basic block must begin a section. The
3259  // entry block is always placed in the function section and is handled
3260  // separately.
3261  if (MBB.isBeginSection() && !MBB.isEntryBlock()) {
3262  OutStreamer->SwitchSection(
3263  getObjFileLowering().getSectionForMachineBasicBlock(MF->getFunction(),
3264  MBB, TM));
3265  CurrentSectionBeginSym = MBB.getSymbol();
3266  }
3267 
3268  // If the block has its address taken, emit any labels that were used to
3269  // reference the block. It is possible that there is more than one label
3270  // here, because multiple LLVM BB's may have been RAUW'd to this block after
3271  // the references were generated.
3272  const BasicBlock *BB = MBB.getBasicBlock();
3273  if (MBB.hasAddressTaken()) {
3274  if (isVerbose())
3275  OutStreamer->AddComment("Block address taken");
3276 
3277  // MBBs can have their address taken as part of CodeGen without having
3278  // their corresponding BB's address taken in IR
3279  if (BB && BB->hasAddressTaken())
3280  for (MCSymbol *Sym : MMI->getAddrLabelSymbolToEmit(BB))
3281  OutStreamer->emitLabel(Sym);
3282  }
3283 
3284  // Print some verbose block comments.
3285  if (isVerbose()) {
3286  if (BB) {
3287  if (BB->hasName()) {
3288  BB->printAsOperand(OutStreamer->GetCommentOS(),
3289  /*PrintType=*/false, BB->getModule());
3290  OutStreamer->GetCommentOS() << '\n';
3291  }
3292  }
3293 
3294  assert(MLI != nullptr && "MachineLoopInfo should has been computed");
3296  }
3297 
3298  // Print the main label for the block.
3299  if (shouldEmitLabelForBasicBlock(MBB)) {
3300  if (isVerbose() && MBB.hasLabelMustBeEmitted())
3301  OutStreamer->AddComment("Label of block must be emitted");
3302  OutStreamer->emitLabel(MBB.getSymbol());
3303  } else {
3304  if (isVerbose()) {
3305  // NOTE: Want this comment at start of line, don't emit with AddComment.
3306  OutStreamer->emitRawComment(" %bb." + Twine(MBB.getNumber()) + ":",
3307  false);
3308  }
3309  }
3310 
3311  if (MBB.isEHCatchretTarget() &&
3313  OutStreamer->emitLabel(MBB.getEHCatchretSymbol());
3314  }
3315 
3316  // With BB sections, each basic block must handle CFI information on its own
3317  // if it begins a section (Entry block is handled separately by
3318  // AsmPrinterHandler::beginFunction).
3319  if (MBB.isBeginSection() && !MBB.isEntryBlock())
3320  for (const HandlerInfo &HI : Handlers)
3321  HI.Handler->beginBasicBlock(MBB);
3322 }
3323 
3325  // Check if CFI information needs to be updated for this MBB with basic block
3326  // sections.
3327  if (MBB.isEndSection())
3328  for (const HandlerInfo &HI : Handlers)
3329  HI.Handler->endBasicBlock(MBB);
3330 }
3331 
3332 void AsmPrinter::emitVisibility(MCSymbol *Sym, unsigned Visibility,
3333  bool IsDefinition) const {
3334  MCSymbolAttr Attr = MCSA_Invalid;
3335 
3336  switch (Visibility) {
3337  default: break;
3339  if (IsDefinition)
3340  Attr = MAI->getHiddenVisibilityAttr();
3341  else
3343  break;
3345  Attr = MAI->getProtectedVisibilityAttr();
3346  break;
3347  }
3348 
3349  if (Attr != MCSA_Invalid)
3350  OutStreamer->emitSymbolAttribute(Sym, Attr);
3351 }
3352 
3353 bool AsmPrinter::shouldEmitLabelForBasicBlock(
3354  const MachineBasicBlock &MBB) const {
3355  // With `-fbasic-block-sections=`, a label is needed for every non-entry block
3356  // in the labels mode (option `=labels`) and every section beginning in the
3357  // sections mode (`=all` and `=list=`).
3358  if ((MF->hasBBLabels() || MBB.isBeginSection()) && !MBB.isEntryBlock())
3359  return true;
3360  // A label is needed for any block with at least one predecessor (when that
3361  // predecessor is not the fallthrough predecessor, or if it is an EH funclet
3362  // entry, or if a label is forced).
3363  return !MBB.pred_empty() &&
3366 }
3367 
3368 /// isBlockOnlyReachableByFallthough - Return true if the basic block has
3369 /// exactly one predecessor and the control transfer mechanism between
3370 /// the predecessor and this block is a fall-through.
3371 bool AsmPrinter::
3373  // If this is a landing pad, it isn't a fall through. If it has no preds,
3374  // then nothing falls through to it.
3375  if (MBB->isEHPad() || MBB->pred_empty())
3376  return false;
3377 
3378  // If there isn't exactly one predecessor, it can't be a fall through.
3379  if (MBB->pred_size() > 1)
3380  return false;
3381 
3382  // The predecessor has to be immediately before this block.
3383  MachineBasicBlock *Pred = *MBB->pred_begin();
3384  if (!Pred->isLayoutSuccessor(MBB))
3385  return false;
3386 
3387  // If the block is completely empty, then it definitely does fall through.
3388  if (Pred->empty())
3389  return true;
3390 
3391  // Check the terminators in the previous blocks
3392  for (const auto &MI : Pred->terminators()) {
3393  // If it is not a simple branch, we are in a table somewhere.
3394  if (!MI.isBranch() || MI.isIndirectBranch())
3395  return false;
3396 
3397  // If we are the operands of one of the branches, this is not a fall
3398  // through. Note that targets with delay slots will usually bundle
3399  // terminators with the delay slot instruction.
3400  for (ConstMIBundleOperands OP(MI); OP.isValid(); ++OP) {
3401  if (OP->isJTI())
3402  return false;
3403  if (OP->isMBB() && OP->getMBB() == MBB)
3404  return false;
3405  }
3406  }
3407 
3408  return true;
3409 }
3410 
3411 GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) {
3412  if (!S.usesMetadata())
3413  return nullptr;
3414 
3415  gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
3416  gcp_map_type::iterator GCPI = GCMap.find(&S);
3417  if (GCPI != GCMap.end())
3418  return GCPI->second.get();
3419 
3420  auto Name = S.getName();
3421 
3422  for (const GCMetadataPrinterRegistry::entry &GCMetaPrinter :
3424  if (Name == GCMetaPrinter.getName()) {
3425  std::unique_ptr<GCMetadataPrinter> GMP = GCMetaPrinter.instantiate();
3426  GMP->S = &S;
3427  auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP)));
3428  return IterBool.first->second.get();
3429  }
3430 
3431  report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name));
3432 }
3433 
3435  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
3436  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
3437  bool NeedsDefault = false;
3438  if (MI->begin() == MI->end())
3439  // No GC strategy, use the default format.
3440  NeedsDefault = true;
3441  else
3442  for (auto &I : *MI) {
3443  if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
3444  if (MP->emitStackMaps(SM, *this))
3445  continue;
3446  // The strategy doesn't have printer or doesn't emit custom stack maps.
3447  // Use the default format.
3448  NeedsDefault = true;
3449  }
3450 
3451  if (NeedsDefault)
3453 }
3454 
3455 /// Pin vtable to this file.
3457 
3459 
3460 // In the binary's "xray_instr_map" section, an array of these function entries
3461 // describes each instrumentation point. When XRay patches your code, the index
3462 // into this table will be given to your handler as a patch point identifier.
3464  auto Kind8 = static_cast<uint8_t>(Kind);
3465  Out->emitBinaryData(StringRef(reinterpret_cast<const char *>(&Kind8), 1));
3466  Out->emitBinaryData(
3467  StringRef(reinterpret_cast<const char *>(&AlwaysInstrument), 1));
3468  Out->emitBinaryData(StringRef(reinterpret_cast<const char *>(&Version), 1));
3469  auto Padding = (4 * Bytes) - ((2 * Bytes) + 3);
3470  assert(Padding >= 0 && "Instrumentation map entry > 4 * Word Size");
3471  Out->emitZeros(Padding);
3472 }
3473 
3475  if (Sleds.empty())
3476  return;
3477 
3478  auto PrevSection = OutStreamer->getCurrentSectionOnly();
3479  const Function &F = MF->getFunction();
3480  MCSection *InstMap = nullptr;
3481  MCSection *FnSledIndex = nullptr;
3482  const Triple &TT = TM.getTargetTriple();
3483  // Use PC-relative addresses on all targets.
3484  if (TT.isOSBinFormatELF()) {
3485  auto LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
3486  auto Flags = ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;
3487  StringRef GroupName;
3488  if (F.hasComdat()) {
3489  Flags |= ELF::SHF_GROUP;
3490  GroupName = F.getComdat()->getName();
3491  }
3492  InstMap = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS,
3493  Flags, 0, GroupName, F.hasComdat(),
3494  MCSection::NonUniqueID, LinkedToSym);
3495 
3497  FnSledIndex = OutContext.getELFSection(
3498  "xray_fn_idx", ELF::SHT_PROGBITS, Flags | ELF::SHF_WRITE, 0,
3499  GroupName, F.hasComdat(), MCSection::NonUniqueID, LinkedToSym);
3500  } else if (MF->getSubtarget().getTargetTriple().isOSBinFormatMachO()) {
3501  InstMap = OutContext.getMachOSection("__DATA", "xray_instr_map", 0,
3504  FnSledIndex = OutContext.getMachOSection(
3505  "__DATA", "xray_fn_idx", 0, SectionKind::getReadOnlyWithRel());
3506  } else {
3507  llvm_unreachable("Unsupported target");
3508  }
3509 
3510  auto WordSizeBytes = MAI->getCodePointerSize();
3511 
3512  // Now we switch to the instrumentation map section. Because this is done
3513  // per-function, we are able to create an index entry that will represent the
3514  // range of sleds associated with a function.
3515  auto &Ctx = OutContext;
3516  MCSymbol *SledsStart = OutContext.createTempSymbol("xray_sleds_start", true);
3517  OutStreamer->SwitchSection(InstMap);
3518  OutStreamer->emitLabel(SledsStart);
3519  for (const auto &Sled : Sleds) {
3520  MCSymbol *Dot = Ctx.createTempSymbol();
3521  OutStreamer->emitLabel(Dot);
3522  OutStreamer->emitValueImpl(
3524  MCSymbolRefExpr::create(Dot, Ctx), Ctx),
3525  WordSizeBytes);
3526  OutStreamer->emitValueImpl(
3530  MCConstantExpr::create(WordSizeBytes, Ctx),
3531  Ctx),
3532  Ctx),
3533  WordSizeBytes);
3534  Sled.emit(WordSizeBytes, OutStreamer.get());
3535  }
3536  MCSymbol *SledsEnd = OutContext.createTempSymbol("xray_sleds_end", true);
3537  OutStreamer->emitLabel(SledsEnd);
3538 
3539  // We then emit a single entry in the index per function. We use the symbols
3540  // that bound the instrumentation map as the range for a specific function.
3541  // Each entry here will be 2 * word size aligned, as we're writing down two
3542  // pointers. This should work for both 32-bit and 64-bit platforms.
3543  if (FnSledIndex) {
3544  OutStreamer->SwitchSection(FnSledIndex);
3545  OutStreamer->emitCodeAlignment(2 * WordSizeBytes, &getSubtargetInfo());
3546  OutStreamer->emitSymbolValue(SledsStart, WordSizeBytes, false);
3547  OutStreamer->emitSymbolValue(SledsEnd, WordSizeBytes, false);
3548  OutStreamer->SwitchSection(PrevSection);
3549  }
3550  Sleds.clear();
3551 }
3552 
3554  SledKind Kind, uint8_t Version) {
3555  const Function &F = MI.getMF()->getFunction();
3556  auto Attr = F.getFnAttribute("function-instrument");
3557  bool LogArgs = F.hasFnAttribute("xray-log-args");
3558  bool AlwaysInstrument =
3559  Attr.isStringAttribute() && Attr.getValueAsString() == "xray-always";
3560  if (Kind == SledKind::FUNCTION_ENTER && LogArgs)
3561  Kind = SledKind::LOG_ARGS_ENTER;
3562  Sleds.emplace_back(XRayFunctionEntry{Sled, CurrentFnSym, Kind,
3563  AlwaysInstrument, &F, Version});
3564 }
3565 
3567  const Function &F = MF->getFunction();
3568  unsigned PatchableFunctionPrefix = 0, PatchableFunctionEntry = 0;
3569  (void)F.getFnAttribute("patchable-function-prefix")
3570  .getValueAsString()
3571  .getAsInteger(10, PatchableFunctionPrefix);
3572  (void)F.getFnAttribute("patchable-function-entry")
3573  .getValueAsString()
3574  .getAsInteger(10, PatchableFunctionEntry);
3575  if (!PatchableFunctionPrefix && !PatchableFunctionEntry)
3576  return;
3577  const unsigned PointerSize = getPointerSize();
3579  auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC;
3580  const MCSymbolELF *LinkedToSym = nullptr;
3581  StringRef GroupName;
3582 
3583  // GNU as < 2.35 did not support section flag 'o'. GNU ld < 2.36 did not
3584  // support mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER sections.
3585  if (MAI->useIntegratedAssembler() || MAI->binutilsIsAtLeast(2, 36)) {
3586  Flags |= ELF::SHF_LINK_ORDER;
3587  if (F.hasComdat()) {
3588  Flags |= ELF::SHF_GROUP;
3589  GroupName = F.getComdat()->getName();
3590  }
3591  LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
3592  }
3593  OutStreamer->SwitchSection(OutContext.getELFSection(
3594  "__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0, GroupName,
3595  F.hasComdat(), MCSection::NonUniqueID, LinkedToSym));
3598  }
3599 }
3600 
3602  return OutStreamer->getContext().getDwarfVersion();
3603 }
3604 
3606  OutStreamer->getContext().setDwarfVersion(Version);
3607 }
3608 
3610  return OutStreamer->getContext().getDwarfFormat() == dwarf::DWARF64;
3611 }
3612 
3615  OutStreamer->getContext().getDwarfFormat());
3616 }
3617 
3620  OutStreamer->getContext().getDwarfFormat());
3621 }
llvm::SectionKind::isCommon
bool isCommon() const
Definition: SectionKind.h:167
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
isGOTEquivalentCandidate
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:1548
i
i
Definition: README.txt:29
llvm::HexagonInstrInfo::isTailCall
bool isTailCall(const MachineInstr &MI) const override
Definition: HexagonInstrInfo.cpp:2611
llvm::MCAsmInfo::hasSingleParameterDotFile
bool hasSingleParameterDotFile() const
Definition: MCAsmInfo.h:735
llvm::TargetOptions::EmitStackSizeSection
unsigned EmitStackSizeSection
Emit section containing metadata on function stack sizes.
Definition: TargetOptions.h:288
llvm::lltok::APFloat
@ APFloat
Definition: LLToken.h:495
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
AsmPrinter.h
llvm::TargetOptions::StackUsageOutput
std::string StackUsageOutput
Name of the stack usage file (i.e., .su file) if user passes -fstack-usage.
Definition: TargetOptions.h:342
llvm::TargetLoweringObjectFile::getStaticDtorSection
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
Definition: TargetLoweringObjectFile.h:179
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition: MachineFrameInfo.h:353
llvm::AsmPrinter::emitLabelDifference
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...
Definition: AsmPrinter.cpp:2417
DWARFGroupName
const char DWARFGroupName[]
Definition: AsmPrinter.cpp:144
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:427
llvm::AsmPrinter::isPositionIndependent
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:215
MachineModuleInfoImpls.h
llvm::AsmPrinter::NumUserHandlers
size_t NumUserHandlers
Definition: AsmPrinter.h:196
llvm::MCBinaryExpr::createDiv
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:534
llvm::AsmPrinter::emitLabelDifferenceAsULEB128
void emitLabelDifferenceAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) const
Emit something like ".uleb128 Hi-Lo".
Definition: AsmPrinterDwarf.cpp:56
llvm::SectionKind::isThreadLocal
bool isThreadLocal() const
Definition: SectionKind.h:151
llvm::MachineOptimizationRemarkEmitter::allowExtraAnalysis
bool allowExtraAnalysis(StringRef PassName) const
Whether we allow for extra compile-time budget to perform more analysis to be more informative.
Definition: MachineOptimizationRemarkEmitter.h:166
llvm::ELF::SHT_LLVM_SYMPART
@ SHT_LLVM_SYMPART
Definition: ELF.h:940
llvm::SectionKind::getReadOnlyWithRel
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:207
llvm::MachineBasicBlock::pred_begin
pred_iterator pred_begin()
Definition: MachineBasicBlock.h:316
MCDwarf.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm::AArch64CC::HI
@ HI
Definition: AArch64BaseInfo.h:263
MachineInstr.h
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:53
MathExtras.h
llvm::AsmPrinter::GlobalGOTEquivs
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
Definition: AsmPrinter.h:141
GlobalIFunc.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
GlobalIndirectSymbol.h
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::ConstantDataSequential::getElementByteSize
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
Definition: Constants.cpp:2915
llvm::AsmPrinter::printOffset
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
Definition: AsmPrinter.cpp:3095
GCMetadata.h
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
Comdat.h
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1396
llvm::MCAsmInfo::doesSetDirectiveSuppressReloc
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:713
llvm::AsmPrinter::CFISection
CFISection
Definition: AsmPrinter.h:161
TargetFrameLowering.h
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition: GlobalValue.h:455
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::MachineLoopInfo::getLoopFor
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the innermost loop that BB lives in.
Definition: MachineLoopInfo.h:127
llvm::AsmPrinter::emitXXStructor
virtual void emitXXStructor(const DataLayout &DL, const Constant *CV)
Targets can override this to change how global constants that are part of a C++ static/global constru...
Definition: AsmPrinter.h:516
llvm::AsmPrinter::emitBasicBlockEnd
virtual void emitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
Definition: AsmPrinter.cpp:3324
FileSystem.h
llvm::remarks::RemarkStreamer
Definition: RemarkStreamer.h:42
llvm::TargetMachine::useEmulatedTLS
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
Definition: TargetMachine.cpp:149
MCTargetOptions.h
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::Value::hasOneUse
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:435
llvm::WebAssembly::Nop
static const unsigned Nop
Instruction opcodes emitted via means other than CodeGen.
Definition: WebAssemblyMCTargetDesc.h:136
llvm::MachineBasicBlock::getBasicBlock
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Definition: MachineBasicBlock.h:202
llvm::MCObjectFileInfo::getCommDirectiveSupportsAlignment
bool getCommDirectiveSupportsAlignment() const
Definition: MCObjectFileInfo.h:247
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:50
PseudoProbePrinter.h
Metadata.h
llvm::NamedMDNode::getNumOperands
unsigned getNumOperands() const
Definition: Metadata.cpp:1120
llvm::AsmPrinter::lowerConstant
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
Definition: AsmPrinter.cpp:2472
llvm::GCStrategy
GCStrategy describes a garbage collector algorithm's code generation requirements,...
Definition: GCStrategy.h:66
llvm::ConstantInt::getType
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:173
llvm::GlobalValue::hasExternalLinkage
bool hasExternalLinkage() const
Definition: GlobalValue.h:434
llvm::AsmPrinter::recordSled
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
Definition: AsmPrinter.cpp:3553
emitGlobalConstantFP
static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP)
Definition: AsmPrinter.cpp:2844
llvm::ConstantInt::getBitWidth
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:136
llvm::MCAsmInfo::useIntegratedAssembler
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:814
DebugInfoMetadata.h
llvm::Triple::isOSBinFormatCOFF
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:637
llvm::AsmPrinter::CurrentFnSymForSize
MCSymbol * CurrentFnSymForSize
The symbol used to represent the start of the current function for the purpose of calculating its siz...
Definition: AsmPrinter.h:128
llvm::ExceptionHandling::SjLj
@ SjLj
setjmp/longjmp based exceptions
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:467
llvm::AsmPrinter::createTempSymbol
MCSymbol * createTempSymbol(const Twine &Name) const
Definition: AsmPrinter.cpp:3112
llvm::GlobalValue::dropLLVMManglingEscape
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:488
llvm::HexagonISD::JT
@ JT
Definition: HexagonISelLowering.h:52
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
T
llvm::APInt::getNumWords
unsigned getNumWords() const
Get the number of words.
Definition: APInt.h:1410
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Function
Definition: Function.h:61
llvm::EHStreamer
Emits exception handling directives.
Definition: EHStreamer.h:30
emitGlobalConstantLargeInt
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP)
Definition: AsmPrinter.cpp:2848
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
Pass.h
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
llvm::SectionKind::isBSS
bool isBSS() const
Definition: SectionKind.h:163
llvm::AsmPrinter::MBBSectionRange
Map a basic block section ID to the begin and end symbols of that section which determine the section...
Definition: AsmPrinter.h:132
llvm::MCSA_ELF_TypeObject
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition: MCDirectives.h:25
llvm::MachineConstantPoolEntry::MachineCPVal
MachineConstantPoolValue * MachineCPVal
Definition: MachineConstantPool.h:72
llvm::SectionKind::isThreadBSS
bool isThreadBSS() const
Definition: SectionKind.h:155
MCDirectives.h
llvm::MCSA_Invalid
@ MCSA_Invalid
Not a valid directive.
Definition: MCDirectives.h:19
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:625
llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
Definition: TargetLoweringObjectFile.cpp:129
llvm::GlobalObject::getSection
StringRef getSection() const
Get the custom section of this global if it has one.
Definition: GlobalObject.h:112
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:88
llvm::MachineBasicBlock::isEHFuncletEntry
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
Definition: MachineBasicBlock.h:552
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::GlobalValue::hasWeakLinkage
bool hasWeakLinkage() const
Definition: GlobalValue.h:445
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:133
MCSectionELF.h
RemarkStringTable.h
llvm::AsmPrinter::emitGlobalConstant
void emitGlobalConstant(const DataLayout &DL, const Constant *CV)
Print a general LLVM constant to the .s file.
Definition: AsmPrinter.cpp:3079
DbgTimerDescription
const char DbgTimerDescription[]
Definition: AsmPrinter.cpp:147
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Statistic.h
Path.h
emitKill
static void emitKill(const MachineInstr *MI, AsmPrinter &AP)
Definition: AsmPrinter.cpp:910
llvm::AsmPrinter::CFISection::Debug
@ Debug
Emit .debug_frame.
llvm::AsmPrinter::emitPatchableFunctionEntries
void emitPatchableFunctionEntries()
Definition: AsmPrinter.cpp:3566
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1467
llvm::DataLayout::getTypeStoreSize
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:470
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1541
llvm::MipsISD::Lo
@ Lo
Definition: MipsISelLowering.h:79
llvm::ConstantDataSequential::getElementAsInteger
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Definition: Constants.cpp:3165
llvm::AsmPrinter::Structor::Priority
int Priority
Definition: AsmPrinter.h:412
ErrorHandling.h
MCSectionCOFF.h
llvm::TargetLoweringObjectFile::SectionForGlobal
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
Definition: TargetLoweringObjectFile.cpp:316
llvm::GlobalIndirectSymbol
Definition: GlobalIndirectSymbol.h:28
llvm::GlobalVariable
Definition: GlobalVariable.h:40
DisableDebugInfoPrinting
static cl::opt< bool > DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden, cl::desc("Disable debug info printing"))
llvm::ISD::EH_LABEL
@ EH_LABEL
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
Definition: ISDOpcodes.h:988
llvm::MachineBasicBlock::isEntryBlock
bool isEntryBlock() const
Returns true if this is the entry block of the function.
Definition: MachineBasicBlock.cpp:290
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::BlockAddress::getBasicBlock
BasicBlock * getBasicBlock() const
Definition: Constants.h:877
llvm::GlobalAlias
Definition: GlobalAlias.h:27
llvm::MCSymbol::isUndefined
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:252
llvm::MCBinaryExpr::createAnd
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:529
llvm::MachineFunction::getFunctionNumber
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
Definition: MachineFunction.h:601
llvm::TargetLoweringObjectFile::lowerRelativeReference
virtual const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const
Definition: TargetLoweringObjectFile.h:188
OptimizationRemarkEmitter.h
llvm::AsmPrinter::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:481
llvm::MachineBasicBlock::getEHCatchretSymbol
MCSymbol * getEHCatchretSymbol() const
Return the EHCatchret Symbol for this basic block.
Definition: MachineBasicBlock.cpp:91
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
MachineBasicBlock.h
COFF.h
llvm::AsmPrinter::doFinalization
bool doFinalization(Module &M) override
Shut down the asmprinter.
Definition: AsmPrinter.cpp:1707
llvm::MachineBasicBlock::isReturnBlock
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
Definition: MachineBasicBlock.h:805
llvm::AsmPrinter::emitStackMaps
void emitStackMaps(StackMaps &SM)
Emit the stack maps.
Definition: AsmPrinter.cpp:3434
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:124
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::MachineModuleInfoImpl::SymbolListTy
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
Definition: MachineModuleInfo.h:63
llvm::MachineModuleInfo::hasDebugInfo
bool hasDebugInfo() const
Returns true if valid debug info is present.
Definition: MachineModuleInfo.h:203
llvm::ConstantInt::getLimitedValue
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:244
llvm::MCAsmInfo::hasAltEntry
bool hasAltEntry() const
Definition: MCAsmInfo.h:739
APInt.h
llvm::WinEH::EncodingType::X86
@ X86
Windows x64, Windows Itanium (IA-64)
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition: MachineConstantPool.h:35
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1580
llvm::DenseMapIterator
Definition: DenseMap.h:56
llvm::WasmException
Definition: WasmException.h:22
llvm::StackOffset::getFixed
ScalarTy getFixed() const
Definition: TypeSize.h:149
MachineJumpTableInfo.h
llvm::DILabel::getName
StringRef getName() const
Definition: DebugInfoMetadata.h:3232
llvm::TargetMachine::getRelocationModel
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
Definition: TargetMachine.cpp:70
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
CodeViewLineTablesGroupDescription
const char CodeViewLineTablesGroupDescription[]
Definition: AsmPrinter.cpp:153
DenseMap.h
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1403
llvm::TimePassesIsEnabled
bool TimePassesIsEnabled
If the user specifies the -time-passes argument on an LLVM tool command line then the value of this b...
Definition: PassTimingInfo.cpp:37
Module.h
llvm::AsmPrinter::getFunctionCFISectionType
CFISection getFunctionCFISectionType(const Function &F) const
Get the CFISection type for a function.
Definition: AsmPrinter.cpp:1054
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:333
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:243
llvm::ilist_node_impl::getReverseIterator
reverse_self_iterator getReverseIterator()
Definition: ilist_node.h:84
TargetInstrInfo.h
llvm::AsmPrinter::getDwarfOffsetByteSize
unsigned int getDwarfOffsetByteSize() const
Returns 4 for DWARF32 and 8 for DWARF64.
Definition: AsmPrinter.cpp:3613
llvm::AsmPrinter::setDwarfVersion
void setDwarfVersion(uint16_t Version)
Definition: AsmPrinter.cpp:3605
isRepeatedByteSequence
static int isRepeatedByteSequence(const ConstantDataSequential *V)
isRepeatedByteSequence - Determine whether the given value is composed of a repeated sequence of iden...
Definition: AsmPrinter.cpp:2655
llvm::TargetLoweringObjectFile::getStaticCtorSection
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
Definition: TargetLoweringObjectFile.h:174
llvm::ARMException
Definition: DwarfException.h:71
EHPersonalities.h
llvm::AsmPrinter::SledKind
SledKind
Definition: AsmPrinter.h:289
llvm::Triple::isOSBinFormatXCOFF
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
Definition: Triple.h:655
llvm::WinEH::EncodingType::Itanium
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
llvm::ConstantFP::getValueAPF
const APFloat & getValueAPF() const
Definition: Constants.h:297
llvm::MachineJumpTableInfo::EK_BlockAddress
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.
Definition: MachineJumpTableInfo.h:49
llvm::MachineModuleInfo::hasNosplitStack
bool hasNosplitStack() const
Definition: MachineModuleInfo.h:226
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::MCAsmInfo::getCodePointerSize
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:536
llvm::CallingConv::Cold
@ Cold
Definition: CallingConv.h:48
llvm::Optional< unsigned >
llvm::TargetInstrInfo::getNop
virtual MCInst getNop() const
Return the noop instruction to use for a noop.
Definition: TargetInstrInfo.cpp:475
llvm::AsmPrinter::Structor
llvm.global_ctors and llvm.global_dtors are arrays of Structor structs.
Definition: AsmPrinter.h:411
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
GlobalObject.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
Operator.h
llvm::VectorType::getElementType
Type * getElementType() const
Definition: DerivedTypes.h:422
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
STLExtras.h
llvm::MachineBasicBlock::back
MachineInstr & back()
Definition: MachineBasicBlock.h:248
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2586
llvm::MachineFunction::getJTISymbol
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
Definition: MachineFunction.cpp:678
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::GCMetadataPrinter
GCMetadataPrinter - Emits GC metadata as assembly code.
Definition: GCMetadataPrinter.h:39
llvm::MachineBasicBlock::terminators
iterator_range< iterator > terminators()
Definition: MachineBasicBlock.h:288
llvm::MCAsmInfo::hasFunctionAlignment
bool hasFunctionAlignment() const
Definition: MCAsmInfo.h:733
llvm::AsmPrinter::ORE
MachineOptimizationRemarkEmitter * ORE
Optimization remark emitter.
Definition: AsmPrinter.h:112
llvm::MCAsmInfo::getWinEHEncodingType
WinEH::EncodingType getWinEHEncodingType() const
Definition: MCAsmInfo.h:763
llvm::Registry::entries
static iterator_range< iterator > entries()
Definition: Registry.h:101
Format.h
llvm::AsmPrinter::CurrentFnDescSym
MCSymbol * CurrentFnDescSym
The symbol for the current function descriptor on AIX.
Definition: AsmPrinter.h:123
llvm::MachineJumpTableInfo::EK_Custom32
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
Definition: MachineJumpTableInfo.h:76
llvm::ConstantDataSequential::isString
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
Definition: Constants.cpp:3258
ConstantFolding.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::StackMaps
Definition: StackMaps.h:251
emitGlobalConstantDataSequential
static void emitGlobalConstantDataSequential(const DataLayout &DL, const ConstantDataSequential *CDS, AsmPrinter &AP)
Definition: AsmPrinter.cpp:2701
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
llvm::ELF::SHF_LINK_ORDER
@ SHF_LINK_ORDER
Definition: ELF.h:1003
llvm::AsmPrinter::emitBBAddrMapSection
void emitBBAddrMapSection(const MachineFunction &MF)
Definition: AsmPrinter.cpp:1136
llvm::AsmPrinter::emitGlobalVariable
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:508
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:52
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:92
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:90
llvm::AsmPrinter::EmitToStreamer
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:243
llvm::MCSymbolAttr
MCSymbolAttr
Definition: MCDirectives.h:18
llvm::MachineFunction::getFrameInstructions
const std::vector< MCCFIInstruction > & getFrameInstructions() const
Returns a reference to a list of cfi instructions in the function's prologue.
Definition: MachineFunction.h:1006
llvm::MCSA_Cold
@ MCSA_Cold
.cold (MachO)
Definition: MCDirectives.h:22
llvm::ISD::ARITH_FENCE
@ ARITH_FENCE
ARITH_FENCE - This corresponds to a arithmetic fence intrinsic.
Definition: ISDOpcodes.h:1105
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::MCContext::getMachOSection
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:420
llvm::MipsISD::Hi
@ Hi
Definition: MipsISelLowering.h:75
llvm::ISD::INLINEASM
@ INLINEASM
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:980
llvm::ExceptionHandling::AIX
@ AIX
AIX Exception Handling.
a
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
Definition: README.txt:489
llvm::MCSA_Local
@ MCSA_Local
.local (ELF)
Definition: MCDirectives.h:37
llvm::ISD::PSEUDO_PROBE
@ PSEUDO_PROBE
Pseudo probe for AutoFDO, as a place holder in a basic block to improve the sample counts quality.
Definition: ISDOpcodes.h:1197
llvm::IsConstantOffsetFromGlobal
bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL, DSOLocalEquivalent **DSOEquiv=nullptr)
If this constant is a constant offset from a global, return the global and the constant.
Definition: ConstantFolding.cpp:303
llvm::MachineBasicBlock::isBeginSection
bool isBeginSection() const
Returns true if this block begins any section.
Definition: MachineBasicBlock.h:564
llvm::MachineJumpTableInfo::getEntrySize
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
Definition: MachineFunction.cpp:1249
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
llvm::MCSymbolELF
Definition: MCSymbolELF.h:14
llvm::TargetLoweringObjectFile
Definition: TargetLoweringObjectFile.h:43
llvm::MachineJumpTableInfo::getEntryKind
JTEntryKind getEntryKind() const
Definition: MachineJumpTableInfo.h:84
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:910
WasmException.h
llvm::MCSA_NoDeadStrip
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Definition: MCDirectives.h:38
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition: EHPersonalities.cpp:21
llvm::ConstantDataSequential::getElementAsAPFloat
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
Definition: Constants.cpp:3213
llvm::AsmPrinter::GOTEquivUsePair
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:140
llvm::SectionKind::getReadOnly
static SectionKind getReadOnly()
Definition: SectionKind.h:185
Instruction.h
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:60
CommandLine.h
llvm::FixedVectorType::getNumElements
unsigned getNumElements() const
Definition: DerivedTypes.h:568
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::MachineBasicBlock::pred_size
unsigned pred_size() const
Definition: MachineBasicBlock.h:328
llvm::TargetLoweringObjectFile::lowerDSOLocalEquivalent
virtual const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const
Definition: TargetLoweringObjectFile.h:200
TargetLowering.h
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::LoopBase::getParentLoop
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
Definition: LoopInfo.h:113
llvm::remarks::RemarkStreamer::getSerializer
remarks::RemarkSerializer & getSerializer()
Return the serializer used for this stream.
Definition: RemarkStreamer.h:61
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:820
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:289
llvm::MCContext::getOrCreateSymbol
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:191
llvm::GCModuleInfo::iterator
SmallVector< std::unique_ptr< GCStrategy >, 1 >::const_iterator iterator
Definition: GCMetadata.h:181
llvm::MCAsmInfo::hasFourStringsDotFile
bool hasFourStringsDotFile() const
Definition: MCAsmInfo.h:736
llvm::Triple::isOSBinFormatELF
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:632
llvm::TargetLoweringObjectFile::getSectionForCommandLines
virtual MCSection * getSectionForCommandLines() const
If supported, return the section to use for the llvm.commandline metadata.
Definition: TargetLoweringObjectFile.h:234
llvm::MachineFunction::setSection
void setSection(MCSection *S)
Indicates the Section this function belongs to.
Definition: MachineFunction.h:584
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
GlobalValue.h
llvm::MCObjectFileInfo::getDataSection
MCSection * getDataSection() const
Definition: MCObjectFileInfo.h:259
MachineLoopInfo.h
ELF.h
llvm::ConstantDataSequential
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Definition: Constants.h:569
TargetMachine.h
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:228
llvm::TargetMachine::getProgramPointerSize
unsigned getProgramPointerSize() const
Definition: TargetMachine.h:193
llvm::APInt::lshrInPlace
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
Definition: APInt.h:815
llvm::AsmPrinter::emitLinkage
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
Definition: AsmPrinter.cpp:441
llvm::GlobalValue::VisibilityTypes
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:62
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::GlobalValue::hasAppendingLinkage
bool hasAppendingLinkage() const
Definition: GlobalValue.h:448
Constants.h
llvm::MCObjectFileInfo::getTLSExtraDataSection
MCSection * getTLSExtraDataSection() const
Definition: MCObjectFileInfo.h:341
llvm::Constant::isNullValue
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:74
llvm::DILocalScope::getNonLexicalBlockFileScope
DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
Definition: DebugInfoMetadata.cpp:820
llvm::AsmPrinter::XRayFunctionEntry::Version
uint8_t Version
Definition: AsmPrinter.h:308
SmallString.h
llvm::DILocalVariable
Local variable.
Definition: DebugInfoMetadata.h:3097
emitGlobalConstantStruct
static void emitGlobalConstantStruct(const DataLayout &DL, const ConstantStruct *CS, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
Definition: AsmPrinter.cpp:2772
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::ExceptionHandling
ExceptionHandling
Definition: MCTargetOptions.h:18
llvm::TargetOptions::UseInitArray
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Definition: TargetOptions.h:240
llvm::MCBinaryExpr::createMul
static const MCBinaryExpr * createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:579
EHTimerDescription
const char EHTimerDescription[]
Definition: AsmPrinter.cpp:149
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::TargetOptions::ForceDwarfFrameSection
unsigned ForceDwarfFrameSection
Emit DWARF debug frame section.
Definition: TargetOptions.h:330
llvm::MCSA_AltEntry
@ MCSA_AltEntry
.alt_entry (MachO)
Definition: MCDirectives.h:40
Twine.h
canBeHidden
static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI)
Definition: AsmPrinter.cpp:434
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::GlobalObject
Definition: GlobalObject.h:28
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3189
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:107
MCSymbolELF.h
MCContext.h
llvm::Type::print
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
Definition: AsmWriter.cpp:4562
llvm::MachineOperand::MO_FrameIndex
@ MO_FrameIndex
Abstract Stack Frame Index.
Definition: MachineOperand.h:57
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:321
MCSectionMachO.h
llvm::Registry::entry
SimpleRegistryEntry< T > entry
Definition: Registry.h:47
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::AsmPrinter::SetupMachineFunction
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
Definition: AsmPrinter.cpp:1962
llvm::AsmPrinter::emitFunctionEntryLabel
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
Definition: AsmPrinter.cpp:843
MCSymbol.h
gcp_map_type
DenseMap< GCStrategy *, std::unique_ptr< GCMetadataPrinter > > gcp_map_type
Definition: AsmPrinter.cpp:163
llvm::MCValue::isAbsolute
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:50
llvm::GlobalValue::hasPrivateLinkage
bool hasPrivateLinkage() const
Definition: GlobalValue.h:450
llvm::MachineFunction::hasBBLabels
bool hasBBLabels() const
Returns true if basic block labels are to be generated for this function.
Definition: MachineFunction.h:611
llvm::AsmPrinter::emitStartOfAsmFile
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:475
CFGuardDescription
const char CFGuardDescription[]
Definition: AsmPrinter.cpp:151
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
llvm::PseudoProbeDescMetadataName
constexpr const char * PseudoProbeDescMetadataName
Definition: PseudoProbe.h:26
emitDebugValueComment
static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP)
emitDebugValueComment - This method handles the target-independent form of DBG_VALUE,...
Definition: AsmPrinter.cpp:927
MCInst.h
llvm::AsmPrinter::isBlockOnlyReachableByFallthrough
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
Definition: AsmPrinter.cpp:3372
Remark.h
llvm::TargetOptions::MCOptions
MCTargetOptions MCOptions
Machine level options.
Definition: TargetOptions.h:414
TargetOpcodes.h
llvm::AsmPrinterHandler::markFunctionEnd
virtual void markFunctionEnd()
Definition: AsmPrinter.cpp:3458
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::WinEH::EncodingType::Invalid
@ Invalid
llvm::MachineFunction::size
unsigned size() const
Definition: MachineFunction.h:818
llvm::MachineConstantPoolEntry::getSectionKind
SectionKind getSectionKind(const DataLayout *DL) const
Definition: MachineFunction.cpp:1380
llvm::Mangler::getNameWithPrefix
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:114
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MCSA_ELF_TypeIndFunction
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
llvm::MachineConstantPoolEntry::getAlign
Align getAlign() const
Definition: MachineConstantPool.h:95
MCSubtargetInfo.h
llvm::MachineFunction::rbegin
reverse_iterator rbegin()
Definition: MachineFunction.h:813
llvm::ConstantArray
ConstantArray - Constant Array Declarations.
Definition: Constants.h:409
llvm::WinException
Definition: WinException.h:26
llvm::MachineConstantPoolEntry::Val
union llvm::MachineConstantPoolEntry::@180 Val
The constant itself.
llvm::APFloat::convertToDouble
double convertToDouble() const
Converts this APFloat to host double value.
Definition: APFloat.cpp:4902
llvm::Triple::isOSBinFormatMachO
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:645
llvm::MCObjectFileInfo::getStackSizesSection
MCSection * getStackSizesSection(const MCSection &TextSec) const
Definition: MCObjectFileInfo.cpp:1053
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::MCAsmInfo::needsDwarfSectionOffsetDirective
bool needsDwarfSectionOffsetDirective() const
Definition: MCAsmInfo.h:611
llvm::AsmPrinter::emitInstruction
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
Definition: AsmPrinter.h:499
MachineInstrBundle.h
llvm::AsmPrinter::MLI
MachineLoopInfo * MLI
This is a pointer to the current MachineLoopInfo.
Definition: AsmPrinter.h:109
llvm::MCAsmInfo::useAssignmentForEHBegin
bool useAssignmentForEHBegin() const
Definition: MCAsmInfo.h:652
llvm::isNoOpWithoutInvoke
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
Definition: EHPersonalities.h:96
llvm::AsmPrinter::CurrentFnSym
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:119
llvm::MachineOptimizationRemarkAnalysis
Diagnostic information for optimization analysis remarks.
Definition: MachineOptimizationRemarkEmitter.h:108
llvm::AsmPrinter::emitAlignment
void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr) const
Emit an alignment directive to the specified power of two boundary.
Definition: AsmPrinter.cpp:2450
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::ExceptionHandling::Wasm
@ Wasm
WebAssembly Exception Handling.
llvm::MachineBasicBlock::isEHCatchretTarget
bool isEHCatchretTarget() const
Returns true if this is a target block of a catchret.
Definition: MachineBasicBlock.h:546
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::AsmPrinter::emitEndOfAsmFile
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:479
DWARFGroupDescription
const char DWARFGroupDescription[]
Definition: AsmPrinter.cpp:145
llvm::Function::hasPersonalityFn
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:785
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:398
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition: MachineFrameInfo.h:553
llvm::MemoryLocation::UnknownSize
@ UnknownSize
Definition: MemoryLocation.h:214
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
SmallPtrSet.h
llvm::AsmPrinter::XRayFunctionEntry::AlwaysInstrument
bool AlwaysInstrument
Definition: AsmPrinter.h:306
llvm::AsmPrinter::emitFunctionBodyStart
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:483
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:206
DwarfDebug.h
llvm::remarks::RemarkStreamer::needsSection
bool needsSection() const
Check if the remarks also need to have associated metadata in a section.
Definition: RemarkStreamer.cpp:49
llvm::GlobalValue::hasGlobalUnnamedAddr
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:196
llvm::AsmPrinter::CurrentPatchableFunctionEntrySym
MCSymbol * CurrentPatchableFunctionEntrySym
The symbol for the entry in __patchable_function_entires.
Definition: AsmPrinter.h:115
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::ConstantStruct::getType
StructType * getType() const
Specialization - reduce amount of casting.
Definition: Constants.h:480
llvm::APFloat::bitcastToAPInt
APInt bitcastToAPInt() const
Definition: APFloat.h:1132
llvm::AsmPrinter::emitInt8
void emitInt8(int Value) const
Emit a byte directive and value.
Definition: AsmPrinter.cpp:2401
llvm::MCAsmInfo::doesUseCFIForDebug
bool doesUseCFIForDebug() const
Definition: MCAsmInfo.h:769
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::MCAsmInfo::hasNoDeadStrip
bool hasNoDeadStrip() const
Definition: MCAsmInfo.h:738
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Triple::isOSAIX
bool isOSAIX() const
Tests whether the OS is AIX.
Definition: Triple.h:627
llvm::Type::isFunctionTy
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:219
MCSectionXCOFF.h
llvm::TargetLoweringObjectFile::getSectionForJumpTable
virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
Definition: TargetLoweringObjectFile.cpp:350
llvm::MachineModuleInfo::setDebugInfoAvailability
void setDebugInfoAvailability(bool avail)
Definition: MachineModuleInfo.h:204
llvm::TargetLoweringObjectFile::getKindForGlobal
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Definition: TargetLoweringObjectFile.cpp:202
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:345
llvm::AsmPrinter::getFunctionBegin
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:247
llvm::AsmPrinter::emitBasicBlockStart
virtual void emitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
Definition: AsmPrinter.cpp:3244
llvm::MCCFIInstruction
Definition: MCDwarf.h:434
llvm::remarks::RemarkSerializer
This is the base class for a remark serializer.
Definition: RemarkSerializer.h:38
llvm::MCAsmInfo::getProtectedVisibilityAttr
MCSymbolAttr getProtectedVisibilityAttr() const
Definition: MCAsmInfo.h:756
Type.h
RemarkFormat.h
llvm::AsmPrinter::getPointerSize
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:234
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::TargetLoweringObjectFile::getFunctionEntryPointSymbol
virtual MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const
If supported, return the function entry point symbol.
Definition: TargetLoweringObjectFile.h:272
llvm::MCBinaryExpr::createShl
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:594
llvm::AsmPrinter::XRayFunctionEntry::Kind
SledKind Kind
Definition: AsmPrinter.h:305
llvm::SmallString< 128 >
llvm::MachineJumpTableInfo::EK_LabelDifference32
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
Definition: MachineJumpTableInfo.h:68
llvm::TargetMachine::isPositionIndependent
bool isPositionIndependent() const
Definition: TargetMachine.cpp:44
llvm::MCAsmInfo::hasWeakDefCanBeHiddenDirective
bool hasWeakDefCanBeHiddenDirective() const
Definition: MCAsmInfo.h:744
llvm::MCStreamer::emitBinaryData
virtual void emitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
Definition: MCStreamer.cpp:1190
llvm::MachineBasicBlock::getSectionIDNum
unsigned getSectionIDNum() const
Returns the unique section ID number of this basic block.
Definition: MachineBasicBlock.h:577
MachineOptimizationRemarkEmitter.h
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
llvm::MCDR_DataRegionJT32
@ MCDR_DataRegionJT32
.data_region jt32
Definition: MCDirectives.h:62
llvm::MachineModuleInfoCOFF
MachineModuleInfoCOFF - This is a MachineModuleInfoImpl implementation for COFF targets.
Definition: MachineModuleInfoImpls.h:85
llvm::DILocalVariable::getScope
DILocalScope * getScope() const
Get the local scope for this variable.
Definition: DebugInfoMetadata.h:3153
llvm::Value::user_back
User * user_back()
Definition: Value.h:408
llvm::AsmPrinter::Handlers
std::vector< HandlerInfo > Handlers
A vector of all debug/EH info emitters we should use.
Definition: AsmPrinter.h:195
EHTimerName
const char EHTimerName[]
Definition: AsmPrinter.cpp:148
llvm::AsmPrinter::CFISection::None
@ None
Do not emit either .eh_frame or .debug_frame.
llvm::AsmPrinter::AsmPrinter
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: AsmPrinter.cpp:197
llvm::MachineFunction::getMMI
MachineModuleInfo & getMMI() const
Definition: MachineFunction.h:577
handleIndirectSymViaGOTPCRel
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,...
Definition: AsmPrinter.cpp:2908
llvm::ConstantArray::getType
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Definition: Constants.h:428
llvm::TargetLowering::getPICJumpTableRelocBaseExpr
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,...
Definition: TargetLowering.cpp:463
llvm::AsmPrinter::emitMachineConstantPoolValue
virtual void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
Definition: AsmPrinter.cpp:3090
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::MCSA_WeakDefAutoPrivate
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:47
llvm::PseudoProbeHandler
Definition: PseudoProbePrinter.h:26
llvm::AsmPrinter::emitFrameAlloc
void emitFrameAlloc(const MachineInstr &MI)
Definition: AsmPrinter.cpp:1109
llvm::DataLayout::isBigEndian
bool isBigEndian() const
Definition: DataLayout.h:243
llvm::AsmPrinter::GetJTSetSymbol
MCSymbol * GetJTSetSymbol(unsigned UID, unsigned MBBID) const
Return the symbol for the specified jump table .set FIXME: privatize to AsmPrinter.
Definition: AsmPrinter.cpp:3159
Timer.h
BasicBlock.h
llvm::ConstantDataSequential::getRawDataValues
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
Definition: Constants.cpp:2888
llvm::cl::opt< bool >
llvm::GlobalObject::hasSection
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:104
llvm::APFloat
Definition: APFloat.h:701
llvm::GlobalValue::hasAvailableExternallyLinkage
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:435
llvm::remarks::RemarkStreamer::getFilename
Optional< StringRef > getFilename() const
Return the filename that the remark diagnostics are emitted to.
Definition: RemarkStreamer.h:55
llvm::AsmPrinterHandler::~AsmPrinterHandler
virtual ~AsmPrinterHandler()
Pin vtable to this file.
needFuncLabelsForEHOrDebugInfo
static bool needFuncLabelsForEHOrDebugInfo(const MachineFunction &MF)
Definition: AsmPrinter.cpp:1227
llvm::ConstantVector::getType
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Definition: Constants.h:516
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
llvm::AsmPrinter::emitInt64
void emitInt64(uint64_t Value) const
Emit a long long directive and value.
Definition: AsmPrinter.cpp:2410
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::MachineJumpTableInfo::getJumpTables
const std::vector< MachineJumpTableEntry > & getJumpTables() const
Definition: MachineJumpTableInfo.h:99
llvm::MachineLoop
Definition: MachineLoopInfo.h:45
llvm::Module::getName
StringRef getName() const
Get a short "name" for the module.
Definition: Module.h:244
llvm::GlobalValue::canBenefitFromLocalAlias
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:105
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:136
llvm::MachineJumpTableInfo::EK_GPRel64BlockAddress
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
Definition: MachineJumpTableInfo.h:54
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
emitComments
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS)
emitComments - Pretty-print comments for instructions.
Definition: AsmPrinter.cpp:862
llvm::TargetMachine::isNoopAddrSpaceCast
virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const
Returns true if a cast between SrcAS and DestAS is a noop.
Definition: TargetMachine.h:307
llvm::MachineDominatorTree::getBase
DomTreeT & getBase()
Definition: MachineDominators.h:87
llvm::TargetLoweringObjectFile::supportGOTPCRelWithOffset
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset?
Definition: TargetLoweringObjectFile.h:213
llvm::MachineOptimizationRemarkEmitter::emit
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Emit an optimization remark.
Definition: MachineOptimizationRemarkEmitter.cpp:49
llvm::AsmPrinter::GetCPISymbol
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
Definition: AsmPrinter.cpp:3125
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::DwarfDebug
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:295
llvm::AsmPrinter::emitLabelPlusOffset
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...
Definition: AsmPrinter.cpp:2425
emitGlobalConstantVector
static void emitGlobalConstantVector(const DataLayout &DL, const ConstantVector *CV, AsmPrinter &AP)
Definition: AsmPrinter.cpp:2760
llvm::StructLayout
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
Definition: DataLayout.h:612
uint64_t
PPTimerName
const char PPTimerName[]
Definition: AsmPrinter.cpp:154
llvm::sys::fs::OF_Text
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
Definition: FileSystem.h:761
llvm::AsmPrinter::needsCFIForDebug
bool needsCFIForDebug() const
Since emitting CFI unwind information is entangled with supporting the exceptions,...
Definition: AsmPrinter.cpp:1078
llvm::APInt::getRawData
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:526
llvm::MachineInstr::ReloadReuse
@ ReloadReuse
Definition: MachineInstr.h:75
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:229
llvm::MachineBasicBlock::hasAddressTaken
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
Definition: MachineBasicBlock.h:211
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:578
llvm::MCBinaryExpr::createOr
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:589
llvm::DwarfCFIException
Definition: DwarfException.h:37
llvm::TargetMachine::getMCSubtargetInfo
const MCSubtargetInfo * getMCSubtargetInfo() const
Definition: TargetMachine.h:211
llvm::TargetLoweringObjectFile::supportIndirectSymViaGOTPCRel
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol,...
Definition: TargetLoweringObjectFile.h:207
s
multiplies can be turned into SHL s
Definition: README.txt:370
llvm::MCSA_WeakReference
@ MCSA_WeakReference
.weak_reference (MachO)
Definition: MCDirectives.h:46
llvm::StackMaps::serializeToStackMapSection
void serializeToStackMapSection()
If there is any stack map data, create a stack map section and serialize the map info into it.
Definition: StackMaps.cpp:708
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
llvm::AsmPrinter::GetBlockAddressSymbol
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
Definition: AsmPrinter.cpp:3116
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::AsmPrinter::getSymbolPreferLocal
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
Definition: AsmPrinter.cpp:490
MemoryLocation.h
llvm::DenseMap
Definition: DenseMap.h:714
MCSymbolXCOFF.h
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:985
llvm::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
llvm::TargetOptions::EmitAddrsig
unsigned EmitAddrsig
Emit address-significance table.
Definition: TargetOptions.h:300
llvm::MCAsmInfo::hasVisibilityOnlyWithLinkage
bool hasVisibilityOnlyWithLinkage() const
Definition: MCAsmInfo.h:621
llvm::GlobalValue::hasComdat
bool hasComdat() const
Definition: GlobalValue.h:222
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MCContext::createLinkerPrivateTempSymbol
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:297
llvm::dwarf::getUnitLengthFieldByteSize
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
Definition: Dwarf.h:671
llvm::AsmPrinter::needsSEHMoves
bool needsSEHMoves()
Definition: AsmPrinter.cpp:1074
MachineConstantPool.h
llvm::ConstantDataSequential::getElementType
Type * getElementType() const
Return the element type of the array/vector.
Definition: Constants.cpp:2882
llvm::MachineModuleInfo::getAddrLabelSymbol
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
Definition: MachineModuleInfo.h:237
PPGroupName
const char PPGroupName[]
Definition: AsmPrinter.cpp:156
llvm::DwarfDebug::emitInitialLocDirective
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID)
Emits inital debug location directive.
Definition: DwarfDebug.cpp:2120
llvm::MachineBasicBlock::getAlignment
Align getAlignment() const
Return alignment of the basic block.
Definition: MachineBasicBlock.h:519
MachineFunctionPass.h
emitGlobalConstantArray
static void emitGlobalConstantArray(const DataLayout &DL, const ConstantArray *CA, AsmPrinter &AP, const Constant *BaseCV, uint64_t Offset)
Definition: AsmPrinter.cpp:2741
llvm::Type::isHalfTy
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:141
llvm::MCSymbol::isVariable
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:293
llvm::GlobalValue::isDiscardableIfUnused
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:372
llvm::AsmPrinter::emitJumpTableInfo
virtual void emitJumpTableInfo()
Print assembly representations of the jump tables used by the current function to the current output ...
Definition: AsmPrinter.cpp:2095
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
llvm::MCSection::NonUniqueID
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
llvm::ConstantVector
Constant Vector Declarations.
Definition: Constants.h:493
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:541
llvm::NamedMDNode::getOperand
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1124
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:120
llvm::MachineFunction::getConstantPool
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
Definition: MachineFunction.h:658
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineBasicBlock::canFallThrough
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
Definition: MachineBasicBlock.cpp:961
llvm::TargetLoweringObjectFile::getIndirectSymViaGOTPCRel
virtual const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Get the target specific PC relative GOT entry relocation.
Definition: TargetLoweringObjectFile.h:223
llvm::MachineConstantPoolEntry::isMachineConstantPoolEntry
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
Definition: MachineConstantPool.h:93
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:486
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::MCSectionCOFF
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::MachineModuleInfo::getAddrLabelSymbolToEmit
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
Definition: MachineModuleInfo.cpp:259
llvm::SectionKind::isThreadData
bool isThreadData() const
Definition: SectionKind.h:156
llvm::TargetOptions::XRayOmitFunctionIndex
unsigned XRayOmitFunctionIndex
Emit XRay Function Index section.
Definition: TargetOptions.h:333
llvm::LoopBase::getLoopDepth