[PATCH vkd3d 4/7] vkd3d-shader/hlsl: Factor out an hlsl_block structure.
Giovanni Mascellani
gmascellani at codeweavers.com
Wed Oct 20 06:42:56 CDT 2021
Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
Absolutely agree with this one.
Let me just notice that it becomes a little odd to have stuff like
then_instrs.instrs. Maybe "then_instrs" could be replaced with
"then_branch" or "then_body", given that with the new typing it refers
to the block as a whole, not to a list of instructions (even though the
block is nothing else than a list of instructions).
Il 15/10/21 23:54, Zebediah Figura ha scritto:
> This doesn't hold anything other than a list, nor do I have any immediate plans
> for it to hold anything other than a list, but I'm adding it for some degree of
> clarity. Passing around untyped list pointers is not my favourite hobby.
>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
> libs/vkd3d-shader/hlsl.c | 24 +++++++++++-----------
> libs/vkd3d-shader/hlsl.h | 13 ++++++++----
> libs/vkd3d-shader/hlsl.y | 16 +++++++--------
> libs/vkd3d-shader/hlsl_codegen.c | 34 ++++++++++++++++----------------
> libs/vkd3d-shader/hlsl_sm1.c | 2 +-
> libs/vkd3d-shader/hlsl_sm4.c | 2 +-
> 6 files changed, 48 insertions(+), 43 deletions(-)
>
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index 641e05471..a72e0a18f 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -602,8 +602,8 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condit
> 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);
> + list_init(&iff->then_instrs.instrs);
> + list_init(&iff->else_instrs.instrs);
> return iff;
> }
>
> @@ -674,7 +674,7 @@ struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_loc
> if (!(loop = hlsl_alloc(ctx, sizeof(*loop))))
> return NULL;
> init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
> - list_init(&loop->body);
> + list_init(&loop->body.instrs);
> return loop;
> }
>
> @@ -685,7 +685,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl
>
> if (!(decl = hlsl_alloc(ctx, sizeof(*decl))))
> return NULL;
> - list_init(&decl->body);
> + list_init(&decl->body.instrs);
> decl->return_type = return_type;
> decl->parameters = parameters;
> decl->loc = loc;
> @@ -1199,9 +1199,9 @@ static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer,
> vkd3d_string_buffer_printf(buffer, "if (");
> dump_src(buffer, &if_node->condition);
> vkd3d_string_buffer_printf(buffer, ")\n{\n");
> - dump_instr_list(ctx, buffer, &if_node->then_instrs);
> + dump_instr_list(ctx, buffer, &if_node->then_instrs.instrs);
> vkd3d_string_buffer_printf(buffer, "}\nelse\n{\n");
> - dump_instr_list(ctx, buffer, &if_node->else_instrs);
> + dump_instr_list(ctx, buffer, &if_node->else_instrs.instrs);
> vkd3d_string_buffer_printf(buffer, "}\n");
> }
>
> @@ -1230,7 +1230,7 @@ static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_i
> static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop)
> {
> vkd3d_string_buffer_printf(buffer, "for (;;)\n{\n");
> - dump_instr_list(ctx, buffer, &loop->body);
> + dump_instr_list(ctx, buffer, &loop->body.instrs);
> vkd3d_string_buffer_printf(buffer, "}\n");
> }
>
> @@ -1342,7 +1342,7 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl
> vkd3d_string_buffer_printf(&buffer, "\n");
> }
> if (func->has_body)
> - dump_instr_list(ctx, &buffer, &func->body);
> + dump_instr_list(ctx, &buffer, &func->body.instrs);
>
> vkd3d_string_buffer_trace(&buffer);
> vkd3d_string_buffer_cleanup(&buffer);
> @@ -1393,8 +1393,8 @@ static void free_ir_expr(struct hlsl_ir_expr *expr)
>
> static void free_ir_if(struct hlsl_ir_if *if_node)
> {
> - hlsl_free_instr_list(&if_node->then_instrs);
> - hlsl_free_instr_list(&if_node->else_instrs);
> + hlsl_free_instr_list(&if_node->then_instrs.instrs);
> + hlsl_free_instr_list(&if_node->else_instrs.instrs);
> hlsl_src_remove(&if_node->condition);
> vkd3d_free(if_node);
> }
> @@ -1412,7 +1412,7 @@ static void free_ir_load(struct hlsl_ir_load *load)
>
> static void free_ir_loop(struct hlsl_ir_loop *loop)
> {
> - hlsl_free_instr_list(&loop->body);
> + hlsl_free_instr_list(&loop->body.instrs);
> vkd3d_free(loop);
> }
>
> @@ -1483,7 +1483,7 @@ void hlsl_free_instr(struct hlsl_ir_node *node)
> static void free_function_decl(struct hlsl_ir_function_decl *decl)
> {
> vkd3d_free(decl->parameters);
> - hlsl_free_instr_list(&decl->body);
> + hlsl_free_instr_list(&decl->body.instrs);
> vkd3d_free(decl);
> }
>
> diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
> index 99e00b081..a7503d5c8 100644
> --- a/libs/vkd3d-shader/hlsl.h
> +++ b/libs/vkd3d-shader/hlsl.h
> @@ -189,6 +189,11 @@ struct hlsl_ir_node
> struct hlsl_reg reg;
> };
>
> +struct hlsl_block
> +{
> + struct list instrs;
> +};
> +
> struct hlsl_src
> {
> struct hlsl_ir_node *node;
> @@ -258,7 +263,7 @@ struct hlsl_ir_function_decl
> struct rb_entry entry;
> struct hlsl_ir_function *func;
> struct list *parameters;
> - struct list body;
> + struct hlsl_block body;
> bool has_body;
> };
>
> @@ -266,15 +271,15 @@ struct hlsl_ir_if
> {
> struct hlsl_ir_node node;
> struct hlsl_src condition;
> - struct list then_instrs;
> - struct list else_instrs;
> + struct hlsl_block then_instrs;
> + struct hlsl_block else_instrs;
> };
>
> struct hlsl_ir_loop
> {
> struct hlsl_ir_node node;
> /* loop condition is stored in the body (as "if (!condition) break;") */
> - struct list body;
> + struct hlsl_block body;
> unsigned int next_index; /* liveness index of the end of the loop */
> };
>
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index 27ebf0722..aae0ebcea 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -340,7 +340,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_lis
>
> if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, condition->loc)))
> return false;
> - list_add_head(&iff->then_instrs, &jump->node.entry);
> + list_add_head(&iff->then_instrs.instrs, &jump->node.entry);
> return true;
> }
>
> @@ -372,15 +372,15 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, struc
> goto oom;
>
> if (type != LOOP_DO_WHILE)
> - list_move_tail(&loop->body, cond);
> + list_move_tail(&loop->body.instrs, cond);
>
> - list_move_tail(&loop->body, body);
> + list_move_tail(&loop->body.instrs, body);
>
> if (iter)
> - list_move_tail(&loop->body, iter);
> + list_move_tail(&loop->body.instrs, iter);
>
> if (type == LOOP_DO_WHILE)
> - list_move_tail(&loop->body, cond);
> + list_move_tail(&loop->body.instrs, cond);
>
> vkd3d_free(init);
> vkd3d_free(cond);
> @@ -2248,7 +2248,7 @@ func_declaration:
> {
> $$ = $1;
> $$.decl->has_body = true;
> - list_move_tail(&$$.decl->body, $2);
> + list_move_tail(&$$.decl->body.instrs, $2);
> vkd3d_free($2);
> hlsl_pop_scope(ctx);
> }
> @@ -2876,9 +2876,9 @@ selection_statement:
>
> if (!(instr = hlsl_new_if(ctx, condition, @1)))
> YYABORT;
> - list_move_tail(&instr->then_instrs, $5.then_instrs);
> + list_move_tail(&instr->then_instrs.instrs, $5.then_instrs);
> if ($5.else_instrs)
> - list_move_tail(&instr->else_instrs, $5.else_instrs);
> + list_move_tail(&instr->else_instrs.instrs, $5.else_instrs);
> vkd3d_free($5.then_instrs);
> vkd3d_free($5.else_instrs);
> if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1)
> diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
> index a96c701d7..a48777645 100644
> --- a/libs/vkd3d-shader/hlsl_codegen.c
> +++ b/libs/vkd3d-shader/hlsl_codegen.c
> @@ -201,12 +201,12 @@ static void append_output_var_copy(struct hlsl_ctx *ctx, struct list *instrs, st
> }
>
> static bool transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *),
> - struct list *instrs, void *context)
> + struct hlsl_block *block, void *context)
> {
> struct hlsl_ir_node *instr, *next;
> bool progress = 0;
>
> - LIST_FOR_EACH_ENTRY_SAFE(instr, next, instrs, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY_SAFE(instr, next, &block->instrs, struct hlsl_ir_node, entry)
> {
> if (instr->type == HLSL_IR_IF)
> {
> @@ -538,11 +538,11 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
>
> /* Allocate a unique, ordered index to each instruction, which will be used for
> * computing liveness ranges. */
> -static unsigned int index_instructions(struct list *instrs, unsigned int index)
> +static unsigned int index_instructions(struct hlsl_block *block, unsigned int index)
> {
> struct hlsl_ir_node *instr;
>
> - LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
> {
> instr->index = index++;
>
> @@ -584,12 +584,12 @@ static void dump_function(struct rb_entry *entry, void *context)
> * 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 hlsl_block *block, unsigned int loop_first, unsigned int loop_last)
> {
> struct hlsl_ir_node *instr;
> struct hlsl_ir_var *var;
>
> - LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
> {
> const unsigned int var_last_read = loop_last ? max(instr->index, loop_last) : instr->index;
>
> @@ -836,11 +836,11 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir
> }
> }
>
> -static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness)
> +static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness)
> {
> struct hlsl_ir_node *instr;
>
> - LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
> {
> if (!instr->reg.allocated && instr->last_read)
> {
> @@ -893,12 +893,12 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *i
> }
> }
>
> -static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness)
> +static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness)
> {
> struct hlsl_constant_defs *defs = &ctx->constant_defs;
> struct hlsl_ir_node *instr;
>
> - LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
> {
> switch (instr->type)
> {
> @@ -1303,23 +1303,23 @@ struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct
>
> int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out)
> {
> - struct list *const body = &entry_func->body;
> + struct hlsl_block *const body = &entry_func->body;
> struct hlsl_ir_var *var;
> bool progress;
>
> - list_move_head(body, &ctx->static_initializers);
> + list_move_head(&body->instrs, &ctx->static_initializers);
>
> LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry)
> {
> if (var->modifiers & HLSL_STORAGE_UNIFORM)
> - prepend_uniform_copy(ctx, body, var);
> + prepend_uniform_copy(ctx, &body->instrs, var);
> }
>
> LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry)
> {
> if (var->data_type->type == HLSL_CLASS_OBJECT || (var->modifiers & HLSL_STORAGE_UNIFORM))
> {
> - prepend_uniform_copy(ctx, body, var);
> + prepend_uniform_copy(ctx, &body->instrs, var);
> }
> else
> {
> @@ -1328,9 +1328,9 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
> "Parameter \"%s\" is missing a semantic.", var->name);
>
> if (var->modifiers & HLSL_STORAGE_IN)
> - prepend_input_var_copy(ctx, body, var);
> + prepend_input_var_copy(ctx, &body->instrs, var);
> if (var->modifiers & HLSL_STORAGE_OUT)
> - append_output_var_copy(ctx, body, var);
> + append_output_var_copy(ctx, &body->instrs, var);
> }
> }
> if (entry_func->return_var)
> @@ -1339,7 +1339,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
> hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
> "Entry point \"%s\" is missing a return value semantic.", entry_func->func->name);
>
> - append_output_var_copy(ctx, body, entry_func->return_var);
> + append_output_var_copy(ctx, &body->instrs, entry_func->return_var);
> }
>
> while (transform_ir(ctx, fold_redundant_casts, body, NULL));
> diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c
> index f7ccf742f..c3d27eea1 100644
> --- a/libs/vkd3d-shader/hlsl_sm1.c
> +++ b/libs/vkd3d-shader/hlsl_sm1.c
> @@ -768,7 +768,7 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b
> {
> const struct hlsl_ir_node *instr;
>
> - LIST_FOR_EACH_ENTRY(instr, &entry_func->body, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &entry_func->body.instrs, struct hlsl_ir_node, entry)
> {
> if (instr->data_type)
> {
> diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
> index aee06b004..9d45e1633 100644
> --- a/libs/vkd3d-shader/hlsl_sm4.c
> +++ b/libs/vkd3d-shader/hlsl_sm4.c
> @@ -1472,7 +1472,7 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx,
> if (ctx->temp_count)
> write_sm4_dcl_temps(&buffer, ctx->temp_count);
>
> - LIST_FOR_EACH_ENTRY(instr, &entry_func->body, struct hlsl_ir_node, entry)
> + LIST_FOR_EACH_ENTRY(instr, &entry_func->body.instrs, struct hlsl_ir_node, entry)
> {
> if (instr->data_type)
> {
>
More information about the wine-devel
mailing list