glsl/ir_builder: Add helpers for making if-statements
authorChad Versace <chad.versace@linux.intel.com>
Fri, 11 Jan 2013 23:53:11 +0000 (15:53 -0800)
committerChad Versace <chad.versace@linux.intel.com>
Fri, 25 Jan 2013 05:24:10 +0000 (21:24 -0800)
Add two overloaded variants of
    ir_if *if_tree()

The new functions allow one to chain together if-trees within a single C++
expression that resembles a real if-statement.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
src/glsl/ir_builder.cpp
src/glsl/ir_builder.h

index b7a116e371d7bc690254d22c88d6f2632dc63b78..8fb30a02a99e58cd7c329cf42770c01424a6208d 100644 (file)
@@ -333,4 +333,33 @@ u2f(operand a)
    return expr(ir_unop_u2f, a);
 }
 
+ir_if*
+if_tree(operand condition,
+        ir_instruction *then_branch)
+{
+   assert(then_branch != NULL);
+
+   void *mem_ctx = ralloc_parent(condition.val);
+
+   ir_if *result = new(mem_ctx) ir_if(condition.val);
+   result->then_instructions.push_tail(then_branch);
+   return result;
+}
+
+ir_if*
+if_tree(operand condition,
+        ir_instruction *then_branch,
+        ir_instruction *else_branch)
+{
+   assert(then_branch != NULL);
+   assert(else_branch != NULL);
+
+   void *mem_ctx = ralloc_parent(condition.val);
+
+   ir_if *result = new(mem_ctx) ir_if(condition.val);
+   result->then_instructions.push_tail(then_branch);
+   result->else_instructions.push_tail(else_branch);
+   return result;
+}
+
 } /* namespace ir_builder */
index 82e37628ec70b29ebcde6adbcd9c8dd318286805..690ac74ebcdfeaf82410256637b29c581b9865b7 100644 (file)
@@ -174,4 +174,10 @@ ir_swizzle *swizzle_xy(operand a);
 ir_swizzle *swizzle_xyz(operand a);
 ir_swizzle *swizzle_xyzw(operand a);
 
+ir_if *if_tree(operand condition,
+               ir_instruction *then_branch);
+ir_if *if_tree(operand condition,
+               ir_instruction *then_branch,
+               ir_instruction *else_branch);
+
 } /* namespace ir_builder */