[PATCH 3/5] d3dcompiler: Compute liveness ranges for anonymous nodes.

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


From: Zebediah Figura <zfigura at codeweavers.com>

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

diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index e1cdd9a8ba0..df45a7082fe 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -658,10 +658,15 @@ 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;
+
+    /* Liveness ranges. "index" is the index of this instruction. Since this is
+     * essentially an SSA value, the earliest live point is the index. This is
+     * true even for loops, since currently we can't have a reference to a
+     * value generated in an earlier iteration of the loop. */
+    unsigned int index, last_read;
 };
 
 #define HLSL_STORAGE_EXTERN          0x00000001
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index bdf619a9224..312949c5840 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -2604,7 +2604,9 @@ static struct hlsl_ir_var *hlsl_var_from_deref(const struct hlsl_deref *deref)
 
 /* Compute the earliest and latest liveness for each variable. In the case that
  * a variable is accessed inside of a loop, we promote its liveness to extend
- * to at least the range of the entire loop. */
+ * to at least the range of the entire loop. Note that we don't need to do this
+ * for anonymous nodes, since there's currently no way to use a node which was
+ * calculated in an earlier iteration of the loop. */
 static void compute_liveness_recurse(struct list *instrs, unsigned int loop_first, unsigned int loop_last)
 {
     struct hlsl_ir_node *instr;
@@ -2620,6 +2622,17 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
             var = hlsl_var_from_deref(&assignment->lhs);
             if (!var->first_write)
                 var->first_write = loop_first ? min(instr->index, loop_first) : instr->index;
+            assignment->rhs->last_read = instr->index;
+            break;
+        }
+        case HLSL_IR_CONSTANT:
+            break;
+        case HLSL_IR_CONSTRUCTOR:
+        {
+            struct hlsl_ir_constructor *constructor = constructor_from_node(instr);
+            unsigned int i;
+            for (i = 0; i < constructor->args_count; ++i)
+                constructor->args[i]->last_read = instr->index;
             break;
         }
         case HLSL_IR_DEREF:
@@ -2627,6 +2640,18 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
             struct hlsl_ir_deref *deref = deref_from_node(instr);
             var = hlsl_var_from_deref(&deref->src);
             var->last_read = loop_last ? max(instr->index, loop_last) : instr->index;
+            if (deref->src.type == HLSL_IR_DEREF_ARRAY)
+                deref->src.v.array.index->last_read = instr->index;
+            break;
+        }
+        case HLSL_IR_EXPR:
+        {
+            struct hlsl_ir_expr *expr = expr_from_node(instr);
+            expr->operands[0]->last_read = instr->index;
+            if (expr->operands[1])
+                expr->operands[1]->last_read = instr->index;
+            if (expr->operands[2])
+                expr->operands[2]->last_read = instr->index;
             break;
         }
         case HLSL_IR_IF:
@@ -2635,6 +2660,14 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
             compute_liveness_recurse(iff->then_instrs, loop_first, loop_last);
             if (iff->else_instrs)
                 compute_liveness_recurse(iff->else_instrs, loop_first, loop_last);
+            iff->condition->last_read = instr->index;
+            break;
+        }
+        case HLSL_IR_JUMP:
+        {
+            struct hlsl_ir_jump *jump = jump_from_node(instr);
+            if (jump->type == HLSL_IR_JUMP_RETURN && jump->return_value)
+                jump->return_value->last_read = instr->index;
             break;
         }
         case HLSL_IR_LOOP:
@@ -2644,6 +2677,12 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
                     loop_last ? loop_last : loop->next_index);
             break;
         }
+        case HLSL_IR_SWIZZLE:
+        {
+            struct hlsl_ir_swizzle *swizzle = swizzle_from_node(instr);
+            swizzle->val->last_read = instr->index;
+            break;
+        }
         default:
             break;
         }
-- 
2.25.1




More information about the wine-devel mailing list