[PATCH vkd3d 4/5] vkd3d-shader/hlsl: Handle loops in copy propagation.
Giovanni Mascellani
gmascellani at codeweavers.com
Tue Nov 9 03:44:38 CST 2021
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
libs/vkd3d-shader/hlsl_codegen.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 78bcd079..fe6a9908 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -537,6 +537,28 @@ end:
return progress;
}
+/* The loop body can inherit the variable state avaiable when entering
+ * the "loop", except that all variables that are written in the body
+ * must be invalidated (because at the beginning of each execution we
+ * don't know whether the body has already executed or not). The same
+ * is valid for after the "loop", because we don't know whether the
+ * body has executed or not. */
+static bool copy_propagation_loop(struct hlsl_ctx *ctx, struct hlsl_ir_loop *loop,
+ struct copy_propagation_state *state)
+{
+ bool progress = false;
+
+ copy_propagation_invalidate_from_block(ctx, state, &loop->body);
+ if (!copy_propagation_duplicate(ctx, state))
+ return progress;
+
+ progress |= copy_propagation_recursive(ctx, &loop->body, state);
+
+ copy_propagation_pop(state);
+
+ return progress;
+}
+
static bool copy_propagation_recursive(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct copy_propagation_state *state)
{
@@ -560,7 +582,7 @@ static bool copy_propagation_recursive(struct hlsl_ctx *ctx, struct hlsl_block *
return progress;
case HLSL_IR_LOOP:
- FIXME("Copy propagation doesn't support loops yet, leaving.\n");
+ progress |= copy_propagation_loop(ctx, hlsl_ir_loop(instr), state);
return progress;
default:
--
2.33.1
More information about the wine-devel
mailing list