aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-04-11 06:10:10 +0000
committerJustin Bogner <mail@justinbogner.com>2014-04-11 06:10:10 +0000
commit6699b197f657547e9f3fd1ad699df68d8a19dc52 (patch)
treec76cdad261d1adaced35130412e47cb58d94ed00
parent94d470b741ae6296ac42dd6809ff866c30239a93 (diff)
downloadclang_35a-6699b197f657547e9f3fd1ad699df68d8a19dc52.tar.gz
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206021 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CodeGenPGO.cpp6
-rw-r--r--test/Profile/Inputs/c-general.profdata7
-rw-r--r--test/Profile/c-general.c22
3 files changed, 33 insertions, 2 deletions
diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp
index 8c3340a9d3..ea069cebfe 100644
--- a/lib/CodeGen/CodeGenPGO.cpp
+++ b/lib/CodeGen/CodeGenPGO.cpp
@@ -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());
diff --git a/test/Profile/Inputs/c-general.profdata b/test/Profile/Inputs/c-general.profdata
index a1d56104a2..b1d1d06122 100644
--- a/test/Profile/Inputs/c-general.profdata
+++ b/test/Profile/Inputs/c-general.profdata
@@ -129,6 +129,13 @@ boolop_loops
50
26
+conditional_operator
+3
+3
+1
+0
+1
+
do_fallthrough
4
4
diff --git a/test/Profile/c-general.c b/test/Profile/c-general.c
index 2475f26692..1359d287af 100644
--- a/test/Profile/c-general.c
+++ b/test/Profile/c-general.c
@@ -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;