From 912299cb3992d44b2d75e48b3273fcf9c0dbd77c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 14 Jan 2022 19:10:04 -0800 Subject: [PATCH] glsl: Eliminate ir_assignment::condition Reformatting is left for the next commit. v2: Remove assignments from the contructors. :face_palm: Reviewed-by: Matt Turner Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 19 +++---------------- src/compiler/glsl/ir.cpp | 2 -- src/compiler/glsl/ir.h | 17 ----------------- .../glsl/ir_builder_print_visitor.cpp | 3 --- src/compiler/glsl/ir_clone.cpp | 2 -- src/compiler/glsl/ir_constant_expression.cpp | 10 ---------- src/compiler/glsl/ir_hv_accept.cpp | 3 --- src/compiler/glsl/ir_print_visitor.cpp | 3 --- src/compiler/glsl/loop_analysis.cpp | 6 ++---- src/compiler/glsl/lower_if_to_cond_assign.cpp | 8 -------- .../lower_variable_index_to_cond_assign.cpp | 17 +---------------- src/compiler/glsl/opt_array_splitting.cpp | 2 -- .../glsl/opt_constant_propagation.cpp | 3 --- src/compiler/glsl/opt_constant_variable.cpp | 6 ------ .../glsl/opt_copy_propagation_elements.cpp | 3 --- src/compiler/glsl/opt_dead_code_local.cpp | 7 ------- src/compiler/glsl/opt_structure_splitting.cpp | 5 ++--- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 7 +------ 18 files changed, 9 insertions(+), 114 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 8885f37d8a7..180b2c115e7 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -1718,15 +1718,9 @@ 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->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); - } else { - nir_copy_deref_with_access(&b, lhs, rhs, lhs_qualifiers, - rhs_qualifiers); - } + + nir_copy_deref_with_access(&b, lhs, rhs, lhs_qualifiers, + rhs_qualifiers); return; } @@ -1763,15 +1757,8 @@ nir_visitor::visit(ir_assignment *ir) } enum gl_access_qualifier qualifiers = deref_get_qualifier(lhs_deref); - 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); - } else { - nir_store_deref_with_access(&b, lhs_deref, src, write_mask, - qualifiers); - } } /* diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp index da44984cfca..de8e82ad0d3 100644 --- a/src/compiler/glsl/ir.cpp +++ b/src/compiler/glsl/ir.cpp @@ -153,7 +153,6 @@ ir_assignment::ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, unsigned write_mask) : ir_instruction(ir_type_assignment) { - this->unused_condition = NULL; this->rhs = rhs; this->lhs = lhs; this->write_mask = write_mask; @@ -165,7 +164,6 @@ 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->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 7420cf47c5f..672f96794b2 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -1518,23 +1518,6 @@ public: */ ir_rvalue *rhs; - /** - * Optional condition for the assignment. - */ -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 3f1cfd67cdc..ba63d523a84 100644 --- a/src/compiler/glsl/ir_builder_print_visitor.cpp +++ b/src/compiler/glsl/ir_builder_print_visitor.cpp @@ -507,8 +507,6 @@ ir_builder_print_visitor::visit_enter(ir_assignment *ir) if (s != visit_continue) return (s == visit_continue_with_parent) ? visit_continue : s; - assert(ir->get_condition() == NULL); - const struct hash_entry *const he_lhs = _mesa_hash_table_search(index_map, ir->lhs); @@ -529,7 +527,6 @@ 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->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 d09c424283c..877db52c8bf 100644 --- a/src/compiler/glsl/ir_clone.cpp +++ b/src/compiler/glsl/ir_clone.cpp @@ -259,8 +259,6 @@ 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->get_condition() == NULL); - return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), this->rhs->clone(mem_ctx, ht), this->write_mask); diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp index 4196ef10885..fc876f7f543 100644 --- a/src/compiler/glsl/ir_constant_expression.cpp +++ b/src/compiler/glsl/ir_constant_expression.cpp @@ -1070,16 +1070,6 @@ 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->get_condition()) { - ir_constant *cond = - asg->get_condition()->constant_expression_value(mem_ctx, - variable_context); - if (!cond) - return false; - if (!cond->get_bool_component(0)) - break; - } - ir_constant *store = NULL; int offset = 0; diff --git a/src/compiler/glsl/ir_hv_accept.cpp b/src/compiler/glsl/ir_hv_accept.cpp index 03489b3f3da..e47adf282de 100644 --- a/src/compiler/glsl/ir_hv_accept.cpp +++ b/src/compiler/glsl/ir_hv_accept.cpp @@ -312,9 +312,6 @@ ir_assignment::accept(ir_hierarchical_visitor *v) if (s != visit_continue) return (s == visit_continue_with_parent) ? visit_continue : s; - 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 ea07c22730a..0b510519e4c 100644 --- a/src/compiler/glsl/ir_print_visitor.cpp +++ b/src/compiler/glsl/ir_print_visitor.cpp @@ -444,9 +444,6 @@ void ir_print_visitor::visit(ir_assignment *ir) { fprintf(f, "(assign "); - 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 0fc7bcc067d..c8db6f63b38 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->get_condition() != NULL) ? NULL : assign->rhs; + return assign->rhs; break; } @@ -241,7 +241,6 @@ incremented_before_terminator(ir_loop *loop, ir_variable *var, ir_variable *assignee = assign->lhs->whole_variable_referenced(); if (assignee == var) { - assert(assign->get_condition() == NULL); return true; } @@ -275,8 +274,7 @@ loop_variable::record_reference(bool in_assignee, if (in_assignee) { assert(current_assignment != NULL); - if (in_conditional_code_or_nested_loop || - current_assignment->get_condition() != NULL) { + if (in_conditional_code_or_nested_loop) { 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 e21517353f0..ad6f03901c4 100644 --- a/src/compiler/glsl/lower_if_to_cond_assign.cpp +++ b/src/compiler/glsl/lower_if_to_cond_assign.cpp @@ -193,7 +193,6 @@ move_block_to_cond_assign(void *mem_ctx, _mesa_set_search( set, assign->lhs->variable_referenced()) != NULL; - if (!assign->get_condition()) { if (assign_to_cv) { assign->rhs = new(mem_ctx) ir_expression(ir_binop_logic_and, @@ -207,13 +206,6 @@ move_block_to_cond_assign(void *mem_ctx, assign->rhs, assign->lhs->as_dereference()); } - } else { - assign->rhs = - new(mem_ctx) ir_expression(ir_triop_csel, - cond_expr->clone(mem_ctx, NULL), - assign->rhs, - assign->lhs->as_dereference()); - } } } 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 d91cd22cb96..4e7761e756b 100644 --- a/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp +++ b/src/compiler/glsl/lower_variable_index_to_cond_assign.cpp @@ -381,22 +381,7 @@ public: switch_generator sg(ag, index); - /* If the original assignment has a condition, respect that original - * 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->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->get_condition()); - ir_factory then_body(&if_stmt->then_instructions, body.mem_ctx); - - sg.generate(0, length, then_body); - body.emit(if_stmt); - } else { - sg.generate(0, length, body); - } + sg.generate(0, length, body); base_ir->insert_before(&list); return var; diff --git a/src/compiler/glsl/opt_array_splitting.cpp b/src/compiler/glsl/opt_array_splitting.cpp index 8af1f9b626c..1d9212b011d 100644 --- a/src/compiler/glsl/opt_array_splitting.cpp +++ b/src/compiler/glsl/opt_array_splitting.cpp @@ -416,8 +416,6 @@ 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->get_condition() == NULL); - ir_assignment *assign_i = new(mem_ctx) ir_assignment(lhs_i, rhs_i); ir->insert_before(assign_i); diff --git a/src/compiler/glsl/opt_constant_propagation.cpp b/src/compiler/glsl/opt_constant_propagation.cpp index cec2b5d1aa8..755b5ac4e4a 100644 --- a/src/compiler/glsl/opt_constant_propagation.cpp +++ b/src/compiler/glsl/opt_constant_propagation.cpp @@ -486,9 +486,6 @@ ir_constant_propagation_visitor::add_constant(ir_assignment *ir) { acp_entry *entry; - if (ir->get_condition()) - return; - if (!ir->write_mask) return; diff --git a/src/compiler/glsl/opt_constant_variable.cpp b/src/compiler/glsl/opt_constant_variable.cpp index dccbd429285..bbde9229950 100644 --- a/src/compiler/glsl/opt_constant_variable.cpp +++ b/src/compiler/glsl/opt_constant_variable.cpp @@ -116,12 +116,6 @@ ir_constant_variable_visitor::visit_enter(ir_assignment *ir) if (entry->var->constant_value) return visit_continue; - /* OK, now find if we actually have all the right conditions for - * this to be a constant value assigned to the var. - */ - if (ir->get_condition()) - return visit_continue; - ir_variable *var = ir->whole_variable_written(); if (!var) return visit_continue; diff --git a/src/compiler/glsl/opt_copy_propagation_elements.cpp b/src/compiler/glsl/opt_copy_propagation_elements.cpp index 73f21ace8e9..77f7070dd3b 100644 --- a/src/compiler/glsl/opt_copy_propagation_elements.cpp +++ b/src/compiler/glsl/opt_copy_propagation_elements.cpp @@ -654,9 +654,6 @@ ir_copy_propagation_elements_visitor::kill(kill_entry *k) void ir_copy_propagation_elements_visitor::add_copy(ir_assignment *ir) { - if (ir->get_condition()) - return; - { ir_variable *lhs_var = ir->whole_variable_written(); ir_dereference_variable *rhs = ir->rhs->as_dereference_variable(); diff --git a/src/compiler/glsl/opt_dead_code_local.cpp b/src/compiler/glsl/opt_dead_code_local.cpp index 0ef79acf86b..746c6d5f76d 100644 --- a/src/compiler/glsl/opt_dead_code_local.cpp +++ b/src/compiler/glsl/opt_dead_code_local.cpp @@ -175,7 +175,6 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) bool progress = false; kill_for_derefs_visitor v(assignments); - if (ir->get_condition() == NULL) { /* If this is an assignment of the form "foo = foo;", remove the whole * instruction and be done with it. */ @@ -184,13 +183,9 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) ir->remove(); return true; } - } /* Kill assignment entries for things used to produce this assignment. */ ir->rhs->accept(&v); - if (ir->get_condition()) { - ir->get_condition()->accept(&v); - } /* Kill assignment enties used as array indices. */ @@ -199,7 +194,6 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) assert(var); /* Now, check if we did a whole-variable assignment. */ - 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 @@ -287,7 +281,6 @@ process_assignment(void *lin_ctx, ir_assignment *ir, exec_list *assignments) } } } - } /* Add this instruction to the assignment list available to be removed. */ assignment_entry *entry = new(lin_ctx) assignment_entry(var, ir); diff --git a/src/compiler/glsl/opt_structure_splitting.cpp b/src/compiler/glsl/opt_structure_splitting.cpp index ae2e5b92e77..223d28820ce 100644 --- a/src/compiler/glsl/opt_structure_splitting.cpp +++ b/src/compiler/glsl/opt_structure_splitting.cpp @@ -160,8 +160,7 @@ ir_structure_reference_visitor::visit_enter(ir_assignment *ir) return visit_continue_with_parent; if (ir->lhs->as_dereference_variable() && - ir->rhs->as_dereference_variable() && - !ir->get_condition()) { + ir->rhs->as_dereference_variable()) { /* We'll split copies of a structure to copies of components, so don't * descend to the ir_dereference_variables. */ @@ -264,7 +263,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->get_condition()) { + if (lhs_entry || rhs_entry) { 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 980e00eb0be..8291a13d008 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -3387,12 +3387,7 @@ glsl_to_tgsi_visitor::visit(ir_assignment *ir) assert(l.file != PROGRAM_UNDEFINED); assert(r.file != PROGRAM_UNDEFINED); - 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); - } else if (ir->rhs->as_expression() && + if (ir->rhs->as_expression() && this->instructions.get_tail() && ir->rhs == ((glsl_to_tgsi_instruction *)this->instructions.get_tail())->ir && !((glsl_to_tgsi_instruction *)this->instructions.get_tail())->is_64bit_expanded &&