@@ -392,6 +392,11 @@ class SampleProfileReader {
392
392
// / which doesn't support loading function profiles on demand.
393
393
virtual bool collectFuncsFromModule () { return false ; }
394
394
395
+ virtual std::error_code readOnDemand (const DenseSet<StringRef> &FuncsToUse,
396
+ SampleProfileMap &Profiles) {
397
+ return sampleprof_error::not_implemented;
398
+ };
399
+
395
400
// / Print all the profiles on stream \p OS.
396
401
void dump (raw_ostream &OS = dbgs());
397
402
@@ -413,6 +418,16 @@ class SampleProfileReader {
413
418
if (It != Profiles.end ())
414
419
return &It->second ;
415
420
421
+ if (FuncNameToProfNameMap && !FuncNameToProfNameMap->empty ()) {
422
+ auto R = FuncNameToProfNameMap->find (FunctionId (Fname));
423
+ if (R != FuncNameToProfNameMap->end ()) {
424
+ Fname = R->second .stringRef ();
425
+ auto It = Profiles.find (FunctionId (Fname));
426
+ if (It != Profiles.end ())
427
+ return &It->second ;
428
+ }
429
+ }
430
+
416
431
if (Remapper) {
417
432
if (auto NameInProfile = Remapper->lookUpNameInProfile (Fname)) {
418
433
auto It = Profiles.find (FunctionId (*NameInProfile));
@@ -494,6 +509,11 @@ class SampleProfileReader {
494
509
495
510
void setModule (const Module *Mod) { M = Mod; }
496
511
512
+ void setFuncNameToProfNameMap (
513
+ HashKeyMap<std::unordered_map, FunctionId, FunctionId> *FPMap) {
514
+ FuncNameToProfNameMap = FPMap;
515
+ }
516
+
497
517
protected:
498
518
// / Map every function to its associated profile.
499
519
// /
@@ -522,6 +542,21 @@ class SampleProfileReader {
522
542
523
543
std::unique_ptr<SampleProfileReaderItaniumRemapper> Remapper;
524
544
545
+ // A map pointer to the FuncNameToProfNameMap in SampleProfileLoader,
546
+ // which maps the function name to the matched profile name. This is used
547
+ // for sample loader to look up profile using the new name.
548
+ HashKeyMap<std::unordered_map, FunctionId, FunctionId>
549
+ *FuncNameToProfNameMap = nullptr ;
550
+
551
+ // A map from a function's context hash to its meta data section range, used
552
+ // for on-demand read function profile metadata.
553
+ std::unordered_map<uint64_t , std::pair<const uint8_t *, const uint8_t *>>
554
+ FContextToMetaDataSecRange;
555
+
556
+ std::pair<const uint8_t *, const uint8_t *> LBRProfileSecRange;
557
+
558
+ bool ProfileHasAttribute = false ;
559
+
525
560
// / \brief Whether samples are collected based on pseudo probes.
526
561
bool ProfileIsProbeBased = false ;
527
562
@@ -621,6 +656,8 @@ class SampleProfileReaderBinary : public SampleProfileReader {
621
656
622
657
// / Read the next function profile instance.
623
658
std::error_code readFuncProfile (const uint8_t *Start);
659
+ std::error_code readFuncProfile (const uint8_t *Start,
660
+ SampleProfileMap &Profiles);
624
661
625
662
// / Read the contents of the given profile instance.
626
663
std::error_code readProfile (FunctionSamples &FProfile);
@@ -720,11 +757,15 @@ class SampleProfileReaderExtBinaryBase : public SampleProfileReaderBinary {
720
757
std::error_code readSecHdrTableEntry (uint64_t Idx);
721
758
std::error_code readSecHdrTable ();
722
759
760
+ std::error_code readFuncMetadataOnDemand (bool ProfileHasAttribute,
761
+ SampleProfileMap &Profiles);
723
762
std::error_code readFuncMetadata (bool ProfileHasAttribute);
724
763
std::error_code readFuncMetadata (bool ProfileHasAttribute,
725
764
FunctionSamples *FProfile);
726
765
std::error_code readFuncOffsetTable ();
727
766
std::error_code readFuncProfiles ();
767
+ std::error_code readFuncProfiles (const DenseSet<StringRef> &FuncsToUse,
768
+ SampleProfileMap &Profiles);
728
769
std::error_code readNameTableSec (bool IsMD5, bool FixedLengthMD5);
729
770
std::error_code readCSNameTableSec ();
730
771
std::error_code readProfileSymbolList ();
@@ -776,6 +817,12 @@ class SampleProfileReaderExtBinaryBase : public SampleProfileReaderBinary {
776
817
// / the reader has been given a module.
777
818
bool collectFuncsFromModule () override ;
778
819
820
+ // / Read the profiles on-demand for the given functions. This is used after
821
+ // / stale call graph matching finds new functions whose profiles aren't read
822
+ // / at the beginning and we need to re-read the profiles.
823
+ std::error_code readOnDemand (const DenseSet<StringRef> &FuncsToUse,
824
+ SampleProfileMap &Profiles) override ;
825
+
779
826
std::unique_ptr<ProfileSymbolList> getProfileSymbolList () override {
780
827
return std::move (ProfSymList);
781
828
};
0 commit comments