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 @@ -360,10 +360,7 @@ /// it needs to be parsed by the SampleProfileReaderText class. std::error_code SampleProfileWriterText::writeSample(const FunctionSamples &S) { auto &OS = *OutputStream; - if (FunctionSamples::ProfileIsCS) - OS << "[" << S.getNameWithContext() << "]:" << S.getTotalSamples(); - else - OS << S.getName() << ":" << S.getTotalSamples(); + OS << S.getNameWithContext(true) << ":" << S.getTotalSamples(); if (Indent == 0) OS << ":" << S.getHeadSamples(); OS << "\n"; diff --git a/llvm/test/tools/llvm-profgen/cs-extbinary.test b/llvm/test/tools/llvm-profgen/cs-extbinary.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-profgen/cs-extbinary.test @@ -0,0 +1,14 @@ +; test for dwarf-based cs profile +; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/recursion-compression-noprobe.perfscript --binary=%S/Inputs/recursion-compression-noprobe.perfbin --output=%t1 --csprof-cold-thres=0 +; RUN: llvm-profdata merge --sample --text --output=%t2 %t1 +; RUN: FileCheck %S/recursion-compression-noprobe.test --input-file %t2 +; RUN: llvm-profdata merge --sample --extbinary --output=%t3 %t2 && llvm-profdata merge --sample --text --output=%t4 %t3 +; RUN: diff -b %t2 %t4 + + +; test for probe-based cs profile +; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/recursion-compression-pseudoprobe.perfscript --binary=%S/Inputs/recursion-compression-pseudoprobe.perfbin --output=%t5 --csprof-cold-thres=0 +; RUN: llvm-profdata merge --sample --text --output=%t6 %t5 +; RUN: FileCheck %S/recursion-compression-pseudoprobe.test --input-file %t6 +; RUN: llvm-profdata merge --sample --extbinary --output=%t7 %t6 && llvm-profdata merge --sample --text --output=%t8 %t7 +; RUN: diff -b %t6 %t8 diff --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test --- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test +++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test @@ -2,11 +2,11 @@ ; RUN: FileCheck %s --input-file %t ; CHECK:[main:1 @ foo]:44:0 -; CHECK: 2.2: 14 +; CHECK: 2.1: 14 ; CHECK: 3: 15 -; CHECK: 3.2: 14 bar:14 -; CHECK: 3.4: 1 -; CHECK:[main:1 @ foo:3.2 @ bar]:14:0 +; CHECK: 3.1: 14 bar:14 +; CHECK: 3.2: 1 +; CHECK:[main:1 @ foo:3.1 @ bar]:14:0 ; CHECK: 1: 14 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Range Counter: @@ -15,10 +15,9 @@ ; CHECK-UNWINDER: (67e, 69b): 1 ; CHECK-UNWINDER: (67e, 6ad): 13 ; CHECK-UNWINDER: (6bd, 6c8): 14 -; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar +; CHECK-UNWINDER: main:1 @ foo:3.1 @ bar ; CHECK-UNWINDER: (6af, 6bb): 14 - ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Branch Counter: ; CHECK-UNWINDER: main:1 @ foo ; CHECK-UNWINDER: (69b, 670): 1 diff --git a/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test --- a/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test +++ b/llvm/test/tools/llvm-profgen/noinline-cs-noprobe.test @@ -36,6 +36,8 @@ + + ; original code: ; clang -O0 -g test.c -o a.out #include diff --git a/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test b/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test --- a/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test +++ b/llvm/test/tools/llvm-profgen/recursion-compression-noprobe.test @@ -10,16 +10,17 @@ ; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb]:12:0 ; CHECK-UNCOMPRESS: 1: 11 ; CHECK-UNCOMPRESS: 2: 1 fa:1 -; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:3:0 -; CHECK-UNCOMPRESS: 1: 1 -; CHECK-UNCOMPRESS: 2: 2 fb:1 ; CHECK-UNCOMPRESS:[main:1 @ foo]:3:0 ; CHECK-UNCOMPRESS: 2: 1 ; CHECK-UNCOMPRESS: 3: 2 fa:1 -; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa:2 @ fb:2 @ fa]:1:0 -; CHECK-UNCOMPRESS: 4: 1 +; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa]:3:0 +; CHECK-UNCOMPRESS: 1: 1 +; CHECK-UNCOMPRESS: 2: 2 fb:1 ; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa:2 @ fb]:1:0 ; CHECK-UNCOMPRESS: 2: 1 fa:1 +; CHECK-UNCOMPRESS:[main:1 @ foo:3 @ fa:2 @ fb:2 @ fa:2 @ fb:2 @ fa]:1:0 +; CHECK-UNCOMPRESS: 4: 1 + ; CHECK: [main:1 @ foo:3 @ fa]:14:0 ; CHECK: 1: 1 diff --git a/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test b/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test --- a/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test +++ b/llvm/test/tools/llvm-profgen/recursion-compression-pseudoprobe.test @@ -4,11 +4,11 @@ ; RUN: llvm-profgen --perfscript=%S/Inputs/recursion-compression-pseudoprobe.perfscript --binary=%S/Inputs/recursion-compression-pseudoprobe.perfbin --output=%t --show-unwinder-output --csprof-cold-thres=0 | FileCheck %s --check-prefix=CHECK-UNWINDER ; RUN: FileCheck %s --input-file %t -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa]:4:1 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa]:4:1 ; CHECK-UNCOMPRESS: 1: 1 ; CHECK-UNCOMPRESS: 3: 1 -; CHECK-UNCOMPRESS: 4: 1 -; CHECK-UNCOMPRESS: 7: 1 fb:1 +; CHECK-UNCOMPRESS: 5: 1 +; CHECK-UNCOMPRESS: 8: 1 fa:1 ; CHECK-UNCOMPRESS: !CFGChecksum: 120515930909 ; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa]:4:1 ; CHECK-UNCOMPRESS: 1: 1 @@ -16,28 +16,13 @@ ; CHECK-UNCOMPRESS: 4: 1 ; CHECK-UNCOMPRESS: 7: 1 fb:1 ; CHECK-UNCOMPRESS: !CFGChecksum: 120515930909 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa]:4:1 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa]:4:1 ; CHECK-UNCOMPRESS: 1: 1 ; CHECK-UNCOMPRESS: 3: 1 -; CHECK-UNCOMPRESS: 5: 1 -; CHECK-UNCOMPRESS: 8: 1 fa:1 +; CHECK-UNCOMPRESS: 4: 1 +; CHECK-UNCOMPRESS: 7: 1 fb:1 ; CHECK-UNCOMPRESS: !CFGChecksum: 120515930909 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa:7 @ fb]:3:1 -; CHECK-UNCOMPRESS: 1: 1 -; CHECK-UNCOMPRESS: 3: 1 -; CHECK-UNCOMPRESS: 6: 1 fa:1 -; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb]:3:1 -; CHECK-UNCOMPRESS: 1: 1 -; CHECK-UNCOMPRESS: 3: 1 -; CHECK-UNCOMPRESS: 6: 1 fa:1 -; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 -; CHECK-UNCOMPRESS: 1: 1 -; CHECK-UNCOMPRESS: 3: 1 -; CHECK-UNCOMPRESS: 6: 1 fa:1 -; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 ; CHECK-UNCOMPRESS: 1: 1 ; CHECK-UNCOMPRESS: 2: 1 ; CHECK-UNCOMPRESS: 5: 1 fb:1 @@ -47,11 +32,26 @@ ; CHECK-UNCOMPRESS: 2: 1 ; CHECK-UNCOMPRESS: 5: 1 fb:1 ; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 -; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 ; CHECK-UNCOMPRESS: 1: 1 ; CHECK-UNCOMPRESS: 2: 1 ; CHECK-UNCOMPRESS: 5: 1 fb:1 ; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb]:3:1 +; CHECK-UNCOMPRESS: 1: 1 +; CHECK-UNCOMPRESS: 3: 1 +; CHECK-UNCOMPRESS: 6: 1 fa:1 +; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb]:3:1 +; CHECK-UNCOMPRESS: 1: 1 +; CHECK-UNCOMPRESS: 3: 1 +; CHECK-UNCOMPRESS: 6: 1 fa:1 +; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 +; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa:7 @ fb]:3:1 +; CHECK-UNCOMPRESS: 1: 1 +; CHECK-UNCOMPRESS: 3: 1 +; CHECK-UNCOMPRESS: 6: 1 fa:1 +; CHECK-UNCOMPRESS: !CFGChecksum: 72617220756 ; CHECK-UNCOMPRESS: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa:7 @ fb:6 @ fa]:2:1 ; CHECK-UNCOMPRESS: 1: 1 ; CHECK-UNCOMPRESS: 3: 1 @@ -74,30 +74,31 @@ ; CHECK: 4: 1 ; CHECK: 7: 1 fb:1 ; CHECK: !CFGChecksum: 120515930909 -; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa]:4:1 -; CHECK: 1: 1 -; CHECK: 3: 1 -; CHECK: 4: 1 -; CHECK: 7: 1 fb:1 -; CHECK: !CFGChecksum: 120515930909 ; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa]:4:1 ; CHECK: 1: 1 ; CHECK: 3: 1 ; CHECK: 5: 1 ; CHECK: 8: 1 fa:1 ; CHECK: !CFGChecksum: 120515930909 -; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa:7 @ fb]:3:1 +; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa]:4:1 +; CHECK: 1: 1 +; CHECK: 3: 1 +; CHECK: 4: 1 +; CHECK: 7: 1 fb:1 +; CHECK: !CFGChecksum: 120515930909 +; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb]:3:1 ; CHECK: 1: 1 ; CHECK: 3: 1 ; CHECK: 6: 1 fa:1 ; CHECK: !CFGChecksum: 72617220756 -; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb]:3:1 +; CHECK: [main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 @ fb:6 @ fa:8 @ fa:7 @ fb:6 @ fa:7 @ fb]:3:1 ; CHECK: 1: 1 ; CHECK: 3: 1 ; CHECK: 6: 1 fa:1 ; CHECK: !CFGChecksum: 72617220756 + ; CHECK-UNWINDER: Binary(recursion-compression-pseudoprobe.perfbin)'s Range Counter: ; CHECK-UNWINDER: main:2 @ foo:5 @ fa:8 @ fa:7 @ fb:5 ; CHECK-UNWINDER: (7a0, 7a7): 1 diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.h b/llvm/tools/llvm-profgen/ProfileGenerator.h --- a/llvm/tools/llvm-profgen/ProfileGenerator.h +++ b/llvm/tools/llvm-profgen/ProfileGenerator.h @@ -28,11 +28,9 @@ create(const BinarySampleCounterMap &BinarySampleCounters, enum PerfScriptType SampleType); virtual void generateProfile() = 0; - // Merge and trim profile with cold context before serialization, - // only eligible for CS profile - virtual void - mergeAndTrimColdProfile(StringMap &ProfileMap){}; // Use SampleProfileWriter to serialize profile map + virtual void write(std::unique_ptr Writer, + StringMap &ProfileMap); void write(); protected: @@ -68,8 +66,6 @@ public: void generateProfile() override { - // Enable context-sensitive functionalities in SampleProf - FunctionSamples::ProfileIsCS = true; for (const auto &BI : BinarySampleCounters) { ProfiledBinary *Binary = BI.first; for (const auto &CI : BI.second) { @@ -205,7 +201,9 @@ FunctionSamples &getFunctionProfileForContext(StringRef ContextId); // Merge cold context profile whose total sample is below threshold // into base profile. - void mergeAndTrimColdProfile(StringMap &ProfileMap) override; + void mergeAndTrimColdProfile(StringMap &ProfileMap); + void write(std::unique_ptr Writer, + StringMap &ProfileMap) override; private: // Helper function for updating body sample for a leaf location in diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -76,13 +76,16 @@ return ProfileGenerator; } +void ProfileGenerator::write(std::unique_ptr Writer, + StringMap &ProfileMap) { + Writer->write(ProfileMap); +} + void ProfileGenerator::write() { auto WriterOrErr = SampleProfileWriter::create(OutputFilename, OutputFormat); if (std::error_code EC = WriterOrErr.getError()) exitWithError(EC, OutputFilename); - auto Writer = std::move(WriterOrErr.get()); - mergeAndTrimColdProfile(ProfileMap); - Writer->write(ProfileMap); + write(std::move(WriterOrErr.get()), ProfileMap); } void ProfileGenerator::findDisjointRanges(RangeSample &DisjointRanges, @@ -188,7 +191,6 @@ if (Ret.second) { SampleContext FContext(Ret.first->first(), RawContext); FunctionSamples &FProfile = Ret.first->second; - FProfile.setName(FContext.getNameWithoutContext()); FProfile.setContext(FContext); } return Ret.first->second; @@ -268,16 +270,15 @@ CalleeName, Count); // Record head sample for called target(callee) - // TODO: Cleanup ' @ ' - std::string CalleeContextId = - getCallSite(LeafLoc) + " @ " + CalleeName.str(); + std::ostringstream OCalleeCtxStr; if (ContextId.find(" @ ") != StringRef::npos) { - CalleeContextId = - ContextId.rsplit(" @ ").first.str() + " @ " + CalleeContextId; + OCalleeCtxStr << ContextId.rsplit(" @ ").first.str(); + OCalleeCtxStr << " @ "; } + OCalleeCtxStr << getCallSite(LeafLoc) << " @ " << CalleeName.str(); FunctionSamples &CalleeProfile = - getFunctionProfileForContext(CalleeContextId); + getFunctionProfileForContext(OCalleeCtxStr.str()); assert(Count != 0 && "Unexpected zero weight branch"); CalleeProfile.addHeadSamples(Count); } @@ -334,8 +335,8 @@ EstimatedCallCount = 1; CallerProfile.addCalledTargetSamples( CallerLeafFrameLoc.second.LineOffset, - CallerLeafFrameLoc.second.Discriminator, CalleeProfile.getName(), - EstimatedCallCount); + CallerLeafFrameLoc.second.Discriminator, + CalleeProfile.getContext().getNameWithoutContext(), EstimatedCallCount); CallerProfile.addBodySamples(CallerLeafFrameLoc.second.LineOffset, CallerLeafFrameLoc.second.Discriminator, EstimatedCallCount); @@ -362,8 +363,8 @@ // Remove the code profile from ProfileMap and merge them into BaseProileMap StringMap BaseProfileMap; for (const auto &I : ToRemoveVec) { - auto Ret = - BaseProfileMap.try_emplace(I.second->getName(), FunctionSamples()); + auto Ret = BaseProfileMap.try_emplace( + I.second->getContext().getNameWithoutContext(), FunctionSamples()); FunctionSamples &BaseProfile = Ret.first->second; BaseProfile.merge(*I.second); ProfileMap.erase(I.first); @@ -378,14 +379,27 @@ // Merge the profile if the original profile exists, otherwise just insert // as a new profile FunctionSamples &OrigProfile = getFunctionProfileForContext(I.getKey()); - StringRef TmpName = OrigProfile.getName(); OrigProfile.merge(I.second); - // Should use the name ref from ProfileMap's key to avoid name being freed - // from BaseProfileMap - OrigProfile.setName(TmpName); } } +void CSProfileGenerator::write(std::unique_ptr Writer, + StringMap &ProfileMap) { + mergeAndTrimColdProfile(ProfileMap); + // Add bracket for context key to support different profile binary format + StringMap CxtWithBracketPMap; + for (const auto &Item : ProfileMap) { + std::string ContextWithBracket = "[" + Item.first().str() + "]"; + auto Ret = CxtWithBracketPMap.try_emplace(ContextWithBracket, Item.second); + assert(Ret.second && "Must be a unique context"); + SampleContext FContext(Ret.first->first(), RawContext); + FunctionSamples &FProfile = Ret.first->second; + FProfile.setName(FContext.getNameWithContext(true)); + FProfile.setContext(FContext); + } + Writer->write(CxtWithBracketPMap); +} + // Helper function to extract context prefix string stack // Extract context stack for reusing, leaf context stack will // be added compressed while looking up function profile @@ -399,8 +413,7 @@ } void PseudoProbeCSProfileGenerator::generateProfile() { - // Enable CS and pseudo probe functionalities in SampleProf - FunctionSamples::ProfileIsCS = true; + // Enable pseudo probe functionalities in SampleProf FunctionSamples::ProfileIsProbeBased = true; for (const auto &BI : BinarySampleCounters) { ProfiledBinary *Binary = BI.first; @@ -495,8 +508,9 @@ CallerProfile.setFunctionHash(InlinerDesc->FuncHash); CallerProfile.addBodySamples(CallerIndex, 0, Count); CallerProfile.addTotalSamples(Count); - CallerProfile.addCalledTargetSamples(CallerIndex, 0, - FunctionProfile.getName(), Count); + CallerProfile.addCalledTargetSamples( + CallerIndex, 0, + FunctionProfile.getContext().getNameWithoutContext(), Count); } } } diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -11,6 +11,7 @@ #include "ProfileGenerator.h" #include "llvm/ADT/Triple.h" #include "llvm/Demangle/Demangle.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Format.h" #include "llvm/Support/TargetRegistry.h" @@ -393,7 +394,8 @@ if (UseCanonicalFnName) FunctionName = FunctionSamples::getCanonicalFnName(FunctionName); LineLocation Line(CallerFrame.Line - CallerFrame.StartLine, - CallerFrame.Discriminator); + DILocation::getBaseDiscriminatorFromDiscriminator( + CallerFrame.Discriminator)); FrameLocation Callsite(FunctionName.str(), Line); CallStack.push_back(Callsite); }