print-rtl.h 5.4 KB

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