r600g: Add support for RATs in evergreen_cb()
[mesa.git] / src / glsl / loop_analysis.h
index 50c512f847f286a60d63d525e086009c6a17c48f..05c982fc164e6e11061bc671fcd22821f8543b6a 100644 (file)
@@ -36,6 +36,30 @@ extern class loop_state *
 analyze_loop_variables(exec_list *instructions);
 
 
+/**
+ * Fill in loop control fields
+ *
+ * Based on analysis of loop variables, this function tries to remove sequences
+ * in the loop of the form
+ *
+ *  (if (expression bool ...) (break))
+ *
+ * and fill in the \c ir_loop::from, \c ir_loop::to, and \c ir_loop::counter
+ * fields of the \c ir_loop.
+ *
+ * In this process, some conditional break-statements may be eliminated
+ * altogether.  For example, if it is provable that one loop exit condition will
+ * always be satisfied before another, the unnecessary exit condition will be
+ * removed.
+ */
+extern bool
+set_loop_controls(exec_list *instructions, loop_state *ls);
+
+
+extern bool
+unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations);
+
+
 /**
  * Tracking for all variables used in a loop
  */
@@ -84,8 +108,30 @@ public:
     */
    hash_table *var_hash;
 
+   /**
+    * Maximum number of loop iterations.
+    *
+    * If this value is negative, then the loop may be infinite.  This actually
+    * means that analysis was unable to determine an upper bound on the number
+    * of loop iterations.
+    */
+   int max_iterations;
+
+   /**
+    * Number of ir_loop_jump instructions that operate on this loop
+    */
+   unsigned num_loop_jumps;
+
+   /**
+    * Whether this loop contains any function calls.
+    */
+   bool contains_calls;
+
    loop_variable_state()
    {
+      this->max_iterations = -1;
+      this->num_loop_jumps = 0;
+      this->contains_calls = false;
       this->var_hash = hash_table_ctor(0, hash_table_pointer_hash,
                                       hash_table_pointer_compare);
    }
@@ -94,6 +140,23 @@ public:
    {
       hash_table_dtor(this->var_hash);
    }
+
+   static void* operator new(size_t size, void *ctx)
+   {
+      void *lvs = ralloc_size(ctx, size);
+      assert(lvs != NULL);
+
+      ralloc_set_destructor(lvs, (void (*)(void*)) destructor);
+
+      return lvs;
+   }
+
+private:
+   static void
+   destructor(loop_variable_state *lvs)
+   {
+      lvs->~loop_variable_state();
+   }
 };
 
 
@@ -174,6 +237,8 @@ public:
 
    loop_variable_state *insert(ir_loop *ir);
 
+   bool loop_found;
+
 private:
    loop_state();