@@ -34,45 +34,32 @@ cl::OptionCategory MergeFdataCategory("merge-fdata options");
3434
3535enum SortType : char {
3636 ST_NONE,
37- ST_EXEC_COUNT, // / Sort based on function execution count.
38- ST_TOTAL_BRANCHES, // / Sort based on all branches in the function.
37+ ST_EXEC_COUNT, // / Sort based on function execution count.
38+ ST_TOTAL_BRANCHES, // / Sort based on all branches in the function.
3939};
4040
4141static cl::list<std::string>
42- InputDataFilenames (
43- cl::Positional,
44- cl::CommaSeparated,
45- cl::desc (" <fdata1> [<fdata2>]..." ),
46- cl::OneOrMore,
47- cl::cat(MergeFdataCategory));
48-
49- static cl::opt<SortType>
50- PrintFunctionList (" print" ,
51- cl::desc (" print the list of objects with count to stderr" ),
52- cl::init(ST_NONE),
53- cl::values(clEnumValN(ST_NONE,
54- " none" ,
55- " do not print objects/functions" ),
56- clEnumValN(ST_EXEC_COUNT,
57- " exec" ,
58- " print functions sorted by execution count" ),
59- clEnumValN(ST_TOTAL_BRANCHES,
60- " branches" ,
61- " print functions sorted by total branch count" )),
62- cl::cat(MergeFdataCategory));
63-
64- static cl::opt<bool >
65- SuppressMergedDataOutput (" q" ,
66- cl::desc (" do not print merged data to stdout" ),
67- cl::init(false ),
68- cl::Optional,
69- cl::cat(MergeFdataCategory));
70-
71- static cl::opt<std::string>
72- OutputFilePath (" o" ,
73- cl::value_desc (" file" ),
74- cl::desc(" Write output to <file>" ),
75- cl::cat(MergeFdataCategory));
42+ InputDataFilenames (cl::Positional, cl::CommaSeparated,
43+ cl::desc (" <fdata1> [<fdata2>]..." ), cl::OneOrMore,
44+ cl::cat(MergeFdataCategory));
45+
46+ static cl::opt<SortType> PrintFunctionList (
47+ " print" , cl::desc(" print the list of objects with count to stderr" ),
48+ cl::init(ST_NONE),
49+ cl::values(clEnumValN(ST_NONE, " none" , " do not print objects/functions" ),
50+ clEnumValN(ST_EXEC_COUNT, " exec" ,
51+ " print functions sorted by execution count" ),
52+ clEnumValN(ST_TOTAL_BRANCHES, " branches" ,
53+ " print functions sorted by total branch count" )),
54+ cl::cat(MergeFdataCategory));
55+
56+ static cl::opt<bool > SuppressMergedDataOutput (
57+ " q" , cl::desc(" do not print merged data to stdout" ), cl::init(false ),
58+ cl::Optional, cl::cat(MergeFdataCategory));
59+
60+ static cl::opt<std::string> OutputFilePath (" o" , cl::value_desc(" file" ),
61+ cl::desc(" Write output to <file>" ),
62+ cl::cat(MergeFdataCategory));
7663
7764} // namespace opts
7865
@@ -265,7 +252,10 @@ bool isYAML(const StringRef Filename) {
265252void mergeLegacyProfiles (const SmallVectorImpl<std::string> &Filenames) {
266253 errs () << " Using legacy profile format.\n " ;
267254 std::optional<bool > BoltedCollection;
255+ std::optional<bool > NoLbr;
268256 std::mutex BoltedCollectionMutex;
257+ std::mutex NoLbrMutex;
258+ std::string NoLbrLabel;
269259 typedef StringMap<uint64_t > ProfileTy;
270260
271261 auto ParseProfile = [&](const std::string &Filename, auto &Profiles) {
@@ -298,6 +288,25 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
298288 BoltedCollection = false ;
299289 }
300290
291+ std::lock_guard<std::mutex> Lock1 (NoLbrMutex);
292+ // Check if the string "no_lbr" is in the first line
293+ if (Buf.starts_with (" no_lbr" )) {
294+ if (!NoLbr.value_or (true ))
295+ report_error (
296+ Filename,
297+ " cannot mix profile collected on LBR and non-LBR architectures" );
298+ NoLbr = true ;
299+ size_t Pos = Buf.find (" \n " );
300+ NoLbrLabel = Buf.substr (0 , Pos).str ();
301+ Buf = Buf.drop_front (Pos + 1 );
302+ } else {
303+ if (NoLbr.value_or (false ))
304+ report_error (
305+ Filename,
306+ " cannot mix profile collected on LBR and non-LBR architectures" );
307+ NoLbr = false ;
308+ }
309+
301310 Profile = &Profiles[tid];
302311 }
303312
@@ -336,6 +345,8 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
336345
337346 if (BoltedCollection.value_or (false ))
338347 output () << " boltedcollection\n " ;
348+ if (NoLbr.value_or (false ))
349+ output () << NoLbrLabel << " \n " ;
339350 for (const auto &[Key, Value] : MergedProfile)
340351 output () << Key << " " << Value << " \n " ;
341352
0 commit comments