Skip to content

Commit de0abc0

Browse files
authored
[BOLT][NFC] Simplify YAMLProfileWriter::convert
Use `getAnnotationWithDefault` instead of testing if the annotation is set. If the default value is used, and `CSI.Count` is set to zero, the target is discarded by a check below. Test Plan: NFC Reviewers: maksfb, dcci, rafaelauler, ayermolo Reviewed By: ayermolo Pull Request: llvm#82129
1 parent 061b408 commit de0abc0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,14 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS) {
105105
TargetName = Callee->getOneName();
106106
}
107107

108+
auto getAnnotationWithDefault = [&](const MCInst &Inst, StringRef Ann) {
109+
return BC.MIB->getAnnotationWithDefault(Instr, Ann, 0ull);
110+
};
108111
if (BC.MIB->getConditionalTailCall(Instr)) {
109-
auto CTCCount =
110-
BC.MIB->tryGetAnnotationAs<uint64_t>(Instr, "CTCTakenCount");
111-
if (CTCCount) {
112-
CSI.Count = *CTCCount;
113-
auto CTCMispreds =
114-
BC.MIB->tryGetAnnotationAs<uint64_t>(Instr, "CTCMispredCount");
115-
if (CTCMispreds)
116-
CSI.Mispreds = *CTCMispreds;
117-
}
112+
CSI.Count = getAnnotationWithDefault(Instr, "CTCTakenCount");
113+
CSI.Mispreds = getAnnotationWithDefault(Instr, "CTCMispredCount");
118114
} else {
119-
auto Count = BC.MIB->tryGetAnnotationAs<uint64_t>(Instr, "Count");
120-
if (Count)
121-
CSI.Count = *Count;
115+
CSI.Count = getAnnotationWithDefault(Instr, "Count");
122116
}
123117

124118
if (CSI.Count)

0 commit comments

Comments
 (0)