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).
This commit is contained in:
parent
f1ddca9f21
commit
894ea972a4
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
4
ir.cpp
4
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 */
|
||||
}
|
||||
|
|
10
ir.h
10
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue