[CSSPGO][llvm-profgen] Handle return to external transition.
authorHongtao Yu <hoy@fb.com>
Fri, 18 Jun 2021 16:30:38 +0000 (09:30 -0700)
committerHongtao Yu <hoy@fb.com>
Tue, 22 Jun 2021 23:24:59 +0000 (16:24 -0700)
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

llvm/tools/llvm-profgen/PerfReader.cpp

index aaa4a06..a9805cf 100644 (file)
@@ -460,6 +460,16 @@ bool PerfReader::extractLBRStack(TraceStream &TraceIt,
         // they are likely in different 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;