1 /* Print RTL functions for GCC.
2 Copyright (C) 2016 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/>. */
22 #include "coretypes.h"
31 #include "basic-block.h"
32 #include "print-rtl.h"
33 #include "langhooks.h"
36 /* Print an "(edge-from)" or "(edge-to)" directive describing E
40 print_edge (FILE *outfile
, edge e
, bool from
)
42 fprintf (outfile
, " (%s ", from
? "edge-from" : "edge-to");
43 basic_block bb
= from
? e
->src
: e
->dest
;
48 fprintf (outfile
, "entry");
51 fprintf (outfile
, "exit");
54 fprintf (outfile
, "%i", bb
->index
);
58 /* Express edge flags as a string with " | " separator.
59 e.g. (flags "FALLTHRU | DFS_BACK"). */
60 fprintf (outfile
, " (flags \"");
61 bool seen_flag
= false;
62 #define DEF_EDGE_FLAG(NAME,IDX) \
64 if (e->flags & EDGE_##NAME) \
67 fprintf (outfile, " | "); \
68 fprintf (outfile, "%s", (#NAME)); \
72 #include "cfg-flags.def"
75 fprintf (outfile
, "\"))\n");
78 /* If BB is non-NULL, print the start of a "(block)" directive for it
79 to OUTFILE, otherwise do nothing. */
82 begin_any_block (FILE *outfile
, basic_block bb
)
90 fprintf (outfile
, " (block %i\n", bb
->index
);
91 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
92 print_edge (outfile
, e
, true);
95 /* If BB is non-NULL, print the end of a "(block)" directive for it
96 to OUTFILE, otherwise do nothing. */
99 end_any_block (FILE *outfile
, basic_block bb
)
107 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
108 print_edge (outfile
, e
, false);
109 fprintf (outfile
, " ) ;; block %i\n", bb
->index
);
112 /* Determine if INSN is of a kind that can have a basic block. */
115 can_have_basic_block_p (const rtx_insn
*insn
)
117 rtx_code code
= GET_CODE (insn
);
120 gcc_assert (GET_RTX_FORMAT (code
)[2] == 'B');
124 /* Write FN to OUTFILE in a form suitable for parsing, with indentation
125 and comments to make the structure easy for a human to grok. Track
126 the basic blocks of insns in the chain, wrapping those that are within
127 blocks within "(block)" directives.
131 (function "times_two"
133 (note 1 0 4 (nil) NOTE_INSN_DELETED)
135 (edge-from entry (flags "FALLTHRU"))
136 (note 4 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
137 (insn 2 4 3 2 (set (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
138 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])
139 (reg:SI 5 di [ i ])) t.c:2 -1
141 (note 3 2 6 2 NOTE_INSN_FUNCTION_BEG)
142 (insn 6 3 7 2 (set (reg:SI 89)
143 (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
144 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])) t.c:3 -1
146 (insn 7 6 10 2 (parallel [
147 (set (reg:SI 87 [ _2 ])
148 (ashift:SI (reg:SI 89)
149 (const_int 1 [0x1])))
150 (clobber (reg:CC 17 flags))
152 (expr_list:REG_EQUAL (ashift:SI (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
153 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])
156 (insn 10 7 14 2 (set (reg:SI 88 [ <retval> ])
157 (reg:SI 87 [ _2 ])) t.c:3 -1
159 (insn 14 10 15 2 (set (reg/i:SI 0 ax)
160 (reg:SI 88 [ <retval> ])) t.c:4 -1
162 (insn 15 14 0 2 (use (reg/i:SI 0 ax)) t.c:4 -1
164 (edge-to exit (flags "FALLTHRU"))
172 ) ;; function "times_two"
176 print_rtx_function (FILE *outfile
, function
*fn
)
178 tree fdecl
= fn
->decl
;
180 const char *dname
= lang_hooks
.decl_printable_name (fdecl
, 2);
182 fprintf (outfile
, "(function \"%s\"\n", dname
);
184 /* The instruction chain. */
185 fprintf (outfile
, " (insn-chain\n");
186 basic_block curr_bb
= NULL
;
187 for (rtx_insn
*insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
190 if (can_have_basic_block_p (insn
))
191 insn_bb
= BLOCK_FOR_INSN (insn
);
194 if (curr_bb
!= insn_bb
)
196 end_any_block (outfile
, curr_bb
);
198 begin_any_block (outfile
, curr_bb
);
200 print_rtl_single_with_indent (outfile
, insn
, curr_bb
? 6 : 4);
202 end_any_block (outfile
, curr_bb
);
203 fprintf (outfile
, " ) ;; insn-chain\n");
205 /* Additional RTL state. */
206 fprintf (outfile
, " (crtl\n");
207 fprintf (outfile
, " (return_rtx \n");
208 print_rtl_single_with_indent (outfile
, crtl
->return_rtx
, 6);
209 fprintf (outfile
, " ) ;; return_rtx\n");
210 fprintf (outfile
, " ) ;; crtl\n");
212 fprintf (outfile
, ") ;; function \"%s\"\n", dname
);