Add a very simple cost model to estimate runtime cost of running code.

This is currently only used to decide whether it's worth doing an
"are all lanes running" check at the start of functions--for small
functions, it's not worth the overhead.

The cost is estimated relatively early in compilation (e.g. before
we know if an array access is a scatter/gather or not, before
constant folding, etc.), so there are many known shortcomings.
This commit is contained in:
Matt Pharr
2011-09-16 15:09:17 -07:00
parent 38fc13d1ab
commit ca87579f23
6 changed files with 263 additions and 9 deletions

21
ispc.h
View File

@@ -148,6 +148,8 @@ public:
pointer in place of the original ASTNode *. */
virtual ASTNode *TypeCheck() = 0;
virtual int EstimateCost() const = 0;
/** All AST nodes must track the file position where they are
defined. */
const SourcePos pos;
@@ -365,6 +367,25 @@ struct Globals {
std::vector<std::string> cppArgs;
};
enum {
COST_FUNCALL = 4,
COST_TASK_LAUNCH = 16,
COST_SELECT = 4,
COST_RETURN = 4,
COST_SIMPLE_ARITH_LOGIC_OP = 1,
COST_COMPLEX_ARITH_OP = 4,
COST_COHERENT_BREAK_CONTINE = 4,
COST_REGULAR_BREAK_CONTINUE = 2,
COST_UNIFORM_LOOP = 4,
COST_VARYING_LOOP = 6,
COST_SYNC = 32,
COST_LOAD = 2,
COST_DEREF = 4,
COST_TYPECAST_SIMPLE = 1,
COST_TYPECAST_COMPLEX = 4,
COST_GATHER = 8
};
extern Globals *g;
extern Module *m;