Skip to content

Commit 92758a9

Browse files
author
spupyrev
committed
[BOLT] computing raw branch count for yaml profiles
`Function.RawBranchCount` is initialized for fdata profile but not for yaml one. The diff adds the computation of the field for yaml profiles Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D144211
1 parent 69bab9d commit 92758a9

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,10 @@ class BinaryFunction {
17941794
/// executions corresponding to this function.
17951795
uint64_t getRawBranchCount() const { return RawBranchCount; }
17961796

1797+
/// Set the profile data about the number of branch executions corresponding
1798+
/// to this function.
1799+
void setRawBranchCount(uint64_t Count) { RawBranchCount = Count; }
1800+
17971801
/// Return the execution count for functions with known profile.
17981802
/// Return 0 if the function has no profile.
17991803
uint64_t getKnownExecutionCount() const {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
470470
OS << "\n Image : 0x" << Twine::utohexstr(getImageAddress());
471471
if (ExecutionCount != COUNT_NO_PROFILE) {
472472
OS << "\n Exec Count : " << ExecutionCount;
473+
OS << "\n Branch Count: " << RawBranchCount;
473474
OS << "\n Profile Acc : " << format("%.1f%%", ProfileMatchRatio * 100.0f);
474475
}
475476

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ bool YAMLProfileReader::parseFunctionProfile(
8383

8484
BF.setExecutionCount(YamlBF.ExecCount);
8585

86+
uint64_t FuncRawBranchCount = 0;
87+
for (const yaml::bolt::BinaryBasicBlockProfile &YamlBB : YamlBF.Blocks)
88+
for (const yaml::bolt::SuccessorInfo &YamlSI : YamlBB.Successors)
89+
FuncRawBranchCount += YamlSI.Count;
90+
BF.setRawBranchCount(FuncRawBranchCount);
91+
8692
if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash(/*UseDFS=*/true)) {
8793
if (opts::Verbosity >= 1)
8894
errs() << "BOLT-WARNING: function hash mismatch\n";

bolt/test/X86/branch-data.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
# Also checks that llvm-bolt disassembler and CFG builder is working properly.
44

55
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
6-
RUN: llvm-bolt %t.exe -o /dev/null --data %p/Inputs/blarge.fdata --print-cfg
6+
RUN: llvm-bolt %t.exe -o /dev/null --data %p/Inputs/blarge.fdata --print-cfg | FileCheck %s
77

88
CHECK: Binary Function "usqrt"
99
CHECK: State : CFG constructed
1010
CHECK: Address : 0x401170
1111
CHECK: Size : 0x43
12-
CHECK: MaxSize : 0x50
13-
CHECK: Offset : 0x1170
12+
CHECK: MaxSize : 0x43
13+
CHECK: Offset : 0xcb0
1414
CHECK: Section : .text
1515
CHECK: IsSimple : 1
1616
CHECK: BB Count : 5
1717
CHECK: Exec Count : 199
18+
CHECK: Branch Count: 7689
1819
CHECK: }
1920
CHECK: .LBB{{.*}}
2021
CHECK: Exec Count : 199

0 commit comments

Comments
 (0)