Machine-readable RTL dumps: print_rtx_function
[official-gcc.git] / gcc / print-rtl-function.c
blobc4b99c03a37f82f2a0243dd667bede1627ede420
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
9 version.
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
14 for more details.
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 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "alias.h"
26 #include "tree.h"
27 #include "cfg.h"
28 #include "flags.h"
29 #include "predict.h"
30 #include "function.h"
31 #include "basic-block.h"
32 #include "print-rtl.h"
33 #include "langhooks.h"
34 #include "emit-rtl.h"
36 /* Write FN to OUTFILE in a form suitable for parsing, with indentation
37 and comments to make the structure easy for a human to grok.
39 Example output:
41 (function "times_two"
42 (insn-chain
43 (note 1 0 4 (nil) NOTE_INSN_DELETED)
44 (note 4 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
45 (insn 2 4 3 2 (set (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
46 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])
47 (reg:SI 5 di [ i ])) t.c:2 -1
48 (nil))
49 (note 3 2 6 2 NOTE_INSN_FUNCTION_BEG)
50 (insn 6 3 7 2 (set (reg:SI 89)
51 (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
52 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])) t.c:3 -1
53 (nil))
54 (insn 7 6 10 2 (parallel [
55 (set (reg:SI 87 [ _2 ])
56 (ashift:SI (reg:SI 89)
57 (const_int 1 [0x1])))
58 (clobber (reg:CC 17 flags))
59 ]) t.c:3 -1
60 (expr_list:REG_EQUAL (ashift:SI (mem/c:SI (plus:DI (reg/f:DI 82 virtual-stack-vars)
61 (const_int -4 [0xfffffffffffffffc])) [1 i+0 S4 A32])
62 (const_int 1 [0x1]))
63 (nil)))
64 (insn 10 7 14 2 (set (reg:SI 88 [ <retval> ])
65 (reg:SI 87 [ _2 ])) t.c:3 -1
66 (nil))
67 (insn 14 10 15 2 (set (reg/i:SI 0 ax)
68 (reg:SI 88 [ <retval> ])) t.c:4 -1
69 (nil))
70 (insn 15 14 0 2 (use (reg/i:SI 0 ax)) t.c:4 -1
71 (nil))
72 ) ;; insn-chain
73 (cfg
74 (bb 0
75 (edge 0 2 (flags 0x1))
76 ) ;; bb
77 (bb 2
78 (edge 2 1 (flags 0x1))
79 ) ;; bb
80 (bb 1
81 ) ;; bb
82 ) ;; cfg
83 (crtl
84 (return_rtx
85 (reg/i:SI 0 ax)
86 ) ;; return_rtx
87 ) ;; crtl
88 ) ;; function "times_two"
91 DEBUG_FUNCTION void
92 print_rtx_function (FILE *outfile, function *fn)
94 tree fdecl = fn->decl;
96 const char *dname = lang_hooks.decl_printable_name (fdecl, 2);
98 fprintf (outfile, "(function \"%s\"\n", dname);
100 /* The instruction chain. */
101 fprintf (outfile, " (insn-chain\n");
102 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
103 print_rtl_single_with_indent (outfile, insn, 4);
104 fprintf (outfile, " ) ;; insn-chain\n");
106 /* The CFG. */
107 fprintf (outfile, " (cfg\n");
109 basic_block bb;
110 FOR_ALL_BB_FN (bb, fn)
112 fprintf (outfile, " (bb %i\n", bb->index);
113 edge e;
114 edge_iterator ei;
115 FOR_EACH_EDGE (e, ei, bb->succs)
116 fprintf (outfile, " (edge %i %i (flags 0x%x))\n",
117 e->src->index, e->dest->index, e->flags);
118 fprintf (outfile, " ) ;; bb\n");
121 fprintf (outfile, " ) ;; cfg\n");
123 /* Additional RTL state. */
124 fprintf (outfile, " (crtl\n");
125 fprintf (outfile, " (return_rtx \n");
126 print_rtl_single_with_indent (outfile, crtl->return_rtx, 6);
127 fprintf (outfile, " ) ;; return_rtx\n");
128 fprintf (outfile, " ) ;; crtl\n");
130 fprintf (outfile, ") ;; function \"%s\"\n", dname);