@@ -1176,15 +1176,20 @@ class PGOUseFunc {
11761176
11771177 void handleInstrProfError (Error Err, uint64_t MismatchedFuncSum);
11781178
1179+ // / Get the profile record, assign it to \p ProfileRecord, handle errors if
1180+ // / necessary, and assign \p ProgramMaxCount. \returns true if there are no
1181+ // / errors.
1182+ bool getRecord (IndexedInstrProfReader *PGOReader);
1183+
11791184 // Read counts for the instrumented BB from profile.
1180- bool readCounters (IndexedInstrProfReader *PGOReader, bool &AllZeros,
1185+ bool readCounters (bool &AllZeros,
11811186 InstrProfRecord::CountPseudoKind &PseudoKind);
11821187
11831188 // Populate the counts for all BBs.
11841189 void populateCounters ();
11851190
11861191 // Set block coverage based on profile coverage values.
1187- void populateCoverage (IndexedInstrProfReader *PGOReader );
1192+ void populateCoverage ();
11881193
11891194 // Set the branch weights based on the count values.
11901195 void setBranchWeights ();
@@ -1208,7 +1213,7 @@ class PGOUseFunc {
12081213 uint64_t getFuncHash () const { return FuncInfo.FunctionHash ; }
12091214
12101215 // Return the profile record for this function;
1211- InstrProfRecord &getProfileRecord () { return ProfileRecord; }
1216+ NamedInstrProfRecord &getProfileRecord () { return ProfileRecord; }
12121217
12131218 // Return the auxiliary BB information.
12141219 PGOUseBBInfo &getBBInfo (const BasicBlock *BB) const {
@@ -1246,7 +1251,7 @@ class PGOUseFunc {
12461251 uint32_t ProfileCountSize = 0 ;
12471252
12481253 // ProfileRecord for this function.
1249- InstrProfRecord ProfileRecord;
1254+ NamedInstrProfRecord ProfileRecord;
12501255
12511256 // Function hotness info derived from profile.
12521257 FuncFreqAttr FreqAttr;
@@ -1441,21 +1446,26 @@ void PGOUseFunc::handleInstrProfError(Error Err, uint64_t MismatchedFuncSum) {
14411446 });
14421447}
14431448
1444- // Read the profile from ProfileFileName and assign the value to the
1445- // instrumented BB and the edges. This function also updates ProgramMaxCount.
1446- // Return true if the profile are successfully read, and false on errors.
1447- bool PGOUseFunc::readCounters (IndexedInstrProfReader *PGOReader, bool &AllZeros,
1448- InstrProfRecord::CountPseudoKind &PseudoKind) {
1449- auto &Ctx = M->getContext ();
1449+ bool PGOUseFunc::getRecord (IndexedInstrProfReader *PGOReader) {
14501450 uint64_t MismatchedFuncSum = 0 ;
1451- Expected<InstrProfRecord> Result = PGOReader->getInstrProfRecord (
1451+ auto Result = PGOReader->getInstrProfRecord (
14521452 FuncInfo.FuncName , FuncInfo.FunctionHash , FuncInfo.DeprecatedFuncName ,
14531453 &MismatchedFuncSum);
14541454 if (Error E = Result.takeError ()) {
14551455 handleInstrProfError (std::move (E), MismatchedFuncSum);
14561456 return false ;
14571457 }
14581458 ProfileRecord = std::move (Result.get ());
1459+ ProgramMaxCount = PGOReader->getMaximumFunctionCount (IsCS);
1460+ return true ;
1461+ }
1462+
1463+ // Read the profile from ProfileFileName and assign the value to the
1464+ // instrumented BB and the edges. Return true if the profile are successfully
1465+ // read, and false on errors.
1466+ bool PGOUseFunc::readCounters (bool &AllZeros,
1467+ InstrProfRecord::CountPseudoKind &PseudoKind) {
1468+ auto &Ctx = M->getContext ();
14591469 PseudoKind = ProfileRecord.getCountPseudoKind ();
14601470 if (PseudoKind != InstrProfRecord::NotPseudo) {
14611471 return true ;
@@ -1488,22 +1498,13 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros,
14881498 DS_Warning));
14891499 return false ;
14901500 }
1491- ProgramMaxCount = PGOReader->getMaximumFunctionCount (IsCS);
14921501 return true ;
14931502}
14941503
1495- void PGOUseFunc::populateCoverage (IndexedInstrProfReader *PGOReader) {
1496- uint64_t MismatchedFuncSum = 0 ;
1497- Expected<InstrProfRecord> Result = PGOReader->getInstrProfRecord (
1498- FuncInfo.FuncName , FuncInfo.FunctionHash , FuncInfo.DeprecatedFuncName ,
1499- &MismatchedFuncSum);
1500- if (auto Err = Result.takeError ()) {
1501- handleInstrProfError (std::move (Err), MismatchedFuncSum);
1502- return ;
1503- }
1504+ void PGOUseFunc::populateCoverage () {
15041505 IsCS ? NumOfCSPGOFunc++ : NumOfPGOFunc++;
15051506
1506- std::vector <uint64_t > & CountsFromProfile = Result. get () .Counts ;
1507+ ArrayRef <uint64_t > CountsFromProfile = ProfileRecord .Counts ;
15071508 DenseMap<const BasicBlock *, bool > Coverage;
15081509 unsigned Index = 0 ;
15091510 for (auto &BB : F)
@@ -2243,8 +2244,10 @@ static bool annotateAllFunctions(
22432244 PGOUseFunc Func (F, &M, TLI, ComdatMembers, BPI, BFI, LI, PSI, IsCS,
22442245 InstrumentFuncEntry, InstrumentLoopEntries,
22452246 HasSingleByteCoverage);
2247+ if (!Func.getRecord (PGOReader.get ()))
2248+ continue ;
22462249 if (HasSingleByteCoverage) {
2247- Func.populateCoverage (PGOReader. get () );
2250+ Func.populateCoverage ();
22482251 continue ;
22492252 }
22502253 // When PseudoKind is set to a vaule other than InstrProfRecord::NotPseudo,
@@ -2253,7 +2256,7 @@ static bool annotateAllFunctions(
22532256 // attribute and drop all the profile counters.
22542257 InstrProfRecord::CountPseudoKind PseudoKind = InstrProfRecord::NotPseudo;
22552258 bool AllZeros = false ;
2256- if (!Func.readCounters (PGOReader. get (), AllZeros, PseudoKind))
2259+ if (!Func.readCounters (AllZeros, PseudoKind))
22572260 continue ;
22582261 if (AllZeros) {
22592262 F.setEntryCount (ProfileCount (0 , Function::PCT_Real));
0 commit comments