annotate gcc/read-rtl-function.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* read-rtl-function.c - Reader for RTL function dumps
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
111
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 "target.h"
kono
parents:
diff changeset
24 #include "tree.h"
kono
parents:
diff changeset
25 #include "diagnostic.h"
kono
parents:
diff changeset
26 #include "read-md.h"
kono
parents:
diff changeset
27 #include "rtl.h"
kono
parents:
diff changeset
28 #include "cfghooks.h"
kono
parents:
diff changeset
29 #include "stringpool.h"
kono
parents:
diff changeset
30 #include "function.h"
kono
parents:
diff changeset
31 #include "tree-cfg.h"
kono
parents:
diff changeset
32 #include "cfg.h"
kono
parents:
diff changeset
33 #include "basic-block.h"
kono
parents:
diff changeset
34 #include "cfgrtl.h"
kono
parents:
diff changeset
35 #include "memmodel.h"
kono
parents:
diff changeset
36 #include "emit-rtl.h"
kono
parents:
diff changeset
37 #include "cgraph.h"
kono
parents:
diff changeset
38 #include "tree-pass.h"
kono
parents:
diff changeset
39 #include "toplev.h"
kono
parents:
diff changeset
40 #include "varasm.h"
kono
parents:
diff changeset
41 #include "read-rtl-function.h"
kono
parents:
diff changeset
42 #include "selftest.h"
kono
parents:
diff changeset
43 #include "selftest-rtl.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
44 #include "regs.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
45 #include "function-abi.h"
111
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 /* Forward decls. */
kono
parents:
diff changeset
48 class function_reader;
kono
parents:
diff changeset
49 class fixup;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* Edges are recorded when parsing the "insn-chain" directive,
kono
parents:
diff changeset
52 and created at the end when all the blocks ought to exist.
kono
parents:
diff changeset
53 This struct records an "edge-from" or "edge-to" directive seen
kono
parents:
diff changeset
54 at LOC, which will be turned into an actual CFG edge once
kono
parents:
diff changeset
55 the "insn-chain" is fully parsed. */
kono
parents:
diff changeset
56
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
57 class deferred_edge
111
kono
parents:
diff changeset
58 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
59 public:
111
kono
parents:
diff changeset
60 deferred_edge (file_location loc, int src_bb_idx, int dest_bb_idx, int flags)
kono
parents:
diff changeset
61 : m_loc (loc), m_src_bb_idx (src_bb_idx), m_dest_bb_idx (dest_bb_idx),
kono
parents:
diff changeset
62 m_flags (flags)
kono
parents:
diff changeset
63 {}
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 file_location m_loc;
kono
parents:
diff changeset
66 int m_src_bb_idx;
kono
parents:
diff changeset
67 int m_dest_bb_idx;
kono
parents:
diff changeset
68 int m_flags;
kono
parents:
diff changeset
69 };
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 /* Subclass of rtx_reader for reading function dumps. */
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 class function_reader : public rtx_reader
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 public:
kono
parents:
diff changeset
76 function_reader ();
kono
parents:
diff changeset
77 ~function_reader ();
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Overridden vfuncs of class md_reader. */
kono
parents:
diff changeset
80 void handle_unknown_directive (file_location, const char *) FINAL OVERRIDE;
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 /* Overridden vfuncs of class rtx_reader. */
kono
parents:
diff changeset
83 rtx read_rtx_operand (rtx x, int idx) FINAL OVERRIDE;
kono
parents:
diff changeset
84 void handle_any_trailing_information (rtx x) FINAL OVERRIDE;
kono
parents:
diff changeset
85 rtx postprocess (rtx) FINAL OVERRIDE;
kono
parents:
diff changeset
86 const char *finalize_string (char *stringbuf) FINAL OVERRIDE;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 rtx_insn **get_insn_by_uid (int uid);
kono
parents:
diff changeset
89 tree parse_mem_expr (const char *desc);
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 private:
kono
parents:
diff changeset
92 void parse_function ();
kono
parents:
diff changeset
93 void create_function ();
kono
parents:
diff changeset
94 void parse_param ();
kono
parents:
diff changeset
95 void parse_insn_chain ();
kono
parents:
diff changeset
96 void parse_block ();
kono
parents:
diff changeset
97 int parse_bb_idx ();
kono
parents:
diff changeset
98 void parse_edge (basic_block block, bool from);
kono
parents:
diff changeset
99 rtx_insn *parse_insn (file_location loc, const char *name);
kono
parents:
diff changeset
100 void parse_cfg (file_location loc);
kono
parents:
diff changeset
101 void parse_crtl (file_location loc);
kono
parents:
diff changeset
102 void create_edges ();
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 int parse_enum_value (int num_values, const char *const *strings);
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 void read_rtx_operand_u (rtx x, int idx);
kono
parents:
diff changeset
107 void read_rtx_operand_i_or_n (rtx x, int idx, char format_char);
kono
parents:
diff changeset
108 rtx read_rtx_operand_r (rtx x);
kono
parents:
diff changeset
109 rtx extra_parsing_for_operand_code_0 (rtx x, int idx);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 void add_fixup_insn_uid (file_location loc, rtx insn, int operand_idx,
kono
parents:
diff changeset
112 int insn_uid);
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 void add_fixup_note_insn_basic_block (file_location loc, rtx insn,
kono
parents:
diff changeset
115 int operand_idx, int bb_idx);
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 void add_fixup_source_location (file_location loc, rtx_insn *insn,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
118 const char *filename, int lineno, int colno);
111
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 void add_fixup_expr (file_location loc, rtx x,
kono
parents:
diff changeset
121 const char *desc);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 rtx consolidate_singletons (rtx x);
kono
parents:
diff changeset
124 rtx parse_rtx ();
kono
parents:
diff changeset
125 void maybe_read_location (rtx_insn *insn);
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 void handle_insn_uids ();
kono
parents:
diff changeset
128 void apply_fixups ();
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 private:
kono
parents:
diff changeset
131 struct uid_hash : int_hash <int, -1, -2> {};
kono
parents:
diff changeset
132 hash_map<uid_hash, rtx_insn *> m_insns_by_uid;
kono
parents:
diff changeset
133 auto_vec<fixup *> m_fixups;
kono
parents:
diff changeset
134 rtx_insn *m_first_insn;
kono
parents:
diff changeset
135 auto_vec<tree> m_fake_scope;
kono
parents:
diff changeset
136 char *m_name;
kono
parents:
diff changeset
137 bool m_have_crtl_directive;
kono
parents:
diff changeset
138 basic_block m_bb_to_insert_after;
kono
parents:
diff changeset
139 auto_vec <deferred_edge> m_deferred_edges;
kono
parents:
diff changeset
140 int m_highest_bb_idx;
kono
parents:
diff changeset
141 };
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 /* Abstract base class for recording post-processing steps that must be
kono
parents:
diff changeset
144 done after reading a .rtl file. */
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 class fixup
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 public:
kono
parents:
diff changeset
149 /* Constructor for a fixup at LOC affecting X. */
kono
parents:
diff changeset
150 fixup (file_location loc, rtx x)
kono
parents:
diff changeset
151 : m_loc (loc), m_rtx (x)
kono
parents:
diff changeset
152 {}
kono
parents:
diff changeset
153 virtual ~fixup () {}
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 virtual void apply (function_reader *reader) const = 0;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 protected:
kono
parents:
diff changeset
158 file_location m_loc;
kono
parents:
diff changeset
159 rtx m_rtx;
kono
parents:
diff changeset
160 };
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 /* An abstract subclass of fixup for post-processing steps that
kono
parents:
diff changeset
163 act on a specific operand of a specific instruction. */
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 class operand_fixup : public fixup
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 public:
kono
parents:
diff changeset
168 /* Constructor for a fixup at LOC affecting INSN's operand
kono
parents:
diff changeset
169 with index OPERAND_IDX. */
kono
parents:
diff changeset
170 operand_fixup (file_location loc, rtx insn, int operand_idx)
kono
parents:
diff changeset
171 : fixup (loc, insn), m_operand_idx (operand_idx)
kono
parents:
diff changeset
172 {}
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 protected:
kono
parents:
diff changeset
175 int m_operand_idx;
kono
parents:
diff changeset
176 };
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 /* A concrete subclass of operand_fixup: fixup an rtx_insn *
kono
parents:
diff changeset
179 field based on an integer UID. */
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 class fixup_insn_uid : public operand_fixup
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 public:
kono
parents:
diff changeset
184 /* Constructor for a fixup at LOC affecting INSN's operand
kono
parents:
diff changeset
185 with index OPERAND_IDX. Record INSN_UID as the uid. */
kono
parents:
diff changeset
186 fixup_insn_uid (file_location loc, rtx insn, int operand_idx, int insn_uid)
kono
parents:
diff changeset
187 : operand_fixup (loc, insn, operand_idx),
kono
parents:
diff changeset
188 m_insn_uid (insn_uid)
kono
parents:
diff changeset
189 {}
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 void apply (function_reader *reader) const;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 private:
kono
parents:
diff changeset
194 int m_insn_uid;
kono
parents:
diff changeset
195 };
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 /* A concrete subclass of operand_fixup: fix up a
kono
parents:
diff changeset
198 NOTE_INSN_BASIC_BLOCK based on an integer block ID. */
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 class fixup_note_insn_basic_block : public operand_fixup
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 public:
kono
parents:
diff changeset
203 fixup_note_insn_basic_block (file_location loc, rtx insn, int operand_idx,
kono
parents:
diff changeset
204 int bb_idx)
kono
parents:
diff changeset
205 : operand_fixup (loc, insn, operand_idx),
kono
parents:
diff changeset
206 m_bb_idx (bb_idx)
kono
parents:
diff changeset
207 {}
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 void apply (function_reader *reader) const;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 private:
kono
parents:
diff changeset
212 int m_bb_idx;
kono
parents:
diff changeset
213 };
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 /* A concrete subclass of fixup (not operand_fixup): fix up
kono
parents:
diff changeset
216 the expr of an rtx (REG or MEM) based on a textual dump. */
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 class fixup_expr : public fixup
kono
parents:
diff changeset
219 {
kono
parents:
diff changeset
220 public:
kono
parents:
diff changeset
221 fixup_expr (file_location loc, rtx x, const char *desc)
kono
parents:
diff changeset
222 : fixup (loc, x),
kono
parents:
diff changeset
223 m_desc (xstrdup (desc))
kono
parents:
diff changeset
224 {}
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 ~fixup_expr () { free (m_desc); }
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 void apply (function_reader *reader) const;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 private:
kono
parents:
diff changeset
231 char *m_desc;
kono
parents:
diff changeset
232 };
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 /* Return a textual description of the operand of INSN with
kono
parents:
diff changeset
235 index OPERAND_IDX. */
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 static const char *
kono
parents:
diff changeset
238 get_operand_name (rtx insn, int operand_idx)
kono
parents:
diff changeset
239 {
kono
parents:
diff changeset
240 gcc_assert (is_a <rtx_insn *> (insn));
kono
parents:
diff changeset
241 switch (operand_idx)
kono
parents:
diff changeset
242 {
kono
parents:
diff changeset
243 case 0:
kono
parents:
diff changeset
244 return "PREV_INSN";
kono
parents:
diff changeset
245 case 1:
kono
parents:
diff changeset
246 return "NEXT_INSN";
kono
parents:
diff changeset
247 default:
kono
parents:
diff changeset
248 return NULL;
kono
parents:
diff changeset
249 }
kono
parents:
diff changeset
250 }
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 /* Fixup an rtx_insn * field based on an integer UID, as read by READER. */
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 void
kono
parents:
diff changeset
255 fixup_insn_uid::apply (function_reader *reader) const
kono
parents:
diff changeset
256 {
kono
parents:
diff changeset
257 rtx_insn **insn_from_uid = reader->get_insn_by_uid (m_insn_uid);
kono
parents:
diff changeset
258 if (insn_from_uid)
kono
parents:
diff changeset
259 XEXP (m_rtx, m_operand_idx) = *insn_from_uid;
kono
parents:
diff changeset
260 else
kono
parents:
diff changeset
261 {
kono
parents:
diff changeset
262 const char *op_name = get_operand_name (m_rtx, m_operand_idx);
kono
parents:
diff changeset
263 if (op_name)
kono
parents:
diff changeset
264 error_at (m_loc,
kono
parents:
diff changeset
265 "insn with UID %i not found for operand %i (`%s') of insn %i",
kono
parents:
diff changeset
266 m_insn_uid, m_operand_idx, op_name, INSN_UID (m_rtx));
kono
parents:
diff changeset
267 else
kono
parents:
diff changeset
268 error_at (m_loc,
kono
parents:
diff changeset
269 "insn with UID %i not found for operand %i of insn %i",
kono
parents:
diff changeset
270 m_insn_uid, m_operand_idx, INSN_UID (m_rtx));
kono
parents:
diff changeset
271 }
kono
parents:
diff changeset
272 }
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 /* Fix up a NOTE_INSN_BASIC_BLOCK based on an integer block ID. */
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 void
kono
parents:
diff changeset
277 fixup_note_insn_basic_block::apply (function_reader *) const
kono
parents:
diff changeset
278 {
kono
parents:
diff changeset
279 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, m_bb_idx);
kono
parents:
diff changeset
280 gcc_assert (bb);
kono
parents:
diff changeset
281 NOTE_BASIC_BLOCK (m_rtx) = bb;
kono
parents:
diff changeset
282 }
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 /* Fix up the expr of an rtx (REG or MEM) based on a textual dump
kono
parents:
diff changeset
285 read by READER. */
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 void
kono
parents:
diff changeset
288 fixup_expr::apply (function_reader *reader) const
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 tree expr = reader->parse_mem_expr (m_desc);
kono
parents:
diff changeset
291 switch (GET_CODE (m_rtx))
kono
parents:
diff changeset
292 {
kono
parents:
diff changeset
293 case REG:
kono
parents:
diff changeset
294 set_reg_attrs_for_decl_rtl (expr, m_rtx);
kono
parents:
diff changeset
295 break;
kono
parents:
diff changeset
296 case MEM:
kono
parents:
diff changeset
297 set_mem_expr (m_rtx, expr);
kono
parents:
diff changeset
298 break;
kono
parents:
diff changeset
299 default:
kono
parents:
diff changeset
300 gcc_unreachable ();
kono
parents:
diff changeset
301 }
kono
parents:
diff changeset
302 }
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 /* Strip trailing whitespace from DESC. */
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 static void
kono
parents:
diff changeset
307 strip_trailing_whitespace (char *desc)
kono
parents:
diff changeset
308 {
kono
parents:
diff changeset
309 char *terminator = desc + strlen (desc);
kono
parents:
diff changeset
310 while (desc < terminator)
kono
parents:
diff changeset
311 {
kono
parents:
diff changeset
312 terminator--;
kono
parents:
diff changeset
313 if (ISSPACE (*terminator))
kono
parents:
diff changeset
314 *terminator = '\0';
kono
parents:
diff changeset
315 else
kono
parents:
diff changeset
316 break;
kono
parents:
diff changeset
317 }
kono
parents:
diff changeset
318 }
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 /* Return the numeric value n for GET_NOTE_INSN_NAME (n) for STRING,
kono
parents:
diff changeset
321 or fail if STRING isn't recognized. */
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 static int
kono
parents:
diff changeset
324 parse_note_insn_name (const char *string)
kono
parents:
diff changeset
325 {
kono
parents:
diff changeset
326 for (int i = 0; i < NOTE_INSN_MAX; i++)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
327 if (strcmp (string, GET_NOTE_INSN_NAME (i)) == 0)
111
kono
parents:
diff changeset
328 return i;
kono
parents:
diff changeset
329 fatal_with_file_and_line ("unrecognized NOTE_INSN name: `%s'", string);
kono
parents:
diff changeset
330 }
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 /* Return the register number for NAME, or return -1 if it isn't
kono
parents:
diff changeset
333 recognized. */
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 static int
kono
parents:
diff changeset
336 lookup_reg_by_dump_name (const char *name)
kono
parents:
diff changeset
337 {
kono
parents:
diff changeset
338 for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
kono
parents:
diff changeset
339 if (reg_names[i][0]
kono
parents:
diff changeset
340 && ! strcmp (name, reg_names[i]))
kono
parents:
diff changeset
341 return i;
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 /* Also lookup virtuals. */
kono
parents:
diff changeset
344 if (!strcmp (name, "virtual-incoming-args"))
kono
parents:
diff changeset
345 return VIRTUAL_INCOMING_ARGS_REGNUM;
kono
parents:
diff changeset
346 if (!strcmp (name, "virtual-stack-vars"))
kono
parents:
diff changeset
347 return VIRTUAL_STACK_VARS_REGNUM;
kono
parents:
diff changeset
348 if (!strcmp (name, "virtual-stack-dynamic"))
kono
parents:
diff changeset
349 return VIRTUAL_STACK_DYNAMIC_REGNUM;
kono
parents:
diff changeset
350 if (!strcmp (name, "virtual-outgoing-args"))
kono
parents:
diff changeset
351 return VIRTUAL_OUTGOING_ARGS_REGNUM;
kono
parents:
diff changeset
352 if (!strcmp (name, "virtual-cfa"))
kono
parents:
diff changeset
353 return VIRTUAL_CFA_REGNUM;
kono
parents:
diff changeset
354 if (!strcmp (name, "virtual-preferred-stack-boundary"))
kono
parents:
diff changeset
355 return VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM;
kono
parents:
diff changeset
356 /* TODO: handle "virtual-reg-%d". */
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 /* In compact mode, pseudos are printed with '< and '>' wrapping the regno,
kono
parents:
diff changeset
359 offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
kono
parents:
diff changeset
360 first non-virtual pseudo is dumped as "<0>". */
kono
parents:
diff changeset
361 if (name[0] == '<' && name[strlen (name) - 1] == '>')
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 int dump_num = atoi (name + 1);
kono
parents:
diff changeset
364 return dump_num + LAST_VIRTUAL_REGISTER + 1;
kono
parents:
diff changeset
365 }
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 /* Not found. */
kono
parents:
diff changeset
368 return -1;
kono
parents:
diff changeset
369 }
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 /* class function_reader : public rtx_reader */
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 /* function_reader's constructor. */
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 function_reader::function_reader ()
kono
parents:
diff changeset
376 : rtx_reader (true),
kono
parents:
diff changeset
377 m_first_insn (NULL),
kono
parents:
diff changeset
378 m_name (NULL),
kono
parents:
diff changeset
379 m_have_crtl_directive (false),
kono
parents:
diff changeset
380 m_bb_to_insert_after (NULL),
kono
parents:
diff changeset
381 m_highest_bb_idx (EXIT_BLOCK)
kono
parents:
diff changeset
382 {
kono
parents:
diff changeset
383 }
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 /* function_reader's destructor. */
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 function_reader::~function_reader ()
kono
parents:
diff changeset
388 {
kono
parents:
diff changeset
389 int i;
kono
parents:
diff changeset
390 fixup *f;
kono
parents:
diff changeset
391 FOR_EACH_VEC_ELT (m_fixups, i, f)
kono
parents:
diff changeset
392 delete f;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 free (m_name);
kono
parents:
diff changeset
395 }
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 /* Implementation of rtx_reader::handle_unknown_directive,
kono
parents:
diff changeset
398 for parsing the remainder of a directive with name NAME
kono
parents:
diff changeset
399 seen at START_LOC.
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 Require a top-level "function" directive, as emitted by
kono
parents:
diff changeset
402 print_rtx_function, and parse it. */
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 void
kono
parents:
diff changeset
405 function_reader::handle_unknown_directive (file_location start_loc,
kono
parents:
diff changeset
406 const char *name)
kono
parents:
diff changeset
407 {
kono
parents:
diff changeset
408 if (strcmp (name, "function"))
kono
parents:
diff changeset
409 fatal_at (start_loc, "expected 'function'");
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 if (flag_lto)
kono
parents:
diff changeset
412 error ("%<__RTL%> function cannot be compiled with %<-flto%>");
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 parse_function ();
kono
parents:
diff changeset
415 }
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 /* Parse the output of print_rtx_function (or hand-written data in the
kono
parents:
diff changeset
418 same format), having already parsed the "(function" heading, and
kono
parents:
diff changeset
419 finishing immediately before the final ")".
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 The "param" and "crtl" clauses are optional. */
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 void
kono
parents:
diff changeset
424 function_reader::parse_function ()
kono
parents:
diff changeset
425 {
kono
parents:
diff changeset
426 m_name = xstrdup (read_string (0));
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 create_function ();
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 while (1)
kono
parents:
diff changeset
431 {
kono
parents:
diff changeset
432 int c = read_skip_spaces ();
kono
parents:
diff changeset
433 if (c == ')')
kono
parents:
diff changeset
434 {
kono
parents:
diff changeset
435 unread_char (c);
kono
parents:
diff changeset
436 break;
kono
parents:
diff changeset
437 }
kono
parents:
diff changeset
438 unread_char (c);
kono
parents:
diff changeset
439 require_char ('(');
kono
parents:
diff changeset
440 file_location loc = get_current_location ();
kono
parents:
diff changeset
441 struct md_name directive;
kono
parents:
diff changeset
442 read_name (&directive);
kono
parents:
diff changeset
443 if (strcmp (directive.string, "param") == 0)
kono
parents:
diff changeset
444 parse_param ();
kono
parents:
diff changeset
445 else if (strcmp (directive.string, "insn-chain") == 0)
kono
parents:
diff changeset
446 parse_insn_chain ();
kono
parents:
diff changeset
447 else if (strcmp (directive.string, "crtl") == 0)
kono
parents:
diff changeset
448 parse_crtl (loc);
kono
parents:
diff changeset
449 else
kono
parents:
diff changeset
450 fatal_with_file_and_line ("unrecognized directive: %s",
kono
parents:
diff changeset
451 directive.string);
kono
parents:
diff changeset
452 }
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 handle_insn_uids ();
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 apply_fixups ();
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 /* Rebuild the JUMP_LABEL field of any JUMP_INSNs in the chain, and the
kono
parents:
diff changeset
459 LABEL_NUSES of any CODE_LABELs.
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 This has to happen after apply_fixups, since only after then do
kono
parents:
diff changeset
462 LABEL_REFs have their label_ref_label set up. */
kono
parents:
diff changeset
463 rebuild_jump_labels (get_insns ());
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 crtl->init_stack_alignment ();
kono
parents:
diff changeset
466 }
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 /* Set up state for the function *before* fixups are applied.
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 Create "cfun" and a decl for the function.
kono
parents:
diff changeset
471 By default, every function decl is hardcoded as
kono
parents:
diff changeset
472 int test_1 (int i, int j, int k);
kono
parents:
diff changeset
473 Set up various other state:
kono
parents:
diff changeset
474 - the cfg and basic blocks (edges are created later, *after* fixups
kono
parents:
diff changeset
475 are applied).
kono
parents:
diff changeset
476 - add the function to the callgraph. */
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 void
kono
parents:
diff changeset
479 function_reader::create_function ()
kono
parents:
diff changeset
480 {
kono
parents:
diff changeset
481 /* We start in cfgrtl mode, rather than cfglayout mode. */
kono
parents:
diff changeset
482 rtl_register_cfg_hooks ();
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 /* When run from selftests or "rtl1", cfun is NULL.
kono
parents:
diff changeset
485 When run from "cc1" for a C function tagged with __RTL, cfun is the
kono
parents:
diff changeset
486 tagged function. */
kono
parents:
diff changeset
487 if (!cfun)
kono
parents:
diff changeset
488 {
kono
parents:
diff changeset
489 tree fn_name = get_identifier (m_name ? m_name : "test_1");
kono
parents:
diff changeset
490 tree int_type = integer_type_node;
kono
parents:
diff changeset
491 tree return_type = int_type;
kono
parents:
diff changeset
492 tree arg_types[3] = {int_type, int_type, int_type};
kono
parents:
diff changeset
493 tree fn_type = build_function_type_array (return_type, 3, arg_types);
kono
parents:
diff changeset
494 tree fndecl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn_name, fn_type);
kono
parents:
diff changeset
495 tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
kono
parents:
diff changeset
496 return_type);
kono
parents:
diff changeset
497 DECL_ARTIFICIAL (resdecl) = 1;
kono
parents:
diff changeset
498 DECL_IGNORED_P (resdecl) = 1;
kono
parents:
diff changeset
499 DECL_RESULT (fndecl) = resdecl;
kono
parents:
diff changeset
500 allocate_struct_function (fndecl, false);
kono
parents:
diff changeset
501 /* This sets cfun. */
kono
parents:
diff changeset
502 current_function_decl = fndecl;
kono
parents:
diff changeset
503 }
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 gcc_assert (cfun);
kono
parents:
diff changeset
506 gcc_assert (current_function_decl);
kono
parents:
diff changeset
507 tree fndecl = current_function_decl;
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 /* Mark this function as being specified as __RTL. */
kono
parents:
diff changeset
510 cfun->curr_properties |= PROP_rtl;
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 /* cc1 normally inits DECL_INITIAL (fndecl) to be error_mark_node.
kono
parents:
diff changeset
513 Create a dummy block for it. */
kono
parents:
diff changeset
514 DECL_INITIAL (fndecl) = make_node (BLOCK);
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 cfun->curr_properties = (PROP_cfg | PROP_rtl);
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 /* Do we need this to force cgraphunit.c to output the function? */
kono
parents:
diff changeset
519 DECL_EXTERNAL (fndecl) = 0;
kono
parents:
diff changeset
520 DECL_PRESERVE_P (fndecl) = 1;
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 /* Add to cgraph. */
kono
parents:
diff changeset
523 cgraph_node::finalize_function (fndecl, false);
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 /* Create bare-bones cfg. This creates the entry and exit blocks. */
kono
parents:
diff changeset
526 init_empty_tree_cfg_for_function (cfun);
kono
parents:
diff changeset
527 ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
kono
parents:
diff changeset
528 EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
kono
parents:
diff changeset
529 init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
kono
parents:
diff changeset
530 init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
kono
parents:
diff changeset
531 m_bb_to_insert_after = ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 }
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 /* Look within the the params of FNDECL for a param named NAME.
kono
parents:
diff changeset
536 Return NULL_TREE if one isn't found. */
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 static tree
kono
parents:
diff changeset
539 find_param_by_name (tree fndecl, const char *name)
kono
parents:
diff changeset
540 {
kono
parents:
diff changeset
541 for (tree arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg))
kono
parents:
diff changeset
542 if (id_equal (DECL_NAME (arg), name))
kono
parents:
diff changeset
543 return arg;
kono
parents:
diff changeset
544 return NULL_TREE;
kono
parents:
diff changeset
545 }
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 /* Parse the content of a "param" directive, having already parsed the
kono
parents:
diff changeset
548 "(param". Consume the trailing ')'. */
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 void
kono
parents:
diff changeset
551 function_reader::parse_param ()
kono
parents:
diff changeset
552 {
kono
parents:
diff changeset
553 require_char_ws ('"');
kono
parents:
diff changeset
554 file_location loc = get_current_location ();
kono
parents:
diff changeset
555 char *name = read_quoted_string ();
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 /* Lookup param by name. */
kono
parents:
diff changeset
558 tree t_param = find_param_by_name (cfun->decl, name);
kono
parents:
diff changeset
559 if (!t_param)
kono
parents:
diff changeset
560 fatal_at (loc, "param not found: %s", name);
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 /* Parse DECL_RTL. */
kono
parents:
diff changeset
563 require_char_ws ('(');
kono
parents:
diff changeset
564 require_word_ws ("DECL_RTL");
kono
parents:
diff changeset
565 DECL_WRTL_CHECK (t_param)->decl_with_rtl.rtl = parse_rtx ();
kono
parents:
diff changeset
566 require_char_ws (')');
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 /* Parse DECL_RTL_INCOMING. */
kono
parents:
diff changeset
569 require_char_ws ('(');
kono
parents:
diff changeset
570 require_word_ws ("DECL_RTL_INCOMING");
kono
parents:
diff changeset
571 DECL_INCOMING_RTL (t_param) = parse_rtx ();
kono
parents:
diff changeset
572 require_char_ws (')');
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 require_char_ws (')');
kono
parents:
diff changeset
575 }
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 /* Parse zero or more child insn elements within an
kono
parents:
diff changeset
578 "insn-chain" element. Consume the trailing ')'. */
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 void
kono
parents:
diff changeset
581 function_reader::parse_insn_chain ()
kono
parents:
diff changeset
582 {
kono
parents:
diff changeset
583 while (1)
kono
parents:
diff changeset
584 {
kono
parents:
diff changeset
585 int c = read_skip_spaces ();
kono
parents:
diff changeset
586 file_location loc = get_current_location ();
kono
parents:
diff changeset
587 if (c == ')')
kono
parents:
diff changeset
588 break;
kono
parents:
diff changeset
589 else if (c == '(')
kono
parents:
diff changeset
590 {
kono
parents:
diff changeset
591 struct md_name directive;
kono
parents:
diff changeset
592 read_name (&directive);
kono
parents:
diff changeset
593 if (strcmp (directive.string, "block") == 0)
kono
parents:
diff changeset
594 parse_block ();
kono
parents:
diff changeset
595 else
kono
parents:
diff changeset
596 parse_insn (loc, directive.string);
kono
parents:
diff changeset
597 }
kono
parents:
diff changeset
598 else
kono
parents:
diff changeset
599 fatal_at (loc, "expected '(' or ')'");
kono
parents:
diff changeset
600 }
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 create_edges ();
kono
parents:
diff changeset
603 }
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 /* Parse zero or more child directives (edges and insns) within a
kono
parents:
diff changeset
606 "block" directive, having already parsed the "(block " heading.
kono
parents:
diff changeset
607 Consume the trailing ')'. */
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 void
kono
parents:
diff changeset
610 function_reader::parse_block ()
kono
parents:
diff changeset
611 {
kono
parents:
diff changeset
612 /* Parse the index value from the dump. This will be an integer;
kono
parents:
diff changeset
613 we don't support "entry" or "exit" here (unlike for edges). */
kono
parents:
diff changeset
614 struct md_name name;
kono
parents:
diff changeset
615 read_name (&name);
kono
parents:
diff changeset
616 int bb_idx = atoi (name.string);
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 /* The term "index" has two meanings for basic blocks in a CFG:
kono
parents:
diff changeset
619 (a) the "index" field within struct basic_block_def.
kono
parents:
diff changeset
620 (b) the index of a basic_block within the cfg's x_basic_block_info
kono
parents:
diff changeset
621 vector, as accessed via BASIC_BLOCK_FOR_FN.
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 These can get out-of-sync when basic blocks are optimized away.
kono
parents:
diff changeset
624 They get back in sync by "compact_blocks".
kono
parents:
diff changeset
625 We reconstruct cfun->cfg->x_basic_block_info->m_vecdata with NULL
kono
parents:
diff changeset
626 values in it for any missing basic blocks, so that (a) == (b) for
kono
parents:
diff changeset
627 all of the blocks we create. The doubly-linked list of basic
kono
parents:
diff changeset
628 blocks (next_bb/prev_bb) skips over these "holes". */
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 if (m_highest_bb_idx < bb_idx)
kono
parents:
diff changeset
631 m_highest_bb_idx = bb_idx;
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 size_t new_size = m_highest_bb_idx + 1;
kono
parents:
diff changeset
634 if (basic_block_info_for_fn (cfun)->length () < new_size)
kono
parents:
diff changeset
635 vec_safe_grow_cleared (basic_block_info_for_fn (cfun), new_size);
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 last_basic_block_for_fn (cfun) = new_size;
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 /* Create the basic block.
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 We can't call create_basic_block and use the regular RTL block-creation
kono
parents:
diff changeset
642 hooks, since this creates NOTE_INSN_BASIC_BLOCK instances. We don't
kono
parents:
diff changeset
643 want to do that; we want to use the notes we were provided with. */
kono
parents:
diff changeset
644 basic_block bb = alloc_block ();
kono
parents:
diff changeset
645 init_rtl_bb_info (bb);
kono
parents:
diff changeset
646 bb->index = bb_idx;
kono
parents:
diff changeset
647 bb->flags = BB_NEW | BB_RTL;
kono
parents:
diff changeset
648 link_block (bb, m_bb_to_insert_after);
kono
parents:
diff changeset
649 m_bb_to_insert_after = bb;
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 n_basic_blocks_for_fn (cfun)++;
kono
parents:
diff changeset
652 SET_BASIC_BLOCK_FOR_FN (cfun, bb_idx, bb);
kono
parents:
diff changeset
653 BB_SET_PARTITION (bb, BB_UNPARTITIONED);
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 /* Handle insns, edge-from and edge-to directives. */
kono
parents:
diff changeset
656 while (1)
kono
parents:
diff changeset
657 {
kono
parents:
diff changeset
658 int c = read_skip_spaces ();
kono
parents:
diff changeset
659 file_location loc = get_current_location ();
kono
parents:
diff changeset
660 if (c == ')')
kono
parents:
diff changeset
661 break;
kono
parents:
diff changeset
662 else if (c == '(')
kono
parents:
diff changeset
663 {
kono
parents:
diff changeset
664 struct md_name directive;
kono
parents:
diff changeset
665 read_name (&directive);
kono
parents:
diff changeset
666 if (strcmp (directive.string, "edge-from") == 0)
kono
parents:
diff changeset
667 parse_edge (bb, true);
kono
parents:
diff changeset
668 else if (strcmp (directive.string, "edge-to") == 0)
kono
parents:
diff changeset
669 parse_edge (bb, false);
kono
parents:
diff changeset
670 else
kono
parents:
diff changeset
671 {
kono
parents:
diff changeset
672 rtx_insn *insn = parse_insn (loc, directive.string);
kono
parents:
diff changeset
673 set_block_for_insn (insn, bb);
kono
parents:
diff changeset
674 if (!BB_HEAD (bb))
kono
parents:
diff changeset
675 BB_HEAD (bb) = insn;
kono
parents:
diff changeset
676 BB_END (bb) = insn;
kono
parents:
diff changeset
677 }
kono
parents:
diff changeset
678 }
kono
parents:
diff changeset
679 else
kono
parents:
diff changeset
680 fatal_at (loc, "expected '(' or ')'");
kono
parents:
diff changeset
681 }
kono
parents:
diff changeset
682 }
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 /* Subroutine of function_reader::parse_edge.
kono
parents:
diff changeset
685 Parse a basic block index, handling "entry" and "exit". */
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 int
kono
parents:
diff changeset
688 function_reader::parse_bb_idx ()
kono
parents:
diff changeset
689 {
kono
parents:
diff changeset
690 struct md_name name;
kono
parents:
diff changeset
691 read_name (&name);
kono
parents:
diff changeset
692 if (strcmp (name.string, "entry") == 0)
kono
parents:
diff changeset
693 return ENTRY_BLOCK;
kono
parents:
diff changeset
694 if (strcmp (name.string, "exit") == 0)
kono
parents:
diff changeset
695 return EXIT_BLOCK;
kono
parents:
diff changeset
696 return atoi (name.string);
kono
parents:
diff changeset
697 }
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 /* Subroutine of parse_edge_flags.
kono
parents:
diff changeset
700 Parse TOK, a token such as "FALLTHRU", converting to the flag value.
kono
parents:
diff changeset
701 Issue an error if the token is unrecognized. */
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 static int
kono
parents:
diff changeset
704 parse_edge_flag_token (const char *tok)
kono
parents:
diff changeset
705 {
kono
parents:
diff changeset
706 #define DEF_EDGE_FLAG(NAME,IDX) \
kono
parents:
diff changeset
707 do { \
kono
parents:
diff changeset
708 if (strcmp (tok, #NAME) == 0) \
kono
parents:
diff changeset
709 return EDGE_##NAME; \
kono
parents:
diff changeset
710 } while (0);
kono
parents:
diff changeset
711 #include "cfg-flags.def"
kono
parents:
diff changeset
712 #undef DEF_EDGE_FLAG
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
713 error ("unrecognized edge flag: %qs", tok);
111
kono
parents:
diff changeset
714 return 0;
kono
parents:
diff changeset
715 }
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 /* Subroutine of function_reader::parse_edge.
kono
parents:
diff changeset
718 Parse STR and convert to a flag value (or issue an error).
kono
parents:
diff changeset
719 The parser uses strtok and hence modifiers STR in-place. */
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 static int
kono
parents:
diff changeset
722 parse_edge_flags (char *str)
kono
parents:
diff changeset
723 {
kono
parents:
diff changeset
724 int result = 0;
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 char *tok = strtok (str, "| ");
kono
parents:
diff changeset
727 while (tok)
kono
parents:
diff changeset
728 {
kono
parents:
diff changeset
729 result |= parse_edge_flag_token (tok);
kono
parents:
diff changeset
730 tok = strtok (NULL, "| ");
kono
parents:
diff changeset
731 }
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 return result;
kono
parents:
diff changeset
734 }
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 /* Parse an "edge-from" or "edge-to" directive within the "block"
kono
parents:
diff changeset
737 directive for BLOCK, having already parsed the "(edge" heading.
kono
parents:
diff changeset
738 Consume the final ")". Record the edge within m_deferred_edges.
kono
parents:
diff changeset
739 FROM is true for an "edge-from" directive, false for an "edge-to"
kono
parents:
diff changeset
740 directive. */
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 void
kono
parents:
diff changeset
743 function_reader::parse_edge (basic_block block, bool from)
kono
parents:
diff changeset
744 {
kono
parents:
diff changeset
745 gcc_assert (block);
kono
parents:
diff changeset
746 int this_bb_idx = block->index;
kono
parents:
diff changeset
747 file_location loc = get_current_location ();
kono
parents:
diff changeset
748 int other_bb_idx = parse_bb_idx ();
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 /* "(edge-from 2)" means src = 2, dest = this_bb_idx, whereas
kono
parents:
diff changeset
751 "(edge-to 3)" means src = this_bb_idx, dest = 3. */
kono
parents:
diff changeset
752 int src_idx = from ? other_bb_idx : this_bb_idx;
kono
parents:
diff changeset
753 int dest_idx = from ? this_bb_idx : other_bb_idx;
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 /* Optional "(flags)". */
kono
parents:
diff changeset
756 int flags = 0;
kono
parents:
diff changeset
757 int c = read_skip_spaces ();
kono
parents:
diff changeset
758 if (c == '(')
kono
parents:
diff changeset
759 {
kono
parents:
diff changeset
760 require_word_ws ("flags");
kono
parents:
diff changeset
761 require_char_ws ('"');
kono
parents:
diff changeset
762 char *str = read_quoted_string ();
kono
parents:
diff changeset
763 flags = parse_edge_flags (str);
kono
parents:
diff changeset
764 require_char_ws (')');
kono
parents:
diff changeset
765 }
kono
parents:
diff changeset
766 else
kono
parents:
diff changeset
767 unread_char (c);
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 require_char_ws (')');
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 /* This BB already exists, but the other BB might not yet.
kono
parents:
diff changeset
772 For now, save the edges, and create them at the end of insn-chain
kono
parents:
diff changeset
773 processing. */
kono
parents:
diff changeset
774 /* For now, only process the (edge-from) to this BB, and (edge-to)
kono
parents:
diff changeset
775 that go to the exit block.
kono
parents:
diff changeset
776 FIXME: we don't yet verify that the edge-from and edge-to directives
kono
parents:
diff changeset
777 are consistent. */
kono
parents:
diff changeset
778 if (from || dest_idx == EXIT_BLOCK)
kono
parents:
diff changeset
779 m_deferred_edges.safe_push (deferred_edge (loc, src_idx, dest_idx, flags));
kono
parents:
diff changeset
780 }
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 /* Parse an rtx instruction, having parsed the opening and parenthesis, and
kono
parents:
diff changeset
783 name NAME, seen at START_LOC, by calling read_rtx_code, calling
kono
parents:
diff changeset
784 set_first_insn and set_last_insn as appropriate, and
kono
parents:
diff changeset
785 adding the insn to the insn chain.
kono
parents:
diff changeset
786 Consume the trailing ')'. */
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 rtx_insn *
kono
parents:
diff changeset
789 function_reader::parse_insn (file_location start_loc, const char *name)
kono
parents:
diff changeset
790 {
kono
parents:
diff changeset
791 rtx x = read_rtx_code (name);
kono
parents:
diff changeset
792 if (!x)
kono
parents:
diff changeset
793 fatal_at (start_loc, "expected insn type; got '%s'", name);
kono
parents:
diff changeset
794 rtx_insn *insn = dyn_cast <rtx_insn *> (x);
kono
parents:
diff changeset
795 if (!insn)
kono
parents:
diff changeset
796 fatal_at (start_loc, "expected insn type; got '%s'", name);
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 /* Consume the trailing ')'. */
kono
parents:
diff changeset
799 require_char_ws (')');
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 rtx_insn *last_insn = get_last_insn ();
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 /* Add "insn" to the insn chain. */
kono
parents:
diff changeset
804 if (last_insn)
kono
parents:
diff changeset
805 {
kono
parents:
diff changeset
806 gcc_assert (NEXT_INSN (last_insn) == NULL);
kono
parents:
diff changeset
807 SET_NEXT_INSN (last_insn) = insn;
kono
parents:
diff changeset
808 }
kono
parents:
diff changeset
809 SET_PREV_INSN (insn) = last_insn;
kono
parents:
diff changeset
810
kono
parents:
diff changeset
811 /* Add it to the sequence. */
kono
parents:
diff changeset
812 set_last_insn (insn);
kono
parents:
diff changeset
813 if (!m_first_insn)
kono
parents:
diff changeset
814 {
kono
parents:
diff changeset
815 m_first_insn = insn;
kono
parents:
diff changeset
816 set_first_insn (insn);
kono
parents:
diff changeset
817 }
kono
parents:
diff changeset
818
kono
parents:
diff changeset
819 if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
kono
parents:
diff changeset
820 maybe_set_max_label_num (label);
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 return insn;
kono
parents:
diff changeset
823 }
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 /* Postprocessing subroutine for parse_insn_chain: all the basic blocks
kono
parents:
diff changeset
826 should have been created by now; create the edges that were seen. */
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 void
kono
parents:
diff changeset
829 function_reader::create_edges ()
kono
parents:
diff changeset
830 {
kono
parents:
diff changeset
831 int i;
kono
parents:
diff changeset
832 deferred_edge *de;
kono
parents:
diff changeset
833 FOR_EACH_VEC_ELT (m_deferred_edges, i, de)
kono
parents:
diff changeset
834 {
kono
parents:
diff changeset
835 /* The BBs should already have been created by parse_block. */
kono
parents:
diff changeset
836 basic_block src = BASIC_BLOCK_FOR_FN (cfun, de->m_src_bb_idx);
kono
parents:
diff changeset
837 if (!src)
kono
parents:
diff changeset
838 fatal_at (de->m_loc, "error: block index %i not found",
kono
parents:
diff changeset
839 de->m_src_bb_idx);
kono
parents:
diff changeset
840 basic_block dst = BASIC_BLOCK_FOR_FN (cfun, de->m_dest_bb_idx);
kono
parents:
diff changeset
841 if (!dst)
kono
parents:
diff changeset
842 fatal_at (de->m_loc, "error: block with index %i not found",
kono
parents:
diff changeset
843 de->m_dest_bb_idx);
kono
parents:
diff changeset
844 unchecked_make_edge (src, dst, de->m_flags);
kono
parents:
diff changeset
845 }
kono
parents:
diff changeset
846 }
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 /* Parse a "crtl" directive, having already parsed the "(crtl" heading
kono
parents:
diff changeset
849 at location LOC.
kono
parents:
diff changeset
850 Consume the final ")". */
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 void
kono
parents:
diff changeset
853 function_reader::parse_crtl (file_location loc)
kono
parents:
diff changeset
854 {
kono
parents:
diff changeset
855 if (m_have_crtl_directive)
kono
parents:
diff changeset
856 error_at (loc, "more than one 'crtl' directive");
kono
parents:
diff changeset
857 m_have_crtl_directive = true;
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 /* return_rtx. */
kono
parents:
diff changeset
860 require_char_ws ('(');
kono
parents:
diff changeset
861 require_word_ws ("return_rtx");
kono
parents:
diff changeset
862 crtl->return_rtx = parse_rtx ();
kono
parents:
diff changeset
863 require_char_ws (')');
kono
parents:
diff changeset
864
kono
parents:
diff changeset
865 require_char_ws (')');
kono
parents:
diff changeset
866 }
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 /* Parse operand IDX of X, returning X, or an equivalent rtx
kono
parents:
diff changeset
869 expression (for consolidating singletons).
kono
parents:
diff changeset
870 This is an overridden implementation of rtx_reader::read_rtx_operand for
kono
parents:
diff changeset
871 function_reader, handling various extra data printed by print_rtx,
kono
parents:
diff changeset
872 and sometimes calling the base class implementation. */
kono
parents:
diff changeset
873
kono
parents:
diff changeset
874 rtx
kono
parents:
diff changeset
875 function_reader::read_rtx_operand (rtx x, int idx)
kono
parents:
diff changeset
876 {
kono
parents:
diff changeset
877 RTX_CODE code = GET_CODE (x);
kono
parents:
diff changeset
878 const char *format_ptr = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
879 const char format_char = format_ptr[idx];
kono
parents:
diff changeset
880 struct md_name name;
kono
parents:
diff changeset
881
kono
parents:
diff changeset
882 /* Override the regular parser for some format codes. */
kono
parents:
diff changeset
883 switch (format_char)
kono
parents:
diff changeset
884 {
kono
parents:
diff changeset
885 case 'e':
kono
parents:
diff changeset
886 if (idx == 7 && CALL_P (x))
kono
parents:
diff changeset
887 {
kono
parents:
diff changeset
888 m_in_call_function_usage = true;
kono
parents:
diff changeset
889 return rtx_reader::read_rtx_operand (x, idx);
kono
parents:
diff changeset
890 m_in_call_function_usage = false;
kono
parents:
diff changeset
891 }
kono
parents:
diff changeset
892 else
kono
parents:
diff changeset
893 return rtx_reader::read_rtx_operand (x, idx);
kono
parents:
diff changeset
894 break;
kono
parents:
diff changeset
895
kono
parents:
diff changeset
896 case 'u':
kono
parents:
diff changeset
897 read_rtx_operand_u (x, idx);
kono
parents:
diff changeset
898 /* Don't run regular parser for 'u'. */
kono
parents:
diff changeset
899 return x;
kono
parents:
diff changeset
900
kono
parents:
diff changeset
901 case 'i':
kono
parents:
diff changeset
902 case 'n':
kono
parents:
diff changeset
903 read_rtx_operand_i_or_n (x, idx, format_char);
kono
parents:
diff changeset
904 /* Don't run regular parser for these codes. */
kono
parents:
diff changeset
905 return x;
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907 case 'B':
kono
parents:
diff changeset
908 gcc_assert (is_compact ());
kono
parents:
diff changeset
909 /* Compact mode doesn't store BBs. */
kono
parents:
diff changeset
910 /* Don't run regular parser. */
kono
parents:
diff changeset
911 return x;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 case 'r':
kono
parents:
diff changeset
914 /* Don't run regular parser for 'r'. */
kono
parents:
diff changeset
915 return read_rtx_operand_r (x);
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 default:
kono
parents:
diff changeset
918 break;
kono
parents:
diff changeset
919 }
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 /* Call base class implementation. */
kono
parents:
diff changeset
922 x = rtx_reader::read_rtx_operand (x, idx);
kono
parents:
diff changeset
923
kono
parents:
diff changeset
924 /* Handle any additional parsing needed to handle what the dump
kono
parents:
diff changeset
925 could contain. */
kono
parents:
diff changeset
926 switch (format_char)
kono
parents:
diff changeset
927 {
kono
parents:
diff changeset
928 case '0':
kono
parents:
diff changeset
929 x = extra_parsing_for_operand_code_0 (x, idx);
kono
parents:
diff changeset
930 break;
kono
parents:
diff changeset
931
kono
parents:
diff changeset
932 case 'w':
kono
parents:
diff changeset
933 if (!is_compact ())
kono
parents:
diff changeset
934 {
kono
parents:
diff changeset
935 /* Strip away the redundant hex dump of the value. */
kono
parents:
diff changeset
936 require_char_ws ('[');
kono
parents:
diff changeset
937 read_name (&name);
kono
parents:
diff changeset
938 require_char_ws (']');
kono
parents:
diff changeset
939 }
kono
parents:
diff changeset
940 break;
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 default:
kono
parents:
diff changeset
943 break;
kono
parents:
diff changeset
944 }
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 return x;
kono
parents:
diff changeset
947 }
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 /* Parse operand IDX of X, of code 'u', when reading function dumps.
kono
parents:
diff changeset
950
kono
parents:
diff changeset
951 The RTL file recorded the ID of an insn (or 0 for NULL); we
kono
parents:
diff changeset
952 must store this as a pointer, but the insn might not have
kono
parents:
diff changeset
953 been loaded yet. Store the ID away for now, via a fixup. */
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 void
kono
parents:
diff changeset
956 function_reader::read_rtx_operand_u (rtx x, int idx)
kono
parents:
diff changeset
957 {
kono
parents:
diff changeset
958 /* In compact mode, the PREV/NEXT insn uids are not dumped, so skip
kono
parents:
diff changeset
959 the "uu" when reading. */
kono
parents:
diff changeset
960 if (is_compact () && GET_CODE (x) != LABEL_REF)
kono
parents:
diff changeset
961 return;
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 struct md_name name;
kono
parents:
diff changeset
964 file_location loc = read_name (&name);
kono
parents:
diff changeset
965 int insn_id = atoi (name.string);
kono
parents:
diff changeset
966 if (insn_id)
kono
parents:
diff changeset
967 add_fixup_insn_uid (loc, x, idx, insn_id);
kono
parents:
diff changeset
968 }
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 /* Read a name, looking for a match against a string found in array
kono
parents:
diff changeset
971 STRINGS of size NUM_VALUES.
kono
parents:
diff changeset
972 Return the index of the the matched string, or emit an error. */
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 int
kono
parents:
diff changeset
975 function_reader::parse_enum_value (int num_values, const char *const *strings)
kono
parents:
diff changeset
976 {
kono
parents:
diff changeset
977 struct md_name name;
kono
parents:
diff changeset
978 read_name (&name);
kono
parents:
diff changeset
979 for (int i = 0; i < num_values; i++)
kono
parents:
diff changeset
980 {
kono
parents:
diff changeset
981 if (strcmp (name.string, strings[i]) == 0)
kono
parents:
diff changeset
982 return i;
kono
parents:
diff changeset
983 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
984 error ("unrecognized enum value: %qs", name.string);
111
kono
parents:
diff changeset
985 return 0;
kono
parents:
diff changeset
986 }
kono
parents:
diff changeset
987
kono
parents:
diff changeset
988 /* Parse operand IDX of X, of code 'i' or 'n' (as specified by FORMAT_CHAR).
kono
parents:
diff changeset
989 Special-cased handling of these, for reading function dumps. */
kono
parents:
diff changeset
990
kono
parents:
diff changeset
991 void
kono
parents:
diff changeset
992 function_reader::read_rtx_operand_i_or_n (rtx x, int idx,
kono
parents:
diff changeset
993 char format_char)
kono
parents:
diff changeset
994 {
kono
parents:
diff changeset
995 /* Handle some of the extra information that print_rtx
kono
parents:
diff changeset
996 can write out for these cases. */
kono
parents:
diff changeset
997 /* print_rtx only writes out operand 5 for notes
kono
parents:
diff changeset
998 for NOTE_KIND values NOTE_INSN_DELETED_LABEL
kono
parents:
diff changeset
999 and NOTE_INSN_DELETED_DEBUG_LABEL. */
kono
parents:
diff changeset
1000 if (idx == 5 && NOTE_P (x))
kono
parents:
diff changeset
1001 return;
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 if (idx == 4 && INSN_P (x))
kono
parents:
diff changeset
1004 {
kono
parents:
diff changeset
1005 maybe_read_location (as_a <rtx_insn *> (x));
kono
parents:
diff changeset
1006 return;
kono
parents:
diff changeset
1007 }
kono
parents:
diff changeset
1008
kono
parents:
diff changeset
1009 /* INSN_CODEs aren't printed in compact mode, so don't attempt to
kono
parents:
diff changeset
1010 parse them. */
kono
parents:
diff changeset
1011 if (is_compact ()
kono
parents:
diff changeset
1012 && INSN_P (x)
kono
parents:
diff changeset
1013 && &INSN_CODE (x) == &XINT (x, idx))
kono
parents:
diff changeset
1014 {
kono
parents:
diff changeset
1015 INSN_CODE (x) = -1;
kono
parents:
diff changeset
1016 return;
kono
parents:
diff changeset
1017 }
kono
parents:
diff changeset
1018
kono
parents:
diff changeset
1019 /* Handle UNSPEC and UNSPEC_VOLATILE's operand 1. */
kono
parents:
diff changeset
1020 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
kono
parents:
diff changeset
1021 if (idx == 1
kono
parents:
diff changeset
1022 && GET_CODE (x) == UNSPEC_VOLATILE)
kono
parents:
diff changeset
1023 {
kono
parents:
diff changeset
1024 XINT (x, 1)
kono
parents:
diff changeset
1025 = parse_enum_value (NUM_UNSPECV_VALUES, unspecv_strings);
kono
parents:
diff changeset
1026 return;
kono
parents:
diff changeset
1027 }
kono
parents:
diff changeset
1028 #endif
kono
parents:
diff changeset
1029 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
kono
parents:
diff changeset
1030 if (idx == 1
kono
parents:
diff changeset
1031 && (GET_CODE (x) == UNSPEC
kono
parents:
diff changeset
1032 || GET_CODE (x) == UNSPEC_VOLATILE))
kono
parents:
diff changeset
1033 {
kono
parents:
diff changeset
1034 XINT (x, 1)
kono
parents:
diff changeset
1035 = parse_enum_value (NUM_UNSPEC_VALUES, unspec_strings);
kono
parents:
diff changeset
1036 return;
kono
parents:
diff changeset
1037 }
kono
parents:
diff changeset
1038 #endif
kono
parents:
diff changeset
1039
kono
parents:
diff changeset
1040 struct md_name name;
kono
parents:
diff changeset
1041 read_name (&name);
kono
parents:
diff changeset
1042 int value;
kono
parents:
diff changeset
1043 if (format_char == 'n')
kono
parents:
diff changeset
1044 value = parse_note_insn_name (name.string);
kono
parents:
diff changeset
1045 else
kono
parents:
diff changeset
1046 value = atoi (name.string);
kono
parents:
diff changeset
1047 XINT (x, idx) = value;
kono
parents:
diff changeset
1048 }
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 /* Parse the 'r' operand of X, returning X, or an equivalent rtx
kono
parents:
diff changeset
1051 expression (for consolidating singletons).
kono
parents:
diff changeset
1052 Special-cased handling of code 'r' for reading function dumps. */
kono
parents:
diff changeset
1053
kono
parents:
diff changeset
1054 rtx
kono
parents:
diff changeset
1055 function_reader::read_rtx_operand_r (rtx x)
kono
parents:
diff changeset
1056 {
kono
parents:
diff changeset
1057 struct md_name name;
kono
parents:
diff changeset
1058 file_location loc = read_name (&name);
kono
parents:
diff changeset
1059 int regno = lookup_reg_by_dump_name (name.string);
kono
parents:
diff changeset
1060 if (regno == -1)
kono
parents:
diff changeset
1061 fatal_at (loc, "unrecognized register: '%s'", name.string);
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 set_regno_raw (x, regno, 1);
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 /* Consolidate singletons. */
kono
parents:
diff changeset
1066 x = consolidate_singletons (x);
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 ORIGINAL_REGNO (x) = regno;
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 /* Parse extra stuff at end of 'r'.
kono
parents:
diff changeset
1071 We may have zero, one, or two sections marked by square
kono
parents:
diff changeset
1072 brackets. */
kono
parents:
diff changeset
1073 int ch = read_skip_spaces ();
kono
parents:
diff changeset
1074 bool expect_original_regno = false;
kono
parents:
diff changeset
1075 if (ch == '[')
kono
parents:
diff changeset
1076 {
kono
parents:
diff changeset
1077 file_location loc = get_current_location ();
kono
parents:
diff changeset
1078 char *desc = read_until ("]", true);
kono
parents:
diff changeset
1079 strip_trailing_whitespace (desc);
kono
parents:
diff changeset
1080 const char *desc_start = desc;
kono
parents:
diff changeset
1081 /* If ORIGINAL_REGNO (rtx) != regno, we will have:
kono
parents:
diff changeset
1082 "orig:%i", ORIGINAL_REGNO (rtx).
kono
parents:
diff changeset
1083 Consume it, we don't set ORIGINAL_REGNO, since we can
kono
parents:
diff changeset
1084 get that from the 2nd copy later. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1085 if (strncmp (desc, "orig:", 5) == 0)
111
kono
parents:
diff changeset
1086 {
kono
parents:
diff changeset
1087 expect_original_regno = true;
kono
parents:
diff changeset
1088 desc_start += 5;
kono
parents:
diff changeset
1089 /* Skip to any whitespace following the integer. */
kono
parents:
diff changeset
1090 const char *space = strchr (desc_start, ' ');
kono
parents:
diff changeset
1091 if (space)
kono
parents:
diff changeset
1092 desc_start = space + 1;
kono
parents:
diff changeset
1093 }
kono
parents:
diff changeset
1094 /* Any remaining text may be the REG_EXPR. Alternatively we have
kono
parents:
diff changeset
1095 no REG_ATTRS, and instead we have ORIGINAL_REGNO. */
kono
parents:
diff changeset
1096 if (ISDIGIT (*desc_start))
kono
parents:
diff changeset
1097 {
kono
parents:
diff changeset
1098 /* Assume we have ORIGINAL_REGNO. */
kono
parents:
diff changeset
1099 ORIGINAL_REGNO (x) = atoi (desc_start);
kono
parents:
diff changeset
1100 }
kono
parents:
diff changeset
1101 else
kono
parents:
diff changeset
1102 {
kono
parents:
diff changeset
1103 /* Assume we have REG_EXPR. */
kono
parents:
diff changeset
1104 add_fixup_expr (loc, x, desc_start);
kono
parents:
diff changeset
1105 }
kono
parents:
diff changeset
1106 free (desc);
kono
parents:
diff changeset
1107 }
kono
parents:
diff changeset
1108 else
kono
parents:
diff changeset
1109 unread_char (ch);
kono
parents:
diff changeset
1110 if (expect_original_regno)
kono
parents:
diff changeset
1111 {
kono
parents:
diff changeset
1112 require_char_ws ('[');
kono
parents:
diff changeset
1113 char *desc = read_until ("]", true);
kono
parents:
diff changeset
1114 ORIGINAL_REGNO (x) = atoi (desc);
kono
parents:
diff changeset
1115 free (desc);
kono
parents:
diff changeset
1116 }
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 return x;
kono
parents:
diff changeset
1119 }
kono
parents:
diff changeset
1120
kono
parents:
diff changeset
1121 /* Additional parsing for format code '0' in dumps, handling a variety
kono
parents:
diff changeset
1122 of special-cases in print_rtx, when parsing operand IDX of X.
kono
parents:
diff changeset
1123 Return X, or possibly a reallocated copy of X. */
kono
parents:
diff changeset
1124
kono
parents:
diff changeset
1125 rtx
kono
parents:
diff changeset
1126 function_reader::extra_parsing_for_operand_code_0 (rtx x, int idx)
kono
parents:
diff changeset
1127 {
kono
parents:
diff changeset
1128 RTX_CODE code = GET_CODE (x);
kono
parents:
diff changeset
1129 int c;
kono
parents:
diff changeset
1130 struct md_name name;
kono
parents:
diff changeset
1131
kono
parents:
diff changeset
1132 if (idx == 1 && code == SYMBOL_REF)
kono
parents:
diff changeset
1133 {
kono
parents:
diff changeset
1134 /* Possibly wrote " [flags %#x]", SYMBOL_REF_FLAGS (in_rtx). */
kono
parents:
diff changeset
1135 c = read_skip_spaces ();
kono
parents:
diff changeset
1136 if (c == '[')
kono
parents:
diff changeset
1137 {
kono
parents:
diff changeset
1138 file_location loc = read_name (&name);
kono
parents:
diff changeset
1139 if (strcmp (name.string, "flags"))
kono
parents:
diff changeset
1140 error_at (loc, "was expecting `%s'", "flags");
kono
parents:
diff changeset
1141 read_name (&name);
kono
parents:
diff changeset
1142 SYMBOL_REF_FLAGS (x) = strtol (name.string, NULL, 16);
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 /* The standard RTX_CODE_SIZE (SYMBOL_REF) used when allocating
kono
parents:
diff changeset
1145 x doesn't have space for the block_symbol information, so
kono
parents:
diff changeset
1146 we must reallocate it if this flag is set. */
kono
parents:
diff changeset
1147 if (SYMBOL_REF_HAS_BLOCK_INFO_P (x))
kono
parents:
diff changeset
1148 {
kono
parents:
diff changeset
1149 /* Emulate the allocation normally done by
kono
parents:
diff changeset
1150 varasm.c:create_block_symbol. */
kono
parents:
diff changeset
1151 unsigned int size = RTX_HDR_SIZE + sizeof (struct block_symbol);
kono
parents:
diff changeset
1152 rtx new_x = (rtx) ggc_internal_alloc (size);
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 /* Copy data over from the smaller SYMBOL_REF. */
kono
parents:
diff changeset
1155 memcpy (new_x, x, RTX_CODE_SIZE (SYMBOL_REF));
kono
parents:
diff changeset
1156 x = new_x;
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 /* We can't reconstruct SYMBOL_REF_BLOCK; set it to NULL. */
kono
parents:
diff changeset
1159 SYMBOL_REF_BLOCK (x) = NULL;
kono
parents:
diff changeset
1160
kono
parents:
diff changeset
1161 /* Zero the offset. */
kono
parents:
diff changeset
1162 SYMBOL_REF_BLOCK_OFFSET (x) = 0;
kono
parents:
diff changeset
1163 }
kono
parents:
diff changeset
1164
kono
parents:
diff changeset
1165 require_char (']');
kono
parents:
diff changeset
1166 }
kono
parents:
diff changeset
1167 else
kono
parents:
diff changeset
1168 unread_char (c);
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 /* If X had a non-NULL SYMBOL_REF_DECL,
kono
parents:
diff changeset
1171 rtx_writer::print_rtx_operand_code_0 would have dumped it
kono
parents:
diff changeset
1172 using print_node_brief.
kono
parents:
diff changeset
1173 Skip the content for now. */
kono
parents:
diff changeset
1174 c = read_skip_spaces ();
kono
parents:
diff changeset
1175 if (c == '<')
kono
parents:
diff changeset
1176 {
kono
parents:
diff changeset
1177 while (1)
kono
parents:
diff changeset
1178 {
kono
parents:
diff changeset
1179 char ch = read_char ();
kono
parents:
diff changeset
1180 if (ch == '>')
kono
parents:
diff changeset
1181 break;
kono
parents:
diff changeset
1182 }
kono
parents:
diff changeset
1183 }
kono
parents:
diff changeset
1184 else
kono
parents:
diff changeset
1185 unread_char (c);
kono
parents:
diff changeset
1186 }
kono
parents:
diff changeset
1187 else if (idx == 3 && code == NOTE)
kono
parents:
diff changeset
1188 {
kono
parents:
diff changeset
1189 /* Note-specific data appears for operand 3, which annoyingly
kono
parents:
diff changeset
1190 is before the enum specifying which kind of note we have
kono
parents:
diff changeset
1191 (operand 4). */
kono
parents:
diff changeset
1192 c = read_skip_spaces ();
kono
parents:
diff changeset
1193 if (c == '[')
kono
parents:
diff changeset
1194 {
kono
parents:
diff changeset
1195 /* Possibly data for a NOTE_INSN_BASIC_BLOCK, of the form:
kono
parents:
diff changeset
1196 [bb %d]. */
kono
parents:
diff changeset
1197 file_location bb_loc = read_name (&name);
kono
parents:
diff changeset
1198 if (strcmp (name.string, "bb"))
kono
parents:
diff changeset
1199 error_at (bb_loc, "was expecting `%s'", "bb");
kono
parents:
diff changeset
1200 read_name (&name);
kono
parents:
diff changeset
1201 int bb_idx = atoi (name.string);
kono
parents:
diff changeset
1202 add_fixup_note_insn_basic_block (bb_loc, x, idx,
kono
parents:
diff changeset
1203 bb_idx);
kono
parents:
diff changeset
1204 require_char_ws (']');
kono
parents:
diff changeset
1205 }
kono
parents:
diff changeset
1206 else
kono
parents:
diff changeset
1207 unread_char (c);
kono
parents:
diff changeset
1208 }
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 return x;
kono
parents:
diff changeset
1211 }
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 /* Implementation of rtx_reader::handle_any_trailing_information.
kono
parents:
diff changeset
1214 Handle the various additional information that print-rtl.c can
kono
parents:
diff changeset
1215 write after the regular fields, when parsing X. */
kono
parents:
diff changeset
1216
kono
parents:
diff changeset
1217 void
kono
parents:
diff changeset
1218 function_reader::handle_any_trailing_information (rtx x)
kono
parents:
diff changeset
1219 {
kono
parents:
diff changeset
1220 struct md_name name;
kono
parents:
diff changeset
1221
kono
parents:
diff changeset
1222 switch (GET_CODE (x))
kono
parents:
diff changeset
1223 {
kono
parents:
diff changeset
1224 case MEM:
kono
parents:
diff changeset
1225 {
kono
parents:
diff changeset
1226 int ch;
kono
parents:
diff changeset
1227 require_char_ws ('[');
kono
parents:
diff changeset
1228 read_name (&name);
kono
parents:
diff changeset
1229 set_mem_alias_set (x, atoi (name.string));
kono
parents:
diff changeset
1230 /* We have either a MEM_EXPR, or a space. */
kono
parents:
diff changeset
1231 if (peek_char () != ' ')
kono
parents:
diff changeset
1232 {
kono
parents:
diff changeset
1233 file_location loc = get_current_location ();
kono
parents:
diff changeset
1234 char *desc = read_until (" +", false);
kono
parents:
diff changeset
1235 add_fixup_expr (loc, consolidate_singletons (x), desc);
kono
parents:
diff changeset
1236 free (desc);
kono
parents:
diff changeset
1237 }
kono
parents:
diff changeset
1238 else
kono
parents:
diff changeset
1239 read_char ();
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 /* We may optionally have '+' for MEM_OFFSET_KNOWN_P. */
kono
parents:
diff changeset
1242 ch = read_skip_spaces ();
kono
parents:
diff changeset
1243 if (ch == '+')
kono
parents:
diff changeset
1244 {
kono
parents:
diff changeset
1245 read_name (&name);
kono
parents:
diff changeset
1246 set_mem_offset (x, atoi (name.string));
kono
parents:
diff changeset
1247 }
kono
parents:
diff changeset
1248 else
kono
parents:
diff changeset
1249 unread_char (ch);
kono
parents:
diff changeset
1250
kono
parents:
diff changeset
1251 /* Handle optional " S" for MEM_SIZE. */
kono
parents:
diff changeset
1252 ch = read_skip_spaces ();
kono
parents:
diff changeset
1253 if (ch == 'S')
kono
parents:
diff changeset
1254 {
kono
parents:
diff changeset
1255 read_name (&name);
kono
parents:
diff changeset
1256 set_mem_size (x, atoi (name.string));
kono
parents:
diff changeset
1257 }
kono
parents:
diff changeset
1258 else
kono
parents:
diff changeset
1259 unread_char (ch);
kono
parents:
diff changeset
1260
kono
parents:
diff changeset
1261 /* Handle optional " A" for MEM_ALIGN. */
kono
parents:
diff changeset
1262 ch = read_skip_spaces ();
kono
parents:
diff changeset
1263 if (ch == 'A' && peek_char () != 'S')
kono
parents:
diff changeset
1264 {
kono
parents:
diff changeset
1265 read_name (&name);
kono
parents:
diff changeset
1266 set_mem_align (x, atoi (name.string));
kono
parents:
diff changeset
1267 }
kono
parents:
diff changeset
1268 else
kono
parents:
diff changeset
1269 unread_char (ch);
kono
parents:
diff changeset
1270
kono
parents:
diff changeset
1271 /* Handle optional " AS" for MEM_ADDR_SPACE. */
kono
parents:
diff changeset
1272 ch = read_skip_spaces ();
kono
parents:
diff changeset
1273 if (ch == 'A' && peek_char () == 'S')
kono
parents:
diff changeset
1274 {
kono
parents:
diff changeset
1275 read_char ();
kono
parents:
diff changeset
1276 read_name (&name);
kono
parents:
diff changeset
1277 set_mem_addr_space (x, atoi (name.string));
kono
parents:
diff changeset
1278 }
kono
parents:
diff changeset
1279 else
kono
parents:
diff changeset
1280 unread_char (ch);
kono
parents:
diff changeset
1281
kono
parents:
diff changeset
1282 require_char (']');
kono
parents:
diff changeset
1283 }
kono
parents:
diff changeset
1284 break;
kono
parents:
diff changeset
1285
kono
parents:
diff changeset
1286 case CODE_LABEL:
kono
parents:
diff changeset
1287 /* Assume that LABEL_NUSES was not dumped. */
kono
parents:
diff changeset
1288 /* TODO: parse LABEL_KIND. */
kono
parents:
diff changeset
1289 /* For now, skip until closing ')'. */
kono
parents:
diff changeset
1290 do
kono
parents:
diff changeset
1291 {
kono
parents:
diff changeset
1292 char ch = read_char ();
kono
parents:
diff changeset
1293 if (ch == ')')
kono
parents:
diff changeset
1294 {
kono
parents:
diff changeset
1295 unread_char (ch);
kono
parents:
diff changeset
1296 break;
kono
parents:
diff changeset
1297 }
kono
parents:
diff changeset
1298 }
kono
parents:
diff changeset
1299 while (1);
kono
parents:
diff changeset
1300 break;
kono
parents:
diff changeset
1301
kono
parents:
diff changeset
1302 default:
kono
parents:
diff changeset
1303 break;
kono
parents:
diff changeset
1304 }
kono
parents:
diff changeset
1305 }
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 /* Parse a tree dump for a MEM_EXPR in DESC and turn it back into a tree.
kono
parents:
diff changeset
1308 We handle "<retval>" and param names within cfun, but for anything else
kono
parents:
diff changeset
1309 we "cheat" by building a global VAR_DECL of type "int" with that name
kono
parents:
diff changeset
1310 (returning the same global for a name if we see the same name more
kono
parents:
diff changeset
1311 than once). */
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 tree
kono
parents:
diff changeset
1314 function_reader::parse_mem_expr (const char *desc)
kono
parents:
diff changeset
1315 {
kono
parents:
diff changeset
1316 tree fndecl = cfun->decl;
kono
parents:
diff changeset
1317
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1318 if (strcmp (desc, "<retval>") == 0)
111
kono
parents:
diff changeset
1319 return DECL_RESULT (fndecl);
kono
parents:
diff changeset
1320
kono
parents:
diff changeset
1321 tree param = find_param_by_name (fndecl, desc);
kono
parents:
diff changeset
1322 if (param)
kono
parents:
diff changeset
1323 return param;
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 /* Search within decls we already created.
kono
parents:
diff changeset
1326 FIXME: use a hash rather than linear search. */
kono
parents:
diff changeset
1327 int i;
kono
parents:
diff changeset
1328 tree t;
kono
parents:
diff changeset
1329 FOR_EACH_VEC_ELT (m_fake_scope, i, t)
kono
parents:
diff changeset
1330 if (id_equal (DECL_NAME (t), desc))
kono
parents:
diff changeset
1331 return t;
kono
parents:
diff changeset
1332
kono
parents:
diff changeset
1333 /* Not found? Create it.
kono
parents:
diff changeset
1334 This allows mimicking of real data but avoids having to specify
kono
parents:
diff changeset
1335 e.g. names of locals, params etc.
kono
parents:
diff changeset
1336 Though this way we don't know if we have a PARM_DECL vs a VAR_DECL,
kono
parents:
diff changeset
1337 and we don't know the types. Fake it by making everything be
kono
parents:
diff changeset
1338 a VAR_DECL of "int" type. */
kono
parents:
diff changeset
1339 t = build_decl (UNKNOWN_LOCATION, VAR_DECL,
kono
parents:
diff changeset
1340 get_identifier (desc),
kono
parents:
diff changeset
1341 integer_type_node);
kono
parents:
diff changeset
1342 m_fake_scope.safe_push (t);
kono
parents:
diff changeset
1343 return t;
kono
parents:
diff changeset
1344 }
kono
parents:
diff changeset
1345
kono
parents:
diff changeset
1346 /* Record that at LOC we saw an insn uid INSN_UID for the operand with index
kono
parents:
diff changeset
1347 OPERAND_IDX within INSN, so that the pointer value can be fixed up in
kono
parents:
diff changeset
1348 later post-processing. */
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 void
kono
parents:
diff changeset
1351 function_reader::add_fixup_insn_uid (file_location loc, rtx insn, int operand_idx,
kono
parents:
diff changeset
1352 int insn_uid)
kono
parents:
diff changeset
1353 {
kono
parents:
diff changeset
1354 m_fixups.safe_push (new fixup_insn_uid (loc, insn, operand_idx, insn_uid));
kono
parents:
diff changeset
1355 }
kono
parents:
diff changeset
1356
kono
parents:
diff changeset
1357 /* Record that at LOC we saw an basic block index BB_IDX for the operand with index
kono
parents:
diff changeset
1358 OPERAND_IDX within INSN, so that the pointer value can be fixed up in
kono
parents:
diff changeset
1359 later post-processing. */
kono
parents:
diff changeset
1360
kono
parents:
diff changeset
1361 void
kono
parents:
diff changeset
1362 function_reader::add_fixup_note_insn_basic_block (file_location loc, rtx insn,
kono
parents:
diff changeset
1363 int operand_idx, int bb_idx)
kono
parents:
diff changeset
1364 {
kono
parents:
diff changeset
1365 m_fixups.safe_push (new fixup_note_insn_basic_block (loc, insn, operand_idx,
kono
parents:
diff changeset
1366 bb_idx));
kono
parents:
diff changeset
1367 }
kono
parents:
diff changeset
1368
kono
parents:
diff changeset
1369 /* Placeholder hook for recording source location information seen in a dump.
kono
parents:
diff changeset
1370 This is empty for now. */
kono
parents:
diff changeset
1371
kono
parents:
diff changeset
1372 void
kono
parents:
diff changeset
1373 function_reader::add_fixup_source_location (file_location, rtx_insn *,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1374 const char *, int, int)
111
kono
parents:
diff changeset
1375 {
kono
parents:
diff changeset
1376 }
kono
parents:
diff changeset
1377
kono
parents:
diff changeset
1378 /* Record that at LOC we saw textual description DESC of the MEM_EXPR or REG_EXPR
kono
parents:
diff changeset
1379 of INSN, so that the fields can be fixed up in later post-processing. */
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 void
kono
parents:
diff changeset
1382 function_reader::add_fixup_expr (file_location loc, rtx insn,
kono
parents:
diff changeset
1383 const char *desc)
kono
parents:
diff changeset
1384 {
kono
parents:
diff changeset
1385 gcc_assert (desc);
kono
parents:
diff changeset
1386 /* Fail early if the RTL reader erroneously hands us an int. */
kono
parents:
diff changeset
1387 gcc_assert (!ISDIGIT (desc[0]));
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 m_fixups.safe_push (new fixup_expr (loc, insn, desc));
kono
parents:
diff changeset
1390 }
kono
parents:
diff changeset
1391
kono
parents:
diff changeset
1392 /* Helper function for consolidate_reg. Return the global rtx for
kono
parents:
diff changeset
1393 the register with regno REGNO. */
kono
parents:
diff changeset
1394
kono
parents:
diff changeset
1395 static rtx
kono
parents:
diff changeset
1396 lookup_global_register (int regno)
kono
parents:
diff changeset
1397 {
kono
parents:
diff changeset
1398 /* We can't use a switch here, as some of the REGNUMs might not be constants
kono
parents:
diff changeset
1399 for some targets. */
kono
parents:
diff changeset
1400 if (regno == STACK_POINTER_REGNUM)
kono
parents:
diff changeset
1401 return stack_pointer_rtx;
kono
parents:
diff changeset
1402 else if (regno == FRAME_POINTER_REGNUM)
kono
parents:
diff changeset
1403 return frame_pointer_rtx;
kono
parents:
diff changeset
1404 else if (regno == HARD_FRAME_POINTER_REGNUM)
kono
parents:
diff changeset
1405 return hard_frame_pointer_rtx;
kono
parents:
diff changeset
1406 else if (regno == ARG_POINTER_REGNUM)
kono
parents:
diff changeset
1407 return arg_pointer_rtx;
kono
parents:
diff changeset
1408 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
kono
parents:
diff changeset
1409 return virtual_incoming_args_rtx;
kono
parents:
diff changeset
1410 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
kono
parents:
diff changeset
1411 return virtual_stack_vars_rtx;
kono
parents:
diff changeset
1412 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
kono
parents:
diff changeset
1413 return virtual_stack_dynamic_rtx;
kono
parents:
diff changeset
1414 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
kono
parents:
diff changeset
1415 return virtual_outgoing_args_rtx;
kono
parents:
diff changeset
1416 else if (regno == VIRTUAL_CFA_REGNUM)
kono
parents:
diff changeset
1417 return virtual_cfa_rtx;
kono
parents:
diff changeset
1418 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
kono
parents:
diff changeset
1419 return virtual_preferred_stack_boundary_rtx;
kono
parents:
diff changeset
1420 #ifdef return_ADDRESS_POINTER_REGNUM
kono
parents:
diff changeset
1421 else if (regno == RETURN_ADDRESS_POINTER_REGNUM)
kono
parents:
diff changeset
1422 return return_address_pointer_rtx;
kono
parents:
diff changeset
1423 #endif
kono
parents:
diff changeset
1424
kono
parents:
diff changeset
1425 return NULL;
kono
parents:
diff changeset
1426 }
kono
parents:
diff changeset
1427
kono
parents:
diff changeset
1428 /* Ensure that the backend can cope with a REG with regno REGNO.
kono
parents:
diff changeset
1429 Normally REG instances are created by gen_reg_rtx which updates
kono
parents:
diff changeset
1430 regno_reg_rtx, growing it as necessary.
kono
parents:
diff changeset
1431 The REG instances created from the dumpfile weren't created this
kono
parents:
diff changeset
1432 way, so we need to manually update regno_reg_rtx. */
kono
parents:
diff changeset
1433
kono
parents:
diff changeset
1434 static void
kono
parents:
diff changeset
1435 ensure_regno (int regno)
kono
parents:
diff changeset
1436 {
kono
parents:
diff changeset
1437 if (reg_rtx_no < regno + 1)
kono
parents:
diff changeset
1438 reg_rtx_no = regno + 1;
kono
parents:
diff changeset
1439
kono
parents:
diff changeset
1440 crtl->emit.ensure_regno_capacity ();
kono
parents:
diff changeset
1441 gcc_assert (regno < crtl->emit.regno_pointer_align_length);
kono
parents:
diff changeset
1442 }
kono
parents:
diff changeset
1443
kono
parents:
diff changeset
1444 /* Helper function for consolidate_singletons, for handling REG instances.
kono
parents:
diff changeset
1445 Given REG instance X of some regno, return the singleton rtx for that
kono
parents:
diff changeset
1446 regno, if it exists, or X. */
kono
parents:
diff changeset
1447
kono
parents:
diff changeset
1448 static rtx
kono
parents:
diff changeset
1449 consolidate_reg (rtx x)
kono
parents:
diff changeset
1450 {
kono
parents:
diff changeset
1451 gcc_assert (GET_CODE (x) == REG);
kono
parents:
diff changeset
1452
kono
parents:
diff changeset
1453 unsigned int regno = REGNO (x);
kono
parents:
diff changeset
1454
kono
parents:
diff changeset
1455 ensure_regno (regno);
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 /* Some register numbers have their rtx created in init_emit_regs
kono
parents:
diff changeset
1458 e.g. stack_pointer_rtx for STACK_POINTER_REGNUM.
kono
parents:
diff changeset
1459 Consolidate on this. */
kono
parents:
diff changeset
1460 rtx global_reg = lookup_global_register (regno);
kono
parents:
diff changeset
1461 if (global_reg)
kono
parents:
diff changeset
1462 return global_reg;
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 /* Populate regno_reg_rtx if necessary. */
kono
parents:
diff changeset
1465 if (regno_reg_rtx[regno] == NULL)
kono
parents:
diff changeset
1466 regno_reg_rtx[regno] = x;
kono
parents:
diff changeset
1467 /* Use it. */
kono
parents:
diff changeset
1468 gcc_assert (GET_CODE (regno_reg_rtx[regno]) == REG);
kono
parents:
diff changeset
1469 gcc_assert (REGNO (regno_reg_rtx[regno]) == regno);
kono
parents:
diff changeset
1470 if (GET_MODE (x) == GET_MODE (regno_reg_rtx[regno]))
kono
parents:
diff changeset
1471 return regno_reg_rtx[regno];
kono
parents:
diff changeset
1472
kono
parents:
diff changeset
1473 return x;
kono
parents:
diff changeset
1474 }
kono
parents:
diff changeset
1475
kono
parents:
diff changeset
1476 /* When reading RTL function dumps, we must consolidate some
kono
parents:
diff changeset
1477 rtx so that we use singletons where singletons are expected
kono
parents:
diff changeset
1478 (e.g. we don't want multiple "(const_int 0 [0])" rtx, since
kono
parents:
diff changeset
1479 these are tested via pointer equality against const0_rtx.
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 Return the equivalent singleton rtx for X, if any, otherwise X. */
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 rtx
kono
parents:
diff changeset
1484 function_reader::consolidate_singletons (rtx x)
kono
parents:
diff changeset
1485 {
kono
parents:
diff changeset
1486 if (!x)
kono
parents:
diff changeset
1487 return x;
kono
parents:
diff changeset
1488
kono
parents:
diff changeset
1489 switch (GET_CODE (x))
kono
parents:
diff changeset
1490 {
kono
parents:
diff changeset
1491 case PC: return pc_rtx;
kono
parents:
diff changeset
1492 case RETURN: return ret_rtx;
kono
parents:
diff changeset
1493 case SIMPLE_RETURN: return simple_return_rtx;
kono
parents:
diff changeset
1494 case CC0: return cc0_rtx;
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 case REG:
kono
parents:
diff changeset
1497 return consolidate_reg (x);
kono
parents:
diff changeset
1498
kono
parents:
diff changeset
1499 case CONST_INT:
kono
parents:
diff changeset
1500 return gen_rtx_CONST_INT (GET_MODE (x), INTVAL (x));
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 default:
kono
parents:
diff changeset
1503 break;
kono
parents:
diff changeset
1504 }
kono
parents:
diff changeset
1505
kono
parents:
diff changeset
1506 return x;
kono
parents:
diff changeset
1507 }
kono
parents:
diff changeset
1508
kono
parents:
diff changeset
1509 /* Parse an rtx directive, including both the opening/closing parentheses,
kono
parents:
diff changeset
1510 and the name. */
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 rtx
kono
parents:
diff changeset
1513 function_reader::parse_rtx ()
kono
parents:
diff changeset
1514 {
kono
parents:
diff changeset
1515 require_char_ws ('(');
kono
parents:
diff changeset
1516 struct md_name directive;
kono
parents:
diff changeset
1517 read_name (&directive);
kono
parents:
diff changeset
1518 rtx result
kono
parents:
diff changeset
1519 = consolidate_singletons (read_rtx_code (directive.string));
kono
parents:
diff changeset
1520 require_char_ws (')');
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522 return result;
kono
parents:
diff changeset
1523 }
kono
parents:
diff changeset
1524
kono
parents:
diff changeset
1525 /* Implementation of rtx_reader::postprocess for reading function dumps.
kono
parents:
diff changeset
1526 Return the equivalent singleton rtx for X, if any, otherwise X. */
kono
parents:
diff changeset
1527
kono
parents:
diff changeset
1528 rtx
kono
parents:
diff changeset
1529 function_reader::postprocess (rtx x)
kono
parents:
diff changeset
1530 {
kono
parents:
diff changeset
1531 return consolidate_singletons (x);
kono
parents:
diff changeset
1532 }
kono
parents:
diff changeset
1533
kono
parents:
diff changeset
1534 /* Implementation of rtx_reader::finalize_string for reading function dumps.
kono
parents:
diff changeset
1535 Make a GC-managed copy of STRINGBUF. */
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 const char *
kono
parents:
diff changeset
1538 function_reader::finalize_string (char *stringbuf)
kono
parents:
diff changeset
1539 {
kono
parents:
diff changeset
1540 return ggc_strdup (stringbuf);
kono
parents:
diff changeset
1541 }
kono
parents:
diff changeset
1542
kono
parents:
diff changeset
1543 /* Attempt to parse optional location information for insn INSN, as
kono
parents:
diff changeset
1544 potentially written out by rtx_writer::print_rtx_operand_code_i.
kono
parents:
diff changeset
1545 We look for a quoted string followed by a colon. */
kono
parents:
diff changeset
1546
kono
parents:
diff changeset
1547 void
kono
parents:
diff changeset
1548 function_reader::maybe_read_location (rtx_insn *insn)
kono
parents:
diff changeset
1549 {
kono
parents:
diff changeset
1550 file_location loc = get_current_location ();
kono
parents:
diff changeset
1551
kono
parents:
diff changeset
1552 /* Attempt to parse a quoted string. */
kono
parents:
diff changeset
1553 int ch = read_skip_spaces ();
kono
parents:
diff changeset
1554 if (ch == '"')
kono
parents:
diff changeset
1555 {
kono
parents:
diff changeset
1556 char *filename = read_quoted_string ();
kono
parents:
diff changeset
1557 require_char (':');
kono
parents:
diff changeset
1558 struct md_name line_num;
kono
parents:
diff changeset
1559 read_name (&line_num);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1560
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1561 int column = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1562 int ch = read_char ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1563 if (ch == ':')
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1564 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1565 struct md_name column_num;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1566 read_name (&column_num);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1567 column = atoi (column_num.string);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1568 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1569 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1570 unread_char (ch);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1571 add_fixup_source_location (loc, insn, filename,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1572 atoi (line_num.string),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1573 column);
111
kono
parents:
diff changeset
1574 }
kono
parents:
diff changeset
1575 else
kono
parents:
diff changeset
1576 unread_char (ch);
kono
parents:
diff changeset
1577 }
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 /* Postprocessing subroutine of function_reader::parse_function.
kono
parents:
diff changeset
1580 Populate m_insns_by_uid. */
kono
parents:
diff changeset
1581
kono
parents:
diff changeset
1582 void
kono
parents:
diff changeset
1583 function_reader::handle_insn_uids ()
kono
parents:
diff changeset
1584 {
kono
parents:
diff changeset
1585 /* Locate the currently assigned INSN_UID values, storing
kono
parents:
diff changeset
1586 them in m_insns_by_uid. */
kono
parents:
diff changeset
1587 int max_uid = 0;
kono
parents:
diff changeset
1588 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
kono
parents:
diff changeset
1589 {
kono
parents:
diff changeset
1590 if (m_insns_by_uid.get (INSN_UID (insn)))
kono
parents:
diff changeset
1591 error ("duplicate insn UID: %i", INSN_UID (insn));
kono
parents:
diff changeset
1592 m_insns_by_uid.put (INSN_UID (insn), insn);
kono
parents:
diff changeset
1593 if (INSN_UID (insn) > max_uid)
kono
parents:
diff changeset
1594 max_uid = INSN_UID (insn);
kono
parents:
diff changeset
1595 }
kono
parents:
diff changeset
1596
kono
parents:
diff changeset
1597 /* Ensure x_cur_insn_uid is 1 more than the biggest insn UID seen.
kono
parents:
diff changeset
1598 This is normally updated by the various make_*insn_raw functions. */
kono
parents:
diff changeset
1599 crtl->emit.x_cur_insn_uid = max_uid + 1;
kono
parents:
diff changeset
1600 }
kono
parents:
diff changeset
1601
kono
parents:
diff changeset
1602 /* Apply all of the recorded fixups. */
kono
parents:
diff changeset
1603
kono
parents:
diff changeset
1604 void
kono
parents:
diff changeset
1605 function_reader::apply_fixups ()
kono
parents:
diff changeset
1606 {
kono
parents:
diff changeset
1607 int i;
kono
parents:
diff changeset
1608 fixup *f;
kono
parents:
diff changeset
1609 FOR_EACH_VEC_ELT (m_fixups, i, f)
kono
parents:
diff changeset
1610 f->apply (this);
kono
parents:
diff changeset
1611 }
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 /* Given a UID value, try to locate a pointer to the corresponding
kono
parents:
diff changeset
1614 rtx_insn *, or NULL if if can't be found. */
kono
parents:
diff changeset
1615
kono
parents:
diff changeset
1616 rtx_insn **
kono
parents:
diff changeset
1617 function_reader::get_insn_by_uid (int uid)
kono
parents:
diff changeset
1618 {
kono
parents:
diff changeset
1619 return m_insns_by_uid.get (uid);
kono
parents:
diff changeset
1620 }
kono
parents:
diff changeset
1621
kono
parents:
diff changeset
1622 /* Run the RTL dump parser, parsing a dump located at PATH.
kono
parents:
diff changeset
1623 Return true iff the file was successfully parsed. */
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 bool
kono
parents:
diff changeset
1626 read_rtl_function_body (const char *path)
kono
parents:
diff changeset
1627 {
kono
parents:
diff changeset
1628 initialize_rtl ();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1629 crtl->abi = &default_function_abi;
111
kono
parents:
diff changeset
1630 init_emit ();
kono
parents:
diff changeset
1631 init_varasm_status ();
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 function_reader reader;
kono
parents:
diff changeset
1634 if (!reader.read_file (path))
kono
parents:
diff changeset
1635 return false;
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 return true;
kono
parents:
diff changeset
1638 }
kono
parents:
diff changeset
1639
kono
parents:
diff changeset
1640 /* Run the RTL dump parser on the range of lines between START_LOC and
kono
parents:
diff changeset
1641 END_LOC (including those lines). */
kono
parents:
diff changeset
1642
kono
parents:
diff changeset
1643 bool
kono
parents:
diff changeset
1644 read_rtl_function_body_from_file_range (location_t start_loc,
kono
parents:
diff changeset
1645 location_t end_loc)
kono
parents:
diff changeset
1646 {
kono
parents:
diff changeset
1647 expanded_location exploc_start = expand_location (start_loc);
kono
parents:
diff changeset
1648 expanded_location exploc_end = expand_location (end_loc);
kono
parents:
diff changeset
1649
kono
parents:
diff changeset
1650 if (exploc_start.file != exploc_end.file)
kono
parents:
diff changeset
1651 {
kono
parents:
diff changeset
1652 error_at (end_loc, "start/end of RTL fragment are in different files");
kono
parents:
diff changeset
1653 return false;
kono
parents:
diff changeset
1654 }
kono
parents:
diff changeset
1655 if (exploc_start.line >= exploc_end.line)
kono
parents:
diff changeset
1656 {
kono
parents:
diff changeset
1657 error_at (end_loc,
kono
parents:
diff changeset
1658 "start of RTL fragment must be on an earlier line than end");
kono
parents:
diff changeset
1659 return false;
kono
parents:
diff changeset
1660 }
kono
parents:
diff changeset
1661
kono
parents:
diff changeset
1662 initialize_rtl ();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1663 crtl->abi = &fndecl_abi (cfun->decl).base_abi ();
111
kono
parents:
diff changeset
1664 init_emit ();
kono
parents:
diff changeset
1665 init_varasm_status ();
kono
parents:
diff changeset
1666
kono
parents:
diff changeset
1667 function_reader reader;
kono
parents:
diff changeset
1668 if (!reader.read_file_fragment (exploc_start.file, exploc_start.line,
kono
parents:
diff changeset
1669 exploc_end.line - 1))
kono
parents:
diff changeset
1670 return false;
kono
parents:
diff changeset
1671
kono
parents:
diff changeset
1672 return true;
kono
parents:
diff changeset
1673 }
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 #if CHECKING_P
kono
parents:
diff changeset
1676
kono
parents:
diff changeset
1677 namespace selftest {
kono
parents:
diff changeset
1678
kono
parents:
diff changeset
1679 /* Verify that parse_edge_flags works. */
kono
parents:
diff changeset
1680
kono
parents:
diff changeset
1681 static void
kono
parents:
diff changeset
1682 test_edge_flags ()
kono
parents:
diff changeset
1683 {
kono
parents:
diff changeset
1684 /* parse_edge_flags modifies its input (due to strtok), so we must make
kono
parents:
diff changeset
1685 a copy of the literals. */
kono
parents:
diff changeset
1686 #define ASSERT_PARSE_EDGE_FLAGS(EXPECTED, STR) \
kono
parents:
diff changeset
1687 do { \
kono
parents:
diff changeset
1688 char *str = xstrdup (STR); \
kono
parents:
diff changeset
1689 ASSERT_EQ (EXPECTED, parse_edge_flags (str)); \
kono
parents:
diff changeset
1690 free (str); \
kono
parents:
diff changeset
1691 } while (0)
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693 ASSERT_PARSE_EDGE_FLAGS (0, "");
kono
parents:
diff changeset
1694 ASSERT_PARSE_EDGE_FLAGS (EDGE_FALLTHRU, "FALLTHRU");
kono
parents:
diff changeset
1695 ASSERT_PARSE_EDGE_FLAGS (EDGE_ABNORMAL_CALL, "ABNORMAL_CALL");
kono
parents:
diff changeset
1696 ASSERT_PARSE_EDGE_FLAGS (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL,
kono
parents:
diff changeset
1697 "ABNORMAL | ABNORMAL_CALL");
kono
parents:
diff changeset
1698
kono
parents:
diff changeset
1699 #undef ASSERT_PARSE_EDGE_FLAGS
kono
parents:
diff changeset
1700 }
kono
parents:
diff changeset
1701
kono
parents:
diff changeset
1702 /* Verify that lookup_reg_by_dump_name works. */
kono
parents:
diff changeset
1703
kono
parents:
diff changeset
1704 static void
kono
parents:
diff changeset
1705 test_parsing_regnos ()
kono
parents:
diff changeset
1706 {
kono
parents:
diff changeset
1707 ASSERT_EQ (-1, lookup_reg_by_dump_name ("this is not a register"));
kono
parents:
diff changeset
1708
kono
parents:
diff changeset
1709 /* Verify lookup of virtual registers. */
kono
parents:
diff changeset
1710 ASSERT_EQ (VIRTUAL_INCOMING_ARGS_REGNUM,
kono
parents:
diff changeset
1711 lookup_reg_by_dump_name ("virtual-incoming-args"));
kono
parents:
diff changeset
1712 ASSERT_EQ (VIRTUAL_STACK_VARS_REGNUM,
kono
parents:
diff changeset
1713 lookup_reg_by_dump_name ("virtual-stack-vars"));
kono
parents:
diff changeset
1714 ASSERT_EQ (VIRTUAL_STACK_DYNAMIC_REGNUM,
kono
parents:
diff changeset
1715 lookup_reg_by_dump_name ("virtual-stack-dynamic"));
kono
parents:
diff changeset
1716 ASSERT_EQ (VIRTUAL_OUTGOING_ARGS_REGNUM,
kono
parents:
diff changeset
1717 lookup_reg_by_dump_name ("virtual-outgoing-args"));
kono
parents:
diff changeset
1718 ASSERT_EQ (VIRTUAL_CFA_REGNUM,
kono
parents:
diff changeset
1719 lookup_reg_by_dump_name ("virtual-cfa"));
kono
parents:
diff changeset
1720 ASSERT_EQ (VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM,
kono
parents:
diff changeset
1721 lookup_reg_by_dump_name ("virtual-preferred-stack-boundary"));
kono
parents:
diff changeset
1722
kono
parents:
diff changeset
1723 /* Verify lookup of non-virtual pseudos. */
kono
parents:
diff changeset
1724 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 1, lookup_reg_by_dump_name ("<0>"));
kono
parents:
diff changeset
1725 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 2, lookup_reg_by_dump_name ("<1>"));
kono
parents:
diff changeset
1726 }
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 /* Verify that edge E is as expected, with the src and dest basic blocks
kono
parents:
diff changeset
1729 having indices EXPECTED_SRC_IDX and EXPECTED_DEST_IDX respectively, and
kono
parents:
diff changeset
1730 the edge having flags equal to EXPECTED_FLAGS.
kono
parents:
diff changeset
1731 Use LOC as the effective location when reporting failures. */
kono
parents:
diff changeset
1732
kono
parents:
diff changeset
1733 static void
kono
parents:
diff changeset
1734 assert_edge_at (const location &loc, edge e, int expected_src_idx,
kono
parents:
diff changeset
1735 int expected_dest_idx, int expected_flags)
kono
parents:
diff changeset
1736 {
kono
parents:
diff changeset
1737 ASSERT_EQ_AT (loc, expected_src_idx, e->src->index);
kono
parents:
diff changeset
1738 ASSERT_EQ_AT (loc, expected_dest_idx, e->dest->index);
kono
parents:
diff changeset
1739 ASSERT_EQ_AT (loc, expected_flags, e->flags);
kono
parents:
diff changeset
1740 }
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 /* Verify that edge EDGE is as expected, with the src and dest basic blocks
kono
parents:
diff changeset
1743 having indices EXPECTED_SRC_IDX and EXPECTED_DEST_IDX respectively, and
kono
parents:
diff changeset
1744 the edge having flags equal to EXPECTED_FLAGS. */
kono
parents:
diff changeset
1745
kono
parents:
diff changeset
1746 #define ASSERT_EDGE(EDGE, EXPECTED_SRC_IDX, EXPECTED_DEST_IDX, \
kono
parents:
diff changeset
1747 EXPECTED_FLAGS) \
kono
parents:
diff changeset
1748 assert_edge_at (SELFTEST_LOCATION, EDGE, EXPECTED_SRC_IDX, \
kono
parents:
diff changeset
1749 EXPECTED_DEST_IDX, EXPECTED_FLAGS)
kono
parents:
diff changeset
1750
kono
parents:
diff changeset
1751 /* Verify that we can load RTL dumps. */
kono
parents:
diff changeset
1752
kono
parents:
diff changeset
1753 static void
kono
parents:
diff changeset
1754 test_loading_dump_fragment_1 ()
kono
parents:
diff changeset
1755 {
kono
parents:
diff changeset
1756 // TODO: filter on target?
kono
parents:
diff changeset
1757 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("asr_div1.rtl"));
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 /* Verify that the insns were loaded correctly. */
kono
parents:
diff changeset
1760 rtx_insn *insn_1 = get_insns ();
kono
parents:
diff changeset
1761 ASSERT_TRUE (insn_1);
kono
parents:
diff changeset
1762 ASSERT_EQ (1, INSN_UID (insn_1));
kono
parents:
diff changeset
1763 ASSERT_EQ (INSN, GET_CODE (insn_1));
kono
parents:
diff changeset
1764 ASSERT_EQ (SET, GET_CODE (PATTERN (insn_1)));
kono
parents:
diff changeset
1765 ASSERT_EQ (NULL, PREV_INSN (insn_1));
kono
parents:
diff changeset
1766
kono
parents:
diff changeset
1767 rtx_insn *insn_2 = NEXT_INSN (insn_1);
kono
parents:
diff changeset
1768 ASSERT_TRUE (insn_2);
kono
parents:
diff changeset
1769 ASSERT_EQ (2, INSN_UID (insn_2));
kono
parents:
diff changeset
1770 ASSERT_EQ (INSN, GET_CODE (insn_2));
kono
parents:
diff changeset
1771 ASSERT_EQ (insn_1, PREV_INSN (insn_2));
kono
parents:
diff changeset
1772 ASSERT_EQ (NULL, NEXT_INSN (insn_2));
kono
parents:
diff changeset
1773
kono
parents:
diff changeset
1774 /* Verify that registers were loaded correctly. */
kono
parents:
diff changeset
1775 rtx insn_1_dest = SET_DEST (PATTERN (insn_1));
kono
parents:
diff changeset
1776 ASSERT_EQ (REG, GET_CODE (insn_1_dest));
kono
parents:
diff changeset
1777 ASSERT_EQ ((LAST_VIRTUAL_REGISTER + 1) + 2, REGNO (insn_1_dest));
kono
parents:
diff changeset
1778 rtx insn_1_src = SET_SRC (PATTERN (insn_1));
kono
parents:
diff changeset
1779 ASSERT_EQ (LSHIFTRT, GET_CODE (insn_1_src));
kono
parents:
diff changeset
1780 rtx reg = XEXP (insn_1_src, 0);
kono
parents:
diff changeset
1781 ASSERT_EQ (REG, GET_CODE (reg));
kono
parents:
diff changeset
1782 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 1, REGNO (reg));
kono
parents:
diff changeset
1783
kono
parents:
diff changeset
1784 /* Verify that get_insn_by_uid works. */
kono
parents:
diff changeset
1785 ASSERT_EQ (insn_1, get_insn_by_uid (1));
kono
parents:
diff changeset
1786 ASSERT_EQ (insn_2, get_insn_by_uid (2));
kono
parents:
diff changeset
1787
kono
parents:
diff changeset
1788 /* Verify that basic blocks were created. */
kono
parents:
diff changeset
1789 ASSERT_EQ (2, BLOCK_FOR_INSN (insn_1)->index);
kono
parents:
diff changeset
1790 ASSERT_EQ (2, BLOCK_FOR_INSN (insn_2)->index);
kono
parents:
diff changeset
1791
kono
parents:
diff changeset
1792 /* Verify that the CFG was recreated. */
kono
parents:
diff changeset
1793 ASSERT_TRUE (cfun);
kono
parents:
diff changeset
1794 verify_three_block_rtl_cfg (cfun);
kono
parents:
diff changeset
1795 basic_block bb2 = BASIC_BLOCK_FOR_FN (cfun, 2);
kono
parents:
diff changeset
1796 ASSERT_TRUE (bb2 != NULL);
kono
parents:
diff changeset
1797 ASSERT_EQ (BB_RTL, bb2->flags & BB_RTL);
kono
parents:
diff changeset
1798 ASSERT_EQ (2, bb2->index);
kono
parents:
diff changeset
1799 ASSERT_EQ (insn_1, BB_HEAD (bb2));
kono
parents:
diff changeset
1800 ASSERT_EQ (insn_2, BB_END (bb2));
kono
parents:
diff changeset
1801 }
kono
parents:
diff changeset
1802
kono
parents:
diff changeset
1803 /* Verify loading another RTL dump. */
kono
parents:
diff changeset
1804
kono
parents:
diff changeset
1805 static void
kono
parents:
diff changeset
1806 test_loading_dump_fragment_2 ()
kono
parents:
diff changeset
1807 {
kono
parents:
diff changeset
1808 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("simple-cse.rtl"));
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 rtx_insn *insn_1 = get_insn_by_uid (1);
kono
parents:
diff changeset
1811 rtx_insn *insn_2 = get_insn_by_uid (2);
kono
parents:
diff changeset
1812 rtx_insn *insn_3 = get_insn_by_uid (3);
kono
parents:
diff changeset
1813
kono
parents:
diff changeset
1814 rtx set1 = single_set (insn_1);
kono
parents:
diff changeset
1815 ASSERT_NE (NULL, set1);
kono
parents:
diff changeset
1816 rtx set2 = single_set (insn_2);
kono
parents:
diff changeset
1817 ASSERT_NE (NULL, set2);
kono
parents:
diff changeset
1818 rtx set3 = single_set (insn_3);
kono
parents:
diff changeset
1819 ASSERT_NE (NULL, set3);
kono
parents:
diff changeset
1820
kono
parents:
diff changeset
1821 rtx src1 = SET_SRC (set1);
kono
parents:
diff changeset
1822 ASSERT_EQ (PLUS, GET_CODE (src1));
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 rtx src2 = SET_SRC (set2);
kono
parents:
diff changeset
1825 ASSERT_EQ (PLUS, GET_CODE (src2));
kono
parents:
diff changeset
1826
kono
parents:
diff changeset
1827 /* Both src1 and src2 refer to "(reg:SI %0)".
kono
parents:
diff changeset
1828 Verify that we have pointer equality. */
kono
parents:
diff changeset
1829 rtx lhs1 = XEXP (src1, 0);
kono
parents:
diff changeset
1830 rtx lhs2 = XEXP (src2, 0);
kono
parents:
diff changeset
1831 ASSERT_EQ (lhs1, lhs2);
kono
parents:
diff changeset
1832
kono
parents:
diff changeset
1833 /* Verify that the CFG was recreated. */
kono
parents:
diff changeset
1834 ASSERT_TRUE (cfun);
kono
parents:
diff changeset
1835 verify_three_block_rtl_cfg (cfun);
kono
parents:
diff changeset
1836 }
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 /* Verify that CODE_LABEL insns are loaded correctly. */
kono
parents:
diff changeset
1839
kono
parents:
diff changeset
1840 static void
kono
parents:
diff changeset
1841 test_loading_labels ()
kono
parents:
diff changeset
1842 {
kono
parents:
diff changeset
1843 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("example-labels.rtl"));
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 rtx_insn *insn_100 = get_insn_by_uid (100);
kono
parents:
diff changeset
1846 ASSERT_EQ (CODE_LABEL, GET_CODE (insn_100));
kono
parents:
diff changeset
1847 ASSERT_EQ (100, INSN_UID (insn_100));
kono
parents:
diff changeset
1848 ASSERT_EQ (NULL, LABEL_NAME (insn_100));
kono
parents:
diff changeset
1849 ASSERT_EQ (0, LABEL_NUSES (insn_100));
kono
parents:
diff changeset
1850 ASSERT_EQ (30, CODE_LABEL_NUMBER (insn_100));
kono
parents:
diff changeset
1851
kono
parents:
diff changeset
1852 rtx_insn *insn_200 = get_insn_by_uid (200);
kono
parents:
diff changeset
1853 ASSERT_EQ (CODE_LABEL, GET_CODE (insn_200));
kono
parents:
diff changeset
1854 ASSERT_EQ (200, INSN_UID (insn_200));
kono
parents:
diff changeset
1855 ASSERT_STREQ ("some_label_name", LABEL_NAME (insn_200));
kono
parents:
diff changeset
1856 ASSERT_EQ (0, LABEL_NUSES (insn_200));
kono
parents:
diff changeset
1857 ASSERT_EQ (40, CODE_LABEL_NUMBER (insn_200));
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 /* Ensure that the presence of CODE_LABEL_NUMBER == 40
kono
parents:
diff changeset
1860 means that the next label num to be handed out will be 41. */
kono
parents:
diff changeset
1861 ASSERT_EQ (41, max_label_num ());
kono
parents:
diff changeset
1862
kono
parents:
diff changeset
1863 /* Ensure that label names read from a dump are GC-managed
kono
parents:
diff changeset
1864 and are found through the insn. */
kono
parents:
diff changeset
1865 forcibly_ggc_collect ();
kono
parents:
diff changeset
1866 ASSERT_TRUE (ggc_marked_p (insn_200));
kono
parents:
diff changeset
1867 ASSERT_TRUE (ggc_marked_p (LABEL_NAME (insn_200)));
kono
parents:
diff changeset
1868 }
kono
parents:
diff changeset
1869
kono
parents:
diff changeset
1870 /* Verify that the loader copes with an insn with a mode. */
kono
parents:
diff changeset
1871
kono
parents:
diff changeset
1872 static void
kono
parents:
diff changeset
1873 test_loading_insn_with_mode ()
kono
parents:
diff changeset
1874 {
kono
parents:
diff changeset
1875 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("insn-with-mode.rtl"));
kono
parents:
diff changeset
1876 rtx_insn *insn = get_insns ();
kono
parents:
diff changeset
1877 ASSERT_EQ (INSN, GET_CODE (insn));
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 /* Verify that the "TI" mode was set from "insn:TI". */
kono
parents:
diff changeset
1880 ASSERT_EQ (TImode, GET_MODE (insn));
kono
parents:
diff changeset
1881 }
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 /* Verify that the loader copes with a jump_insn to a label_ref. */
kono
parents:
diff changeset
1884
kono
parents:
diff changeset
1885 static void
kono
parents:
diff changeset
1886 test_loading_jump_to_label_ref ()
kono
parents:
diff changeset
1887 {
kono
parents:
diff changeset
1888 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("jump-to-label-ref.rtl"));
kono
parents:
diff changeset
1889
kono
parents:
diff changeset
1890 rtx_insn *jump_insn = get_insn_by_uid (1);
kono
parents:
diff changeset
1891 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
kono
parents:
diff changeset
1892
kono
parents:
diff changeset
1893 rtx_insn *barrier = get_insn_by_uid (2);
kono
parents:
diff changeset
1894 ASSERT_EQ (BARRIER, GET_CODE (barrier));
kono
parents:
diff changeset
1895
kono
parents:
diff changeset
1896 rtx_insn *code_label = get_insn_by_uid (100);
kono
parents:
diff changeset
1897 ASSERT_EQ (CODE_LABEL, GET_CODE (code_label));
kono
parents:
diff changeset
1898
kono
parents:
diff changeset
1899 /* Verify the jump_insn. */
kono
parents:
diff changeset
1900 ASSERT_EQ (4, BLOCK_FOR_INSN (jump_insn)->index);
kono
parents:
diff changeset
1901 ASSERT_EQ (SET, GET_CODE (PATTERN (jump_insn)));
kono
parents:
diff changeset
1902 /* Ensure that the "(pc)" is using the global singleton. */
kono
parents:
diff changeset
1903 ASSERT_RTX_PTR_EQ (pc_rtx, SET_DEST (PATTERN (jump_insn)));
kono
parents:
diff changeset
1904 rtx label_ref = SET_SRC (PATTERN (jump_insn));
kono
parents:
diff changeset
1905 ASSERT_EQ (LABEL_REF, GET_CODE (label_ref));
kono
parents:
diff changeset
1906 ASSERT_EQ (code_label, label_ref_label (label_ref));
kono
parents:
diff changeset
1907 ASSERT_EQ (code_label, JUMP_LABEL (jump_insn));
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 /* Verify the code_label. */
kono
parents:
diff changeset
1910 ASSERT_EQ (5, BLOCK_FOR_INSN (code_label)->index);
kono
parents:
diff changeset
1911 ASSERT_EQ (NULL, LABEL_NAME (code_label));
kono
parents:
diff changeset
1912 ASSERT_EQ (1, LABEL_NUSES (code_label));
kono
parents:
diff changeset
1913
kono
parents:
diff changeset
1914 /* Verify the generated CFG. */
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 /* Locate blocks. */
kono
parents:
diff changeset
1917 basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents:
diff changeset
1918 ASSERT_TRUE (entry != NULL);
kono
parents:
diff changeset
1919 ASSERT_EQ (ENTRY_BLOCK, entry->index);
kono
parents:
diff changeset
1920
kono
parents:
diff changeset
1921 basic_block exit = EXIT_BLOCK_PTR_FOR_FN (cfun);
kono
parents:
diff changeset
1922 ASSERT_TRUE (exit != NULL);
kono
parents:
diff changeset
1923 ASSERT_EQ (EXIT_BLOCK, exit->index);
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 basic_block bb4 = (*cfun->cfg->x_basic_block_info)[4];
kono
parents:
diff changeset
1926 basic_block bb5 = (*cfun->cfg->x_basic_block_info)[5];
kono
parents:
diff changeset
1927 ASSERT_EQ (4, bb4->index);
kono
parents:
diff changeset
1928 ASSERT_EQ (5, bb5->index);
kono
parents:
diff changeset
1929
kono
parents:
diff changeset
1930 /* Entry block. */
kono
parents:
diff changeset
1931 ASSERT_EQ (NULL, entry->preds);
kono
parents:
diff changeset
1932 ASSERT_EQ (1, entry->succs->length ());
kono
parents:
diff changeset
1933 ASSERT_EDGE ((*entry->succs)[0], 0, 4, EDGE_FALLTHRU);
kono
parents:
diff changeset
1934
kono
parents:
diff changeset
1935 /* bb4. */
kono
parents:
diff changeset
1936 ASSERT_EQ (1, bb4->preds->length ());
kono
parents:
diff changeset
1937 ASSERT_EDGE ((*bb4->preds)[0], 0, 4, EDGE_FALLTHRU);
kono
parents:
diff changeset
1938 ASSERT_EQ (1, bb4->succs->length ());
kono
parents:
diff changeset
1939 ASSERT_EDGE ((*bb4->succs)[0], 4, 5, 0x0);
kono
parents:
diff changeset
1940
kono
parents:
diff changeset
1941 /* bb5. */
kono
parents:
diff changeset
1942 ASSERT_EQ (1, bb5->preds->length ());
kono
parents:
diff changeset
1943 ASSERT_EDGE ((*bb5->preds)[0], 4, 5, 0x0);
kono
parents:
diff changeset
1944 ASSERT_EQ (1, bb5->succs->length ());
kono
parents:
diff changeset
1945 ASSERT_EDGE ((*bb5->succs)[0], 5, 1, EDGE_FALLTHRU);
kono
parents:
diff changeset
1946
kono
parents:
diff changeset
1947 /* Exit block. */
kono
parents:
diff changeset
1948 ASSERT_EQ (1, exit->preds->length ());
kono
parents:
diff changeset
1949 ASSERT_EDGE ((*exit->preds)[0], 5, 1, EDGE_FALLTHRU);
kono
parents:
diff changeset
1950 ASSERT_EQ (NULL, exit->succs);
kono
parents:
diff changeset
1951 }
kono
parents:
diff changeset
1952
kono
parents:
diff changeset
1953 /* Verify that the loader copes with a jump_insn to a label_ref
kono
parents:
diff changeset
1954 marked "return". */
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 static void
kono
parents:
diff changeset
1957 test_loading_jump_to_return ()
kono
parents:
diff changeset
1958 {
kono
parents:
diff changeset
1959 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("jump-to-return.rtl"));
kono
parents:
diff changeset
1960
kono
parents:
diff changeset
1961 rtx_insn *jump_insn = get_insn_by_uid (1);
kono
parents:
diff changeset
1962 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
kono
parents:
diff changeset
1963 ASSERT_RTX_PTR_EQ (ret_rtx, JUMP_LABEL (jump_insn));
kono
parents:
diff changeset
1964 }
kono
parents:
diff changeset
1965
kono
parents:
diff changeset
1966 /* Verify that the loader copes with a jump_insn to a label_ref
kono
parents:
diff changeset
1967 marked "simple_return". */
kono
parents:
diff changeset
1968
kono
parents:
diff changeset
1969 static void
kono
parents:
diff changeset
1970 test_loading_jump_to_simple_return ()
kono
parents:
diff changeset
1971 {
kono
parents:
diff changeset
1972 rtl_dump_test t (SELFTEST_LOCATION,
kono
parents:
diff changeset
1973 locate_file ("jump-to-simple-return.rtl"));
kono
parents:
diff changeset
1974
kono
parents:
diff changeset
1975 rtx_insn *jump_insn = get_insn_by_uid (1);
kono
parents:
diff changeset
1976 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
kono
parents:
diff changeset
1977 ASSERT_RTX_PTR_EQ (simple_return_rtx, JUMP_LABEL (jump_insn));
kono
parents:
diff changeset
1978 }
kono
parents:
diff changeset
1979
kono
parents:
diff changeset
1980 /* Verify that the loader copes with a NOTE_INSN_BASIC_BLOCK. */
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 static void
kono
parents:
diff changeset
1983 test_loading_note_insn_basic_block ()
kono
parents:
diff changeset
1984 {
kono
parents:
diff changeset
1985 rtl_dump_test t (SELFTEST_LOCATION,
kono
parents:
diff changeset
1986 locate_file ("note_insn_basic_block.rtl"));
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 rtx_insn *note = get_insn_by_uid (1);
kono
parents:
diff changeset
1989 ASSERT_EQ (NOTE, GET_CODE (note));
kono
parents:
diff changeset
1990 ASSERT_EQ (2, BLOCK_FOR_INSN (note)->index);
kono
parents:
diff changeset
1991
kono
parents:
diff changeset
1992 ASSERT_EQ (NOTE_INSN_BASIC_BLOCK, NOTE_KIND (note));
kono
parents:
diff changeset
1993 ASSERT_EQ (2, NOTE_BASIC_BLOCK (note)->index);
kono
parents:
diff changeset
1994 ASSERT_EQ (BASIC_BLOCK_FOR_FN (cfun, 2), NOTE_BASIC_BLOCK (note));
kono
parents:
diff changeset
1995 }
kono
parents:
diff changeset
1996
kono
parents:
diff changeset
1997 /* Verify that the loader copes with a NOTE_INSN_DELETED. */
kono
parents:
diff changeset
1998
kono
parents:
diff changeset
1999 static void
kono
parents:
diff changeset
2000 test_loading_note_insn_deleted ()
kono
parents:
diff changeset
2001 {
kono
parents:
diff changeset
2002 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("note-insn-deleted.rtl"));
kono
parents:
diff changeset
2003
kono
parents:
diff changeset
2004 rtx_insn *note = get_insn_by_uid (1);
kono
parents:
diff changeset
2005 ASSERT_EQ (NOTE, GET_CODE (note));
kono
parents:
diff changeset
2006 ASSERT_EQ (NOTE_INSN_DELETED, NOTE_KIND (note));
kono
parents:
diff changeset
2007 }
kono
parents:
diff changeset
2008
kono
parents:
diff changeset
2009 /* Verify that the const_int values are consolidated, since
kono
parents:
diff changeset
2010 pointer equality corresponds to value equality.
kono
parents:
diff changeset
2011 TODO: do this for all in CASE_CONST_UNIQUE. */
kono
parents:
diff changeset
2012
kono
parents:
diff changeset
2013 static void
kono
parents:
diff changeset
2014 test_loading_const_int ()
kono
parents:
diff changeset
2015 {
kono
parents:
diff changeset
2016 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("const-int.rtl"));
kono
parents:
diff changeset
2017
kono
parents:
diff changeset
2018 /* Verify that const_int values below MAX_SAVED_CONST_INT use
kono
parents:
diff changeset
2019 the global values. */
kono
parents:
diff changeset
2020 ASSERT_EQ (const0_rtx, SET_SRC (PATTERN (get_insn_by_uid (1))));
kono
parents:
diff changeset
2021 ASSERT_EQ (const1_rtx, SET_SRC (PATTERN (get_insn_by_uid (2))));
kono
parents:
diff changeset
2022 ASSERT_EQ (constm1_rtx, SET_SRC (PATTERN (get_insn_by_uid (3))));
kono
parents:
diff changeset
2023
kono
parents:
diff changeset
2024 /* Verify that other const_int values are consolidated. */
kono
parents:
diff changeset
2025 rtx int256 = gen_rtx_CONST_INT (SImode, 256);
kono
parents:
diff changeset
2026 ASSERT_EQ (int256, SET_SRC (PATTERN (get_insn_by_uid (4))));
kono
parents:
diff changeset
2027 }
kono
parents:
diff changeset
2028
ko&#