nir: Return progress from nir_lower_doubles().
authorMatt Turner <mattst88@gmail.com>
Fri, 24 Feb 2017 23:27:07 +0000 (15:27 -0800)
committerMatt Turner <mattst88@gmail.com>
Thu, 23 Mar 2017 21:34:43 +0000 (14:34 -0700)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_double_ops.c

index 910352dba077883406ca35ed523640651d36e8c6..1b9e17fe89d1e75df2455987237eb95c95bb622b 100644 (file)
@@ -2567,7 +2567,7 @@ typedef enum {
    nir_lower_dmod = (1 << 8)
 } nir_lower_doubles_options;
 
-void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
+bool nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
 void nir_lower_64bit_pack(nir_shader *shader);
 
 bool nir_normalize_cubemap_coords(nir_shader *shader);
index 00eeb89b1bdc056ae2e38bf21e097d9304dc5e98..b3543bc6963ee4c2161a72aa72db1af2e4bfcd9e 100644 (file)
@@ -456,61 +456,61 @@ lower_mod(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1)
                     nir_imm_double(b, 0.0));
 }
 
-static void
+static bool
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 {
    assert(instr->dest.dest.is_ssa);
    if (instr->dest.dest.ssa.bit_size != 64)
-      return;
+      return false;
 
    switch (instr->op) {
    case nir_op_frcp:
       if (!(options & nir_lower_drcp))
-         return;
+         return false;
       break;
 
    case nir_op_fsqrt:
       if (!(options & nir_lower_dsqrt))
-         return;
+         return false;
       break;
 
    case nir_op_frsq:
       if (!(options & nir_lower_drsq))
-         return;
+         return false;
       break;
 
    case nir_op_ftrunc:
       if (!(options & nir_lower_dtrunc))
-         return;
+         return false;
       break;
 
    case nir_op_ffloor:
       if (!(options & nir_lower_dfloor))
-         return;
+         return false;
       break;
 
    case nir_op_fceil:
       if (!(options & nir_lower_dceil))
-         return;
+         return false;
       break;
 
    case nir_op_ffract:
       if (!(options & nir_lower_dfract))
-         return;
+         return false;
       break;
 
    case nir_op_fround_even:
       if (!(options & nir_lower_dround_even))
-         return;
+         return false;
       break;
 
    case nir_op_fmod:
       if (!(options & nir_lower_dmod))
-         return;
+         return false;
       break;
 
    default:
-      return;
+      return false;
    }
 
    nir_builder bld;
@@ -560,20 +560,40 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 
    nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(result));
    nir_instr_remove(&instr->instr);
+   return true;
 }
 
-void
+static bool
+nir_lower_doubles_impl(nir_function_impl *impl,
+                       nir_lower_doubles_options options)
+{
+   bool progress = false;
+
+   nir_foreach_block(block, impl) {
+      nir_foreach_instr_safe(instr, block) {
+         if (instr->type == nir_instr_type_alu)
+            progress |= lower_doubles_instr(nir_instr_as_alu(instr),
+                                            options);
+      }
+   }
+
+   if (progress)
+      nir_metadata_preserve(impl, nir_metadata_block_index |
+                                  nir_metadata_dominance);
+
+   return progress;
+}
+
+bool
 nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options)
 {
+   bool progress = false;
+
    nir_foreach_function(function, shader) {
-      if (!function->impl)
-         continue;
-
-      nir_foreach_block(block, function->impl) {
-         nir_foreach_instr_safe(instr, block) {
-            if (instr->type == nir_instr_type_alu)
-               lower_doubles_instr(nir_instr_as_alu(instr), options);
-         }
+      if (function->impl) {
+         progress |= nir_lower_doubles_impl(function->impl, options);
       }
    }
+
+   return progress;
 }