15#ifndef LLVM_CODEGEN_ASMPRINTER_H
16#define LLVM_CODEGEN_ASMPRINTER_H
39class AsmPrinterHandler;
46class DebugHandlerBase;
51class GCMetadataPrinter;
57class MachineBasicBlock;
58class MachineConstantPoolValue;
59class MachineDominatorTree;
62class MachineJumpTableInfo;
64class MachineModuleInfo;
65class MachineOptimizationRemarkEmitter;
67class MCCFIInstruction;
78class PseudoProbeHandler;
81class TargetLoweringObjectFile;
123 MCSymbol *CurrentPatchableFunctionEntrySym =
nullptr;
181 MCSymbol *CurrentSectionBeginSym =
nullptr;
185 std::unique_ptr<AddrLabelMap> AddrLabelSymbols;
195 struct FunctionInfo {
203 enum class FunctionKind :
uint64_t {
205 NOT_INDIRECT_TARGET = 0,
208 INDIRECT_TARGET_UNKNOWN_TID = 1,
211 INDIRECT_TARGET_KNOWN_TID = 2,
216 SmallVector<std::pair<CGTypeId, MCSymbol *>> CallSiteLabels;
219 enum CallGraphSectionFormatVersion :
uint64_t {
224 std::unique_ptr<raw_fd_ostream> StackUsageStream;
227 DenseMap<const MDNode *, SmallVector<const MCSymbol *>> PCSectionsSymbols;
246 size_t NumUserHandlers = 0;
252 std::unique_ptr<MachineDominatorTree> OwnedMDT;
255 std::unique_ptr<MachineLoopInfo> OwnedMLI;
262 std::unique_ptr<PseudoProbeHandler> PP;
265 CFISection ModuleCFISection = CFISection::None;
270 bool HasSplitStack =
false;
275 bool HasNoSplitStack =
false;
278 bool DbgInfoAvailable =
false;
282 char &
ID = AsmPrinter::ID);
291 void setDwarfVersion(
uint16_t Version);
293 bool isDwarf64()
const;
296 unsigned int getDwarfOffsetByteSize()
const;
299 unsigned int getUnitLengthFieldByteSize()
const;
304 bool isPositionIndependent()
const;
310 unsigned getFunctionNumber()
const;
327 return getAddrLabelSymbolToEmit(BB).front();
343 void takeDeletedSymbolsForFunction(
const Function *
F,
344 std::vector<MCSymbol *> &Result);
364 const MCSection *getCurrentSection()
const;
377 return DwarfUsesRelocationsAcrossSections;
381 DwarfUsesRelocationsAcrossSections =
Enable;
390 void emitIndirectCalleeLabels(
391 FunctionInfo &FuncInfo,
432 void emitXRayTable();
434 void emitPatchableFunctionEntries();
445 bool doInitialization(
Module &M)
override;
449 bool doFinalization(
Module &M)
override;
453 SetupMachineFunction(MF);
467 void emitFunctionBody();
482 void emitCallGraphSection(
const MachineFunction &MF, FunctionInfo &FuncInfo);
495 CFISection getFunctionCFISectionType(
const Function &
F)
const;
506 bool needsSEHMoves();
512 bool usesCFIWithoutEH()
const;
521 virtual void emitJumpTableInfo();
561 unsigned MaxBytesToEmit = 0)
const;
584 void computeGlobalGOTEquivs(
Module &M);
589 void emitGlobalGOTEquivs();
592 void emitStackMaps();
598 void addAsmPrinterHandler(std::unique_ptr<AsmPrinterHandler> Handler);
634 virtual MCSymbol *GetCPISymbol(
unsigned CPID)
const;
636 virtual void emitFunctionEntryLabel();
647 emitGlobalConstant(
DL, CV);
678 "Mach-O IFunc lowering is not yet supported on this target");
684 "Mach-O IFunc lowering is not yet supported on this target");
688 void emitNops(
unsigned N);
705 MCSymbol *GetJTISymbol(
unsigned JTID,
bool isLinkerPrivate =
false)
const;
709 MCSymbol *GetJTSetSymbol(
unsigned UID,
unsigned MBBID)
const;
724 void emitInt8(
int Value)
const;
727 void emitInt16(
int Value)
const;
730 void emitInt32(
int Value)
const;
736 void emitSLEB128(int64_t
Value,
const char *
Desc =
nullptr)
const;
740 unsigned PadTo = 0)
const;
746 unsigned Size)
const;
749 void emitLabelDifferenceAsULEB128(
const MCSymbol *
Hi,
756 unsigned Size,
bool IsSectionRelative =
false)
const;
761 bool IsSectionRelative =
false)
const {
762 emitLabelPlusOffset(Label, 0,
Size, IsSectionRelative);
775 unsigned GetSizeOfEncodedValue(
unsigned Encoding)
const;
778 virtual void emitTTypeReference(
const GlobalValue *GV,
unsigned Encoding);
783 void emitDwarfSymbolReference(
const MCSymbol *Label,
784 bool ForceOffset =
false)
const;
797 emitDwarfStringOffset(S.
getEntry());
809 void emitDwarfUnitLength(
uint64_t Length,
const Twine &Comment)
const;
815 const Twine &Comment)
const;
819 unsigned Encoding)
const;
821 void emitCallSiteValue(
uint64_t Value,
unsigned Encoding)
const;
842 for (
const auto &Abbrev : Abbrevs)
843 emitDwarfAbbrev(*Abbrev);
846 emitULEB128(0,
"EOM(3)");
849 void emitDwarfAbbrev(
const DIEAbbrev &Abbrev)
const;
852 void emitDwarfDIE(
const DIE &Die)
const;
863 getCodeViewJumpTableInfo(
int JTI,
const MachineInstr *BranchInstr,
872 void emitCOFFReplaceableFunctionData(
Module &M);
875 void emitCOFFFeatureSymbol(
Module &M);
900 virtual bool PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
907 virtual bool PrintAsmMemoryOperand(
const MachineInstr *
MI,
unsigned OpNo,
912 virtual void emitInlineAsmStart()
const;
925 void emitVisibility(
MCSymbol *
Sym,
unsigned Visibility,
926 bool IsDefinition =
true)
const;
940 mutable unsigned LastFn = 0;
941 mutable unsigned Counter = ~0U;
943 bool DwarfUsesRelocationsAcrossSections =
false;
946 virtual void emitFunctionHeader();
949 virtual void emitFunctionHeaderComment();
958 const MDNode *LocMDNode =
nullptr,
967 unsigned addInlineAsmDiagBuffer(
StringRef AsmStr,
968 const MDNode *LocMDNode)
const;
982 void emitModuleIdents(
Module &M);
984 virtual void emitModuleCommandLines(
Module &M);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)
static std::optional< TypeSize > getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
static void emitInlineAsm(LLVMContext &C, BasicBlock *BB, StringRef AsmText)
static SDValue lowerConstant(SDValue Op, SelectionDAG &DAG, const RISCVSubtarget &Subtarget)
This file defines the SmallVector class.
support::ulittle16_t & Lo
support::ulittle16_t & Hi
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class is intended to be used as a driving class for all asm writers.
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
SmallVector< XRayFunctionEntry, 4 > Sleds
MapVector< MBBSectionID, MBBSectionRange > MBBSectionRanges
CFISection getModuleCFISectionType() const
Get the CFISection type for the module.
DwarfDebug * getDwarfDebug()
virtual const MCExpr * lowerConstantPtrAuth(const ConstantPtrAuth &CPA)
TargetMachine & TM
Target machine description.
DenseMap< const MachineBasicBlock *, SmallVector< MCSymbol *, 1 > > CurrentFnCallsiteEndSymbols
Vector of symbols marking the end of the callsites in the current function, keyed by their containing...
DwarfDebug * getDwarfDebug() const
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
MCSymbol * getFunctionBegin() const
virtual void emitMachOIFuncStubHelperBody(Module &M, const GlobalIFunc &GI, MCSymbol *LazyPointer)
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
SmallVector< std::unique_ptr< AsmPrinterHandler >, 2 > Handlers
virtual void emitStartOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the start of their fi...
bool hasDebugInfo() const
Returns true if valid debug info is present.
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
std::pair< const GlobalVariable *, unsigned > GOTEquivUsePair
Map global GOT equivalent MCSymbols to GlobalVariables and keep track of its number of uses by other ...
virtual void emitEndOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the end of their file...
virtual void emitMachOIFuncStubBody(Module &M, const GlobalIFunc &GI, MCSymbol *LazyPointer)
virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const
virtual const MCSymbol * getFunctionFrameSymbol() const
Return symbol for the function pseudo stack if the stack frame is not a register based.
void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const
Emit the 4-or 8-byte offset of a string from the start of its section.
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
MCContext & OutContext
This is the context for the output file that we are streaming.
virtual const MCSubtargetInfo * getIFuncMCSubtargetInfo() const
getSubtargetInfo() cannot be used where this is needed because we don't have a MachineFunction when w...
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
void setDwarfUsesRelocationsAcrossSections(bool Enable)
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
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...
virtual void emitFunctionDescriptor()
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
bool isVerbose() const
Return true if assembly output should contain comments.
MCSymbol * getFunctionEnd() const
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...
SmallVector< std::unique_ptr< AsmPrinterHandler >, 1 > EHHandlers
A handle to the EH info emitter (if present).
virtual void emitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
bool doesDwarfUseRelocationsAcrossSections() const
LLVM Basic Block Representation.
The address of a basic block.
ConstantArray - Constant Array Declarations.
A signed pointer, in the ptrauth sense.
This is an important base class in LLVM.
Dwarf abbreviation, describes the organization of a debug information object.
A structured debug information entry.
A parsed version of the target data layout string in and methods for querying it.
Collects and handles dwarf debug information.
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
const DwarfStringPoolEntry & getEntry() const
GCStrategy describes a garbage collector algorithm's code generation requirements,...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Streaming machine code generation interface.
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Abstract base class for all machine specific constantpool value subclasses.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Representation of each machine instruction.
This class contains meta information specific to a module.
MachineOperand class - Representation of each machine instruction operand.
This class implements a map that also provides access to all stored values in a deterministic order.
A Module instance is used to store all the information related to an LLVM module.
Analysis providing profile information.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A class that holds the constants that represent static data and their profile information and provide...
StringRef - Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Map a basic block section ID to the begin and end symbols of that section which determine the section...
llvm.global_ctors and llvm.global_dtors are arrays of Structor structs.
const MCSymbol * Function
const class Function * Fn
Description of the encoding of one expression Op.
Data for a string pool entry.