dumpfile.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* Definitions for the shared dumpfile.
  2. Copyright (C) 2004-2018 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License 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_DUMPFILE_H
  16. #define GCC_DUMPFILE_H 1
  17. /* Different tree dump places. When you add new tree dump places,
  18. extend the DUMP_FILES array in dumpfile.c. */
  19. enum tree_dump_index
  20. {
  21. TDI_none, /* No dump */
  22. TDI_cgraph, /* dump function call graph. */
  23. TDI_inheritance, /* dump type inheritance graph. */
  24. TDI_clones, /* dump IPA cloning decisions. */
  25. TDI_original, /* dump each function before optimizing it */
  26. TDI_gimple, /* dump each function after gimplifying it */
  27. TDI_nested, /* dump each function after unnesting it */
  28. TDI_lang_all, /* enable all the language dumps. */
  29. TDI_tree_all, /* enable all the GENERIC/GIMPLE dumps. */
  30. TDI_rtl_all, /* enable all the RTL dumps. */
  31. TDI_ipa_all, /* enable all the IPA dumps. */
  32. TDI_end
  33. };
  34. /* Enum used to distinguish dump files to types. */
  35. enum dump_kind
  36. {
  37. DK_none,
  38. DK_lang,
  39. DK_tree,
  40. DK_rtl,
  41. DK_ipa
  42. };
  43. /* Bit masks to control dumping. Not all values are applicable to all
  44. dumps. Add new ones at the end. When you define new values, extend
  45. the DUMP_OPTIONS array in dumpfile.c. The TDF_* flags coexist with
  46. MSG_* flags (for -fopt-info) and the bit values must be chosen to
  47. allow that. */
  48. #define TDF_ADDRESS (1 << 0) /* dump node addresses */
  49. #define TDF_SLIM (1 << 1) /* don't go wild following links */
  50. #define TDF_RAW (1 << 2) /* don't unparse the function */
  51. #define TDF_DETAILS (1 << 3) /* show more detailed info about
  52. each pass */
  53. #define TDF_STATS (1 << 4) /* dump various statistics about
  54. each pass */
  55. #define TDF_BLOCKS (1 << 5) /* display basic block boundaries */
  56. #define TDF_VOPS (1 << 6) /* display virtual operands */
  57. #define TDF_LINENO (1 << 7) /* display statement line numbers */
  58. #define TDF_UID (1 << 8) /* display decl UIDs */
  59. #define TDF_STMTADDR (1 << 9) /* Address of stmt. */
  60. #define TDF_GRAPH (1 << 10) /* a graph dump is being emitted */
  61. #define TDF_MEMSYMS (1 << 11) /* display memory symbols in expr.
  62. Implies TDF_VOPS. */
  63. #define TDF_RHS_ONLY (1 << 12) /* a flag to only print the RHS of
  64. a gimple stmt. */
  65. #define TDF_ASMNAME (1 << 13) /* display asm names of decls */
  66. #define TDF_EH (1 << 14) /* display EH region number
  67. holding this gimple statement. */
  68. #define TDF_NOUID (1 << 15) /* omit UIDs from dumps. */
  69. #define TDF_ALIAS (1 << 16) /* display alias information */
  70. #define TDF_ENUMERATE_LOCALS (1 << 17) /* Enumerate locals by uid. */
  71. #define TDF_CSELIB (1 << 18) /* Dump cselib details. */
  72. #define TDF_SCEV (1 << 19) /* Dump SCEV details. */
  73. #define TDF_GIMPLE (1 << 20) /* Dump in GIMPLE FE syntax */
  74. #define TDF_FOLDING (1 << 21) /* Dump folding details. */
  75. #define MSG_OPTIMIZED_LOCATIONS (1 << 22) /* -fopt-info optimized sources */
  76. #define MSG_MISSED_OPTIMIZATION (1 << 23) /* missed opportunities */
  77. #define MSG_NOTE (1 << 24) /* general optimization info */
  78. #define MSG_ALL (MSG_OPTIMIZED_LOCATIONS | MSG_MISSED_OPTIMIZATION \
  79. | MSG_NOTE)
  80. #define TDF_COMPARE_DEBUG (1 << 25) /* Dumping for -fcompare-debug. */
  81. /* Value of TDF_NONE is used just for bits filtered by TDF_KIND_MASK. */
  82. #define TDF_NONE 0
  83. /* Flags to control high-level -fopt-info dumps. Usually these flags
  84. define a group of passes. An optimization pass can be part of
  85. multiple groups. */
  86. #define OPTGROUP_NONE (0)
  87. #define OPTGROUP_IPA (1 << 1) /* IPA optimization passes */
  88. #define OPTGROUP_LOOP (1 << 2) /* Loop optimization passes */
  89. #define OPTGROUP_INLINE (1 << 3) /* Inlining passes */
  90. #define OPTGROUP_OMP (1 << 4) /* OMP (Offloading and Multi
  91. Processing) transformations */
  92. #define OPTGROUP_VEC (1 << 5) /* Vectorization passes */
  93. #define OPTGROUP_OTHER (1 << 6) /* All other passes */
  94. #define OPTGROUP_ALL (OPTGROUP_IPA | OPTGROUP_LOOP | OPTGROUP_INLINE \
  95. | OPTGROUP_OMP | OPTGROUP_VEC | OPTGROUP_OTHER)
  96. /* Dump flags type. */
  97. typedef uint64_t dump_flags_t;
  98. /* Define a tree dump switch. */
  99. struct dump_file_info
  100. {
  101. /* Suffix to give output file. */
  102. const char *suffix;
  103. /* Command line dump switch. */
  104. const char *swtch;
  105. /* Command line glob. */
  106. const char *glob;
  107. /* Filename for the pass-specific stream. */
  108. const char *pfilename;
  109. /* Filename for the -fopt-info stream. */
  110. const char *alt_filename;
  111. /* Pass-specific dump stream. */
  112. FILE *pstream;
  113. /* -fopt-info stream. */
  114. FILE *alt_stream;
  115. /* Dump kind. */
  116. dump_kind dkind;
  117. /* Dump flags. */
  118. dump_flags_t pflags;
  119. /* A pass flags for -fopt-info. */
  120. int alt_flags;
  121. /* Flags for -fopt-info given by a user. */
  122. int optgroup_flags;
  123. /* State of pass-specific stream. */
  124. int pstate;
  125. /* State of the -fopt-info stream. */
  126. int alt_state;
  127. /* Dump file number. */
  128. int num;
  129. /* Fields "suffix", "swtch", "glob" can be const strings,
  130. or can be dynamically allocated, needing free. */
  131. bool owns_strings;
  132. /* When a given dump file is being initialized, this flag is set to true
  133. if the corresponding TDF_graph dump file has also been initialized. */
  134. bool graph_dump_initialized;
  135. };
  136. /* In dumpfile.c */
  137. extern FILE *dump_begin (int, dump_flags_t *);
  138. extern void dump_end (int, FILE *);
  139. extern int opt_info_switch_p (const char *);
  140. extern const char *dump_flag_name (int);
  141. extern void dump_printf (dump_flags_t, const char *, ...) ATTRIBUTE_PRINTF_2;
  142. extern void dump_printf_loc (dump_flags_t, source_location,
  143. const char *, ...) ATTRIBUTE_PRINTF_3;
  144. extern void dump_function (int phase, tree fn);
  145. extern void dump_basic_block (int, basic_block, int);
  146. extern void dump_generic_expr_loc (int, source_location, int, tree);
  147. extern void dump_generic_expr (dump_flags_t, dump_flags_t, tree);
  148. extern void dump_gimple_stmt_loc (dump_flags_t, source_location, dump_flags_t,
  149. gimple *, int);
  150. extern void dump_gimple_stmt (dump_flags_t, dump_flags_t, gimple *, int);
  151. extern void print_combine_total_stats (void);
  152. extern bool enable_rtl_dump_file (void);
  153. template<unsigned int N, typename C>
  154. void dump_dec (int, const poly_int<N, C> &);
  155. /* In tree-dump.c */
  156. extern void dump_node (const_tree, dump_flags_t, FILE *);
  157. /* In combine.c */
  158. extern void dump_combine_total_stats (FILE *);
  159. /* In cfghooks.c */
  160. extern void dump_bb (FILE *, basic_block, int, dump_flags_t);
  161. /* Global variables used to communicate with passes. */
  162. extern FILE *dump_file;
  163. extern FILE *alt_dump_file;
  164. extern dump_flags_t dump_flags;
  165. extern const char *dump_file_name;
  166. /* Return true if any of the dumps is enabled, false otherwise. */
  167. static inline bool
  168. dump_enabled_p (void)
  169. {
  170. return (dump_file || alt_dump_file);
  171. }
  172. namespace gcc {
  173. class dump_manager
  174. {
  175. public:
  176. dump_manager ();
  177. ~dump_manager ();
  178. /* Register a dumpfile.
  179. TAKE_OWNERSHIP determines whether callee takes ownership of strings
  180. SUFFIX, SWTCH, and GLOB. */
  181. unsigned int
  182. dump_register (const char *suffix, const char *swtch, const char *glob,
  183. dump_kind dkind, int optgroup_flags, bool take_ownership);
  184. /* Allow languages and middle-end to register their dumps before the
  185. optimization passes. */
  186. void
  187. register_dumps ();
  188. /* Return the dump_file_info for the given phase. */
  189. struct dump_file_info *
  190. get_dump_file_info (int phase) const;
  191. struct dump_file_info *
  192. get_dump_file_info_by_switch (const char *swtch) const;
  193. /* Return the name of the dump file for the given phase.
  194. If the dump is not enabled, returns NULL. */
  195. char *
  196. get_dump_file_name (int phase) const;
  197. char *
  198. get_dump_file_name (struct dump_file_info *dfi) const;
  199. int
  200. dump_switch_p (const char *arg);
  201. /* Start a dump for PHASE. Store user-supplied dump flags in
  202. *FLAG_PTR. Return the number of streams opened. Set globals
  203. DUMP_FILE, and ALT_DUMP_FILE to point to the opened streams, and
  204. set dump_flags appropriately for both pass dump stream and
  205. -fopt-info stream. */
  206. int
  207. dump_start (int phase, dump_flags_t *flag_ptr);
  208. /* Finish a tree dump for PHASE and close associated dump streams. Also
  209. reset the globals DUMP_FILE, ALT_DUMP_FILE, and DUMP_FLAGS. */
  210. void
  211. dump_finish (int phase);
  212. FILE *
  213. dump_begin (int phase, dump_flags_t *flag_ptr);
  214. /* Returns nonzero if tree dump PHASE has been initialized. */
  215. int
  216. dump_initialized_p (int phase) const;
  217. /* Returns the switch name of PHASE. */
  218. const char *
  219. dump_flag_name (int phase) const;
  220. private:
  221. int
  222. dump_phase_enabled_p (int phase) const;
  223. int
  224. dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob);
  225. int
  226. dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename);
  227. int
  228. opt_info_enable_passes (int optgroup_flags, dump_flags_t flags,
  229. const char *filename);
  230. private:
  231. /* Dynamically registered dump files and switches. */
  232. int m_next_dump;
  233. struct dump_file_info *m_extra_dump_files;
  234. size_t m_extra_dump_files_in_use;
  235. size_t m_extra_dump_files_alloced;
  236. /* Grant access to dump_enable_all. */
  237. friend bool ::enable_rtl_dump_file (void);
  238. /* Grant access to opt_info_enable_passes. */
  239. friend int ::opt_info_switch_p (const char *arg);
  240. }; // class dump_manager
  241. } // namespace gcc
  242. #endif /* GCC_DUMPFILE_H */