From fc2954419d754c2dd8c32eb1fd971d8bc800fdbb Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sat, 15 Oct 2011 13:52:08 -0700 Subject: [PATCH] Update cost model to include "if" overhead in "if" statement calculation. --- ispc.h | 2 ++ stmt.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ispc.h b/ispc.h index ba5ce632..a2cacc99 100644 --- a/ispc.h +++ b/ispc.h @@ -367,6 +367,8 @@ enum { COST_TASK_LAUNCH = 16, COST_TYPECAST_COMPLEX = 4, COST_TYPECAST_SIMPLE = 1, + COST_UNIFORM_IF = 2, + COST_VARYING_IF = 3, COST_UNIFORM_LOOP = 4, COST_VARYING_LOOP = 6, COST_ASSERT = 8, diff --git a/stmt.cpp b/stmt.cpp index b2c43b4d..364f931b 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -541,9 +541,15 @@ Stmt *IfStmt::TypeCheck() { int IfStmt::EstimateCost() const { - return ((test ? test->EstimateCost() : 0) + - (trueStmts ? trueStmts->EstimateCost() : 0) + - (falseStmts ? falseStmts->EstimateCost() : 0)); + int ifcost = 0; + const Type *type; + if (test && (type = test->GetType()) != NULL) + ifcost = type->IsUniformType() ? COST_UNIFORM_IF : COST_VARYING_IF; + + return ifcost + + ((test ? test->EstimateCost() : 0) + + (trueStmts ? trueStmts->EstimateCost() : 0) + + (falseStmts ? falseStmts->EstimateCost() : 0)); }