diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -143,7 +143,7 @@ /// will be a list of one or more functions. class SampleRecord { public: - using CallTargetMap = StringMap; + using CallTargetMap = std::map; SampleRecord() = default; @@ -185,7 +185,7 @@ sampleprof_error merge(const SampleRecord &Other, uint64_t Weight = 1) { sampleprof_error Result = addSamples(Other.getSamples(), Weight); for (const auto &I : Other.getCallTargets()) { - MergeResult(Result, addCalledTarget(I.first(), I.second, Weight)); + MergeResult(Result, addCalledTarget(I.first, I.second, Weight)); } return Result; } @@ -388,11 +388,11 @@ // profile annotation cannot be done until backend compilation in ThinLTO. for (const auto &BS : BodySamples) for (const auto &TS : BS.second.getCallTargets()) - if (TS.getValue() > Threshold) { + if (TS.second > Threshold) { const Function *Callee = - M->getFunction(getNameInModule(TS.getKey(), M)); + M->getFunction(getNameInModule(TS.first, M)); if (!Callee || !Callee->getSubprogram()) - S.insert(getGUID(TS.getKey())); + S.insert(getGUID(TS.first)); } for (const auto &CS : CallsiteSamples) for (const auto &NameFS : CS.second) diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp --- a/llvm/lib/ProfileData/SampleProf.cpp +++ b/llvm/lib/ProfileData/SampleProf.cpp @@ -101,7 +101,7 @@ if (hasCalls()) { OS << ", calls:"; for (const auto &I : getCallTargets()) - OS << " " << I.first() << ":" << I.second; + OS << " " << I.first << ":" << I.second; } OS << "\n"; } diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -101,7 +101,7 @@ OS << Sample.getSamples(); for (const auto &J : Sample.getCallTargets()) - OS << " " << J.first() << ":" << J.second; + OS << " " << J.first << ":" << J.second; OS << "\n"; } @@ -142,7 +142,7 @@ for (const auto &I : S.getBodySamples()) { const SampleRecord &Sample = I.second; for (const auto &J : Sample.getCallTargets()) - addName(J.first()); + addName(J.first); } // Recursively add all the names for inlined callsites. @@ -295,7 +295,7 @@ encodeULEB128(Sample.getSamples(), OS); encodeULEB128(Sample.getCallTargets().size(), OS); for (const auto &J : Sample.getCallTargets()) { - StringRef Callee = J.first(); + StringRef Callee = J.first; uint64_t CalleeSamples = J.second; if (std::error_code EC = writeNameIdx(Callee)) return EC; diff --git a/llvm/lib/Target/X86/X86InsertPrefetch.cpp b/llvm/lib/Target/X86/X86InsertPrefetch.cpp --- a/llvm/lib/Target/X86/X86InsertPrefetch.cpp +++ b/llvm/lib/Target/X86/X86InsertPrefetch.cpp @@ -123,7 +123,7 @@ // Convert serialized prefetch hints into PrefetchInfo objects, and populate // the Prefetches vector. for (const auto &S_V : *T) { - StringRef Name = S_V.getKey(); + StringRef Name = S_V.first; if (Name.consume_front(SerializedPrefetchPrefix)) { int64_t D = static_cast(S_V.second); unsigned IID = 0; diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -1296,7 +1296,7 @@ const SampleRecord::CallTargetMap &M) { SmallVector R; for (auto I = M.begin(); I != M.end(); ++I) - R.push_back({FunctionSamples::getGUID(I->getKey()), I->getValue()}); + R.push_back({FunctionSamples::getGUID(I->first), I->second}); llvm::sort(R, [](const InstrProfValueData &L, const InstrProfValueData &R) { if (L.Count == R.Count) return L.Value > R.Value; diff --git a/llvm/test/tools/llvm-profdata/Inputs/sample-profile.proftext b/llvm/test/tools/llvm-profdata/Inputs/sample-profile.proftext --- a/llvm/test/tools/llvm-profdata/Inputs/sample-profile.proftext +++ b/llvm/test/tools/llvm-profdata/Inputs/sample-profile.proftext @@ -1,7 +1,3 @@ -_Z3bari:20301:1437 - 1: 1437 -_Z3fooi:7711:610 - 1: 610 main:184019:0 4: 534 4.2: 534 @@ -14,3 +10,7 @@ 1: 1000 10: inline2:2000 1: 2000 +_Z3bari:20301:1437 + 1: 1437 +_Z3fooi:7711:610 + 1: 610 diff --git a/llvm/test/tools/llvm-profdata/roundtrip.test b/llvm/test/tools/llvm-profdata/roundtrip.test --- a/llvm/test/tools/llvm-profdata/roundtrip.test +++ b/llvm/test/tools/llvm-profdata/roundtrip.test @@ -4,3 +4,6 @@ RUN: llvm-profdata merge -o %t.1.profdata %t.0.proftext RUN: llvm-profdata show -o %t.1.proftext -all-functions -text %t.1.profdata RUN: diff %t.1.proftext %S/Inputs/IR_profile.proftext +RUN: llvm-profdata merge --sample --binary -output=%t.2.profdata %S/Inputs/sample-profile.proftext +RUN: llvm-profdata merge --sample --text -output=%t.2.proftext %t.2.profdata +RUN: diff %t.2.proftext %S/Inputs/sample-profile.proftext \ No newline at end of file diff --git a/llvm/test/tools/llvm-profdata/sample-profile-basic.test b/llvm/test/tools/llvm-profdata/sample-profile-basic.test --- a/llvm/test/tools/llvm-profdata/sample-profile-basic.test +++ b/llvm/test/tools/llvm-profdata/sample-profile-basic.test @@ -3,7 +3,7 @@ 1- Show all functions RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW1 SHOW1-DAG: Function: main: 184019, 0, 7 sampled lines -SHOW1-DAG: 9: 2064, calls: _Z3fooi:631 _Z3bari:1471 +SHOW1-DAG: 9: 2064, calls: _Z3bari:1471 _Z3fooi:631 SHOW1-DAG: Function: _Z3fooi: 7711, 610, 1 sampled lines SHOW1-DAG: Function: _Z3bari: 20301, 1437, 1 sampled lines SHOW1-DAG: 1: 1437 @@ -26,7 +26,7 @@ RUN: llvm-profdata merge --sample %p/Inputs/sample-profile.proftext -o %t-binprof RUN: llvm-profdata merge --sample --text %p/Inputs/sample-profile.proftext %t-binprof -o - | FileCheck %s --check-prefix=MERGE1 MERGE1: main:368038:0 -MERGE1: 9: 4128 _Z3fooi:1262 _Z3bari:2942 +MERGE1: 9: 4128 _Z3bari:2942 _Z3fooi:1262 MERGE1: _Z3bari:40602:2874 MERGE1: _Z3fooi:15422:1220 diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -409,7 +409,7 @@ for (const auto &Target : BodySample.second.getCallTargets()) { Result.addCalledTargetSamples(BodySample.first.LineOffset, BodySample.first.Discriminator, - Remapper(Target.first()), Target.second); + Remapper(Target.first), Target.second); } } for (const auto &CallsiteSamples : Samples.getCallsiteSamples()) {