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