r206021 - CodeGen: Handle binary conditional operators in PGO instrumentation

Justin Bogner mail at justinbogner.com
Thu Apr 10 23:10:10 PDT 2014


Author: bogner
Date: Fri Apr 11 01:10:10 2014
New Revision: 206021

URL: http://llvm.org/viewvc/llvm-project?rev=206021&view=rev
Log:
CodeGen: Handle binary conditional operators in PGO instrumentation

This treats binary conditional operators in the same way as ternary
conditional operators for instrumentation based profiling.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
    cfe/trunk/test/Profile/Inputs/c-general.profdata
    cfe/trunk/test/Profile/c-general.c

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=206021&r1=206020&r2=206021&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Apr 11 01:10:10 2014
@@ -442,7 +442,8 @@ namespace {
     }
     /// Assign a counter for the "true" part of a conditional operator. The
     /// count in the "false" part will be calculated from this counter.
-    void VisitConditionalOperator(const ConditionalOperator *E) {
+    void VisitAbstractConditionalOperator(
+        const AbstractConditionalOperator *E) {
       CounterMap[E] = NextCounter++;
       Visit(E->getCond());
       Visit(E->getTrueExpr());
@@ -768,7 +769,8 @@ namespace {
       Visit(S->getHandlerBlock());
     }
 
-    void VisitConditionalOperator(const ConditionalOperator *E) {
+    void VisitAbstractConditionalOperator(
+        const AbstractConditionalOperator *E) {
       RecordStmtCount(E);
       RegionCounter Cnt(PGO, E);
       Visit(E->getCond());

Modified: cfe/trunk/test/Profile/Inputs/c-general.profdata
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/c-general.profdata?rev=206021&r1=206020&r2=206021&view=diff
==============================================================================
--- cfe/trunk/test/Profile/Inputs/c-general.profdata (original)
+++ cfe/trunk/test/Profile/Inputs/c-general.profdata Fri Apr 11 01:10:10 2014
@@ -129,6 +129,13 @@ boolop_loops
 50
 26
 
+conditional_operator
+3
+3
+1
+0
+1
+
 do_fallthrough
 4
 4

Modified: cfe/trunk/test/Profile/c-general.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-general.c?rev=206021&r1=206020&r2=206021&view=diff
==============================================================================
--- cfe/trunk/test/Profile/c-general.c (original)
+++ cfe/trunk/test/Profile/c-general.c Fri Apr 11 01:10:10 2014
@@ -11,6 +11,7 @@
 // PGOGEN: @[[BSC:__llvm_profile_counters_big_switch]] = global [17 x i64] zeroinitializer
 // PGOGEN: @[[BOC:__llvm_profile_counters_boolean_operators]] = global [8 x i64] zeroinitializer
 // PGOGEN: @[[BLC:__llvm_profile_counters_boolop_loops]] = global [9 x i64] zeroinitializer
+// PGOGEN: @[[COC:__llvm_profile_counters_conditional_operator]] = global [3 x i64] zeroinitializer
 // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = global [1 x i64] zeroinitializer
 // PGOGEN: @[[STC:__llvm_profile_counters_static_func]] = internal global [2 x i64] zeroinitializer
 
@@ -412,6 +413,24 @@ void boolop_loops() {
   // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
 }
 
+// PGOGEN-LABEL: @conditional_operator()
+// PGOUSE-LABEL: @conditional_operator()
+// PGOGEN: store {{.*}} @[[COC]], i64 0, i64 0
+void conditional_operator() {
+  int i = 100;
+
+  // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 1
+  // PGOUSE: br {{.*}} !prof ![[CO1:[0-9]+]]
+  int j = i < 50 ? i : 1;
+
+  // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 2
+  // PGOUSE: br {{.*}} !prof ![[CO2:[0-9]+]]
+  int k = i ?: 0;
+
+  // PGOGEN-NOT: store {{.*}} @[[COC]],
+  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
+}
+
 void do_fallthrough() {
   for (int i = 0; i < 10; ++i) {
     int j = 0;
@@ -503,6 +522,8 @@ static void static_func() {
 // PGOUSE-DAG: ![[BL6]] = metadata !{metadata !"branch_weights", i32 51, i32 2}
 // PGOUSE-DAG: ![[BL7]] = metadata !{metadata !"branch_weights", i32 26, i32 27}
 // PGOUSE-DAG: ![[BL8]] = metadata !{metadata !"branch_weights", i32 51, i32 2}
+// PGOUSE-DAG: ![[CO1]] = metadata !{metadata !"branch_weights", i32 1, i32 2}
+// PGOUSE-DAG: ![[CO2]] = metadata !{metadata !"branch_weights", i32 2, i32 1}
 // PGOUSE-DAG: ![[ST1]] = metadata !{metadata !"branch_weights", i32 11, i32 2}
 
 int main(int argc, const char *argv[]) {
@@ -514,6 +535,7 @@ int main(int argc, const char *argv[]) {
   big_switch();
   boolean_operators();
   boolop_loops();
+  conditional_operator();
   do_fallthrough();
   static_func();
   return 0;





More information about the cfe-commits mailing list