Put function bodies under function signatures, instead of flat in the parent.
authorEric Anholt <eric@anholt.net>
Wed, 7 Apr 2010 20:19:11 +0000 (13:19 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 8 Apr 2010 00:23:23 +0000 (17:23 -0700)
This will let us know the length of function bodies for the purpose of
inlining (among other uses).

ast_to_hir.cpp
builtin_function.cpp
glsl_types.cpp
ir.cpp
ir.h
ir_constant_folding.cpp
ir_print_visitor.cpp

index 07d40e27d2401703d0570c704871eb2b98dea5d5..d74e54c602ef664ab3292c2ae3d464565e25ca59 100644 (file)
@@ -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();
 
index 684a10c8893e13feda1df68e25396fbf24a372c0..f8ec38c90b557cacadbd4e32fca07f4692f936e7 100644 (file)
@@ -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
index 24b3e3f59f9a67d885023a8e9a4198992195a05e..b7abdaef2ce0f8053ae31e5d45640e99d4a3f681 100644 (file)
@@ -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 99a966e1540c39a776852aac644f68a130d5f5d7..ed0658a18f417cb8d60f3c64754ce2a76507c0a6 100644 (file)
--- 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 7ae5e3b952ac5ce8fed3fa43c013895b0974cce6..95991c013fabd78d34aeb6bb8d02040a27f9e789 100644 (file)
--- 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;
index e43f6f0ea4c9eb2d5507ec57f768bc26d7afd5ee..294f2c2409f902174b7a5490ffc18c172ad0e280 100644 (file)
@@ -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);
 }
 
 
index 20f9a5b5c50f1f0ec76191c6b94b6e0d2d5cbaea..8396973f6c5eb282029a4776e91f44ecd21af245 100644 (file)
@@ -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");
+   }
 }