[PATCH 3/5] d3dcompiler: Add a dead code elimination pass.
Zebediah Figura
z.figura12 at gmail.com
Mon Jun 29 18:55:37 CDT 2020
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/d3dcompiler_43/hlsl.y | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 15bd0d007b9..932a75bb6dd 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -2937,6 +2937,32 @@ static BOOL fold_constants(struct hlsl_ir_node *instr)
return TRUE;
}
+static BOOL dce(struct hlsl_ir_node *instr)
+{
+ 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);
+ 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)
@@ -3109,6 +3135,7 @@ HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
list_move_head(entry_func->body, &hlsl_ctx.static_initializers);
while (transform_ir(fold_constants, entry_func->body));
+ while (transform_ir(dce, entry_func->body));
/* Index 0 means unused; index 1 means function entry, so start at 2. */
index_instructions(entry_func->body, 2);
--
2.27.0
More information about the wine-devel
mailing list