[PATCH 1/5] d3dcompiler: Index instructions for liveness ranges.

Zebediah Figura z.figura12 at gmail.com
Sun Mar 29 21:53:16 CDT 2020


From: Zebediah Figura <zfigura at codeweavers.com>

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/d3dcompiler_43/d3dcompiler_private.h |  2 +
 dlls/d3dcompiler_43/hlsl.y                | 65 ++++++++++++++++++++---
 dlls/d3dcompiler_43/utils.c               |  2 +-
 3 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index 2a926282128..0dee4129f01 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -658,6 +658,7 @@ struct hlsl_ir_node
 {
     struct list entry;
     enum hlsl_ir_node_type type;
+    unsigned int index; /* for liveness ranges */
     struct hlsl_type *data_type;
 
     struct source_location loc;
@@ -734,6 +735,7 @@ struct hlsl_ir_loop
     struct hlsl_ir_node node;
     /* loop condition is stored in the body (as "if (!condition) break;") */
     struct list *body;
+    unsigned int next_index; /* liveness index of the end of the loop */
 };
 
 enum hlsl_ir_expr_op {
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 4c3e96caa0d..bf1704b5d55 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -915,6 +915,19 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr
     return NULL;
 }
 
+static struct hlsl_ir_function_decl *get_func_entry(const char *name)
+{
+    struct wine_rb_entry *entry;
+
+    if ((entry = wine_rb_get(&hlsl_ctx.functions, name))
+            && (entry = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry)->overloads.root))
+    {
+        return WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry);
+    }
+
+    return NULL;
+}
+
 static struct list *append_unop(struct list *list, struct hlsl_ir_node *node)
 {
     list_add_tail(list, &node->entry);
@@ -2545,9 +2558,37 @@ static void dump_function(struct wine_rb_entry *entry, void *context)
     wine_rb_for_each_entry(&func->overloads, dump_function_decl, NULL);
 }
 
+/* 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)
+{
+    struct hlsl_ir_node *instr;
+
+    LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
+    {
+        instr->index = index++;
+
+        if (instr->type == HLSL_IR_IF)
+        {
+            struct hlsl_ir_if *iff = if_from_node(instr);
+            index = index_instructions(iff->then_instrs, index);
+            if (iff->else_instrs)
+                index = index_instructions(iff->else_instrs, index);
+        }
+        else if (instr->type == HLSL_IR_LOOP)
+        {
+            index = index_instructions(loop_from_node(instr)->body, index);
+            loop_from_node(instr)->next_index = index;
+        }
+    }
+
+    return index;
+}
+
 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
         const char *entrypoint, char **messages)
 {
+    struct hlsl_ir_function_decl *entry_func;
     struct hlsl_scope *scope, *next_scope;
     struct hlsl_type *hlsl_type, *next_type;
     struct hlsl_ir_var *var, *next_var;
@@ -2573,12 +2614,6 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
 
     hlsl_parse();
 
-    if (TRACE_ON(hlsl_parser))
-    {
-        TRACE("IR dump.\n");
-        wine_rb_for_each_entry(&hlsl_ctx.functions, dump_function, NULL);
-    }
-
     TRACE("Compilation status = %d\n", hlsl_ctx.status);
     if (messages)
     {
@@ -2597,6 +2632,24 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
         d3dcompiler_free((void *)hlsl_ctx.source_files[i]);
     d3dcompiler_free(hlsl_ctx.source_files);
 
+    if (hlsl_ctx.status == PARSE_ERR)
+        goto out;
+
+    if (!(entry_func = get_func_entry(entrypoint)))
+    {
+        hlsl_message("error: entry point %s is not defined\n", debugstr_a(entrypoint));
+        goto out;
+    }
+
+    index_instructions(entry_func->body, 1);
+
+    if (TRACE_ON(hlsl_parser))
+    {
+        TRACE("IR dump.\n");
+        wine_rb_for_each_entry(&hlsl_ctx.functions, dump_function, NULL);
+    }
+
+out:
     TRACE("Freeing functions IR.\n");
     wine_rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL);
 
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c
index 6e9bb593e00..84323c334f8 100644
--- a/dlls/d3dcompiler_43/utils.c
+++ b/dlls/d3dcompiler_43/utils.c
@@ -2156,7 +2156,7 @@ static void debug_dump_ir_loop(const struct hlsl_ir_loop *loop)
 
 static void debug_dump_instr(const struct hlsl_ir_node *instr)
 {
-    wine_dbg_printf("%p: ", instr);
+    wine_dbg_printf("%4u: %p: ", instr->index, instr);
     switch (instr->type)
     {
         case HLSL_IR_EXPR:
-- 
2.25.1




More information about the wine-devel mailing list