@@ -222,8 +222,6 @@ std::error_code SampleProfileReaderText::readImpl() {
222222 sampleprof_error Result = sampleprof_error::success;
223223
224224 InlineCallStack InlineStack;
225- int CSProfileCount = 0 ;
226- int RegularProfileCount = 0 ;
227225 uint32_t ProbeProfileCount = 0 ;
228226
229227 // SeenMetadata tracks whether we have processed metadata for the current
@@ -257,11 +255,9 @@ std::error_code SampleProfileReaderText::readImpl() {
257255 SampleContext FContext (FName);
258256 if (FContext.hasContext ())
259257 ++CSProfileCount;
260- else
261- ++RegularProfileCount;
262258 Profiles[FContext] = FunctionSamples ();
263259 FunctionSamples &FProfile = Profiles[FContext];
264- FProfile.setName (FContext.getName ());
260+ FProfile.setName (FContext.getNameWithoutContext ());
265261 FProfile.setContext (FContext);
266262 MergeResult (Result, FProfile.addTotalSamples (NumSamples));
267263 MergeResult (Result, FProfile.addHeadSamples (NumHeadSamples));
@@ -324,13 +320,14 @@ std::error_code SampleProfileReaderText::readImpl() {
324320 }
325321 }
326322
327- assert ((RegularProfileCount == 0 || CSProfileCount == 0 ) &&
323+ assert ((CSProfileCount == 0 || CSProfileCount == Profiles. size () ) &&
328324 " Cannot have both context-sensitive and regular profile" );
329325 ProfileIsCS = (CSProfileCount > 0 );
330326 assert ((ProbeProfileCount == 0 || ProbeProfileCount == Profiles.size ()) &&
331327 " Cannot have both probe-based profiles and regular profiles" );
332328 ProfileIsProbeBased = (ProbeProfileCount > 0 );
333329 FunctionSamples::ProfileIsProbeBased = ProfileIsProbeBased;
330+ FunctionSamples::ProfileIsCS = ProfileIsCS;
334331
335332 if (Result == sampleprof_error::success)
336333 computeSummary ();
@@ -546,12 +543,16 @@ SampleProfileReaderBinary::readFuncProfile(const uint8_t *Start) {
546543 if (std::error_code EC = FName.getError ())
547544 return EC;
548545
549- Profiles[*FName] = FunctionSamples ();
550- FunctionSamples &FProfile = Profiles[*FName];
551- FProfile.setName (*FName);
552-
546+ SampleContext FContext (*FName);
547+ Profiles[FContext] = FunctionSamples ();
548+ FunctionSamples &FProfile = Profiles[FContext];
549+ FProfile.setName (FContext.getNameWithoutContext ());
550+ FProfile.setContext (FContext);
553551 FProfile.addHeadSamples (*NumHeadSamples);
554552
553+ if (FContext.hasContext ())
554+ CSProfileCount++;
555+
555556 if (std::error_code EC = readProfile (FProfile))
556557 return EC;
557558 return sampleprof_error::success;
@@ -654,40 +655,44 @@ std::error_code SampleProfileReaderExtBinaryBase::readFuncProfiles() {
654655 return EC;
655656 }
656657 assert (Data == End && " More data is read than expected" );
657- return sampleprof_error::success;
658- }
659-
660- if (Remapper) {
661- for (auto Name : FuncsToUse) {
662- Remapper->insert (Name);
658+ } else {
659+ if (Remapper) {
660+ for (auto Name : FuncsToUse) {
661+ Remapper->insert (Name);
662+ }
663663 }
664- }
665664
666- if (useMD5 ()) {
667- for (auto Name : FuncsToUse) {
668- auto GUID = std::to_string (MD5Hash (Name));
669- auto iter = FuncOffsetTable.find (StringRef (GUID));
670- if (iter == FuncOffsetTable.end ())
671- continue ;
672- const uint8_t *FuncProfileAddr = Start + iter->second ;
673- assert (FuncProfileAddr < End && " out of LBRProfile section" );
674- if (std::error_code EC = readFuncProfile (FuncProfileAddr))
675- return EC;
676- }
677- } else {
678- for (auto NameOffset : FuncOffsetTable) {
679- auto FuncName = NameOffset.first ;
680- if (!FuncsToUse.count (FuncName) &&
681- (!Remapper || !Remapper->exist (FuncName)))
682- continue ;
683- const uint8_t *FuncProfileAddr = Start + NameOffset.second ;
684- assert (FuncProfileAddr < End && " out of LBRProfile section" );
685- if (std::error_code EC = readFuncProfile (FuncProfileAddr))
686- return EC;
665+ if (useMD5 ()) {
666+ for (auto Name : FuncsToUse) {
667+ auto GUID = std::to_string (MD5Hash (Name));
668+ auto iter = FuncOffsetTable.find (StringRef (GUID));
669+ if (iter == FuncOffsetTable.end ())
670+ continue ;
671+ const uint8_t *FuncProfileAddr = Start + iter->second ;
672+ assert (FuncProfileAddr < End && " out of LBRProfile section" );
673+ if (std::error_code EC = readFuncProfile (FuncProfileAddr))
674+ return EC;
675+ }
676+ } else {
677+ for (auto NameOffset : FuncOffsetTable) {
678+ SampleContext FContext (NameOffset.first );
679+ auto FuncName = FContext.getNameWithoutContext ();
680+ if (!FuncsToUse.count (FuncName) &&
681+ (!Remapper || !Remapper->exist (FuncName)))
682+ continue ;
683+ const uint8_t *FuncProfileAddr = Start + NameOffset.second ;
684+ assert (FuncProfileAddr < End && " out of LBRProfile section" );
685+ if (std::error_code EC = readFuncProfile (FuncProfileAddr))
686+ return EC;
687+ }
687688 }
689+ Data = End;
688690 }
689691
690- Data = End;
692+ assert ((CSProfileCount == 0 || CSProfileCount == Profiles.size ()) &&
693+ " Cannot have both context-sensitive and regular profile" );
694+ ProfileIsCS = (CSProfileCount > 0 );
695+ FunctionSamples::ProfileIsCS = ProfileIsCS;
691696 return sampleprof_error::success;
692697}
693698
@@ -887,7 +892,8 @@ std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata() {
887892 if (std::error_code EC = Checksum.getError ())
888893 return EC;
889894
890- Profiles[*FName].setFunctionHash (*Checksum);
895+ SampleContext FContext (*FName);
896+ Profiles[FContext].setFunctionHash (*Checksum);
891897 }
892898 return sampleprof_error::success;
893899}
0 commit comments