[llvm] 9deb7ee - [Debug-Info][NFC] add a wrapper for Die.addValue
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri May 7 00:24:19 PDT 2021
Author: Chen Zheng
Date: 2021-05-07T07:24:09Z
New Revision: 9deb7eeaf76c3285b72ce75d30fcade63b96e2dc
URL: https://github.com/llvm/llvm-project/commit/9deb7eeaf76c3285b72ce75d30fcade63b96e2dc
DIFF: https://github.com/llvm/llvm-project/commit/9deb7eeaf76c3285b72ce75d30fcade63b96e2dc.diff
LOG: [Debug-Info][NFC] add a wrapper for Die.addValue
Add a new wrapper function addAttribute() for Die.addValue() function,
so we can do some attributes control in one single interface.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D101125
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index ac7a316398441..faa14dca1c3f1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -83,7 +83,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
if (!Base || Base == Label) {
unsigned idx = DD->getAddressPool().getIndex(Label);
- Die.addValue(DIEValueAllocator, Attribute,
+ addAttribute(Die, Attribute,
DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx
: dwarf::DW_FORM_GNU_addr_index,
DIEInteger(idx));
@@ -100,7 +100,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
addPoolOpAddress(*Loc, Label);
addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc);
} else
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
+ addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
new (DIEValueAllocator) DIEAddrOffset(
DD->getAddressPool().getIndex(Base), Label, Base));
}
@@ -112,11 +112,9 @@ void DwarfCompileUnit::addLocalLabelAddress(DIE &Die,
DD->addArangeLabel(SymbolCU(this, Label));
if (Label)
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
- DIELabel(Label));
+ addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label));
else
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
- DIEInteger(0));
+ addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0));
}
unsigned DwarfCompileUnit::getOrCreateSourceID(const DIFile *File) {
@@ -1472,7 +1470,7 @@ void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute,
dwarf::Form Form = (DD->getDwarfVersion() >= 5)
? dwarf::DW_FORM_loclistx
: DD->getDwarfSectionOffsetForm();
- Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
+ addAttribute(Die, Attribute, Form, DIELocList(Index));
}
void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var,
@@ -1504,7 +1502,7 @@ void DwarfCompileUnit::applyLabelAttributes(const DbgLabel &Label,
/// Add a Dwarf expression attribute data and value.
void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,
const MCExpr *Expr) {
- Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
+ addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr));
}
void DwarfCompileUnit::applySubprogramAttributesToDefinition(
@@ -1538,7 +1536,7 @@ void DwarfCompileUnit::addAddrTableBase() {
}
void DwarfCompileUnit::addBaseTypeRef(DIEValueList &Die, int64_t Idx) {
- Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
+ addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 40d290ebe47fa..2b171ae3b6e84 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -219,11 +219,9 @@ void DwarfUnit::insertDIE(DIE *D) {
void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) {
if (DD->getDwarfVersion() >= 4)
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present,
- DIEInteger(1));
+ addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));
else
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag,
- DIEInteger(1));
+ addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));
}
void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
@@ -232,7 +230,7 @@ void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
Form = DIEInteger::BestForm(false, Integer);
assert(Form != dwarf::DW_FORM_implicit_const &&
"DW_FORM_implicit_const is used only for signed integers");
- Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
+ addAttribute(Die, Attribute, *Form, DIEInteger(Integer));
}
void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form,
@@ -244,7 +242,7 @@ void DwarfUnit::addSInt(DIEValueList &Die, dwarf::Attribute Attribute,
Optional<dwarf::Form> Form, int64_t Integer) {
if (!Form)
Form = DIEInteger::BestForm(true, Integer);
- Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
+ addAttribute(Die, Attribute, *Form, DIEInteger(Integer));
}
void DwarfUnit::addSInt(DIELoc &Die, Optional<dwarf::Form> Form,
@@ -258,7 +256,7 @@ void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,
return;
if (DD->useInlineStrings()) {
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string,
+ addAttribute(Die, Attribute, dwarf::DW_FORM_string,
new (DIEValueAllocator)
DIEInlineString(String, DIEValueAllocator));
return;
@@ -282,13 +280,12 @@ void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,
else if (Index > 0xff)
IxForm = dwarf::DW_FORM_strx2;
}
- Die.addValue(DIEValueAllocator, Attribute, IxForm,
- DIEString(StringPoolEntry));
+ addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry));
}
void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute,
dwarf::Form Form, const MCSymbol *Label) {
- Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
+ addAttribute(Die, Attribute, Form, DIELabel(Label));
}
void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) {
@@ -355,7 +352,7 @@ void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
void DwarfUnit::addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute,
const MCSymbol *Hi, const MCSymbol *Lo) {
- Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_data4,
+ addAttribute(Die, Attribute, dwarf::DW_FORM_data4,
new (DIEValueAllocator) DIEDelta(Hi, Lo));
}
@@ -370,8 +367,8 @@ void DwarfUnit::addDIETypeSignature(DIE &Die, uint64_t Signature) {
// and think this is a full definition.
addFlag(Die, dwarf::DW_AT_declaration);
- Die.addValue(DIEValueAllocator, dwarf::DW_AT_signature,
- dwarf::DW_FORM_ref_sig8, DIEInteger(Signature));
+ addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
+ DIEInteger(Signature));
}
void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
@@ -383,7 +380,7 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
CU = getUnitDie().getUnit();
if (!EntryCU)
EntryCU = getUnitDie().getUnit();
- Die.addValue(DIEValueAllocator, Attribute,
+ addAttribute(Die, Attribute,
EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
Entry);
}
@@ -398,15 +395,14 @@ DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N) {
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) {
Loc->ComputeSize(Asm);
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
- Die.addValue(DIEValueAllocator, Attribute,
- Loc->BestForm(DD->getDwarfVersion()), Loc);
+ addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
}
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
DIEBlock *Block) {
Block->ComputeSize(Asm);
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
- Die.addValue(DIEValueAllocator, Attribute, Form, Block);
+ addAttribute(Die, Attribute, Form, Block);
}
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
@@ -1639,8 +1635,8 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
// Objective-C properties.
if (DINode *PNode = DT->getObjCProperty())
if (DIE *PDie = getDIE(PNode))
- MemberDie.addValue(DIEValueAllocator, dwarf::DW_AT_APPLE_property,
- dwarf::DW_FORM_ref4, DIEEntry(*PDie));
+ addAttribute(MemberDie, dwarf::DW_AT_APPLE_property,
+ dwarf::DW_FORM_ref4, DIEEntry(*PDie));
if (DT->isArtificial())
addFlag(MemberDie, dwarf::DW_AT_artificial);
@@ -1746,7 +1742,7 @@ void DwarfTypeUnit::emitHeader(bool UseOffsets) {
void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
const MCSymbol *Hi, const MCSymbol *Lo) {
- Die.addValue(DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(),
+ addAttribute(Die, Attribute, DD->getDwarfSectionOffsetForm(),
new (DIEValueAllocator) DIEDelta(Hi, Lo));
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 10fd725cb8ae7..aca831a535a19 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -76,6 +76,13 @@ class DwarfUnit : public DIEUnit {
bool isShareableAcrossCUs(const DINode *D) const;
+ template <typename T>
+ void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute,
+ dwarf::Form Form, T &&Value) {
+ Die.addValue(DIEValueAllocator,
+ DIEValue(Attribute, Form, std::forward<T>(Value)));
+ }
+
public:
// Accessors.
AsmPrinter* getAsmPrinter() const { return Asm; }
More information about the llvm-commits
mailing list