Module: vkd3d Branch: master Commit: 7c2083d37414ba0200d0ecca736b16fdd8c0491d URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=7c2083d37414ba0200d0ecca...
Author: Zebediah Figura zfigura@codeweavers.com Date: Tue Mar 16 16:31:54 2021 -0500
vkd3d-shader: Add a dead code elimination pass.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com Signed-off-by: Henri Verbeet hverbeet@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
libs/vkd3d-shader/hlsl_codegen.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index c8d8d17..22ad3ed 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -120,6 +120,32 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi return true; }
+static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) +{ + switch (instr->type) + { + case HLSL_IR_CONSTANT: + case HLSL_IR_EXPR: + case HLSL_IR_LOAD: + case HLSL_IR_SWIZZLE: + if (list_empty(&instr->uses)) + { + list_remove(&instr->entry); + hlsl_free_instr(instr); + return true; + } + break; + + case HLSL_IR_ASSIGNMENT: + case HLSL_IR_IF: + case HLSL_IR_JUMP: + case HLSL_IR_LOOP: + break; + } + + return false; +} + /* Allocate a unique, ordered index to each instruction, which will be used for * computing liveness ranges. */ static unsigned int index_instructions(struct list *instrs, unsigned int index) @@ -264,6 +290,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun list_move_head(entry_func->body, &ctx->static_initializers);
while (transform_ir(ctx, fold_constants, entry_func->body, NULL)); + while (transform_ir(ctx, dce, entry_func->body, NULL));
/* Index 0 means unused; index 1 means function entry, so start at 2. */ index_instructions(entry_func->body, 2);