glsl: calculate number of operands in an expression once

Extra validation is added to ir_validate to make sure this is
always updated to the correct numer of operands, as passes like
lower_instructions modify the instructions directly rather then
generating a new one.

The reduction in time is so small that it is not really
measurable. However callgrind was reporting this function as
being called just under 34 million times while compiling the
Deus Ex shaders (just pre-linking was profiled) with 0.20%
spent in this function.

v2:
 - make num_operands a unit8_t
 - fix unsigned/signed mismatches

Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
This commit is contained in:
Timothy Arceri 2017-08-09 13:34:02 +10:00
parent 5563872dbf
commit e2e2c5abd2
22 changed files with 103 additions and 32 deletions

View File

@ -1494,11 +1494,11 @@ nir_visitor::visit(ir_expression *ir)
} }
nir_ssa_def *srcs[4]; nir_ssa_def *srcs[4];
for (unsigned i = 0; i < ir->get_num_operands(); i++) for (unsigned i = 0; i < ir->num_operands; i++)
srcs[i] = evaluate_rvalue(ir->operands[i]); srcs[i] = evaluate_rvalue(ir->operands[i]);
glsl_base_type types[4]; glsl_base_type types[4];
for (unsigned i = 0; i < ir->get_num_operands(); i++) for (unsigned i = 0; i < ir->num_operands; i++)
if (supports_ints) if (supports_ints)
types[i] = ir->operands[i]->type->base_type; types[i] = ir->operands[i]->type->base_type;
else else

View File

@ -203,11 +203,16 @@ ir_expression::ir_expression(int op, const struct glsl_type *type,
this->operands[1] = op1; this->operands[1] = op1;
this->operands[2] = op2; this->operands[2] = op2;
this->operands[3] = op3; this->operands[3] = op3;
init_num_operands();
#ifndef NDEBUG #ifndef NDEBUG
int num_operands = get_num_operands(this->operation); for (unsigned i = num_operands; i < 4; i++) {
for (int i = num_operands; i < 4; i++) {
assert(this->operands[i] == NULL); assert(this->operands[i] == NULL);
} }
for (unsigned i = 0; i < num_operands; i++) {
assert(this->operands[i] != NULL);
}
#endif #endif
} }
@ -221,6 +226,9 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
this->operands[3] = NULL; this->operands[3] = NULL;
assert(op <= ir_last_unop); assert(op <= ir_last_unop);
init_num_operands();
assert(num_operands == 1);
assert(this->operands[0]);
switch (this->operation) { switch (this->operation) {
case ir_unop_bit_not: case ir_unop_bit_not:
@ -425,6 +433,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1)
this->operands[3] = NULL; this->operands[3] = NULL;
assert(op > ir_last_unop); assert(op > ir_last_unop);
init_num_operands();
assert(num_operands == 2);
for (unsigned i = 0; i < num_operands; i++) {
assert(this->operands[i] != NULL);
}
switch (this->operation) { switch (this->operation) {
case ir_binop_all_equal: case ir_binop_all_equal:
@ -519,6 +532,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1,
this->operands[3] = NULL; this->operands[3] = NULL;
assert(op > ir_last_binop && op <= ir_last_triop); assert(op > ir_last_binop && op <= ir_last_triop);
init_num_operands();
assert(num_operands == 3);
for (unsigned i = 0; i < num_operands; i++) {
assert(this->operands[i] != NULL);
}
switch (this->operation) { switch (this->operation) {
case ir_triop_fma: case ir_triop_fma:

View File

@ -1579,8 +1579,21 @@ public:
virtual ir_variable *variable_referenced() const; virtual ir_variable *variable_referenced() const;
/**
* Determine the number of operands used by an expression
*/
void init_num_operands()
{
if (operation == ir_quadop_vector) {
num_operands = this->type->vector_elements;
} else {
num_operands = get_num_operands(operation);
}
}
ir_expression_operation operation; ir_expression_operation operation;
ir_rvalue *operands[4]; ir_rvalue *operands[4];
uint8_t num_operands;
}; };

View File

@ -117,7 +117,7 @@ is_simple_operand(const ir_rvalue *ir, unsigned depth = 1)
case ir_type_expression: { case ir_type_expression: {
const ir_expression *expr = (ir_expression *) ir; const ir_expression *expr = (ir_expression *) ir;
for (unsigned i = 0; i < expr->get_num_operands(); i++) { for (unsigned i = 0; i < expr->num_operands; i++) {
if (!is_simple_operand(expr->operands[i], depth - 1)) if (!is_simple_operand(expr->operands[i], depth - 1))
return false; return false;
} }
@ -485,7 +485,7 @@ ir_builder_print_visitor::visit_enter(ir_assignment *ir)
return visit_continue; return visit_continue;
if (rhs_expr != NULL) { if (rhs_expr != NULL) {
const unsigned num_op = rhs_expr->get_num_operands(); const unsigned num_op = rhs_expr->num_operands;
for (unsigned i = 0; i < num_op; i++) { for (unsigned i = 0; i < num_op; i++) {
if (is_simple_operand(rhs_expr->operands[i])) if (is_simple_operand(rhs_expr->operands[i]))
@ -538,7 +538,7 @@ ir_builder_print_visitor::visit_leave(ir_assignment *ir)
void void
ir_builder_print_visitor::print_without_declaration(const ir_expression *ir) ir_builder_print_visitor::print_without_declaration(const ir_expression *ir)
{ {
const unsigned num_op = ir->get_num_operands(); const unsigned num_op = ir->num_operands;
static const char *const arity[] = { static const char *const arity[] = {
"", "unop", "binop", "triop", "quadop" "", "unop", "binop", "triop", "quadop"
@ -594,7 +594,7 @@ ir_builder_print_visitor::print_without_declaration(const ir_expression *ir)
ir_visitor_status ir_visitor_status
ir_builder_print_visitor::visit_enter(ir_expression *ir) ir_builder_print_visitor::visit_enter(ir_expression *ir)
{ {
const unsigned num_op = ir->get_num_operands(); const unsigned num_op = ir->num_operands;
for (unsigned i = 0; i < num_op; i++) { for (unsigned i = 0; i < num_op; i++) {
if (is_simple_operand(ir->operands[i])) if (is_simple_operand(ir->operands[i]))

View File

@ -160,7 +160,7 @@ ir_expression::clone(void *mem_ctx, struct hash_table *ht) const
ir_rvalue *op[ARRAY_SIZE(this->operands)] = { NULL, }; ir_rvalue *op[ARRAY_SIZE(this->operands)] = { NULL, };
unsigned int i; unsigned int i;
for (i = 0; i < get_num_operands(); i++) { for (i = 0; i < num_operands; i++) {
op[i] = this->operands[i]->clone(mem_ctx, ht); op[i] = this->operands[i]->clone(mem_ctx, ht);
} }

View File

@ -638,7 +638,7 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
for (unsigned operand = 0; operand < this->get_num_operands(); operand++) { for (unsigned operand = 0; operand < this->num_operands; operand++) {
op[operand] = this->operands[operand]->constant_expression_value(variable_context); op[operand] = this->operands[operand]->constant_expression_value(variable_context);
if (!op[operand]) if (!op[operand])
return NULL; return NULL;

View File

@ -202,7 +202,7 @@ ir_expression::equals(const ir_instruction *ir, enum ir_node_type ignore) const
if (operation != other->operation) if (operation != other->operation)
return false; return false;
for (unsigned i = 0; i < get_num_operands(); i++) { for (unsigned i = 0; i < num_operands; i++) {
if (!operands[i]->equals(other->operands[i], ignore)) if (!operands[i]->equals(other->operands[i], ignore))
return false; return false;
} }

View File

@ -137,7 +137,7 @@ ir_expression::accept(ir_hierarchical_visitor *v)
if (s != visit_continue) if (s != visit_continue)
return (s == visit_continue_with_parent) ? visit_continue : s; return (s == visit_continue_with_parent) ? visit_continue : s;
for (unsigned i = 0; i < this->get_num_operands(); i++) { for (unsigned i = 0; i < this->num_operands; i++) {
switch (this->operands[i]->accept(v)) { switch (this->operands[i]->accept(v)) {
case visit_continue: case visit_continue:
break; break;

View File

@ -291,7 +291,7 @@ void ir_print_visitor::visit(ir_expression *ir)
fprintf(f, " %s ", ir_expression_operation_strings[ir->operation]); fprintf(f, " %s ", ir_expression_operation_strings[ir->operation]);
for (unsigned i = 0; i < ir->get_num_operands(); i++) { for (unsigned i = 0; i < ir->num_operands; i++) {
ir->operands[i]->accept(this); ir->operands[i]->accept(this);
} }

View File

@ -39,7 +39,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_expression *ir)
{ {
unsigned int operand; unsigned int operand;
for (operand = 0; operand < ir->get_num_operands(); operand++) { for (operand = 0; operand < ir->num_operands; operand++) {
handle_rvalue(&ir->operands[operand]); handle_rvalue(&ir->operands[operand]);
} }

View File

@ -236,6 +236,14 @@ ir_validate::visit_enter(ir_function_signature *ir)
ir_visitor_status ir_visitor_status
ir_validate::visit_leave(ir_expression *ir) ir_validate::visit_leave(ir_expression *ir)
{ {
for (unsigned i = ir->num_operands; i < 4; i++) {
assert(ir->operands[i] == NULL);
}
for (unsigned i = 0; i < ir->num_operands; i++) {
assert(ir->operands[i] != NULL);
}
switch (ir->operation) { switch (ir->operation) {
case ir_unop_bit_not: case ir_unop_bit_not:
assert(ir->operands[0]->type == ir->type); assert(ir->operands[0]->type == ir->type);

View File

@ -193,6 +193,7 @@ void
lower_instructions_visitor::sub_to_add_neg(ir_expression *ir) lower_instructions_visitor::sub_to_add_neg(ir_expression *ir)
{ {
ir->operation = ir_binop_add; ir->operation = ir_binop_add;
ir->init_num_operands();
ir->operands[1] = new(ir) ir_expression(ir_unop_neg, ir->operands[1]->type, ir->operands[1] = new(ir) ir_expression(ir_unop_neg, ir->operands[1]->type,
ir->operands[1], NULL); ir->operands[1], NULL);
this->progress = true; this->progress = true;
@ -211,6 +212,7 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
/* op0 / op1 -> op0 * (1.0 / op1) */ /* op0 / op1 -> op0 * (1.0 / op1) */
ir->operation = ir_binop_mul; ir->operation = ir_binop_mul;
ir->init_num_operands();
ir->operands[1] = expr; ir->operands[1] = expr;
this->progress = true; this->progress = true;
@ -261,6 +263,7 @@ lower_instructions_visitor::int_div_to_mul_rcp(ir_expression *ir)
ir->operation = ir_unop_i2u; ir->operation = ir_unop_i2u;
ir->operands[0] = new(ir) ir_expression(ir_unop_f2i, op0); ir->operands[0] = new(ir) ir_expression(ir_unop_f2i, op0);
} }
ir->init_num_operands();
ir->operands[1] = NULL; ir->operands[1] = NULL;
this->progress = true; this->progress = true;
@ -272,6 +275,7 @@ lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E)); ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E));
ir->operation = ir_unop_exp2; ir->operation = ir_unop_exp2;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type, ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type,
ir->operands[0], log2_e); ir->operands[0], log2_e);
this->progress = true; this->progress = true;
@ -285,6 +289,7 @@ lower_instructions_visitor::pow_to_exp2(ir_expression *ir)
ir->operands[0]); ir->operands[0]);
ir->operation = ir_unop_exp2; ir->operation = ir_unop_exp2;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[1]->type, ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[1]->type,
ir->operands[1], log2_x); ir->operands[1], log2_x);
ir->operands[1] = NULL; ir->operands[1] = NULL;
@ -295,6 +300,7 @@ void
lower_instructions_visitor::log_to_log2(ir_expression *ir) lower_instructions_visitor::log_to_log2(ir_expression *ir)
{ {
ir->operation = ir_binop_mul; ir->operation = ir_binop_mul;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type, ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
ir->operands[0], NULL); ir->operands[0], NULL);
ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E)); ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E));
@ -345,6 +351,7 @@ lower_instructions_visitor::mod_to_floor(ir_expression *ir)
floor_expr); floor_expr);
ir->operation = ir_binop_sub; ir->operation = ir_binop_sub;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_dereference_variable(x); ir->operands[0] = new(ir) ir_dereference_variable(x);
ir->operands[1] = mul_expr; ir->operands[1] = mul_expr;
this->progress = true; this->progress = true;
@ -465,12 +472,14 @@ lower_instructions_visitor::ldexp_to_arith(ir_expression *ir)
if (!lowering(INSERT_TO_SHIFTS)) { if (!lowering(INSERT_TO_SHIFTS)) {
ir_constant *exp_width = new(ir) ir_constant(8, vec_elem); ir_constant *exp_width = new(ir) ir_constant(8, vec_elem);
ir->operation = ir_unop_bitcast_i2f; ir->operation = ir_unop_bitcast_i2f;
ir->init_num_operands();
ir->operands[0] = bitfield_insert(bitcast_f2i(x), resulting_biased_exp, ir->operands[0] = bitfield_insert(bitcast_f2i(x), resulting_biased_exp,
exp_shift_clone, exp_width); exp_shift_clone, exp_width);
ir->operands[1] = NULL; ir->operands[1] = NULL;
} else { } else {
ir_constant *sign_mantissa_mask = new(ir) ir_constant(0x807fffffu, vec_elem); ir_constant *sign_mantissa_mask = new(ir) ir_constant(0x807fffffu, vec_elem);
ir->operation = ir_unop_bitcast_u2f; ir->operation = ir_unop_bitcast_u2f;
ir->init_num_operands();
ir->operands[0] = bit_or(bit_and(bitcast_f2u(x), sign_mantissa_mask), ir->operands[0] = bit_or(bit_and(bitcast_f2u(x), sign_mantissa_mask),
lshift(i2u(resulting_biased_exp), exp_shift_clone)); lshift(i2u(resulting_biased_exp), exp_shift_clone));
} }
@ -595,6 +604,7 @@ lower_instructions_visitor::dldexp_to_arith(ir_expression *ir)
} }
ir->operation = ir_quadop_vector; ir->operation = ir_quadop_vector;
ir->init_num_operands();
ir->operands[0] = results[0]; ir->operands[0] = results[0];
ir->operands[1] = results[1]; ir->operands[1] = results[1];
ir->operands[2] = results[2]; ir->operands[2] = results[2];
@ -671,6 +681,7 @@ lower_instructions_visitor::dfrexp_sig_to_arith(ir_expression *ir)
/* Put the dvec back together */ /* Put the dvec back together */
ir->operation = ir_quadop_vector; ir->operation = ir_quadop_vector;
ir->init_num_operands();
ir->operands[0] = results[0]; ir->operands[0] = results[0];
ir->operands[1] = results[1]; ir->operands[1] = results[1];
ir->operands[2] = results[2]; ir->operands[2] = results[2];
@ -724,6 +735,7 @@ lower_instructions_visitor::dfrexp_exp_to_arith(ir_expression *ir)
/* For non-zero inputs, shift the exponent down and apply bias. */ /* For non-zero inputs, shift the exponent down and apply bias. */
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_dereference_variable(is_not_zero); ir->operands[0] = new(ir) ir_dereference_variable(is_not_zero);
ir->operands[1] = add(exponent_bias, u2i(rshift(high_words, exponent_shift))); ir->operands[1] = add(exponent_bias, u2i(rshift(high_words, exponent_shift)));
ir->operands[2] = izero; ir->operands[2] = izero;
@ -744,6 +756,7 @@ lower_instructions_visitor::carry_to_arith(ir_expression *ir)
ir_rvalue *x_clone = ir->operands[0]->clone(ir, NULL); ir_rvalue *x_clone = ir->operands[0]->clone(ir, NULL);
ir->operation = ir_unop_i2u; ir->operation = ir_unop_i2u;
ir->init_num_operands();
ir->operands[0] = b2i(less(add(ir->operands[0], ir->operands[1]), x_clone)); ir->operands[0] = b2i(less(add(ir->operands[0], ir->operands[1]), x_clone));
ir->operands[1] = NULL; ir->operands[1] = NULL;
@ -761,6 +774,7 @@ lower_instructions_visitor::borrow_to_arith(ir_expression *ir)
*/ */
ir->operation = ir_unop_i2u; ir->operation = ir_unop_i2u;
ir->init_num_operands();
ir->operands[0] = b2i(less(ir->operands[0], ir->operands[1])); ir->operands[0] = b2i(less(ir->operands[0], ir->operands[1]));
ir->operands[1] = NULL; ir->operands[1] = NULL;
@ -777,6 +791,7 @@ lower_instructions_visitor::sat_to_clamp(ir_expression *ir)
*/ */
ir->operation = ir_binop_min; ir->operation = ir_binop_min;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_expression(ir_binop_max, ir->operands[0]->type, ir->operands[0] = new(ir) ir_expression(ir_binop_max, ir->operands[0]->type,
ir->operands[0], ir->operands[0],
new(ir) ir_constant(0.0f)); new(ir) ir_constant(0.0f));
@ -807,6 +822,7 @@ lower_instructions_visitor::double_dot_to_fma(ir_expression *ir)
} }
ir->operation = ir_triop_fma; ir->operation = ir_triop_fma;
ir->init_num_operands();
ir->operands[0] = swizzle(ir->operands[0], 0, 1); ir->operands[0] = swizzle(ir->operands[0], 0, 1);
ir->operands[1] = swizzle(ir->operands[1], 0, 1); ir->operands[1] = swizzle(ir->operands[1], 0, 1);
ir->operands[2] = new(ir) ir_dereference_variable(temp); ir->operands[2] = new(ir) ir_dereference_variable(temp);
@ -833,6 +849,7 @@ lower_instructions_visitor::double_lrp(ir_expression *ir)
} }
ir->operation = ir_triop_fma; ir->operation = ir_triop_fma;
ir->init_num_operands();
ir->operands[0] = swizzle(op2, swizval, op0->type->vector_elements); ir->operands[0] = swizzle(op2, swizval, op0->type->vector_elements);
ir->operands[2] = mul(sub(one, op2->clone(ir, NULL)), op0); ir->operands[2] = mul(sub(one, op2->clone(ir, NULL)), op0);
@ -857,6 +874,7 @@ lower_instructions_visitor::dceil_to_dfrac(ir_expression *ir)
i.insert_before(assign(frtemp, fract(ir->operands[0]))); i.insert_before(assign(frtemp, fract(ir->operands[0])));
ir->operation = ir_binop_add; ir->operation = ir_binop_add;
ir->init_num_operands();
ir->operands[0] = sub(ir->operands[0]->clone(ir, NULL), frtemp); ir->operands[0] = sub(ir->operands[0]->clone(ir, NULL), frtemp);
ir->operands[1] = csel(nequal(frtemp, zero), one, zero->clone(ir, NULL)); ir->operands[1] = csel(nequal(frtemp, zero), one, zero->clone(ir, NULL));
@ -871,6 +889,7 @@ lower_instructions_visitor::dfloor_to_dfrac(ir_expression *ir)
* result = sub(x, frtemp); * result = sub(x, frtemp);
*/ */
ir->operation = ir_binop_sub; ir->operation = ir_binop_sub;
ir->init_num_operands();
ir->operands[1] = fract(ir->operands[0]->clone(ir, NULL)); ir->operands[1] = fract(ir->operands[0]->clone(ir, NULL));
this->progress = true; this->progress = true;
@ -910,6 +929,7 @@ lower_instructions_visitor::dround_even_to_dfrac(ir_expression *ir)
i.insert_before(assign(t2, sub(temp, frtemp))); i.insert_before(assign(t2, sub(temp, frtemp)));
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = equal(fract(ir->operands[0]->clone(ir, NULL)), ir->operands[0] = equal(fract(ir->operands[0]->clone(ir, NULL)),
p5->clone(ir, NULL)); p5->clone(ir, NULL));
ir->operands[1] = csel(equal(fract(mul(t2, p5->clone(ir, NULL))), ir->operands[1] = csel(equal(fract(mul(t2, p5->clone(ir, NULL))),
@ -945,6 +965,7 @@ lower_instructions_visitor::dtrunc_to_dfrac(ir_expression *ir)
i.insert_before(assign(temp, sub(arg->clone(ir, NULL), frtemp))); i.insert_before(assign(temp, sub(arg->clone(ir, NULL), frtemp)));
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = gequal(arg->clone(ir, NULL), zero); ir->operands[0] = gequal(arg->clone(ir, NULL), zero);
ir->operands[1] = new (ir) ir_dereference_variable(temp); ir->operands[1] = new (ir) ir_dereference_variable(temp);
ir->operands[2] = add(temp, ir->operands[2] = add(temp,
@ -968,6 +989,7 @@ lower_instructions_visitor::dsign_to_csel(ir_expression *ir)
ir_constant *neg_one = new(ir) ir_constant(-1.0, arg->type->vector_elements); ir_constant *neg_one = new(ir) ir_constant(-1.0, arg->type->vector_elements);
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = less(arg->clone(ir, NULL), ir->operands[0] = less(arg->clone(ir, NULL),
zero->clone(ir, NULL)); zero->clone(ir, NULL));
ir->operands[1] = neg_one; ir->operands[1] = neg_one;
@ -1017,6 +1039,7 @@ lower_instructions_visitor::bit_count_to_math(ir_expression *ir)
/* int(((temp + (temp >> 4) & 0xF0F0F0Fu) * 0x1010101u) >> 24); */ /* int(((temp + (temp >> 4) & 0xF0F0F0Fu) * 0x1010101u) >> 24); */
ir->operation = ir_unop_u2i; ir->operation = ir_unop_u2i;
ir->init_num_operands();
ir->operands[0] = rshift(mul(bit_and(add(temp, rshift(temp, c4)), c0F0F0F0F), ir->operands[0] = rshift(mul(bit_and(add(temp, rshift(temp, c4)), c0F0F0F0F),
c01010101), c01010101),
c24); c24);
@ -1060,6 +1083,7 @@ lower_instructions_visitor::extract_to_shifts(ir_expression *ir)
* (value >> offset) & mask; * (value >> offset) & mask;
*/ */
ir->operation = ir_binop_bit_and; ir->operation = ir_binop_bit_and;
ir->init_num_operands();
ir->operands[0] = rshift(ir->operands[0], ir->operands[1]); ir->operands[0] = rshift(ir->operands[0], ir->operands[1]);
ir->operands[1] = mask; ir->operands[1] = mask;
ir->operands[2] = NULL; ir->operands[2] = NULL;
@ -1090,6 +1114,7 @@ lower_instructions_visitor::extract_to_shifts(ir_expression *ir)
* (bits == 0) ? 0 : e; * (bits == 0) ? 0 : e;
*/ */
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = equal(c0, bits); ir->operands[0] = equal(c0, bits);
ir->operands[1] = c0->clone(ir, NULL); ir->operands[1] = c0->clone(ir, NULL);
ir->operands[2] = expr; ir->operands[2] = expr;
@ -1156,6 +1181,7 @@ lower_instructions_visitor::insert_to_shifts(ir_expression *ir)
/* (base & ~mask) | ((insert << offset) & mask) */ /* (base & ~mask) | ((insert << offset) & mask) */
ir->operation = ir_binop_bit_or; ir->operation = ir_binop_bit_or;
ir->init_num_operands();
ir->operands[0] = bit_and(ir->operands[0], bit_not(mask)); ir->operands[0] = bit_and(ir->operands[0], bit_not(mask));
ir->operands[1] = bit_and(lshift(ir->operands[1], offset), mask); ir->operands[1] = bit_and(lshift(ir->operands[1], offset), mask);
ir->operands[2] = NULL; ir->operands[2] = NULL;
@ -1239,10 +1265,12 @@ lower_instructions_visitor::reverse_to_shifts(ir_expression *ir)
if (ir->operands[0]->type->base_type == GLSL_TYPE_UINT) { if (ir->operands[0]->type->base_type == GLSL_TYPE_UINT) {
ir->operation = ir_binop_bit_or; ir->operation = ir_binop_bit_or;
ir->init_num_operands();
ir->operands[0] = rshift(temp, c16); ir->operands[0] = rshift(temp, c16);
ir->operands[1] = lshift(temp, c16->clone(ir, NULL)); ir->operands[1] = lshift(temp, c16->clone(ir, NULL));
} else { } else {
ir->operation = ir_unop_u2i; ir->operation = ir_unop_u2i;
ir->init_num_operands();
ir->operands[0] = bit_or(rshift(temp, c16), ir->operands[0] = bit_or(rshift(temp, c16),
lshift(temp, c16->clone(ir, NULL))); lshift(temp, c16->clone(ir, NULL)));
} }
@ -1323,6 +1351,7 @@ lower_instructions_visitor::find_lsb_to_float_cast(ir_expression *ir)
* small. * small.
*/ */
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = equal(lsb_only, c0); ir->operands[0] = equal(lsb_only, c0);
ir->operands[1] = cminus1; ir->operands[1] = cminus1;
ir->operands[2] = new(ir) ir_dereference_variable(lsb); ir->operands[2] = new(ir) ir_dereference_variable(lsb);
@ -1423,6 +1452,7 @@ lower_instructions_visitor::find_msb_to_float_cast(ir_expression *ir)
* be negative. It will only be negative (-0x7f, in fact) if temp is 0. * be negative. It will only be negative (-0x7f, in fact) if temp is 0.
*/ */
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = less(msb, c0); ir->operands[0] = less(msb, c0);
ir->operands[1] = cminus1; ir->operands[1] = cminus1;
ir->operands[2] = new(ir) ir_dereference_variable(msb); ir->operands[2] = new(ir) ir_dereference_variable(msb);
@ -1555,6 +1585,7 @@ lower_instructions_visitor::imul_high_to_mul(ir_expression *ir)
assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
ir->operation = ir_binop_add; ir->operation = ir_binop_add;
ir->init_num_operands();
ir->operands[0] = add(hi, rshift(t1, c16->clone(ir, NULL))); ir->operands[0] = add(hi, rshift(t1, c16->clone(ir, NULL)));
ir->operands[1] = rshift(t2, c16->clone(ir, NULL)); ir->operands[1] = rshift(t2, c16->clone(ir, NULL));
} else { } else {
@ -1577,6 +1608,7 @@ lower_instructions_visitor::imul_high_to_mul(ir_expression *ir)
u2i(_carry(bit_not(lo), c1))))); u2i(_carry(bit_not(lo), c1)))));
ir->operation = ir_triop_csel; ir->operation = ir_triop_csel;
ir->init_num_operands();
ir->operands[0] = new(ir) ir_dereference_variable(different_signs); ir->operands[0] = new(ir) ir_dereference_variable(different_signs);
ir->operands[1] = new(ir) ir_dereference_variable(neg_hi); ir->operands[1] = new(ir) ir_dereference_variable(neg_hi);
ir->operands[2] = u2i(hi); ir->operands[2] = u2i(hi);

View File

@ -258,7 +258,7 @@ lower_64bit::lower_op_to_function_call(ir_instruction *base_ir,
ir_expression *ir, ir_expression *ir,
ir_function_signature *callee) ir_function_signature *callee)
{ {
const unsigned num_operands = ir->get_num_operands(); const unsigned num_operands = ir->num_operands;
ir_variable *src[4][4]; ir_variable *src[4][4];
ir_variable *dst[4]; ir_variable *dst[4];
void *const mem_ctx = ralloc_parent(ir); void *const mem_ctx = ralloc_parent(ir);
@ -319,7 +319,7 @@ lower_64bit_visitor::handle_op(ir_expression *ir,
const char *function_name, const char *function_name,
function_generator generator) function_generator generator)
{ {
for (unsigned i = 0; i < ir->get_num_operands(); i++) for (unsigned i = 0; i < ir->num_operands; i++)
if (!ir->operands[i]->type->is_integer_64()) if (!ir->operands[i]->type->is_integer_64())
return ir; return ir;

View File

@ -76,7 +76,7 @@ mat_op_to_vec_predicate(ir_instruction *ir)
if (!expr) if (!expr)
return false; return false;
for (i = 0; i < expr->get_num_operands(); i++) { for (i = 0; i < expr->num_operands; i++) {
if (expr->operands[i]->type->is_matrix()) if (expr->operands[i]->type->is_matrix())
return true; return true;
} }
@ -294,7 +294,7 @@ ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_dereference *result,
static bool static bool
has_matrix_operand(const ir_expression *expr, unsigned &columns) has_matrix_operand(const ir_expression *expr, unsigned &columns)
{ {
for (unsigned i = 0; i < expr->get_num_operands(); i++) { for (unsigned i = 0; i < expr->num_operands; i++) {
if (expr->operands[i]->type->is_matrix()) { if (expr->operands[i]->type->is_matrix()) {
columns = expr->operands[i]->type->matrix_columns; columns = expr->operands[i]->type->matrix_columns;
return true; return true;
@ -318,7 +318,7 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
if (!has_matrix_operand(orig_expr, matrix_columns)) if (!has_matrix_operand(orig_expr, matrix_columns))
return visit_continue; return visit_continue;
assert(orig_expr->get_num_operands() <= 2); assert(orig_expr->num_operands <= 2);
mem_ctx = ralloc_parent(orig_assign); mem_ctx = ralloc_parent(orig_assign);
@ -329,7 +329,7 @@ ir_mat_op_to_vec_visitor::visit_leave(ir_assignment *orig_assign)
/* Store the expression operands in temps so we can use them /* Store the expression operands in temps so we can use them
* multiple times. * multiple times.
*/ */
for (i = 0; i < orig_expr->get_num_operands(); i++) { for (i = 0; i < orig_expr->num_operands; i++) {
ir_assignment *assign; ir_assignment *assign;
ir_dereference *deref = orig_expr->operands[i]->as_dereference(); ir_dereference *deref = orig_expr->operands[i]->as_dereference();

View File

@ -627,7 +627,7 @@ lower_ubo_reference_visitor::check_ssbo_unsized_array_length_expression(ir_expre
return; return;
} }
for (unsigned i = 0; i < ir->get_num_operands(); i++) { for (unsigned i = 0; i < ir->num_operands; i++) {
if (ir->operands[i]->ir_type != ir_type_expression) if (ir->operands[i]->ir_type != ir_type_expression)
continue; continue;
ir_expression *expr = (ir_expression *) ir->operands[i]; ir_expression *expr = (ir_expression *) ir->operands[i];

View File

@ -165,7 +165,7 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_expression *ir)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < ir->get_num_operands(); i++) { for (i = 0; i < ir->num_operands; i++) {
ir->operands[i] = convert_vector_extract_to_cond_assign(ir->operands[i]); ir->operands[i] = convert_vector_extract_to_cond_assign(ir->operands[i]);
} }

View File

@ -133,7 +133,7 @@ lower_vector_visitor::handle_rvalue(ir_rvalue **rvalue)
*/ */
void *const mem_ctx = expr; void *const mem_ctx = expr;
assert(expr->type->vector_elements == expr->get_num_operands()); assert(expr->type->vector_elements == expr->num_operands);
/* Generate a temporary with the same type as the ir_quadop_operation. /* Generate a temporary with the same type as the ir_quadop_operation.
*/ */

View File

@ -328,8 +328,8 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
} }
} }
assert(ir->get_num_operands() <= 4); assert(ir->num_operands <= 4);
for (unsigned i = 0; i < ir->get_num_operands(); i++) { for (unsigned i = 0; i < ir->num_operands; i++) {
if (ir->operands[i]->type->is_matrix()) if (ir->operands[i]->type->is_matrix())
return ir; return ir;

View File

@ -74,7 +74,7 @@ ir_constant_fold(ir_rvalue **rvalue)
*/ */
ir_expression *expr = (*rvalue)->as_expression(); ir_expression *expr = (*rvalue)->as_expression();
if (expr) { if (expr) {
for (unsigned int i = 0; i < expr->get_num_operands(); i++) { for (unsigned int i = 0; i < expr->num_operands; i++) {
if (!expr->operands[i]->as_constant()) if (!expr->operands[i]->as_constant())
return false; return false;
} }

View File

@ -232,7 +232,7 @@ ir_tree_grafting_visitor::visit_enter(ir_call *ir)
ir_visitor_status ir_visitor_status
ir_tree_grafting_visitor::visit_enter(ir_expression *ir) ir_tree_grafting_visitor::visit_enter(ir_expression *ir)
{ {
for (unsigned int i = 0; i < ir->get_num_operands(); i++) { for (unsigned int i = 0; i < ir->num_operands; i++) {
if (do_graft(&ir->operands[i])) if (do_graft(&ir->operands[i]))
return visit_stop; return visit_stop;
} }

View File

@ -1004,7 +1004,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
return; return;
} }
for (operand = 0; operand < ir->get_num_operands(); operand++) { for (operand = 0; operand < ir->num_operands; operand++) {
this->result.file = PROGRAM_UNDEFINED; this->result.file = PROGRAM_UNDEFINED;
ir->operands[operand]->accept(this); ir->operands[operand]->accept(this);
if (this->result.file == PROGRAM_UNDEFINED) { if (this->result.file == PROGRAM_UNDEFINED) {
@ -1736,7 +1736,7 @@ ir_to_mesa_visitor::process_move_condition(ir_rvalue *ir)
bool switch_order = false; bool switch_order = false;
ir_expression *const expr = ir->as_expression(); ir_expression *const expr = ir->as_expression();
if ((expr != NULL) && (expr->get_num_operands() == 2)) { if ((expr != NULL) && (expr->num_operands == 2)) {
bool zero_on_left = false; bool zero_on_left = false;
if (expr->operands[0]->is_zero()) { if (expr->operands[0]->is_zero()) {

View File

@ -1575,7 +1575,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
if (ir->operation == ir_quadop_vector) if (ir->operation == ir_quadop_vector)
assert(!"ir_quadop_vector should have been lowered"); assert(!"ir_quadop_vector should have been lowered");
for (unsigned int operand = 0; operand < ir->get_num_operands(); operand++) { for (unsigned int operand = 0; operand < ir->num_operands; operand++) {
this->result.file = PROGRAM_UNDEFINED; this->result.file = PROGRAM_UNDEFINED;
ir->operands[operand]->accept(this); ir->operands[operand]->accept(this);
if (this->result.file == PROGRAM_UNDEFINED) { if (this->result.file == PROGRAM_UNDEFINED) {
@ -2990,7 +2990,7 @@ glsl_to_tgsi_visitor::process_move_condition(ir_rvalue *ir)
ir_expression *const expr = ir->as_expression(); ir_expression *const expr = ir->as_expression();
if (native_integers) { if (native_integers) {
if ((expr != NULL) && (expr->get_num_operands() == 2)) { if ((expr != NULL) && (expr->num_operands == 2)) {
enum glsl_base_type type = expr->operands[0]->type->base_type; enum glsl_base_type type = expr->operands[0]->type->base_type;
if (type == GLSL_TYPE_INT || type == GLSL_TYPE_UINT || if (type == GLSL_TYPE_INT || type == GLSL_TYPE_UINT ||
type == GLSL_TYPE_BOOL) { type == GLSL_TYPE_BOOL) {
@ -3019,7 +3019,7 @@ glsl_to_tgsi_visitor::process_move_condition(ir_rvalue *ir)
return switch_order; return switch_order;
} }
if ((expr != NULL) && (expr->get_num_operands() == 2)) { if ((expr != NULL) && (expr->num_operands == 2)) {
bool zero_on_left = false; bool zero_on_left = false;
if (expr->operands[0]->is_zero()) { if (expr->operands[0]->is_zero()) {