Skip to content

[BOLT][NFC] Expose YAMLProfileWriter::convert function #76909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bolt/include/bolt/Profile/YAMLProfileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef BOLT_PROFILE_YAML_PROFILE_WRITER_H
#define BOLT_PROFILE_YAML_PROFILE_WRITER_H

#include "bolt/Profile/ProfileYAMLMapping.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>

Expand All @@ -29,6 +30,9 @@ class YAMLProfileWriter {

/// Save execution profile for that instance.
std::error_code writeProfile(const RewriteInstance &RI);

static yaml::bolt::BinaryFunctionProfile convert(const BinaryFunction &BF,
bool UseDFS);
};

} // namespace bolt
Expand Down
17 changes: 7 additions & 10 deletions bolt/lib/Profile/YAMLProfileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "bolt/Core/BinaryBasicBlock.h"
#include "bolt/Core/BinaryFunction.h"
#include "bolt/Profile/ProfileReaderBase.h"
#include "bolt/Profile/ProfileYAMLMapping.h"
#include "bolt/Rewrite/RewriteInstance.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
Expand All @@ -26,15 +25,15 @@ extern llvm::cl::opt<bool> ProfileUseDFS;
namespace llvm {
namespace bolt {

namespace {
void convert(const BinaryFunction &BF,
yaml::bolt::BinaryFunctionProfile &YamlBF) {
yaml::bolt::BinaryFunctionProfile
YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS) {
yaml::bolt::BinaryFunctionProfile YamlBF;
const BinaryContext &BC = BF.getBinaryContext();

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

// Prepare function and block hashes
BF.computeHash(opts::ProfileUseDFS);
BF.computeHash(UseDFS);
BF.computeBlockHashes();

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

BinaryFunction::BasicBlockOrderType Order;
llvm::copy(opts::ProfileUseDFS ? BF.dfs() : BF.getLayout().blocks(),
llvm::copy(UseDFS ? BF.dfs() : BF.getLayout().blocks(),
std::back_inserter(Order));

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

YamlBF.Blocks.emplace_back(YamlBB);
}
return YamlBF;
}
} // end anonymous namespace

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

yaml::bolt::BinaryFunctionProfile YamlBF;
convert(BF, YamlBF);
BP.Functions.emplace_back(YamlBF);
BP.Functions.emplace_back(convert(BF, opts::ProfileUseDFS));
}
}

Expand Down