[Mesa-dev] [PATCH 5/5] compiler/list: add and use foreach_in_list_from[_safe] macros

Nicolai Hähnle nhaehnle at gmail.com
Sat May 7 22:05:08 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/compiler/glsl/list.h          | 17 +++++++++++++++++
 src/compiler/glsl/lower_jumps.cpp |  7 +------
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/list.h b/src/compiler/glsl/list.h
index f05d437..3ecd3e4 100644
--- a/src/compiler/glsl/list.h
+++ b/src/compiler/glsl/list.h
@@ -736,5 +736,22 @@ inline void exec_node::insert_before(exec_list *before)
            (((__node) = (__type *) __cur) || true);                    \
            __cur = __next, __next = __next->next)
 
+/**
+ * Iterate over a list starting at a given node.
+ */
+#define foreach_in_list_from(__type, __node, __begin) \
+   for (__type *(__node), **__flag = &(__node); __flag; __flag = NULL) \
+      for (exec_node *__cur = (__begin);                               \
+           !__cur->is_tail_sentinel() &&                               \
+           (((__node) = (__type *) __cur) || true);                    \
+           __cur = __cur->next)
+
+#define foreach_in_list_from_safe(__type, __node, __begin) \
+   for (__type *(__node), **__flag = &(__node); __flag; __flag = NULL) \
+      for (struct exec_node *__cur = (__begin),                        \
+                            *__next = __cur->next;                     \
+           __next != NULL &&                                           \
+           (((__node) = (__type *) __cur) || true);                    \
+           __cur = __next, __next = __next->next)
 
 #endif /* LIST_CONTAINER_H */
diff --git a/src/compiler/glsl/lower_jumps.cpp b/src/compiler/glsl/lower_jumps.cpp
index 3cfa2e0..f57c30f 100644
--- a/src/compiler/glsl/lower_jumps.cpp
+++ b/src/compiler/glsl/lower_jumps.cpp
@@ -797,21 +797,16 @@ lower_continue:
              * any instructions that that are already wrapped in the
              * appropriate guard.
              */
-            ir_instruction* ir_after;
-            for(ir_after = (ir_instruction*)ir->get_next(); !ir_after->is_tail_sentinel();)
-            {
+            foreach_in_list_from_safe(ir_instruction, ir_after, ir->get_next()) {
                ir_if* ir_if = ir_after->as_if();
                if(ir_if && ir_if->else_instructions.is_empty()) {
                   ir_dereference_variable* ir_if_cond_deref = ir_if->condition->as_dereference_variable();
                   if(ir_if_cond_deref && ir_if_cond_deref->var == this->loop.execute_flag) {
-                     ir_instruction* ir_next = (ir_instruction*)ir_after->get_next();
                      ir_after->insert_before(&ir_if->then_instructions);
                      ir_after->remove();
-                     ir_after = ir_next;
                      continue;
                   }
                }
-               ir_after = (ir_instruction*)ir_after->get_next();
 
                /* only set this if we find any unprotected instruction */
                this->progress = true;
-- 
2.7.4



More information about the mesa-dev mailing list