aboutsummaryrefslogtreecommitdiff
path: root/gcc/print-rtl.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-12-06 21:03:33 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-12-06 21:03:33 +0000
commit00439aef2dbc4f95ba6e4926d5f27d0bb28edcec (patch)
tree6b5d45747cd0e0cd9296318d0fa03ac636f2b7d1 /gcc/print-rtl.h
parent9a38b8b940299eeceb51652bc070834809bb126e (diff)
downloadgcc-00439aef2dbc4f95ba6e4926d5f27d0bb28edcec.zip
gcc-00439aef2dbc4f95ba6e4926d5f27d0bb28edcec.tar.gz
gcc-00439aef2dbc4f95ba6e4926d5f27d0bb28edcec.tar.bz2
print_rtx: implement support for reuse IDs (v2)
gcc/ChangeLog: * config/i386/i386.c: Include print-rtl.h. (selftest::ix86_test_dumping_memory_blockage): New function. (selftest::ix86_run_selftests): Call it. * print-rtl-function.c (print_rtx_function): Create an rtx_reuse_manager and use it. * print-rtl.c: Include "rtl-iter.h". (rtx_writer::rtx_writer): Add reuse_manager param. (rtx_reuse_manager::rtx_reuse_manager): New ctor. (uses_rtx_reuse_p): New function. (rtx_reuse_manager::preprocess): New function. (rtx_reuse_manager::has_reuse_id): New function. (rtx_reuse_manager::seen_def_p): New function. (rtx_reuse_manager::set_seen_def): New function. (rtx_writer::print_rtx): If "in_rtx" has a reuse ID, print it as a prefix the first time in_rtx is seen, and print reuse_rtx subsequently. (print_inline_rtx): Supply NULL for new reuse_manager param. (debug_rtx): Likewise. (print_rtl): Likewise. (print_rtl_single): Likewise. (rtx_writer::print_rtl_single_with_indent): Likewise. * print-rtl.h: Include bitmap.h when building for host. (rtx_writer::rtx_writer): Add reuse_manager param. (rtx_writer::m_rtx_reuse_manager): New field. (class rtx_reuse_manager): New class. * rtl-tests.c (selftest::assert_rtl_dump_eq): Add reuse_manager param and use it when constructing rtx_writer. (selftest::test_dumping_rtx_reuse): New function. (selftest::rtl_tests_c_tests): Call it. * selftest-rtl.h (class rtx_reuse_manager): New forward decl. (selftest::assert_rtl_dump_eq): Add reuse_manager param. (ASSERT_RTL_DUMP_EQ): Supply NULL for reuse_manager param. (ASSERT_RTL_DUMP_EQ_WITH_REUSE): New macro. From-SVN: r243317
Diffstat (limited to 'gcc/print-rtl.h')
-rw-r--r--gcc/print-rtl.h81
1 files changed, 80 insertions, 1 deletions
diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h
index e722038..5f7cefb 100644
--- a/gcc/print-rtl.h
+++ b/gcc/print-rtl.h
@@ -20,12 +20,19 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_PRINT_RTL_H
#define GCC_PRINT_RTL_H
+#ifndef GENERATOR_FILE
+#include "bitmap.h"
+#endif /* #ifndef GENERATOR_FILE */
+
+class rtx_reuse_manager;
+
/* A class for writing rtx to a FILE *. */
class rtx_writer
{
public:
- rtx_writer (FILE *outfile, int ind, bool simple, bool compact);
+ rtx_writer (FILE *outfile, int ind, bool simple, bool compact,
+ rtx_reuse_manager *reuse_manager);
void print_rtx (const_rtx in_rtx);
void print_rtl (const_rtx rtx_first);
@@ -60,6 +67,9 @@ class rtx_writer
printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1),
- insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc). */
bool m_compact;
+
+ /* An optional instance of rtx_reuse_manager. */
+ rtx_reuse_manager *m_rtx_reuse_manager;
};
#ifdef BUFSIZ
@@ -80,4 +90,73 @@ extern const char *str_pattern_slim (const_rtx);
extern void print_rtx_function (FILE *file, function *fn, bool compact);
+#ifndef GENERATOR_FILE
+
+/* For some rtx codes (such as SCRATCH), instances are defined to only be
+ equal for pointer equality: two distinct SCRATCH instances are non-equal.
+ copy_rtx preserves this equality by reusing the SCRATCH instance.
+
+ For example, in this x86 instruction:
+
+ (cinsn (set (mem/v:BLK (scratch:DI) [0 A8])
+ (unspec:BLK [
+ (mem/v:BLK (scratch:DI) [0 A8])
+ ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2
+ (nil))
+
+ the two instances of "(scratch:DI)" are actually the same underlying
+ rtx pointer (and thus "equal"), and the insn will only be recognized
+ (as "*memory_blockage") if this pointer-equality is preserved.
+
+ To be able to preserve this pointer-equality when round-tripping
+ through dumping/loading the rtl, we need some syntax. The first
+ time a reused rtx is encountered in the dump, we prefix it with
+ a reuse ID:
+
+ (0|scratch:DI)
+
+ Subsequent references to the rtx in the dump can be expressed using
+ "reuse_rtx" e.g.:
+
+ (reuse_rtx 0)
+
+ This class is responsible for tracking a set of reuse IDs during a dump.
+
+ Dumping with reuse-support is done in two passes:
+
+ (a) a first pass in which "preprocess" is called on each top-level rtx
+ to be seen in the dump. This traverses the rtx and its descendents,
+ identifying rtx that will be seen more than once in the actual dump,
+ and assigning them reuse IDs.
+
+ (b) the actual dump, via print_rtx etc. print_rtx detect the presence
+ of a live rtx_reuse_manager and uses it if there is one. Any rtx
+ that were assigned reuse IDs will be printed with it the first time
+ that they are seen, and then printed as "(reuse_rtx ID)" subsequently.
+
+ The first phase is needed since otherwise there would be no way to tell
+ if an rtx will be reused when first encountering it. */
+
+class rtx_reuse_manager
+{
+ public:
+ rtx_reuse_manager ();
+
+ /* The first pass. */
+ void preprocess (const_rtx x);
+
+ /* The second pass (within print_rtx). */
+ bool has_reuse_id (const_rtx x, int *out);
+ bool seen_def_p (int reuse_id);
+ void set_seen_def (int reuse_id);
+
+ private:
+ hash_map<const_rtx, int> m_rtx_occurrence_count;
+ hash_map<const_rtx, int> m_rtx_reuse_ids;
+ bitmap_head m_defs_seen;
+ int m_next_id;
+};
+
+#endif /* #ifndef GENERATOR_FILE */
+
#endif // GCC_PRINT_RTL_H