diff --git a/bolt/include/bolt/Profile/DataAggregator.h b/bolt/include/bolt/Profile/DataAggregator.h --- a/bolt/include/bolt/Profile/DataAggregator.h +++ b/bolt/include/bolt/Profile/DataAggregator.h @@ -27,6 +27,9 @@ class BinaryContext; class BoltAddressTranslation; +// The format to use with -o in aggregation mode (perf2bolt) +enum ProfileOutputKind { PO_Fdata, PO_YAML }; + /// DataAggregator inherits all parsing logic from DataReader as well as /// its data structures used to represent aggregated profile data in memory. /// 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 ProfileOutput; + 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::ProfileOutput == ProfileOutputKind::PO_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 @@ -208,6 +208,15 @@ clEnumValN(PPP_All, "all", "enable all debugging printout")), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); +cl::opt ProfileOutput( + "profile-output", + cl::desc( + "format to dump profile output in aggregation mode, default is fdata"), + cl::init(PO_Fdata), + cl::values(clEnumValN(PO_Fdata, "fdata", "offset-based plaintext format"), + clEnumValN(PO_YAML, "yaml", "dense YAML reprensentation")), + cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); + static cl::opt RelocationMode( "relocs", cl::desc("use relocations in the binary (default=autodetect)"), cl::cat(BoltCategory)); @@ -2796,6 +2805,11 @@ YAMLProfileWriter PW(opts::SaveProfile); PW.writeProfile(*this); } + if (opts::AggregateOnly && + opts::ProfileOutput == ProfileOutputKind::PO_YAML) { + YAMLProfileWriter PW(opts::OutputFilename); + PW.writeProfile(*this); + } // Release memory used by profile reader. ProfileReader.reset();