From: Amir Ayupov Date: Mon, 19 Sep 2022 20:36:50 +0000 (-0700) Subject: [BOLT] Control aggregation mode output profile file format X-Git-Tag: upstream/17.0.6~33105 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39336fc09cac61fa38a6bc2d30731fe0e38d38a2;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h index 9216048..b7cca81 100644 --- a/bolt/include/bolt/Utils/CommandLineOpts.h +++ b/bolt/include/bolt/Utils/CommandLineOpts.h @@ -49,6 +49,11 @@ extern llvm::cl::opt OutputFilename; 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 index 6ac315e..1e45af7 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 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 @@ 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 5c2d124..434bea0 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 b90a735..d17d68a 100644 --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -154,6 +154,15 @@ cl::opt PrintSections("print-sections", 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 index 4421c76..c737034 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