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

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 17:34:14 PDT 2022


Author: Hongtao Yu
Date: 2022-03-31T17:33:58-07:00
New Revision: 4c2b57ae48cd333d7dac3f6e5fc1d5e900bfa902

URL: https://github.com/llvm/llvm-project/commit/4c2b57ae48cd333d7dac3f6e5fc1d5e900bfa902
DIFF: https://github.com/llvm/llvm-project/commit/4c2b57ae48cd333d7dac3f6e5fc1d5e900bfa902.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index c497dff752d17..85214f6987314 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;
 }
 


        


More information about the llvm-commits mailing list