ipa-inline.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Inlining decision heuristics.
  2. Copyright (C) 2003-2020 Free Software Foundation, Inc.
  3. Contributed by Jan Hubicka
  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_IPA_INLINE_H
  17. #define GCC_IPA_INLINE_H
  18. /* Data we cache about callgraph edges during inlining to avoid expensive
  19. re-computations during the greedy algorithm. */
  20. class edge_growth_cache_entry
  21. {
  22. public:
  23. sreal time, nonspec_time;
  24. int size;
  25. ipa_hints hints;
  26. edge_growth_cache_entry()
  27. : size (0), hints (0) {}
  28. edge_growth_cache_entry(int64_t time, int64_t nonspec_time,
  29. int size, ipa_hints hints)
  30. : time (time), nonspec_time (nonspec_time), size (size),
  31. hints (hints) {}
  32. };
  33. extern fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache;
  34. /* In ipa-inline-analysis.c */
  35. int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
  36. int estimate_growth (struct cgraph_node *);
  37. bool growth_positive_p (struct cgraph_node *, struct cgraph_edge *, int);
  38. int do_estimate_edge_size (struct cgraph_edge *edge);
  39. sreal do_estimate_edge_time (struct cgraph_edge *edge, sreal *nonspec_time = NULL);
  40. ipa_hints do_estimate_edge_hints (struct cgraph_edge *edge);
  41. void reset_node_cache (struct cgraph_node *node);
  42. void initialize_growth_caches ();
  43. void free_growth_caches (void);
  44. /* In ipa-inline.c */
  45. unsigned int early_inliner (function *fun);
  46. bool inline_account_function_p (struct cgraph_node *node);
  47. /* In ipa-inline-transform.c */
  48. bool inline_call (struct cgraph_edge *, bool, vec<cgraph_edge *> *, int *, bool,
  49. bool *callee_removed = NULL);
  50. unsigned int inline_transform (struct cgraph_node *);
  51. void clone_inlined_nodes (struct cgraph_edge *e, bool, bool, int *);
  52. extern int ncalls_inlined;
  53. extern int nfunctions_inlined;
  54. extern function_summary <tree *> *ipa_saved_clone_sources;
  55. /* Return estimated size of the inline sequence of EDGE. */
  56. static inline int
  57. estimate_edge_size (struct cgraph_edge *edge)
  58. {
  59. edge_growth_cache_entry *entry;
  60. if (edge_growth_cache == NULL
  61. || (entry = edge_growth_cache->get (edge)) == NULL
  62. || entry->size == 0)
  63. return do_estimate_edge_size (edge);
  64. return entry->size - (entry->size > 0);
  65. }
  66. /* Return lower bound on estimated callee growth after inlining EDGE. */
  67. static inline int
  68. estimate_min_edge_growth (struct cgraph_edge *edge)
  69. {
  70. ipa_call_summary *s = ipa_call_summaries->get (edge);
  71. struct cgraph_node *callee = edge->callee->ultimate_alias_target ();
  72. return (ipa_fn_summaries->get (callee)->min_size - s->call_stmt_size);
  73. }
  74. /* Return estimated callee growth after inlining EDGE. */
  75. static inline int
  76. estimate_edge_growth (struct cgraph_edge *edge)
  77. {
  78. ipa_call_summary *s = ipa_call_summaries->get (edge);
  79. gcc_checking_assert (s->call_stmt_size || !edge->callee->analyzed);
  80. return (estimate_edge_size (edge) - s->call_stmt_size);
  81. }
  82. /* Return estimated callee runtime increase after inlining
  83. EDGE. */
  84. static inline sreal
  85. estimate_edge_time (struct cgraph_edge *edge, sreal *nonspec_time = NULL)
  86. {
  87. edge_growth_cache_entry *entry;
  88. if (edge_growth_cache == NULL
  89. || (entry = edge_growth_cache->get (edge)) == NULL
  90. || entry->time == 0)
  91. return do_estimate_edge_time (edge, nonspec_time);
  92. if (nonspec_time)
  93. *nonspec_time = edge_growth_cache->get (edge)->nonspec_time;
  94. return entry->time;
  95. }
  96. /* Return estimated callee runtime increase after inlining
  97. EDGE. */
  98. static inline ipa_hints
  99. estimate_edge_hints (struct cgraph_edge *edge)
  100. {
  101. edge_growth_cache_entry *entry;
  102. if (edge_growth_cache == NULL
  103. || (entry = edge_growth_cache->get (edge)) == NULL
  104. || entry->hints == 0)
  105. return do_estimate_edge_hints (edge);
  106. return entry->hints - 1;
  107. }
  108. #endif /* GCC_IPA_INLINE_H */