glsl: Fix type-deduction for and/or/xor expressions
[mesa.git] / src / glsl / opt_function_inlining.cpp
index 8fef358cc97b102c68d007bbdc5dcf348d632d69..0733d5180d86a7f422568e174534efeb8f33b698 100644 (file)
@@ -27,7 +27,6 @@
  * Replaces calls to functions with the body of the function.
  */
 
-#include <inttypes.h>
 #include "ir.h"
 #include "ir_visitor.h"
 #include "ir_function_inlining.h"
@@ -40,6 +39,8 @@ do_sampler_replacement(exec_list *instructions,
                       ir_variable *sampler,
                       ir_dereference *deref);
 
+namespace {
+
 class ir_function_inlining_visitor : public ir_hierarchical_visitor {
 public:
    ir_function_inlining_visitor()
@@ -54,7 +55,6 @@ public:
 
    virtual ir_visitor_status visit_enter(ir_expression *);
    virtual ir_visitor_status visit_enter(ir_call *);
-   virtual ir_visitor_status visit_enter(ir_assignment *);
    virtual ir_visitor_status visit_enter(ir_return *);
    virtual ir_visitor_status visit_enter(ir_texture *);
    virtual ir_visitor_status visit_enter(ir_swizzle *);
@@ -62,25 +62,13 @@ public:
    bool progress;
 };
 
-
-bool
-automatic_inlining_predicate(ir_instruction *ir)
-{
-   ir_call *call = ir->as_call();
-
-   if (call && can_inline(call))
-      return true;
-
-   return false;
-}
+} /* unnamed namespace */
 
 bool
 do_function_inlining(exec_list *instructions)
 {
    ir_function_inlining_visitor v;
 
-   do_expression_flattening(instructions, automatic_inlining_predicate);
-
    v.run(instructions);
 
    return v.progress;
@@ -90,12 +78,12 @@ static void
 replace_return_with_assignment(ir_instruction *ir, void *data)
 {
    void *ctx = ralloc_parent(ir);
-   ir_variable *retval = (ir_variable *)data;
+   ir_dereference *orig_deref = (ir_dereference *) data;
    ir_return *ret = ir->as_return();
 
    if (ret) {
       if (ret->value) {
-        ir_rvalue *lhs = new(ctx) ir_dereference_variable(retval);
+        ir_rvalue *lhs = orig_deref->clone(ctx, NULL);
         ret->replace_with(new(ctx) ir_assignment(lhs, ret->value, NULL));
       } else {
         /* un-valued return has to be the last return, or we shouldn't
@@ -107,14 +95,13 @@ replace_return_with_assignment(ir_instruction *ir, void *data)
    }
 }
 
-ir_rvalue *
+void
 ir_call::generate_inline(ir_instruction *next_ir)
 {
    void *ctx = ralloc_parent(this);
    ir_variable **parameters;
    int num_parameters;
    int i;
-   ir_variable *retval = NULL;
    struct hash_table *ht;
 
    ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
@@ -125,13 +112,6 @@ ir_call::generate_inline(ir_instruction *next_ir)
 
    parameters = new ir_variable *[num_parameters];
 
-   /* Generate storage for the return value. */
-   if (!this->callee->return_type->is_void()) {
-      retval = new(ctx) ir_variable(this->callee->return_type, "_ret_val",
-                                   ir_var_auto);
-      next_ir->insert_before(retval);
-   }
-
    /* Generate the declarations for the parameters to our inlined code,
     * and set up the mapping of real function body variables to ours.
     */
@@ -164,9 +144,9 @@ ir_call::generate_inline(ir_instruction *next_ir)
       }
 
       /* Move the actual param into our param variable if it's an 'in' type. */
-      if (parameters[i] && (sig_param->mode == ir_var_in ||
+      if (parameters[i] && (sig_param->mode == ir_var_function_in ||
                            sig_param->mode == ir_var_const_in ||
-                           sig_param->mode == ir_var_inout)) {
+                           sig_param->mode == ir_var_function_inout)) {
         ir_assignment *assign;
 
         assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(parameters[i]),
@@ -186,7 +166,7 @@ ir_call::generate_inline(ir_instruction *next_ir)
       ir_instruction *new_ir = ir->clone(ctx, ht);
 
       new_instructions.push_tail(new_ir);
-      visit_tree(new_ir, replace_return_with_assignment, retval);
+      visit_tree(new_ir, replace_return_with_assignment, this->return_deref);
    }
 
    /* If any samplers were passed in, replace any deref of the sampler
@@ -222,8 +202,8 @@ ir_call::generate_inline(ir_instruction *next_ir)
       const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get();
 
       /* Move our param variable into the actual param if it's an 'out' type. */
-      if (parameters[i] && (sig_param->mode == ir_var_out ||
-                           sig_param->mode == ir_var_inout)) {
+      if (parameters[i] && (sig_param->mode == ir_var_function_out ||
+                           sig_param->mode == ir_var_function_inout)) {
         ir_assignment *assign;
 
         assign = new(ctx) ir_assignment(param->clone(ctx, NULL)->as_rvalue(),
@@ -239,11 +219,6 @@ ir_call::generate_inline(ir_instruction *next_ir)
    delete [] parameters;
 
    hash_table_dtor(ht);
-
-   if (retval)
-      return new(ctx) ir_dereference_variable(retval);
-   else
-      return NULL;
 }
 
 
@@ -283,13 +258,7 @@ ir_visitor_status
 ir_function_inlining_visitor::visit_enter(ir_call *ir)
 {
    if (can_inline(ir)) {
-      /* If the call was part of some tree, then it should have been
-       * flattened out or we shouldn't have seen it because of a
-       * visit_continue_with_parent in this visitor.
-       */
-      assert(ir == base_ir);
-
-      (void) ir->generate_inline(ir);
+      ir->generate_inline(ir);
       ir->remove();
       this->progress = true;
    }
@@ -298,25 +267,6 @@ ir_function_inlining_visitor::visit_enter(ir_call *ir)
 }
 
 
-ir_visitor_status
-ir_function_inlining_visitor::visit_enter(ir_assignment *ir)
-{
-   ir_call *call = ir->rhs->as_call();
-   if (!call || !can_inline(call))
-      return visit_continue;
-
-   /* generates the parameter setup, function body, and returns the return
-    * value of the function
-    */
-   ir_rvalue *rhs = call->generate_inline(ir);
-   assert(rhs);
-
-   ir->rhs = rhs;
-   this->progress = true;
-
-   return visit_continue;
-}
-
 /**
  * Replaces references to the "sampler" variable with a clone of "deref."
  *