[Mesa-dev] obtain def-use chain in glsl s-expression

Kenneth Graunke kenneth at whitecape.org
Wed Aug 28 08:17:07 PDT 2013


On 08/27/2013 11:34 PM, Liu Xin wrote:
> Hi, Mesa community,
>
> I am not familiar with S-expression or other forms of lisp languages.

That's OK - the IR has no resemblance to actual Scheme or Lisp 
programming.  We just print and read the () syntax because it's simple.

> I am working on GLSL IR transformation.  for example, i want to change a
> variable to a array of same type.
>
> By now , i can find the definition of a variable. How can i update all
> uses of this variable in S-expression? I think all uses of this variable
> are in the form of ir_dereference_variable.

That's right.  ir_dereference_variable is an actual use of a variable.

> The difficulty is how to  collect d-u chain using hierarchical visitor.

Yeah...sadly, the compiler doesn't have UD chains.  Ian was working on 
those a few years back, but the code never landed.

> I think some optimizer
> authors  must have the same problem. Could you give me a pass which
> solved my problem?  so I can take reference.

You might look at opt_array_splitting.  It uses two visitors:

First, ir_array_reference_visitor walks over the IR and finds variables 
it might want to transform, storing those in a hash table.  As a second 
pass, ir_array_splitting_visitor walks over the IR and actually 
transforms things.

ir_array_splitting_visitor is also an ir_rvalue visitor, which is useful 
for transforming expression trees.  You get passed an ir_rvalue ** 
pointer, and can replace a whole subexpression tree with something else. 
  In your case, you'll probably find ir_dereference_variables and 
replace them with ir_dereference_arrays.  (In the printed IR, replace 
(var_ref foo) with (array_ref (var_ref new_foo_array) ...subscript...).)

Good luck!

--Ken


More information about the mesa-dev mailing list