r206091 - CodeGen: Test instrumentation based profiling of templates

Justin Bogner mail at justinbogner.com
Fri Apr 11 17:54:07 PDT 2014


Author: bogner
Date: Fri Apr 11 19:54:06 2014
New Revision: 206091

URL: http://llvm.org/viewvc/llvm-project?rev=206091&view=rev
Log:
CodeGen: Test instrumentation based profiling of templates

Make sure that templates are handled correctly by profile
instrumentation.

Added:
    cfe/trunk/test/Profile/Inputs/cxx-templates.profdata
    cfe/trunk/test/Profile/cxx-templates.cpp

Added: cfe/trunk/test/Profile/Inputs/cxx-templates.profdata
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/cxx-templates.profdata?rev=206091&view=auto
==============================================================================
--- cfe/trunk/test/Profile/Inputs/cxx-templates.profdata (added)
+++ cfe/trunk/test/Profile/Inputs/cxx-templates.profdata Fri Apr 11 19:54:06 2014
@@ -0,0 +1,17 @@
+main
+1
+1
+1
+
+_Z4loopILj0EEvv
+2
+2
+1
+0
+
+_Z4loopILj100EEvv
+2
+2
+1
+100
+

Added: cfe/trunk/test/Profile/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-templates.cpp?rev=206091&view=auto
==============================================================================
--- cfe/trunk/test/Profile/cxx-templates.cpp (added)
+++ cfe/trunk/test/Profile/cxx-templates.cpp Fri Apr 11 19:54:06 2014
@@ -0,0 +1,41 @@
+// Tests for instrumentation of templated code. Each instantiation of a template
+// should be instrumented separately.
+
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-generate > %tgen
+// RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s
+// RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
+
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%S/Inputs/cxx-templates.profdata > %tuse
+// RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
+// RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
+
+// T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = linkonce_odr global [2 x i64] zeroinitializer
+// T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = linkonce_odr global [2 x i64] zeroinitializer
+
+// T0GEN-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
+// T0USE-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
+// T100GEN-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
+// T100USE-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
+template <unsigned N> void loop() {
+  // ALL-NOT: ret
+  // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 0
+  // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 0
+
+  // ALL-NOT: ret
+  // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 1
+  // T0USE: br {{.*}} !prof ![[T01:[0-9]+]]
+  // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 1
+  // T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]
+  for (unsigned I = 0; I < N; ++I) {}
+
+  // ALL: ret
+}
+
+// T0USE-DAG: ![[T01]] = metadata !{metadata !"branch_weights", i32 1, i32 2}
+// T100USE-DAG: ![[T1001]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
+
+int main(int argc, const char *argv[]) {
+  loop<0>();
+  loop<100>();
+  return 0;
+}





More information about the cfe-commits mailing list