annotate gcc/print-rtl.h @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* Print RTL for GCC.
kono
parents:
diff changeset
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef GCC_PRINT_RTL_H
kono
parents:
diff changeset
21 #define GCC_PRINT_RTL_H
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #ifndef GENERATOR_FILE
kono
parents:
diff changeset
24 #include "bitmap.h"
kono
parents:
diff changeset
25 #endif /* #ifndef GENERATOR_FILE */
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 class rtx_reuse_manager;
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 /* A class for writing rtx to a FILE *. */
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 class rtx_writer
kono
parents:
diff changeset
32 {
kono
parents:
diff changeset
33 public:
kono
parents:
diff changeset
34 rtx_writer (FILE *outfile, int ind, bool simple, bool compact,
kono
parents:
diff changeset
35 rtx_reuse_manager *reuse_manager);
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 void print_rtx (const_rtx in_rtx);
kono
parents:
diff changeset
38 void print_rtl (const_rtx rtx_first);
kono
parents:
diff changeset
39 int print_rtl_single_with_indent (const_rtx x, int ind);
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 void finish_directive ();
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 private:
kono
parents:
diff changeset
44 void print_rtx_operand_code_0 (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
45 void print_rtx_operand_code_e (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
46 void print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
47 void print_rtx_operand_code_i (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
48 void print_rtx_operand_code_r (const_rtx in_rtx);
kono
parents:
diff changeset
49 void print_rtx_operand_code_u (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
50 void print_rtx_operand (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
51 bool operand_has_default_value_p (const_rtx in_rtx, int idx);
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 private:
kono
parents:
diff changeset
54 FILE *m_outfile;
kono
parents:
diff changeset
55 int m_sawclose;
kono
parents:
diff changeset
56 int m_indent;
kono
parents:
diff changeset
57 bool m_in_call_function_usage;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* True means use simplified format without flags, modes, etc. */
kono
parents:
diff changeset
60 bool m_simple;
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 /* If true, use compact dump format:
kono
parents:
diff changeset
63 - PREV/NEXT_INSN UIDs are omitted
kono
parents:
diff changeset
64 - INSN_CODEs are omitted,
kono
parents:
diff changeset
65 - register numbers are omitted for hard and virtual regs, and
kono
parents:
diff changeset
66 non-virtual pseudos are offset relative to the first such reg, and
kono
parents:
diff changeset
67 printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1),
kono
parents:
diff changeset
68 - insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc). */
kono
parents:
diff changeset
69 bool m_compact;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 /* An optional instance of rtx_reuse_manager. */
kono
parents:
diff changeset
72 rtx_reuse_manager *m_rtx_reuse_manager;
kono
parents:
diff changeset
73 };
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 #ifdef BUFSIZ
kono
parents:
diff changeset
76 extern void print_rtl (FILE *, const_rtx);
kono
parents:
diff changeset
77 #endif
kono
parents:
diff changeset
78 extern void print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec);
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 extern void dump_value_slim (FILE *, const_rtx, int);
kono
parents:
diff changeset
81 extern void dump_insn_slim (FILE *, const rtx_insn *);
kono
parents:
diff changeset
82 extern void dump_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
kono
parents:
diff changeset
83 int, int);
kono
parents:
diff changeset
84 extern void print_value (pretty_printer *, const_rtx, int);
kono
parents:
diff changeset
85 extern void print_pattern (pretty_printer *, const_rtx, int);
kono
parents:
diff changeset
86 extern void print_insn (pretty_printer *pp, const rtx_insn *x, int verbose);
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 extern void rtl_dump_bb_for_graph (pretty_printer *, basic_block);
kono
parents:
diff changeset
89 extern const char *str_pattern_slim (const_rtx);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 extern void print_rtx_function (FILE *file, function *fn, bool compact);
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 #ifndef GENERATOR_FILE
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /* For some rtx codes (such as SCRATCH), instances are defined to only be
kono
parents:
diff changeset
96 equal for pointer equality: two distinct SCRATCH instances are non-equal.
kono
parents:
diff changeset
97 copy_rtx preserves this equality by reusing the SCRATCH instance.
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 For example, in this x86 instruction:
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 (cinsn (set (mem/v:BLK (scratch:DI) [0 A8])
kono
parents:
diff changeset
102 (unspec:BLK [
kono
parents:
diff changeset
103 (mem/v:BLK (scratch:DI) [0 A8])
kono
parents:
diff changeset
104 ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2
kono
parents:
diff changeset
105 (nil))
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 the two instances of "(scratch:DI)" are actually the same underlying
kono
parents:
diff changeset
108 rtx pointer (and thus "equal"), and the insn will only be recognized
kono
parents:
diff changeset
109 (as "*memory_blockage") if this pointer-equality is preserved.
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 To be able to preserve this pointer-equality when round-tripping
kono
parents:
diff changeset
112 through dumping/loading the rtl, we need some syntax. The first
kono
parents:
diff changeset
113 time a reused rtx is encountered in the dump, we prefix it with
kono
parents:
diff changeset
114 a reuse ID:
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 (0|scratch:DI)
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 Subsequent references to the rtx in the dump can be expressed using
kono
parents:
diff changeset
119 "reuse_rtx" e.g.:
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 (reuse_rtx 0)
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 This class is responsible for tracking a set of reuse IDs during a dump.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 Dumping with reuse-support is done in two passes:
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 (a) a first pass in which "preprocess" is called on each top-level rtx
kono
parents:
diff changeset
128 to be seen in the dump. This traverses the rtx and its descendents,
kono
parents:
diff changeset
129 identifying rtx that will be seen more than once in the actual dump,
kono
parents:
diff changeset
130 and assigning them reuse IDs.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 (b) the actual dump, via print_rtx etc. print_rtx detect the presence
kono
parents:
diff changeset
133 of a live rtx_reuse_manager and uses it if there is one. Any rtx
kono
parents:
diff changeset
134 that were assigned reuse IDs will be printed with it the first time
kono
parents:
diff changeset
135 that they are seen, and then printed as "(reuse_rtx ID)" subsequently.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 The first phase is needed since otherwise there would be no way to tell
kono
parents:
diff changeset
138 if an rtx will be reused when first encountering it. */
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 class rtx_reuse_manager
kono
parents:
diff changeset
141 {
kono
parents:
diff changeset
142 public:
kono
parents:
diff changeset
143 rtx_reuse_manager ();
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 /* The first pass. */
kono
parents:
diff changeset
146 void preprocess (const_rtx x);
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /* The second pass (within print_rtx). */
kono
parents:
diff changeset
149 bool has_reuse_id (const_rtx x, int *out);
kono
parents:
diff changeset
150 bool seen_def_p (int reuse_id);
kono
parents:
diff changeset
151 void set_seen_def (int reuse_id);
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 private:
kono
parents:
diff changeset
154 hash_map<const_rtx, int> m_rtx_occurrence_count;
kono
parents:
diff changeset
155 hash_map<const_rtx, int> m_rtx_reuse_ids;
kono
parents:
diff changeset
156 auto_bitmap m_defs_seen;
kono
parents:
diff changeset
157 int m_next_id;
kono
parents:
diff changeset
158 };
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 #endif /* #ifndef GENERATOR_FILE */
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 #endif // GCC_PRINT_RTL_H