Mesa (master): nir: check NIR_SKIP to skip passes by name

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 18 20:36:27 UTC 2019


Module: Mesa
Branch: master
Commit: cd56d79b59f367ef0c52d76fc5d37ecc87d0e84b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cd56d79b59f367ef0c52d76fc5d37ecc87d0e84b

Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date:   Thu Jan 17 13:06:04 2019 -0800

nir: check NIR_SKIP to skip passes by name

Passes' function names, separated by comma, listed in NIR_SKIP
environment variable will be skipped in debug mode.  The mechanism is
hooked into the _PASS macro, like NIR_PRINT.

The extra macro NIR_SKIP is available as a developer convenience, to
skip at pointer other than the passes entry points.

v2: Fix typo in NIR_SKIP macro. (Bas)

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

---

 src/compiler/nir/nir.h | 24 ++++++++++++++++++++++++
 src/util/debug.c       | 14 ++++++++++++++
 src/util/debug.h       |  2 ++
 3 files changed, 40 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 7a7e910ba4..d12c499ad7 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2772,6 +2772,23 @@ void nir_metadata_set_validation_flag(nir_shader *shader);
 void nir_metadata_check_validation_flag(nir_shader *shader);
 
 static inline bool
+should_skip_nir(const char *name)
+{
+   static const char *list = NULL;
+   if (!list) {
+      /* Comma separated list of names to skip. */
+      list = getenv("NIR_SKIP");
+      if (!list)
+         list = "";
+   }
+
+   if (!list[0])
+      return false;
+
+   return comma_separated_list_contains(list, name);
+}
+
+static inline bool
 should_clone_nir(void)
 {
    static int should_clone = -1;
@@ -2804,12 +2821,17 @@ should_print_nir(void)
 static inline void nir_validate_shader(nir_shader *shader, const char *when) { (void) shader; (void)when; }
 static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
 static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
+static inline bool should_skip_nir(const char *pass_name) { return false; }
 static inline bool should_clone_nir(void) { return false; }
 static inline bool should_serialize_deserialize_nir(void) { return false; }
 static inline bool should_print_nir(void) { return false; }
 #endif /* NDEBUG */
 
 #define _PASS(pass, nir, do_pass) do {                               \
+   if (should_skip_nir(#pass)) {                                     \
+      printf("skipping %s\n", #pass);                                \
+      break;                                                         \
+   }                                                                 \
    do_pass                                                           \
    nir_validate_shader(nir, "after " #pass);                         \
    if (should_clone_nir()) {                                         \
@@ -2843,6 +2865,8 @@ static inline bool should_print_nir(void) { return false; }
       nir_print_shader(nir, stdout);                                 \
 )
 
+#define NIR_SKIP(name) should_skip_nir(#name)
+
 void nir_calc_dominance_impl(nir_function_impl *impl);
 void nir_calc_dominance(nir_shader *shader);
 
diff --git a/src/util/debug.c b/src/util/debug.c
index 2773b55cc4..09de1a8bbe 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -53,6 +53,20 @@ parse_debug_string(const char *debug,
    return flag;
 }
 
+bool
+comma_separated_list_contains(const char *list, const char *s)
+{
+   assert(list);
+   const size_t len = strlen(s);
+
+   for (unsigned n; n = strcspn(list, ","), *list; list += MAX2(1, n)) {
+      if (n == len && !strncmp(list, s, n))
+         return true;
+   }
+
+   return false;
+}
+
 /**
  * Reads an environment variable and interprets its value as a boolean.
  *
diff --git a/src/util/debug.h b/src/util/debug.h
index 2e34ebe342..bbcc197554 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -40,6 +40,8 @@ uint64_t
 parse_debug_string(const char *debug,
                    const struct debug_control *control);
 bool
+comma_separated_list_contains(const char *list, const char *s);
+bool
 env_var_as_boolean(const char *var_name, bool default_value);
 unsigned
 env_var_as_unsigned(const char *var_name, unsigned default_value);




More information about the mesa-commit mailing list