From: Eric Anholt Date: Wed, 7 Apr 2010 20:19:11 +0000 (-0700) Subject: Put function bodies under function signatures, instead of flat in the parent. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=894ea972a4defdaafeaa3a248c113b06c7ae0c7e;p=mesa.git Put function bodies under function signatures, instead of flat in the parent. This will let us know the length of function bodies for the purpose of inlining (among other uses). --- diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 07d40e27d24..d74e54c602e 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -1450,7 +1450,7 @@ ast_declarator_list::hir(exec_list *instructions, * FINISHME: required or not. */ - if (var->type->array_size() <= earlier->max_array_access) { + if (var->type->array_size() <= (int)earlier->max_array_access) { YYLTYPE loc = this->get_location(); _mesa_glsl_error(& loc, state, "array size must be > %u due to " @@ -1914,7 +1914,7 @@ ast_function_definition::hir(exec_list *instructions, assert(state->current_function == NULL); state->current_function = signature; - ir_label *label = new ir_label(signature->function_name()); + ir_label *label = new ir_label(signature->function_name(), signature); if (signature->definition == NULL) { signature->definition = label; } @@ -1931,7 +1931,7 @@ ast_function_definition::hir(exec_list *instructions, ir_variable *const var = proto->clone(); - instructions->push_tail(var); + signature->body.push_tail(var); /* The only way a parameter would "exist" is if two parameters have * the same name. @@ -1949,7 +1949,7 @@ ast_function_definition::hir(exec_list *instructions, * instructions to the list that currently consists of the function label * and the function parameters. */ - this->body->hir(instructions, state); + this->body->hir(&signature->body, state); state->symbols->pop_scope(); diff --git a/builtin_function.cpp b/builtin_function.cpp index 684a10c8893..f8ec38c90b5 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -216,7 +216,7 @@ generate_function_instance(ir_function *f, ir_function_signature *const sig = new ir_function_signature(type); f->add_signature(sig); - ir_label *const label = new ir_label(name); + ir_label *const label = new ir_label(name, sig); instructions->push_tail(label); sig->definition = label; static const char *arg_names[] = { @@ -234,16 +234,16 @@ generate_function_instance(ir_function *f, var = new ir_variable(type, arg_names[i]); var->mode = ir_var_in; - instructions->push_tail(var); + sig->body.push_tail(var); declarations[i] = var; } ir_variable *retval = new ir_variable(ret_type, "__retval"); - instructions->push_tail(retval); + sig->body.push_tail(retval); declarations[16] = retval; - generate(instructions, declarations, type); + generate(&sig->body, declarations, type); } void diff --git a/glsl_types.cpp b/glsl_types.cpp index 24b3e3f59f9..b7abdaef2ce 100644 --- a/glsl_types.cpp +++ b/glsl_types.cpp @@ -180,7 +180,8 @@ glsl_type::generate_constructor_prototype(glsl_symbol_table *symtab) const */ static ir_label * generate_constructor_intro(const glsl_type *type, unsigned parameter_count, - exec_list *parameters, exec_list *instructions, + ir_function_signature *const signature, + exec_list *instructions, ir_variable **declarations) { /* Names of parameters used in vector and matrix constructors @@ -194,25 +195,25 @@ generate_constructor_intro(const glsl_type *type, unsigned parameter_count, const glsl_type *const parameter_type = type->get_base_type(); - ir_label *const label = new ir_label(type->name); + ir_label *const label = new ir_label(type->name, signature); instructions->push_tail(label); for (unsigned i = 0; i < parameter_count; i++) { ir_variable *var = new ir_variable(parameter_type, names[i]); var->mode = ir_var_in; - parameters->push_tail(var); + signature->parameters.push_tail(var); var = new ir_variable(parameter_type, names[i]); var->mode = ir_var_in; - instructions->push_tail(var); + signature->body.push_tail(var); declarations[i] = var; } ir_variable *retval = new ir_variable(type, "__retval"); - instructions->push_tail(retval); + signature->body.push_tail(retval); declarations[16] = retval; return label; @@ -453,11 +454,11 @@ generate_constructor(glsl_symbol_table *symtab, const struct glsl_type *types, f->add_signature(sig); sig->definition = - generate_constructor_intro(& types[i], 1, & sig->parameters, + generate_constructor_intro(& types[i], 1, sig, instructions, declarations); if (types[i].is_vector()) { - generate_vec_body_from_scalar(instructions, declarations); + generate_vec_body_from_scalar(&sig->body, declarations); ir_function_signature *const vec_sig = new ir_function_signature(& types[i]); @@ -465,13 +466,13 @@ generate_constructor(glsl_symbol_table *symtab, const struct glsl_type *types, vec_sig->definition = generate_constructor_intro(& types[i], types[i].vector_elements, - & vec_sig->parameters, instructions, + vec_sig, instructions, declarations); - generate_vec_body_from_N_scalars(instructions, declarations); + generate_vec_body_from_N_scalars(&sig->body, declarations); } else { assert(types[i].is_matrix()); - generate_mat_body_from_scalar(instructions, declarations); + generate_mat_body_from_scalar(&sig->body, declarations); ir_function_signature *const mat_sig = new ir_function_signature(& types[i]); @@ -481,7 +482,7 @@ generate_constructor(glsl_symbol_table *symtab, const struct glsl_type *types, generate_constructor_intro(& types[i], (types[i].vector_elements * types[i].matrix_columns), - & mat_sig->parameters, instructions, + mat_sig, instructions, declarations); generate_mat_body_from_N_scalars(instructions, declarations); } diff --git a/ir.cpp b/ir.cpp index 99a966e1540..ed0658a18f4 100644 --- a/ir.cpp +++ b/ir.cpp @@ -110,8 +110,8 @@ ir_expression::get_num_operands(void) return num_operands[this->operation]; } -ir_label::ir_label(const char *label) - : ir_instruction(), label(label) +ir_label::ir_label(const char *label, ir_function_signature *signature) + : ir_instruction(), label(label), signature(signature) { /* empty */ } diff --git a/ir.h b/ir.h index 7ae5e3b952a..95991c013fa 100644 --- a/ir.h +++ b/ir.h @@ -170,7 +170,7 @@ public: class ir_label : public ir_instruction { public: - ir_label(const char *label); + ir_label(const char *label, ir_function_signature *signature); virtual void accept(ir_visitor *v) { @@ -178,11 +178,16 @@ public: } const char *label; + + ir_function_signature *signature; }; /*@{*/ class ir_function_signature : public ir_instruction { + /* An ir_function_signature will be part of the list of signatures in + * an ir_function. + */ public: ir_function_signature(const glsl_type *return_type); @@ -216,6 +221,9 @@ public: */ ir_label *definition; + /** Body of instructions in the function. */ + struct exec_list body; + private: /** Function of which this signature is one overload. */ class ir_function *function; diff --git a/ir_constant_folding.cpp b/ir_constant_folding.cpp index e43f6f0ea4c..294f2c2409f 100644 --- a/ir_constant_folding.cpp +++ b/ir_constant_folding.cpp @@ -46,14 +46,14 @@ ir_constant_folding_visitor::visit(ir_variable *ir) void ir_constant_folding_visitor::visit(ir_label *ir) { - (void) ir; + ir->signature->accept(this); } void ir_constant_folding_visitor::visit(ir_function_signature *ir) { - (void) ir; + visit_exec_list(&ir->body, this); } diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index 20f9a5b5c50..8396973f6c5 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -66,14 +66,20 @@ void ir_print_visitor::visit(ir_variable *ir) void ir_print_visitor::visit(ir_label *ir) { - printf("\n(label %s)", ir->label); + printf("\n(label %s\n", ir->label); + ir->signature->accept(this); + printf(")"); } void ir_print_visitor::visit(ir_function_signature *ir) { - printf("%s:%d:\n", __func__, __LINE__); - (void) ir; + foreach_iter(exec_list_iterator, iter, ir->body) { + ir_instruction *const inst = (ir_instruction *) iter.get(); + + inst->accept(this); + printf("\n"); + } }