Skip to content
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

[BOLT] Expose pseudo probe function checksum and GUID #99389

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions bolt/include/bolt/Core/BinaryFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ class BinaryFunction {
/// different parameters by every pass.
mutable uint64_t Hash{0};

/// Function hash assigned by the compiler and stored in pseudo probe
/// description of the source function.
uint64_t PseudoProbeDescHash{0};

/// For PLT functions it contains a symbol associated with a function
/// reference. It is nullptr for non-PLT functions.
const MCSymbol *PLTSymbol{nullptr};
Expand Down Expand Up @@ -2256,6 +2260,11 @@ class BinaryFunction {
/// Returns the last computed hash value of the function.
size_t getHash() const { return Hash; }

/// Returns the function hash from pseudo-probe description of the function.
size_t getPseudoProbeDescHash() const { return PseudoProbeDescHash; }
aaupov marked this conversation as resolved.
Show resolved Hide resolved

void setPseudoProbeDescHash(uint64_t Hash) { PseudoProbeDescHash = Hash; }

using OperandHashFuncTy =
function_ref<typename std::string(const MCOperand &)>;

Expand Down
2 changes: 2 additions & 0 deletions bolt/include/bolt/Profile/ProfileYAMLMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ struct BinaryFunctionProfile {
llvm::yaml::Hex64 Hash{0};
uint64_t ExecCount{0};
std::vector<BinaryBasicBlockProfile> Blocks;
llvm::yaml::Hex64 PseudoProbeDescHash{0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a pseudo-probe hash, just like GUID isn't really a pseudo-probe GUID. Can we call it CFG checksum/hash?

bool Used{false};
};
} // end namespace bolt
Expand All @@ -164,6 +165,7 @@ template <> struct MappingTraits<bolt::BinaryFunctionProfile> {
YamlIO.mapRequired("nblocks", BFP.NumBasicBlocks);
YamlIO.mapOptional("blocks", BFP.Blocks,
std::vector<bolt::BinaryBasicBlockProfile>());
YamlIO.mapOptional("pseudo_probe_desc_hash", BFP.PseudoProbeDescHash);
}
};

Expand Down
1 change: 1 addition & 0 deletions bolt/lib/Profile/DataAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,7 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
YamlBF.Hash = BAT->getBFHash(FuncAddress);
YamlBF.ExecCount = BF->getKnownExecutionCount();
YamlBF.NumBasicBlocks = BAT->getNumBasicBlocks(FuncAddress);
YamlBF.PseudoProbeDescHash = BF->getPseudoProbeDescHash();
const BoltAddressTranslation::BBHashMapTy &BlockMap =
BAT->getBBHashMap(FuncAddress);
YamlBF.Blocks.resize(YamlBF.NumBasicBlocks);
Expand Down
1 change: 1 addition & 0 deletions bolt/lib/Profile/YAMLProfileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
YamlBF.Hash = BF.getHash();
YamlBF.NumBasicBlocks = BF.size();
YamlBF.ExecCount = BF.getKnownExecutionCount();
YamlBF.PseudoProbeDescHash = BF.getPseudoProbeDescHash();

BinaryFunction::BasicBlockOrderType Order;
llvm::copy(UseDFS ? BF.dfs() : BF.getLayout().blocks(),
Expand Down
14 changes: 13 additions & 1 deletion bolt/lib/Rewrite/PseudoProbeRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ class PseudoProbeRewriter final : public MetadataRewriter {
PseudoProbeRewriter(BinaryContext &BC)
: MetadataRewriter("pseudo-probe-rewriter", BC) {}

Error preCFGInitializer() override;
Error postEmitFinalizer() override;
};

Error PseudoProbeRewriter::postEmitFinalizer() {
Error PseudoProbeRewriter::preCFGInitializer() {
parsePseudoProbe();

return Error::success();
}

Error PseudoProbeRewriter::postEmitFinalizer() {
updatePseudoProbes();

return Error::success();
Expand Down Expand Up @@ -138,6 +144,12 @@ void PseudoProbeRewriter::parsePseudoProbe() {
ProbeDecoder.printGUID2FuncDescMap(outs());
ProbeDecoder.printProbesForAllAddresses(outs());
}

for (const auto &[GUID, FuncDesc] : ProbeDecoder.getGUID2FuncDescMap())
if (FuncStartAddrs.contains(GUID))
if (BinaryFunction *BF =
BC.getBinaryFunctionAtAddress(FuncStartAddrs[GUID]))
BF->setPseudoProbeDescHash(FuncDesc.FuncHash);
}

void PseudoProbeRewriter::updatePseudoProbes() {
Expand Down
13 changes: 13 additions & 0 deletions bolt/test/X86/pseudoprobe-decoding-inline.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# REQUIRES: system-linux
# RUN: llvm-bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s

# PREAGG: B X:0 #foo# 1 0
# PREAGG: B X:0 #bar# 1 0
# PREAGG: B X:0 #main# 1 0
# RUN: link_fdata %s %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin %t.preagg PREAGG
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-YAML
# CHECK-YAML: name: bar
# CHECK-YAML: pseudo_probe_desc_hash: 0x10E852DA94
# CHECK-YAML: name: foo
# CHECK-YAML: pseudo_probe_desc_hash: 0x200205A19C5B4
# CHECK-YAML: name: main
# CHECK-YAML: pseudo_probe_desc_hash: 0x10000FFFFFFFF

CHECK: Report of decoding input pseudo probe binaries

CHECK-NEXT: Pseudo Probe Desc:
Expand Down
Loading