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