Skip to content

Commit 075c50c

Browse files
labathyuxuanchen1997
authored andcommitted
[BOLT][DWARF][NFC] A better DIEBuilder for the llvm API change in #98905 (#99324)
Summary: The caller (cloneAttribute) already switches on the reference type. By aligning the cases with the retrieval functions, we can avoid branching twice. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250831
1 parent e3ebac0 commit 075c50c

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ class DIEBuilder {
135135

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

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

167160
/// Clone an attribute in reference format.
168-
void cloneDieReferenceAttribute(
161+
void cloneDieOffsetReferenceAttribute(
169162
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
170-
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
171-
const DWARFFormValue &Val);
163+
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref);
172164

173165
/// Clone an attribute in block format.
174166
void cloneBlockAttribute(

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -551,25 +551,6 @@ void DIEBuilder::finish() {
551551
updateReferences();
552552
}
553553

554-
DWARFDie DIEBuilder::resolveDIEReference(
555-
const DWARFFormValue &RefValue,
556-
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
557-
DWARFUnit *&RefCU, DWARFDebugInfoEntry &DwarfDebugInfoEntry) {
558-
assert(RefValue.isFormClass(DWARFFormValue::FC_Reference));
559-
uint64_t RefOffset;
560-
if (std::optional<uint64_t> Off = RefValue.getAsRelativeReference()) {
561-
RefOffset = RefValue.getUnit()->getOffset() + *Off;
562-
} else if (Off = RefValue.getAsDebugInfoReference(); Off) {
563-
RefOffset = *Off;
564-
} else {
565-
BC.errs()
566-
<< "BOLT-WARNING: [internal-dwarf-error]: unsupported reference type: "
567-
<< FormEncodingString(RefValue.getForm()) << ".\n";
568-
return DWARFDie();
569-
}
570-
return resolveDIEReference(AttrSpec, RefOffset, RefCU, DwarfDebugInfoEntry);
571-
}
572-
573554
DWARFDie DIEBuilder::resolveDIEReference(
574555
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
575556
const uint64_t RefOffset, DWARFUnit *&RefCU,
@@ -613,23 +594,14 @@ DWARFDie DIEBuilder::resolveDIEReference(
613594
return DWARFDie();
614595
}
615596

616-
void DIEBuilder::cloneDieReferenceAttribute(
597+
void DIEBuilder::cloneDieOffsetReferenceAttribute(
617598
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
618-
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
619-
const DWARFFormValue &Val) {
620-
uint64_t Ref;
621-
if (std::optional<uint64_t> Off = Val.getAsRelativeReference())
622-
Ref = Val.getUnit()->getOffset() + *Off;
623-
else if (Off = Val.getAsDebugInfoReference(); Off)
624-
Ref = *Off;
625-
else
626-
return;
627-
599+
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref) {
628600
DIE *NewRefDie = nullptr;
629601
DWARFUnit *RefUnit = nullptr;
630602

631603
DWARFDebugInfoEntry DDIEntry;
632-
const DWARFDie RefDie = resolveDIEReference(Val, AttrSpec, RefUnit, DDIEntry);
604+
const DWARFDie RefDie = resolveDIEReference(AttrSpec, Ref, RefUnit, DDIEntry);
633605

634606
if (!RefDie)
635607
return;
@@ -834,7 +806,7 @@ void DIEBuilder::cloneAddressAttribute(
834806
void DIEBuilder::cloneRefsigAttribute(
835807
DIE &Die, DWARFAbbreviationDeclaration::AttributeSpec AttrSpec,
836808
const DWARFFormValue &Val) {
837-
const std::optional<uint64_t> SigVal = Val.getRawUValue();
809+
const std::optional<uint64_t> SigVal = Val.getAsSignatureReference();
838810
Die.addValue(getState().DIEAlloc, AttrSpec.Attr, dwarf::DW_FORM_ref_sig8,
839811
DIEInteger(*SigVal));
840812
}
@@ -902,11 +874,16 @@ void DIEBuilder::cloneAttribute(
902874
cloneStringAttribute(Die, U, AttrSpec, Val);
903875
break;
904876
case dwarf::DW_FORM_ref_addr:
877+
cloneDieOffsetReferenceAttribute(Die, U, InputDIE, AttrSpec,
878+
*Val.getAsDebugInfoReference());
879+
break;
905880
case dwarf::DW_FORM_ref1:
906881
case dwarf::DW_FORM_ref2:
907882
case dwarf::DW_FORM_ref4:
908883
case dwarf::DW_FORM_ref8:
909-
cloneDieReferenceAttribute(Die, U, InputDIE, AttrSpec, Val);
884+
cloneDieOffsetReferenceAttribute(Die, U, InputDIE, AttrSpec,
885+
Val.getUnit()->getOffset() +
886+
*Val.getAsRelativeReference());
910887
break;
911888
case dwarf::DW_FORM_block:
912889
case dwarf::DW_FORM_block1:

0 commit comments

Comments
 (0)