From fb630cd783e7c0e10e1c57978251a243095c753c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 14 Jan 2022 18:56:41 -0800 Subject: [PATCH] glsl: Make ir_assignment::condition private And add get_condition(). This proof that nothing remains that could possibly set ::condition to anything other than NULL. v2: Fix bad rebase. Reviewed-by: Matt Turner Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 8 ++++---- src/compiler/glsl/ir.cpp | 4 ++-- src/compiler/glsl/ir.h | 13 ++++++++++++- src/compiler/glsl/ir_builder_print_visitor.cpp | 4 ++-- src/compiler/glsl/ir_clone.cpp | 2 +- src/compiler/glsl/ir_constant_expression.cpp | 4 ++-- src/compiler/glsl/ir_hv_accept.cpp | 4 ++-- src/compiler/glsl/ir_print_visitor.cpp | 4 ++-- src/compiler/glsl/loop_analysis.cpp | 6 +++--- src/compiler/glsl/lower_if_to_cond_assign.cpp | 2 +- .../glsl/lower_variable_index_to_cond_assign.cpp | 4 ++-- src/compiler/glsl/opt_array_splitting.cpp | 2 +- src/compiler/glsl/opt_constant_propagation.cpp | 2 +- src/compiler/glsl/opt_constant_variable.cpp | 2 +- src/compiler/glsl/opt_copy_propagation_elements.cpp | 2 +- src/compiler/glsl/opt_dead_code_local.cpp | 8 ++++---- src/compiler/glsl/opt_structure_splitting.cpp | 4 ++-- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 4 ++-- 18 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index c011db2171b..8885f37d8a7 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -1718,8 +1718,8 @@ nir_visitor::visit(ir_assignment *ir) nir_deref_instr *rhs = evaluate_deref(ir->rhs); enum gl_access_qualifier lhs_qualifiers = deref_get_qualifier(lhs); enum gl_access_qualifier rhs_qualifiers = deref_get_qualifier(rhs); - if (ir->condition) { - nir_push_if(&b, evaluate_rvalue(ir->condition)); + if (ir->get_condition()) { + nir_push_if(&b, evaluate_rvalue(ir->get_condition())); nir_copy_deref_with_access(&b, lhs, rhs, lhs_qualifiers, rhs_qualifiers); nir_pop_if(&b, NULL); @@ -1763,8 +1763,8 @@ nir_visitor::visit(ir_assignment *ir) } enum gl_access_qualifier qualifiers = deref_get_qualifier(lhs_deref); - if (ir->condition) { - nir_push_if(&b, evaluate_rvalue(ir->condition)); + if (ir->get_condition()) { + nir_push_if(&b, evaluate_rvalue(ir->get_condition())); nir_store_deref_with_access(&b, lhs_deref, src, write_mask, qualifiers); nir_pop_if(&b, NULL); diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp index c8cb1ee249b..da44984cfca 100644 --- a/src/compiler/glsl/ir.cpp +++ b/src/compiler/glsl/ir.cpp @@ -153,7 +153,7 @@ ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, unsigned write_mask) : ir_instruction(ir_type_assignment) { - this->condition = NULL; + this->unused_condition = NULL; this->rhs = rhs; this->lhs = lhs; this->write_mask = write_mask; @@ -165,7 +165,7 @@ ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs) : ir_instruction(ir_type_assignment) { - this->condition = NULL; + this->unused_condition = NULL; this->rhs = rhs; /* If the RHS is a vector type, assume that all components of the vector diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index 4ec62db8074..7420cf47c5f 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -1521,8 +1521,19 @@ public: /** * Optional condition for the assignment. */ - ir_rvalue *condition; +private: + ir_rvalue *unused_condition; +public: + inline ir_rvalue *get_condition() + { + return unused_condition; + } + + inline const ir_rvalue *get_condition() const + { + return unused_condition; + } /** * Component mask written diff --git a/src/compiler/glsl/ir_builder_print_visitor.cpp b/src/compiler/glsl/ir_builder_print_visitor.cpp index 5ab50a58415..3f1cfd67cdc 100644 --- a/src/compiler/glsl/ir_builder_print_visitor.cpp +++ b/src/compiler/glsl/ir_builder_print_visitor.cpp @@ -507,7 +507,7 @@ ir_builder_print_visitor::visit_enter(ir_assignment *ir) if (s != visit_continue) return (s == visit_continue_with_parent) ? visit_continue : s; - assert(ir->condition == NULL); + assert(ir->get_condition() == NULL); const struct hash_entry *const he_lhs = _mesa_hash_table_search(index_map, ir->lhs); @@ -529,7 +529,7 @@ ir_builder_print_visitor::visit_leave(ir_assignment *ir) const struct hash_entry *const he_rhs = _mesa_hash_table_search(index_map, ir->rhs); - assert(ir->condition == NULL); + assert(ir->get_condition() == NULL); assert(ir->lhs && ir->rhs); print_with_indent("body.emit(assign(r%04X, r%04X, 0x%02x));\n\n", diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp index bc5c25e0e47..d09c424283c 100644 --- a/src/compiler/glsl/ir_clone.cpp +++ b/src/compiler/glsl/ir_clone.cpp @@ -259,7 +259,7 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const ir_assignment * ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const { - assert(this->condition == NULL); + assert(this->get_condition() == NULL); return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), this->rhs->clone(mem_ctx, ht), diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp index 1f2f786e2f0..4196ef10885 100644 --- a/src/compiler/glsl/ir_constant_expression.cpp +++ b/src/compiler/glsl/ir_constant_expression.cpp @@ -1070,9 +1070,9 @@ bool ir_function_signature::constant_expression_evaluate_expression_list(void *m /* (assign [condition] (write-mask) (ref) (value)) */ case ir_type_assignment: { ir_assignment *asg = inst->as_assignment(); - if (asg->condition) { + if (asg->get_condition()) { ir_constant *cond = - asg->condition->constant_expression_value(mem_ctx, + asg->get_condition()->constant_expression_value(mem_ctx, variable_context); if (!cond) return false; diff --git a/src/compiler/glsl/ir_hv_accept.cpp b/src/compiler/glsl/ir_hv_accept.cpp index 93eda6783e0..03489b3f3da 100644 --- a/src/compiler/glsl/ir_hv_accept.cpp +++ b/src/compiler/glsl/ir_hv_accept.cpp @@ -312,8 +312,8 @@ ir_assignment::accept(ir_hierarchical_visitor *v) if (s != visit_continue) return (s == visit_continue_with_parent) ? visit_continue : s; - if (this->condition) - s = this->condition->accept(v); + if (this->get_condition()) + s = this->get_condition()->accept(v); return (s == visit_stop) ? s : v->visit_leave(this); } diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp index 8e7204f9715..ea07c22730a 100644 --- a/src/compiler/glsl/ir_print_visitor.cpp +++ b/src/compiler/glsl/ir_print_visitor.cpp @@ -444,8 +444,8 @@ void ir_print_visitor::visit(ir_assignment *ir) { fprintf(f, "(assign "); - if (ir->condition) - ir->condition->accept(this); + if (ir->get_condition()) + ir->get_condition()->accept(this); char mask[5]; unsigned j = 0; diff --git a/src/compiler/glsl/loop_analysis.cpp b/src/compiler/glsl/loop_analysis.cpp index 37cc2ae4e1a..0fc7bcc067d 100644 --- a/src/compiler/glsl/loop_analysis.cpp +++ b/src/compiler/glsl/loop_analysis.cpp @@ -71,7 +71,7 @@ find_initial_value(ir_loop *loop, ir_variable *var) ir_variable *assignee = assign->lhs->whole_variable_referenced(); if (assignee == var) - return (assign->condition != NULL) ? NULL : assign->rhs; + return (assign->get_condition() != NULL) ? NULL : assign->rhs; break; } @@ -241,7 +241,7 @@ incremented_before_terminator(ir_loop *loop, ir_variable *var, ir_variable *assignee = assign->lhs->whole_variable_referenced(); if (assignee == var) { - assert(assign->condition == NULL); + assert(assign->get_condition() == NULL); return true; } @@ -276,7 +276,7 @@ loop_variable::record_reference(bool in_assignee, assert(current_assignment != NULL); if (in_conditional_code_or_nested_loop || - current_assignment->condition != NULL) { + current_assignment->get_condition() != NULL) { this->conditional_or_nested_assignment = true; } diff --git a/src/compiler/glsl/lower_if_to_cond_assign.cpp b/src/compiler/glsl/lower_if_to_cond_assign.cpp index 3ff44ee1c87..e21517353f0 100644 --- a/src/compiler/glsl/lower_if_to_cond_assign.cpp +++ b/src/compiler/glsl/lower_if_to_cond_assign.cpp @@ -193,7 +193,7 @@ move_block_to_cond_assign(void *mem_ctx, _mesa_set_search( set, assign->lhs->variable_referenced()) != NULL; - if (!assign->condition) { + if (!assign->get_condition()) { if (assign_to_cv) { assign->rhs = new(mem_ctx) ir_expression(ir_binop_logic_and, diff --git a/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp b/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp index 1c5076076ce..d91cd22cb96 100644 --- a/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp +++ b/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp @@ -385,11 +385,11 @@ public: * condition! This is acomplished by wrapping the new conditional * assignments in an if-statement that uses the original condition. */ - if (orig_assign != NULL && orig_assign->condition != NULL) { + if (orig_assign != NULL && orig_assign->get_condition() != NULL) { /* No need to clone the condition because the IR that it hangs on is * going to be removed from the instruction sequence. */ - ir_if *if_stmt = new(mem_ctx) ir_if(orig_assign->condition); + ir_if *if_stmt = new(mem_ctx) ir_if(orig_assign->get_condition()); ir_factory then_body(&if_stmt->then_instructions, body.mem_ctx); sg.generate(0, length, then_body); diff --git a/src/compiler/glsl/opt_array_splitting.cpp b/src/compiler/glsl/opt_array_splitting.cpp index 63b1a01290c..8af1f9b626c 100644 --- a/src/compiler/glsl/opt_array_splitting.cpp +++ b/src/compiler/glsl/opt_array_splitting.cpp @@ -416,7 +416,7 @@ ir_array_splitting_visitor::visit_leave(ir_assignment *ir) new(mem_ctx) ir_dereference_array(ir->rhs->clone(mem_ctx, NULL), new(mem_ctx) ir_constant(i)); - assert(ir->condition == NULL); + assert(ir->get_condition() == NULL); ir_assignment *assign_i = new(mem_ctx) ir_assignment(lhs_i, rhs_i); diff --git a/src/compiler/glsl/opt_constant_propagation.cpp b/src/compiler/glsl/opt_constant_propagation.cpp index 1e598b70df4..cec2b5d1aa8 100644 --- a/src/compiler/glsl/opt_constant_propagation.cpp +++ b/src/compiler/glsl/opt_constant_propagation.cpp @@ -486,7 +486,7 @@ ir_constant_propagation_visitor::add_constant(ir_assignment *ir) { acp_entry *entry; - if (ir->condition) + if (ir->get_condition()) return; if (!ir->write_mask) diff --git a/src/compiler/glsl/opt_constant_variable.cpp b/src/compiler/glsl/opt_constant_variable.cpp index 3f2b6a04b9f..dccbd429285 100644 --- a/src/compiler/glsl/opt_constant_variable.cpp +++ b/src/compiler/glsl/opt_constant_variable.cpp @@ -119,7 +119,7 @@ ir_constant_variable_visitor::visit_enter(ir_assignment *ir) /* OK, now find if we actually have all the right conditions for * this to be a constant value assigned to the var. */ - if (ir->condition) + if (ir->get_condition()) return visit_continue; ir_variable *var = ir->whole_variable_written(); diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp b/src/compiler/glsl/opt_copy_propagation_elements.cpp index 081909903e5..73f21ace8e9 100644 --- a/src/compiler/glsl/opt_copy_propagation_elements.cpp +++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp @@ -654,7 +654,7 @@ ir_copy_propagation_elements_visitor::kill(kill_entry *k) void ir_copy_propagation_elements_visitor::add_copy(ir_assignment *ir) { - if (ir->condition) + if (ir->get_condition()) return; { diff --git a/src/compiler/glsl/opt_dead_code_local.cpp b/src/compiler/glsl/opt_dead_code_local.cpp index b2d35bbaff8..0ef79acf86b 100644 --- a/src/compiler/glsl/opt_dead_code_local.cpp +++ b/src/compiler/glsl/opt_dead_code_local.cpp @@ -175,7 +175,7 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) bool progress = false; kill_for_derefs_visitor v(assignments); - if (ir->condition == NULL) { + if (ir->get_condition() == NULL) { /* If this is an assignment of the form "foo = foo;", remove the whole * instruction and be done with it. */ @@ -188,8 +188,8 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) /* Kill assignment entries for things used to produce this assignment. */ ir->rhs->accept(&v); - if (ir->condition) { - ir->condition->accept(&v); + if (ir->get_condition()) { + ir->get_condition()->accept(&v); } /* Kill assignment enties used as array indices. @@ -199,7 +199,7 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) assert(var); /* Now, check if we did a whole-variable assignment. */ - if (!ir->condition) { + if (!ir->get_condition()) { ir_dereference_variable *deref_var = ir->lhs->as_dereference_variable(); /* If it's a vector type, we can do per-channel elimination of diff --git a/src/compiler/glsl/opt_structure_splitting.cpp b/src/compiler/glsl/opt_structure_splitting.cpp index 89e08f0b062..ae2e5b92e77 100644 --- a/src/compiler/glsl/opt_structure_splitting.cpp +++ b/src/compiler/glsl/opt_structure_splitting.cpp @@ -161,7 +161,7 @@ ir_structure_reference_visitor::visit_enter(ir_assignment *ir) if (ir->lhs->as_dereference_variable() && ir->rhs->as_dereference_variable() && - !ir->condition) { + !ir->get_condition()) { /* We'll split copies of a structure to copies of components, so don't * descend to the ir_dereference_variables. */ @@ -264,7 +264,7 @@ ir_structure_splitting_visitor::visit_leave(ir_assignment *ir) variable_entry *rhs_entry = rhs_deref ? get_splitting_entry(rhs_deref->var) : NULL; const glsl_type *type = ir->rhs->type; - if ((lhs_entry || rhs_entry) && !ir->condition) { + if ((lhs_entry || rhs_entry) && !ir->get_condition()) { for (unsigned int i = 0; i < type->length; i++) { ir_dereference *new_lhs, *new_rhs; void *mem_ctx = lhs_entry ? lhs_entry->mem_ctx : rhs_entry->mem_ctx; diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index ab794bf65b0..980e00eb0be 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -3387,8 +3387,8 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir) assert(l.file != PROGRAM_UNDEFINED); assert(r.file != PROGRAM_UNDEFINED); - if (ir->condition) { - const bool switch_order = this->process_move_condition(ir->condition); + if (ir->get_condition()) { + const bool switch_order = this->process_move_condition(ir->get_condition()); st_src_reg condition = this->result; emit_block_mov(ir, ir->lhs->type, &l, &r, &condition, switch_order);