22 :
DwarfUnit(UID, dwarf::DW_TAG_compile_unit, Node, A, DW, DWU),
23 Skeleton(nullptr), BaseAddress(nullptr) {
79 const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V);
81 CE->
getOpcode() != Instruction::GetElementPtr)
86 if (!isa<GlobalValue>(Ptr) ||
87 !isa<StructType>(cast<PointerType>(Ptr->
getType())->getElementType()))
122 DeclContext =
resolve(SDMDecl->getScope());
123 assert(SDMDecl->isStaticMember() &&
"Expected static member decl");
148 bool addToAccelTable =
false;
150 addToAccelTable =
true;
153 if (
Global->isThreadLocal()) {
156 assert((PointerSize == 4 || PointerSize == 8) &&
157 "Add support for other sizes if necessary");
162 PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u);
175 : dwarf::DW_OP_form_tls_address);
184 dyn_cast_or_null<ConstantInt>(GV->
getVariable())) {
187 addToAccelTable =
true;
190 Value *Ptr = CE->getOperand(0);
202 if (addToAccelTable) {
221 if (CURanges.empty() || !SameAsPrevCU ||
222 (&CURanges.back().getEnd()->getSection() !=
224 CURanges.push_back(Range);
228 CURanges.back().setEnd(Range.
getEnd());
264 assert(Begin &&
"Begin label should not be null!");
265 assert(End &&
"End label should not be null!");
266 assert(Begin->
isDefined() &&
"Invalid starting label");
267 assert(End->
isDefined() &&
"Invalid end label");
288 if (!includeMinimalInlineScopes()) {
311 "Only handle inlined subprograms here, use "
312 "constructSubprogramScopeDIE for non-inlined "
332 unsigned ChildScopeCount;
339 if (!includeMinimalInlineScopes()) {
348 if (Children.size() == ChildScopeCount) {
349 FinalChildren.
insert(FinalChildren.
end(),
350 std::make_move_iterator(Children.begin()),
351 std::make_move_iterator(Children.end()));
355 assert(ScopeDIE &&
"Scope DIE should not be null.");
359 for (
auto &
I : Children)
362 FinalChildren.
push_back(std::move(ScopeDIE));
395 (Skeleton ? Skeleton :
this)->CURangeLists.push_back(std::move(
List));
400 if (Ranges.
size() == 1) {
401 const auto &single = Ranges.
front();
426 assert(OriginDIE &&
"Unable to find original DIE for an inlined subprogram.");
463 auto D = constructVariableDIEImpl(DV, Abstract);
468 DIE *DwarfCompileUnit::constructVariableDIEImpl(
const DbgVariable &DV,
487 if (
const MachineInstr *DVInsn = DV.
getMInsn()) {
488 assert(DVInsn->getNumOperands() == 4);
489 if (DVInsn->getOperand(0).isReg()) {
490 const MachineOperand RegOp = DVInsn->getOperand(0);
492 if (DVInsn->getOperand(1).isImm()) {
493 MachineLocation Location(RegOp.getReg(),
494 DVInsn->getOperand(1).getImm());
496 }
else if (RegOp.getReg())
498 }
else if (DVInsn->getOperand(0).isImm())
500 else if (DVInsn->getOperand(0).isFPImm())
502 else if (DVInsn->getOperand(0).isCImm())
515 DIEDwarfExpression DwarfExpr(*
Asm, *
this, *Loc);
517 unsigned FrameReg = 0;
519 int Offset = TFI->getFrameIndexReference(*
Asm->
MF, FI, FrameReg);
521 "Wrong number of expressions");
522 DwarfExpr.AddMachineRegIndirect(FrameReg, Offset);
523 DwarfExpr.AddExpression((*Expr)->expr_op_begin(), (*Expr)->expr_op_end());
533 DIE *&ObjectPointer) {
542 unsigned *ChildScopeCount) {
543 DIE *ObjectPointer =
nullptr;
548 unsigned ChildCountWithoutScopes = Children.
size();
554 *ChildScopeCount = Children.
size() - ChildCountWithoutScopes;
556 return ObjectPointer;
581 if (FnArgs.
size() > 1 && !FnArgs[FnArgs.
size() - 1] &&
582 !includeMinimalInlineScopes())
594 for (
auto &
I : Children)
597 return ObjectPointer;
610 if (includeMinimalInlineScopes())
616 else if (
auto *SPDecl =
SP->getDeclaration()) {
624 AbsDef = &
createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE,
nullptr);
627 if (!includeMinimalInlineScopes())
639 if (
auto *NS = dyn_cast<DINamespace>(Entity))
641 else if (
auto *M = dyn_cast<DIModule>(Entity))
643 else if (
auto *
SP = dyn_cast<DISubprogram>(Entity))
645 else if (
auto *
T = dyn_cast<DIType>(Entity))
647 else if (
auto *GV = dyn_cast<DIGlobalVariable>(Entity))
650 EntityDie =
getDIE(Entity);
669 if (!D && !includeMinimalInlineScopes())
680 assert(SP &&
"CU's subprogram list contains a non-subprogram");
681 assert(SP->isDefinition() &&
682 "CU's subprogram list contains a subprogram declaration");
683 auto Variables = SP->getVariables();
684 if (Variables.size() == 0)
695 SPDIE->
addChild(std::move(VariableDie));
712 if (includeMinimalInlineScopes())
715 GlobalNames[FullName] = &Die;
721 if (includeMinimalInlineScopes())
724 GlobalTypes[FullName] = &Die;
745 if (Location.
isReg())
773 DwarfExpr.
AddExpression(Expr->expr_op_begin(), Expr->expr_op_end());
809 auto *SPDecl = SP->getDeclaration();
815 bool DwarfCompileUnit::isDwoUnit()
const {
819 bool DwarfCompileUnit::includeMinimalInlineScopes()
const {
StringRef getName() const
void push_back(const T &Elt)
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
const DILocalScope * getScopeNode() const
unsigned getUniqueID() const
const MachineInstr * getMInsn() const
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
const DICompileUnit * getCUNode() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
MCSymbol * getSymbol(const GlobalValue *GV) const
DIELoc - Represents an expression location.
unsigned getDebugLocListIndex() const
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
const DataLayout & getDataLayout() const
Return information about data layout.
const MachineFunction * getCurrentFunction() const
void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End)
unsigned getNumOperands() const
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Collects and handles dwarf debug information.
const MachineFunction * MF
The current machine function.
SmallVectorImpl< InsnRange > & getRanges()
void collectDeadVariables(const DISubprogram *SP)
unsigned getEmissionKind() const
std::string str() const
str - Get the contents as an std::string.
DenseMap< LexicalScope *, SmallVector< DbgVariable *, 8 > > & getScopeVariables()
StringRef getName() const
DIScope * getScope() const
bool hasComplexAddress() const
bool AddMachineRegExpression(const DIExpression *Expr, unsigned MachineReg, unsigned PieceOffsetInBits=0)
Emit an entire expression on top of a machine register location.
void reserve(size_type N)
DIELocList - Represents a pointer to a location list in the debug_loc section.
LexicalScope - This class is used to track scope information.
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
bool useGNUTLSOpcode() const
Returns whether to use DW_OP_GNU_push_tls_address, instead of the standard DW_OP_form_tls_address opc...
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
const DILocation * getInlinedAt() const
DIE & updateSubprogramScopeDIE(const DISubprogram *SP)
Find DIE for the given subprogram and attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes...
AsmPrinter * Asm
Target of Dwarf emission.
DIE * constructLexicalScopeDIE(LexicalScope *Scope)
Construct new DW_TAG_lexical_block for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels...
DIE * getOrCreateTypeDIE(const MDNode *N)
Find existing DIE or create new DIE for the given type.
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block)
Add block data.
virtual void emitHeader(bool UseOffsets)
Emit the header for this unit, not including the initial length field.
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
SmallVectorImpl< LexicalScope * > & getChildren()
void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie)
DIE * createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE)
bool isArtificial() const
Return true if DbgVariable is artificial.
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
T * resolve(TypedDINodeRef< T > Ref) const
Look in the DwarfDebug map for the MDNode that corresponds to the reference.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
void addConstantFPValue(DIE &Die, const MachineOperand &MO)
Add constant value entry in variable DIE.
void attachRangesOrLowHighPC(DIE &D, SmallVector< RangeSpan, 2 > Ranges)
value_iterator addValue(BumpPtrAllocator &Alloc, DIEValue Value)
addValue - Add a value and attributes to a DIE.
const ArrayRef< int > getFrameIndex() const
bool addRegisterOffset(DIELoc &TheDie, unsigned Reg, int64_t Offset)
Add register offset.
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null. ...
uint64_t getIndexedOffset(Type *Ty, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
StringRef getFilename() const
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
StringRef getName() const
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
void addScopeRangeList(DIE &ScopeDIE, SmallVector< RangeSpan, 2 > Range)
A helper function to construct a RangeSpanList for a given lexical scope.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
AddressPool & getAddressPool()
LexicalScope * getParent() const
void constructScopeDIE(LexicalScope *Scope, SmallVectorImpl< DIE * > &FinalChildren)
ConstantExpr - a constant value that is initialized with an expression using other constant values...
void addComplexAddress(const DbgVariable &DV, DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Start with the address based on the location provided, and generate the DWARF information necessary t...
iterator_range< ImportedEntityMap::const_iterator > findImportedEntitiesForScope(const MDNode *Scope) const
void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr)
Add a Dwarf expression attribute data and value.
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
This class is used to track local variable information.
const ArrayRef< const DIExpression * > getExpression() const
void applySubprogramAttributesToDefinition(const DISubprogram *SP, DIE &SPDie)
virtual const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info...
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
DIScopeRef getScope() const
void addAddress(DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Add an address attribute to a die based on the location provided.
DIE * getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV)
getOrCreateGlobalVariableDIE - get or create global variable DIE.
DIE * getOrCreateNameSpace(const DINamespace *NS)
bool addRegisterOpPiece(DIELoc &TheDie, unsigned Reg, unsigned SizeInBits=0, unsigned OffsetInBits=0)
Add register operand.
DIE & addChild(DIE *Child)
Add a child to the DIE.
DIScope * getScope() const
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
MCSection * getDwarfLineSection() const
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
This dwarf writer support class manages information associated with a source file.
const DIType * getType() const
void applyStmtList(DIE &D)
Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
StringRef getName() const
const MCAsmInfo * MAI
Target Asm Printer information.
void addSourceLine(DIE &Die, unsigned Line, StringRef File, StringRef Directory)
Add location information to specified debug information entry.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isLocalToUnit() const
DIE - A structured debug information entry.
This class is intended to be used as a driving class for all asm writers.
DIEExpr - An expression DIE.
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Value * getOperand(unsigned i) const
void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLocalLabelAddress - Add a dwarf label attribute data and value using DW_FORM_addr only...
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope)
bool isAbstractScope() const
DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
addSectionLabel - Add a Dwarf section label attribute data and value.
DIE * constructImportedEntityDIE(const DIImportedEntity *Module)
Construct import_module DIE.
DINodeRef getEntity() const
Helper used to pair up a symbol and its DWARF compile unit.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
DIE * constructVariableDIE(DbgVariable &DV, bool Abstract=false)
constructVariableDIE - Construct a DIE for the given DbgVariable.
DITypeRef getType() const
An imported module (C++ using directive or similar).
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Base class for scope-like contexts.
DIEDelta - A simple label difference DIE.
StringRef getDisplayName() const
StringRef getDirectory() const
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
virtual const TargetFrameLowering * getFrameLowering() const
unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override
Look up the source ID with the given directory and source file names.
DIE * constructInlinedScopeDIE(LexicalScope *Scope)
This scope represents inlined body of a function.
bool AddMachineRegIndirect(unsigned MachineReg, int Offset=0)
Emit an indirect dwarf register operation for the given machine register.
void setPrevCU(const DwarfCompileUnit *PrevCU)
This is the shared class of boolean and integer constants.
void constructSubprogramScopeDIE(LexicalScope *Scope)
Construct a DIE for this subprogram scope.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
MCSymbol * getBeginSymbol()
MCSymbol * createTempSymbol(const Twine &Name) const
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
void addAccelName(StringRef Name, const DIE &Die)
const DILocalVariable * getVariable() const
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
iterator insert(iterator I, T &&Elt)
SmallPtrSet< const MDNode *, 16 > & getProcessedSPNodes()
void addRange(RangeSpan Range)
addRange - Add an address range to the list of ranges for this unit.
DIE::value_iterator addLabel(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
DIEInteger - An integer value DIE.
static bool isPhysicalRegister(unsigned Reg)
isPhysicalRegister - Return true if the specified register number is in the physical register namespa...
DIE & createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N=nullptr)
Create a DIE with the given Tag, add the DIE to its parent, and call insertDIE if MD is not null...
MCSymbol * getFunctionBegin() const
void addVariableAddress(const DbgVariable &DV, DIE &Die, MachineLocation Location)
Add DW_AT_location attribute for a DbgVariable based on provided MachineLocation. ...
MCSymbol * getFunctionEnd() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
DIE * getOrCreateModule(const DIModule *M)
void addBlockByrefAddress(const DbgVariable &DV, DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Start with the address based on the location provided, and generate the DWARF information necessary t...
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
dwarf::Tag getTag() const
DwarfExpression implementation for singular DW_AT_location.
void addSubprogramNames(const DISubprogram *SP, DIE &Die)
static const ConstantExpr * getMergedGlobalExpr(const Value *V)
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
BumpPtrAllocator DIEValueAllocator
bool isBlockByrefVariable() const
bool isObjectPointer() const
StringRef getName() const
LLVM Value Representation.
DIDerivedType * getStaticDataMemberDeclaration() const
void addGlobalName(StringRef Name, DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
DIE & UnitDie
Unit debug information entry.
MCSection * getDwarfRangesSection() const
bool isDefinition() const
Constant * getVariable() const
void addOpAddress(DIELoc &Die, const MCSymbol *Label)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index)
Add a Dwarf loclistptr attribute data and value.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal=false)
void finishSubprogramDefinition(const DISubprogram *SP)
unsigned getDwarfVersion() const
Returns the Dwarf Version.
void addUInt(DIE &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
StringRef getLinkageName() const
bool doesDwarfUseRelocationsAcrossSections() const
void AddExpression(DIExpression::expr_op_iterator I, DIExpression::expr_op_iterator E, unsigned PieceOffsetInBits=0)
Emit a the operations remaining the DIExpressionIterator I.
const MCSymbol * getEnd() const
void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLabelAddress - Add a dwarf label attribute data and value using either DW_FORM_addr or DW_FORM_GNU...
bool empty() const
empty - Check if the string is empty.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
DIE * createScopeChildrenDIE(LexicalScope *Scope, SmallVectorImpl< DIE * > &Children, unsigned *ChildScopeCount=nullptr)
A helper function to create children of a Scope DIE.