From f06aed8e1d15cf2f41b8163db07689dee35c9c42 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 26 Jan 2024 15:24:39 +1100 Subject: [PATCH] glsl: make an explicitly safe version of visit_exec_list() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit visit_exec_list() has always called foreach_in_list_safe() here were rename that version to visit_exec_list_safe() and create a version that calls the non-safe foreach call. There are only 2 users of visit_exec_list() we change lower_jumps to use the renamed version and leave glsl_to_nir() to use the non-safe version as it never deletes the current instruction and in the following patch we will add code that may delete the next instruction meaning the safe version would be unsafe to use. Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/ir.cpp | 8 ++++++++ src/compiler/glsl/ir.h | 3 +++ src/compiler/glsl/lower_jumps.cpp | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp index 517fddb2acd..095fc165164 100644 --- a/src/compiler/glsl/ir.cpp +++ b/src/compiler/glsl/ir.cpp @@ -2221,6 +2221,14 @@ ir_rvalue::error_value(void *mem_ctx) void visit_exec_list(exec_list *list, ir_visitor *visitor) +{ + foreach_in_list(ir_instruction, node, list) { + node->accept(visitor); + } +} + +void +visit_exec_list_safe(exec_list *list, ir_visitor *visitor) { foreach_in_list_safe(ir_instruction, node, list) { node->accept(visitor); diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index 89a9df62c2a..332b662a8f6 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -2427,6 +2427,9 @@ public: void visit_exec_list(exec_list *list, ir_visitor *visitor); +void +visit_exec_list_safe(exec_list *list, ir_visitor *visitor); + /** * Validate invariants on each IR node in a list */ diff --git a/src/compiler/glsl/lower_jumps.cpp b/src/compiler/glsl/lower_jumps.cpp index f6efb9d78b8..e2c7da8d1b5 100644 --- a/src/compiler/glsl/lower_jumps.cpp +++ b/src/compiler/glsl/lower_jumps.cpp @@ -929,7 +929,7 @@ do_lower_jumps(exec_list *instructions, bool pull_out_jumps, bool lower_sub_retu bool progress_ever = false; do { v.progress = false; - visit_exec_list(instructions, &v); + visit_exec_list_safe(instructions, &v); progress_ever = v.progress || progress_ever; } while (v.progress);