nir: Add a helper to determine if an intrinsic can be reordered
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 4 Jun 2019 11:02:31 +0000 (13:02 +0200)
committerConnor Abbott <cwabbott0@gmail.com>
Wed, 19 Jun 2019 12:08:28 +0000 (14:08 +0200)
This is simple now, but we're going to be adding a few more conditions
to this later.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/nir/nir.h
src/compiler/nir/nir_instr_set.c
src/compiler/nir/nir_opt_gcm.c

index 3977e75dc4b2ce6c893804566ee2611d807ef48a..bbe3fed70ddf185ed3fcf56ae7129c8b7949e681 100644 (file)
@@ -1455,6 +1455,16 @@ nir_intrinsic_align(const nir_intrinsic_instr *intrin)
 void nir_rewrite_image_intrinsic(nir_intrinsic_instr *instr,
                                  nir_ssa_def *handle, bool bindless);
 
+/* Determine if an intrinsic can be arbitrarily reordered and eliminated. */
+static inline bool
+nir_intrinsic_can_reorder(nir_intrinsic_instr *instr)
+{
+   const nir_intrinsic_info *info =
+      &nir_intrinsic_infos[instr->intrinsic];
+   return (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
+          (info->flags & NIR_INTRINSIC_CAN_REORDER);
+}
+
 /**
  * \group texture information
  *
index 1a6a7ab7743901a240042b82c9910d2a1fe02418..7707b83f4892a58665a33ee51bd12aae35c18c8f 100644 (file)
@@ -756,12 +756,8 @@ instr_can_rewrite(nir_instr *instr)
    case nir_instr_type_load_const:
    case nir_instr_type_phi:
       return true;
-   case nir_instr_type_intrinsic: {
-      const nir_intrinsic_info *info =
-         &nir_intrinsic_infos[nir_instr_as_intrinsic(instr)->intrinsic];
-      return (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
-             (info->flags & NIR_INTRINSIC_CAN_REORDER);
-   }
+   case nir_instr_type_intrinsic:
+      return nir_intrinsic_can_reorder(nir_instr_as_intrinsic(instr));
    case nir_instr_type_call:
    case nir_instr_type_jump:
    case nir_instr_type_ssa_undef:
index e7d3f8ec424fa352b716382caa1685fd72b820d7..aeae2ad6401074146cbc4c1285706e6cad657425 100644 (file)
@@ -152,11 +152,7 @@ gcm_pin_instructions_block(nir_block *block, struct gcm_state *state)
          break;
 
       case nir_instr_type_intrinsic: {
-         const nir_intrinsic_info *info =
-            &nir_intrinsic_infos[nir_instr_as_intrinsic(instr)->intrinsic];
-
-         if ((info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
-             (info->flags & NIR_INTRINSIC_CAN_REORDER)) {
+         if (nir_intrinsic_can_reorder(nir_instr_as_intrinsic(instr))) {
             instr->pass_flags = 0;
          } else {
             instr->pass_flags = GCM_INSTR_PINNED;