-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Introduce DwarfUnit::addBlock helper method #168446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-debuginfo Author: Tom Tromey (tromey) ChangesThis patch is just a small cleanup that unifies the various spots that add a DWARF expression to the output. Full diff: https://github.com/llvm/llvm-project/pull/168446.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 1666a0e36b39a..dc19c57bf59fd 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -441,6 +441,14 @@ void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
addBlock(Die, Attribute, Block->BestForm(), Block);
}
+void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, 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)
@@ -824,27 +832,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()) {
@@ -1207,11 +1202,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.)
@@ -1607,11 +1598,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)
@@ -1649,11 +1636,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)
@@ -1699,11 +1682,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);
}
}
};
@@ -1770,44 +1749,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()) {
@@ -1917,11 +1880,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);
@@ -1945,11 +1904,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();
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 9c0b68b315b50..e42615bfebcf3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -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, DIExpression *Expr);
+
/// Add location information to specified debug information entry.
void addSourceLine(DIE &Die, unsigned Line, unsigned Column,
const DIFile *File);
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Michael137
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
🐧 Linux x64 Test Results
|
This patch is just a small cleanup that unifies the various spots that add a DWARF expression to the output.
db6b688 to
ff4b914
Compare
|
Rebased and ran clang-format this time. |
Uhh, did not rebase, but did address review comments. |
|
FWIW I can't push this, so someone will have to do it for me. Thank you. |
This patch is just a small cleanup that unifies the various spots that add a DWARF expression to the output.