glsl: tidy up get_num_operands()
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 9 Aug 2017 03:34:03 +0000 (13:34 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 11 Aug 2017 00:43:16 +0000 (10:43 +1000)
Also add a comment that this should only be used by the ir_reader
interface for testing purposes.

v2:
 - fix grammar in comment
 - use unreachable rather than assert

Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
src/compiler/glsl/ir.cpp
src/compiler/glsl/ir.h

index 51b875058b1ec6a220854aabb43ba34cf71be8ed..98bbd915396abae6c6d24a9ebbb46b23bcfc3c28 100644 (file)
@@ -556,7 +556,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1,
    }
 }
 
    }
 }
 
-unsigned int
+/**
+ * This is only here for ir_reader to used for testing purposes. Please use
+ * the precomputed num_operands field if you need the number of operands.
+ */
+unsigned
 ir_expression::get_num_operands(ir_expression_operation op)
 {
    assert(op <= ir_last_opcode);
 ir_expression::get_num_operands(ir_expression_operation op)
 {
    assert(op <= ir_last_opcode);
@@ -573,8 +577,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
    if (op <= ir_last_quadop)
       return 4;
 
    if (op <= ir_last_quadop)
       return 4;
 
-   assert(false);
-   return 0;
+   unreachable("Could not calculate number of operands");
 }
 
 #include "ir_expression_operation_strings.h"
 }
 
 #include "ir_expression_operation_strings.h"
index 58e6356566fd180346bd36dd2b1f18b6ab0bd7e8..d53b44304d8eae8d7bdd36d96103819d348e23be 100644 (file)
@@ -1538,18 +1538,10 @@ public:
    virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
 
    /**
    virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
 
    /**
-    * Determine the number of operands used by an expression
+    * This is only here for ir_reader to used for testing purposes please use
+    * the precomputed num_operands field if you need the number of operands.
     */
     */
-   static unsigned int get_num_operands(ir_expression_operation);
-
-   /**
-    * Determine the number of operands used by an expression
-    */
-   unsigned int get_num_operands() const
-   {
-      return (this->operation == ir_quadop_vector)
-        ? this->type->vector_elements : get_num_operands(operation);
-   }
+   static unsigned get_num_operands(ir_expression_operation);
 
    /**
     * Return whether the expression operates on vectors horizontally.
 
    /**
     * Return whether the expression operates on vectors horizontally.