Mesa (master): nir: Use get_once() helper for one-time init's

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 24 21:24:54 UTC 2020


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

Author: Rob Clark <robdclark at chromium.org>
Date:   Mon Nov 23 14:27:28 2020 -0800

nir: Use get_once() helper for one-time init's

Makes the code more concise, and makes helgrind/drd happy at the same
time!

Signed-off-by: Rob Clark <robdclark at chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7644>

---

 src/compiler/nir/nir.h          | 26 +++++---------------------
 src/compiler/nir/nir_validate.c | 12 ++----------
 2 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 9666d232579..a87c5b66c50 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4181,15 +4181,9 @@ 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 = "";
-   }
+   const char *list = get_once(getenv("NIR_SKIP"));
 
-   if (!list[0])
+   if (!list || !list[0])
       return false;
 
    return comma_separated_list_contains(list, name);
@@ -4198,29 +4192,19 @@ should_skip_nir(const char *name)
 static inline bool
 should_clone_nir(void)
 {
-   static int should_clone = -1;
-   if (should_clone < 0)
-      should_clone = env_var_as_boolean("NIR_TEST_CLONE", false);
-
-   return should_clone;
+   return get_once(env_var_as_boolean("NIR_TEST_CLONE", false));
 }
 
 static inline bool
 should_serialize_deserialize_nir(void)
 {
-   static int test_serialize = -1;
-   if (test_serialize < 0)
-      test_serialize = env_var_as_boolean("NIR_TEST_SERIALIZE", false);
-
-   return test_serialize;
+   return get_once(env_var_as_boolean("NIR_TEST_SERIALIZE", false));
 }
 
 static inline bool
 should_print_nir(nir_shader *shader)
 {
-   static int should_print = -1;
-   if (should_print < 0)
-      should_print = env_var_as_unsigned("NIR_PRINT", 0);
+   int should_print = get_once(env_var_as_unsigned("NIR_PRINT", 0));
 
    if (should_print == 1)
       return !shader->info.internal;
diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c
index e8bf1b6c2ce..0809e20596c 100644
--- a/src/compiler/nir/nir_validate.c
+++ b/src/compiler/nir/nir_validate.c
@@ -1531,12 +1531,7 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
    validate_assert(state, state->ssa_srcs->entries == 0);
    _mesa_set_clear(state->ssa_srcs, NULL);
 
-   static int validate_dominance = -1;
-   if (validate_dominance < 0) {
-      validate_dominance =
-         env_var_as_boolean("NIR_VALIDATE_SSA_DOMINANCE", false);
-   }
-   if (validate_dominance)
+   if (get_once(env_var_as_boolean("NIR_VALIDATE_SSA_DOMINANCE", false)))
       validate_ssa_dominance(impl, state);
 }
 
@@ -1610,10 +1605,7 @@ dump_errors(validate_state *state, const char *when)
 void
 nir_validate_shader(nir_shader *shader, const char *when)
 {
-   static int should_validate = -1;
-   if (should_validate < 0)
-      should_validate = env_var_as_boolean("NIR_VALIDATE", true);
-   if (!should_validate)
+   if (!get_once(env_var_as_boolean("NIR_VALIDATE", true)))
       return;
 
    validate_state state;



More information about the mesa-commit mailing list