Index: llvm/include/llvm/ProfileData/SampleProf.h =================================================================== --- llvm/include/llvm/ProfileData/SampleProf.h +++ llvm/include/llvm/ProfileData/SampleProf.h @@ -1342,7 +1342,7 @@ // To retain the context, checksum, attributes of the original profile, make // a copy of it if no profile is found. SampleContext &Context = FS.getContext(); - auto Ret = OutputProfiles.emplace(Context, FS); + auto Ret = OutputProfiles.try_emplace(Context, FS); FunctionSamples &Profile = Ret.first->second; if (Ret.second) { // When it's the copy of the old profile, just clear all the inlinees' @@ -1351,9 +1351,14 @@ // We recompute TotalSamples later, so here set to zero. Profile.setTotalSamples(0); } else { - for (const auto &Line : FS.getBodySamples()) { - Profile.addBodySamples(Line.first.LineOffset, Line.first.Discriminator, - Line.second.getSamples()); + for (const auto &[DI, SampleRecord] : FS.getBodySamples()) { + Profile.addBodySamples(DI.LineOffset, DI.Discriminator, + SampleRecord.getSamples()); + for (const auto &[CalledTarget, CallTargetSamples] : + SampleRecord.getCallTargets()) { + Profile.addCalledTargetSamples(DI.LineOffset, DI.Discriminator, + CalledTarget, CallTargetSamples); + } } } Index: llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext =================================================================== --- llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext +++ llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext @@ -1,6 +1,7 @@ baz:160:10 1: 10 3: 20 + 4: 21 qux:5 quux:6 corge:10 5: foo:30 1: 20 3: bar:10 Index: llvm/test/tools/llvm-profdata/sample-flatten-profile.test =================================================================== --- llvm/test/tools/llvm-profdata/sample-flatten-profile.test +++ llvm/test/tools/llvm-profdata/sample-flatten-profile.test @@ -7,6 +7,7 @@ ; CHECK:baz:169:10 ; CHECK-NEXT: 1: 10 ; CHECK-NEXT: 3: 20 +; CHECK-NEXT: 4: 21 corge:10 quux:6 qux:5 ; CHECK-NEXT: 5: 20 foo:20 ; CHECK-NEXT: 6: 2 bar:2 ; CHECK-NEXT: 10: 1