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