[Mesa-dev] [PATCH 5/5] glsl: Demote 'type' from ir_instruction to ir_rvalue and ir_variable.

Kenneth Graunke kenneth at whitecape.org
Tue Sep 20 18:28:19 PDT 2011


Variables have types, expression trees have types, but statements don't.
Rather than have a nonsensical field that stays NULL in the base class,
just move it to where it makes sense.

Fix up a few places that lazily used ir_instruction even though they
actually knew the particular subclass.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/ast_function.cpp                        |    2 +-
 src/glsl/ir.h                                    |    9 +++++++--
 src/glsl/ir_function.cpp                         |    2 +-
 src/glsl/ir_validate.cpp                         |    4 +++-
 src/glsl/lower_variable_index_to_cond_assign.cpp |    2 +-
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp     |    2 +-
 6 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index c7d9c06..5ab6081 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -83,7 +83,7 @@ prototype_string(const glsl_type *return_type, const char *name,
 
    const char *comma = "";
    foreach_list(node, parameters) {
-      const ir_instruction *const param = (ir_instruction *) node;
+      const ir_variable *const param = (ir_variable *) node;
 
       ralloc_asprintf_append(&str, "%s%s", comma, param->type->name);
       comma = ", ";
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 96b900e..460eabf 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -87,7 +87,6 @@ enum ir_node_type {
 class ir_instruction : public exec_node {
 public:
    enum ir_node_type ir_type;
-   const struct glsl_type *type;
 
    /** ir_print_visitor helper for debugging. */
    void print(void) const;
@@ -126,13 +125,14 @@ protected:
    ir_instruction()
    {
       ir_type = ir_type_unset;
-      type = NULL;
    }
 };
 
 
 class ir_rvalue : public ir_instruction {
 public:
+   const struct glsl_type *type;
+
    virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0;
 
    virtual ir_constant *constant_expression_value() = 0;
@@ -301,6 +301,11 @@ public:
    unsigned component_slots() const;
 
    /**
+    * Declared type of the variable
+    */
+   const struct glsl_type *type;
+
+   /**
     * Delcared name of the variable
     */
    const char *name;
diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
index 51d32b4..55f16e8 100644
--- a/src/glsl/ir_function.cpp
+++ b/src/glsl/ir_function.cpp
@@ -59,7 +59,7 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
 
 
       const ir_variable *const param = (ir_variable *) node_a;
-      const ir_instruction *const actual = (ir_instruction *) node_b;
+      const ir_rvalue *const actual = (ir_rvalue *) node_b;
 
       if (param->type == actual->type)
 	 continue;
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 7ea878b..3bed833 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -616,7 +616,9 @@ check_node_type(ir_instruction *ir, void *data)
       printf("Instruction node with unset type\n");
       ir->print(); printf("\n");
    }
-   assert(ir->type != glsl_type::error_type);
+   ir_rvalue *value = ir->as_rvalue();
+   if (value != NULL)
+      assert(value->type != glsl_type::error_type);
 }
 
 void
diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp
index f8e4a1d..5777107 100644
--- a/src/glsl/lower_variable_index_to_cond_assign.cpp
+++ b/src/glsl/lower_variable_index_to_cond_assign.cpp
@@ -117,7 +117,7 @@ compare_index_block(exec_list *instructions, ir_variable *index,
 }
 
 static inline bool
-is_array_or_matrix(const ir_instruction *ir)
+is_array_or_matrix(const ir_rvalue *ir)
 {
    return (ir->type->is_array() || ir->type->is_matrix());
 }
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index df43be0..fd84911 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1304,7 +1304,7 @@ fs_visitor::visit(ir_constant *ir)
       }
    } else if (ir->type->is_record()) {
       foreach_list(node, &ir->components) {
-	 ir_instruction *const field = (ir_instruction *) node;
+	 ir_constant *const field = (ir_constant *) node;
 	 const unsigned size = type_size(field->type);
 
 	 field->accept(this);
-- 
1.7.6.1



More information about the mesa-dev mailing list