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-2026 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
27namespace diagnostics { class sarif_builder; }
28namespace json { class object; }
29
31
32/* A class for writing rtx to a FILE *. */
33
35{
36 public:
37 rtx_writer (FILE *outfile, int ind, bool simple, bool compact,
38 rtx_reuse_manager *reuse_manager);
39
40 void print_rtx (const_rtx in_rtx);
41 void print_rtl (const_rtx rtx_first);
43
44 void finish_directive ();
45
46 private:
47 void print_rtx_operand_code_0 (const_rtx in_rtx, int idx);
48 void print_rtx_operand_code_e (const_rtx in_rtx, int idx);
49 void print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx);
50 void print_rtx_operand_code_i (const_rtx in_rtx, int idx);
51 void print_rtx_operand_code_L (const_rtx in_rtx, int idx);
53 void print_rtx_operand_code_u (const_rtx in_rtx, int idx);
54 void print_rtx_operand (const_rtx in_rtx, int idx);
55 bool operand_has_default_value_p (const_rtx in_rtx, int idx);
56
57 private:
58 FILE *m_outfile;
62
63 /* True means use simplified format without flags, modes, etc. */
65
66 /* If true, use compact dump format:
67 - PREV/NEXT_INSN UIDs are omitted
68 - INSN_CODEs are omitted,
69 - register numbers are omitted for hard and virtual regs, and
70 non-virtual pseudos are offset relative to the first such reg, and
71 printed with a '%' sigil e.g. "%0" for (LAST_VIRTUAL_REGISTER + 1),
72 - insn names are prefixed with "c" (e.g. "cinsn", "cnote", etc). */
74
75#ifndef GENERATOR_FILE
76 /* An optional instance of rtx_reuse_manager. */
78#endif
79};
80
81#ifdef BUFSIZ
82extern void print_rtl (FILE *, const_rtx);
83#endif
84extern void print_rtx_insn_vec (FILE *file, const vec<rtx_insn *> &vec);
85
86extern void dump_value_slim (FILE *, const_rtx, int);
87extern void dump_insn_slim (FILE *, const rtx_insn *);
88extern void dump_rtl_slim (FILE *, const rtx_insn *, const rtx_insn *,
89 int, int);
90extern void print_value (pretty_printer *, const_rtx, int);
91extern void print_pattern (pretty_printer *, const_rtx, int);
92extern void print_insn (pretty_printer *pp, const rtx_insn *x, int verbose);
93extern void print_insn_with_notes (pretty_printer *, const rtx_insn *);
94
96extern void
100extern const char *str_pattern_slim (const_rtx);
101
102extern void print_rtx_function (FILE *file, function *fn, bool compact);
103
104#ifndef GENERATOR_FILE
105
106/* For some rtx codes (such as SCRATCH), instances are defined to only be
107 equal for pointer equality: two distinct SCRATCH instances are non-equal.
108 copy_rtx preserves this equality by reusing the SCRATCH instance.
109
110 For example, in this x86 instruction:
111
112 (cinsn (set (mem/v:BLK (scratch:DI) [0 A8])
113 (unspec:BLK [
114 (mem/v:BLK (scratch:DI) [0 A8])
115 ] UNSPEC_MEMORY_BLOCKAGE)) "test.c":2
116 (nil))
117
118 the two instances of "(scratch:DI)" are actually the same underlying
119 rtx pointer (and thus "equal"), and the insn will only be recognized
120 (as "*memory_blockage") if this pointer-equality is preserved.
121
122 To be able to preserve this pointer-equality when round-tripping
123 through dumping/loading the rtl, we need some syntax. The first
124 time a reused rtx is encountered in the dump, we prefix it with
125 a reuse ID:
126
127 (0|scratch:DI)
128
129 Subsequent references to the rtx in the dump can be expressed using
130 "reuse_rtx" e.g.:
131
132 (reuse_rtx 0)
133
134 This class is responsible for tracking a set of reuse IDs during a dump.
135
136 Dumping with reuse-support is done in two passes:
137
138 (a) a first pass in which "preprocess" is called on each top-level rtx
139 to be seen in the dump. This traverses the rtx and its descendents,
140 identifying rtx that will be seen more than once in the actual dump,
141 and assigning them reuse IDs.
142
143 (b) the actual dump, via print_rtx etc. print_rtx detect the presence
144 of a live rtx_reuse_manager and uses it if there is one. Any rtx
145 that were assigned reuse IDs will be printed with it the first time
146 that they are seen, and then printed as "(reuse_rtx ID)" subsequently.
147
148 The first phase is needed since otherwise there would be no way to tell
149 if an rtx will be reused when first encountering it. */
150
152{
153 public:
155
156 /* The first pass. */
157 void preprocess (const_rtx x);
158
159 /* The second pass (within print_rtx). */
160 bool has_reuse_id (const_rtx x, int *out);
161 bool seen_def_p (int reuse_id);
162 void set_seen_def (int reuse_id);
163
164 private:
169};
170
171#endif /* #ifndef GENERATOR_FILE */
172
173#endif // GCC_PRINT_RTL_H
Definition bitmap.h:950
Definition sarif-sink.cc:776
Definition hash-map.h:40
Definition json.h:188
Definition pretty-print.h:241
Definition print-rtl.h:152
int m_next_id
Definition print-rtl.h:168
rtx_reuse_manager()
Definition print-rtl.cc:105
auto_bitmap m_defs_seen
Definition print-rtl.h:167
hash_map< const_rtx, int > m_rtx_occurrence_count
Definition print-rtl.h:165
void set_seen_def(int reuse_id)
Definition print-rtl.cc:181
void preprocess(const_rtx x)
Definition print-rtl.cc:137
hash_map< const_rtx, int > m_rtx_reuse_ids
Definition print-rtl.h:166
bool seen_def_p(int reuse_id)
Definition print-rtl.cc:173
bool has_reuse_id(const_rtx x, int *out)
Definition print-rtl.cc:157
bool m_sawclose
Definition print-rtl.h:60
void print_rtx_operand_code_i(const_rtx in_rtx, int idx)
Definition print-rtl.cc:492
FILE * m_outfile
Definition print-rtl.h:58
void print_rtl(const_rtx rtx_first)
Definition print-rtl.cc:1194
bool operand_has_default_value_p(const_rtx in_rtx, int idx)
Definition print-rtl.cc:772
void print_rtx_operand_code_u(const_rtx in_rtx, int idx)
Definition print-rtl.cc:615
void print_rtx_operand_codes_E_and_V(const_rtx in_rtx, int idx)
Definition print-rtl.cc:371
void finish_directive()
Definition print-rtl.cc:1053
void print_rtx_operand_code_L(const_rtx in_rtx, int idx)
Definition print-rtl.cc:446
void print_rtx_operand_code_0(const_rtx in_rtx, int idx)
Definition print-rtl.cc:222
void print_rtx_operand_code_r(const_rtx in_rtx)
Definition print-rtl.cc:547
int m_indent
Definition print-rtl.h:59
bool m_in_call_function_usage
Definition print-rtl.h:61
bool m_simple
Definition print-rtl.h:64
void print_rtx_operand(const_rtx in_rtx, int idx)
Definition print-rtl.cc:662
void print_rtx(const_rtx in_rtx)
Definition print-rtl.cc:807
void print_rtl_single_with_indent(const_rtx x, int ind)
Definition print-rtl.cc:1254
rtx_reuse_manager * m_rtx_reuse_manager
Definition print-rtl.h:77
bool m_compact
Definition print-rtl.h:73
void print_rtx_operand_code_e(const_rtx in_rtx, int idx)
Definition print-rtl.cc:348
rtx_writer(FILE *outfile, int ind, bool simple, bool compact, rtx_reuse_manager *reuse_manager)
Definition print-rtl.cc:91
bool verbose
Definition collect-utils.cc:35
struct basic_block_def * basic_block
Definition coretypes.h:372
const struct rtx_def * const_rtx
Definition coretypes.h:58
Definition cfghooks.h:26
Definition cfghooks.h:27
void print_rtl(FILE *outf, const_rtx rtx_first)
Definition print-rtl.cc:1236
void dump_insn_slim(FILE *, const rtx_insn *)
Definition print-rtl.cc:2098
void print_rtx_insn_vec(FILE *file, const vec< rtx_insn * > &vec)
Definition print-rtl.cc:1284
void print_value(pretty_printer *, const_rtx, int)
Definition print-rtl.cc:1677
const char * str_pattern_slim(const_rtx)
Definition print-rtl.cc:2180
void rtl_dump_bb_for_graph(pretty_printer *, basic_block)
Definition print-rtl.cc:2134
void print_insn_with_notes(pretty_printer *, const rtx_insn *)
Definition print-rtl.cc:2062
void print_pattern(pretty_printer *, const_rtx, int)
Definition print-rtl.cc:1792
void print_insn(pretty_printer *pp, const rtx_insn *x, int verbose)
Definition print-rtl.cc:1927
void rtl_dump_bb_as_sarif_properties(diagnostics::sarif_builder *, json::object &, basic_block)
Definition print-rtl.cc:2155
void dump_value_slim(FILE *, const_rtx, int)
Definition print-rtl.cc:2087
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:2110
Definition function.h:249
Definition rtl.h:546
Definition vec.h:450