Go to the documentation of this file.
15 #ifndef LLVM_CODEGEN_ASMPRINTER_H
16 #define LLVM_CODEGEN_ASMPRINTER_H
42 class GCMetadataPrinter;
47 class MachineBasicBlock;
48 class MachineConstantPoolValue;
49 class MachineDominatorTree;
50 class MachineFunction;
52 class MachineJumpTableInfo;
53 class MachineLoopInfo;
54 class MachineModuleInfo;
55 class MachineOptimizationRemarkEmitter;
57 class MCCFIInstruction;
63 class MCSubtargetInfo;
65 class MCTargetOptions;
68 class PseudoProbeHandler;
72 class TargetLoweringObjectFile;
176 MCSymbol *CurrentSectionBeginSym =
nullptr;
180 std::unique_ptr<AddrLabelMap> AddrLabelSymbols;
183 void *GCMetadataPrinters =
nullptr;
189 std::unique_ptr<raw_fd_ostream> StackUsageStream;
203 std::unique_ptr<MachineDominatorTree> OwnedMDT;
206 std::unique_ptr<MachineLoopInfo> OwnedMLI;
221 bool HasSplitStack =
false;
226 bool HasNoSplitStack =
false;
287 std::vector<MCSymbol *> &Result);
471 unsigned MaxBytesToEmit = 0)
const;
618 unsigned Size)
const;
628 unsigned Size,
bool IsSectionRelative =
false)
const;
633 bool IsSectionRelative =
false)
const {
646 unsigned PadTo = 0)
const;
663 bool ForceOffset =
false)
const;
694 const Twine &Comment)
const;
698 unsigned Encoding)
const;
721 for (
const auto &Abbrev : Abbrevs)
782 bool IsDefinition =
true)
const;
796 mutable unsigned LastFn = 0;
797 mutable unsigned Counter = ~0U;
800 virtual void emitFunctionHeader();
803 virtual void emitFunctionHeaderComment();
809 const MDNode *LocMDNode =
nullptr,
818 unsigned addInlineAsmDiagBuffer(
StringRef AsmStr,
819 const MDNode *LocMDNode)
const;
829 void emitModuleIdents(
Module &M);
831 void emitModuleCommandLines(
Module &M);
848 #endif // LLVM_CODEGEN_ASMPRINTER_H
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...
bool isPositionIndependent() const
void emitLabelDifferenceAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) const
Emit something like ".uleb128 Hi-Lo".
MapVector< const MCSymbol *, GOTEquivUsePair > GlobalGOTEquivs
This is an optimization pass for GlobalISel generic memory operations.
MCSymbol * getFunctionEnd() const
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
StringRef TimerGroupDescription
A parsed version of the target data layout string in and methods for querying it.
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...
virtual void emitBasicBlockEnd(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the end of a basic block.
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
GCStrategy describes a garbage collector algorithm's code generation requirements,...
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, uint8_t Version=0)
MCSymbol * CurrentFnSymForSize
The symbol used to represent the start of the current function for the purpose of calculating its siz...
MCSymbol * createTempSymbol(const Twine &Name) const
DwarfDebug * getDwarfDebug()
Context object for machine code objects.
Map a basic block section ID to the begin and end symbols of that section which determine the section...
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
const MCAsmInfo * MAI
Target Asm Printer information.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void emitGlobalConstant(const DataLayout &DL, const Constant *CV)
Print a general LLVM constant to the .s file.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
@ Debug
Emit .debug_frame.
void emitPatchableFunctionEntries()
void emitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
const MCSymbol * Function
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
bool doFinalization(Module &M) override
Shut down the asmprinter.
void emitStackMaps(StackMaps &SM)
Emit the stack maps.
Abstract base class for all machine specific constantpool value subclasses.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
CFISection getFunctionCFISectionType(const Function &F) const
Get the CFISection type for a function.
unsigned int getDwarfOffsetByteSize() const
Returns 4 for DWARF32 and 8 for DWARF64.
void setDwarfVersion(uint16_t Version)
void emitDwarfOffset(const MCSymbol *Label, uint64_t Offset) const
Emit something like ".long Label + Offset" or ".quad Label + Offset" depending on the DWARF format.
llvm.global_ctors and llvm.global_dtors are arrays of Structor structs.
This class implements a map that also provides access to all stored values in a deterministic order.
A structured debug information entry.
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...
Instances of this class represent a single low-level machine instruction.
MachineOptimizationRemarkEmitter * ORE
Optimization remark emitter.
const class Function * Fn
MCSymbol * CurrentFnDescSym
The symbol for the current function descriptor on AIX.
void emitCallSiteOffset(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Encoding) const
Emit reference to a call site with a specified encoding.
String pool entry reference.
void emitBBAddrMapSection(const MachineFunction &MF)
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
LLVM Basic Block Representation.
void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const
Emit the 4-or 8-byte offset of a string from the start of its section.
std::pair< const GlobalVariable *, unsigned > GOTEquivUsePair
Map global GOT equivalent MCSymbols to GlobalVariables and keep track of its number of uses by other ...
Streaming machine code generation interface.
Dwarf abbreviation, describes the organization of a debug information object.
void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void addAsmPrinterHandler(HandlerInfo Handler)
Represent the analysis usage information of a pass.
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
virtual void emitStartOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the start of their fi...
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
MachineOperand class - Representation of each machine instruction operand.
ConstantArray - Constant Array Declarations.
This class contains meta information specific to a module.
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
MachineLoopInfo * MLI
This is a pointer to the current MachineLoopInfo.
DwarfDebug * getDwarfDebug() const
MCSymbol * CurrentFnSym
The symbol for the current function.
This class implements an extremely fast bulk output stream that can only output to a stream.
virtual void emitEndOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the end of their file...
CFISection getModuleCFISectionType() const
Get the CFISection type for the module.
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
MCSymbol * CurrentPatchableFunctionEntrySym
The symbol for the entry in __patchable_function_entires.
void emitInt8(int Value) const
Emit a byte directive and value.
This struct is a compact representation of a valid (non-zero power of two) alignment.
virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const
StringRef TimerDescription
MCSymbol * getFunctionBegin() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
virtual void emitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
std::unique_ptr< AsmPrinterHandler > Handler
std::vector< HandlerInfo > Handlers
A vector of all debug/EH info emitters we should use.
@ None
Do not emit either .eh_frame or .debug_frame.
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
virtual void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV)
void emitFrameAlloc(const MachineInstr &MI)
MCSymbol * GetJTSetSymbol(unsigned UID, unsigned MBBID) const
Return the symbol for the specified jump table .set FIXME: privatize to AsmPrinter.
void emitInt64(uint64_t Value) const
Emit a long long directive and value.
This is an important base class in LLVM.
Data for a string pool entry.
virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS, StringRef Code) const
Print information related to the specified machine instr that is independent of the operand,...
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
Representation of each machine instruction.
Collects and handles dwarf debug information.
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...
bool needsCFIForDebug() const
Since emitting CFI unwind information is entangled with supporting the exceptions,...
unsigned GetSizeOfEncodedValue(unsigned Encoding) const
Return the size of the encoding in bytes.
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
HandlerInfo(std::unique_ptr< AsmPrinterHandler > Handler, StringRef TimerName, StringRef TimerDescription, StringRef TimerGroupName, StringRef TimerGroupDescription)
virtual void emitJumpTableInfo()
Print assembly representations of the jump tables used by the current function to the current output ...
virtual const MCSymbol * getFunctionFrameSymbol() const
Return symbol for the function pseudo stack if the stack frame is not a register based.
MCSymbol * getSymbol(const GlobalValue *GV) const
Primary interface to the complete machine description for the target machine.
void emitDwarfUnitLength(uint64_t Length, const Twine &Comment) const
Emit a unit length field.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
MCSymbol * getMBBExceptionSym(const MachineBasicBlock &MBB)
MachineFunction * MF
The current machine function.
MCContext & OutContext
This is the context for the output file that we are streaming.
@ BasicBlock
Various leaf nodes.
void emitRemarksSection(remarks::RemarkStreamer &RS)
virtual void emitImplicitDef(const MachineInstr *MI) const
Targets can override this to customize the output of IMPLICIT_DEF instructions in verbose mode.
A Module instance is used to store all the information related to an LLVM module.
bool emitSpecialLLVMGlobal(const GlobalVariable *GV)
Check to see if the specified global is a special global used by LLVM.
void emitDwarfLengthOrOffset(uint64_t Value) const
Emit 32- or 64-bit value depending on the DWARF format.
void computeGlobalGOTEquivs(Module &M)
Unnamed constant global variables solely contaning a pointer to another globals variable act like a g...
MachineDominatorTree * MDT
This is a pointer to the current MachineDominatorTree.
void emitCFIInstruction(const MachineInstr &MI)
virtual void emitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
The address of a basic block.
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
void emitGlobalGOTEquivs()
Constant expressions using GOT equivalent globals may not be eligible for PC relative GOT entry conve...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
void takeDeletedSymbolsForFunction(const Function *F, std::vector< MCSymbol * > &Result)
If the specified function has had any references to address-taken blocks generated,...
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void preprocessXXStructorList(const DataLayout &DL, const Constant *List, SmallVector< Structor, 8 > &Structors)
This method gathers an array of Structors and then sorts them out by Priority.
SmallVector< XRayFunctionEntry, 4 > Sleds
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Machine Check Debug Module
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
unsigned int getUnitLengthFieldByteSize() const
Returns 4 for DWARF32 and 12 for DWARF64.
void emitStackUsage(const MachineFunction &MF)
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
static Align getGVAlignment(const GlobalObject *GV, const DataLayout &DL, Align InAlign=Align(1))
Return the alignment for the specified GV.
void emitPseudoProbe(const MachineInstr &MI)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void emitNops(unsigned N)
Emit N NOP instructions.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
struct HandlerInfo and Handlers permit users or target extended AsmPrinter to add their own handlers.
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
void emitStackSizeSection(const MachineFunction &MF)
uint16_t getDwarfVersion() const
This class is intended to be used as a driving class for all asm writers.
void emitVisibility(MCSymbol *Sym, unsigned Visibility, bool IsDefinition=true) const
This emits visibility information about symbol, if this is supported by the target.
void emitInt32(int Value) const
Emit a long directive and value.
virtual void emitTTypeReference(const GlobalValue *GV, unsigned Encoding)
Emit reference to a ttype global with a specified encoding.
MapVector< unsigned, MBBSectionRange > MBBSectionRanges
TargetMachine & TM
Target machine description.
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...
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
void emitFunctionBody()
This method emits the body and trailer for a function.
virtual void emitFunctionDescriptor()
MCSymbol * CurrentFnBegin
const DataLayout & getDataLayout() const
Return information about data layout.
void emitDwarfStringOffset(DwarfStringPoolEntry S) const
Emit the 4- or 8-byte offset of a string from the start of its section.
const MCSection * getCurrentSection() const
Return the current section we are emitting to.
void emitDwarfDIE(const DIE &Die) const
Recursively emit Dwarf DIE tree.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
void emitInitialRawDwarfLocDirective(const MachineFunction &MF)
Emits inital debug location directive.
void emitXRayTable()
Emit a table with all XRay instrumentation points.
void emitCallSiteValue(uint64_t Value, unsigned Encoding) const
Emit an integer value corresponding to the call site encoding.
bool isVerbose() const
Return true if assembly output should contain comments.
virtual void emitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Generic base class for all target subtargets.
unsigned getFunctionNumber() const
Return a unique ID for the current function.
void emitEncodingByte(unsigned Val, const char *Desc=nullptr) const
Emit a .byte 42 directive that corresponds to an encoding.
LLVM Value Representation.
void emitInt16(int Value) const
Emit a short directive and value.
virtual void emitXXStructorList(const DataLayout &DL, const Constant *List, bool IsCtor)
This method emits llvm.global_ctors or llvm.global_dtors list.
Base class for the full range of assembler expressions which are needed for parsing.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
void emit(int, MCStreamer *) const
virtual void emitConstantPool()
Print to the current output stream assembly representations of the constants in the constant pool MCP...
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.