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

Liu Xin liuxin at icubecorp.com
Wed Aug 28 20:40:32 PDT 2013



On 08/28/2013 11:17 PM, Kenneth Graunke wrote:
> 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.
>
indeed, I gradually realize glsl IR is not same from lisp at all. in 
lisp, (if (cond) (then) (else)) is an expression. I found that ir_if in 
is not a subclass of ir_rvalue.
it's a statement . that is to say, glsl IR is not functional language. 
it's  a procedural language with a lot of parentheses.


>> 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
yes, your pointers are really helpful.   thank you.

--lx



More information about the mesa-dev mailing list