nir: Remove lower_to_source_mods
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 1 Aug 2023 14:32:24 +0000 (10:32 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Wed, 2 Aug 2023 14:26:45 +0000 (10:26 -0400)
Unused.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24450>

src/compiler/nir/meson.build
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_to_source_mods.c [deleted file]

index 3aa73c4..0d514a7 100644 (file)
@@ -214,7 +214,6 @@ files_libnir = files(
   'nir_lower_tex.c',
   'nir_lower_texcoord_replace.c',
   'nir_lower_texcoord_replace_late.c',
-  'nir_lower_to_source_mods.c',
   'nir_lower_two_sided_color.c',
   'nir_lower_undef_to_zero.c',
   'nir_lower_vars_to_ssa.c',
index dc47e92..4f198dd 100644 (file)
@@ -5846,15 +5846,6 @@ void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *option
 
 bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned offset_align_state);
 
-typedef enum  {
-   nir_lower_fabs_source_mods = 1 << 0,
-   nir_lower_fneg_source_mods = 1 << 1,
-   nir_lower_triop_abs = 1 << 2,
-   nir_lower_all_source_mods = (1 << 3) - 1
-} nir_lower_to_source_mods_flags;
-
-bool nir_lower_to_source_mods(nir_shader *shader, nir_lower_to_source_mods_flags options);
-
 typedef enum {
    nir_lower_gs_intrinsics_per_stream = 1 << 0,
    nir_lower_gs_intrinsics_count_primitives = 1 << 1,
diff --git a/src/compiler/nir/nir_lower_to_source_mods.c b/src/compiler/nir/nir_lower_to_source_mods.c
deleted file mode 100644 (file)
index a41fba3..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.
- */
-
-#include "nir.h"
-#include "nir_builder.h"
-
-/*
- * This pass lowers the neg, abs, and sat operations to source modifiers on
- * ALU operations to make things nicer for the backend.  It's just much
- * easier to not have them when we're doing optimizations.
- */
-
-static void
-alu_src_consume_abs(nir_alu_src *src)
-{
-   src->abs = true;
-}
-
-static void
-alu_src_consume_negate(nir_alu_src *src)
-{
-   /* If abs is set on the source, the negate goes away */
-   if (!src->abs)
-      src->negate = !src->negate;
-}
-
-static bool
-nir_lower_to_source_mods_instr(nir_builder *b, nir_instr *instr,
-                               void *data)
-{
-   nir_lower_to_source_mods_flags options =
-      *((nir_lower_to_source_mods_flags*) data);
-
-   bool progress = false;
-
-   if (instr->type != nir_instr_type_alu)
-      return false;
-
-   nir_alu_instr *alu = nir_instr_as_alu(instr);
-
-   bool lower_abs = (nir_op_infos[alu->op].num_inputs < 3) ||
-         (options & nir_lower_triop_abs);
-
-   for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
-      if (!alu->src[i].src.is_ssa)
-         continue;
-
-      if (alu->src[i].src.ssa->parent_instr->type != nir_instr_type_alu)
-         continue;
-
-      nir_alu_instr *parent = nir_instr_as_alu(alu->src[i].src.ssa->parent_instr);
-
-      if (parent->dest.saturate)
-         continue;
-
-      if (nir_alu_type_get_base_type(nir_op_infos[alu->op].input_types[i]) != nir_type_float)
-         continue;
-
-      if (!(parent->op == nir_op_fabs && (options & nir_lower_fabs_source_mods)) &&
-          !(parent->op == nir_op_fneg && (options & nir_lower_fneg_source_mods))) {
-         continue;
-      }
-
-      if (nir_src_bit_size(alu->src[i].src) == 64)
-         continue;
-
-      /* We can only do a rewrite if the source we are copying is SSA.
-       * Otherwise, moving the read might invalidly reorder reads/writes
-       * on a register.
-       */
-      if (!parent->src[0].src.is_ssa)
-         continue;
-
-      if (!lower_abs && (parent->op == nir_op_fabs || parent->src[0].abs))
-         continue;
-
-      nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src);
-
-      /* Apply any modifiers that come from the parent opcode */
-      if (parent->op == nir_op_fneg)
-         alu_src_consume_negate(&alu->src[i]);
-      if (parent->op == nir_op_fabs)
-         alu_src_consume_abs(&alu->src[i]);
-
-      /* Apply modifiers from the parent source */
-      if (parent->src[0].negate)
-         alu_src_consume_negate(&alu->src[i]);
-      if (parent->src[0].abs)
-         alu_src_consume_abs(&alu->src[i]);
-
-      for (int j = 0; j < 4; ++j) {
-         if (!nir_alu_instr_channel_used(alu, i, j))
-            continue;
-         alu->src[i].swizzle[j] = parent->src[0].swizzle[alu->src[i].swizzle[j]];
-      }
-
-      if (nir_ssa_def_is_unused(&parent->dest.dest.ssa))
-         nir_instr_remove(&parent->instr);
-
-      progress = true;
-   }
-
-   /* We've covered sources.  Now we're going to try and saturate the
-    * destination if we can.
-    */
-
-   if (!alu->dest.dest.is_ssa)
-      return progress;
-
-   if (nir_dest_bit_size(alu->dest.dest) == 64)
-      return progress;
-
-   /* We can only saturate float destinations */
-   if (nir_alu_type_get_base_type(nir_op_infos[alu->op].output_type) !=
-       nir_type_float)
-      return progress;
-
-   bool all_children_are_sat = true;
-   nir_foreach_use_including_if(child_src, &alu->dest.dest.ssa) {
-      if (child_src->is_if) {
-         all_children_are_sat = false;
-         break;
-      }
-  
-      assert(child_src->is_ssa);
-      nir_instr *child = child_src->parent_instr;
-      if (child->type != nir_instr_type_alu) {
-         all_children_are_sat = false;
-         continue;
-      }
-
-      nir_alu_instr *child_alu = nir_instr_as_alu(child);
-      if (child_alu->src[0].negate || child_alu->src[0].abs) {
-         all_children_are_sat = false;
-         continue;
-      }
-
-      if (child_alu->op != nir_op_fsat) {
-         all_children_are_sat = false;
-         continue;
-      }
-   }
-
-   if (!all_children_are_sat)
-      return progress;
-
-   alu->dest.saturate = true;
-   progress = true;
-
-   nir_foreach_use(child_src, &alu->dest.dest.ssa) {
-      assert(child_src->is_ssa);
-      nir_alu_instr *child_alu = nir_instr_as_alu(child_src->parent_instr);
-
-      child_alu->op = nir_op_mov;
-      child_alu->dest.saturate = false;
-      /* We could propagate the dest of our instruction to the
-       * destinations of the uses here.  However, one quick round of
-       * copy propagation will clean that all up and then we don't have
-       * the complexity.
-       */
-   }
-
-   return progress;
-}
-
-bool
-nir_lower_to_source_mods(nir_shader *shader,
-                         nir_lower_to_source_mods_flags options)
-{
-   return nir_shader_instructions_pass(shader,
-                                       nir_lower_to_source_mods_instr,
-                                       nir_metadata_block_index |
-                                       nir_metadata_dominance,
-                                       &options);
-}