2 Copyright (C) 1987-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_PRINT_RTL_H
21 #define GCC_PRINT_RTL_H
23 #ifndef GENERATOR_FILE
25 #endif /* #ifndef GENERATOR_FILE */
27 class rtx_reuse_manager
;
29 /* A class for writing rtx to a FILE *. */
34 rtx_writer (FILE *outfile
, int ind
, bool simple
, bool compact
,
35 rtx_reuse_manager
*reuse_manager
);
37 void print_rtx (const_rtx in_rtx
);
38 void print_rtl (const_rtx rtx_first
);
39 int print_rtl_single_with_indent (const_rtx x
, int ind
);
41 void finish_directive ();
44 void print_rtx_operand_code_0 (const_rtx in_rtx
, int idx
);
45 void print_rtx_operand_code_e (const_rtx in_rtx
, int idx
);
46 void print_rtx_operand_codes_E_and_V (const_rtx in_rtx
, int idx
);
47 void print_rtx_operand_code_i (const_rtx in_rtx
, int idx
);
48 void print_rtx_operand_code_r (const_rtx in_rtx
);
49 void print_rtx_operand_code_u (const_rtx in_rtx
, int idx
);
50 void print_rtx_operand (const_rtx in_rtx
, int idx
);
51 bool operand_has_default_value_p (const_rtx in_rtx
, int idx
);
57 bool m_in_call_function_usage
;
59 /* True means use simplified format without flags, modes, etc. */
62 /* If true, use compact dump format:
63 - PREV/NEXT_INSN UIDs are omitted
64 - INSN_CODEs are omitted,
65 - register numbers are omitted for hard and virtual regs, and
66 non-virtual pseudos are offset relative to the first such reg, and
67 printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1),
68 - insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc). */
71 /* An optional instance of rtx_reuse_manager. */
72 rtx_reuse_manager
*m_rtx_reuse_manager
;
76 extern void print_rtl (FILE *, const_rtx
);
78 extern void print_rtx_insn_vec (FILE *file
, const vec
<rtx_insn
*> &vec
);
80 extern void dump_value_slim (FILE *, const_rtx
, int);
81 extern void dump_insn_slim (FILE *, const rtx_insn
*);
82 extern void dump_rtl_slim (FILE *, const rtx_insn
*, const rtx_insn
*,
84 extern void print_value (pretty_printer
*, const_rtx
, int);
85 extern void print_pattern (pretty_printer
*, const_rtx
, int);
86 extern void print_insn (pretty_printer
*pp
, const rtx_insn
*x
, int verbose
);
88 extern void rtl_dump_bb_for_graph (pretty_printer
*, basic_block
);
89 extern const char *str_pattern_slim (const_rtx
);
91 extern void print_rtx_function (FILE *file
, function
*fn
, bool compact
);
93 #ifndef GENERATOR_FILE
95 /* For some rtx codes (such as SCRATCH), instances are defined to only be
96 equal for pointer equality: two distinct SCRATCH instances are non-equal.
97 copy_rtx preserves this equality by reusing the SCRATCH instance.
99 For example, in this x86 instruction:
101 (cinsn (set (mem/v:BLK (scratch:DI) [0 A8])
103 (mem/v:BLK (scratch:DI) [0 A8])
104 ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2
107 the two instances of "(scratch:DI)" are actually the same underlying
108 rtx pointer (and thus "equal"), and the insn will only be recognized
109 (as "*memory_blockage") if this pointer-equality is preserved.
111 To be able to preserve this pointer-equality when round-tripping
112 through dumping/loading the rtl, we need some syntax. The first
113 time a reused rtx is encountered in the dump, we prefix it with
118 Subsequent references to the rtx in the dump can be expressed using
123 This class is responsible for tracking a set of reuse IDs during a dump.
125 Dumping with reuse-support is done in two passes:
127 (a) a first pass in which "preprocess" is called on each top-level rtx
128 to be seen in the dump. This traverses the rtx and its descendents,
129 identifying rtx that will be seen more than once in the actual dump,
130 and assigning them reuse IDs.
132 (b) the actual dump, via print_rtx etc. print_rtx detect the presence
133 of a live rtx_reuse_manager and uses it if there is one. Any rtx
134 that were assigned reuse IDs will be printed with it the first time
135 that they are seen, and then printed as "(reuse_rtx ID)" subsequently.
137 The first phase is needed since otherwise there would be no way to tell
138 if an rtx will be reused when first encountering it. */
140 class rtx_reuse_manager
143 rtx_reuse_manager ();
145 /* The first pass. */
146 void preprocess (const_rtx x
);
148 /* The second pass (within print_rtx). */
149 bool has_reuse_id (const_rtx x
, int *out
);
150 bool seen_def_p (int reuse_id
);
151 void set_seen_def (int reuse_id
);
154 hash_map
<const_rtx
, int> m_rtx_occurrence_count
;
155 hash_map
<const_rtx
, int> m_rtx_reuse_ids
;
156 auto_bitmap m_defs_seen
;
160 #endif /* #ifndef GENERATOR_FILE */
162 #endif // GCC_PRINT_RTL_H