On 09/09/2026 13:46, Richard Biener wrote:


debug_imm_uses_for?

Sure, naming is hard :)

nathan

--
Nathan Sidwell
From a2ad1184aefc1a99ef2857951fce2dc7e99cb81f Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <[email protected]>
Date: Wed, 9 Sep 2026 12:10:21 -0400
Subject: [PATCH] Add ssa def/use printer

	gcc/
	* gimple-pretty-print.h (print_ssa_imm_uses): Declare.
	(debug_imm_uses_for): Declare.
	* gimple-pretty-print.cc (print_ssa_imm_uses): New.
	(debug_imm_uses_for): New.
---
 gcc/gimple-pretty-print.cc | 26 ++++++++++++++++++++++++++
 gcc/gimple-pretty-print.h  |  4 ++++
 2 files changed, 30 insertions(+)

diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 001865605a1..dd723a344e5 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -89,6 +89,32 @@ debug_gimple_stmt (gimple *gs)
   print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
 }
 
+/* Print the defining ssa stmt and each immediate use stmt for VAR to
+   STREAM.  */
+
+void
+print_ssa_imm_uses (FILE *stream, tree var)
+{
+  if (!SSA_VAR_P (var))
+    return;
+
+  auto def = SSA_NAME_DEF_STMT (var);
+  print_gimple_stmt (stream, def, 0);
+
+  use_operand_p use_p;
+  imm_use_iterator iter;
+
+  FOR_EACH_IMM_USE_FAST (use_p, iter, var)
+    print_gimple_stmt (stream, USE_STMT (use_p), 0);
+}
+
+/* Print the defining ssa stmt and each immediate stmt for VAR to stderr.  */
+
+DEBUG_FUNCTION void
+debug_imm_uses_for (tree var)
+{
+  print_ssa_imm_uses (stderr, var);
+}
 
 /* Return formatted string of a VALUE probability
    (biased by REG_BR_PROB_BASE).  Returned string is allocated
diff --git a/gcc/gimple-pretty-print.h b/gcc/gimple-pretty-print.h
index 8013f2d5909..1bff6b59cb3 100644
--- a/gcc/gimple-pretty-print.h
+++ b/gcc/gimple-pretty-print.h
@@ -33,6 +33,10 @@ extern void print_gimple_seq (FILE *, gimple_seq, int, dump_flags_t);
 extern void print_gimple_stmt (FILE *, gimple *, int, dump_flags_t = TDF_NONE);
 extern void debug (gimple &ref);
 extern void debug (gimple *ptr);
+
+extern void debug_imm_uses_for (tree ssa_var);
+extern void print_ssa_imm_uses (FILE *, tree ssa_var);
+
 extern void print_gimple_expr (FILE *, gimple *, int, dump_flags_t = TDF_NONE);
 extern void pp_gimple_stmt_1 (pretty_printer *, const gimple *, int,
 			      dump_flags_t);
-- 
2.55.0

Reply via email to