[Mesa-dev] [PATCH 21/26] glsl: Make ir_instruction::ir_type private

Ian Romanick idr at freedesktop.org
Mon Jul 14 15:48:53 PDT 2014


From: Ian Romanick <ian.d.romanick at intel.com>

In the next patch, the type of ir_type is going to change from enum to
uint8_t.  Since the type won't be an enum, we won't get compiler
warnings about, for example, switch statements that don't have cases for
all the enum values.  Using a getter that returns the enum type will
enable us to continue getting those warnings.

Also, ir_type should never be changed after an object is created.
Having it set in the constructor and no setter effectively makes it
write-once.

No change Valgrind massif results for a trimmed apitrace of dota2.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ast_function.cpp                  | 2 +-
 src/glsl/ast_to_hir.cpp                    | 2 +-
 src/glsl/glsl_parser_extras.cpp            | 2 +-
 src/glsl/ir.h                              | 8 +++++++-
 src/glsl/ir_constant_expression.cpp        | 4 ++--
 src/glsl/ir_print_visitor.cpp              | 2 +-
 src/glsl/ir_validate.cpp                   | 6 +++---
 src/glsl/loop_analysis.cpp                 | 2 +-
 src/glsl/loop_controls.cpp                 | 2 +-
 src/glsl/loop_unroll.cpp                   | 2 +-
 src/glsl/lower_clip_distance.cpp           | 4 ++--
 src/glsl/lower_if_to_cond_assign.cpp       | 4 ++--
 src/glsl/lower_jumps.cpp                   | 6 +++---
 src/glsl/lower_offset_array.cpp            | 2 +-
 src/glsl/lower_ubo_reference.cpp           | 4 ++--
 src/glsl/lower_vector.cpp                  | 4 ++--
 src/glsl/lower_vector_insert.cpp           | 2 +-
 src/glsl/opt_constant_folding.cpp          | 2 +-
 src/glsl/opt_cse.cpp                       | 2 +-
 src/glsl/opt_dead_builtin_variables.cpp    | 2 +-
 src/glsl/opt_rebalance_tree.cpp            | 4 ++--
 src/glsl/opt_redundant_jumps.cpp           | 6 +++---
 src/glsl/opt_structure_splitting.cpp       | 2 +-
 src/glsl/opt_vectorize.cpp                 | 2 +-
 src/mesa/program/ir_to_mesa.cpp            | 2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 2 +-
 26 files changed, 44 insertions(+), 38 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 2402e79..92c5bf1 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -171,7 +171,7 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
 
       /* Verify that 'const_in' parameters are ir_constants. */
       if (formal->data.mode == ir_var_const_in &&
-	  actual->ir_type != ir_type_constant) {
+	  actual->get_ir_type() != ir_type_constant) {
 	 _mesa_glsl_error(&loc, state,
 			  "parameter `in %s' must be a constant expression",
 			  formal->name);
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 0a4b3a6..97b2033 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -767,7 +767,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
    /* If the assignment LHS comes back as an ir_binop_vector_extract
     * expression, move it to the RHS as an ir_triop_vector_insert.
     */
-   if (lhs->ir_type == ir_type_expression) {
+   if (lhs->get_ir_type() == ir_type_expression) {
       ir_expression *const lhs_expr = lhs->as_expression();
 
       if (unlikely(lhs_expr->operation == ir_binop_vector_extract)) {
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 1fe38f3..ebfc031 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1532,7 +1532,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
     * are fly-weights that are looked up by glsl_type.
     */
    foreach_in_list (ir_instruction, ir, shader->ir) {
-      switch (ir->ir_type) {
+      switch (ir->get_ir_type()) {
       case ir_type_function: {
          /* If the function is a built-in that is partially overridden in the
           * shader, the ir_function stored in the symbol table may not be the
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 42ccb00..ee42857 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -87,9 +87,15 @@ enum ir_node_type {
  * Base class of all IR instructions
  */
 class ir_instruction : public exec_node {
-public:
+private:
    enum ir_node_type ir_type;
 
+public:
+   inline enum ir_node_type get_ir_type() const
+   {
+      return this->ir_type;
+   }
+
    /**
     * GCC 4.7+ and clang warn when deleting an ir_instruction unless
     * there's a virtual destructor present.  Because we almost
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 5570ed4..e277314 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -402,7 +402,7 @@ constant_referenced(const ir_dereference *deref,
    if (variable_context == NULL)
       return false;
 
-   switch (deref->ir_type) {
+   switch (deref->get_ir_type()) {
    case ir_type_dereference_array: {
       const ir_dereference_array *const da =
          (const ir_dereference_array *) deref;
@@ -1785,7 +1785,7 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(const s
 									 ir_constant **result)
 {
    foreach_in_list(ir_instruction, inst, &body) {
-      switch(inst->ir_type) {
+      switch(inst->get_ir_type()) {
 
 	 /* (declare () type symbol) */
       case ir_type_variable: {
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index bd39805..5f0847b 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -69,7 +69,7 @@ _mesa_print_ir(FILE *f, exec_list *instructions,
    fprintf(f, "(\n");
    foreach_in_list(ir_instruction, ir, instructions) {
       ir->fprint(f);
-      if (ir->ir_type != ir_type_function)
+      if (ir->get_ir_type() != ir_type_function)
 	 fprintf(f, "\n");
    }
    fprintf(f, "\n)");
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 23f55fc..1fda18a 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -173,7 +173,7 @@ ir_validate::visit_enter(ir_function *ir)
     * in fact, function signatures.
     */
    foreach_in_list(ir_instruction, sig, &ir->signatures) {
-      if (sig->ir_type != ir_type_function_signature) {
+      if (sig->get_ir_type() != ir_type_function_signature) {
 	 printf("Non-signature in signature list of function `%s'\n",
 		ir->name);
 	 abort();
@@ -749,7 +749,7 @@ ir_validate::visit_enter(ir_call *ir)
 {
    ir_function_signature *const callee = ir->callee;
 
-   if (callee->ir_type != ir_type_function_signature) {
+   if (callee->get_ir_type() != ir_type_function_signature) {
       printf("IR called by ir_call is not ir_function_signature!\n");
       abort();
    }
@@ -824,7 +824,7 @@ check_node_type(ir_instruction *ir, void *data)
 {
    (void) data;
 
-   if (ir->ir_type >= ir_type_max) {
+   if (ir->get_ir_type() >= ir_type_max) {
       printf("Instruction node with unset type\n");
       ir->print(); printf("\n");
    }
diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp
index 21d46eb..3219521 100644
--- a/src/glsl/loop_analysis.cpp
+++ b/src/glsl/loop_analysis.cpp
@@ -618,7 +618,7 @@ is_loop_terminator(ir_if *ir)
    if (inst == NULL)
       return false;
 
-   if (inst->ir_type != ir_type_loop_jump)
+   if (inst->get_ir_type() != ir_type_loop_jump)
       return false;
 
    ir_loop_jump *const jump = (ir_loop_jump *) inst;
diff --git a/src/glsl/loop_controls.cpp b/src/glsl/loop_controls.cpp
index 36b49eb..a53bb5e 100644
--- a/src/glsl/loop_controls.cpp
+++ b/src/glsl/loop_controls.cpp
@@ -49,7 +49,7 @@ find_initial_value(ir_loop *loop, ir_variable *var)
 	node = node->prev) {
       ir_instruction *ir = (ir_instruction *) node;
 
-      switch (ir->ir_type) {
+      switch (ir->get_ir_type()) {
       case ir_type_call:
       case ir_type_loop:
       case ir_type_loop_jump:
diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
index ce795f6..e8af08f 100644
--- a/src/glsl/loop_unroll.cpp
+++ b/src/glsl/loop_unroll.cpp
@@ -56,7 +56,7 @@ public:
 static bool
 is_break(ir_instruction *ir)
 {
-   return ir != NULL && ir->ir_type == ir_type_loop_jump
+   return ir != NULL && ir->get_ir_type() == ir_type_loop_jump
 		     && ((ir_loop_jump *) ir)->is_break();
 }
 
diff --git a/src/glsl/lower_clip_distance.cpp b/src/glsl/lower_clip_distance.cpp
index 2d6138d..3f7fae1 100644
--- a/src/glsl/lower_clip_distance.cpp
+++ b/src/glsl/lower_clip_distance.cpp
@@ -343,7 +343,7 @@ lower_clip_distance_visitor::handle_rvalue(ir_rvalue **rv)
 void
 lower_clip_distance_visitor::fix_lhs(ir_assignment *ir)
 {
-   if (ir->lhs->ir_type == ir_type_expression) {
+   if (ir->lhs->get_ir_type() == ir_type_expression) {
       void *mem_ctx = ralloc_parent(ir);
       ir_expression *const expr = (ir_expression *) ir->lhs;
 
@@ -352,7 +352,7 @@ lower_clip_distance_visitor::fix_lhs(ir_assignment *ir)
        *     (vector_extract gl_ClipDistanceMESA[i], j).
        */
       assert(expr->operation == ir_binop_vector_extract);
-      assert(expr->operands[0]->ir_type == ir_type_dereference_array);
+      assert(expr->operands[0]->get_ir_type() == ir_type_dereference_array);
       assert(expr->operands[0]->type == glsl_type::vec4_type);
 
       ir_dereference *const new_lhs = (ir_dereference *) expr->operands[0];
diff --git a/src/glsl/lower_if_to_cond_assign.cpp b/src/glsl/lower_if_to_cond_assign.cpp
index 3232ce9..08946f6 100644
--- a/src/glsl/lower_if_to_cond_assign.cpp
+++ b/src/glsl/lower_if_to_cond_assign.cpp
@@ -97,7 +97,7 @@ void
 check_control_flow(ir_instruction *ir, void *data)
 {
    bool *found_control_flow = (bool *)data;
-   switch (ir->ir_type) {
+   switch (ir->get_ir_type()) {
    case ir_type_call:
    case ir_type_discard:
    case ir_type_loop:
@@ -117,7 +117,7 @@ move_block_to_cond_assign(void *mem_ctx,
 			  struct hash_table *ht)
 {
    foreach_in_list_safe(ir_instruction, ir, instructions) {
-      if (ir->ir_type == ir_type_assignment) {
+      if (ir->get_ir_type() == ir_type_assignment) {
 	 ir_assignment *assign = (ir_assignment *)ir;
 
 	 if (hash_table_find(ht, assign) == NULL) {
diff --git a/src/glsl/lower_jumps.cpp b/src/glsl/lower_jumps.cpp
index ec7a0c5..7f15490 100644
--- a/src/glsl/lower_jumps.cpp
+++ b/src/glsl/lower_jumps.cpp
@@ -452,12 +452,12 @@ struct ir_lower_jumps_visitor : public ir_control_flow_visitor {
    {
       if(!ir)
          return strength_none;
-      else if(ir->ir_type == ir_type_loop_jump) {
+      else if(ir->get_ir_type() == ir_type_loop_jump) {
          if(((ir_loop_jump*)ir)->is_break())
             return strength_break;
          else
             return strength_continue;
-      } else if(ir->ir_type == ir_type_return)
+      } else if(ir->get_ir_type() == ir_type_return)
          return strength_return;
       else
          return strength_none;
@@ -982,7 +982,7 @@ lower_continue:
       if (ir->return_type->is_void() &&
           get_jump_strength((ir_instruction *) ir->body.get_tail())) {
          ir_jump *jump = (ir_jump *) ir->body.get_tail();
-         assert (jump->ir_type == ir_type_return);
+         assert (jump->get_ir_type() == ir_type_return);
          jump->remove();
       }
 
diff --git a/src/glsl/lower_offset_array.cpp b/src/glsl/lower_offset_array.cpp
index 5b48526..ec58aa4 100644
--- a/src/glsl/lower_offset_array.cpp
+++ b/src/glsl/lower_offset_array.cpp
@@ -54,7 +54,7 @@ public:
 void
 brw_lower_offset_array_visitor::handle_rvalue(ir_rvalue **rv)
 {
-   if (*rv == NULL || (*rv)->ir_type != ir_type_texture)
+   if (*rv == NULL || (*rv)->get_ir_type() != ir_type_texture)
       return;
 
    ir_texture *ir = (ir_texture *) *rv;
diff --git a/src/glsl/lower_ubo_reference.cpp b/src/glsl/lower_ubo_reference.cpp
index 90e65bd..2454631 100644
--- a/src/glsl/lower_ubo_reference.cpp
+++ b/src/glsl/lower_ubo_reference.cpp
@@ -74,7 +74,7 @@ interface_field_name(void *mem_ctx, char *base_name, ir_dereference *d)
    ir_constant *previous_index = NULL;
 
    while (d != NULL) {
-      switch (d->ir_type) {
+      switch (d->get_ir_type()) {
       case ir_type_dereference_variable: {
          ir_dereference_variable *v = (ir_dereference_variable *) d;
          if (previous_index
@@ -160,7 +160,7 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
     * array dereference has a variable index.
     */
    while (deref) {
-      switch (deref->ir_type) {
+      switch (deref->get_ir_type()) {
       case ir_type_dereference_variable: {
 	 const_offset += ubo_var->Offset;
 	 deref = NULL;
diff --git a/src/glsl/lower_vector.cpp b/src/glsl/lower_vector.cpp
index a658410..2c99d39 100644
--- a/src/glsl/lower_vector.cpp
+++ b/src/glsl/lower_vector.cpp
@@ -71,7 +71,7 @@ is_extended_swizzle(ir_expression *ir)
       ir_rvalue *op = ir->operands[i];
 
       while (op != NULL) {
-	 switch (op->ir_type) {
+	 switch (op->get_ir_type()) {
 	 case ir_type_constant: {
 	    const ir_constant *const c = op->as_constant();
 
@@ -199,7 +199,7 @@ lower_vector_visitor::handle_rvalue(ir_rvalue **rvalue)
    /* FINISHME: This should try to coalesce assignments.
     */
    for (unsigned i = 0; i < expr->type->vector_elements; i++) {
-      if (expr->operands[i]->ir_type == ir_type_constant)
+      if (expr->operands[i]->get_ir_type() == ir_type_constant)
 	 continue;
 
       ir_dereference *const lhs = new(mem_ctx) ir_dereference_variable(temp);
diff --git a/src/glsl/lower_vector_insert.cpp b/src/glsl/lower_vector_insert.cpp
index 6d7cfa9..4c31c09 100644
--- a/src/glsl/lower_vector_insert.cpp
+++ b/src/glsl/lower_vector_insert.cpp
@@ -55,7 +55,7 @@ public:
 void
 vector_insert_visitor::handle_rvalue(ir_rvalue **rv)
 {
-   if (*rv == NULL || (*rv)->ir_type != ir_type_expression)
+   if (*rv == NULL || (*rv)->get_ir_type() != ir_type_expression)
       return;
 
    ir_expression *const expr = (ir_expression *) *rv;
diff --git a/src/glsl/opt_constant_folding.cpp b/src/glsl/opt_constant_folding.cpp
index d0e5754..fd9f792 100644
--- a/src/glsl/opt_constant_folding.cpp
+++ b/src/glsl/opt_constant_folding.cpp
@@ -63,7 +63,7 @@ public:
 void
 ir_constant_folding_visitor::handle_rvalue(ir_rvalue **rvalue)
 {
-   if (*rvalue == NULL || (*rvalue)->ir_type == ir_type_constant)
+   if (*rvalue == NULL || (*rvalue)->get_ir_type() == ir_type_constant)
       return;
 
    /* Note that we do rvalue visitoring on leaving.  So if an
diff --git a/src/glsl/opt_cse.cpp b/src/glsl/opt_cse.cpp
index 9c96835..7ff3c9c 100644
--- a/src/glsl/opt_cse.cpp
+++ b/src/glsl/opt_cse.cpp
@@ -226,7 +226,7 @@ is_cse_candidate(ir_rvalue *ir)
    /* Only handle expressions and textures currently.  We may want to extend
     * to variable-index array dereferences at some point.
     */
-   switch (ir->ir_type) {
+   switch (ir->get_ir_type()) {
    case ir_type_expression:
    case ir_type_texture:
       break;
diff --git a/src/glsl/opt_dead_builtin_variables.cpp b/src/glsl/opt_dead_builtin_variables.cpp
index 85c75d6..805a41a 100644
--- a/src/glsl/opt_dead_builtin_variables.cpp
+++ b/src/glsl/opt_dead_builtin_variables.cpp
@@ -36,7 +36,7 @@ optimize_dead_builtin_variables(exec_list *instructions,
                                 enum ir_variable_mode other)
 {
    foreach_in_list_safe(ir_variable, var, instructions) {
-      if (var->ir_type != ir_type_variable || var->data.used)
+      if (var->get_ir_type() != ir_type_variable || var->data.used)
          continue;
 
       if (var->data.mode != ir_var_uniform
diff --git a/src/glsl/opt_rebalance_tree.cpp b/src/glsl/opt_rebalance_tree.cpp
index 773aab3..e0d3d94 100644
--- a/src/glsl/opt_rebalance_tree.cpp
+++ b/src/glsl/opt_rebalance_tree.cpp
@@ -202,8 +202,8 @@ is_reduction(ir_instruction *ir, void *data)
    /* Array/record dereferences have subtrees that are not part of the expr
     * tree we're balancing. Skip trees containing them.
     */
-   if (ir->ir_type == ir_type_dereference_array ||
-       ir->ir_type == ir_type_dereference_record) {
+   if (ir->get_ir_type() == ir_type_dereference_array ||
+       ir->get_ir_type() == ir_type_dereference_record) {
       ird->is_reduction = false;
       return;
    }
diff --git a/src/glsl/opt_redundant_jumps.cpp b/src/glsl/opt_redundant_jumps.cpp
index ee384d0..19caefc 100644
--- a/src/glsl/opt_redundant_jumps.cpp
+++ b/src/glsl/opt_redundant_jumps.cpp
@@ -70,8 +70,8 @@ redundant_jumps_visitor::visit_leave(ir_if *ir)
    if ((last_then == NULL) || (last_else == NULL))
       return visit_continue;
 
-   if ((last_then->ir_type != ir_type_loop_jump)
-       || (last_else->ir_type != ir_type_loop_jump))
+   if ((last_then->get_ir_type() != ir_type_loop_jump)
+       || (last_else->get_ir_type() != ir_type_loop_jump))
       return visit_continue;
 
    ir_loop_jump *const then_jump = (ir_loop_jump *) last_then;
@@ -104,7 +104,7 @@ redundant_jumps_visitor::visit_leave(ir_loop *ir)
    ir_instruction *const last =
       (ir_instruction *) ir->body_instructions.get_tail();
 
-   if (last && (last->ir_type == ir_type_loop_jump)
+   if (last && (last->get_ir_type() == ir_type_loop_jump)
        && (((ir_loop_jump *) last)->mode == ir_loop_jump::jump_continue)) {
       last->remove();
       this->progress = true;
diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp
index 5e82fe9..bcc469f 100644
--- a/src/glsl/opt_structure_splitting.cpp
+++ b/src/glsl/opt_structure_splitting.cpp
@@ -220,7 +220,7 @@ ir_structure_splitting_visitor::get_splitting_entry(ir_variable *var)
 void
 ir_structure_splitting_visitor::split_deref(ir_dereference **deref)
 {
-   if ((*deref)->ir_type != ir_type_dereference_record)
+   if ((*deref)->get_ir_type() != ir_type_dereference_record)
       return;
 
    ir_dereference_record *deref_record = (ir_dereference_record *)*deref;
diff --git a/src/glsl/opt_vectorize.cpp b/src/glsl/opt_vectorize.cpp
index 28534a8..95026dc 100644
--- a/src/glsl/opt_vectorize.cpp
+++ b/src/glsl/opt_vectorize.cpp
@@ -133,7 +133,7 @@ rewrite_swizzle(ir_instruction *ir, void *data)
 {
    ir_swizzle_mask *mask = (ir_swizzle_mask *)data;
 
-   switch (ir->ir_type) {
+   switch (ir->get_ir_type()) {
    case ir_type_swizzle: {
       ir_swizzle *swz = (ir_swizzle *)ir;
       if (swz->val->type->is_vector()) {
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index def21b2..aea50d6 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -947,7 +947,7 @@ ir_to_mesa_visitor::emit_swz(ir_expression *ir)
       assert(op->type->is_scalar());
 
       while (op != NULL) {
-	 switch (op->ir_type) {
+	 switch (op->get_ir_type()) {
 	 case ir_type_constant: {
 
 	    assert(op->type->is_scalar());
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index ef3f3e0..491437f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2179,7 +2179,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_array *ir)
 
    is_2D_input = this->prog->Target == GL_GEOMETRY_PROGRAM_NV &&
                  src.file == PROGRAM_INPUT &&
-                 ir->array->ir_type != ir_type_dereference_array;
+                 ir->array->get_ir_type() != ir_type_dereference_array;
 
    if (is_2D_input)
       element_size = 1;
-- 
1.8.1.4



More information about the mesa-dev mailing list