Skip to content

Commit 4d19676

Browse files
authored
[BOLT] Add profile-use-pseudo-probes option
Move pseudo probe profile generation under --profile-use-pseudo-probes option. Note that updating pseudo probes is independent from this flag. Test Plan: updated pseudoprobe-decoding-inline.test Reviewers: maksfb, rafaelauler, ayermolo, dcci, WenleiHe Reviewed By: WenleiHe Pull Request: #100299
1 parent 6c23f97 commit 4d19676

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ MaxSamples("max-samples",
8888
cl::cat(AggregatorCategory));
8989

9090
extern cl::opt<opts::ProfileFormatKind> ProfileFormat;
91+
extern cl::opt<bool> ProfileUsePseudoProbes;
9192
extern cl::opt<std::string> SaveProfile;
9293

9394
cl::opt<bool> ReadPreAggregated(
@@ -2298,7 +2299,8 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
22982299

22992300
yaml::bolt::BinaryProfile BP;
23002301

2301-
const MCPseudoProbeDecoder *PseudoProbeDecoder = BC.getPseudoProbeDecoder();
2302+
const MCPseudoProbeDecoder *PseudoProbeDecoder =
2303+
opts::ProfileUsePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
23022304

23032305
// Fill out the header info.
23042306
BP.Header.Version = 1;

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ llvm::cl::opt<bool>
4949
llvm::cl::opt<bool> ProfileUseDFS("profile-use-dfs",
5050
cl::desc("use DFS order for YAML profile"),
5151
cl::Hidden, cl::cat(BoltOptCategory));
52+
53+
llvm::cl::opt<bool> ProfileUsePseudoProbes(
54+
"profile-use-pseudo-probes",
55+
cl::desc("Use pseudo probes for profile generation and matching"),
56+
cl::Hidden, cl::cat(BoltOptCategory));
5257
} // namespace opts
5358

5459
namespace llvm {

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace opts {
2424
extern llvm::cl::opt<bool> ProfileUseDFS;
25+
extern llvm::cl::opt<bool> ProfileUsePseudoProbes;
2526
} // namespace opts
2627

2728
namespace llvm {
@@ -57,7 +58,8 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
5758
const BoltAddressTranslation *BAT) {
5859
yaml::bolt::BinaryFunctionProfile YamlBF;
5960
const BinaryContext &BC = BF.getBinaryContext();
60-
const MCPseudoProbeDecoder *PseudoProbeDecoder = BC.getPseudoProbeDecoder();
61+
const MCPseudoProbeDecoder *PseudoProbeDecoder =
62+
opts::ProfileUsePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
6163

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

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static cl::opt<PrintPseudoProbesOptions> PrintPseudoProbes(
4949
clEnumValN(PPP_All, "all", "enable all debugging printout")),
5050
cl::Hidden, cl::cat(BoltCategory));
5151

52+
extern cl::opt<bool> ProfileUsePseudoProbes;
5253
} // namespace opts
5354

5455
namespace {
@@ -89,12 +90,15 @@ class PseudoProbeRewriter final : public MetadataRewriter {
8990
};
9091

9192
Error PseudoProbeRewriter::preCFGInitializer() {
92-
parsePseudoProbe();
93+
if (opts::ProfileUsePseudoProbes)
94+
parsePseudoProbe();
9395

9496
return Error::success();
9597
}
9698

9799
Error PseudoProbeRewriter::postEmitFinalizer() {
100+
if (!opts::ProfileUsePseudoProbes)
101+
parsePseudoProbe();
98102
updatePseudoProbes();
99103

100104
return Error::success();

bolt/test/X86/pseudoprobe-decoding-inline.test

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# PREAGG: B X:0 #main# 1 0
77
## Check pseudo-probes in regular YAML profile (non-BOLTed binary)
88
# RUN: link_fdata %s %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin %t.preagg PREAGG
9-
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
9+
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-use-pseudo-probes
1010
# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-YAML
1111
## Check pseudo-probes in BAT YAML profile (BOLTed binary)
1212
# RUN: link_fdata %s %t.bolt %t.preagg2 PREAGG
13-
# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2
13+
# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-use-pseudo-probes
1414
# RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML
1515
# CHECK-YAML: name: bar
1616
# CHECK-YAML: - bid: 0
@@ -29,6 +29,14 @@
2929
# CHECK-YAML: pseudo_probes: [ { guid: 0xDB956436E78DD5FA, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 1, type: 0 }, { guid: 0x5CF8C24CDB18BDAC, id: 2, type: 0 } ]
3030
# CHECK-YAML: guid: 0xDB956436E78DD5FA
3131
# CHECK-YAML: pseudo_probe_desc_hash: 0x10000FFFFFFFF
32+
#
33+
## Check that without --profile-use-pseudo-probes option, no pseudo probes are
34+
## generated
35+
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
36+
# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-NO-OPT
37+
# CHECK-NO-OPT-NOT: pseudo_probes
38+
# CHECK-NO-OPT-NOT: guid
39+
# CHECK-NO-OPT-NOT: pseudo_probe_desc_hash
3240

3341
CHECK: Report of decoding input pseudo probe binaries
3442

0 commit comments

Comments
 (0)