[llvm] 30ca33e - [llvm-profgen] Ignore the whole trace with the leading external branch

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 13 17:04:18 PDT 2021


Author: wlei
Date: 2021-10-13T16:52:29-07:00
New Revision: 30ca33eab00b8c815ef95fbb3a14e61dc3278b5b

URL: https://github.com/llvm/llvm-project/commit/30ca33eab00b8c815ef95fbb3a14e61dc3278b5b
DIFF: https://github.com/llvm/llvm-project/commit/30ca33eab00b8c815ef95fbb3a14e61dc3278b5b.diff

LOG: [llvm-profgen] Ignore the whole trace with the leading external branch

The first LBR entry can be an external branch, we should ignore the whole trace.

```
     7f7448e889e4 0x7f7448e889e4/0x7f7448e88826/P/-/-/1  0x7f7448e8899f/0x7f7448e889d8/P/-/-/4  ...
```

Reviewed By: wenlei, hoy

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

Added: 
    llvm/test/tools/llvm-profgen/Inputs/artificial-branch.perfscript

Modified: 
    llvm/test/tools/llvm-profgen/inline-noprobe2.test
    llvm/tools/llvm-profgen/PerfReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-profgen/Inputs/artificial-branch.perfscript b/llvm/test/tools/llvm-profgen/Inputs/artificial-branch.perfscript
new file mode 100644
index 0000000000000..c468989b716d1
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/Inputs/artificial-branch.perfscript
@@ -0,0 +1 @@
+           400870 0x400870/0x400540/P/-/-/1  0x4008bf/0x400870/P/-/-/7  0x7f7448e88cc1/0x400875/P/-/-/1  0x7f7448e88875/0x7f7448e88cbd/P/-/-/2  0x7f7448e88840/0x7f7448e8885c/P/-/-/1  0x7f7448e8882d/0x7f7448e8883a/P/-/-/1  0x7f7448e889e4/0x7f7448e88826/P/-/-/1  0x7f7448e8899f/0x7f7448e889d8/P/-/-/4  0x7f7448e88821/0x7f7448e88960/P/-/-/1  0x7f7448e887f9/0x7f7448e88815/P/-/-/2  0x7f7448e887e4/0x7f7448e887f2/P/-/-/2  0x7f7448e88cb8/0x7f7448e887c0/P/-/-/1  0x400540/0x7f7448e88cb0/P/-/-/1  0x400870/0x400540/P/-/-/1  0x4008bf/0x400870/P/-/-/5

diff  --git a/llvm/test/tools/llvm-profgen/inline-noprobe2.test b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
index d27eaaccdcbca..6a523ddef3085 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe2.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
@@ -1,16 +1,31 @@
-
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/artificial-branch.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t  --skip-symbolization --use-offset=0
+; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-ARTIFICIAL-BRANCH
+; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t  --skip-symbolization --use-offset=0
+; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-RAW-PROFILE
 ; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
 ; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
 
 ; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
 ; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
 
+; CHECK-ARTIFICIAL-BRANCH: 3
+; CHECK-ARTIFICIAL-BRANCH: 400540-400540:1
+; CHECK-ARTIFICIAL-BRANCH: 400870-400870:2
+; CHECK-ARTIFICIAL-BRANCH: 400875-4008bf:1
+; CHECK-ARTIFICIAL-BRANCH: 2
+; CHECK-ARTIFICIAL-BRANCH: 400870->400540:2
+; CHECK-ARTIFICIAL-BRANCH: 4008bf->400870:2
+
 ; CHECK-SYM-LIST: Dump profile symbol list
 ; CHECK-SYM-LIST: main
 ; CHECK-SYM-LIST: partition_pivot_first
 ; CHECK-SYM-LIST: partition_pivot_last
 ; CHECK-SYM-LIST: quick_sort
 
+
+;CHECK-RAW-PROFILE-NOT: 7f7448e889e4
+;CHECK-RAW-PROFILE-NOT: 7f7448e88826
+
 ;CHECK:       partition_pivot_first:1045:5
 ;CHECK-NEXT:  0: 5
 ;CHECK-NEXT:  1: 5

diff  --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 4478cac82c662..8fd2bfd8ecd70 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -492,13 +492,13 @@ bool PerfReaderBase::extractLBRStack(TraceStream &TraceIt,
     if (IsExternal) {
       if (PrevTrDst)
         continue;
-      else if (!LBRStack.empty()) {
+      if (!LBRStack.empty()) {
         WithColor::warning()
             << "Invalid transfer to external code in LBR record at line "
             << TraceIt.getLineNumber() << ": " << TraceIt.getCurrentLine()
             << "\n";
-        break;
       }
+      break;
     }
 
     if (IsOutgoing) {


        


More information about the llvm-commits mailing list