LLVM  5.0.0
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 GlobalIndirectSymbol;
47 class GlobalObject;
48 class GlobalValue;
49 class GlobalVariable;
50 class GCStrategy;
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 class MCContext;
62 class MCExpr;
63 class MCInst;
64 class MCSection;
65 class MCStreamer;
66 class MCSubtargetInfo;
67 class MCSymbol;
68 class MCTargetOptions;
69 class MDNode;
70 class Module;
71 class raw_ostream;
72 class TargetLoweringObjectFile;
73 class TargetMachine;
74 
75 /// This class is intended to be used as a driving class for all asm writers.
77 public:
78  /// Target machine description.
79  ///
81 
82  /// Target Asm Printer information.
83  ///
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  const MachineFunction *MF = nullptr;
97 
98  /// This is a pointer to the current MachineModuleInfo.
99  MachineModuleInfo *MMI = nullptr;
100 
101  /// Optimization remark emitter.
103 
104  /// The symbol for the current function. This is recalculated at the beginning
105  /// of each call to runOnMachineFunction().
106  ///
107  MCSymbol *CurrentFnSym = nullptr;
108 
109  /// The symbol used to represent the start of the current function for the
110  /// purpose of calculating its size (e.g. using the .size directive). By
111  /// default, this is equal to CurrentFnSym.
113 
114  /// Map global GOT equivalent MCSymbols to GlobalVariables and keep track of
115  /// its number of uses by other globals.
116  using GOTEquivUsePair = std::pair<const GlobalVariable *, unsigned>;
118 
119  /// Enable print [latency:throughput] in output
120  bool EnablePrintSchedInfo = false;
121 
122 private:
123  MCSymbol *CurrentFnBegin = nullptr;
124  MCSymbol *CurrentFnEnd = nullptr;
125  MCSymbol *CurExceptionSym = nullptr;
126 
127  // The garbage collection metadata printer table.
128  void *GCMetadataPrinters = nullptr; // Really a DenseMap.
129 
130  /// Emit comments in assembly output if this is true.
131  ///
132  bool VerboseAsm;
133  static char ID;
134 
135  /// If VerboseAsm is set, a pointer to the loop info for this function.
136  MachineLoopInfo *LI = nullptr;
137 
138  struct HandlerInfo {
139  AsmPrinterHandler *Handler;
140  const char *TimerName;
141  const char *TimerDescription;
142  const char *TimerGroupName;
143  const char *TimerGroupDescription;
144 
145  HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName,
146  const char *TimerDescription, const char *TimerGroupName,
147  const char *TimerGroupDescription)
148  : Handler(Handler), TimerName(TimerName),
149  TimerDescription(TimerDescription), TimerGroupName(TimerGroupName),
150  TimerGroupDescription(TimerGroupDescription) {}
151  };
152  /// A vector of all debug/EH info emitters we should use. This vector
153  /// maintains ownership of the emitters.
155 
156 public:
157  struct SrcMgrDiagInfo {
159  std::vector<const MDNode *> LocInfos;
161  void *DiagContext;
162  };
163 
164 private:
165  /// Structure for generating diagnostics for inline assembly. Only initialised
166  /// when necessary.
167  mutable std::unique_ptr<SrcMgrDiagInfo> DiagInfo;
168 
169  /// If the target supports dwarf debug info, this pointer is non-null.
170  DwarfDebug *DD = nullptr;
171 
172  /// If the current module uses dwarf CFI annotations strictly for debugging.
173  bool isCFIMoveForDebugging = false;
174 
175 protected:
176  explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
177 
178 public:
179  ~AsmPrinter() override;
180 
181  DwarfDebug *getDwarfDebug() { return DD; }
182  DwarfDebug *getDwarfDebug() const { return DD; }
183 
184  uint16_t getDwarfVersion() const;
185  void setDwarfVersion(uint16_t Version);
186 
187  bool isPositionIndependent() const;
188 
189  /// Return true if assembly output should contain comments.
190  ///
191  bool isVerbose() const { return VerboseAsm; }
192 
193  /// Return a unique ID for the current function.
194  ///
195  unsigned getFunctionNumber() const;
196 
197  MCSymbol *getFunctionBegin() const { return CurrentFnBegin; }
198  MCSymbol *getFunctionEnd() const { return CurrentFnEnd; }
200 
201  /// Return information about object file lowering.
203 
204  /// Return information about data layout.
205  const DataLayout &getDataLayout() const;
206 
207  /// Return the pointer size from the TargetMachine
208  unsigned getPointerSize() const;
209 
210  /// Return information about subtarget.
211  const MCSubtargetInfo &getSubtargetInfo() const;
212 
213  void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
214 
215  /// Return the current section we are emitting to.
216  const MCSection *getCurrentSection() const;
217 
219  const GlobalValue *GV) const;
220 
221  MCSymbol *getSymbol(const GlobalValue *GV) const;
222 
223  //===------------------------------------------------------------------===//
224  // XRay instrumentation implementation.
225  //===------------------------------------------------------------------===//
226 public:
227  // This describes the kind of sled we're storing in the XRay table.
228  enum class SledKind : uint8_t {
229  FUNCTION_ENTER = 0,
230  FUNCTION_EXIT = 1,
231  TAIL_CALL = 2,
232  LOG_ARGS_ENTER = 3,
233  CUSTOM_EVENT = 4,
234  };
235 
236  // The table will contain these structs that point to the sled, the function
237  // containing the sled, and what kind of sled (and whether they should always
238  // be instrumented).
240  const MCSymbol *Sled;
244  const class Function *Fn;
245 
246  void emit(int, MCStreamer *, const MCSymbol *) const;
247  };
248 
249  // All the sleds to be emitted.
251 
252  // Helper function to record a given XRay sled.
253  void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind);
254 
255  /// Emit a table with all XRay instrumentation points.
256  void emitXRayTable();
257 
258  //===------------------------------------------------------------------===//
259  // MachineFunctionPass Implementation.
260  //===------------------------------------------------------------------===//
261 
262  /// Record analysis usage.
263  ///
264  void getAnalysisUsage(AnalysisUsage &AU) const override;
265 
266  /// Set up the AsmPrinter when we are working on a new module. If your pass
267  /// overrides this, it must make sure to explicitly call this implementation.
268  bool doInitialization(Module &M) override;
269 
270  /// Shut down the asmprinter. If you override this in your pass, you must make
271  /// sure to call it explicitly.
272  bool doFinalization(Module &M) override;
273 
274  /// Emit the specified function out to the OutStreamer.
278  return false;
279  }
280 
281  //===------------------------------------------------------------------===//
282  // Coarse grained IR lowering routines.
283  //===------------------------------------------------------------------===//
284 
285  /// This should be called when a new MachineFunction is being processed from
286  /// runOnMachineFunction.
288 
289  /// This method emits the body and trailer for a function.
290  void EmitFunctionBody();
291 
292  void emitCFIInstruction(const MachineInstr &MI);
293 
294  void emitFrameAlloc(const MachineInstr &MI);
295 
298 
299  /// Returns false if needsCFIMoves() == CFI_M_EH for any function
300  /// in the module.
301  bool needsOnlyDebugCFIMoves() const { return isCFIMoveForDebugging; }
302 
303  bool needsSEHMoves();
304 
305  /// Print to the current output stream assembly representations of the
306  /// constants in the constant pool MCP. This is used to print out constants
307  /// which have been "spilled to memory" by the code generator.
308  ///
309  virtual void EmitConstantPool();
310 
311  /// Print assembly representations of the jump tables used by the current
312  /// function to the current output stream.
313  ///
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  ///
329  void EmitAlignment(unsigned NumBits, const GlobalObject *GO = nullptr) const;
330 
331  /// Lower the specified LLVM Constant to an MCExpr.
332  virtual const MCExpr *lowerConstant(const Constant *CV);
333 
334  /// \brief Print a general LLVM constant to the .s file.
335  void EmitGlobalConstant(const DataLayout &DL, const Constant *CV);
336 
337  /// \brief Unnamed constant global variables solely contaning a pointer to
338  /// another globals variable act like a global variable "proxy", or GOT
339  /// equivalents, i.e., it's only used to hold the address of the latter. One
340  /// optimization is to replace accesses to these proxies by using the GOT
341  /// entry for the final global instead. Hence, we select GOT equivalent
342  /// candidates among all the module global variables, avoid emitting them
343  /// unnecessarily and finally replace references to them by pc relative
344  /// accesses to GOT entries.
346 
347  /// \brief Constant expressions using GOT equivalent globals may not be
348  /// eligible for PC relative GOT entry conversion, in such cases we need to
349  /// emit the proxies we previously omitted in EmitGlobalVariable.
350  void emitGlobalGOTEquivs();
351 
352  //===------------------------------------------------------------------===//
353  // Overridable Hooks
354  //===------------------------------------------------------------------===//
355 
356  // Targets can, or in the case of EmitInstruction, must implement these to
357  // customize output.
358 
359  /// This virtual method can be overridden by targets that want to emit
360  /// something at the start of their file.
361  virtual void EmitStartOfAsmFile(Module &) {}
362 
363  /// This virtual method can be overridden by targets that want to emit
364  /// something at the end of their file.
365  virtual void EmitEndOfAsmFile(Module &) {}
366 
367  /// Targets can override this to emit stuff before the first basic block in
368  /// the function.
369  virtual void EmitFunctionBodyStart() {}
370 
371  /// Targets can override this to emit stuff after the last basic block in the
372  /// function.
373  virtual void EmitFunctionBodyEnd() {}
374 
375  /// Targets can override this to emit stuff at the start of a basic block.
376  /// By default, this method prints the label for the specified
377  /// MachineBasicBlock, an alignment (if present) and a comment describing it
378  /// if appropriate.
379  virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB) const;
380 
381  /// Targets can override this to emit stuff at the end of a basic block.
382  virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB) {}
383 
384  /// Targets should implement this to emit instructions.
385  virtual void EmitInstruction(const MachineInstr *) {
386  llvm_unreachable("EmitInstruction not implemented");
387  }
388 
389  /// Return the symbol for the specified constant pool entry.
390  virtual MCSymbol *GetCPISymbol(unsigned CPID) const;
391 
392  virtual void EmitFunctionEntryLabel();
393 
395 
396  /// Targets can override this to change how global constants that are part of
397  /// a C++ static/global constructor list are emitted.
398  virtual void EmitXXStructor(const DataLayout &DL, const Constant *CV) {
399  EmitGlobalConstant(DL, CV);
400  }
401 
402  /// Return true if the basic block has exactly one predecessor and the control
403  /// transfer mechanism between the predecessor and this block is a
404  /// fall-through.
405  virtual bool
407 
408  /// Targets can override this to customize the output of IMPLICIT_DEF
409  /// instructions in verbose mode.
410  virtual void emitImplicitDef(const MachineInstr *MI) const;
411 
412  //===------------------------------------------------------------------===//
413  // Symbol Lowering Routines.
414  //===------------------------------------------------------------------===//
415 
416  MCSymbol *createTempSymbol(const Twine &Name) const;
417 
418  /// Return the MCSymbol for a private symbol with global value name as its
419  /// base, with the specified suffix.
421  StringRef Suffix) const;
422 
423  /// Return the MCSymbol for the specified ExternalSymbol.
425 
426  /// Return the symbol for the specified jump table entry.
427  MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;
428 
429  /// Return the symbol for the specified jump table .set
430  /// FIXME: privatize to AsmPrinter.
431  MCSymbol *GetJTSetSymbol(unsigned UID, unsigned MBBID) const;
432 
433  /// Return the MCSymbol used to satisfy BlockAddress uses of the specified
434  /// basic block.
435  MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA) const;
436  MCSymbol *GetBlockAddressSymbol(const BasicBlock *BB) const;
437 
438  //===------------------------------------------------------------------===//
439  // Emission Helper Routines.
440  //===------------------------------------------------------------------===//
441 
442  /// This is just convenient handler for printing offsets.
443  void printOffset(int64_t Offset, raw_ostream &OS) const;
444 
445  /// Emit a byte directive and value.
446  ///
447  void EmitInt8(int Value) const;
448 
449  /// Emit a short directive and value.
450  ///
451  void EmitInt16(int Value) const;
452 
453  /// Emit a long directive and value.
454  ///
455  void EmitInt32(int Value) const;
456 
457  /// Emit something like ".long Hi-Lo" where the size in bytes of the directive
458  /// is specified by Size and Hi/Lo specify the labels. This implicitly uses
459  /// .set if it is available.
460  void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
461  unsigned Size) const;
462 
463  /// Emit something like ".long Label+Offset" where the size in bytes of the
464  /// directive is specified by Size and Label specifies the label. This
465  /// implicitly uses .set if it is available.
466  void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset,
467  unsigned Size, bool IsSectionRelative = false) const;
468 
469  /// Emit something like ".long Label" where the size in bytes of the directive
470  /// is specified by Size and Label specifies the label.
471  void EmitLabelReference(const MCSymbol *Label, unsigned Size,
472  bool IsSectionRelative = false) const {
473  EmitLabelPlusOffset(Label, 0, Size, IsSectionRelative);
474  }
475 
476  //===------------------------------------------------------------------===//
477  // Dwarf Emission Helper Routines
478  //===------------------------------------------------------------------===//
479 
480  /// Emit the specified signed leb128 value.
481  void EmitSLEB128(int64_t Value, const char *Desc = nullptr) const;
482 
483  /// Emit the specified unsigned leb128 value.
484  void EmitULEB128(uint64_t Value, const char *Desc = nullptr,
485  unsigned PadTo = 0) 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  GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy &C);
626  /// Emit GlobalAlias or GlobalIFunc.
627  void emitGlobalIndirectSymbol(Module &M,
628  const GlobalIndirectSymbol& GIS);
629 };
630 
631 } // end namespace llvm
632 
633 #endif // LLVM_CODEGEN_ASMPRINTER_H
virtual void EmitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:425
void setDwarfVersion(uint16_t Version)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
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:361
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:420
void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const
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:63
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:196
bool doFinalization(Module &M) override
Shut down the asmprinter.
void EmitInt8(int Value) const
Emit a byte directive and value.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
bool EnablePrintSchedInfo
Enable print [latency:throughput] in output.
Definition: AsmPrinter.h:120
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...
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
DataLayout DL
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 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:203
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:398
static int Counter
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
virtual void EmitConstantPool()
Print to the current output stream assembly representations of the constants in the constant pool MCP...
This class implements a map that also provides access to all stored values in a deterministic order...
Definition: MapVector.h:38
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:188
Metadata node.
Definition: Metadata.h:862
void EmitInt32(int Value) const
Emit a long directive and value.
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:662
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:471
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:204
LLVMContext::InlineAsmDiagHandlerTy DiagHandler
Definition: AsmPrinter.h:160
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:116
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:415
The address of a basic block.
Definition: Constants.h:813
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:365
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void emitDwarfDIE(const DIE &Die) const
Recursively emit Dwarf DIE tree.
String pool entry reference.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
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...
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
SmallVector< XRayFunctionEntry, 4 > Sleds
Definition: AsmPrinter.h:250
uint16_t getDwarfVersion() const
void EmitEncodingByte(unsigned Val, const char *Desc=nullptr) const
Emit a .byte 42 directive that corresponds to an encoding.
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:218
void EmitFunctionBody()
This method emits the body and trailer for a function.
Definition: AsmPrinter.cpp:969
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:275
bool needsOnlyDebugCFIMoves() const
Returns false if needsCFIMoves() == CFI_M_EH for any function in the module.
Definition: AsmPrinter.h:301
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
const MCSection * getCurrentSection() const
Return the current section we are emitting to.
Definition: AsmPrinter.cpp:214
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...
virtual void EmitDebugThreadLocal(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:623
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:786
const char * Name
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:159
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:167
virtual void EmitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
Definition: AsmPrinter.h:373
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:107
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: AsmPrinter.cpp:165
unsigned GetSizeOfEncodedValue(unsigned Encoding) const
Return the size of the encoding in bytes.
This is an important base class in LLVM.
Definition: Constant.h:42
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind)
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...
MCSymbol * GetJTSetSymbol(unsigned UID, unsigned MBBID) const
Return the symbol for the specified jump table .set FIXME: privatize to AsmPrinter.
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:76
Represent the analysis usage information of a pass.
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:181
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
~AsmPrinter() override
Definition: AsmPrinter.cpp:171
void emitFrameAlloc(const MachineInstr &MI)
Definition: AsmPrinter.cpp:944
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 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
void EmitAlignment(unsigned NumBits, const GlobalObject *GO=nullptr) const
Emit an alignment directive to the specified power of two boundary.
void emitCFIInstruction(const MachineInstr &MI)
Definition: AsmPrinter.cpp:919
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
Definition: AsmPrinter.h:117
The optimization diagnostic interface.
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:385
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:209
bool EmitSpecialLLVMGlobal(const GlobalVariable *GV)
Check to see if the specified global is a special global used by LLVM.
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:528
const class Function * Fn
Definition: AsmPrinter.h:244
void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const
Emit reference to a ttype global with a specified encoding.
MCSymbol * createTempSymbol(const Twine &Name) const
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:182
DwarfDebug * getDwarfDebug() const
Definition: AsmPrinter.h:182
void emit(int, MCStreamer *, const MCSymbol *) const
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB) const
Targets can override this to emit stuff at the start of a basic block.
ConstantArray - Constant Array Declarations.
Definition: Constants.h:405
virtual void EmitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
Definition: AsmPrinter.h:369
MCSymbol * getCurExceptionSym()
void(*)(const SMDiagnostic &, void *Context, unsigned LocCookie) InlineAsmDiagHandlerTy
Definition: LLVMContext.h:168
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
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:228
GCStrategy describes a garbage collector algorithm's code generation requirements, and provides overridable hooks for those needs which cannot be abstractly described.
Definition: GCStrategy.h:80
void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
#define C
Definition: LargeTest.cpp:25
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:197
void EmitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
const NodeList & List
Definition: RDFGraph.cpp:205
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
virtual void EmitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
Definition: AsmPrinter.h:382
MCSubtargetInfo - Generic base class for all target subtargets.
MCSymbol * getFunctionEnd() const
Definition: AsmPrinter.h:198
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:202
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:716
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
CFIMoveType needsCFIMoves()
Definition: AsmPrinter.cpp:904
const unsigned Kind
void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const
Emit the 4-byte offset of a string from the start of its section.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:192
void EmitGlobalConstant(const DataLayout &DL, const Constant *CV)
Print a general LLVM constant to the .s file.
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:44
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
MCSymbol * CurrentFnSymForSize
The symbol used to represent the start of the current function for the purpose of calculating its siz...
Definition: AsmPrinter.h:112
GCMetadataPrinter - Emits GC metadata as assembly code.
IRTranslator LLVM IR MI
MachineOptimizationRemarkEmitter * ORE
Optimization remark emitter.
Definition: AsmPrinter.h:102
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::vector< const MDNode * > LocInfos
Definition: AsmPrinter.h:159
bool isVerbose() const
Return true if assembly output should contain comments.
Definition: AsmPrinter.h:191
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const uint64_t Version
Definition: InstrProf.h:864
This class contains meta information specific to a module.