mesa: better function inlining in the presence of 'return' statements
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 1 Jul 2008 17:48:57 +0000 (11:48 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 1 Jul 2008 17:48:57 +0000 (11:48 -0600)
commit44c99ad23655204fd2e567fc38512f12e5f262af
tree954a996ef3c2dd659ba324efe4390529f6acc1db
parent7d4f01413f16c15b55e99aba6da18b5c979c880c
mesa: better function inlining in the presence of 'return' statements

Before, the presence of a 'return' statement always prevented inlining
a function.  This was because we didn't want to accidentally return from
the _calling_ function.  We still need the semantic of 'return' when inlining
but we can't always use unconditional branches/jumps (GPUs don't always
support arbitrary branching).

Now, we allow inlining functions w/ return if the return is the last
statement in the function.  This fixes the common case of a function
that returns a value, such as:

vec4 square(const in vec4 x)
{
   return x * x;
}

which effectively compiles into:

vec4 square(const in vec4 x)
{
   __retVal = x * x;
   return;
}

The 'return' can be no-op'd now and we can inline the function.

cherry-picked from master
src/mesa/shader/slang/slang_codegen.c