diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index be339617..07213fc1 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1789,6 +1789,23 @@ struct hlsl_ir_node *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *cond return &iff->node; } +void hlsl_block_add_if(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *condition, + struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_node *instr = hlsl_new_if(ctx, condition, then_block, else_block, loc); + + if (instr) + { + hlsl_block_add_instr(block, instr); + } + else + { + hlsl_block_cleanup(then_block); + if (else_block) + hlsl_block_cleanup(else_block); + } +} + struct hlsl_ir_switch_case *hlsl_new_switch_case(struct hlsl_ctx *ctx, unsigned int value, bool is_default, struct hlsl_block *body, const struct vkd3d_shader_location *loc) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d97ac95b..7fe3938f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1515,6 +1515,8 @@ struct hlsl_ir_node *hlsl_block_add_expr(struct hlsl_ctx *ctx, struct hlsl_block struct hlsl_type *data_type, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_block_add_float_constant(struct hlsl_ctx *ctx, struct hlsl_block *block, float f, const struct vkd3d_shader_location *loc); +void hlsl_block_add_if(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *condition, + struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_block_add_int_constant(struct hlsl_ctx *ctx, struct hlsl_block *block, int32_t n, const struct vkd3d_shader_location *loc); void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_jump_type type, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b392bd99..15ed6095 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -451,7 +451,7 @@ static uint32_t add_modifiers(struct hlsl_ctx *ctx, uint32_t modifiers, uint32_t static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *cond_block) { - struct hlsl_ir_node *condition, *cast, *not, *iff; + struct hlsl_ir_node *condition, *cast, *not; struct hlsl_block then_block; struct hlsl_type *bool_type; @@ -473,10 +473,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *co hlsl_block_init(&then_block); hlsl_block_add_jump(ctx, &then_block, HLSL_IR_JUMP_BREAK, NULL, &condition->loc); - - if (!(iff = hlsl_new_if(ctx, not, &then_block, NULL, &condition->loc))) - return false; - hlsl_block_add_instr(cond_block, iff); + hlsl_block_add_if(ctx, cond_block, not, &then_block, NULL, &condition->loc); return true; } @@ -8990,7 +8987,6 @@ selection_statement: { struct hlsl_ir_node *condition = node_from_block($4); const struct parse_attribute_list *attributes = &$1; - struct hlsl_ir_node *instr; unsigned int i; check_attribute_list_for_duplicates(ctx, attributes); @@ -9020,19 +9016,13 @@ selection_statement: YYABORT; } - if (!(instr = hlsl_new_if(ctx, condition, $6.then_block, $6.else_block, &@2))) - { - destroy_block($6.then_block); - destroy_block($6.else_block); - cleanup_parse_attribute_list(&$1); - YYABORT; - } + hlsl_block_add_if(ctx, $4, condition, $6.then_block, $6.else_block, &@2); + destroy_block($6.then_block); destroy_block($6.else_block); cleanup_parse_attribute_list(&$1); $$ = $4; - hlsl_block_add_instr($$, instr); } if_body: diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 36d87baa..3b97694a 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1011,7 +1011,7 @@ static bool lower_return(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fun else if (cf_instr) { struct list *tail = list_tail(&block->instrs); - struct hlsl_ir_node *not, *iff, *load; + struct hlsl_ir_node *not, *load; struct hlsl_block then_block; /* If we're in a loop, we should have used "break" instead. */ @@ -1026,10 +1026,7 @@ static bool lower_return(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fun load = hlsl_block_add_simple_load(ctx, block, func->early_return_var, &cf_instr->loc); not = hlsl_block_add_unary_expr(ctx, block, HLSL_OP1_LOGIC_NOT, load, &cf_instr->loc); - - if (!(iff = hlsl_new_if(ctx, not, &then_block, NULL, &cf_instr->loc))) - return false; - list_add_tail(&block->instrs, &iff->entry); + hlsl_block_add_if(ctx, block, not, &then_block, NULL, &cf_instr->loc); } return has_early_return;