[PATCH vkd3d v5 6/6] vkd3d-shader/hlsl: Handle loops in copy propagation.
Giovanni Mascellani
gmascellani at codeweavers.com
Mon Nov 15 08:27:16 CST 2021
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
libs/vkd3d-shader/hlsl_codegen.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 0ecd8348..53108788 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -266,7 +266,15 @@ static void replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
* "else") can inherit the variable state available just before the
* conditional block. After the conditional block, all variables that
* might have been written in either branch must be invalidated,
- * because we don't know which branch has executed. */
+ * because we don't know which branch has executed.
+ *
+ * When entering a loop block, we can inherit the variable state
+ * available just before the loop block, except that all variables
+ * that are written in the body must be invalidated (because at the
+ * beginning of each execution of the body we don't know whether the
+ * body has already executed or not). The same is valid after the loop
+ * block, because we don't know whether the body has executed at all
+ * or not. */
struct copy_propagation_value
{
@@ -570,6 +578,22 @@ end:
return progress;
}
+static bool copy_propagation_process_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_transform_block(ctx, &loop->body, state);
+
+ copy_propagation_pop(state);
+
+ return progress;
+}
+
static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct copy_propagation_state *state)
{
@@ -593,7 +617,7 @@ static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_b
return progress;
case HLSL_IR_LOOP:
- FIXME("Copy propagation doesn't support loops yet, leaving.\n");
+ progress |= copy_propagation_process_loop(ctx, hlsl_ir_loop(instr), state);
return progress;
default:
--
2.33.1
More information about the wine-devel
mailing list