[Mesa-dev] [PATCH 6/6] glsl: Generate IR for switch statements
Dan McCabe
zen3d.linux at gmail.com
Fri Jun 24 13:17:34 PDT 2011
On 06/20/2011 03:50 PM, Ian Romanick wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 06/17/2011 05:43 PM, Dan McCabe wrote:
>> Beware! Here be dragons!
>>
>>
> I think this will generate the wrong code for:
>
> for (i = 0; i< 10; i++) {
> switch (i) {
> default: continue;
> }
> }
>
> It seems like that will generate some approximation of:
>
> for (i = 0; i< 10; i++) {
> do {
> continue;
> break;
> } while (true);
> }
>
> Right? This is why I had originally tracked loops and switch-statements
> in a single stack. In this situation, you'd want to set a "do a
> continue" flag in the switch-statement and emit a break (from the
> switch). Something like:
>
>
> for (i = 0; i< 10; i++) {
> bool do_cont = false;
>
> do {
> do_cont = true;
> break;
> break;
> } while (true);
>
> if (do_cont)
> continue;
> }
>
>
Yikes! Looks like you tripped over one of those dragons :(.
Using a do_cont variable (or similar device) feels kludgey to me. I've
been mulling this over for the last couple of days while I did other
things and I think the right way to do this might be to get rid of the
use of "loop" altogether.
But the devil is in the details, which I haven't worked out yet. Going
back to the unified loop/switch stack might be needed, though.
cheers, danm
More information about the mesa-dev
mailing list