Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 21 additions & 65 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
addBlock(Die, Attribute, Block->BestForm(), Block);
}

void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
const DIExpression *Expr) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Die, Attribute, DwarfExpr.finalize());
}

void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, unsigned Column,
const DIFile *File) {
if (Line == 0)
Expand Down Expand Up @@ -824,27 +833,14 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);
} else if (DIExpression *Expr = STy->getStringLengthExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
// This is to describe the memory location of the
// length of a Fortran deferred length string, so
// lock it down as such.
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_string_length, Expr);
} else {
uint64_t Size = STy->getSizeInBits() >> 3;
addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
}

if (DIExpression *Expr = STy->getStringLocationExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
// This is to describe the memory location of the
// string, so lock it down as such.
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_data_location, Expr);
}

if (STy->getEncoding()) {
Expand Down Expand Up @@ -1207,11 +1203,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
addDIEEntry(Buffer, dwarf::DW_AT_bit_size, *VarDIE);
} else if (auto *Exp =
dyn_cast_or_null<DIExpression>(CTy->getRawSizeInBits())) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Exp);
addBlock(Buffer, dwarf::DW_AT_bit_size, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_bit_size, Exp);
} else {
uint64_t Size = CTy->getSizeInBits() >> 3;
// Add size if non-zero (derived types might be zero-sized.)
Expand Down Expand Up @@ -1607,11 +1599,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &DW_Subrange, const DISubrangeType *SR,
if (auto *VarDIE = getDIE(BV))
addDIEEntry(DW_Subrange, Attr, *VarDIE);
} else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(BE);
addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
addBlock(DW_Subrange, Attr, BE);
} else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
if (Attr == dwarf::DW_AT_GNU_bias) {
if (BI->getSExtValue() != 0)
Expand Down Expand Up @@ -1649,11 +1637,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {
if (auto *VarDIE = getDIE(BV))
addDIEEntry(DW_Subrange, Attr, *VarDIE);
} else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(BE);
addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
addBlock(DW_Subrange, Attr, BE);
} else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
if (Attr == dwarf::DW_AT_count) {
if (BI->getSExtValue() != -1)
Expand Down Expand Up @@ -1699,11 +1683,7 @@ void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
BE->getElement(1));
} else {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(BE);
addBlock(DwGenericSubrange, Attr, DwarfExpr.finalize());
addBlock(DwGenericSubrange, Attr, BE);
}
}
};
Expand Down Expand Up @@ -1770,44 +1750,28 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);
} else if (DIExpression *Expr = CTy->getDataLocationExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_data_location, Expr);
}

if (DIVariable *Var = CTy->getAssociated()) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);
} else if (DIExpression *Expr = CTy->getAssociatedExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_associated, Expr);
}

if (DIVariable *Var = CTy->getAllocated()) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);
} else if (DIExpression *Expr = CTy->getAllocatedExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_allocated, Expr);
}

if (auto *RankConst = CTy->getRankConst()) {
addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
RankConst->getSExtValue());
} else if (auto *RankExpr = CTy->getRankExp()) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(RankExpr);
addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
addBlock(Buffer, dwarf::DW_AT_rank, RankExpr);
}

if (auto *BitStride = CTy->getBitStrideConst()) {
Expand Down Expand Up @@ -1917,11 +1881,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
} else if (auto *Exp = dyn_cast<DIExpression>(DT->getRawSizeInBits())) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Exp);
addBlock(MemberDie, dwarf::DW_AT_bit_size, DwarfExpr.finalize());
addBlock(MemberDie, dwarf::DW_AT_bit_size, Exp);
} else {
Size = DT->getSizeInBits();
FieldSize = DD->getBaseTypeSize(DT);
Expand All @@ -1945,11 +1905,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
} else if (auto *Expr =
dyn_cast_or_null<DIExpression>(DT->getRawOffsetInBits())) {
if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 6) {
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.setMemoryLocationKind();
DwarfExpr.addExpression(Expr);
addBlock(MemberDie, dwarf::DW_AT_data_bit_offset, DwarfExpr.finalize());
addBlock(MemberDie, dwarf::DW_AT_data_bit_offset, Expr);
}
} else {
uint32_t AlignInBytes = DT->getAlignInBytes();
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class DwarfUnit : public DIEUnit {
void addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
DIEBlock *Block);

/// Add an expression as block data.
void addBlock(DIE &Die, dwarf::Attribute Attribute, const DIExpression *Expr);

/// Add location information to specified debug information entry.
void addSourceLine(DIE &Die, unsigned Line, unsigned Column,
const DIFile *File);
Expand Down
Loading