[PATCH] D122844: [llvm-profgen] Fixing a context attribure update issue due to a non-derministic processing order on different platforms.

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 12:36:21 PDT 2022


hoy created this revision.
Herald added subscribers: modimo, wenlei.
Herald added a project: All.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122844

Files:
  llvm/tools/llvm-profgen/ProfileGenerator.cpp


Index: llvm/tools/llvm-profgen/ProfileGenerator.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -712,7 +712,24 @@
     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().hasAttribute(ContextWasInlined))
+      FProfile.getContext().setAllAttributes(ContextWasInlined);
   }
+
   return I->second;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122844.419542.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220331/15554e53/attachment.bin>


More information about the llvm-commits mailing list