[llvm] 5c86598 - [CSSPGO][llvm-profgen] Handle return to external transition.

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 16:25:11 PDT 2021


Author: Hongtao Yu
Date: 2021-06-22T16:24:59-07:00
New Revision: 5c8659801a4976ef2b327f4071d98086efd42a36

URL: https://github.com/llvm/llvm-project/commit/5c8659801a4976ef2b327f4071d98086efd42a36
DIFF: https://github.com/llvm/llvm-project/commit/5c8659801a4976ef2b327f4071d98086efd42a36.diff

LOG: [CSSPGO][llvm-profgen] Handle return to external transition.

In a callback case, a return from internal code, say A, to external runtime can happen. The external runtime can then call back to another internal routine, say B. Making an artificial branch that looks like a return from A to B can confuse the unwinder to treat the instruction before B as the call instruction.

Reviewed By: wenlei, wmi

Differential Revision: https://reviews.llvm.org/D104546

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index aaa4a06a2283c..a9805cfa35503 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -460,6 +460,16 @@ bool PerfReader::extractLBRStack(TraceStream &TraceIt,
         // they are likely in 
diff erent contexts.
         break;
       }
+
+      if (Binary->addressIsReturn(Src)) {
+        // In a callback case, a return from internal code, say A, to external
+        // runtime can happen. The external runtime can then call back to
+        // another internal routine, say B. Making an artificial branch that
+        // looks like a return from A to B can confuse the unwinder to treat
+        // the instruction before B as the call instruction.
+        break;
+      }
+
       // For transition to external code, group the Source with the next
       // availabe transition target.
       Dst = PrevTrDst;


        


More information about the llvm-commits mailing list