[compiler-rt] r277381 - [Profile] Add new test case to cover comdat renaming

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 1 17:08:17 PDT 2016


On Mon, Aug 1, 2016 at 1:28 PM, Xinliang David Li via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: davidxl
> Date: Mon Aug  1 15:28:26 2016
> New Revision: 277381
>
> URL: http://llvm.org/viewvc/llvm-project?rev=277381&view=rev
> Log:
> [Profile] Add new test case to cover comdat renaming
>
> Test checks that context specific profiles for comdat functions
> are not lost.
>

Nice! This is a neat benefit of the privatization approach
(context-sensitivity for comdat).


>
>
> Added:
>     compiler-rt/trunk/test/profile/Inputs/comdat_rename.h
>     compiler-rt/trunk/test/profile/Inputs/comdat_rename_1.cc
>     compiler-rt/trunk/test/profile/Inputs/comdat_rename_2.cc
>     compiler-rt/trunk/test/profile/Linux/comdat_rename.test
>
> Added: compiler-rt/trunk/test/profile/Inputs/comdat_rename.h
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/comdat_rename.h?rev=277381&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/profile/Inputs/comdat_rename.h (added)
> +++ compiler-rt/trunk/test/profile/Inputs/comdat_rename.h Mon Aug  1
> 15:28:26 2016
> @@ -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;
> +};
>
> Added: compiler-rt/trunk/test/profile/Inputs/comdat_rename_1.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/comdat_rename_1.cc?rev=277381&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/profile/Inputs/comdat_rename_1.cc (added)
> +++ compiler-rt/trunk/test/profile/Inputs/comdat_rename_1.cc Mon Aug  1
> 15:28:26 2016
> @@ -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); }
>
> Added: compiler-rt/trunk/test/profile/Inputs/comdat_rename_2.cc
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/comdat_rename_2.cc?rev=277381&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/profile/Inputs/comdat_rename_2.cc (added)
> +++ compiler-rt/trunk/test/profile/Inputs/comdat_rename_2.cc Mon Aug  1
> 15:28:26 2016
> @@ -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}
>
> Added: compiler-rt/trunk/test/profile/Linux/comdat_rename.test
> URL:
> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/comdat_rename.test?rev=277381&view=auto
>
> ==============================================================================
> --- compiler-rt/trunk/test/profile/Linux/comdat_rename.test (added)
> +++ compiler-rt/trunk/test/profile/Linux/comdat_rename.test Mon Aug  1
> 15:28:26 2016
> @@ -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
>

It may make sense to make an Inputs/ dir in the Linux dir so you can just
do `%S/Inputs/...`.

-- Sean Silva


>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160801/6d0a6871/attachment.html>


More information about the llvm-commits mailing list