Commit 0a9f2d8b authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3dcompiler: Store the "then" and "else" instruction lists directly in the hlsl_ir_if structure.

parent 2ccf1db2
...@@ -742,8 +742,8 @@ struct hlsl_ir_if ...@@ -742,8 +742,8 @@ struct hlsl_ir_if
{ {
struct hlsl_ir_node node; struct hlsl_ir_node node;
struct hlsl_src condition; struct hlsl_src condition;
struct list *then_instrs; struct list then_instrs;
struct list *else_instrs; struct list else_instrs;
}; };
struct hlsl_ir_loop struct hlsl_ir_loop
......
...@@ -284,6 +284,19 @@ static BOOL type_is_void(const struct hlsl_type *type) ...@@ -284,6 +284,19 @@ static BOOL type_is_void(const struct hlsl_type *type)
return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID; return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID;
} }
static struct hlsl_ir_if *new_if(struct hlsl_ir_node *condition, struct source_location loc)
{
struct hlsl_ir_if *iff;
if (!(iff = d3dcompiler_alloc(sizeof(*iff))))
return NULL;
init_node(&iff->node, HLSL_IR_IF, NULL, loc);
hlsl_src_from_node(&iff->condition, condition);
list_init(&iff->then_instrs);
list_init(&iff->else_instrs);
return iff;
}
static BOOL append_conditional_break(struct list *cond_list) static BOOL append_conditional_break(struct list *cond_list)
{ {
struct hlsl_ir_node *condition, *not; struct hlsl_ir_node *condition, *not;
...@@ -302,22 +315,13 @@ static BOOL append_conditional_break(struct list *cond_list) ...@@ -302,22 +315,13 @@ static BOOL append_conditional_break(struct list *cond_list)
} }
list_add_tail(cond_list, &not->entry); list_add_tail(cond_list, &not->entry);
if (!(iff = d3dcompiler_alloc(sizeof(*iff)))) if (!(iff = new_if(not, condition->loc)))
{ {
ERR("Out of memory.\n"); ERR("Out of memory.\n");
return FALSE; return FALSE;
} }
init_node(&iff->node, HLSL_IR_IF, NULL, condition->loc);
hlsl_src_from_node(&iff->condition, not);
list_add_tail(cond_list, &iff->node.entry); list_add_tail(cond_list, &iff->node.entry);
if (!(iff->then_instrs = d3dcompiler_alloc(sizeof(*iff->then_instrs))))
{
ERR("Out of memory.\n");
return FALSE;
}
list_init(iff->then_instrs);
if (!(jump = d3dcompiler_alloc(sizeof(*jump)))) if (!(jump = d3dcompiler_alloc(sizeof(*jump))))
{ {
ERR("Out of memory.\n"); ERR("Out of memory.\n");
...@@ -325,7 +329,7 @@ static BOOL append_conditional_break(struct list *cond_list) ...@@ -325,7 +329,7 @@ static BOOL append_conditional_break(struct list *cond_list)
} }
init_node(&jump->node, HLSL_IR_JUMP, NULL, condition->loc); init_node(&jump->node, HLSL_IR_JUMP, NULL, condition->loc);
jump->type = HLSL_IR_JUMP_BREAK; jump->type = HLSL_IR_JUMP_BREAK;
list_add_head(iff->then_instrs, &jump->node.entry); list_add_head(&iff->then_instrs, &jump->node.entry);
return TRUE; return TRUE;
} }
...@@ -2211,18 +2215,15 @@ jump_statement: ...@@ -2211,18 +2215,15 @@ jump_statement:
selection_statement: KW_IF '(' expr ')' if_body selection_statement: KW_IF '(' expr ')' if_body
{ {
struct hlsl_ir_if *instr = d3dcompiler_alloc(sizeof(*instr));
struct hlsl_ir_node *condition = node_from_list($3); struct hlsl_ir_node *condition = node_from_list($3);
struct hlsl_ir_if *instr;
if (!instr) if (!(instr = new_if(condition, get_location(&@1))))
{
ERR("Out of memory\n");
YYABORT; YYABORT;
} list_move_tail(&instr->then_instrs, $5.then_instrs);
init_node(&instr->node, HLSL_IR_IF, NULL, get_location(&@1)); list_move_tail(&instr->else_instrs, $5.else_instrs);
hlsl_src_from_node(&instr->condition, condition); d3dcompiler_free($5.then_instrs);
instr->then_instrs = $5.then_instrs; d3dcompiler_free($5.else_instrs);
instr->else_instrs = $5.else_instrs;
if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1) if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1)
{ {
hlsl_report_message(instr->node.loc, HLSL_LEVEL_ERROR, hlsl_report_message(instr->node.loc, HLSL_LEVEL_ERROR,
...@@ -2851,9 +2852,8 @@ static unsigned int index_instructions(struct list *instrs, unsigned int index) ...@@ -2851,9 +2852,8 @@ static unsigned int index_instructions(struct list *instrs, unsigned int index)
if (instr->type == HLSL_IR_IF) if (instr->type == HLSL_IR_IF)
{ {
struct hlsl_ir_if *iff = if_from_node(instr); struct hlsl_ir_if *iff = if_from_node(instr);
index = index_instructions(iff->then_instrs, index); index = index_instructions(&iff->then_instrs, index);
if (iff->else_instrs) index = index_instructions(&iff->else_instrs, index);
index = index_instructions(iff->else_instrs, index);
} }
else if (instr->type == HLSL_IR_LOOP) else if (instr->type == HLSL_IR_LOOP)
{ {
...@@ -2902,9 +2902,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs ...@@ -2902,9 +2902,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
case HLSL_IR_IF: case HLSL_IR_IF:
{ {
struct hlsl_ir_if *iff = if_from_node(instr); struct hlsl_ir_if *iff = if_from_node(instr);
compute_liveness_recurse(iff->then_instrs, loop_first, loop_last); compute_liveness_recurse(&iff->then_instrs, loop_first, loop_last);
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.node->last_read = instr->index; iff->condition.node->last_read = instr->index;
break; break;
} }
......
...@@ -2018,14 +2018,10 @@ static void debug_dump_ir_if(const struct hlsl_ir_if *if_node) ...@@ -2018,14 +2018,10 @@ static void debug_dump_ir_if(const struct hlsl_ir_if *if_node)
wine_dbg_printf("if ("); wine_dbg_printf("if (");
debug_dump_src(&if_node->condition); debug_dump_src(&if_node->condition);
wine_dbg_printf(")\n{\n"); wine_dbg_printf(")\n{\n");
debug_dump_instr_list(if_node->then_instrs); debug_dump_instr_list(&if_node->then_instrs);
wine_dbg_printf("}\nelse\n{\n");
debug_dump_instr_list(&if_node->else_instrs);
wine_dbg_printf("}\n"); wine_dbg_printf("}\n");
if (if_node->else_instrs)
{
wine_dbg_printf("else\n{\n");
debug_dump_instr_list(if_node->else_instrs);
wine_dbg_printf("}\n");
}
} }
static void debug_dump_ir_loop(const struct hlsl_ir_loop *loop) static void debug_dump_ir_loop(const struct hlsl_ir_loop *loop)
...@@ -2157,8 +2153,12 @@ static void free_ir_assignment(struct hlsl_ir_assignment *assignment) ...@@ -2157,8 +2153,12 @@ static void free_ir_assignment(struct hlsl_ir_assignment *assignment)
static void free_ir_if(struct hlsl_ir_if *if_node) static void free_ir_if(struct hlsl_ir_if *if_node)
{ {
free_instr_list(if_node->then_instrs); struct hlsl_ir_node *node, *next_node;
free_instr_list(if_node->else_instrs);
LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->then_instrs, struct hlsl_ir_node, entry)
free_instr(node);
LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->else_instrs, struct hlsl_ir_node, entry)
free_instr(node);
hlsl_src_remove(&if_node->condition); hlsl_src_remove(&if_node->condition);
d3dcompiler_free(if_node); d3dcompiler_free(if_node);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment