diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index bc2e43cfff8..a61b84d6b54 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -722,6 +722,7 @@ struct hlsl_ir_function struct hlsl_ir_function_decl { struct hlsl_type *return_type; + struct hlsl_ir_var *return_var; struct source_location loc; struct wine_rb_entry entry; struct hlsl_ir_function *func; @@ -832,7 +833,6 @@ struct hlsl_ir_jump { struct hlsl_ir_node node; enum hlsl_ir_jump_type type; - struct hlsl_ir_node *return_value; }; struct hlsl_ir_swizzle diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 70ffa70fe10..1797996ddbd 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -507,35 +507,6 @@ static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const cha return NULL; } -static struct hlsl_ir_jump *new_return(struct hlsl_ir_node *value, struct source_location loc) -{ - struct hlsl_type *return_type = hlsl_ctx.cur_function->return_type; - struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump)); - if (!jump) - { - ERR("Out of memory\n"); - return NULL; - } - init_node(&jump->node, HLSL_IR_JUMP, NULL, loc); - jump->type = HLSL_IR_JUMP_RETURN; - if (value) - { - if (!(jump->return_value = implicit_conversion(value, return_type, &loc))) - { - d3dcompiler_free(jump); - return NULL; - } - } - else if (!type_is_void(return_type)) - { - hlsl_report_message(loc, HLSL_LEVEL_ERROR, "non-void function must return a value"); - d3dcompiler_free(jump); - return NULL; - } - - return jump; -} - static struct hlsl_ir_var *new_synthetic_var(const char *name, struct hlsl_type *type, const struct source_location loc) { @@ -578,6 +549,39 @@ static struct hlsl_ir_assignment *make_simple_assignment(struct hlsl_ir_var *lhs return new_assignment(lhs, NULL, rhs, 0, rhs->loc); } +static struct hlsl_ir_jump *new_return(struct hlsl_ir_node *return_value, struct source_location loc) +{ + struct hlsl_type *return_type = hlsl_ctx.cur_function->return_type; + struct hlsl_ir_jump *jump; + + if (return_value) + { + struct hlsl_ir_assignment *assignment; + + if (!(return_value = implicit_conversion(return_value, return_type, &loc))) + return NULL; + + if (!(assignment = make_simple_assignment(hlsl_ctx.cur_function->return_var, return_value))) + return NULL; + list_add_after(&return_value->entry, &assignment->node.entry); + } + else if (!type_is_void(return_type)) + { + hlsl_report_message(loc, HLSL_LEVEL_ERROR, "non-void function must return a value"); + return NULL; + } + + if (!(jump = d3dcompiler_alloc(sizeof(*jump)))) + { + ERR("Out of memory\n"); + return NULL; + } + init_node(&jump->node, HLSL_IR_JUMP, NULL, loc); + jump->type = HLSL_IR_JUMP_RETURN; + + return jump; +} + static struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct source_location loc) { struct hlsl_ir_constant *c; @@ -1264,6 +1268,21 @@ static struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type decl->parameters = parameters; decl->semantic = semantic; decl->loc = loc; + + if (!type_is_void(return_type)) + { + struct hlsl_ir_var *return_var; + char name[28]; + + sprintf(name, "", decl); + if (!(return_var = new_synthetic_var(name, return_type, loc))) + { + d3dcompiler_free(decl); + return NULL; + } + decl->return_var = return_var; + } + return decl; } @@ -2818,8 +2837,6 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs assignment->lhs.offset->last_read = instr->index; break; } - case HLSL_IR_CONSTANT: - break; case HLSL_IR_CONSTRUCTOR: { struct hlsl_ir_constructor *constructor = constructor_from_node(instr); @@ -2847,13 +2864,6 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs 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_LOAD: { struct hlsl_ir_load *load = load_from_node(instr); @@ -2876,7 +2886,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs swizzle->val->last_read = instr->index; break; } - default: + case HLSL_IR_CONSTANT: + case HLSL_IR_JUMP: break; } } @@ -2899,6 +2910,9 @@ static void compute_liveness(struct hlsl_ir_function_decl *entry_func) var->last_read = UINT_MAX; } + if (entry_func->return_var) + entry_func->return_var->last_read = UINT_MAX; + compute_liveness_recurse(entry_func->body, 0, 0); } diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 4fdda3513f7..60bb5ff8145 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -2039,10 +2039,7 @@ static void debug_dump_ir_jump(const struct hlsl_ir_jump *jump) wine_dbg_printf("discard"); break; case HLSL_IR_JUMP_RETURN: - wine_dbg_printf("return "); - if (jump->return_value) - debug_dump_src(jump->return_value); - wine_dbg_printf(";"); + wine_dbg_printf("return"); break; } }