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