Skip to content

Commit

Permalink
[bolt] A better DIEBuilder for the llvm API change in llvm#98905
Browse files Browse the repository at this point in the history
The caller (cloneAttribute) already switches on the reference type. By
aligning the cases with the retrieval functions, we can avoid branching
twice.
  • Loading branch information
labath committed Jul 17, 2024
1 parent e093109 commit 8f4287e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
12 changes: 2 additions & 10 deletions bolt/include/bolt/Core/DIEBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ class DIEBuilder {

/// Returns current state of the DIEBuilder
State &getState() { return *BuilderState.get(); }
/// Resolve the reference in DIE, if target is not loaded into IR,
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p
/// RefValue.
DWARFDie resolveDIEReference(
const DWARFFormValue &RefValue,
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
DWARFUnit *&RefCU, DWARFDebugInfoEntry &DwarfDebugInfoEntry);

/// Resolve the reference in DIE, if target is not loaded into IR,
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p
Expand All @@ -165,10 +158,9 @@ class DIEBuilder {
const DWARFFormValue &Val);

/// Clone an attribute in reference format.
void cloneDieReferenceAttribute(
void cloneDieOffsetReferenceAttribute(
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
const DWARFFormValue &Val);
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref);

/// Clone an attribute in block format.
void cloneBlockAttribute(
Expand Down
43 changes: 10 additions & 33 deletions bolt/lib/Core/DIEBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,25 +551,6 @@ void DIEBuilder::finish() {
updateReferences();
}

DWARFDie DIEBuilder::resolveDIEReference(
const DWARFFormValue &RefValue,
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
DWARFUnit *&RefCU, DWARFDebugInfoEntry &DwarfDebugInfoEntry) {
assert(RefValue.isFormClass(DWARFFormValue::FC_Reference));
uint64_t RefOffset;
if (std::optional<uint64_t> Off = RefValue.getAsRelativeReference()) {
RefOffset = RefValue.getUnit()->getOffset() + *Off;
} else if (Off = RefValue.getAsDebugInfoReference(); Off) {
RefOffset = *Off;
} else {
BC.errs()
<< "BOLT-WARNING: [internal-dwarf-error]: unsupported reference type: "
<< FormEncodingString(RefValue.getForm()) << ".\n";
return DWARFDie();
}
return resolveDIEReference(AttrSpec, RefOffset, RefCU, DwarfDebugInfoEntry);
}

DWARFDie DIEBuilder::resolveDIEReference(
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
const uint64_t RefOffset, DWARFUnit *&RefCU,
Expand Down Expand Up @@ -613,23 +594,14 @@ DWARFDie DIEBuilder::resolveDIEReference(
return DWARFDie();
}

void DIEBuilder::cloneDieReferenceAttribute(
void DIEBuilder::cloneDieOffsetReferenceAttribute(
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
const DWARFFormValue &Val) {
uint64_t Ref;
if (std::optional<uint64_t> Off = Val.getAsRelativeReference())
Ref = Val.getUnit()->getOffset() + *Off;
else if (Off = Val.getAsDebugInfoReference(); Off)
Ref = *Off;
else
return;

const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref) {
DIE *NewRefDie = nullptr;
DWARFUnit *RefUnit = nullptr;

DWARFDebugInfoEntry DDIEntry;
const DWARFDie RefDie = resolveDIEReference(Val, AttrSpec, RefUnit, DDIEntry);
const DWARFDie RefDie = resolveDIEReference(AttrSpec, Ref, RefUnit, DDIEntry);

if (!RefDie)
return;
Expand Down Expand Up @@ -834,7 +806,7 @@ void DIEBuilder::cloneAddressAttribute(
void DIEBuilder::cloneRefsigAttribute(
DIE &Die, DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
const DWARFFormValue &Val) {
const std::optional<uint64_t> SigVal = Val.getRawUValue();
const std::optional<uint64_t> SigVal = Val.getAsSignatureReference();
Die.addValue(getState().DIEAlloc, AttrSpec.Attr, dwarf::DW_FORM_ref_sig8,
DIEInteger(*SigVal));
}
Expand Down Expand Up @@ -902,11 +874,16 @@ void DIEBuilder::cloneAttribute(
cloneStringAttribute(Die, U, AttrSpec, Val);
break;
case dwarf::DW_FORM_ref_addr:
cloneDieOffsetReferenceAttribute(Die, U, InputDIE, AttrSpec,
*Val.getAsDebugInfoReference());
break;
case dwarf::DW_FORM_ref1:
case dwarf::DW_FORM_ref2:
case dwarf::DW_FORM_ref4:
case dwarf::DW_FORM_ref8:
cloneDieReferenceAttribute(Die, U, InputDIE, AttrSpec, Val);
cloneDieOffsetReferenceAttribute(Die, U, InputDIE, AttrSpec,
Val.getUnit()->getOffset() +
*Val.getAsRelativeReference());
break;
case dwarf::DW_FORM_block:
case dwarf::DW_FORM_block1:
Expand Down

0 comments on commit 8f4287e

Please sign in to comment.