annotate gcc/print-rtl-function.c @ 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 functions for GCC.
kono
parents:
diff changeset
2 Copyright (C) 2016-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 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "tm.h"
kono
parents:
diff changeset
24 #include "rtl.h"
kono
parents:
diff changeset
25 #include "alias.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "flags.h"
kono
parents:
diff changeset
28 #include "predict.h"
kono
parents:
diff changeset
29 #include "function.h"
kono
parents:
diff changeset
30 #include "basic-block.h"
kono
parents:
diff changeset
31 #include "print-rtl.h"
kono
parents:
diff changeset
32 #include "langhooks.h"
kono
parents:
diff changeset
33 #include "memmodel.h"
kono
parents:
diff changeset
34 #include "emit-rtl.h"
kono
parents:
diff changeset
35 #include "varasm.h"
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 /* Print an "(edge-from)" or "(edge-to)" directive describing E
kono
parents:
diff changeset
38 to OUTFILE. */
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 static void
kono
parents:
diff changeset
41 print_edge (FILE *outfile, edge e, bool from)
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 fprintf (outfile, " (%s ", from ? "edge-from" : "edge-to");
kono
parents:
diff changeset
44 basic_block bb = from ? e->src : e->dest;
kono
parents:
diff changeset
45 gcc_assert (bb);
kono
parents:
diff changeset
46 switch (bb->index)
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 case ENTRY_BLOCK:
kono
parents:
diff changeset
49 fprintf (outfile, "entry");
kono
parents:
diff changeset
50 break;
kono
parents:
diff changeset
51 case EXIT_BLOCK:
kono
parents:
diff changeset
52 fprintf (outfile, "exit");
kono
parents:
diff changeset
53 break;
kono
parents:
diff changeset
54 default:
kono
parents:
diff changeset
55 fprintf (outfile, "%i", bb->index);
kono
parents:
diff changeset
56 break;
kono
parents:
diff changeset
57 }
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* Express edge flags as a string with " | " separator.
kono
parents:
diff changeset
60 e.g. (flags "FALLTHRU | DFS_BACK"). */
kono
parents:
diff changeset
61 if (e->flags)
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 fprintf (outfile, " (flags \"");
kono
parents:
diff changeset
64 bool seen_flag = false;
kono
parents:
diff changeset
65 #define DEF_EDGE_FLAG(NAME,IDX) \
kono
parents:
diff changeset
66 do { \
kono
parents:
diff changeset
67 if (e->flags & EDGE_##NAME) \
kono
parents:
diff changeset
68 { \
kono
parents:
diff changeset
69 if (seen_flag) \
kono
parents:
diff changeset
70 fprintf (outfile, " | "); \
kono
parents:
diff changeset
71 fprintf (outfile, "%s", (#NAME)); \
kono
parents:
diff changeset
72 seen_flag = true; \
kono
parents:
diff changeset
73 } \
kono
parents:
diff changeset
74 } while (0);
kono
parents:
diff changeset
75 #include "cfg-flags.def"
kono
parents:
diff changeset
76 #undef DEF_EDGE_FLAG
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 fprintf (outfile, "\")");
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 fprintf (outfile, ")\n");
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* If BB is non-NULL, print the start of a "(block)" directive for it
kono
parents:
diff changeset
85 to OUTFILE, otherwise do nothing. */
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 static void
kono
parents:
diff changeset
88 begin_any_block (FILE *outfile, basic_block bb)
kono
parents:
diff changeset
89 {
kono
parents:
diff changeset
90 if (!bb)
kono
parents:
diff changeset
91 return;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 edge e;
kono
parents:
diff changeset
94 edge_iterator ei;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 fprintf (outfile, " (block %i\n", bb->index);
kono
parents:
diff changeset
97 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents:
diff changeset
98 print_edge (outfile, e, true);
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* If BB is non-NULL, print the end of a "(block)" directive for it
kono
parents:
diff changeset
102 to OUTFILE, otherwise do nothing. */
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 static void
kono
parents:
diff changeset
105 end_any_block (FILE *outfile, basic_block bb)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 if (!bb)
kono
parents:
diff changeset
108 return;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 edge e;
kono
parents:
diff changeset
111 edge_iterator ei;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents:
diff changeset
114 print_edge (outfile, e, false);
kono
parents:
diff changeset
115 fprintf (outfile, " ) ;; block %i\n", bb->index);
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Determine if INSN is of a kind that can have a basic block. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 static bool
kono
parents:
diff changeset
121 can_have_basic_block_p (const rtx_insn *insn)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 rtx_code code = GET_CODE (insn);
kono
parents:
diff changeset
124 if (code == BARRIER)
kono
parents:
diff changeset
125 return false;
kono
parents:
diff changeset
126 gcc_assert (GET_RTX_FORMAT (code)[2] == 'B');
kono
parents:
diff changeset
127 return true;
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* Subroutine of print_param. Write the name of ARG, if any, to OUTFILE. */
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 static void
kono
parents:
diff changeset
133 print_any_param_name (FILE *outfile, tree arg)
kono
parents:
diff changeset
134 {
kono
parents:
diff changeset
135 if (DECL_NAME (arg))
kono
parents:
diff changeset
136 fprintf (outfile, " \"%s\"", IDENTIFIER_POINTER (DECL_NAME (arg)));
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 /* Print a "(param)" directive for ARG to OUTFILE. */
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 static void
kono
parents:
diff changeset
142 print_param (FILE *outfile, rtx_writer &w, tree arg)
kono
parents:
diff changeset
143 {
kono
parents:
diff changeset
144 fprintf (outfile, " (param");
kono
parents:
diff changeset
145 print_any_param_name (outfile, arg);
kono
parents:
diff changeset
146 fprintf (outfile, "\n");
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /* Print the value of DECL_RTL (without lazy-evaluation). */
kono
parents:
diff changeset
149 fprintf (outfile, " (DECL_RTL ");
kono
parents:
diff changeset
150 w.print_rtx (DECL_RTL_IF_SET (arg));
kono
parents:
diff changeset
151 w.finish_directive ();
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 /* Print DECL_INCOMING_RTL. */
kono
parents:
diff changeset
154 fprintf (outfile, " (DECL_RTL_INCOMING ");
kono
parents:
diff changeset
155 w.print_rtx (DECL_INCOMING_RTL (arg));
kono
parents:
diff changeset
156 fprintf (outfile, ")");
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 w.finish_directive ();
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 /* Write FN to OUTFILE in a form suitable for parsing, with indentation
kono
parents:
diff changeset
162 and comments to make the structure easy for a human to grok. Track
kono
parents:
diff changeset
163 the basic blocks of insns in the chain, wrapping those that are within
kono
parents:
diff changeset
164 blocks within "(block)" directives.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 If COMPACT, then instructions are printed in a compact form:
kono
parents:
diff changeset
167 - INSN_UIDs are omitted, except for jumps and CODE_LABELs,
kono
parents:
diff changeset
168 - INSN_CODEs are omitted,
kono
parents:
diff changeset
169 - register numbers are omitted for hard and virtual regs, and
kono
parents:
diff changeset
170 non-virtual pseudos are offset relative to the first such reg, and
kono
parents:
diff changeset
171 printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1),
kono
parents:
diff changeset
172 - insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc)
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Example output (with COMPACT==true):
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 (function "times_two"
kono
parents:
diff changeset
177 (param "i"
kono
parents:
diff changeset
178 (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
kono
parents:
diff changeset
179 (const_int -4)) [1 i+0 S4 A32]))
kono
parents:
diff changeset
180 (DECL_RTL_INCOMING (reg:SI di [ i ])))
kono
parents:
diff changeset
181 (insn-chain
kono
parents:
diff changeset
182 (cnote 1 NOTE_INSN_DELETED)
kono
parents:
diff changeset
183 (block 2
kono
parents:
diff changeset
184 (edge-from entry (flags "FALLTHRU"))
kono
parents:
diff changeset
185 (cnote 4 [bb 2] NOTE_INSN_BASIC_BLOCK)
kono
parents:
diff changeset
186 (cinsn 2 (set (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
kono
parents:
diff changeset
187 (const_int -4)) [1 i+0 S4 A32])
kono
parents:
diff changeset
188 (reg:SI di [ i ])) "t.c":2)
kono
parents:
diff changeset
189 (cnote 3 NOTE_INSN_FUNCTION_BEG)
kono
parents:
diff changeset
190 (cinsn 6 (set (reg:SI <2>)
kono
parents:
diff changeset
191 (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
kono
parents:
diff changeset
192 (const_int -4)) [1 i+0 S4 A32])) "t.c":3)
kono
parents:
diff changeset
193 (cinsn 7 (parallel [
kono
parents:
diff changeset
194 (set (reg:SI <0> [ _2 ])
kono
parents:
diff changeset
195 (ashift:SI (reg:SI <2>)
kono
parents:
diff changeset
196 (const_int 1)))
kono
parents:
diff changeset
197 (clobber (reg:CC flags))
kono
parents:
diff changeset
198 ]) "t.c":3
kono
parents:
diff changeset
199 (expr_list:REG_EQUAL (ashift:SI (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars)
kono
parents:
diff changeset
200 (const_int -4)) [1 i+0 S4 A32])
kono
parents:
diff changeset
201 (const_int 1))))
kono
parents:
diff changeset
202 (cinsn 10 (set (reg:SI <1> [ <retval> ])
kono
parents:
diff changeset
203 (reg:SI <0> [ _2 ])) "t.c":3)
kono
parents:
diff changeset
204 (cinsn 14 (set (reg/i:SI ax)
kono
parents:
diff changeset
205 (reg:SI <1> [ <retval> ])) "t.c":4)
kono
parents:
diff changeset
206 (cinsn 15 (use (reg/i:SI ax)) "t.c":4)
kono
parents:
diff changeset
207 (edge-to exit (flags "FALLTHRU"))
kono
parents:
diff changeset
208 ) ;; block 2
kono
parents:
diff changeset
209 ) ;; insn-chain
kono
parents:
diff changeset
210 (crtl
kono
parents:
diff changeset
211 (return_rtx
kono
parents:
diff changeset
212 (reg/i:SI ax)
kono
parents:
diff changeset
213 ) ;; return_rtx
kono
parents:
diff changeset
214 ) ;; crtl
kono
parents:
diff changeset
215 ) ;; function "times_two"
kono
parents:
diff changeset
216 */
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 DEBUG_FUNCTION void
kono
parents:
diff changeset
219 print_rtx_function (FILE *outfile, function *fn, bool compact)
kono
parents:
diff changeset
220 {
kono
parents:
diff changeset
221 rtx_reuse_manager r;
kono
parents:
diff changeset
222 rtx_writer w (outfile, 0, false, compact, &r);
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 /* Support "reuse_rtx" in the dump. */
kono
parents:
diff changeset
225 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
kono
parents:
diff changeset
226 r.preprocess (insn);
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 tree fdecl = fn->decl;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 const char *dname = lang_hooks.decl_printable_name (fdecl, 1);
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 fprintf (outfile, "(function \"%s\"\n", dname);
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 /* Params. */
kono
parents:
diff changeset
235 for (tree arg = DECL_ARGUMENTS (fdecl); arg; arg = DECL_CHAIN (arg))
kono
parents:
diff changeset
236 print_param (outfile, w, arg);
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* The instruction chain. */
kono
parents:
diff changeset
239 fprintf (outfile, " (insn-chain\n");
kono
parents:
diff changeset
240 basic_block curr_bb = NULL;
kono
parents:
diff changeset
241 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 basic_block insn_bb;
kono
parents:
diff changeset
244 if (can_have_basic_block_p (insn))
kono
parents:
diff changeset
245 insn_bb = BLOCK_FOR_INSN (insn);
kono
parents:
diff changeset
246 else
kono
parents:
diff changeset
247 insn_bb = NULL;
kono
parents:
diff changeset
248 if (curr_bb != insn_bb)
kono
parents:
diff changeset
249 {
kono
parents:
diff changeset
250 end_any_block (outfile, curr_bb);
kono
parents:
diff changeset
251 curr_bb = insn_bb;
kono
parents:
diff changeset
252 begin_any_block (outfile, curr_bb);
kono
parents:
diff changeset
253 }
kono
parents:
diff changeset
254 w.print_rtl_single_with_indent (insn, curr_bb ? 6 : 4);
kono
parents:
diff changeset
255 }
kono
parents:
diff changeset
256 end_any_block (outfile, curr_bb);
kono
parents:
diff changeset
257 fprintf (outfile, " ) ;; insn-chain\n");
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 /* Additional RTL state. */
kono
parents:
diff changeset
260 fprintf (outfile, " (crtl\n");
kono
parents:
diff changeset
261 fprintf (outfile, " (return_rtx \n");
kono
parents:
diff changeset
262 w.print_rtl_single_with_indent (crtl->return_rtx, 6);
kono
parents:
diff changeset
263 fprintf (outfile, " ) ;; return_rtx\n");
kono
parents:
diff changeset
264 fprintf (outfile, " ) ;; crtl\n");
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 fprintf (outfile, ") ;; function \"%s\"\n", dname);
kono
parents:
diff changeset
267 }