diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -712,7 +712,23 @@ FunctionSamples &FProfile = Ret.first->second; FProfile.setContext(FContext); return Ret.first->second; + } else { + // Update ContextWasInlined attribute for existing contexts. A context can + // be created by invoking this function in two ways: + // - by using a probe and its calling context. + // - by removing the leaf frame from an existing contexts. + // The first way is used when generating a function profile for a given LBR + // range, and the input `WasLeafInlined` is computed depending on the + // actually probe in the LBR range. The second way is used when using the + // entry count of an inlinee function profile to update its inliner callsite + // count, so `WasLeafInlined` is unknown for the inliner frame. The two + // invocations can happen in any order, and here we are making sure + // `ContextWasInlined` is always set correctly. + FunctionSamples &FProfile = I->second; + if (WasLeafInlined) + FProfile.getContext().setAttribute(ContextWasInlined); } + return I->second; }