[Mesa-dev] [RFC 11/12] nir: Add return lowering pass
Jason Ekstrand
jason at jlekstrand.net
Sat Dec 26 17:15:32 PST 2015
On Sat, Dec 26, 2015 at 4:59 PM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> On Sat, Dec 26, 2015 at 7:08 PM, Jason Ekstrand <jason at jlekstrand.net>
> wrote:
> >
> > On Dec 26, 2015 3:04 PM, "Connor Abbott" <cwabbott0 at gmail.com> wrote:
> >>
> >> On Sat, Dec 26, 2015 at 5:57 PM, Jason Ekstrand <jason at jlekstrand.net>
> >> wrote:
> >> >
> >> > On Dec 26, 2015 2:22 PM, "Connor Abbott" <cwabbott0 at gmail.com> wrote:
>
[snip]
> >> >> There are a few problems with this approach.
> >> >>
> >> >> First off, imagine something like:
> >> >>
> >> >> if (...) {
> >> >> if (...) return;
> >> >> }
> >> >> ...
> >> >>
> >> >> If I'm reading this correctly, we'd lower this to:
> >> >>
> >> >> if (...) {
> >> >> if (...) ;
> >> >> }
> >> >> ...
> >> >
> >> > Oops... You're right. I meant to add returns. This
> >> >
> >> > if (...) {
> >> > if (...) return;
> >> > // foo
> >> > }
> >> >
> >> > Should be lowered to
> >> >
> >> > if (...) {
> >> > if (...) {
> >> > } else {
> >> > // foo
> >> > }
> >> > return;
> >> > }
> >> >
> >> > Which we can then lower further.
> >>
> >> I don't think that's correct though. What if there's stuff after the
> >> outer if? It'll only get executed if the outer if condition is false,
> >> instead of if either one is false. I think we really need the flag in
> >> this case.
> >
> > If there's stuff in the outer if, it gets moved into the else
>
> Stuff after the outer if, not in it.
>
Right. I'm thinking what we probably want is a two-pass approach.
Pass 1: Loops. We recurs into all loops and lower returns to set the
return flag and break. This pass goes top-down and depth-first to ensure
that we hit the "if (return_flag) return" after the loop it belongs to. I
also just realized that "if (return_flag return" needs to be inserted after
the phi nodes. We'll need a new cursor helper for that.
Pass 2: If's not in loops. At this point, we can ignore loops completely
since we've already lowered all of them and we need only consider blocks.
This pass is a post-order bottom-up DFS. We look at if/else blocks and, if
one of them has a return, move the stuff after the node into whichever case
doesn't return and put a return after the node.
How does that sound?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151226/85b7cf64/attachment.html>
More information about the mesa-dev
mailing list