* download_ecj: Remove.
[official-gcc.git] / gcc / read-rtl-function.c
blobc5cb3f7953f7cf587e14c148445d3474a7d70745
1 /* read-rtl-function.c - Reader for RTL function dumps
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "target.h"
24 #include "tree.h"
25 #include "diagnostic.h"
26 #include "read-md.h"
27 #include "rtl.h"
28 #include "cfghooks.h"
29 #include "stringpool.h"
30 #include "function.h"
31 #include "tree-cfg.h"
32 #include "cfg.h"
33 #include "basic-block.h"
34 #include "cfgrtl.h"
35 #include "memmodel.h"
36 #include "emit-rtl.h"
37 #include "cgraph.h"
38 #include "tree-pass.h"
39 #include "toplev.h"
40 #include "varasm.h"
41 #include "read-rtl-function.h"
42 #include "selftest.h"
43 #include "selftest-rtl.h"
45 /* Forward decls. */
46 class function_reader;
47 class fixup;
49 /* Edges are recorded when parsing the "insn-chain" directive,
50 and created at the end when all the blocks ought to exist.
51 This struct records an "edge-from" or "edge-to" directive seen
52 at LOC, which will be turned into an actual CFG edge once
53 the "insn-chain" is fully parsed. */
55 struct deferred_edge
57 deferred_edge (file_location loc, int src_bb_idx, int dest_bb_idx, int flags)
58 : m_loc (loc), m_src_bb_idx (src_bb_idx), m_dest_bb_idx (dest_bb_idx),
59 m_flags (flags)
62 file_location m_loc;
63 int m_src_bb_idx;
64 int m_dest_bb_idx;
65 int m_flags;
68 /* Subclass of rtx_reader for reading function dumps. */
70 class function_reader : public rtx_reader
72 public:
73 function_reader ();
74 ~function_reader ();
76 /* Overridden vfuncs of class md_reader. */
77 void handle_unknown_directive (file_location, const char *) FINAL OVERRIDE;
79 /* Overridden vfuncs of class rtx_reader. */
80 rtx read_rtx_operand (rtx x, int idx) FINAL OVERRIDE;
81 void handle_any_trailing_information (rtx x) FINAL OVERRIDE;
82 rtx postprocess (rtx) FINAL OVERRIDE;
83 const char *finalize_string (char *stringbuf) FINAL OVERRIDE;
85 rtx_insn **get_insn_by_uid (int uid);
86 tree parse_mem_expr (const char *desc);
88 private:
89 void parse_function ();
90 void create_function ();
91 void parse_param ();
92 void parse_insn_chain ();
93 void parse_block ();
94 int parse_bb_idx ();
95 void parse_edge (basic_block block, bool from);
96 rtx_insn *parse_insn (file_location loc, const char *name);
97 void parse_cfg (file_location loc);
98 void parse_crtl (file_location loc);
99 void create_edges ();
101 int parse_enum_value (int num_values, const char *const *strings);
103 void read_rtx_operand_u (rtx x, int idx);
104 void read_rtx_operand_i_or_n (rtx x, int idx, char format_char);
105 rtx read_rtx_operand_r (rtx x);
106 void extra_parsing_for_operand_code_0 (rtx x, int idx);
108 void add_fixup_insn_uid (file_location loc, rtx insn, int operand_idx,
109 int insn_uid);
111 void add_fixup_note_insn_basic_block (file_location loc, rtx insn,
112 int operand_idx, int bb_idx);
114 void add_fixup_source_location (file_location loc, rtx_insn *insn,
115 const char *filename, int lineno);
117 void add_fixup_expr (file_location loc, rtx x,
118 const char *desc);
120 rtx consolidate_singletons (rtx x);
121 rtx parse_rtx ();
122 void maybe_read_location (rtx_insn *insn);
124 void handle_insn_uids ();
125 void apply_fixups ();
127 private:
128 struct uid_hash : int_hash <int, -1, -2> {};
129 hash_map<uid_hash, rtx_insn *> m_insns_by_uid;
130 auto_vec<fixup *> m_fixups;
131 rtx_insn *m_first_insn;
132 auto_vec<tree> m_fake_scope;
133 char *m_name;
134 bool m_have_crtl_directive;
135 basic_block m_bb_to_insert_after;
136 auto_vec <deferred_edge> m_deferred_edges;
137 int m_highest_bb_idx;
140 /* Abstract base class for recording post-processing steps that must be
141 done after reading a .rtl file. */
143 class fixup
145 public:
146 /* Constructor for a fixup at LOC affecting X. */
147 fixup (file_location loc, rtx x)
148 : m_loc (loc), m_rtx (x)
150 virtual ~fixup () {}
152 virtual void apply (function_reader *reader) const = 0;
154 protected:
155 file_location m_loc;
156 rtx m_rtx;
159 /* An abstract subclass of fixup for post-processing steps that
160 act on a specific operand of a specific instruction. */
162 class operand_fixup : public fixup
164 public:
165 /* Constructor for a fixup at LOC affecting INSN's operand
166 with index OPERAND_IDX. */
167 operand_fixup (file_location loc, rtx insn, int operand_idx)
168 : fixup (loc, insn), m_operand_idx (operand_idx)
171 protected:
172 int m_operand_idx;
175 /* A concrete subclass of operand_fixup: fixup an rtx_insn *
176 field based on an integer UID. */
178 class fixup_insn_uid : public operand_fixup
180 public:
181 /* Constructor for a fixup at LOC affecting INSN's operand
182 with index OPERAND_IDX. Record INSN_UID as the uid. */
183 fixup_insn_uid (file_location loc, rtx insn, int operand_idx, int insn_uid)
184 : operand_fixup (loc, insn, operand_idx),
185 m_insn_uid (insn_uid)
188 void apply (function_reader *reader) const;
190 private:
191 int m_insn_uid;
194 /* A concrete subclass of operand_fixup: fix up a
195 NOTE_INSN_BASIC_BLOCK based on an integer block ID. */
197 class fixup_note_insn_basic_block : public operand_fixup
199 public:
200 fixup_note_insn_basic_block (file_location loc, rtx insn, int operand_idx,
201 int bb_idx)
202 : operand_fixup (loc, insn, operand_idx),
203 m_bb_idx (bb_idx)
206 void apply (function_reader *reader) const;
208 private:
209 int m_bb_idx;
212 /* A concrete subclass of fixup (not operand_fixup): fix up
213 the expr of an rtx (REG or MEM) based on a textual dump. */
215 class fixup_expr : public fixup
217 public:
218 fixup_expr (file_location loc, rtx x, const char *desc)
219 : fixup (loc, x),
220 m_desc (xstrdup (desc))
223 ~fixup_expr () { free (m_desc); }
225 void apply (function_reader *reader) const;
227 private:
228 char *m_desc;
231 /* Return a textual description of the operand of INSN with
232 index OPERAND_IDX. */
234 static const char *
235 get_operand_name (rtx insn, int operand_idx)
237 gcc_assert (is_a <rtx_insn *> (insn));
238 switch (operand_idx)
240 case 0:
241 return "PREV_INSN";
242 case 1:
243 return "NEXT_INSN";
244 default:
245 return NULL;
249 /* Fixup an rtx_insn * field based on an integer UID, as read by READER. */
251 void
252 fixup_insn_uid::apply (function_reader *reader) const
254 rtx_insn **insn_from_uid = reader->get_insn_by_uid (m_insn_uid);
255 if (insn_from_uid)
256 XEXP (m_rtx, m_operand_idx) = *insn_from_uid;
257 else
259 const char *op_name = get_operand_name (m_rtx, m_operand_idx);
260 if (op_name)
261 error_at (m_loc,
262 "insn with UID %i not found for operand %i (`%s') of insn %i",
263 m_insn_uid, m_operand_idx, op_name, INSN_UID (m_rtx));
264 else
265 error_at (m_loc,
266 "insn with UID %i not found for operand %i of insn %i",
267 m_insn_uid, m_operand_idx, INSN_UID (m_rtx));
271 /* Fix up a NOTE_INSN_BASIC_BLOCK based on an integer block ID. */
273 void
274 fixup_note_insn_basic_block::apply (function_reader *) const
276 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, m_bb_idx);
277 gcc_assert (bb);
278 NOTE_BASIC_BLOCK (m_rtx) = bb;
281 /* Fix up the expr of an rtx (REG or MEM) based on a textual dump
282 read by READER. */
284 void
285 fixup_expr::apply (function_reader *reader) const
287 tree expr = reader->parse_mem_expr (m_desc);
288 switch (GET_CODE (m_rtx))
290 case REG:
291 set_reg_attrs_for_decl_rtl (expr, m_rtx);
292 break;
293 case MEM:
294 set_mem_expr (m_rtx, expr);
295 break;
296 default:
297 gcc_unreachable ();
301 /* Strip trailing whitespace from DESC. */
303 static void
304 strip_trailing_whitespace (char *desc)
306 char *terminator = desc + strlen (desc);
307 while (desc < terminator)
309 terminator--;
310 if (ISSPACE (*terminator))
311 *terminator = '\0';
312 else
313 break;
317 /* Return the numeric value n for GET_NOTE_INSN_NAME (n) for STRING,
318 or fail if STRING isn't recognized. */
320 static int
321 parse_note_insn_name (const char *string)
323 for (int i = 0; i < NOTE_INSN_MAX; i++)
324 if (0 == strcmp (string, GET_NOTE_INSN_NAME (i)))
325 return i;
326 fatal_with_file_and_line ("unrecognized NOTE_INSN name: `%s'", string);
329 /* Return the register number for NAME, or return -1 if it isn't
330 recognized. */
332 static int
333 lookup_reg_by_dump_name (const char *name)
335 for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
336 if (reg_names[i][0]
337 && ! strcmp (name, reg_names[i]))
338 return i;
340 /* Also lookup virtuals. */
341 if (!strcmp (name, "virtual-incoming-args"))
342 return VIRTUAL_INCOMING_ARGS_REGNUM;
343 if (!strcmp (name, "virtual-stack-vars"))
344 return VIRTUAL_STACK_VARS_REGNUM;
345 if (!strcmp (name, "virtual-stack-dynamic"))
346 return VIRTUAL_STACK_DYNAMIC_REGNUM;
347 if (!strcmp (name, "virtual-outgoing-args"))
348 return VIRTUAL_OUTGOING_ARGS_REGNUM;
349 if (!strcmp (name, "virtual-cfa"))
350 return VIRTUAL_CFA_REGNUM;
351 if (!strcmp (name, "virtual-preferred-stack-boundary"))
352 return VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM;
353 /* TODO: handle "virtual-reg-%d". */
355 /* In compact mode, pseudos are printed with '< and '>' wrapping the regno,
356 offseting it by (LAST_VIRTUAL_REGISTER + 1), so that the
357 first non-virtual pseudo is dumped as "<0>". */
358 if (name[0] == '<' && name[strlen (name) - 1] == '>')
360 int dump_num = atoi (name + 1);
361 return dump_num + LAST_VIRTUAL_REGISTER + 1;
364 /* Not found. */
365 return -1;
368 /* class function_reader : public rtx_reader */
370 /* function_reader's constructor. */
372 function_reader::function_reader ()
373 : rtx_reader (true),
374 m_first_insn (NULL),
375 m_name (NULL),
376 m_have_crtl_directive (false),
377 m_bb_to_insert_after (NULL),
378 m_highest_bb_idx (EXIT_BLOCK)
382 /* function_reader's destructor. */
384 function_reader::~function_reader ()
386 int i;
387 fixup *f;
388 FOR_EACH_VEC_ELT (m_fixups, i, f)
389 delete f;
391 free (m_name);
394 /* Implementation of rtx_reader::handle_unknown_directive,
395 for parsing the remainder of a directive with name NAME
396 seen at START_LOC.
398 Require a top-level "function" directive, as emitted by
399 print_rtx_function, and parse it. */
401 void
402 function_reader::handle_unknown_directive (file_location start_loc,
403 const char *name)
405 if (strcmp (name, "function"))
406 fatal_at (start_loc, "expected 'function'");
408 parse_function ();
411 /* Parse the output of print_rtx_function (or hand-written data in the
412 same format), having already parsed the "(function" heading, and
413 finishing immediately before the final ")".
415 The "param" and "crtl" clauses are optional. */
417 void
418 function_reader::parse_function ()
420 m_name = xstrdup (read_string (0));
422 create_function ();
424 while (1)
426 int c = read_skip_spaces ();
427 if (c == ')')
429 unread_char (c);
430 break;
432 unread_char (c);
433 require_char ('(');
434 file_location loc = get_current_location ();
435 struct md_name directive;
436 read_name (&directive);
437 if (strcmp (directive.string, "param") == 0)
438 parse_param ();
439 else if (strcmp (directive.string, "insn-chain") == 0)
440 parse_insn_chain ();
441 else if (strcmp (directive.string, "crtl") == 0)
442 parse_crtl (loc);
443 else
444 fatal_with_file_and_line ("unrecognized directive: %s",
445 directive.string);
448 handle_insn_uids ();
450 apply_fixups ();
452 /* Rebuild the JUMP_LABEL field of any JUMP_INSNs in the chain, and the
453 LABEL_NUSES of any CODE_LABELs.
455 This has to happen after apply_fixups, since only after then do
456 LABEL_REFs have their label_ref_label set up. */
457 rebuild_jump_labels (get_insns ());
459 crtl->init_stack_alignment ();
462 /* Set up state for the function *before* fixups are applied.
464 Create "cfun" and a decl for the function.
465 By default, every function decl is hardcoded as
466 int test_1 (int i, int j, int k);
467 Set up various other state:
468 - the cfg and basic blocks (edges are created later, *after* fixups
469 are applied).
470 - add the function to the callgraph. */
472 void
473 function_reader::create_function ()
475 /* We start in cfgrtl mode, rather than cfglayout mode. */
476 rtl_register_cfg_hooks ();
478 /* Create cfun. */
479 tree fn_name = get_identifier (m_name ? m_name : "test_1");
480 tree int_type = integer_type_node;
481 tree return_type = int_type;
482 tree arg_types[3] = {int_type, int_type, int_type};
483 tree fn_type = build_function_type_array (return_type, 3, arg_types);
484 tree fndecl = build_decl_stat (UNKNOWN_LOCATION, FUNCTION_DECL, fn_name,
485 fn_type);
486 tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE,
487 return_type);
488 DECL_ARTIFICIAL (resdecl) = 1;
489 DECL_IGNORED_P (resdecl) = 1;
490 DECL_RESULT (fndecl) = resdecl;
491 allocate_struct_function (fndecl, false);
492 /* This sets cfun. */
494 current_function_decl = fndecl;
496 cfun->curr_properties = (PROP_cfg | PROP_rtl);
498 /* Do we need this to force cgraphunit.c to output the function? */
499 DECL_EXTERNAL (fndecl) = 0;
500 DECL_PRESERVE_P (fndecl) = 1;
502 /* Add to cgraph. */
503 cgraph_node::finalize_function (fndecl, false);
505 /* Create bare-bones cfg. This creates the entry and exit blocks. */
506 init_empty_tree_cfg_for_function (cfun);
507 ENTRY_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
508 EXIT_BLOCK_PTR_FOR_FN (cfun)->flags |= BB_RTL;
509 init_rtl_bb_info (ENTRY_BLOCK_PTR_FOR_FN (cfun));
510 init_rtl_bb_info (EXIT_BLOCK_PTR_FOR_FN (cfun));
511 m_bb_to_insert_after = ENTRY_BLOCK_PTR_FOR_FN (cfun);
515 /* Look within the the params of FNDECL for a param named NAME.
516 Return NULL_TREE if one isn't found. */
518 static tree
519 find_param_by_name (tree fndecl, const char *name)
521 for (tree arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg))
522 if (strcmp (name, IDENTIFIER_POINTER (DECL_NAME (arg))) == 0)
523 return arg;
524 return NULL_TREE;
527 /* Parse the content of a "param" directive, having already parsed the
528 "(param". Consume the trailing ')'. */
530 void
531 function_reader::parse_param ()
533 require_char_ws ('"');
534 file_location loc = get_current_location ();
535 char *name = read_quoted_string ();
537 /* Lookup param by name. */
538 tree t_param = find_param_by_name (cfun->decl, name);
539 if (!t_param)
540 fatal_at (loc, "param not found: %s", name);
542 /* Parse DECL_RTL. */
543 require_char_ws ('(');
544 require_word_ws ("DECL_RTL");
545 DECL_WRTL_CHECK (t_param)->decl_with_rtl.rtl = parse_rtx ();
546 require_char_ws (')');
548 /* Parse DECL_RTL_INCOMING. */
549 require_char_ws ('(');
550 require_word_ws ("DECL_RTL_INCOMING");
551 DECL_INCOMING_RTL (t_param) = parse_rtx ();
552 require_char_ws (')');
554 require_char_ws (')');
557 /* Parse zero or more child insn elements within an
558 "insn-chain" element. Consume the trailing ')'. */
560 void
561 function_reader::parse_insn_chain ()
563 while (1)
565 int c = read_skip_spaces ();
566 file_location loc = get_current_location ();
567 if (c == ')')
568 break;
569 else if (c == '(')
571 struct md_name directive;
572 read_name (&directive);
573 if (strcmp (directive.string, "block") == 0)
574 parse_block ();
575 else
576 parse_insn (loc, directive.string);
578 else
579 fatal_at (loc, "expected '(' or ')'");
582 create_edges ();
585 /* Parse zero or more child directives (edges and insns) within a
586 "block" directive, having already parsed the "(block " heading.
587 Consume the trailing ')'. */
589 void
590 function_reader::parse_block ()
592 /* Parse the index value from the dump. This will be an integer;
593 we don't support "entry" or "exit" here (unlike for edges). */
594 struct md_name name;
595 read_name (&name);
596 int bb_idx = atoi (name.string);
598 /* The term "index" has two meanings for basic blocks in a CFG:
599 (a) the "index" field within struct basic_block_def.
600 (b) the index of a basic_block within the cfg's x_basic_block_info
601 vector, as accessed via BASIC_BLOCK_FOR_FN.
603 These can get out-of-sync when basic blocks are optimized away.
604 They get back in sync by "compact_blocks".
605 We reconstruct cfun->cfg->x_basic_block_info->m_vecdata with NULL
606 values in it for any missing basic blocks, so that (a) == (b) for
607 all of the blocks we create. The doubly-linked list of basic
608 blocks (next_bb/prev_bb) skips over these "holes". */
610 if (m_highest_bb_idx < bb_idx)
611 m_highest_bb_idx = bb_idx;
613 size_t new_size = m_highest_bb_idx + 1;
614 if (basic_block_info_for_fn (cfun)->length () < new_size)
615 vec_safe_grow_cleared (basic_block_info_for_fn (cfun), new_size);
617 last_basic_block_for_fn (cfun) = new_size;
619 /* Create the basic block.
621 We can't call create_basic_block and use the regular RTL block-creation
622 hooks, since this creates NOTE_INSN_BASIC_BLOCK instances. We don't
623 want to do that; we want to use the notes we were provided with. */
624 basic_block bb = alloc_block ();
625 init_rtl_bb_info (bb);
626 bb->index = bb_idx;
627 bb->flags = BB_NEW | BB_RTL;
628 link_block (bb, m_bb_to_insert_after);
629 m_bb_to_insert_after = bb;
631 n_basic_blocks_for_fn (cfun)++;
632 SET_BASIC_BLOCK_FOR_FN (cfun, bb_idx, bb);
633 BB_SET_PARTITION (bb, BB_UNPARTITIONED);
635 /* Handle insns, edge-from and edge-to directives. */
636 while (1)
638 int c = read_skip_spaces ();
639 file_location loc = get_current_location ();
640 if (c == ')')
641 break;
642 else if (c == '(')
644 struct md_name directive;
645 read_name (&directive);
646 if (strcmp (directive.string, "edge-from") == 0)
647 parse_edge (bb, true);
648 else if (strcmp (directive.string, "edge-to") == 0)
649 parse_edge (bb, false);
650 else
652 rtx_insn *insn = parse_insn (loc, directive.string);
653 set_block_for_insn (insn, bb);
654 if (!BB_HEAD (bb))
655 BB_HEAD (bb) = insn;
656 BB_END (bb) = insn;
659 else
660 fatal_at (loc, "expected '(' or ')'");
664 /* Subroutine of function_reader::parse_edge.
665 Parse a basic block index, handling "entry" and "exit". */
668 function_reader::parse_bb_idx ()
670 struct md_name name;
671 read_name (&name);
672 if (strcmp (name.string, "entry") == 0)
673 return ENTRY_BLOCK;
674 if (strcmp (name.string, "exit") == 0)
675 return EXIT_BLOCK;
676 return atoi (name.string);
679 /* Subroutine of parse_edge_flags.
680 Parse TOK, a token such as "FALLTHRU", converting to the flag value.
681 Issue an error if the token is unrecognized. */
683 static int
684 parse_edge_flag_token (const char *tok)
686 #define DEF_EDGE_FLAG(NAME,IDX) \
687 do { \
688 if (strcmp (tok, #NAME) == 0) \
689 return EDGE_##NAME; \
690 } while (0);
691 #include "cfg-flags.def"
692 #undef DEF_EDGE_FLAG
693 error ("unrecognized edge flag: '%s'", tok);
694 return 0;
697 /* Subroutine of function_reader::parse_edge.
698 Parse STR and convert to a flag value (or issue an error).
699 The parser uses strtok and hence modifiers STR in-place. */
701 static int
702 parse_edge_flags (char *str)
704 int result = 0;
706 char *tok = strtok (str, "| ");
707 while (tok)
709 result |= parse_edge_flag_token (tok);
710 tok = strtok (NULL, "| ");
713 return result;
716 /* Parse an "edge-from" or "edge-to" directive within the "block"
717 directive for BLOCK, having already parsed the "(edge" heading.
718 Consume the final ")". Record the edge within m_deferred_edges.
719 FROM is true for an "edge-from" directive, false for an "edge-to"
720 directive. */
722 void
723 function_reader::parse_edge (basic_block block, bool from)
725 gcc_assert (block);
726 int this_bb_idx = block->index;
727 file_location loc = get_current_location ();
728 int other_bb_idx = parse_bb_idx ();
730 /* "(edge-from 2)" means src = 2, dest = this_bb_idx, whereas
731 "(edge-to 3)" means src = this_bb_idx, dest = 3. */
732 int src_idx = from ? other_bb_idx : this_bb_idx;
733 int dest_idx = from ? this_bb_idx : other_bb_idx;
735 /* Optional "(flags)". */
736 int flags = 0;
737 int c = read_skip_spaces ();
738 if (c == '(')
740 require_word_ws ("flags");
741 require_char_ws ('"');
742 char *str = read_quoted_string ();
743 flags = parse_edge_flags (str);
744 require_char_ws (')');
746 else
747 unread_char (c);
749 require_char_ws (')');
751 /* This BB already exists, but the other BB might not yet.
752 For now, save the edges, and create them at the end of insn-chain
753 processing. */
754 /* For now, only process the (edge-from) to this BB, and (edge-to)
755 that go to the exit block.
756 FIXME: we don't yet verify that the edge-from and edge-to directives
757 are consistent. */
758 if (from || dest_idx == EXIT_BLOCK)
759 m_deferred_edges.safe_push (deferred_edge (loc, src_idx, dest_idx, flags));
762 /* Parse an rtx instruction, having parsed the opening and parenthesis, and
763 name NAME, seen at START_LOC, by calling read_rtx_code, calling
764 set_first_insn and set_last_insn as appropriate, and
765 adding the insn to the insn chain.
766 Consume the trailing ')'. */
768 rtx_insn *
769 function_reader::parse_insn (file_location start_loc, const char *name)
771 rtx x = read_rtx_code (name);
772 if (!x)
773 fatal_at (start_loc, "expected insn type; got '%s'", name);
774 rtx_insn *insn = dyn_cast <rtx_insn *> (x);
775 if (!insn)
776 fatal_at (start_loc, "expected insn type; got '%s'", name);
778 /* Consume the trailing ')'. */
779 require_char_ws (')');
781 rtx_insn *last_insn = get_last_insn ();
783 /* Add "insn" to the insn chain. */
784 if (last_insn)
786 gcc_assert (NEXT_INSN (last_insn) == NULL);
787 SET_NEXT_INSN (last_insn) = insn;
789 SET_PREV_INSN (insn) = last_insn;
791 /* Add it to the sequence. */
792 set_last_insn (insn);
793 if (!m_first_insn)
795 m_first_insn = insn;
796 set_first_insn (insn);
799 if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
800 maybe_set_max_label_num (label);
802 return insn;
805 /* Postprocessing subroutine for parse_insn_chain: all the basic blocks
806 should have been created by now; create the edges that were seen. */
808 void
809 function_reader::create_edges ()
811 int i;
812 deferred_edge *de;
813 FOR_EACH_VEC_ELT (m_deferred_edges, i, de)
815 /* The BBs should already have been created by parse_block. */
816 basic_block src = BASIC_BLOCK_FOR_FN (cfun, de->m_src_bb_idx);
817 if (!src)
818 fatal_at (de->m_loc, "error: block index %i not found",
819 de->m_src_bb_idx);
820 basic_block dst = BASIC_BLOCK_FOR_FN (cfun, de->m_dest_bb_idx);
821 if (!dst)
822 fatal_at (de->m_loc, "error: block with index %i not found",
823 de->m_dest_bb_idx);
824 unchecked_make_edge (src, dst, de->m_flags);
828 /* Parse a "crtl" directive, having already parsed the "(crtl" heading
829 at location LOC.
830 Consume the final ")". */
832 void
833 function_reader::parse_crtl (file_location loc)
835 if (m_have_crtl_directive)
836 error_at (loc, "more than one 'crtl' directive");
837 m_have_crtl_directive = true;
839 /* return_rtx. */
840 require_char_ws ('(');
841 require_word_ws ("return_rtx");
842 crtl->return_rtx = parse_rtx ();
843 require_char_ws (')');
845 require_char_ws (')');
848 /* Parse operand IDX of X, returning X, or an equivalent rtx
849 expression (for consolidating singletons).
850 This is an overridden implementation of rtx_reader::read_rtx_operand for
851 function_reader, handling various extra data printed by print_rtx,
852 and sometimes calling the base class implementation. */
855 function_reader::read_rtx_operand (rtx x, int idx)
857 RTX_CODE code = GET_CODE (x);
858 const char *format_ptr = GET_RTX_FORMAT (code);
859 const char format_char = format_ptr[idx];
860 struct md_name name;
862 /* Override the regular parser for some format codes. */
863 switch (format_char)
865 case 'e':
866 if (idx == 7 && CALL_P (x))
868 m_in_call_function_usage = true;
869 return rtx_reader::read_rtx_operand (x, idx);
870 m_in_call_function_usage = false;
872 else
873 return rtx_reader::read_rtx_operand (x, idx);
874 break;
876 case 'u':
877 read_rtx_operand_u (x, idx);
878 /* Don't run regular parser for 'u'. */
879 return x;
881 case 'i':
882 case 'n':
883 read_rtx_operand_i_or_n (x, idx, format_char);
884 /* Don't run regular parser for these codes. */
885 return x;
887 case 'B':
888 gcc_assert (is_compact ());
889 /* Compact mode doesn't store BBs. */
890 /* Don't run regular parser. */
891 return x;
893 case 'r':
894 /* Don't run regular parser for 'r'. */
895 return read_rtx_operand_r (x);
897 default:
898 break;
901 /* Call base class implementation. */
902 x = rtx_reader::read_rtx_operand (x, idx);
904 /* Handle any additional parsing needed to handle what the dump
905 could contain. */
906 switch (format_char)
908 case '0':
909 extra_parsing_for_operand_code_0 (x, idx);
910 break;
912 case 'w':
913 if (!is_compact ())
915 /* Strip away the redundant hex dump of the value. */
916 require_char_ws ('[');
917 read_name (&name);
918 require_char_ws (']');
920 break;
922 default:
923 break;
926 return x;
929 /* Parse operand IDX of X, of code 'u', when reading function dumps.
931 The RTL file recorded the ID of an insn (or 0 for NULL); we
932 must store this as a pointer, but the insn might not have
933 been loaded yet. Store the ID away for now, via a fixup. */
935 void
936 function_reader::read_rtx_operand_u (rtx x, int idx)
938 /* In compact mode, the PREV/NEXT insn uids are not dumped, so skip
939 the "uu" when reading. */
940 if (is_compact () && GET_CODE (x) != LABEL_REF)
941 return;
943 struct md_name name;
944 file_location loc = read_name (&name);
945 int insn_id = atoi (name.string);
946 if (insn_id)
947 add_fixup_insn_uid (loc, x, idx, insn_id);
950 /* Read a name, looking for a match against a string found in array
951 STRINGS of size NUM_VALUES.
952 Return the index of the the matched string, or emit an error. */
955 function_reader::parse_enum_value (int num_values, const char *const *strings)
957 struct md_name name;
958 read_name (&name);
959 for (int i = 0; i < num_values; i++)
961 if (strcmp (name.string, strings[i]) == 0)
962 return i;
964 error ("unrecognized enum value: '%s'", name.string);
965 return 0;
968 /* Parse operand IDX of X, of code 'i' or 'n' (as specified by FORMAT_CHAR).
969 Special-cased handling of these, for reading function dumps. */
971 void
972 function_reader::read_rtx_operand_i_or_n (rtx x, int idx,
973 char format_char)
975 /* Handle some of the extra information that print_rtx
976 can write out for these cases. */
977 /* print_rtx only writes out operand 5 for notes
978 for NOTE_KIND values NOTE_INSN_DELETED_LABEL
979 and NOTE_INSN_DELETED_DEBUG_LABEL. */
980 if (idx == 5 && NOTE_P (x))
981 return;
983 if (idx == 4 && INSN_P (x))
985 maybe_read_location (as_a <rtx_insn *> (x));
986 return;
989 /* INSN_CODEs aren't printed in compact mode, so don't attempt to
990 parse them. */
991 if (is_compact ()
992 && INSN_P (x)
993 && &INSN_CODE (x) == &XINT (x, idx))
995 INSN_CODE (x) = -1;
996 return;
999 /* Handle UNSPEC and UNSPEC_VOLATILE's operand 1. */
1000 #if !defined(GENERATOR_FILE) && NUM_UNSPECV_VALUES > 0
1001 if (idx == 1
1002 && GET_CODE (x) == UNSPEC_VOLATILE)
1004 XINT (x, 1)
1005 = parse_enum_value (NUM_UNSPECV_VALUES, unspecv_strings);
1006 return;
1008 #endif
1009 #if !defined(GENERATOR_FILE) && NUM_UNSPEC_VALUES > 0
1010 if (idx == 1
1011 && (GET_CODE (x) == UNSPEC
1012 || GET_CODE (x) == UNSPEC_VOLATILE))
1014 XINT (x, 1)
1015 = parse_enum_value (NUM_UNSPEC_VALUES, unspec_strings);
1016 return;
1018 #endif
1020 struct md_name name;
1021 read_name (&name);
1022 int value;
1023 if (format_char == 'n')
1024 value = parse_note_insn_name (name.string);
1025 else
1026 value = atoi (name.string);
1027 XINT (x, idx) = value;
1030 /* Parse the 'r' operand of X, returning X, or an equivalent rtx
1031 expression (for consolidating singletons).
1032 Special-cased handling of code 'r' for reading function dumps. */
1035 function_reader::read_rtx_operand_r (rtx x)
1037 struct md_name name;
1038 file_location loc = read_name (&name);
1039 int regno = lookup_reg_by_dump_name (name.string);
1040 if (regno == -1)
1041 fatal_at (loc, "unrecognized register: '%s'", name.string);
1043 set_regno_raw (x, regno, 1);
1045 /* Consolidate singletons. */
1046 x = consolidate_singletons (x);
1048 ORIGINAL_REGNO (x) = regno;
1050 /* Parse extra stuff at end of 'r'.
1051 We may have zero, one, or two sections marked by square
1052 brackets. */
1053 int ch = read_skip_spaces ();
1054 bool expect_original_regno = false;
1055 if (ch == '[')
1057 file_location loc = get_current_location ();
1058 char *desc = read_until ("]", true);
1059 strip_trailing_whitespace (desc);
1060 const char *desc_start = desc;
1061 /* If ORIGINAL_REGNO (rtx) != regno, we will have:
1062 "orig:%i", ORIGINAL_REGNO (rtx).
1063 Consume it, we don't set ORIGINAL_REGNO, since we can
1064 get that from the 2nd copy later. */
1065 if (0 == strncmp (desc, "orig:", 5))
1067 expect_original_regno = true;
1068 desc_start += 5;
1069 /* Skip to any whitespace following the integer. */
1070 const char *space = strchr (desc_start, ' ');
1071 if (space)
1072 desc_start = space + 1;
1074 /* Any remaining text may be the REG_EXPR. Alternatively we have
1075 no REG_ATTRS, and instead we have ORIGINAL_REGNO. */
1076 if (ISDIGIT (*desc_start))
1078 /* Assume we have ORIGINAL_REGNO. */
1079 ORIGINAL_REGNO (x) = atoi (desc_start);
1081 else
1083 /* Assume we have REG_EXPR. */
1084 add_fixup_expr (loc, x, desc_start);
1086 free (desc);
1088 else
1089 unread_char (ch);
1090 if (expect_original_regno)
1092 require_char_ws ('[');
1093 char *desc = read_until ("]", true);
1094 ORIGINAL_REGNO (x) = atoi (desc);
1095 free (desc);
1098 return x;
1101 /* Additional parsing for format code '0' in dumps, handling a variety
1102 of special-cases in print_rtx, when parsing operand IDX of X. */
1104 void
1105 function_reader::extra_parsing_for_operand_code_0 (rtx x, int idx)
1107 RTX_CODE code = GET_CODE (x);
1108 int c;
1109 struct md_name name;
1111 if (idx == 1 && code == SYMBOL_REF)
1113 /* Possibly wrote " [flags %#x]", SYMBOL_REF_FLAGS (in_rtx). */
1114 c = read_skip_spaces ();
1115 if (c == '[')
1117 file_location loc = read_name (&name);
1118 if (strcmp (name.string, "flags"))
1119 error_at (loc, "was expecting `%s'", "flags");
1120 read_name (&name);
1121 SYMBOL_REF_FLAGS (x) = strtol (name.string, NULL, 16);
1123 /* We can't reconstruct SYMBOL_REF_BLOCK; set it to NULL. */
1124 if (SYMBOL_REF_HAS_BLOCK_INFO_P (x))
1125 SYMBOL_REF_BLOCK (x) = NULL;
1127 require_char (']');
1129 else
1130 unread_char (c);
1132 /* If X had a non-NULL SYMBOL_REF_DECL,
1133 rtx_writer::print_rtx_operand_code_0 would have dumped it
1134 using print_node_brief.
1135 Skip the content for now. */
1136 c = read_skip_spaces ();
1137 if (c == '<')
1139 while (1)
1141 char ch = read_char ();
1142 if (ch == '>')
1143 break;
1146 else
1147 unread_char (c);
1149 else if (idx == 3 && code == NOTE)
1151 /* Note-specific data appears for operand 3, which annoyingly
1152 is before the enum specifying which kind of note we have
1153 (operand 4). */
1154 c = read_skip_spaces ();
1155 if (c == '[')
1157 /* Possibly data for a NOTE_INSN_BASIC_BLOCK, of the form:
1158 [bb %d]. */
1159 file_location bb_loc = read_name (&name);
1160 if (strcmp (name.string, "bb"))
1161 error_at (bb_loc, "was expecting `%s'", "bb");
1162 read_name (&name);
1163 int bb_idx = atoi (name.string);
1164 add_fixup_note_insn_basic_block (bb_loc, x, idx,
1165 bb_idx);
1166 require_char_ws (']');
1168 else
1169 unread_char (c);
1173 /* Implementation of rtx_reader::handle_any_trailing_information.
1174 Handle the various additional information that print-rtl.c can
1175 write after the regular fields, when parsing X. */
1177 void
1178 function_reader::handle_any_trailing_information (rtx x)
1180 struct md_name name;
1182 switch (GET_CODE (x))
1184 case MEM:
1186 int ch;
1187 require_char_ws ('[');
1188 read_name (&name);
1189 set_mem_alias_set (x, atoi (name.string));
1190 /* We have either a MEM_EXPR, or a space. */
1191 if (peek_char () != ' ')
1193 file_location loc = get_current_location ();
1194 char *desc = read_until (" +", false);
1195 add_fixup_expr (loc, consolidate_singletons (x), desc);
1196 free (desc);
1198 else
1199 read_char ();
1201 /* We may optionally have '+' for MEM_OFFSET_KNOWN_P. */
1202 ch = read_skip_spaces ();
1203 if (ch == '+')
1205 read_name (&name);
1206 set_mem_offset (x, atoi (name.string));
1208 else
1209 unread_char (ch);
1211 /* Handle optional " S" for MEM_SIZE. */
1212 ch = read_skip_spaces ();
1213 if (ch == 'S')
1215 read_name (&name);
1216 set_mem_size (x, atoi (name.string));
1218 else
1219 unread_char (ch);
1221 /* Handle optional " A" for MEM_ALIGN. */
1222 ch = read_skip_spaces ();
1223 if (ch == 'A' && peek_char () != 'S')
1225 read_name (&name);
1226 set_mem_align (x, atoi (name.string));
1228 else
1229 unread_char (ch);
1231 /* Handle optional " AS" for MEM_ADDR_SPACE. */
1232 ch = read_skip_spaces ();
1233 if (ch == 'A' && peek_char () == 'S')
1235 read_char ();
1236 read_name (&name);
1237 set_mem_addr_space (x, atoi (name.string));
1239 else
1240 unread_char (ch);
1242 require_char (']');
1244 break;
1246 case CODE_LABEL:
1247 /* Assume that LABEL_NUSES was not dumped. */
1248 /* TODO: parse LABEL_KIND. */
1249 /* For now, skip until closing ')'. */
1252 char ch = read_char ();
1253 if (ch == ')')
1255 unread_char (ch);
1256 break;
1259 while (1);
1260 break;
1262 default:
1263 break;
1267 /* Parse a tree dump for a MEM_EXPR in DESC and turn it back into a tree.
1268 We handle "<retval>" and param names within cfun, but for anything else
1269 we "cheat" by building a global VAR_DECL of type "int" with that name
1270 (returning the same global for a name if we see the same name more
1271 than once). */
1273 tree
1274 function_reader::parse_mem_expr (const char *desc)
1276 tree fndecl = cfun->decl;
1278 if (0 == strcmp (desc, "<retval>"))
1279 return DECL_RESULT (fndecl);
1281 tree param = find_param_by_name (fndecl, desc);
1282 if (param)
1283 return param;
1285 /* Search within decls we already created.
1286 FIXME: use a hash rather than linear search. */
1287 int i;
1288 tree t;
1289 FOR_EACH_VEC_ELT (m_fake_scope, i, t)
1290 if (strcmp (desc, IDENTIFIER_POINTER (DECL_NAME (t))) == 0)
1291 return t;
1293 /* Not found? Create it.
1294 This allows mimicking of real data but avoids having to specify
1295 e.g. names of locals, params etc.
1296 Though this way we don't know if we have a PARM_DECL vs a VAR_DECL,
1297 and we don't know the types. Fake it by making everything be
1298 a VAR_DECL of "int" type. */
1299 t = build_decl (UNKNOWN_LOCATION, VAR_DECL,
1300 get_identifier (desc),
1301 integer_type_node);
1302 m_fake_scope.safe_push (t);
1303 return t;
1306 /* Record that at LOC we saw an insn uid INSN_UID for the operand with index
1307 OPERAND_IDX within INSN, so that the pointer value can be fixed up in
1308 later post-processing. */
1310 void
1311 function_reader::add_fixup_insn_uid (file_location loc, rtx insn, int operand_idx,
1312 int insn_uid)
1314 m_fixups.safe_push (new fixup_insn_uid (loc, insn, operand_idx, insn_uid));
1317 /* Record that at LOC we saw an basic block index BB_IDX for the operand with index
1318 OPERAND_IDX within INSN, so that the pointer value can be fixed up in
1319 later post-processing. */
1321 void
1322 function_reader::add_fixup_note_insn_basic_block (file_location loc, rtx insn,
1323 int operand_idx, int bb_idx)
1325 m_fixups.safe_push (new fixup_note_insn_basic_block (loc, insn, operand_idx,
1326 bb_idx));
1329 /* Placeholder hook for recording source location information seen in a dump.
1330 This is empty for now. */
1332 void
1333 function_reader::add_fixup_source_location (file_location, rtx_insn *,
1334 const char *, int)
1338 /* Record that at LOC we saw textual description DESC of the MEM_EXPR or REG_EXPR
1339 of INSN, so that the fields can be fixed up in later post-processing. */
1341 void
1342 function_reader::add_fixup_expr (file_location loc, rtx insn,
1343 const char *desc)
1345 gcc_assert (desc);
1346 /* Fail early if the RTL reader erroneously hands us an int. */
1347 gcc_assert (!ISDIGIT (desc[0]));
1349 m_fixups.safe_push (new fixup_expr (loc, insn, desc));
1352 /* Helper function for consolidate_reg. Return the global rtx for
1353 the register with regno REGNO. */
1355 static rtx
1356 lookup_global_register (int regno)
1358 /* We can't use a switch here, as some of the REGNUMs might not be constants
1359 for some targets. */
1360 if (regno == STACK_POINTER_REGNUM)
1361 return stack_pointer_rtx;
1362 else if (regno == FRAME_POINTER_REGNUM)
1363 return frame_pointer_rtx;
1364 else if (regno == HARD_FRAME_POINTER_REGNUM)
1365 return hard_frame_pointer_rtx;
1366 else if (regno == ARG_POINTER_REGNUM)
1367 return arg_pointer_rtx;
1368 else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
1369 return virtual_incoming_args_rtx;
1370 else if (regno == VIRTUAL_STACK_VARS_REGNUM)
1371 return virtual_stack_vars_rtx;
1372 else if (regno == VIRTUAL_STACK_DYNAMIC_REGNUM)
1373 return virtual_stack_dynamic_rtx;
1374 else if (regno == VIRTUAL_OUTGOING_ARGS_REGNUM)
1375 return virtual_outgoing_args_rtx;
1376 else if (regno == VIRTUAL_CFA_REGNUM)
1377 return virtual_cfa_rtx;
1378 else if (regno == VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM)
1379 return virtual_preferred_stack_boundary_rtx;
1380 #ifdef return_ADDRESS_POINTER_REGNUM
1381 else if (regno == RETURN_ADDRESS_POINTER_REGNUM)
1382 return return_address_pointer_rtx;
1383 #endif
1385 return NULL;
1388 /* Ensure that the backend can cope with a REG with regno REGNO.
1389 Normally REG instances are created by gen_reg_rtx which updates
1390 regno_reg_rtx, growing it as necessary.
1391 The REG instances created from the dumpfile weren't created this
1392 way, so we need to manually update regno_reg_rtx. */
1394 static void
1395 ensure_regno (int regno)
1397 if (reg_rtx_no < regno + 1)
1398 reg_rtx_no = regno + 1;
1400 crtl->emit.ensure_regno_capacity ();
1401 gcc_assert (regno < crtl->emit.regno_pointer_align_length);
1404 /* Helper function for consolidate_singletons, for handling REG instances.
1405 Given REG instance X of some regno, return the singleton rtx for that
1406 regno, if it exists, or X. */
1408 static rtx
1409 consolidate_reg (rtx x)
1411 gcc_assert (GET_CODE (x) == REG);
1413 unsigned int regno = REGNO (x);
1415 ensure_regno (regno);
1417 /* Some register numbers have their rtx created in init_emit_regs
1418 e.g. stack_pointer_rtx for STACK_POINTER_REGNUM.
1419 Consolidate on this. */
1420 rtx global_reg = lookup_global_register (regno);
1421 if (global_reg)
1422 return global_reg;
1424 /* Populate regno_reg_rtx if necessary. */
1425 if (regno_reg_rtx[regno] == NULL)
1426 regno_reg_rtx[regno] = x;
1427 /* Use it. */
1428 gcc_assert (GET_CODE (regno_reg_rtx[regno]) == REG);
1429 gcc_assert (REGNO (regno_reg_rtx[regno]) == regno);
1430 if (GET_MODE (x) == GET_MODE (regno_reg_rtx[regno]))
1431 return regno_reg_rtx[regno];
1433 return x;
1436 /* When reading RTL function dumps, we must consolidate some
1437 rtx so that we use singletons where singletons are expected
1438 (e.g. we don't want multiple "(const_int 0 [0])" rtx, since
1439 these are tested via pointer equality against const0_rtx.
1441 Return the equivalent singleton rtx for X, if any, otherwise X. */
1444 function_reader::consolidate_singletons (rtx x)
1446 if (!x)
1447 return x;
1449 switch (GET_CODE (x))
1451 case PC: return pc_rtx;
1452 case RETURN: return ret_rtx;
1453 case SIMPLE_RETURN: return simple_return_rtx;
1454 case CC0: return cc0_rtx;
1456 case REG:
1457 return consolidate_reg (x);
1459 case CONST_INT:
1460 return gen_rtx_CONST_INT (GET_MODE (x), INTVAL (x));
1462 default:
1463 break;
1466 return x;
1469 /* Parse an rtx directive, including both the opening/closing parentheses,
1470 and the name. */
1473 function_reader::parse_rtx ()
1475 require_char_ws ('(');
1476 struct md_name directive;
1477 read_name (&directive);
1478 rtx result
1479 = consolidate_singletons (read_rtx_code (directive.string));
1480 require_char_ws (')');
1482 return result;
1485 /* Implementation of rtx_reader::postprocess for reading function dumps.
1486 Return the equivalent singleton rtx for X, if any, otherwise X. */
1489 function_reader::postprocess (rtx x)
1491 return consolidate_singletons (x);
1494 /* Implementation of rtx_reader::finalize_string for reading function dumps.
1495 Make a GC-managed copy of STRINGBUF. */
1497 const char *
1498 function_reader::finalize_string (char *stringbuf)
1500 return ggc_strdup (stringbuf);
1503 /* Attempt to parse optional location information for insn INSN, as
1504 potentially written out by rtx_writer::print_rtx_operand_code_i.
1505 We look for a quoted string followed by a colon. */
1507 void
1508 function_reader::maybe_read_location (rtx_insn *insn)
1510 file_location loc = get_current_location ();
1512 /* Attempt to parse a quoted string. */
1513 int ch = read_skip_spaces ();
1514 if (ch == '"')
1516 char *filename = read_quoted_string ();
1517 require_char (':');
1518 struct md_name line_num;
1519 read_name (&line_num);
1520 add_fixup_source_location (loc, insn, filename, atoi (line_num.string));
1522 else
1523 unread_char (ch);
1526 /* Postprocessing subroutine of function_reader::parse_function.
1527 Populate m_insns_by_uid. */
1529 void
1530 function_reader::handle_insn_uids ()
1532 /* Locate the currently assigned INSN_UID values, storing
1533 them in m_insns_by_uid. */
1534 int max_uid = 0;
1535 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
1537 if (m_insns_by_uid.get (INSN_UID (insn)))
1538 error ("duplicate insn UID: %i", INSN_UID (insn));
1539 m_insns_by_uid.put (INSN_UID (insn), insn);
1540 if (INSN_UID (insn) > max_uid)
1541 max_uid = INSN_UID (insn);
1544 /* Ensure x_cur_insn_uid is 1 more than the biggest insn UID seen.
1545 This is normally updated by the various make_*insn_raw functions. */
1546 crtl->emit.x_cur_insn_uid = max_uid + 1;
1549 /* Apply all of the recorded fixups. */
1551 void
1552 function_reader::apply_fixups ()
1554 int i;
1555 fixup *f;
1556 FOR_EACH_VEC_ELT (m_fixups, i, f)
1557 f->apply (this);
1560 /* Given a UID value, try to locate a pointer to the corresponding
1561 rtx_insn *, or NULL if if can't be found. */
1563 rtx_insn **
1564 function_reader::get_insn_by_uid (int uid)
1566 return m_insns_by_uid.get (uid);
1569 /* Run the RTL dump parser, parsing a dump located at PATH.
1570 Return true iff the file was successfully parsed. */
1572 bool
1573 read_rtl_function_body (const char *path)
1575 initialize_rtl ();
1576 init_emit ();
1577 init_varasm_status ();
1579 function_reader reader;
1580 if (!reader.read_file (path))
1581 return false;
1583 return true;
1586 #if CHECKING_P
1588 namespace selftest {
1590 /* Verify that parse_edge_flags works. */
1592 static void
1593 test_edge_flags ()
1595 /* parse_edge_flags modifies its input (due to strtok), so we must make
1596 a copy of the literals. */
1597 #define ASSERT_PARSE_EDGE_FLAGS(EXPECTED, STR) \
1598 do { \
1599 char *str = xstrdup (STR); \
1600 ASSERT_EQ (EXPECTED, parse_edge_flags (str)); \
1601 free (str); \
1602 } while (0)
1604 ASSERT_PARSE_EDGE_FLAGS (0, "");
1605 ASSERT_PARSE_EDGE_FLAGS (EDGE_FALLTHRU, "FALLTHRU");
1606 ASSERT_PARSE_EDGE_FLAGS (EDGE_ABNORMAL_CALL, "ABNORMAL_CALL");
1607 ASSERT_PARSE_EDGE_FLAGS (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL,
1608 "ABNORMAL | ABNORMAL_CALL");
1610 #undef ASSERT_PARSE_EDGE_FLAGS
1613 /* Verify that lookup_reg_by_dump_name works. */
1615 static void
1616 test_parsing_regnos ()
1618 ASSERT_EQ (-1, lookup_reg_by_dump_name ("this is not a register"));
1620 /* Verify lookup of virtual registers. */
1621 ASSERT_EQ (VIRTUAL_INCOMING_ARGS_REGNUM,
1622 lookup_reg_by_dump_name ("virtual-incoming-args"));
1623 ASSERT_EQ (VIRTUAL_STACK_VARS_REGNUM,
1624 lookup_reg_by_dump_name ("virtual-stack-vars"));
1625 ASSERT_EQ (VIRTUAL_STACK_DYNAMIC_REGNUM,
1626 lookup_reg_by_dump_name ("virtual-stack-dynamic"));
1627 ASSERT_EQ (VIRTUAL_OUTGOING_ARGS_REGNUM,
1628 lookup_reg_by_dump_name ("virtual-outgoing-args"));
1629 ASSERT_EQ (VIRTUAL_CFA_REGNUM,
1630 lookup_reg_by_dump_name ("virtual-cfa"));
1631 ASSERT_EQ (VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM,
1632 lookup_reg_by_dump_name ("virtual-preferred-stack-boundary"));
1634 /* Verify lookup of non-virtual pseudos. */
1635 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 1, lookup_reg_by_dump_name ("<0>"));
1636 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 2, lookup_reg_by_dump_name ("<1>"));
1639 /* Verify that edge E is as expected, with the src and dest basic blocks
1640 having indices EXPECTED_SRC_IDX and EXPECTED_DEST_IDX respectively, and
1641 the edge having flags equal to EXPECTED_FLAGS.
1642 Use LOC as the effective location when reporting failures. */
1644 static void
1645 assert_edge_at (const location &loc, edge e, int expected_src_idx,
1646 int expected_dest_idx, int expected_flags)
1648 ASSERT_EQ_AT (loc, expected_src_idx, e->src->index);
1649 ASSERT_EQ_AT (loc, expected_dest_idx, e->dest->index);
1650 ASSERT_EQ_AT (loc, expected_flags, e->flags);
1653 /* Verify that edge EDGE is as expected, with the src and dest basic blocks
1654 having indices EXPECTED_SRC_IDX and EXPECTED_DEST_IDX respectively, and
1655 the edge having flags equal to EXPECTED_FLAGS. */
1657 #define ASSERT_EDGE(EDGE, EXPECTED_SRC_IDX, EXPECTED_DEST_IDX, \
1658 EXPECTED_FLAGS) \
1659 assert_edge_at (SELFTEST_LOCATION, EDGE, EXPECTED_SRC_IDX, \
1660 EXPECTED_DEST_IDX, EXPECTED_FLAGS)
1662 /* Verify that we can load RTL dumps. */
1664 static void
1665 test_loading_dump_fragment_1 ()
1667 // TODO: filter on target?
1668 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("asr_div1.rtl"));
1670 /* Verify that the insns were loaded correctly. */
1671 rtx_insn *insn_1 = get_insns ();
1672 ASSERT_TRUE (insn_1);
1673 ASSERT_EQ (1, INSN_UID (insn_1));
1674 ASSERT_EQ (INSN, GET_CODE (insn_1));
1675 ASSERT_EQ (SET, GET_CODE (PATTERN (insn_1)));
1676 ASSERT_EQ (NULL, PREV_INSN (insn_1));
1678 rtx_insn *insn_2 = NEXT_INSN (insn_1);
1679 ASSERT_TRUE (insn_2);
1680 ASSERT_EQ (2, INSN_UID (insn_2));
1681 ASSERT_EQ (INSN, GET_CODE (insn_2));
1682 ASSERT_EQ (insn_1, PREV_INSN (insn_2));
1683 ASSERT_EQ (NULL, NEXT_INSN (insn_2));
1685 /* Verify that registers were loaded correctly. */
1686 rtx insn_1_dest = SET_DEST (PATTERN (insn_1));
1687 ASSERT_EQ (REG, GET_CODE (insn_1_dest));
1688 ASSERT_EQ ((LAST_VIRTUAL_REGISTER + 1) + 2, REGNO (insn_1_dest));
1689 rtx insn_1_src = SET_SRC (PATTERN (insn_1));
1690 ASSERT_EQ (LSHIFTRT, GET_CODE (insn_1_src));
1691 rtx reg = XEXP (insn_1_src, 0);
1692 ASSERT_EQ (REG, GET_CODE (reg));
1693 ASSERT_EQ (LAST_VIRTUAL_REGISTER + 1, REGNO (reg));
1695 /* Verify that get_insn_by_uid works. */
1696 ASSERT_EQ (insn_1, get_insn_by_uid (1));
1697 ASSERT_EQ (insn_2, get_insn_by_uid (2));
1699 /* Verify that basic blocks were created. */
1700 ASSERT_EQ (2, BLOCK_FOR_INSN (insn_1)->index);
1701 ASSERT_EQ (2, BLOCK_FOR_INSN (insn_2)->index);
1703 /* Verify that the CFG was recreated. */
1704 ASSERT_TRUE (cfun);
1705 verify_three_block_rtl_cfg (cfun);
1706 basic_block bb2 = BASIC_BLOCK_FOR_FN (cfun, 2);
1707 ASSERT_TRUE (bb2 != NULL);
1708 ASSERT_EQ (BB_RTL, bb2->flags & BB_RTL);
1709 ASSERT_EQ (2, bb2->index);
1710 ASSERT_EQ (insn_1, BB_HEAD (bb2));
1711 ASSERT_EQ (insn_2, BB_END (bb2));
1714 /* Verify loading another RTL dump. */
1716 static void
1717 test_loading_dump_fragment_2 ()
1719 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("simple-cse.rtl"));
1721 rtx_insn *insn_1 = get_insn_by_uid (1);
1722 rtx_insn *insn_2 = get_insn_by_uid (2);
1723 rtx_insn *insn_3 = get_insn_by_uid (3);
1725 rtx set1 = single_set (insn_1);
1726 ASSERT_NE (NULL, set1);
1727 rtx set2 = single_set (insn_2);
1728 ASSERT_NE (NULL, set2);
1729 rtx set3 = single_set (insn_3);
1730 ASSERT_NE (NULL, set3);
1732 rtx src1 = SET_SRC (set1);
1733 ASSERT_EQ (PLUS, GET_CODE (src1));
1735 rtx src2 = SET_SRC (set2);
1736 ASSERT_EQ (PLUS, GET_CODE (src2));
1738 /* Both src1 and src2 refer to "(reg:SI %0)".
1739 Verify that we have pointer equality. */
1740 rtx lhs1 = XEXP (src1, 0);
1741 rtx lhs2 = XEXP (src2, 0);
1742 ASSERT_EQ (lhs1, lhs2);
1744 /* Verify that the CFG was recreated. */
1745 ASSERT_TRUE (cfun);
1746 verify_three_block_rtl_cfg (cfun);
1749 /* Verify that CODE_LABEL insns are loaded correctly. */
1751 static void
1752 test_loading_labels ()
1754 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("example-labels.rtl"));
1756 rtx_insn *insn_100 = get_insn_by_uid (100);
1757 ASSERT_EQ (CODE_LABEL, GET_CODE (insn_100));
1758 ASSERT_EQ (100, INSN_UID (insn_100));
1759 ASSERT_EQ (NULL, LABEL_NAME (insn_100));
1760 ASSERT_EQ (0, LABEL_NUSES (insn_100));
1761 ASSERT_EQ (30, CODE_LABEL_NUMBER (insn_100));
1763 rtx_insn *insn_200 = get_insn_by_uid (200);
1764 ASSERT_EQ (CODE_LABEL, GET_CODE (insn_200));
1765 ASSERT_EQ (200, INSN_UID (insn_200));
1766 ASSERT_STREQ ("some_label_name", LABEL_NAME (insn_200));
1767 ASSERT_EQ (0, LABEL_NUSES (insn_200));
1768 ASSERT_EQ (40, CODE_LABEL_NUMBER (insn_200));
1770 /* Ensure that the presence of CODE_LABEL_NUMBER == 40
1771 means that the next label num to be handed out will be 41. */
1772 ASSERT_EQ (41, max_label_num ());
1774 /* Ensure that label names read from a dump are GC-managed
1775 and are found through the insn. */
1776 forcibly_ggc_collect ();
1777 ASSERT_TRUE (ggc_marked_p (insn_200));
1778 ASSERT_TRUE (ggc_marked_p (LABEL_NAME (insn_200)));
1781 /* Verify that the loader copes with an insn with a mode. */
1783 static void
1784 test_loading_insn_with_mode ()
1786 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("insn-with-mode.rtl"));
1787 rtx_insn *insn = get_insns ();
1788 ASSERT_EQ (INSN, GET_CODE (insn));
1790 /* Verify that the "TI" mode was set from "insn:TI". */
1791 ASSERT_EQ (TImode, GET_MODE (insn));
1794 /* Verify that the loader copes with a jump_insn to a label_ref. */
1796 static void
1797 test_loading_jump_to_label_ref ()
1799 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("jump-to-label-ref.rtl"));
1801 rtx_insn *jump_insn = get_insn_by_uid (1);
1802 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
1804 rtx_insn *barrier = get_insn_by_uid (2);
1805 ASSERT_EQ (BARRIER, GET_CODE (barrier));
1807 rtx_insn *code_label = get_insn_by_uid (100);
1808 ASSERT_EQ (CODE_LABEL, GET_CODE (code_label));
1810 /* Verify the jump_insn. */
1811 ASSERT_EQ (4, BLOCK_FOR_INSN (jump_insn)->index);
1812 ASSERT_EQ (SET, GET_CODE (PATTERN (jump_insn)));
1813 /* Ensure that the "(pc)" is using the global singleton. */
1814 ASSERT_RTX_PTR_EQ (pc_rtx, SET_DEST (PATTERN (jump_insn)));
1815 rtx label_ref = SET_SRC (PATTERN (jump_insn));
1816 ASSERT_EQ (LABEL_REF, GET_CODE (label_ref));
1817 ASSERT_EQ (code_label, label_ref_label (label_ref));
1818 ASSERT_EQ (code_label, JUMP_LABEL (jump_insn));
1820 /* Verify the code_label. */
1821 ASSERT_EQ (5, BLOCK_FOR_INSN (code_label)->index);
1822 ASSERT_EQ (NULL, LABEL_NAME (code_label));
1823 ASSERT_EQ (1, LABEL_NUSES (code_label));
1825 /* Verify the generated CFG. */
1827 /* Locate blocks. */
1828 basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
1829 ASSERT_TRUE (entry != NULL);
1830 ASSERT_EQ (ENTRY_BLOCK, entry->index);
1832 basic_block exit = EXIT_BLOCK_PTR_FOR_FN (cfun);
1833 ASSERT_TRUE (exit != NULL);
1834 ASSERT_EQ (EXIT_BLOCK, exit->index);
1836 basic_block bb4 = (*cfun->cfg->x_basic_block_info)[4];
1837 basic_block bb5 = (*cfun->cfg->x_basic_block_info)[5];
1838 ASSERT_EQ (4, bb4->index);
1839 ASSERT_EQ (5, bb5->index);
1841 /* Entry block. */
1842 ASSERT_EQ (NULL, entry->preds);
1843 ASSERT_EQ (1, entry->succs->length ());
1844 ASSERT_EDGE ((*entry->succs)[0], 0, 4, EDGE_FALLTHRU);
1846 /* bb4. */
1847 ASSERT_EQ (1, bb4->preds->length ());
1848 ASSERT_EDGE ((*bb4->preds)[0], 0, 4, EDGE_FALLTHRU);
1849 ASSERT_EQ (1, bb4->succs->length ());
1850 ASSERT_EDGE ((*bb4->succs)[0], 4, 5, 0x0);
1852 /* bb5. */
1853 ASSERT_EQ (1, bb5->preds->length ());
1854 ASSERT_EDGE ((*bb5->preds)[0], 4, 5, 0x0);
1855 ASSERT_EQ (1, bb5->succs->length ());
1856 ASSERT_EDGE ((*bb5->succs)[0], 5, 1, EDGE_FALLTHRU);
1858 /* Exit block. */
1859 ASSERT_EQ (1, exit->preds->length ());
1860 ASSERT_EDGE ((*exit->preds)[0], 5, 1, EDGE_FALLTHRU);
1861 ASSERT_EQ (NULL, exit->succs);
1864 /* Verify that the loader copes with a jump_insn to a label_ref
1865 marked "return". */
1867 static void
1868 test_loading_jump_to_return ()
1870 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("jump-to-return.rtl"));
1872 rtx_insn *jump_insn = get_insn_by_uid (1);
1873 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
1874 ASSERT_RTX_PTR_EQ (ret_rtx, JUMP_LABEL (jump_insn));
1877 /* Verify that the loader copes with a jump_insn to a label_ref
1878 marked "simple_return". */
1880 static void
1881 test_loading_jump_to_simple_return ()
1883 rtl_dump_test t (SELFTEST_LOCATION,
1884 locate_file ("jump-to-simple-return.rtl"));
1886 rtx_insn *jump_insn = get_insn_by_uid (1);
1887 ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
1888 ASSERT_RTX_PTR_EQ (simple_return_rtx, JUMP_LABEL (jump_insn));
1891 /* Verify that the loader copes with a NOTE_INSN_BASIC_BLOCK. */
1893 static void
1894 test_loading_note_insn_basic_block ()
1896 rtl_dump_test t (SELFTEST_LOCATION,
1897 locate_file ("note_insn_basic_block.rtl"));
1899 rtx_insn *note = get_insn_by_uid (1);
1900 ASSERT_EQ (NOTE, GET_CODE (note));
1901 ASSERT_EQ (2, BLOCK_FOR_INSN (note)->index);
1903 ASSERT_EQ (NOTE_INSN_BASIC_BLOCK, NOTE_KIND (note));
1904 ASSERT_EQ (2, NOTE_BASIC_BLOCK (note)->index);
1905 ASSERT_EQ (BASIC_BLOCK_FOR_FN (cfun, 2), NOTE_BASIC_BLOCK (note));
1908 /* Verify that the loader copes with a NOTE_INSN_DELETED. */
1910 static void
1911 test_loading_note_insn_deleted ()
1913 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("note-insn-deleted.rtl"));
1915 rtx_insn *note = get_insn_by_uid (1);
1916 ASSERT_EQ (NOTE, GET_CODE (note));
1917 ASSERT_EQ (NOTE_INSN_DELETED, NOTE_KIND (note));
1920 /* Verify that the const_int values are consolidated, since
1921 pointer equality corresponds to value equality.
1922 TODO: do this for all in CASE_CONST_UNIQUE. */
1924 static void
1925 test_loading_const_int ()
1927 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("const-int.rtl"));
1929 /* Verify that const_int values below MAX_SAVED_CONST_INT use
1930 the global values. */
1931 ASSERT_EQ (const0_rtx, SET_SRC (PATTERN (get_insn_by_uid (1))));
1932 ASSERT_EQ (const1_rtx, SET_SRC (PATTERN (get_insn_by_uid (2))));
1933 ASSERT_EQ (constm1_rtx, SET_SRC (PATTERN (get_insn_by_uid (3))));
1935 /* Verify that other const_int values are consolidated. */
1936 rtx int256 = gen_rtx_CONST_INT (SImode, 256);
1937 ASSERT_EQ (int256, SET_SRC (PATTERN (get_insn_by_uid (4))));
1940 /* Verify that the loader copes with a SYMBOL_REF. */
1942 static void
1943 test_loading_symbol_ref ()
1945 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("symbol-ref.rtl"));
1947 rtx_insn *insn = get_insns ();
1949 rtx high = SET_SRC (PATTERN (insn));
1950 ASSERT_EQ (HIGH, GET_CODE (high));
1952 rtx symbol_ref = XEXP (high, 0);
1953 ASSERT_EQ (SYMBOL_REF, GET_CODE (symbol_ref));
1955 /* Verify that "[flags 0xc0]" was parsed. */
1956 ASSERT_EQ (0xc0, SYMBOL_REF_FLAGS (symbol_ref));
1957 /* TODO: we don't yet load SYMBOL_REF_DECL. */
1960 /* Verify that the loader can rebuild a CFG. */
1962 static void
1963 test_loading_cfg ()
1965 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("cfg-test.rtl"));
1967 ASSERT_STREQ ("cfg_test", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
1969 ASSERT_TRUE (cfun);
1971 ASSERT_TRUE (cfun->cfg != NULL);
1972 ASSERT_EQ (6, n_basic_blocks_for_fn (cfun));
1973 ASSERT_EQ (6, n_edges_for_fn (cfun));
1975 /* The "fake" basic blocks. */
1976 basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
1977 ASSERT_TRUE (entry != NULL);
1978 ASSERT_EQ (ENTRY_BLOCK, entry->index);
1980 basic_block exit = EXIT_BLOCK_PTR_FOR_FN (cfun);
1981 ASSERT_TRUE (exit != NULL);
1982 ASSERT_EQ (EXIT_BLOCK, exit->index);
1984 /* The "real" basic blocks. */
1985 basic_block bb2 = (*cfun->cfg->x_basic_block_info)[2];
1986 basic_block bb3 = (*cfun->cfg->x_basic_block_info)[3];
1987 basic_block bb4 = (*cfun->cfg->x_basic_block_info)[4];
1988 basic_block bb5 = (*cfun->cfg->x_basic_block_info)[5];
1990 ASSERT_EQ (2, bb2->index);
1991 ASSERT_EQ (3, bb3->index);
1992 ASSERT_EQ (4, bb4->index);
1993 ASSERT_EQ (5, bb5->index);
1995 /* Verify connectivity. */
1997 /* Entry block. */
1998 ASSERT_EQ (NULL, entry->preds);
1999 ASSERT_EQ (1, entry->succs->length ());
2000 ASSERT_EDGE ((*entry->succs)[0], 0, 2, EDGE_FALLTHRU);
2002 /* bb2. */
2003 ASSERT_EQ (1, bb2->preds->length ());
2004 ASSERT_EDGE ((*bb2->preds)[0], 0, 2, EDGE_FALLTHRU);
2005 ASSERT_EQ (2, bb2->succs->length ());
2006 ASSERT_EDGE ((*bb2->succs)[0], 2, 3, EDGE_TRUE_VALUE);
2007 ASSERT_EDGE ((*bb2->succs)[1], 2, 4, EDGE_FALSE_VALUE);
2009 /* bb3. */
2010 ASSERT_EQ (1, bb3->preds->length ());
2011 ASSERT_EDGE ((*bb3->preds)[0], 2, 3, EDGE_TRUE_VALUE);
2012 ASSERT_EQ (1, bb3->succs->length ());
2013 ASSERT_EDGE ((*bb3->succs)[0], 3, 5, EDGE_FALLTHRU);
2015 /* bb4. */
2016 ASSERT_EQ (1, bb4->preds->length ());
2017 ASSERT_EDGE ((*bb4->preds)[0], 2, 4, EDGE_FALSE_VALUE);
2018 ASSERT_EQ (1, bb4->succs->length ());
2019 ASSERT_EDGE ((*bb4->succs)[0], 4, 5, EDGE_FALLTHRU);
2021 /* bb5. */
2022 ASSERT_EQ (2, bb5->preds->length ());
2023 ASSERT_EDGE ((*bb5->preds)[0], 3, 5, EDGE_FALLTHRU);
2024 ASSERT_EDGE ((*bb5->preds)[1], 4, 5, EDGE_FALLTHRU);
2025 ASSERT_EQ (1, bb5->succs->length ());
2026 ASSERT_EDGE ((*bb5->succs)[0], 5, 1, EDGE_FALLTHRU);
2028 /* Exit block. */
2029 ASSERT_EQ (1, exit->preds->length ());
2030 ASSERT_EDGE ((*exit->preds)[0], 5, 1, EDGE_FALLTHRU);
2031 ASSERT_EQ (NULL, exit->succs);
2034 /* Verify that the loader copes with sparse block indices.
2035 This testcase loads a file with a "(block 42)". */
2037 static void
2038 test_loading_bb_index ()
2040 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("bb-index.rtl"));
2042 ASSERT_STREQ ("test_bb_index", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
2044 ASSERT_TRUE (cfun);
2046 ASSERT_TRUE (cfun->cfg != NULL);
2047 ASSERT_EQ (3, n_basic_blocks_for_fn (cfun));
2048 ASSERT_EQ (43, basic_block_info_for_fn (cfun)->length ());
2049 ASSERT_EQ (2, n_edges_for_fn (cfun));
2051 ASSERT_EQ (NULL, (*cfun->cfg->x_basic_block_info)[41]);
2052 basic_block bb42 = (*cfun->cfg->x_basic_block_info)[42];
2053 ASSERT_NE (NULL, bb42);
2054 ASSERT_EQ (42, bb42->index);
2057 /* Verify that function_reader::handle_any_trailing_information correctly
2058 parses all the possible items emitted for a MEM. */
2060 static void
2061 test_loading_mem ()
2063 rtl_dump_test t (SELFTEST_LOCATION, locate_file ("mem.rtl"));
2065 ASSERT_STREQ ("test_mem", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
2066 ASSERT_TRUE (cfun);
2068 /* Verify parsing of "[42 i+17 S8 A128 AS5]". */
2069 rtx_insn *insn_1 = get_insn_by_uid (1);
2070 rtx set1 = single_set (insn_1);
2071 rtx mem1 = SET_DEST (set1);
2072 ASSERT_EQ (42, MEM_ALIAS_SET (mem1));
2073 /* "+17". */
2074 ASSERT_TRUE (MEM_OFFSET_KNOWN_P (mem1));
2075 ASSERT_EQ (17, MEM_OFFSET (mem1));
2076 /* "S8". */
2077 ASSERT_EQ (8, MEM_SIZE (mem1));
2078 /* "A128. */
2079 ASSERT_EQ (128, MEM_ALIGN (mem1));
2080 /* "AS5. */
2081 ASSERT_EQ (5, MEM_ADDR_SPACE (mem1));
2083 /* Verify parsing of "43 i+18 S9 AS6"
2084 (an address space without an alignment). */
2085 rtx_insn *insn_2 = get_insn_by_uid (2);
2086 rtx set2 = single_set (insn_2);
2087 rtx mem2 = SET_DEST (set2);
2088 ASSERT_EQ (43, MEM_ALIAS_SET (mem2));
2089 /* "+18". */
2090 ASSERT_TRUE (MEM_OFFSET_KNOWN_P (mem2));
2091 ASSERT_EQ (18, MEM_OFFSET (mem2));
2092 /* "S9". */
2093 ASSERT_EQ (9, MEM_SIZE (mem2));
2094 /* "AS6. */
2095 ASSERT_EQ (6, MEM_ADDR_SPACE (mem2));
2098 /* Run all of the selftests within this file. */
2100 void
2101 read_rtl_function_c_tests ()
2103 test_edge_flags ();
2104 test_parsing_regnos ();
2105 test_loading_dump_fragment_1 ();
2106 test_loading_dump_fragment_2 ();
2107 test_loading_labels ();
2108 test_loading_insn_with_mode ();
2109 test_loading_jump_to_label_ref ();
2110 test_loading_jump_to_return ();
2111 test_loading_jump_to_simple_return ();
2112 test_loading_note_insn_basic_block ();
2113 test_loading_note_insn_deleted ();
2114 test_loading_const_int ();
2115 test_loading_symbol_ref ();
2116 test_loading_cfg ();
2117 test_loading_bb_index ();
2118 test_loading_mem ();
2121 } // namespace selftest
2123 #endif /* #if CHECKING_P */