[gcc r12-3335] RAII class to change dump_file.
Aldy Hernandez
aldyh@gcc.gnu.org
Fri Sep 3 13:32:05 GMT 2021
https://gcc.gnu.org/g:7200a4424c45b1b10e138bb5c52f58f3cc7da4a0
commit r12-3335-g7200a4424c45b1b10e138bb5c52f58f3cc7da4a0
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Fri Sep 3 11:45:03 2021 +0200
RAII class to change dump_file.
The function dump_ranger() shows everything the ranger knows at the
current time. To do this, we tickle all the statements to force ranger
to provide as much information as possible. During this process, the
relation code will dump status out to the dump_file, whereas in
dump_ranger, we want to dump it out to a specific file (most likely
stderr). This patch changes the dump_file through the life of
dump_ranger() and resets it when its done.
This patch only affects dump/debugging code.
Tested on x86-64 Linux.
gcc/ChangeLog:
* gimple-range-trace.cc (push_dump_file::push_dump_file): New.
(push_dump_file::~push_dump_file): New.
(dump_ranger): Change dump_file temporarily while dumping
ranger.
* gimple-range-trace.h (class push_dump_file): New.
Diff:
---
gcc/gimple-range-trace.cc | 20 ++++++++++++++++++++
gcc/gimple-range-trace.h | 14 ++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/gcc/gimple-range-trace.cc b/gcc/gimple-range-trace.cc
index 449ed8373fd..5175d1400c4 100644
--- a/gcc/gimple-range-trace.cc
+++ b/gcc/gimple-range-trace.cc
@@ -155,11 +155,31 @@ debug_seed_ranger (gimple_ranger &ranger)
}
}
+// Change the current dump_file and dump_flags to F and FLAGS while
+// saving them for later restoring.
+
+push_dump_file::push_dump_file (FILE *f, dump_flags_t flags)
+{
+ old_dump_file = dump_file;
+ old_dump_flags = dump_flags;
+ dump_file = f;
+ dump_flags = flags;
+}
+
+// Restore saved dump_file and dump_flags.
+
+push_dump_file::~push_dump_file ()
+{
+ dump_file = old_dump_file;
+ dump_flags = old_dump_flags;
+}
+
// Dump all that ranger knows for the current function.
DEBUG_FUNCTION void
dump_ranger (FILE *out)
{
+ push_dump_file save (out, dump_flags);
gimple_ranger ranger;
fprintf (out, ";; Function ");
diff --git a/gcc/gimple-range-trace.h b/gcc/gimple-range-trace.h
index d2d1a8b270c..b9546a245d1 100644
--- a/gcc/gimple-range-trace.h
+++ b/gcc/gimple-range-trace.h
@@ -58,4 +58,18 @@ range_tracer::header (const char *str)
return do_header (str);
return 0;
}
+
+// RAII class to change current dump_file and dump_flags, and restore
+// when the object goes out of scope.
+
+class push_dump_file
+{
+public:
+ push_dump_file (FILE *, dump_flags_t);
+ ~push_dump_file ();
+private:
+ FILE *old_dump_file;
+ dump_flags_t old_dump_flags;
+};
+
#endif // GCC_GIMPLE_RANGE_TRACE_H
More information about the Gcc-cvs
mailing list