Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2022-09-19 23:36:50 +0300
committerAmir Ayupov <aaupov@fb.com>2022-09-19 23:37:10 +0300
commit39336fc09cac61fa38a6bc2d30731fe0e38d38a2 (patch)
treed2c8213b0dadf2e83e85b115be14a32d7f2840f0 /bolt
parent6f3276d57e265be0996e2f67e2e872401da8f511 (diff)
[BOLT] Control aggregation mode output profile file format
In perf2bolt and `-aggregate-only` BOLT mode, the output profile file is written in fdata format by default. Provide a knob `-profile-format=[fdata,yaml]` to control the format. Note that `-w` option still dumps in YAML format. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D133995
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Utils/CommandLineOpts.h5
-rw-r--r--bolt/lib/Profile/DataAggregator.cpp5
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp5
-rw-r--r--bolt/lib/Utils/CommandLineOpts.cpp9
-rw-r--r--bolt/test/X86/pre-aggregated-perf.test20
5 files changed, 42 insertions, 2 deletions
diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h
index 9216048854e4..b7cca813bdec 100644
--- a/bolt/include/bolt/Utils/CommandLineOpts.h
+++ b/bolt/include/bolt/Utils/CommandLineOpts.h
@@ -49,6 +49,11 @@ extern llvm::cl::opt<std::string> OutputFilename;
extern llvm::cl::opt<std::string> PerfData;
extern llvm::cl::opt<bool> PrintCacheMetrics;
extern llvm::cl::opt<bool> PrintSections;
+
+// The format to use with -o in aggregation mode (perf2bolt)
+enum ProfileFormatKind { PF_Fdata, PF_YAML };
+
+extern llvm::cl::opt<ProfileFormatKind> ProfileFormat;
extern llvm::cl::opt<bool> SplitEH;
extern llvm::cl::opt<bool> StrictMode;
extern llvm::cl::opt<bool> TimeOpts;
diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp
index 6ac315e97243..1e45af776a74 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -78,6 +78,8 @@ MaxSamples("max-samples",
cl::Hidden,
cl::cat(AggregatorCategory));
+extern cl::opt<opts::ProfileFormatKind> ProfileFormat;
+
cl::opt<bool> ReadPreAggregated(
"pa", cl::desc("skip perf and read data from a pre-aggregated file format"),
cl::cat(AggregatorCategory));
@@ -610,7 +612,8 @@ Error DataAggregator::readProfile(BinaryContext &BC) {
convertBranchData(Function);
}
- if (opts::AggregateOnly) {
+ if (opts::AggregateOnly &&
+ opts::ProfileFormat == opts::ProfileFormatKind::PF_Fdata) {
if (std::error_code EC = writeAggregatedFile(opts::OutputFilename))
report_error("cannot create output data file", EC);
}
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 5c2d124079fd..434bea0d843d 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2838,6 +2838,11 @@ void RewriteInstance::processProfileData() {
YAMLProfileWriter PW(opts::SaveProfile);
PW.writeProfile(*this);
}
+ if (opts::AggregateOnly &&
+ opts::ProfileFormat == opts::ProfileFormatKind::PF_YAML) {
+ YAMLProfileWriter PW(opts::OutputFilename);
+ PW.writeProfile(*this);
+ }
// Release memory used by profile reader.
ProfileReader.reset();
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp
index b90a73543ed6..d17d68aa7968 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -154,6 +154,15 @@ cl::opt<bool> PrintSections("print-sections",
cl::desc("print all registered sections"),
cl::Hidden, cl::cat(BoltCategory));
+cl::opt<ProfileFormatKind> ProfileFormat(
+ "profile-format",
+ cl::desc(
+ "format to dump profile output in aggregation mode, default is fdata"),
+ cl::init(PF_Fdata),
+ cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"),
+ clEnumValN(PF_YAML, "yaml", "dense YAML reprensentation")),
+ cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
+
cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
cl::Hidden, cl::cat(BoltOptCategory));
diff --git a/bolt/test/X86/pre-aggregated-perf.test b/bolt/test/X86/pre-aggregated-perf.test
index 4421c7679553..c737034c0a74 100644
--- a/bolt/test/X86/pre-aggregated-perf.test
+++ b/bolt/test/X86/pre-aggregated-perf.test
@@ -10,10 +10,28 @@
REQUIRES: system-linux
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
-RUN: perf2bolt %t.exe -o %t -pa -p %p/Inputs/pre-aggregated.txt -w %t.new
+RUN: perf2bolt %t.exe -o %t --pa -p %p/Inputs/pre-aggregated.txt -w %t.new
RUN: cat %t | sort | FileCheck %s -check-prefix=PERF2BOLT
RUN: cat %t.new | FileCheck %s -check-prefix=NEWFORMAT
+# Test --profile-format option with perf2bolt
+RUN: perf2bolt %t.exe -o %t.fdata --pa -p %p/Inputs/pre-aggregated.txt \
+RUN: --profile-format=fdata
+RUN: cat %t.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
+
+RUN: perf2bolt %t.exe -o %t.yaml --pa -p %p/Inputs/pre-aggregated.txt \
+RUN: --profile-format=yaml
+RUN: cat %t.yaml | FileCheck %s -check-prefix=NEWFORMAT
+
+# Test --profile-format option with llvm-bolt --aggregate-only
+RUN: llvm-bolt %t.exe -o %t.bolt.fdata --pa -p %p/Inputs/pre-aggregated.txt \
+RUN: --aggregate-only --profile-format=fdata
+RUN: cat %t.bolt.fdata | sort | FileCheck %s -check-prefix=PERF2BOLT
+
+RUN: llvm-bolt %t.exe -o %t.bolt.yaml --pa -p %p/Inputs/pre-aggregated.txt \
+RUN: --aggregate-only --profile-format=yaml
+RUN: cat %t.bolt.yaml | FileCheck %s -check-prefix=NEWFORMAT
+
PERF2BOLT: 0 [unknown] 7f36d18d60c0 1 main 53c 0 2
PERF2BOLT: 1 main 451 1 SolveCubic 0 0 2
PERF2BOLT: 1 main 490 0 [unknown] 4005f0 0 1