Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h
35271 views
//===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H9#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H1011#include "DwarfStringPool.h"12#include "llvm/ADT/DenseMap.h"13#include "llvm/ADT/SmallVector.h"14#include "llvm/ADT/StringRef.h"15#include "llvm/CodeGen/DIE.h"16#include "llvm/Support/Allocator.h"17#include <map>18#include <memory>19#include <utility>2021namespace llvm {2223class AsmPrinter;24class DbgEntity;25class DbgVariable;26class DbgLabel;27class DINode;28class DILocalScope;29class DwarfCompileUnit;30class DwarfUnit;31class LexicalScope;32class MCSection;33class MDNode;3435// Data structure to hold a range for range lists.36struct RangeSpan {37const MCSymbol *Begin;38const MCSymbol *End;39};4041struct RangeSpanList {42// Index for locating within the debug_range section this particular span.43MCSymbol *Label;44const DwarfCompileUnit *CU;45// List of ranges.46SmallVector<RangeSpan, 2> Ranges;47};4849class DwarfFile {50// Target of Dwarf emission, used for sizing of abbreviations.51AsmPrinter *Asm;5253BumpPtrAllocator AbbrevAllocator;5455// Used to uniquely define abbreviations.56DIEAbbrevSet Abbrevs;5758// A pointer to all units in the section.59SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;6061DwarfStringPool StrPool;6263// List of range lists for a given compile unit, separate from the ranges for64// the CU itself.65SmallVector<RangeSpanList, 1> CURangeLists;6667/// DWARF v5: The symbol that designates the start of the contribution to68/// the string offsets table. The contribution is shared by all units.69MCSymbol *StringOffsetsStartSym = nullptr;7071/// DWARF v5: The symbol that designates the base of the range list table.72/// The table is shared by all units.73MCSymbol *RnglistsTableBaseSym = nullptr;7475/// The variables of a lexical scope.76struct ScopeVars {77/// We need to sort Args by ArgNo and check for duplicates. This could also78/// be implemented as a list or vector + std::lower_bound().79std::map<unsigned, DbgVariable *> Args;80SmallVector<DbgVariable *, 8> Locals;81};82/// Collection of DbgVariables of each lexical scope.83DenseMap<LexicalScope *, ScopeVars> ScopeVariables;8485/// Collection of DbgLabels of each lexical scope.86using LabelList = SmallVector<DbgLabel *, 4>;87DenseMap<LexicalScope *, LabelList> ScopeLabels;8889// Collection of abstract subprogram DIEs.90DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;91DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;9293/// Maps MDNodes for type system with the corresponding DIEs. These DIEs can94/// be shared across CUs, that is why we keep the map here instead95/// of in DwarfCompileUnit.96DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;9798public:99DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);100101const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {102return CUs;103}104105std::pair<uint32_t, RangeSpanList *> addRange(const DwarfCompileUnit &CU,106SmallVector<RangeSpan, 2> R);107108/// getRangeLists - Get the vector of range lists.109const SmallVectorImpl<RangeSpanList> &getRangeLists() const {110return CURangeLists;111}112113/// Compute the size and offset of a DIE given an incoming Offset.114unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);115116/// Compute the size and offset of all the DIEs.117void computeSizeAndOffsets();118119/// Compute the size and offset of all the DIEs in the given unit.120/// \returns The size of the root DIE.121unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);122123/// Add a unit to the list of CUs.124void addUnit(std::unique_ptr<DwarfCompileUnit> U);125126/// Emit all of the units to the section listed with the given127/// abbreviation section.128void emitUnits(bool UseOffsets);129130/// Emit the given unit to its section.131void emitUnit(DwarfUnit *TheU, bool UseOffsets);132133/// Emit a set of abbreviations to the specific section.134void emitAbbrevs(MCSection *);135136/// Emit all of the strings to the section given. If OffsetSection is137/// non-null, emit a table of string offsets to it. If UseRelativeOffsets138/// is false, emit absolute offsets to the strings. Otherwise, emit139/// relocatable references to the strings if they are supported by the target.140void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr,141bool UseRelativeOffsets = false);142143/// Returns the string pool.144DwarfStringPool &getStringPool() { return StrPool; }145146MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }147void setStringOffsetsStartSym(MCSymbol *Sym) { StringOffsetsStartSym = Sym; }148149MCSymbol *getRnglistsTableBaseSym() const { return RnglistsTableBaseSym; }150void setRnglistsTableBaseSym(MCSymbol *Sym) { RnglistsTableBaseSym = Sym; }151152void addScopeVariable(LexicalScope *LS, DbgVariable *Var);153154void addScopeLabel(LexicalScope *LS, DbgLabel *Label);155156DenseMap<LexicalScope *, ScopeVars> &getScopeVariables() {157return ScopeVariables;158}159160DenseMap<LexicalScope *, LabelList> &getScopeLabels() {161return ScopeLabels;162}163164DenseMap<const DILocalScope *, DIE *> &getAbstractScopeDIEs() {165return AbstractLocalScopeDIEs;166}167168DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {169return AbstractEntities;170}171172void insertDIE(const MDNode *TypeMD, DIE *Die) {173DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));174}175176DIE *getDIE(const MDNode *TypeMD) {177return DITypeNodeToDieMap.lookup(TypeMD);178}179};180181} // end namespace llvm182183#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H184185186