mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-18 00:48:07 +02:00
Via the Coccinelle patch at the end of the commit message, followed by
sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
ninja -C ~/mesa/build clang-format
cd ~/mesa/src/compiler/nir && clang-format -i *.c
agxfmt
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-return true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
-}
+bool progress = prog_expr;
+return nir_progress(progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
+nir_progress(prog, impl, metadata);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-return true;
+return nir_progress(true, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
+return nir_no_progress(impl);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-other_prog |= prog;
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+nir_progress(prog, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-other_prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-other_prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+nir_progress(impl_progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-prog = true;
+prog = nir_progress(true, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
+nir_progress(prog, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
+nir_no_progress(impl);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
+nir_progress(true, impl, metadata);
squashme! sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33722>
174 lines
4.7 KiB
C
174 lines
4.7 KiB
C
/*
|
|
* Copyright © 2014 Intel Corporation
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice (including the next
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
* Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*
|
|
* Authors:
|
|
* Connor Abbott (cwabbott0@gmail.com)
|
|
*
|
|
*/
|
|
|
|
#include "nir.h"
|
|
#include "nir_builder.h"
|
|
|
|
/**
|
|
* SSA-based copy propagation
|
|
*/
|
|
|
|
static bool
|
|
is_swizzleless_move(nir_alu_instr *instr)
|
|
{
|
|
unsigned num_comp = instr->def.num_components;
|
|
|
|
if (instr->src[0].src.ssa->num_components != num_comp)
|
|
return false;
|
|
|
|
if (instr->op == nir_op_mov) {
|
|
for (unsigned i = 0; i < num_comp; i++) {
|
|
if (instr->src[0].swizzle[i] != i)
|
|
return false;
|
|
}
|
|
} else {
|
|
for (unsigned i = 0; i < num_comp; i++) {
|
|
if (instr->src[i].swizzle[0] != i ||
|
|
instr->src[i].src.ssa != instr->src[0].src.ssa)
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
rewrite_to_vec(nir_alu_instr *mov, nir_alu_instr *vec)
|
|
{
|
|
if (mov->op != nir_op_mov)
|
|
return false;
|
|
|
|
nir_builder b = nir_builder_at(nir_after_instr(&mov->instr));
|
|
|
|
unsigned num_comp = mov->def.num_components;
|
|
nir_alu_instr *new_vec = nir_alu_instr_create(b.shader, nir_op_vec(num_comp));
|
|
for (unsigned i = 0; i < num_comp; i++)
|
|
new_vec->src[i] = vec->src[mov->src[0].swizzle[i]];
|
|
|
|
nir_def *new = nir_builder_alu_instr_finish_and_insert(&b, new_vec);
|
|
nir_def_rewrite_uses(&mov->def, new);
|
|
|
|
/* If we remove "mov" and it's the next instruction in the
|
|
* nir_foreach_instr_safe() loop, then we would end copy-propagation early. */
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
copy_propagate_alu(nir_alu_src *src, nir_alu_instr *copy)
|
|
{
|
|
nir_def *def = NULL;
|
|
nir_alu_instr *user = nir_instr_as_alu(nir_src_parent_instr(&src->src));
|
|
unsigned src_idx = src - user->src;
|
|
assert(src_idx < nir_op_infos[user->op].num_inputs);
|
|
unsigned num_comp = nir_ssa_alu_instr_src_components(user, src_idx);
|
|
|
|
if (copy->op == nir_op_mov) {
|
|
def = copy->src[0].src.ssa;
|
|
|
|
for (unsigned i = 0; i < num_comp; i++)
|
|
src->swizzle[i] = copy->src[0].swizzle[src->swizzle[i]];
|
|
} else {
|
|
def = copy->src[src->swizzle[0]].src.ssa;
|
|
|
|
for (unsigned i = 1; i < num_comp; i++) {
|
|
if (copy->src[src->swizzle[i]].src.ssa != def)
|
|
return rewrite_to_vec(user, copy);
|
|
}
|
|
|
|
for (unsigned i = 0; i < num_comp; i++)
|
|
src->swizzle[i] = copy->src[src->swizzle[i]].swizzle[0];
|
|
}
|
|
|
|
nir_src_rewrite(&src->src, def);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
copy_propagate(nir_src *src, nir_alu_instr *copy)
|
|
{
|
|
if (!is_swizzleless_move(copy))
|
|
return false;
|
|
|
|
nir_src_rewrite(src, copy->src[0].src.ssa);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
copy_prop_instr(nir_instr *instr)
|
|
{
|
|
if (instr->type != nir_instr_type_alu)
|
|
return false;
|
|
|
|
nir_alu_instr *mov = nir_instr_as_alu(instr);
|
|
|
|
if (!nir_op_is_vec_or_mov(mov->op))
|
|
return false;
|
|
|
|
bool progress = false;
|
|
|
|
nir_foreach_use_including_if_safe(src, &mov->def) {
|
|
if (!nir_src_is_if(src) && nir_src_parent_instr(src)->type == nir_instr_type_alu)
|
|
progress |= copy_propagate_alu(container_of(src, nir_alu_src, src), mov);
|
|
else
|
|
progress |= copy_propagate(src, mov);
|
|
}
|
|
|
|
if (progress && nir_def_is_unused(&mov->def))
|
|
nir_instr_remove(&mov->instr);
|
|
|
|
return progress;
|
|
}
|
|
|
|
bool
|
|
nir_copy_prop_impl(nir_function_impl *impl)
|
|
{
|
|
bool progress = false;
|
|
|
|
nir_foreach_block(block, impl) {
|
|
nir_foreach_instr_safe(instr, block) {
|
|
progress |= copy_prop_instr(instr);
|
|
}
|
|
}
|
|
|
|
return nir_progress(progress, impl, nir_metadata_control_flow);
|
|
}
|
|
|
|
bool
|
|
nir_copy_prop(nir_shader *shader)
|
|
{
|
|
bool progress = false;
|
|
|
|
nir_foreach_function_impl(impl, shader) {
|
|
if (nir_copy_prop_impl(impl))
|
|
progress = true;
|
|
}
|
|
|
|
return progress;
|
|
}
|