diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -488,9 +488,6 @@ /// Profile tracker for different context. std::unique_ptr ContextTracker; - /// Flag indicating whether input profile is context-sensitive - bool ProfileIsCS = false; - /// Flag indicating which LTO/ThinLTO phase the pass is invoked in. /// /// We need to know the LTO phase because for example in ThinLTOPrelink @@ -606,7 +603,7 @@ // call instruction should have 0 count. // For CS profile, the callsite count of previously inlined callees is // populated with the entry count of the callees. - if (!ProfileIsCS) + if (!FunctionSamples::ProfileIsCS) if (const auto *CB = dyn_cast(&Inst)) if (!CB->isIndirectCall() && findCalleeFunctionSamples(*CB)) return 0; @@ -645,7 +642,7 @@ // call instruction should have 0 count. // For CS profile, the callsite count of previously inlined callees is // populated with the entry count of the callees. - if (!ProfileIsCS) + if (!FunctionSamples::ProfileIsCS) if (const auto *CB = dyn_cast(&Inst)) if (!CB->isIndirectCall() && findCalleeFunctionSamples(*CB)) return 0; @@ -699,7 +696,7 @@ if (Function *Callee = Inst.getCalledFunction()) CalleeName = Callee->getName(); - if (ProfileIsCS) + if (FunctionSamples::ProfileIsCS) return ContextTracker->getCalleeContextSamplesFor(Inst, CalleeName); const FunctionSamples *FS = findFunctionSamples(Inst); @@ -731,7 +728,7 @@ FunctionSamples::getGUID(R->getName()); }; - if (ProfileIsCS) { + if (FunctionSamples::ProfileIsCS) { auto CalleeSamples = ContextTracker->getIndirectCalleeContextSamplesFor(DIL); if (CalleeSamples.empty()) @@ -784,7 +781,7 @@ auto it = DILocation2SampleMap.try_emplace(DIL,nullptr); if (it.second) { - if (ProfileIsCS) + if (FunctionSamples::ProfileIsCS) it.first->second = ContextTracker->getContextSamplesFor(DIL); else it.first->second = @@ -1058,7 +1055,7 @@ // For AutoFDO profile, retrieve candidate profiles by walking over // the nested inlinee profiles. - if (!ProfileIsCS) { + if (!FunctionSamples::ProfileIsCS) { Samples->findInlinedFunctions(InlinedGUIDs, SymbolMap, Threshold); return; } @@ -1162,7 +1159,7 @@ assert((!FunctionSamples::UseMD5 || FS->GUIDToFuncNameMap) && "GUIDToFuncNameMap has to be populated"); AllCandidates.push_back(CB); - if (FS->getEntrySamples() > 0 || ProfileIsCS) + if (FS->getEntrySamples() > 0 || FunctionSamples::ProfileIsCS) LocalNotInlinedCallSites.try_emplace(CB, FS); if (callsiteIsHot(FS, PSI, ProfAccForSymsInList)) Hot = true; @@ -1273,7 +1270,7 @@ InlinedCallSites->push_back(I); } - if (ProfileIsCS) + if (FunctionSamples::ProfileIsCS) ContextTracker->markContextSamplesInlined(Candidate.CalleeSamples); ++NumCSInlined; @@ -1829,7 +1826,7 @@ std::unique_ptr SampleProfileLoader::buildProfiledCallGraph(CallGraph &CG) { std::unique_ptr ProfiledCG; - if (ProfileIsCS) + if (FunctionSamples::ProfileIsCS) ProfiledCG = std::make_unique(*ContextTracker); else ProfiledCG = std::make_unique(Reader->getProfiles()); @@ -1874,8 +1871,8 @@ assert(&CG->getModule() == &M); - if (UseProfiledCallGraph || - (ProfileIsCS && !UseProfiledCallGraph.getNumOccurrences())) { + if (UseProfiledCallGraph || (FunctionSamples::ProfileIsCS && + !UseProfiledCallGraph.getNumOccurrences())) { // Use profiled call edges to augment the top-down order. There are cases // that the top-down order computed based on the static call graph doesn't // reflect real execution order. For example @@ -2039,8 +2036,7 @@ } } - if (FunctionSamples::ProfileIsCS) { - ProfileIsCS = true; + if (Reader->profileIsCS()) { // Tracker for profiles under different context ContextTracker = std::make_unique( Reader->getProfiles(), &GUIDToFuncNameMap); @@ -2121,7 +2117,7 @@ } // Account for cold calls not inlined.... - if (!ProfileIsCS) + if (!FunctionSamples::ProfileIsCS) for (const std::pair &pair : notInlinedCallInfo) updateProfileCallee(pair.first, pair.second.entryCount); @@ -2197,7 +2193,7 @@ ORE = OwnedORE.get(); } - if (ProfileIsCS) + if (FunctionSamples::ProfileIsCS) Samples = ContextTracker->getBaseSamplesFor(F); else Samples = Reader->getSamplesFor(F);