Mesa (gallium-mesa-7.4): slang: if we detect an if/break or if/ continue within a loop and we're

Alan Hourihane alanh at kemper.freedesktop.org
Wed Mar 18 21:18:25 UTC 2009


Module: Mesa
Branch: gallium-mesa-7.4
Commit: 9338fbe54b0c0f1bf113af58b81bf3f126fcca6e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9338fbe54b0c0f1bf113af58b81bf3f126fcca6e

Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed Mar 18 21:16:35 2009 +0000

slang: if we detect an if/break or if/continue within a loop and we're
trying to unroll, bail, and fallback to doing the real loop.

---

 src/mesa/shader/slang/slang_codegen.c |   45 ++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index ac70632..5be0ed9 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -742,6 +742,23 @@ new_var(slang_assemble_ctx *A, slang_variable *var)
 
 
 /**
+ * Determine if the given operation is of a specific type.
+ */
+static GLboolean
+is_operation_type(const slang_operation *oper, slang_operation_type type)
+{
+   if (oper->type == type)
+      return GL_TRUE;
+   else if ((oper->type == SLANG_OPER_BLOCK_NEW_SCOPE ||
+             oper->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE) &&
+            oper->num_children == 1)
+      return is_operation_type(&oper->children[0], type);
+   else
+      return GL_FALSE;
+}
+
+
+/**
  * Check if the given function is really just a wrapper for a
  * basic assembly instruction.
  */
@@ -2642,6 +2659,17 @@ _slang_unroll_for_loop(slang_assemble_ctx * A, const slang_operation *oper)
       if (!slang_operation_copy(body, &oper->children[3]))
          return NULL;
 
+      /* 
+       * If we detect an if/break or if/continue lets do the real loop
+       * and forget unrolling.
+       */
+      if (body->children[1].type == SLANG_OPER_IF) {
+         if (is_operation_type(&body->children[1].children[1], SLANG_OPER_BREAK))
+	    return NULL;
+         if (is_operation_type(&body->children[1].children[1], SLANG_OPER_CONTINUE))
+	    return NULL;
+      }
+
       /* in body, replace instances of 'varId' with literal 'iter' */
       {
          slang_variable *oldVar;
@@ -2742,23 +2770,6 @@ _slang_gen_continue(slang_assemble_ctx * A, const slang_operation *oper)
 
 
 /**
- * Determine if the given operation is of a specific type.
- */
-static GLboolean
-is_operation_type(const slang_operation *oper, slang_operation_type type)
-{
-   if (oper->type == type)
-      return GL_TRUE;
-   else if ((oper->type == SLANG_OPER_BLOCK_NEW_SCOPE ||
-             oper->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE) &&
-            oper->num_children == 1)
-      return is_operation_type(&oper->children[0], type);
-   else
-      return GL_FALSE;
-}
-
-
-/**
  * Generate IR tree for an if/then/else conditional using high-level
  * IR_IF instruction.
  */




More information about the mesa-commit mailing list