Mesa (main): nir/print: print const value near each use of const ssa variable
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Dec 17 10:40:06 UTC 2021
Module: Mesa
Branch: main
Commit: 504e5cb4e893d8603c1ffde510df1f260f72e798
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=504e5cb4e893d8603c1ffde510df1f260f72e798
Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date: Fri Nov 19 15:47:56 2021 +0100
nir/print: print const value near each use of const ssa variable
Without/with NIR_DEBUG=print,print_const:
-vec4 32 ssa_60 = fadd ssa_59, ssa_58
+vec4 32 ssa_60 = fadd ssa_59 /*(0xbf800000, 0x3e800000, 0x00000000, 0x3f800000) = (-1.000000, 0.250000, 0.000000, 1.000000)*/, ssa_58
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>
---
src/compiler/nir/nir.c | 2 ++
src/compiler/nir/nir.h | 1 +
src/compiler/nir/nir_print.c | 26 +++++++++++++++++++++-----
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 8dc0f54fb81..d02f3d28da8 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -85,6 +85,8 @@ static const struct debug_named_value nir_debug_control[] = {
"Dump resulting callable shader after each successful lowering/optimization call" },
{ "print_ks", NIR_DEBUG_PRINT_KS,
"Dump resulting kernel shader after each successful lowering/optimization call" },
+ { "print_consts", NIR_DEBUG_PRINT_CONSTS,
+ "Print const value near each use of const SSA variable" },
{ NULL }
};
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index f0bd76ab247..f3aba96a0c7 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -91,6 +91,7 @@ extern bool nir_debug_print_shader[MESA_SHADER_KERNEL + 1];
#define NIR_DEBUG_PRINT_IS (1u << 17)
#define NIR_DEBUG_PRINT_CBS (1u << 18)
#define NIR_DEBUG_PRINT_KS (1u << 19)
+#define NIR_DEBUG_PRINT_CONSTS (1u << 20)
#define NIR_DEBUG_PRINT (NIR_DEBUG_PRINT_VS | \
NIR_DEBUG_PRINT_TCS | \
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index f06ea2a8141..c96536b6129 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -111,20 +111,18 @@ print_ssa_def(nir_ssa_def *def, print_state *state)
}
static void
-print_load_const_instr(nir_load_const_instr *instr, print_state *state)
+print_const_from_load(nir_load_const_instr *instr, print_state *state)
{
FILE *fp = state->fp;
- print_ssa_def(&instr->def, state);
-
- fprintf(fp, " = load_const (");
-
/*
* we don't really know the type of the constant (if it will be used as a
* float or an int), so just print the raw constant in hex for fidelity
* and then print in float again for readability.
*/
+ fprintf(fp, "(");
+
for (unsigned i = 0; i < instr->def.num_components; i++) {
if (i != 0)
fprintf(fp, ", ");
@@ -177,11 +175,29 @@ print_load_const_instr(nir_load_const_instr *instr, print_state *state)
fprintf(fp, ")");
}
+static void
+print_load_const_instr(nir_load_const_instr *instr, print_state *state)
+{
+ FILE *fp = state->fp;
+
+ print_ssa_def(&instr->def, state);
+
+ fprintf(fp, " = load_const ");
+
+ print_const_from_load(instr, state);
+}
+
static void
print_ssa_use(nir_ssa_def *def, print_state *state)
{
FILE *fp = state->fp;
fprintf(fp, "ssa_%u", def->index);
+ nir_instr *instr = def->parent_instr;
+ if (instr->type == nir_instr_type_load_const && NIR_DEBUG(PRINT_CONSTS)) {
+ fprintf(fp, " /*");
+ print_const_from_load(nir_instr_as_load_const(instr), state);
+ fprintf(fp, "*/");
+ }
}
static void print_src(const nir_src *src, print_state *state);
More information about the mesa-commit
mailing list