optinfo.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Optimization information.
  2. Copyright (C) 2018-2019 Free Software Foundation, Inc.
  3. Contributed by David Malcolm <dmalcolm@redhat.com>.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_OPTINFO_H
  17. #define GCC_OPTINFO_H
  18. /* An "optinfo" is a bundle of information describing part of an
  19. optimization, which can be emitted to zero or more of several
  20. destinations, such as:
  21. * saved to a file as an "optimization record"
  22. They are generated in response to calls to the "dump_*" API in
  23. dumpfile.h; repeated calls to the "dump_*" API are consolidated
  24. into a pending optinfo instance, with a "dump_*_loc" starting a new
  25. optinfo instance.
  26. The data sent to the dump calls are captured within the pending optinfo
  27. instance as a sequence of optinfo_items. For example, given:
  28. if (dump_enabled_p ())
  29. {
  30. dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
  31. "not vectorized: live stmt not supported: ");
  32. dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, 0);
  33. }
  34. the "dump_printf_loc" call begins a new optinfo containing two items:
  35. (1) a text item containing "not vectorized: live stmt not supported: "
  36. (2) a gimple item for "stmt"
  37. Dump destinations are thus able to access rich metadata about the
  38. items when the optinfo is emitted to them, rather than just having plain
  39. text. For example, when saving the above optinfo to a file as an
  40. "optimization record", the record could capture the source location of
  41. "stmt" above, rather than just its textual form.
  42. The currently pending optinfo is emitted and deleted:
  43. * each time a "dump_*_loc" call occurs (which starts the next optinfo), or
  44. * when the dump files are changed (at the end of a pass)
  45. Dumping to an optinfo instance is non-trivial (due to building optinfo_item
  46. instances), so all usage should be guarded by
  47. if (optinfo_enabled_p ())
  48. which is off by default. */
  49. /* Forward decls. */
  50. struct opt_pass;
  51. class optinfo_item;
  52. /* Return true if any of the active optinfo destinations make use
  53. of inlining information.
  54. (if true, then the information is preserved). */
  55. extern bool optinfo_wants_inlining_info_p ();
  56. /* The various kinds of optinfo. */
  57. enum optinfo_kind
  58. {
  59. OPTINFO_KIND_SUCCESS,
  60. OPTINFO_KIND_FAILURE,
  61. OPTINFO_KIND_NOTE,
  62. OPTINFO_KIND_SCOPE
  63. };
  64. extern const char *optinfo_kind_to_string (enum optinfo_kind kind);
  65. class dump_context;
  66. /* A bundle of information describing part of an optimization. */
  67. class optinfo
  68. {
  69. friend class dump_context;
  70. public:
  71. optinfo (const dump_location_t &loc,
  72. enum optinfo_kind kind,
  73. opt_pass *pass)
  74. : m_loc (loc), m_kind (kind), m_pass (pass), m_items ()
  75. {}
  76. ~optinfo ();
  77. const dump_location_t &
  78. get_dump_location () const { return m_loc; }
  79. const dump_user_location_t &
  80. get_user_location () const { return m_loc.get_user_location (); }
  81. const dump_impl_location_t &
  82. get_impl_location () const { return m_loc.get_impl_location (); }
  83. enum optinfo_kind get_kind () const { return m_kind; }
  84. opt_pass *get_pass () const { return m_pass; }
  85. unsigned int num_items () const { return m_items.length (); }
  86. const optinfo_item *get_item (unsigned int i) const { return m_items[i]; }
  87. location_t get_location_t () const { return m_loc.get_location_t (); }
  88. profile_count get_count () const { return m_loc.get_count (); }
  89. void add_item (optinfo_item *item);
  90. void emit_for_opt_problem () const;
  91. private:
  92. /* Pre-canned ways of manipulating the optinfo, for use by friend class
  93. dump_context. */
  94. void handle_dump_file_kind (dump_flags_t);
  95. private:
  96. dump_location_t m_loc;
  97. enum optinfo_kind m_kind;
  98. opt_pass *m_pass;
  99. auto_vec <optinfo_item *> m_items;
  100. };
  101. /* An enum for discriminating between different kinds of optinfo_item. */
  102. enum optinfo_item_kind
  103. {
  104. OPTINFO_ITEM_KIND_TEXT,
  105. OPTINFO_ITEM_KIND_TREE,
  106. OPTINFO_ITEM_KIND_GIMPLE,
  107. OPTINFO_ITEM_KIND_SYMTAB_NODE
  108. };
  109. /* An item within an optinfo. */
  110. class optinfo_item
  111. {
  112. public:
  113. optinfo_item (enum optinfo_item_kind kind, location_t location,
  114. char *text);
  115. ~optinfo_item ();
  116. enum optinfo_item_kind get_kind () const { return m_kind; }
  117. location_t get_location () const { return m_location; }
  118. const char *get_text () const { return m_text; }
  119. private:
  120. /* Metadata (e.g. for optimization records). */
  121. enum optinfo_item_kind m_kind;
  122. location_t m_location;
  123. /* The textual form of the item, owned by the item. */
  124. char *m_text;
  125. };
  126. #endif /* #ifndef GCC_OPTINFO_H */