[Mesa-dev] [PATCH 12/56] glsl: Just access the ir_expression_operation strings table directly

Ian Romanick idr at freedesktop.org
Tue Jul 19 19:24:31 UTC 2016


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

The operator_string functions gave us some protection against a
malformed table.  Now that the table is generated from the same data
that generates the enum, this is not a concern.  Just cut out the middle
man.

   text	   data	    bss	    dec	    hex	filename
7531892	 273992	  28584	7834468	 778b64	i965_dri-64bit-before.so
7531828	 273992	  28584	7834404	 778b24	i965_dri-64bit-after.so

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/ir.cpp                     | 17 ++---------------
 src/compiler/glsl/ir.h                       | 13 ++-----------
 src/compiler/glsl/ir_expression_operation.py |  2 +-
 src/compiler/glsl/ir_print_visitor.cpp       |  2 +-
 src/compiler/glsl/lower_mat_op_to_vec.cpp    |  2 +-
 5 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 62061d6..64aaeca 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -500,18 +500,6 @@ ir_expression::get_num_operands(ir_expression_operation op)
 
 #include "ir_expression_operation_strings.h"
 
-const char *ir_expression::operator_string(ir_expression_operation op)
-{
-   assert((unsigned int) op < ARRAY_SIZE(operator_strs));
-   assert(ARRAY_SIZE(operator_strs) == (ir_quadop_vector + 1));
-   return operator_strs[op];
-}
-
-const char *ir_expression::operator_string()
-{
-   return operator_string(this->operation);
-}
-
 const char*
 depth_layout_string(ir_depth_layout layout)
 {
@@ -531,9 +519,8 @@ depth_layout_string(ir_depth_layout layout)
 ir_expression_operation
 ir_expression::get_operator(const char *str)
 {
-   const int operator_count = sizeof(operator_strs) / sizeof(operator_strs[0]);
-   for (int op = 0; op < operator_count; op++) {
-      if (strcmp(str, operator_strs[op]) == 0)
+   for (int op = 0; op <= int(ir_last_opcode); op++) {
+      if (strcmp(str, ir_expression_operation_strings[op]) == 0)
 	 return (ir_expression_operation) op;
    }
    return (ir_expression_operation) -1;
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index 68e774c..80c5c83 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -1355,6 +1355,8 @@ public:
 
 #include "ir_expression_operation.h"
 
+extern const char *const ir_expression_operation_strings[ir_last_opcode + 1];
+
 class ir_expression : public ir_rvalue {
 public:
    ir_expression(int op, const struct glsl_type *type,
@@ -1422,17 +1424,6 @@ public:
    }
 
    /**
-    * Return a string representing this expression's operator.
-    */
-   const char *operator_string();
-
-   /**
-    * Return a string representing this expression's operator.
-    */
-   static const char *operator_string(ir_expression_operation);
-
-
-   /**
     * Do a reverse-lookup to translate the given string into an operator.
     */
    static ir_expression_operation get_operator(const char *);
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
index 8b55c28..8e2dd27 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -365,7 +365,7 @@ ${item}
 };""")
 
    strings_template = mako.template.Template(copyright + """
-static const char *const operator_strs[] = {
+const char *const ir_expression_operation_strings[] = {
 % for item in values:
 %  if not isinstance(item, str):
    "${item[2] if item[2] is not None else item[0]}",
diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp
index 0dd1c35..9aa7aa5 100644
--- a/src/compiler/glsl/ir_print_visitor.cpp
+++ b/src/compiler/glsl/ir_print_visitor.cpp
@@ -255,7 +255,7 @@ void ir_print_visitor::visit(ir_expression *ir)
 
    print_type(f, ir->type);
 
-   fprintf(f, " %s ", ir->operator_string());
+   fprintf(f, " %s ", ir_expression_operation_strings[ir->operation]);
 
    for (unsigned i = 0; i < ir->get_num_operands(); i++) {
       ir->operands[i]->accept(this);
diff --git a/src/compiler/glsl/lower_mat_op_to_vec.cpp b/src/compiler/glsl/lower_mat_op_to_vec.cpp
index 266fdc6..9a27029 100644
--- a/src/compiler/glsl/lower_mat_op_to_vec.cpp
+++ b/src/compiler/glsl/lower_mat_op_to_vec.cpp
@@ -428,7 +428,7 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
 
    default:
       printf("FINISHME: Handle matrix operation for %s\n",
-	     orig_expr->operator_string());
+	     ir_expression_operation_strings[orig_expr->operation]);
       abort();
    }
    orig_assign->remove();
-- 
2.5.5



More information about the mesa-dev mailing list