diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h --- a/bolt/include/bolt/Utils/CommandLineOpts.h +++ b/bolt/include/bolt/Utils/CommandLineOpts.h @@ -49,6 +49,11 @@ extern llvm::cl::opt PerfData; extern llvm::cl::opt PrintCacheMetrics; extern llvm::cl::opt PrintSections; + +// The format to use with -o in aggregation mode (perf2bolt) +enum ProfileFormatKind { PF_Fdata, PF_YAML }; + +extern llvm::cl::opt ProfileFormat; extern llvm::cl::opt SplitEH; extern llvm::cl::opt StrictMode; extern llvm::cl::opt TimeOpts; diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -78,6 +78,8 @@ cl::Hidden, cl::cat(AggregatorCategory)); +extern cl::opt ProfileFormat; + cl::opt ReadPreAggregated( "pa", cl::desc("skip perf and read data from a pre-aggregated file format"), cl::cat(AggregatorCategory)); @@ -610,7 +612,8 @@ 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 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -2796,6 +2796,11 @@ 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 --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -154,6 +154,15 @@ cl::desc("print all registered sections"), cl::Hidden, cl::cat(BoltCategory)); +cl::opt 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 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 --- a/bolt/test/X86/pre-aggregated-perf.test +++ b/bolt/test/X86/pre-aggregated-perf.test @@ -14,6 +14,24 @@ 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