OSDN Git Service

mesa: better function inlining in the presence of 'return' statements
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 1 Jul 2008 17:41:21 +0000 (11:41 -0600)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 1 Jul 2008 17:41:21 +0000 (11:41 -0600)
commit32a5c4033665d51277c733318ac0461e5f85ad09
tree5d788e14e59221d65a7d0a2fc123d0c3616546d9
parentb2247c7d29667047cd34180826a8966675f8be3a
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.
src/mesa/shader/slang/slang_codegen.c