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

Ian Romanick idr at freedesktop.org
Tue May 27 19:49:05 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.

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/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_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 +-
 23 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index c70b519..bad410b 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -175,7 +175,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 ef1607d..3fcec19 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -756,7 +756,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/ir.h b/src/glsl/ir.h
index 5d45469..7faee74 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -91,9 +91,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 8afe8f7..c07b951 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -403,7 +403,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
 {
    foreach_list(n, &body) {
       ir_instruction *inst = (ir_instruction *)n;
-      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 0a7695a..e5ac50e 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -70,7 +70,7 @@ _mesa_print_ir(FILE *f, exec_list *instructions,
    foreach_list(n, instructions) {
       ir_instruction *ir = (ir_instruction *) n;
       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 71defc8..1cfd0d5 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -175,7 +175,7 @@ ir_validate::visit_enter(ir_function *ir)
    foreach_list(node, &ir->signatures) {
       ir_instruction *sig = (ir_instruction *) node;
 
-      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();
@@ -720,7 +720,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();
    }
@@ -795,7 +795,7 @@ check_node_type(ir_instruction *ir, void *data)
 {
    (void) data;
 
-   if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
+   if (ir->get_ir_type() <= ir_type_unset || 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 d6a9ac7..2e41048 100644
--- a/src/glsl/loop_analysis.cpp
+++ b/src/glsl/loop_analysis.cpp
@@ -626,7 +626,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 3db06ad..08b7893 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 da53280..c685181 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 f15b217..4c7bfde 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:
@@ -119,7 +119,7 @@ move_block_to_cond_assign(void *mem_ctx,
    foreach_list_safe(node, instructions) {
       ir_instruction *ir = (ir_instruction *) node;
 
-      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 02f65f0..0aaa982 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 0c235ed..2a55d24 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 1b8782b..ac10b1b 100644
--- a/src/glsl/opt_cse.cpp
+++ b/src/glsl/opt_cse.cpp
@@ -228,7 +228,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_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 1ec537b..de21323 100644
--- a/src/glsl/opt_structure_splitting.cpp
+++ b/src/glsl/opt_structure_splitting.cpp
@@ -222,7 +222,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 f9a3b61..7a79bfc 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 59cf123..6112449 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -953,7 +953,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 739e108..9d98f5b 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