14#ifndef LLVM_MC_MCDWARF_H
15#define LLVM_MC_MCDWARF_H
58 bool UseRelocs =
false;
117#define DWARF2_LINE_DEFAULT_IS_STMT 1
119#define DWARF2_FLAG_IS_STMT (1 << 0)
120#define DWARF2_FLAG_BASIC_BLOCK (1 << 1)
121#define DWARF2_FLAG_PROLOGUE_END (1 << 2)
122#define DWARF2_FLAG_EPILOGUE_BEGIN (1 << 3)
128 MCDwarfLoc(
unsigned fileNum,
unsigned line,
unsigned column,
unsigned flags,
129 unsigned isa,
unsigned discriminator)
130 : FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(
isa),
131 Discriminator(discriminator) {}
163 assert(column <= UINT16_MAX);
169 assert(flags <= UINT8_MAX);
181 Discriminator = discriminator;
200 MCSymbol *lineStreamLabel =
nullptr,
201 SMLoc streamLabelDefLoc = {})
242 MCLineDivisions[Sec].push_back(LineEntry);
250 using iterator = MCDwarfLineEntryCollection::iterator;
261 return MCLineDivisions;
288 bool HasAllMD5 =
true;
289 bool HasAnyMD5 =
false;
296 std::optional<MD5::MD5Result> Checksum,
297 std::optional<StringRef> Source,
299 unsigned FileNumber = 0);
300 LLVM_ABI std::pair<MCSymbol *, MCSymbol *>
302 std::optional<MCDwarfLineStr> &LineStr)
const;
303 LLVM_ABI std::pair<MCSymbol *, MCSymbol *>
306 std::optional<MCDwarfLineStr> &LineStr)
const;
312 HasAllMD5 &= MD5Used;
313 HasAnyMD5 |= MD5Used;
316 return MCDwarfFiles.empty() || (HasAllMD5 == HasAnyMD5);
320 std::optional<MD5::MD5Result> Checksum,
321 std::optional<StringRef> Source) {
323 RootFile.Name = std::string(FileName);
340 void emitV2FileDirTables(
MCStreamer *MCOS)
const;
342 std::optional<MCDwarfLineStr> &LineStr)
const;
347 bool HasSplitLineTable =
false;
351 std::optional<MD5::MD5Result> Checksum,
352 std::optional<StringRef> Source) {
353 if (!Header.RootFile.Name.empty())
355 Header.setRootFile(Directory, FileName, Checksum, Source);
359 std::optional<MD5::MD5Result> Checksum,
360 uint16_t DwarfVersion, std::optional<StringRef> Source) {
361 HasSplitLineTable =
true;
362 return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source,
380 std::optional<MCDwarfLineStr> &LineStr)
const;
393 std::optional<MD5::MD5Result> Checksum,
394 std::optional<StringRef> Source,
396 unsigned FileNumber = 0);
398 std::optional<MD5::MD5Result> Checksum,
399 std::optional<StringRef> Source,
uint16_t DwarfVersion,
400 unsigned FileNumber = 0) {
402 DwarfVersion, FileNumber));
406 std::optional<MD5::MD5Result> Checksum,
407 std::optional<StringRef> Source) {
408 Header.CompilationDir = std::string(Directory);
409 Header.RootFile.Name = std::string(FileName);
410 Header.RootFile.DirIndex = 0;
411 Header.RootFile.Checksum = Checksum;
412 Header.RootFile.Source = Source;
413 Header.trackMD5Usage(Checksum.has_value());
414 Header.HasAnySource |= Source.has_value();
419 bool hasRootFile()
const {
return !Header.RootFile.Name.empty(); }
432 Header.Label = Label;
436 return Header.MCDwarfDirs;
440 return Header.MCDwarfDirs;
444 return Header.MCDwarfFiles;
448 return Header.MCDwarfFiles;
452 return MCLineSections;
455 return MCLineSections;
463 int64_t LineDelta,
uint64_t AddrDelta,
468 int64_t LineDelta,
uint64_t AddrDelta);
496 : Name(
name), FileNumber(fileNumber), LineNumber(lineNumber),
510class MCCFIInstruction {
546 unsigned Reg2 = std::numeric_limits<unsigned>::max(),
547 unsigned AddrSpace = 0)
564 std::variant<CommonFields, EscapeFields, LabelFields> ExtraFields;
568 template <
class FieldsType>
570 : Label(L), ExtraFields(
std::forward<FieldsType>(EF)), Operation(
Op),
634 unsigned Register2,
SMLoc Loc = {}) {
635 return {
OpRegister, L, CommonFields{Register1, 0, Register2}, Loc};
691 EscapeFields{std::vector<char>(Vals.
begin(), Vals.
end()),
723 return std::get<CommonFields>(ExtraFields).Register;
728 return std::get<CommonFields>(ExtraFields).Register2;
733 return std::get<CommonFields>(ExtraFields).AddressSpace;
741 return std::get<CommonFields>(ExtraFields).Offset;
746 return std::get<LabelFields>(ExtraFields).CfiLabel;
751 auto &Values = std::get<EscapeFields>(ExtraFields).Values;
752 return StringRef(&Values[0], Values.size());
757 return std::get<EscapeFields>(ExtraFields).Comment;
776 unsigned RAReg =
static_cast<unsigned>(INT_MAX);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file implements a map that provides insertion order iteration.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Tagged union holding either a T or a Error.
Generic interface to target specific assembler backends.
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
MCSymbol * getLabel() const
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_undefined From now on the previous value of Register can't be restored anymore.
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int64_t Size, SMLoc Loc={})
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
unsigned getAddressSpace() const
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
unsigned getRegister2() const
static MCCFIInstruction createLLVMDefAspaceCfa(MCSymbol *L, unsigned Register, int64_t Offset, unsigned AddressSpace, SMLoc Loc)
.cfi_llvm_def_aspace_cfa defines the rule for computing the CFA to be the result of evaluating the DW...
unsigned getRegister() const
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2, SMLoc Loc={})
.cfi_register Previous value of Register1 is saved in register Register2.
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction createValOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_val_offset Previous value of Register is offset Offset from the current CFA register.
static MCCFIInstruction createNegateRAStateWithPC(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
static MCCFIInstruction createNegateRAState(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state AArch64 negate RA state.
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
OpType getOperation() const
StringRef getComment() const
StringRef getValues() const
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
static MCCFIInstruction createWindowSave(MCSymbol *L, SMLoc Loc={})
.cfi_window_save SPARC register window is saved.
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
MCSymbol * getCfiLabel() const
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_same_value Current value of Register is the same as in the previous frame.
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register.
int64_t getOffset() const
static MCCFIInstruction createLabel(MCSymbol *L, MCSymbol *CfiLabel, SMLoc Loc)
Context object for machine code objects.
void maybeSetRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
unsigned getFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, std::optional< StringRef > Source)
LLVM_ABI void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
static LLVM_ABI void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Instances of this class represent the line information for the dwarf line table entries.
void setEndLabel(MCSymbol *EndLabel)
MCSymbol * getLabel() const
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc, MCSymbol *lineStreamLabel=nullptr, SMLoc streamLabelDefLoc={})
MCSymbol * LineStreamLabel
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
LLVM_ABI void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
LLVM_ABI MCDwarfLineStr(MCContext &Ctx)
Construct an instance that can emit .debug_line_str (for use in a normal v5 line table).
LLVM_ABI SmallString< 0 > getFinalizedData()
Returns finalized section.
LLVM_ABI void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
LLVM_ABI size_t addString(StringRef Path)
Adds path Path to the line string.
bool isMD5UsageConsistent() const
const MCDwarfFile & getRootFile() const
void setLabel(MCSymbol *Label)
const SmallVectorImpl< std::string > & getMCDwarfDirs() const
LLVM_ABI void endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS, SMLoc DefLoc, StringRef Name)
void setRootFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
MCDwarfFile & getRootFile()
const MCLineSection & getMCLineSections() const
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
unsigned getFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
SmallVectorImpl< std::string > & getMCDwarfDirs()
SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles()
MCLineSection & getMCLineSections()
MCSymbol * getLabel() const
static LLVM_ABI void emitOne(MCStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
LLVM_ABI void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Instances of this class represent the information from a dwarf .loc directive.
friend class MCDwarfLineEntry
unsigned getLine() const
Get the Line of this MCDwarfLoc.
void setLine(unsigned line)
Set the Line of this MCDwarfLoc.
unsigned getIsa() const
Get the Isa of this MCDwarfLoc.
void setIsa(unsigned isa)
Set the Isa of this MCDwarfLoc.
void setDiscriminator(unsigned discriminator)
Set the Discriminator of this MCDwarfLoc.
unsigned getFlags() const
Get the Flags of this MCDwarfLoc.
unsigned getColumn() const
Get the Column of this MCDwarfLoc.
void setFlags(unsigned flags)
Set the Flags of this MCDwarfLoc.
unsigned getDiscriminator() const
Get the Discriminator of this MCDwarfLoc.
void setColumn(unsigned column)
Set the Column of this MCDwarfLoc.
unsigned getFileNum() const
Get the FileNum of this MCDwarfLoc.
void setFileNum(unsigned fileNum)
Set the FileNum of this MCDwarfLoc.
static LLVM_ABI void Emit(MCStreamer *MCOS)
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, MCSymbol *label)
StringRef getName() const
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
MCSymbol * getLabel() const
unsigned getLineNumber() const
unsigned getFileNumber() const
Instances of this class represent the line information for a compile unit where machine instructions ...
const MCLineDivisionMap & getMCLineEntries() const
LLVM_ABI void addEndEntry(MCSymbol *EndLabel)
MapVector< MCSection *, MCDwarfLineEntryCollection > MCLineDivisionMap
MCDwarfLineEntryCollection::const_iterator const_iterator
MCDwarfLineEntryCollection::iterator iterator
void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec)
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
Streaming object file generation interface.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Streaming machine code generation interface.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
This class implements a map that also provides access to all stored values in a deterministic order.
Wrapper class representing virtual and physical registers.
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Utility for building string tables with deduplicated suffixes.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI MCSymbol * emitListsTableHeaderStart(MCStreamer &S)
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
DWARFExpression::Operation Op
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Implement std::hash so that hash_code can be used in STL containers.
CommonFields(unsigned Reg, int64_t Off=0, unsigned Reg2=std::numeric_limits< unsigned >::max(), unsigned AddrSpace=0)
std::vector< char > Values
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
std::optional< StringRef > Source
The source code of the file.
MCDwarfFrameInfo()=default
const MCSymbol * Personality
unsigned PersonalityEncoding
uint64_t CompactUnwindEncoding
std::vector< MCCFIInstruction > Instructions
unsigned CurrentCfaRegister
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
int8_t DWARF2LineBase
Minimum line offset in a special line info.