Skip to content

Commit 061b408

Browse files
authored
[BOLT][NFC] Expose YAMLProfileWriter::convert function
The function is to be used by YAML profile emission in BAT mode for BinaryFunctions not covered by BAT tables (same as in original binary). Test Plan: NFC Reviewers: rafaelauler, ayermolo, dcci, maksfb Reviewed By: dcci Pull Request: #76909
1 parent 2b7289d commit 061b408

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

bolt/include/bolt/Profile/YAMLProfileWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef BOLT_PROFILE_YAML_PROFILE_WRITER_H
1010
#define BOLT_PROFILE_YAML_PROFILE_WRITER_H
1111

12+
#include "bolt/Profile/ProfileYAMLMapping.h"
1213
#include "llvm/Support/raw_ostream.h"
1314
#include <system_error>
1415

@@ -29,6 +30,9 @@ class YAMLProfileWriter {
2930

3031
/// Save execution profile for that instance.
3132
std::error_code writeProfile(const RewriteInstance &RI);
33+
34+
static yaml::bolt::BinaryFunctionProfile convert(const BinaryFunction &BF,
35+
bool UseDFS);
3236
};
3337

3438
} // namespace bolt

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "bolt/Core/BinaryBasicBlock.h"
1111
#include "bolt/Core/BinaryFunction.h"
1212
#include "bolt/Profile/ProfileReaderBase.h"
13-
#include "bolt/Profile/ProfileYAMLMapping.h"
1413
#include "bolt/Rewrite/RewriteInstance.h"
1514
#include "llvm/Support/CommandLine.h"
1615
#include "llvm/Support/FileSystem.h"
@@ -26,15 +25,15 @@ extern llvm::cl::opt<bool> ProfileUseDFS;
2625
namespace llvm {
2726
namespace bolt {
2827

29-
namespace {
30-
void convert(const BinaryFunction &BF,
31-
yaml::bolt::BinaryFunctionProfile &YamlBF) {
28+
yaml::bolt::BinaryFunctionProfile
29+
YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS) {
30+
yaml::bolt::BinaryFunctionProfile YamlBF;
3231
const BinaryContext &BC = BF.getBinaryContext();
3332

3433
const uint16_t LBRProfile = BF.getProfileFlags() & BinaryFunction::PF_LBR;
3534

3635
// Prepare function and block hashes
37-
BF.computeHash(opts::ProfileUseDFS);
36+
BF.computeHash(UseDFS);
3837
BF.computeBlockHashes();
3938

4039
YamlBF.Name = BF.getPrintName();
@@ -44,7 +43,7 @@ void convert(const BinaryFunction &BF,
4443
YamlBF.ExecCount = BF.getKnownExecutionCount();
4544

4645
BinaryFunction::BasicBlockOrderType Order;
47-
llvm::copy(opts::ProfileUseDFS ? BF.dfs() : BF.getLayout().blocks(),
46+
llvm::copy(UseDFS ? BF.dfs() : BF.getLayout().blocks(),
4847
std::back_inserter(Order));
4948

5049
for (const BinaryBasicBlock *BB : Order) {
@@ -165,8 +164,8 @@ void convert(const BinaryFunction &BF,
165164

166165
YamlBF.Blocks.emplace_back(YamlBB);
167166
}
167+
return YamlBF;
168168
}
169-
} // end anonymous namespace
170169

171170
std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) {
172171
const BinaryContext &BC = RI.getBinaryContext();
@@ -222,9 +221,7 @@ std::error_code YAMLProfileWriter::writeProfile(const RewriteInstance &RI) {
222221
if (!BF.hasValidProfile() && !RI.getProfileReader()->isTrustedSource())
223222
continue;
224223

225-
yaml::bolt::BinaryFunctionProfile YamlBF;
226-
convert(BF, YamlBF);
227-
BP.Functions.emplace_back(YamlBF);
224+
BP.Functions.emplace_back(convert(BF, opts::ProfileUseDFS));
228225
}
229226
}
230227

0 commit comments

Comments
 (0)