From 4c2b57ae48cd333d7dac3f6e5fc1d5e900bfa902 Mon Sep 17 00:00:00 2001 From: Hongtao Yu Date: Thu, 31 Mar 2022 12:35:40 -0700 Subject: [PATCH] [llvm-profgen] Fixing a context attribure update issue due to a non-derministic processing order on different platforms. A context can be created by invoking the `getFunctionProfileForContext` 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 different order on different platforms, since the lbr ranges are stored in an unordered_map, and we are making sure `ContextWasInlined` is always set correctly. This should fix the random test failure introduced by D121655 Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D122844 --- llvm/tools/llvm-profgen/ProfileGenerator.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp index c497dff..85214f6 100644 --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -712,7 +712,21 @@ FunctionSamples &CSProfileGenerator::getFunctionProfileForContext( FunctionSamples &FProfile = Ret.first->second; FProfile.setContext(FContext); return Ret.first->second; + } else { + // Update ContextWasInlined attribute for existing contexts. + // The current function can be called in two ways: + // - when processing a probe of the current frame + // - when processing the entry probe of an inlinee's frame, which + // is then used to update the callsite count of the current frame. + // The two can happen in any order, hence here we are making sure + // `ContextWasInlined` is always set as expected. + // TODO: Note that the former does not always happen if no probes of the + // current frame has samples, and if the latter happens, we could lose the + // attribute. This should be fixed. + if (WasLeafInlined) + I->second.getContext().setAttribute(ContextWasInlined); } + return I->second; } -- 2.7.4