glsl: Make most ir_instruction::as_subclass() functions non-virtual.
authorMatt Turner <mattst88@gmail.com>
Sat, 31 May 2014 02:26:30 +0000 (19:26 -0700)
committerMatt Turner <mattst88@gmail.com>
Wed, 4 Jun 2014 00:58:34 +0000 (17:58 -0700)
commitac25cf55aff6ec81bc36dc9f3257b0c7a6dd17d3
tree88335feeaa1edfaeff95611b08b3069976cb4085
parent773544f0e95e6732e27ce8f6c4567f221f0d2dac
glsl: Make most ir_instruction::as_subclass() functions non-virtual.

There are several common ways to check whether an object is a particular
subclass: dynamic_cast<>, the as_subclass() pattern, or explicit enum
tags.  We originally used the virtual as_subclass methods, but later
added enum tags as they are much nicer for debugging.

Since we have the enum tags, we don't necessarily need to use virtual
functions to implement the as_subclass() methods.  We can just check the
tag and return the pointer or NULL.

This saves 18 entries in the vtable, and instead of two pointer
dereferences per as_subclass() call most are only three inline
instructions.

Compile time of sam3/112.frag (the longest compile in a recent shader-db
run) is reduced by 5% from 348 to 329 ms (n=500).

perf stat of this workload shows:
   24.14% reduction in iTLB-loads:       285,543 -> 216,606
   42.55% reduction in iTLB-load-misses:  18,785 ->  10,792

Reviewed-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
src/glsl/ir.h