@@ -88,27 +88,28 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M,
8888 return {};
8989 }
9090 PGOCtxProfileReader Reader (MB.get ()->getBuffer ());
91- auto MaybeCtx = Reader.loadContexts ();
92- if (!MaybeCtx ) {
91+ auto MaybeProfiles = Reader.loadProfiles ();
92+ if (!MaybeProfiles ) {
9393 M.getContext ().emitError (" contextual profile file is invalid: " +
94- toString (MaybeCtx .takeError ()));
94+ toString (MaybeProfiles .takeError ()));
9595 return {};
9696 }
9797
9898 DenseSet<GlobalValue::GUID> ProfileRootsInModule;
9999 for (const auto &F : M)
100100 if (!F.isDeclaration ())
101101 if (auto GUID = AssignGUIDPass::getGUID (F);
102- MaybeCtx-> find (GUID) != MaybeCtx-> end ())
102+ MaybeProfiles-> Contexts . find (GUID) != MaybeProfiles-> Contexts . end ())
103103 ProfileRootsInModule.insert (GUID);
104104
105105 // Trim first the roots that aren't in this module.
106- for (auto &[RootGuid, _] : llvm::make_early_inc_range (*MaybeCtx))
106+ for (auto &[RootGuid, _] :
107+ llvm::make_early_inc_range (MaybeProfiles->Contexts ))
107108 if (!ProfileRootsInModule.contains (RootGuid))
108- MaybeCtx-> erase (RootGuid);
109+ MaybeProfiles-> Contexts . erase (RootGuid);
109110 // If none of the roots are in the module, we have no profile (for this
110111 // module)
111- if (MaybeCtx-> empty ())
112+ if (MaybeProfiles-> Contexts . empty ())
112113 return {};
113114
114115 // OK, so we have a valid profile and it's applicable to roots in this module.
@@ -146,7 +147,7 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M,
146147 }
147148 // If we made it this far, the Result is valid - which we mark by setting
148149 // .Profiles.
149- Result.Profiles = std::move (*MaybeCtx );
150+ Result.Profiles = std::move (*MaybeProfiles );
150151 Result.initIndex ();
151152 return Result;
152153}
@@ -164,7 +165,7 @@ CtxProfAnalysisPrinterPass::CtxProfAnalysisPrinterPass(raw_ostream &OS)
164165PreservedAnalyses CtxProfAnalysisPrinterPass::run (Module &M,
165166 ModuleAnalysisManager &MAM) {
166167 CtxProfAnalysis::Result &C = MAM.getResult <CtxProfAnalysis>(M);
167- if (!C ) {
168+ if (C. contexts (). empty () ) {
168169 OS << " No contextual profile was provided.\n " ;
169170 return PreservedAnalyses::all ();
170171 }
@@ -179,7 +180,7 @@ PreservedAnalyses CtxProfAnalysisPrinterPass::run(Module &M,
179180
180181 if (Mode == PrintMode::Everything)
181182 OS << " \n Current Profile:\n " ;
182- convertCtxProfToYaml (OS, C.profiles ());
183+ convertCtxProfToYaml (OS, C.contexts ());
183184 OS << " \n " ;
184185 if (Mode == PrintMode::YAML)
185186 return PreservedAnalyses::all ();
@@ -245,7 +246,7 @@ void PGOContextualProfile::initIndex() {
245246 for (auto &[Guid, FI] : FuncInfo)
246247 InsertionPoints[Guid] = &FI.Index ;
247248 preorderVisit<PGOCtxProfContext::CallTargetMapTy, PGOCtxProfContext>(
248- * Profiles, [&](PGOCtxProfContext &Ctx) {
249+ Profiles. Contexts , [&](PGOCtxProfContext &Ctx) {
249250 auto InsertIt = InsertionPoints.find (Ctx.guid ());
250251 if (InsertIt == InsertionPoints.end ())
251252 return ;
@@ -270,7 +271,7 @@ void PGOContextualProfile::update(Visitor V, const Function &F) {
270271void PGOContextualProfile::visit (ConstVisitor V, const Function *F) const {
271272 if (!F)
272273 return preorderVisit<const PGOCtxProfContext::CallTargetMapTy,
273- const PGOCtxProfContext>(* Profiles, V);
274+ const PGOCtxProfContext>(Profiles. Contexts , V);
274275 assert (isFunctionKnown (*F));
275276 GlobalValue::GUID G = getDefinedFunctionGUID (*F);
276277 for (const auto *Node = FuncInfo.find (G)->second .Index .Next ; Node;
@@ -279,11 +280,10 @@ void PGOContextualProfile::visit(ConstVisitor V, const Function *F) const {
279280}
280281
281282const CtxProfFlatProfile PGOContextualProfile::flatten () const {
282- assert (Profiles.has_value ());
283283 CtxProfFlatProfile Flat;
284284 preorderVisit<const PGOCtxProfContext::CallTargetMapTy,
285285 const PGOCtxProfContext>(
286- * Profiles, [&](const PGOCtxProfContext &Ctx) {
286+ Profiles. Contexts , [&](const PGOCtxProfContext &Ctx) {
287287 auto [It, Ins] = Flat.insert ({Ctx.guid (), {}});
288288 if (Ins) {
289289 llvm::append_range (It->second , Ctx.counters ());
0 commit comments