#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFUNIT_H
#include "DwarfDebug.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/Target/TargetMachine.h"
#include <string>
namespace llvm {
class ConstantFP;
class ConstantInt;
class DwarfCompileUnit;
class MCDwarfDwoLineTable;
class MCSymbol;
class DwarfUnit : public DIEUnit {
protected:
const DICompileUnit *CUNode;
BumpPtrAllocator DIEValueAllocator;
AsmPrinter *Asm;
MCSymbol *EndLabel = nullptr;
DwarfDebug *DD;
DwarfFile *DU;
DIE *IndexTyDie = nullptr;
DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
std::vector<DIEBlock *> DIEBlocks;
std::vector<DIELoc *> DIELocs;
DenseMap<DIE *, const DINode *> ContainingTypeMap;
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW,
DwarfFile *DWU);
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal);
bool isShareableAcrossCUs(const DINode *D) const;
template <typename T>
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute,
dwarf::Form Form, T &&Value) {
if (Attribute != 0 && Asm->TM.Options.DebugStrictDwarf &&
DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute))
return;
Die.addValue(DIEValueAllocator,
DIEValue(Attribute, Form, std::forward<T>(Value)));
}
public:
AsmPrinter* getAsmPrinter() const { return Asm; }
MCSymbol *getEndLabel() const { return EndLabel; }
uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
const DICompileUnit *getCUNode() const { return CUNode; }
DwarfDebug &getDwarfDebug() const { return *DD; }
bool hasContent() const { return getUnitDie().hasChildren(); }
std::string getParentContextString(const DIScope *Context) const;
virtual void addGlobalName(StringRef Name, const DIE &Die,
const DIScope *Context) = 0;
virtual void addGlobalType(const DIType *Ty, const DIE &Die,
const DIScope *Context) = 0;
DIE *getDIE(const DINode *D) const;
DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc; }
void insertDIE(const DINode *Desc, DIE *D);
void insertDIE(DIE *D);
void addFlag(DIE &Die, dwarf::Attribute Attribute);
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
Optional<dwarf::Form> Form, uint64_t Integer);
void addUInt(DIEValueList &Block, dwarf::Form Form, uint64_t Integer);
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute,
Optional<dwarf::Form> Form, int64_t Integer);
void addSInt(DIELoc &Die, Optional<dwarf::Form> Form, int64_t Integer);
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form,
const MCSymbol *Label);
void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label);
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer);
void addOpAddress(DIELoc &Die, const MCSymbol *Sym);
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label);
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute,
const MCSymbol *Hi, const MCSymbol *Lo);
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry);
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry Entry);
void addDIETypeSignature(DIE &Die, uint64_t Signature);
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc);
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIEBlock *Block);
void addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
DIEBlock *Block);
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File);
void addSourceLine(DIE &Die, const DILocalVariable *V);
void addSourceLine(DIE &Die, const DIGlobalVariable *G);
void addSourceLine(DIE &Die, const DISubprogram *SP);
void addSourceLine(DIE &Die, const DILabel *L);
void addSourceLine(DIE &Die, const DIType *Ty);
void addSourceLine(DIE &Die, const DIObjCProperty *Ty);
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty);
void addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty);
void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned);
void addConstantValue(DIE &Die, uint64_t Val, const DIType *Ty);
void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val);
void addConstantFPValue(DIE &Die, const ConstantFP *CFP);
void addLinkageName(DIE &Die, StringRef LinkageName);
void addTemplateParams(DIE &Buffer, DINodeArray TParams);
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes);
void addAccess(DIE &Die, DINode::DIFlags Flags);
void addType(DIE &Entity, const DIType *Ty,
dwarf::Attribute Attribute = dwarf::DW_AT_type);
DIE *getOrCreateNameSpace(const DINamespace *NS);
DIE *getOrCreateModule(const DIModule *M);
DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false);
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
bool SkipSPAttributes = false);
DIE *createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty);
DIE *getOrCreateTypeDIE(const MDNode *TyNode);
DIE *getOrCreateContextDIE(const DIScope *Context);
void constructContainingTypeDIEs();
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args);
DIE &createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N = nullptr);
bool useSegmentedStringOffsetsTable() const {
return DD->useSegmentedStringOffsetsTable();
}
virtual unsigned getHeaderSize() const {
return sizeof(int16_t) + Asm->getDwarfOffsetByteSize() + sizeof(int8_t) + (DD->getDwarfVersion() >= 5 ? sizeof(int8_t)
: 0); }
virtual void emitHeader(bool UseOffsets) = 0;
void addStringOffsetsStart();
void addRnglistsBase();
virtual DwarfCompileUnit &getCU() = 0;
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy);
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
const MCSymbol *Lo);
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
const MCSymbol *Label, const MCSymbol *Sec);
void addAnnotation(DIE &Buffer, DINodeArray Annotations);
DIE *createTypeDIE(const DICompositeType *Ty);
protected:
~DwarfUnit();
DIE *getOrCreateStaticMemberDIE(const DIDerivedType *DT);
virtual unsigned getOrCreateSourceID(const DIFile *File) = 0;
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT);
private:
void constructTypeDIE(DIE &Buffer, const DIBasicType *BTy);
void constructTypeDIE(DIE &Buffer, const DIStringType *BTy);
void constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy);
void constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy);
void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR, DIE *IndexTy);
void constructGenericSubrangeDIE(DIE &Buffer, const DIGenericSubrange *SR,
DIE *IndexTy);
void constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy);
void constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy);
DIE &constructMemberDIE(DIE &Buffer, const DIDerivedType *DT);
void constructTemplateTypeParameterDIE(DIE &Buffer,
const DITemplateTypeParameter *TP);
void constructTemplateValueParameterDIE(DIE &Buffer,
const DITemplateValueParameter *TVP);
int64_t getDefaultLowerBound() const;
DIE *getIndexTyDie();
void setIndexTyDie(DIE *D) { IndexTyDie = D; }
virtual void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) = 0;
void updateAcceleratorTables(const DIScope *Context, const DIType *Ty,
const DIE &TyDIE);
virtual bool isDwoUnit() const = 0;
const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
};
class DwarfTypeUnit final : public DwarfUnit {
uint64_t TypeSignature;
const DIE *Ty;
DwarfCompileUnit &CU;
MCDwarfDwoLineTable *SplitLineTable;
bool UsedLineTable = false;
unsigned getOrCreateSourceID(const DIFile *File) override;
void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override;
bool isDwoUnit() const override;
public:
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW,
DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr);
void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
void setType(const DIE *Ty) { this->Ty = Ty; }
void emitHeader(bool UseOffsets) override;
unsigned getHeaderSize() const override {
return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + Asm->getDwarfOffsetByteSize(); }
void addGlobalName(StringRef Name, const DIE &Die,
const DIScope *Context) override;
void addGlobalType(const DIType *Ty, const DIE &Die,
const DIScope *Context) override;
DwarfCompileUnit &getCU() override { return CU; }
};
} #endif