Skip to content

Commit 4c2b57a

Browse files
committed
[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
1 parent 4fbde1e commit 4c2b57a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,21 @@ FunctionSamples &CSProfileGenerator::getFunctionProfileForContext(
712712
FunctionSamples &FProfile = Ret.first->second;
713713
FProfile.setContext(FContext);
714714
return Ret.first->second;
715+
} else {
716+
// Update ContextWasInlined attribute for existing contexts.
717+
// The current function can be called in two ways:
718+
// - when processing a probe of the current frame
719+
// - when processing the entry probe of an inlinee's frame, which
720+
// is then used to update the callsite count of the current frame.
721+
// The two can happen in any order, hence here we are making sure
722+
// `ContextWasInlined` is always set as expected.
723+
// TODO: Note that the former does not always happen if no probes of the
724+
// current frame has samples, and if the latter happens, we could lose the
725+
// attribute. This should be fixed.
726+
if (WasLeafInlined)
727+
I->second.getContext().setAttribute(ContextWasInlined);
715728
}
729+
716730
return I->second;
717731
}
718732

0 commit comments

Comments
 (0)