glsl: Immediately inline built-ins rather than generating calls.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 31 May 2014 06:52:22 +0000 (23:52 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 23 Sep 2016 23:40:40 +0000 (16:40 -0700)
commitb04ef3c08a288a5857349c9e582ee2718fa562f7
tree5a0f938df2c14a190d14eee7efc25ed7a199eede
parent1617f59bc675d6e44d16ab56d95e910d2e2c8f4e
glsl: Immediately inline built-ins rather than generating calls.

In the past, we imported the prototypes of built-in functions, generated
calls to those, and waited until link time to resolve the calls and
import the actual code for the built-in functions.

This severely limited our compile-time optimization opportunities: even
trivial functions like dot() were represented as function calls.  We
also had no way of reasoning about those calls; they could have been
1,000 line functions with side-effects for all we knew.

Practically all built-in functions are trivial translations to
ir_expression opcodes, so it makes sense to just generate those inline.
Since we eventually inline all functions anyway, we may as well just do
it for all built-in functions.

There's only one snag: built-in functions that refer to built-in global
variables need those remapped to the variables in the shader being
compiled, rather than the ones in the built-in shader.  Currently,
ftransform() is the only function matching those criteria, so it seemed
easier to just make it a special case.

On Skylake:

total instructions in shared programs: 12023491 -> 12024010 (0.00%)
instructions in affected programs: 77595 -> 78114 (0.67%)
helped: 97
HURT: 309

total cycles in shared programs: 137239044 -> 137295498 (0.04%)
cycles in affected programs: 16714026 -> 16770480 (0.34%)
helped: 4663
HURT: 4923

while these statistics are in the wrong direction, the number of
hurt programs is small (309 / 41282 = 0.75%), and I don't think
anything can be done about it.  A change like this significantly
alters the order in which optimizations are performed.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by; Ian Romanick <ian.d.romanick@intel.com>
src/compiler/glsl/ast_function.cpp