d3dcompiler: Compute liveness ranges for anonymous nodes.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-03-29 21:53:18 -05:00 committed by Alexandre Julliard
parent 2738e5d2b8
commit 0340b0b044
2 changed files with 46 additions and 2 deletions

View File

@ -658,10 +658,15 @@ struct hlsl_ir_node
{ {
struct list entry; struct list entry;
enum hlsl_ir_node_type type; enum hlsl_ir_node_type type;
unsigned int index; /* for liveness ranges */
struct hlsl_type *data_type; struct hlsl_type *data_type;
struct source_location loc; 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 #define HLSL_STORAGE_EXTERN 0x00000001

View File

@ -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 /* 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 * 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) static void compute_liveness_recurse(struct list *instrs, unsigned int loop_first, unsigned int loop_last)
{ {
struct hlsl_ir_node *instr; 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); var = hlsl_var_from_deref(&assignment->lhs);
if (!var->first_write) if (!var->first_write)
var->first_write = loop_first ? min(instr->index, loop_first) : instr->index; 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; break;
} }
case HLSL_IR_DEREF: 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); struct hlsl_ir_deref *deref = deref_from_node(instr);
var = hlsl_var_from_deref(&deref->src); var = hlsl_var_from_deref(&deref->src);
var->last_read = loop_last ? max(instr->index, loop_last) : instr->index; 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; break;
} }
case HLSL_IR_IF: 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); compute_liveness_recurse(iff->then_instrs, loop_first, loop_last);
if (iff->else_instrs) if (iff->else_instrs)
compute_liveness_recurse(iff->else_instrs, loop_first, loop_last); 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; break;
} }
case HLSL_IR_LOOP: 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); loop_last ? loop_last : loop->next_index);
break; break;
} }
case HLSL_IR_SWIZZLE:
{
struct hlsl_ir_swizzle *swizzle = swizzle_from_node(instr);
swizzle->val->last_read = instr->index;
break;
}
default: default:
break; break;
} }