summaryrefslogtreecommitdiff
path: root/test/profile
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-08-01 20:28:26 +0000
committerXinliang David Li <davidxl@google.com>2016-08-01 20:28:26 +0000
commit8f0c63a6e776705f1df5127d90f164cfb232c694 (patch)
tree3198cf5f2eaf7a398a24616110dcc91819631b14 /test/profile
parent4783923fa8ac34403ce9433fbb09238df2c2f7f6 (diff)
[Profile] Add new test case to cover comdat renaming
Test checks that context specific profiles for comdat functions are not lost. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277381 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile')
-rw-r--r--test/profile/Inputs/comdat_rename.h13
-rw-r--r--test/profile/Inputs/comdat_rename_1.cc33
-rw-r--r--test/profile/Inputs/comdat_rename_2.cc18
-rw-r--r--test/profile/Linux/comdat_rename.test6
4 files changed, 70 insertions, 0 deletions
diff --git a/test/profile/Inputs/comdat_rename.h b/test/profile/Inputs/comdat_rename.h
new file mode 100644
index 000000000..53e1007ac
--- /dev/null
+++ b/test/profile/Inputs/comdat_rename.h
@@ -0,0 +1,13 @@
+struct FOO {
+ FOO() : a(0), b(0) {}
+ int callee();
+ __attribute__((noinline)) void caller(int n) {
+ int r = callee();
+ if (r == 0) {
+ a += n;
+ b += 1;
+ }
+ }
+ int a;
+ int b;
+};
diff --git a/test/profile/Inputs/comdat_rename_1.cc b/test/profile/Inputs/comdat_rename_1.cc
new file mode 100644
index 000000000..36f2a02fe
--- /dev/null
+++ b/test/profile/Inputs/comdat_rename_1.cc
@@ -0,0 +1,33 @@
+#include "comdat_rename.h"
+// callee's out-of-line instance profile data -- it comes
+// from external calls to it from comdat_rename_2.cc.
+// Its inline instance copy's profile data is different and
+// is collected in 'caller''s context.
+int FOO::callee() {
+ // CHECK-LABEL: define {{.*}}callee{{.*}}
+ // CHECK-NOT: br i1 {{.*}}
+ // CHECK: br {{.*}}label{{.*}}, label %[[BB1:[0-9]+]], !prof ![[PD1:[0-9]+]]
+ // CHECK: ; <label>:[[BB1]]:
+ if (b != 0)
+ return a / b;
+ if (a != 0)
+ return 10 / a;
+ return 0;
+}
+
+// This is the 'caller''s comdat copy (after renaming) in this module.
+// The profile counters include a copy of counters from 'callee':
+//
+// CHECK-LABEL: define {{.*}}caller{{.*}}
+// CHECK-NOT: br i1 {{.*}}
+// CHECK: br {{.*}}label{{.*}}, label %[[BB2:[0-9]+]], !prof ![[PD2:[0-9]+]]
+// CHECK: ; <label>:[[BB2]]:
+// CHECK: br {{.*}}label{{.*}}, label %{{.*}}, !prof !{{.*}}
+// CHECK: br {{.*}}label %[[BB3:[0-9]+]], label %{{.*}} !prof ![[PD3:[0-9]+]]
+// CHECK: ; <label>:[[BB3]]:
+//
+// CHECK:![[PD1]] = !{!"branch_weights", i32 0, i32 1}
+// CHECK:![[PD2]] = !{!"branch_weights", i32 1, i32 0}
+// CHECK:![[PD3]] = !{!"branch_weights", i32 {{.*}}, i32 0}
+
+void test(FOO *foo) { foo->caller(10); }
diff --git a/test/profile/Inputs/comdat_rename_2.cc b/test/profile/Inputs/comdat_rename_2.cc
new file mode 100644
index 000000000..c25f3bae5
--- /dev/null
+++ b/test/profile/Inputs/comdat_rename_2.cc
@@ -0,0 +1,18 @@
+#include "comdat_rename.h"
+extern void test(FOO *);
+FOO foo;
+int main() {
+ test(&foo);
+ foo.caller(20);
+ return 0;
+}
+
+// The copy of 'caller' defined in this module -- it has
+// 'callee' call remaining.
+//
+// CHECK-LABEL: define {{.*}}caller{{.*}}
+// CHECK: {{.*}} call {{.*}}
+// CHECK-NOT: br i1 {{.*}}
+// CHECK: br {{.*}}label %[[BB1:[0-9]+]], label{{.*}}!prof ![[PD1:[0-9]+]]
+// CHECK: ; <label>:[[BB1]]:
+// CHECK:![[PD1]] = !{!"branch_weights", i32 0, i32 1}
diff --git a/test/profile/Linux/comdat_rename.test b/test/profile/Linux/comdat_rename.test
new file mode 100644
index 000000000..116b5dc65
--- /dev/null
+++ b/test/profile/Linux/comdat_rename.test
@@ -0,0 +1,6 @@
+// RUN: rm -fr %t.prof
+// RUN: %clangxx_pgogen=%t.prof/ -o %t.gen -O2 %S/../Inputs/comdat_rename_1.cc %S/../Inputs/comdat_rename_2.cc
+// RUN: %t.gen
+// RUN: llvm-profdata merge -o %t.profdata %t.prof/
+// RUN: %clangxx_profuse=%t.profdata -O2 -emit-llvm -S %S/../Inputs/comdat_rename_1.cc -o - | FileCheck %S/../Inputs/comdat_rename_1.cc
+// RUN: %clangxx_profuse=%t.profdata -O2 -emit-llvm -S %S/../Inputs/comdat_rename_2.cc -o - | FileCheck %S/../Inputs/comdat_rename_2.cc