summaryrefslogtreecommitdiffstats
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
commit7380a0d4a631a442d945367e8cad51020834b859 (patch)
tree6913f9b24868a44d697fbd6d8ebcbd0bfc47b304
parent0f81478c7c3b1ff828130c2408181e3798d70092 (diff)
downloadbcm5719-llvm-7380a0d4a631a442d945367e8cad51020834b859.tar.gz
bcm5719-llvm-7380a0d4a631a442d945367e8cad51020834b859.zip
[Profile] Add new test case to cover comdat renaming
Test checks that context specific profiles for comdat functions are not lost. llvm-svn: 277381
-rw-r--r--compiler-rt/test/profile/Inputs/comdat_rename.h13
-rw-r--r--compiler-rt/test/profile/Inputs/comdat_rename_1.cc33
-rw-r--r--compiler-rt/test/profile/Inputs/comdat_rename_2.cc18
-rw-r--r--compiler-rt/test/profile/Linux/comdat_rename.test6
4 files changed, 70 insertions, 0 deletions
diff --git a/compiler-rt/test/profile/Inputs/comdat_rename.h b/compiler-rt/test/profile/Inputs/comdat_rename.h
new file mode 100644
index 00000000000..53e1007acac
--- /dev/null
+++ b/compiler-rt/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/compiler-rt/test/profile/Inputs/comdat_rename_1.cc b/compiler-rt/test/profile/Inputs/comdat_rename_1.cc
new file mode 100644
index 00000000000..36f2a02fe60
--- /dev/null
+++ b/compiler-rt/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/compiler-rt/test/profile/Inputs/comdat_rename_2.cc b/compiler-rt/test/profile/Inputs/comdat_rename_2.cc
new file mode 100644
index 00000000000..c25f3bae586
--- /dev/null
+++ b/compiler-rt/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/compiler-rt/test/profile/Linux/comdat_rename.test b/compiler-rt/test/profile/Linux/comdat_rename.test
new file mode 100644
index 00000000000..116b5dc65b9
--- /dev/null
+++ b/compiler-rt/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
OpenPOWER on IntegriCloud