]> granicus.if.org Git - clang/commitdiff
CodeGen: Handle binary conditional operators in PGO instrumentation
authorJustin Bogner <mail@justinbogner.com>
Fri, 11 Apr 2014 06:10:10 +0000 (06:10 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 11 Apr 2014 06:10:10 +0000 (06:10 +0000)
This treats binary conditional operators in the same way as ternary
conditional operators for instrumentation based profiling.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206021 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenPGO.cpp
test/Profile/Inputs/c-general.profdata
test/Profile/c-general.c

index 8c3340a9d3bd8ae626dc7a633fce4caaecb173e2..ea069cebfe7af8866449abbca56d45ad001ad92d 100644 (file)
@@ -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());
index a1d56104a21c215b8c82fb1a92f81000178a93df..b1d1d061221b79854a7ca203858963157bb53f35 100644 (file)
@@ -129,6 +129,13 @@ boolop_loops
 50
 26
 
+conditional_operator
+3
+3
+1
+0
+1
+
 do_fallthrough
 4
 4
index 2475f26692680fadf304992e5b78943310a4bcab..1359d287afa81be2f1f4a6115ee2ffa567925e83 100644 (file)
@@ -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;