Module: wine
Branch: master
Commit: 0340b0b044b8c058f4cd751f495fa3e0cd126e58
URL: https://source.winehq.org/git/wine.git/?a=commit;h=0340b0b044b8c058f4cd751f…
Author: Zebediah Figura <zfigura(a)codeweavers.com>
Date: Sun Mar 29 21:53:18 2020 -0500
d3dcompiler: Compute liveness ranges for anonymous nodes.
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
---
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 e1cdd9a8ba..df45a7082f 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 14f94c04cd..67393f6ca9 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -2607,7 +2607,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;
@@ -2623,6 +2625,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:
@@ -2630,6 +2643,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:
@@ -2638,6 +2663,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:
@@ -2647,6 +2680,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;
}