glsl: fix handling of quadop_vector constant expression

We forgot to handle the case where the base type was a boolean.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add as_loop_jump() method to ir_instruction

This will let us dynamically downcast to ir_loop_jump, which will be
needed later.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add a foreach_list_reverse macro

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add dead branch analysis

Dead branch analysis determines when the then or else branches of an
if statement will always terminate in a loop jump or return statement,
and hence once we enter that branch we will never get to the statements
after the if. This is useful for determining the dominance tree, which
is needed for the conversion to SSA, as well as various other SSA-based
optimizations.

v2:
-fix & add more comments, store outer_db instead of looking it up (Paul
Berry)

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add loop jump visitor

This visitor will allow us to determine all the loop jumps that
correspond to each loop. In SSA form, each input to a phi node is
associated with a predecessor basic block. In the case of phi nodes
at the beginning and end of loops, these predecessor blocks will
include all blocks that end with a loop_jump (break or continue), and
so in order to insert phi nodes we must know all the loop_jump
instructions that correspond to each loop.

v2:
-add more comments
-store outer_lj instead of looking it up (Paul Berry)

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add swizzle_component() to ir_builder

Like swizzle_x(), swizzle_y(), etc., except the index is programmable.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add SSA infrastructure

This patch introduces all the changes to the IR that are necessary for
representing programs in the SSA form. This consists of a new variable
mode, the SSA temporary, which is guarenteed to be written to exactly
once, and classes to represent phi nodes in the IR.

In the current code, variables are first declared using an ir_variable
instruction inserted into the instruction stream, and then every
dereference will point to the ir_variable declared earlier. SSA
temporaries, however, do not work this way. Instead, the variable
is declared when it is assigned. That is, the variable is "owned" by
the one and only instruction where it is defined.

In SSA, phi nodes may exist at the beginning of any "join nodes," or
basic blocks with more than one predecessor. In our IR, this can happen
in one of three places:

- After an if statement, where the then branch and the else branch
converge.
- At the beginning of a loop, which can be reached from either before
the loop (on the first iteration), the end of the loop (when we get to
the end of the loop and jump back to the beginning), or any continue
statement.
- At the end of a loop, which can be reached from any break statement
within the loop.

Accordingly, there are three different types of phi nodes: if phi nodes,
phi nodes at the beginning of a loop, and phi nodes at the end of a
loop, all of which derive from the ir_phi base class.

v2:

-make ir_phi constructor take the destination (Paul)
-merge ssa_phi, ssa_call, and ssa_assignment into ssa_owner (Paul)
-make ir_phi an abstract class and remove visit(ir_phi *) from ir_visitor
(Paul)
-fix bugs in ir_clone where ssa_owner sometimes wasn't being set
-simplify printing phi node sources (Paul)
-make the name of if/loop phi nodes more consistent when printing (Paul)
-add more invariants to ir_validate (Paul)
glsl: add ssa_assign() to ir_builder

ssa_assign() creates an SSA variable and assignment at the same
time. With this, simple sequences of SSA statements can be easily
created.

Reviewed-by: Paul Berry <stereotype441@gmail.com>
glsl: add pass to convert GLSL IR to SSA form

opt_to_ssa will convert temporaries and local variables to SSA form,
although for now it can't handle array and record dereferences.

v2:
-move class declarations out to a separate header file, move
convert_to_ssa() to the beginning (Paul) -tons more comments (Paul)
-move some code from ir_ssa_variable_state::stack_push() to
ir_ssa_variable_state::new_var(), add more asserts (Paul)
-fix logic in ir_phi_insertion_visitor::visit(ir_dereference_variable *)
(Paul) and optimize it to bail out early in the case of duplicate phi
nodes
-make the control flow stack be a singly-linked list instead of an
exec_list (Paul)
-reorder and rename things in the rewrite visitors to
make what's happening more obvious
WIP: glsl: fixup ir_reader for SSA

TODO finishme
glsl: add a pass to convert out of SSA form

Right now we are being basically as naive as possible, and inserting
more copies than necessary. It is possible to implement a more
sophisticated algorithm later, although extending the current copy
propagation pass to support loops better and/or relying on backends to
do copy propagation may make this unecessary.
glsl: convert to and from SSA form in the compiler

This patch is mainly for allowing me to test these changes with piglit.
In the future, a do_ssa_optimizations() function will need to be
created and used by this code, as well as all other users of
do_common_optimizations().

Reviewed-by: Paul Berry <stereotype441@gmail.com>