LLVM  10.0.0svn
AsmPrinter.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a class to be used as the base class for target specific
10 // asm writers. This class primarily handles common functionality used by
11 // all asm writers.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_ASMPRINTER_H
16 #define LLVM_CODEGEN_ASMPRINTER_H
17 
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Twine.h"
25 #include "llvm/IR/InlineAsm.h"
26 #include "llvm/IR/LLVMContext.h"
28 #include "llvm/Support/SourceMgr.h"
29 #include <cstdint>
30 #include <memory>
31 #include <utility>
32 #include <vector>
33 
34 namespace llvm {
35 
36 class BasicBlock;
37 class BlockAddress;
38 class Constant;
39 class ConstantArray;
40 class DataLayout;
41 class DIE;
42 class DIEAbbrev;
43 class DwarfDebug;
44 class GCMetadataPrinter;
45 class GCStrategy;
46 class GlobalIndirectSymbol;
47 class GlobalObject;
48 class GlobalValue;
49 class GlobalVariable;
50 class MachineBasicBlock;
51 class MachineConstantPoolValue;
52 class MachineDominatorTree;
53 class MachineFunction;
54 class MachineInstr;
55 class MachineJumpTableInfo;
56 class MachineLoopInfo;
57 class MachineModuleInfo;
58 class MachineOptimizationRemarkEmitter;
59 class MCAsmInfo;
60 class MCCFIInstruction;
61 struct MCCodePaddingContext;
62 class MCContext;
63 class MCExpr;
64 class MCInst;
65 class MCSection;
66 class MCStreamer;
67 class MCSubtargetInfo;
68 class MCSymbol;
69 class MCTargetOptions;
70 class MDNode;
71 class Module;
72 class raw_ostream;
73 class StackMaps;
74 class TargetLoweringObjectFile;
75 class TargetMachine;
76 
77 /// This class is intended to be used as a driving class for all asm writers.
79 public:
80  /// Target machine description.
82 
83  /// Target Asm Printer information.
84  const MCAsmInfo *MAI;
85 
86  /// This is the context for the output file that we are streaming. This owns
87  /// all of the global MC-related objects for the generated translation unit.
89 
90  /// This is the MCStreamer object for the file we are generating. This
91  /// contains the transient state for the current translation unit that we are
92  /// generating (such as the current section etc).
93  std::unique_ptr<MCStreamer> OutStreamer;
94 
95  /// The current machine function.
96  MachineFunction *MF = nullptr;
97 
98  /// This is a pointer to the current MachineModuleInfo.
99  MachineModuleInfo *MMI = nullptr;
100 
101  /// This is a pointer to the current MachineLoopInfo.
103 
104  /// This is a pointer to the current MachineLoopInfo.
105  MachineLoopInfo *MLI = nullptr;
106 
107  /// Optimization remark emitter.
109 
110  /// The symbol for the current function. This is recalculated at the beginning
111  /// of each call to runOnMachineFunction().
112  MCSymbol *CurrentFnSym = nullptr;
113 
114  /// The symbol used to represent the start of the current function for the
115  /// purpose of calculating its size (e.g. using the .size directive). By
116  /// default, this is equal to CurrentFnSym.
118 
119  /// Map global GOT equivalent MCSymbols to GlobalVariables and keep track of
120  /// its number of uses by other globals.
121  using GOTEquivUsePair = std::pair<const GlobalVariable *, unsigned>;
123 
124 private:
125  MCSymbol *CurrentFnBegin = nullptr;
126  MCSymbol *CurrentFnEnd = nullptr;
127  MCSymbol *CurExceptionSym = nullptr;
128 
129  // The garbage collection metadata printer table.
130  void *GCMetadataPrinters = nullptr; // Really a DenseMap.
131 
132  /// Emit comments in assembly output if this is true.
133  bool VerboseAsm;
134 
135  static char ID;
136 
137 protected:
138  /// Protected struct HandlerInfo and Handlers permit target extended
139  /// AsmPrinter adds their own handlers.
140  struct HandlerInfo {
141  std::unique_ptr<AsmPrinterHandler> Handler;
142  const char *TimerName;
143  const char *TimerDescription;
144  const char *TimerGroupName;
146 
147  HandlerInfo(std::unique_ptr<AsmPrinterHandler> Handler,
148  const char *TimerName, const char *TimerDescription,
149  const char *TimerGroupName, const char *TimerGroupDescription)
150  : Handler(std::move(Handler)), TimerName(TimerName),
151  TimerDescription(TimerDescription), TimerGroupName(TimerGroupName),
152  TimerGroupDescription(TimerGroupDescription) {}
153  };
154 
155  /// A vector of all debug/EH info emitters we should use. This vector
156  /// maintains ownership of the emitters.
158 
159 public:
160  struct SrcMgrDiagInfo {
162  std::vector<const MDNode *> LocInfos;
164  void *DiagContext;
165  };
166 
167 private:
168  /// If generated on the fly this own the instance.
169  std::unique_ptr<MachineDominatorTree> OwnedMDT;
170 
171  /// If generated on the fly this own the instance.
172  std::unique_ptr<MachineLoopInfo> OwnedMLI;
173 
174  /// Structure for generating diagnostics for inline assembly. Only initialised
175  /// when necessary.
176  mutable std::unique_ptr<SrcMgrDiagInfo> DiagInfo;
177 
178  /// If the target supports dwarf debug info, this pointer is non-null.
179  DwarfDebug *DD = nullptr;
180 
181  /// If the current module uses dwarf CFI annotations strictly for debugging.
182  bool isCFIMoveForDebugging = false;
183 
184 protected:
185  explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
186 
187 public:
188  ~AsmPrinter() override;
189 
190  DwarfDebug *getDwarfDebug() { return DD; }
191  DwarfDebug *getDwarfDebug() const { return DD; }
192 
193  uint16_t getDwarfVersion() const;
194  void setDwarfVersion(uint16_t Version);
195 
196  bool isPositionIndependent() const;
197 
198  /// Return true if assembly output should contain comments.
199  bool isVerbose() const { return VerboseAsm; }
200 
201  /// Return a unique ID for the current function.
202  unsigned getFunctionNumber() const;
203 
204  /// Return symbol for the function pseudo stack if the stack frame is not a
205  /// register based.
206  virtual const MCSymbol *getFunctionFrameSymbol() const { return nullptr; }
207 
208  MCSymbol *getFunctionBegin() const { return CurrentFnBegin; }
209  MCSymbol *getFunctionEnd() const { return CurrentFnEnd; }
211 
212  /// Return information about object file lowering.
214 
215  /// Return information about data layout.
216  const DataLayout &getDataLayout() const;
217 
218  /// Return the pointer size from the TargetMachine
219  unsigned getPointerSize() const;
220 
221  /// Return information about subtarget.
222  const MCSubtargetInfo &getSubtargetInfo() const;
223 
224  void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
225 
226  /// Emits inital debug location directive.
228 
229  /// Return the current section we are emitting to.
230  const MCSection *getCurrentSection() const;
231 
233  const GlobalValue *GV) const;
234 
235  MCSymbol *getSymbol(const GlobalValue *GV) const;
236 
237  //===------------------------------------------------------------------===//
238  // XRay instrumentation implementation.
239  //===------------------------------------------------------------------===//
240 public:
241  // This describes the kind of sled we're storing in the XRay table.
242  enum class SledKind : uint8_t {
243  FUNCTION_ENTER = 0,
244  FUNCTION_EXIT = 1,
245  TAIL_CALL = 2,
246  LOG_ARGS_ENTER = 3,
247  CUSTOM_EVENT = 4,
248  TYPED_EVENT = 5,
249  };
250 
251  // The table will contain these structs that point to the sled, the function
252  // containing the sled, and what kind of sled (and whether they should always
253  // be instrumented). We also use a version identifier that the runtime can use
254  // to decide what to do with the sled, depending on the version of the sled.
256  const MCSymbol *Sled;
260  const class Function *Fn;
261  uint8_t Version;
262 
263  void emit(int, MCStreamer *, const MCSymbol *) const;
264  };
265 
266  // All the sleds to be emitted.
268 
269  // A unique ID used for ELF sections associated with a particular function.
270  unsigned XRayFnUniqueID = 0;
271 
272  // Helper function to record a given XRay sled.
273  void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind,
274  uint8_t Version = 0);
275 
276  /// Emit a table with all XRay instrumentation points.
277  void emitXRayTable();
278 
279  //===------------------------------------------------------------------===//
280  // MachineFunctionPass Implementation.
281  //===------------------------------------------------------------------===//
282 
283  /// Record analysis usage.
284  void getAnalysisUsage(AnalysisUsage &AU) const override;
285 
286  /// Set up the AsmPrinter when we are working on a new module. If your pass
287  /// overrides this, it must make sure to explicitly call this implementation.
288  bool doInitialization(Module &M) override;
289 
290  /// Shut down the asmprinter. If you override this in your pass, you must make
291  /// sure to call it explicitly.
292  bool doFinalization(Module &M) override;
293 
294  /// Emit the specified function out to the OutStreamer.
298  return false;
299  }
300 
301  //===------------------------------------------------------------------===//
302  // Coarse grained IR lowering routines.
303  //===------------------------------------------------------------------===//
304 
305  /// This should be called when a new MachineFunction is being processed from
306  /// runOnMachineFunction.
308 
309  /// This method emits the body and trailer for a function.
310  void EmitFunctionBody();
311 
312  void emitCFIInstruction(const MachineInstr &MI);
313 
314  void emitFrameAlloc(const MachineInstr &MI);
315 
316  void emitStackSizeSection(const MachineFunction &MF);
317 
318  void emitRemarksSection(Module &M);
319 
321  CFIMoveType needsCFIMoves() const;
322 
323  /// Returns false if needsCFIMoves() == CFI_M_EH for any function
324  /// in the module.
325  bool needsOnlyDebugCFIMoves() const { return isCFIMoveForDebugging; }
326 
327  bool needsSEHMoves();
328 
329  /// Print to the current output stream assembly representations of the
330  /// constants in the constant pool MCP. This is used to print out constants
331  /// which have been "spilled to memory" by the code generator.
332  virtual void EmitConstantPool();
333 
334  /// Print assembly representations of the jump tables used by the current
335  /// function to the current output stream.
336  virtual void EmitJumpTableInfo();
337 
338  /// Emit the specified global variable to the .s file.
339  virtual void EmitGlobalVariable(const GlobalVariable *GV);
340 
341  /// Check to see if the specified global is a special global used by LLVM. If
342  /// so, emit it and return true, otherwise do nothing and return false.
343  bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
344 
345  /// Emit an alignment directive to the specified power of two boundary. If a
346  /// global value is specified, and if that global has an explicit alignment
347  /// requested, it will override the alignment request if required for
348  /// correctness.
349  void EmitAlignment(llvm::Align Align, const GlobalObject *GV = nullptr) const;
350 
351  /// Lower the specified LLVM Constant to an MCExpr.
352  virtual const MCExpr *lowerConstant(const Constant *CV);
353 
354  /// Print a general LLVM constant to the .s file.
355  void EmitGlobalConstant(const DataLayout &DL, const Constant *CV);
356 
357  /// Unnamed constant global variables solely contaning a pointer to
358  /// another globals variable act like a global variable "proxy", or GOT
359  /// equivalents, i.e., it's only used to hold the address of the latter. One
360  /// optimization is to replace accesses to these proxies by using the GOT
361  /// entry for the final global instead. Hence, we select GOT equivalent
362  /// candidates among all the module global variables, avoid emitting them
363  /// unnecessarily and finally replace references to them by pc relative
364  /// accesses to GOT entries.
366 
367  /// Constant expressions using GOT equivalent globals may not be
368  /// eligible for PC relative GOT entry conversion, in such cases we need to
369  /// emit the proxies we previously omitted in EmitGlobalVariable.
370  void emitGlobalGOTEquivs();
371 
372  /// Emit the stack maps.
373  void emitStackMaps(StackMaps &SM);
374 
375  //===------------------------------------------------------------------===//
376  // Overridable Hooks
377  //===------------------------------------------------------------------===//
378 
379  // Targets can, or in the case of EmitInstruction, must implement these to
380  // customize output.
381 
382  /// This virtual method can be overridden by targets that want to emit
383  /// something at the start of their file.
384  virtual void EmitStartOfAsmFile(Module &) {}
385 
386  /// This virtual method can be overridden by targets that want to emit
387  /// something at the end of their file.
388  virtual void EmitEndOfAsmFile(Module &) {}
389 
390  /// Targets can override this to emit stuff before the first basic block in
391  /// the function.
392  virtual void EmitFunctionBodyStart() {}
393 
394  /// Targets can override this to emit stuff after the last basic block in the
395  /// function.
396  virtual void EmitFunctionBodyEnd() {}
397 
398  /// Targets can override this to emit stuff at the start of a basic block.
399  /// By default, this method prints the label for the specified
400  /// MachineBasicBlock, an alignment (if present) and a comment describing it
401  /// if appropriate.
402  virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB);
403 
404  /// Targets can override this to emit stuff at the end of a basic block.
405  virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB);
406 
407  /// Targets should implement this to emit instructions.
408  virtual void EmitInstruction(const MachineInstr *) {
409  llvm_unreachable("EmitInstruction not implemented");
410  }
411 
412  /// Return the symbol for the specified constant pool entry.
413  virtual MCSymbol *GetCPISymbol(unsigned CPID) const;
414 
415  virtual void EmitFunctionEntryLabel();
416 
418 
419  /// Targets can override this to change how global constants that are part of
420  /// a C++ static/global constructor list are emitted.
421  virtual void EmitXXStructor(const DataLayout &DL, const Constant *CV) {
422  EmitGlobalConstant(DL, CV);
423  }
424 
425  /// Return true if the basic block has exactly one predecessor and the control
426  /// transfer mechanism between the predecessor and this block is a
427  /// fall-through.
428  virtual bool
430 
431  /// Targets can override this to customize the output of IMPLICIT_DEF
432  /// instructions in verbose mode.
433  virtual void emitImplicitDef(const MachineInstr *MI) const;
434 
435  //===------------------------------------------------------------------===//
436  // Symbol Lowering Routines.
437  //===------------------------------------------------------------------===//
438 
439  MCSymbol *createTempSymbol(const Twine &Name) const;
440 
441  /// Return the MCSymbol for a private symbol with global value name as its
442  /// base, with the specified suffix.
444  StringRef Suffix) const;
445 
446  /// Return the MCSymbol for the specified ExternalSymbol.
448 
449  /// Return the symbol for the specified jump table entry.
450  MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;
451 
452  /// Return the symbol for the specified jump table .set
453  /// FIXME: privatize to AsmPrinter.
454  MCSymbol *GetJTSetSymbol(unsigned UID, unsigned MBBID) const;
455 
456  /// Return the MCSymbol used to satisfy BlockAddress uses of the specified
457  /// basic block.
458  MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA) const;
459  MCSymbol *GetBlockAddressSymbol(const BasicBlock *BB) const;
460 
461  //===------------------------------------------------------------------===//
462  // Emission Helper Routines.
463  //===------------------------------------------------------------------===//
464 
465  /// This is just convenient handler for printing offsets.
466  void printOffset(int64_t Offset, raw_ostream &OS) const;
467 
468  /// Emit a byte directive and value.
469  void emitInt8(int Value) const;
470 
471  /// Emit a short directive and value.
472  void emitInt16(int Value) const;
473 
474  /// Emit a long directive and value.
475  void emitInt32(int Value) const;
476 
477  /// Emit a long long directive and value.
478  void emitInt64(uint64_t Value) const;
479 
480  /// Emit something like ".long Hi-Lo" where the size in bytes of the directive
481  /// is specified by Size and Hi/Lo specify the labels. This implicitly uses
482  /// .set if it is available.
483  void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
484  unsigned Size) const;
485 
486  /// Emit something like ".uleb128 Hi-Lo".
487  void EmitLabelDifferenceAsULEB128(const MCSymbol *Hi,
488  const MCSymbol *Lo) const;
489 
490  /// Emit something like ".long Label+Offset" where the size in bytes of the
491  /// directive is specified by Size and Label specifies the label. This
492  /// implicitly uses .set if it is available.
493  void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
494  unsigned Size, bool IsSectionRelative = false) const;
495 
496  /// Emit something like ".long Label" where the size in bytes of the directive
497  /// is specified by Size and Label specifies the label.
498  void EmitLabelReference(const MCSymbol *Label, unsigned Size,
499  bool IsSectionRelative = false) const {
500  EmitLabelPlusOffset(Label, 0, Size, IsSectionRelative);
501  }
502 
503  /// Emit something like ".long Label + Offset".
504  void EmitDwarfOffset(const MCSymbol *Label, uint64_t Offset) const;
505 
506  //===------------------------------------------------------------------===//
507  // Dwarf Emission Helper Routines
508  //===------------------------------------------------------------------===//
509 
510  /// Emit the specified signed leb128 value.
511  void EmitSLEB128(int64_t Value, const char *Desc = nullptr) const;
512 
513  /// Emit the specified unsigned leb128 value.
514  void EmitULEB128(uint64_t Value, const char *Desc = nullptr, unsigned PadTo = 0) const;
515 
516  /// Emit a .byte 42 directive that corresponds to an encoding. If verbose
517  /// assembly output is enabled, we output comments describing the encoding.
518  /// Desc is a string saying what the encoding is specifying (e.g. "LSDA").
519  void EmitEncodingByte(unsigned Val, const char *Desc = nullptr) const;
520 
521  /// Return the size of the encoding in bytes.
522  unsigned GetSizeOfEncodedValue(unsigned Encoding) const;
523 
524  /// Emit reference to a ttype global with a specified encoding.
525  void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const;
526 
527  /// Emit a reference to a symbol for use in dwarf. Different object formats
528  /// represent this in different ways. Some use a relocation others encode
529  /// the label offset in its section.
530  void emitDwarfSymbolReference(const MCSymbol *Label,
531  bool ForceOffset = false) const;
532 
533  /// Emit the 4-byte offset of a string from the start of its section.
534  ///
535  /// When possible, emit a DwarfStringPool section offset without any
536  /// relocations, and without using the symbol. Otherwise, defers to \a
537  /// emitDwarfSymbolReference().
539 
540  /// Emit the 4-byte offset of a string from the start of its section.
543  }
544 
545  /// Emit reference to a call site with a specified encoding
546  void EmitCallSiteOffset(const MCSymbol *Hi, const MCSymbol *Lo,
547  unsigned Encoding) const;
548  /// Emit an integer value corresponding to the call site encoding
549  void EmitCallSiteValue(uint64_t Value, unsigned Encoding) const;
550 
551  /// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
552  virtual unsigned getISAEncoding() { return 0; }
553 
554  /// Emit the directive and value for debug thread local expression
555  ///
556  /// \p Value - The value to emit.
557  /// \p Size - The size of the integer (in bytes) to emit.
558  virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const;
559 
560  //===------------------------------------------------------------------===//
561  // Dwarf Lowering Routines
562  //===------------------------------------------------------------------===//
563 
564  /// Emit frame instruction to describe the layout of the frame.
565  void emitCFIInstruction(const MCCFIInstruction &Inst) const;
566 
567  /// Emit Dwarf abbreviation table.
568  template <typename T> void emitDwarfAbbrevs(const T &Abbrevs) const {
569  // For each abbreviation.
570  for (const auto &Abbrev : Abbrevs)
571  emitDwarfAbbrev(*Abbrev);
572 
573  // Mark end of abbreviations.
574  EmitULEB128(0, "EOM(3)");
575  }
576 
577  void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const;
578 
579  /// Recursively emit Dwarf DIE tree.
580  void emitDwarfDIE(const DIE &Die) const;
581 
582  //===------------------------------------------------------------------===//
583  // Inline Asm Support
584  //===------------------------------------------------------------------===//
585 
586  // These are hooks that targets can override to implement inline asm
587  // support. These should probably be moved out of AsmPrinter someday.
588 
589  /// Print information related to the specified machine instr that is
590  /// independent of the operand, and may be independent of the instr itself.
591  /// This can be useful for portably encoding the comment character or other
592  /// bits of target-specific knowledge into the asmstrings. The syntax used is
593  /// ${:comment}. Targets can override this to add support for their own
594  /// strange codes.
595  virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
596  const char *Code) const;
597 
598  /// Print the MachineOperand as a symbol. Targets with complex handling of
599  /// symbol references should override the base implementation.
600  virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS);
601 
602  /// Print the specified operand of MI, an INLINEASM instruction, using the
603  /// specified assembler variant. Targets should override this to format as
604  /// appropriate. This method can return true if the operand is erroneous.
605  virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
606  const char *ExtraCode, raw_ostream &OS);
607 
608  /// Print the specified operand of MI, an INLINEASM instruction, using the
609  /// specified assembler variant as an address. Targets should override this to
610  /// format as appropriate. This method can return true if the operand is
611  /// erroneous.
612  virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
613  const char *ExtraCode, raw_ostream &OS);
614 
615  /// Let the target do anything it needs to do before emitting inlineasm.
616  /// \p StartInfo - the subtarget info before parsing inline asm
617  virtual void emitInlineAsmStart() const;
618 
619  /// Let the target do anything it needs to do after emitting inlineasm.
620  /// This callback can be used restore the original mode in case the
621  /// inlineasm contains directives to switch modes.
622  /// \p StartInfo - the original subtarget info before inline asm
623  /// \p EndInfo - the final subtarget info after parsing the inline asm,
624  /// or NULL if the value is unknown.
625  virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
626  const MCSubtargetInfo *EndInfo) const;
627 
628  /// This emits visibility information about symbol, if this is supported by
629  /// the target.
630  void EmitVisibility(MCSymbol *Sym, unsigned Visibility,
631  bool IsDefinition = true) const;
632 
633  /// This emits linkage information about \p GVSym based on \p GV, if this is
634  /// supported by the target.
635  void EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const;
636 
637  /// Return the alignment for the specified \p GV.
638  static llvm::Align getGVAlignment(const GlobalValue *GV, const DataLayout &DL,
639  llvm::Align InAlign = llvm::Align::None());
640 
641 private:
642  /// Private state for PrintSpecial()
643  // Assign a unique ID to this machine instruction.
644  mutable const MachineInstr *LastMI = nullptr;
645  mutable unsigned LastFn = 0;
646  mutable unsigned Counter = ~0U;
647 
648  /// This method emits the header for the current function.
649  virtual void EmitFunctionHeader();
650 
651  /// Emit a blob of inline asm to the output streamer.
652  void
653  EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
654  const MCTargetOptions &MCOptions,
655  const MDNode *LocMDNode = nullptr,
656  InlineAsm::AsmDialect AsmDialect = InlineAsm::AD_ATT) const;
657 
658  /// This method formats and emits the specified machine instruction that is an
659  /// inline asm.
660  void EmitInlineAsm(const MachineInstr *MI) const;
661 
662  /// Add inline assembly info to the diagnostics machinery, so we can
663  /// emit file and position info. Returns SrcMgr memory buffer position.
664  unsigned addInlineAsmDiagBuffer(StringRef AsmStr,
665  const MDNode *LocMDNode) const;
666 
667  //===------------------------------------------------------------------===//
668  // Internal Implementation Details
669  //===------------------------------------------------------------------===//
670 
671  void EmitJumpTableEntry(const MachineJumpTableInfo *MJTI,
672  const MachineBasicBlock *MBB, unsigned uid) const;
673  void EmitLLVMUsedList(const ConstantArray *InitList);
674  /// Emit llvm.ident metadata in an '.ident' directive.
675  void EmitModuleIdents(Module &M);
676  /// Emit bytes for llvm.commandline metadata.
677  void EmitModuleCommandLines(Module &M);
678  void EmitXXStructorList(const DataLayout &DL, const Constant *List,
679  bool isCtor);
680 
681  GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy &S);
682  /// Emit GlobalAlias or GlobalIFunc.
683  void emitGlobalIndirectSymbol(Module &M, const GlobalIndirectSymbol &GIS);
684  void setupCodePaddingContext(const MachineBasicBlock &MBB,
686 };
687 
688 } // end namespace llvm
689 
690 #endif // LLVM_CODEGEN_ASMPRINTER_H
virtual void EmitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:449
void EmitCallSiteOffset(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Encoding) const
Emit reference to a call site with a specified encoding.
void setDwarfVersion(uint16_t Version)
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:215
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
void emitInt64(uint64_t Value) const
Emit a long long directive and value.
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:384
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
LLVMContext & Context
unsigned XRayFnUniqueID
Definition: AsmPrinter.h:270
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool needsOnlyDebugCFIMoves() const
Returns false if needsCFIMoves() == CFI_M_EH for any function in the module.
Definition: AsmPrinter.h:325
bool doFinalization(Module &M) override
Shut down the asmprinter.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:229
uint16_t getDwarfVersion() const
CFIMoveType needsCFIMoves() const
Definition: AsmPrinter.cpp:924
virtual void EmitJumpTableInfo()
Print assembly representations of the jump tables used by the current function to the current output ...
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:292
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:421
virtual void EmitConstantPool()
Print to the current output stream assembly representations of the constants in the constant pool MCP...
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:37
Metadata node.
Definition: Metadata.h:863
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
SmallVector< HandlerInfo, 1 > Handlers
A vector of all debug/EH info emitters we should use.
Definition: AsmPrinter.h:157
LLVMContext::InlineAsmDiagHandlerTy DiagHandler
Definition: AsmPrinter.h:163
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:121
virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:644
DwarfStringPoolEntry getEntry() const
Return the entire string pool entry for convenience.
const char * TimerGroupDescription
Definition: AsmPrinter.h:145
The address of a basic block.
Definition: Constants.h:839
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
Definition: BitVector.h:937
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual void EmitEndOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: AsmPrinter.h:388
void emitDwarfDIE(const DIE &Die) const
Recursively emit Dwarf DIE tree.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
SmallVector< XRayFunctionEntry, 4 > Sleds
Definition: AsmPrinter.h:267
HandlerInfo(std::unique_ptr< AsmPrinterHandler > Handler, const char *TimerName, const char *TimerDescription, const char *TimerGroupName, const char *TimerGroupDescription)
Definition: AsmPrinter.h:147
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:225
void emitXRayTable()
Emit a table with all XRay instrumentation points.
Context object for machine code objects.
Definition: MCContext.h:65
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AsmPrinter.cpp:249
void EmitFunctionBody()
This method emits the body and trailer for a function.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:295
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:208
virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:206
Protected struct HandlerInfo and Handlers permit target extended AsmPrinter adds their own handlers...
Definition: AsmPrinter.h:140
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:199
Data for a string pool entry.
void EmitLabelDifferenceAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) const
Emit something like ".uleb128 Hi-Lo".
void emitGlobalGOTEquivs()
Constant expressions using GOT equivalent globals may not be eligible for PC relative GOT entry conve...
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:99
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
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...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Streaming machine code generation interface.
Definition: MCStreamer.h:190
virtual void EmitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
Definition: AsmPrinter.h:396
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:112
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: AsmPrinter.cpp:189
This is an important base class in LLVM.
Definition: Constant.h:41
A structured debug information entry.
Definition: DIE.h:700
void EmitEncodingByte(unsigned Val, const char *Desc=nullptr) const
Emit a .byte 42 directive that corresponds to an encoding.
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:81
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:439
Represent the analysis usage information of a pass.
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:190
static void EmitInlineAsm(LLVMContext &C, BasicBlock *BB, StringRef AsmText)
void EmitCallSiteValue(uint64_t Value, unsigned Encoding) const
Emit an integer value corresponding to the call site encoding.
void EmitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
Definition: AsmPrinter.h:498
std::unique_ptr< AsmPrinterHandler > Handler
Definition: AsmPrinter.h:141
~AsmPrinter() override
Definition: AsmPrinter.cpp:195
void emitFrameAlloc(const MachineInstr &MI)
Definition: AsmPrinter.cpp:964
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
void computeGlobalGOTEquivs(Module &M)
Unnamed constant global variables solely contaning a pointer to another globals variable act like a g...
void EmitAlignment(llvm::Align Align, const GlobalObject *GV=nullptr) const
Emit an alignment directive to the specified power of two boundary.
void emitStackMaps(StackMaps &SM)
Emit the stack maps.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
Definition: Alignment.h:82
Abstract base class for all machine specific constantpool value subclasses.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
unsigned GetSizeOfEncodedValue(unsigned Encoding) const
Return the size of the encoding in bytes.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
static llvm::Align getGVAlignment(const GlobalValue *GV, const DataLayout &DL, llvm::Align InAlign=llvm::Align::None())
Return the alignment for the specified GV.
Definition: AsmPrinter.cpp:164
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:211
void emitCFIInstruction(const MachineInstr &MI)
Definition: AsmPrinter.cpp:939
virtual void emitImplicitDef(const MachineInstr *MI) const
Targets can override this to customize the output of IMPLICIT_DEF instructions in verbose mode...
Definition: AsmPrinter.cpp:783
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
void EmitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
Definition: AsmPrinter.h:122
void emitDwarfStringOffset(DwarfStringPoolEntry S) const
Emit the 4-byte offset of a string from the start of its section.
The optimization diagnostic interface.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:444
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
virtual void EmitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
Definition: AsmPrinter.h:408
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
DwarfDebug * getDwarfDebug() const
Definition: AsmPrinter.h:191
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:234
bool EmitSpecialLLVMGlobal(const GlobalVariable *GV)
Check to see if the specified global is a special global used by LLVM.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
const class Function * Fn
Definition: AsmPrinter.h:260
void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const
Emit reference to a ttype global with a specified encoding.
void emitInt32(int Value) const
Emit a long directive and value.
MCSymbol * getFunctionEnd() const
Definition: AsmPrinter.h:209
MachineDominatorTree * MDT
This is a pointer to the current MachineLoopInfo.
Definition: AsmPrinter.h:102
ConstantArray - Constant Array Declarations.
Definition: Constants.h:413
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:568
virtual void EmitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:392
MCSymbol * getCurExceptionSym()
void(*)(const SMDiagnostic &, void *Context, unsigned LocCookie) InlineAsmDiagHandlerTy
Definition: LLVMContext.h:144
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
virtual const MCSymbol * getFunctionFrameSymbol() const
Return symbol for the function pseudo stack if the stack frame is not a register based.
Definition: AsmPrinter.h:206
void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const
String pool entry reference.
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
MachineLoopInfo * MLI
This is a pointer to the current MachineLoopInfo.
Definition: AsmPrinter.h:105
Representation of each machine instruction.
Definition: MachineInstr.h:64
void emitInitialRawDwarfLocDirective(const MachineFunction &MF)
Emits inital debug location directive.
Definition: AsmPrinter.cpp:238
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:398
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:79
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
Definition: AsmPrinter.cpp:257
GCStrategy describes a garbage collector algorithm&#39;s code generation requirements, and provides overridable hooks for those needs which cannot be abstractly described.
Definition: GCStrategy.h:66
void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const
Emit the 4-byte offset of a string from the start of its section.
Definition: AsmPrinter.h:541
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
void EmitDwarfOffset(const MCSymbol *Label, uint64_t Offset) const
Emit something like ".long Label + Offset".
void emitRemarksSection(Module &M)
MCSymbol * GetJTSetSymbol(unsigned UID, unsigned MBBID) const
Return the symbol for the specified jump table .set FIXME: privatize to AsmPrinter.
const NodeList & List
Definition: RDFGraph.cpp:201
Generic base class for all target subtargets.
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...
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
uint32_t Size
Definition: Profile.cpp:46
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
Definition: AsmPrinter.h:552
virtual void EmitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
Definition: AsmPrinter.cpp:739
void EmitGlobalConstant(const DataLayout &DL, const Constant *CV)
Print a general LLVM constant to the .s file.
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
MCSymbol * CurrentFnSymForSize
The symbol used to represent the start of the current function for the purpose of calculating its siz...
Definition: AsmPrinter.h:117
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:219
GCMetadataPrinter - Emits GC metadata as assembly code.
IRTranslator LLVM IR MI
MachineOptimizationRemarkEmitter * ORE
Optimization remark emitter.
Definition: AsmPrinter.h:108
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
std::vector< const MDNode * > LocInfos
Definition: AsmPrinter.h:162
const MCSection * getCurrentSection() const
Return the current section we are emitting to.
Definition: AsmPrinter.cpp:245
void EmitVisibility(MCSymbol *Sym, unsigned Visibility, bool IsDefinition=true) const
This emits visibility information about symbol, if this is supported by the target.
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
MCSymbol * createTempSymbol(const Twine &Name) const
const uint64_t Version
Definition: InstrProf.h:984
virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS, const char *Code) const
Print information related to the specified machine instr that is independent of the operand...
void emitStackSizeSection(const MachineFunction &MF)
Definition: AsmPrinter.cpp:974
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void emitInt16(int Value) const
Emit a short directive and value.
This class contains meta information specific to a module.