ipa-inline.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Inlining decision heuristics.
  2. Copyright (C) 2003-2018 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. struct edge_growth_cache_entry
  21. {
  22. sreal time, nonspec_time;
  23. int size;
  24. ipa_hints hints;
  25. edge_growth_cache_entry()
  26. : size (0), hints (0) {}
  27. edge_growth_cache_entry(int64_t time, int64_t nonspec_time,
  28. int size, ipa_hints hints)
  29. : time (time), nonspec_time (nonspec_time), size (size),
  30. hints (hints) {}
  31. };
  32. extern vec<edge_growth_cache_entry> edge_growth_cache;
  33. /* In ipa-inline-analysis.c */
  34. int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
  35. int estimate_growth (struct cgraph_node *);
  36. bool growth_likely_positive (struct cgraph_node *, int);
  37. int do_estimate_edge_size (struct cgraph_edge *edge);
  38. sreal do_estimate_edge_time (struct cgraph_edge *edge);
  39. ipa_hints do_estimate_edge_hints (struct cgraph_edge *edge);
  40. void initialize_growth_caches (void);
  41. void free_growth_caches (void);
  42. /* In ipa-inline.c */
  43. unsigned int early_inliner (function *fun);
  44. bool inline_account_function_p (struct cgraph_node *node);
  45. /* In ipa-inline-transform.c */
  46. bool inline_call (struct cgraph_edge *, bool, vec<cgraph_edge *> *, int *, bool,
  47. bool *callee_removed = NULL);
  48. unsigned int inline_transform (struct cgraph_node *);
  49. void clone_inlined_nodes (struct cgraph_edge *e, bool, bool, int *);
  50. extern int ncalls_inlined;
  51. extern int nfunctions_inlined;
  52. /* Return estimated size of the inline sequence of EDGE. */
  53. static inline int
  54. estimate_edge_size (struct cgraph_edge *edge)
  55. {
  56. int ret;
  57. if ((int)edge_growth_cache.length () <= edge->uid
  58. || !(ret = edge_growth_cache[edge->uid].size))
  59. return do_estimate_edge_size (edge);
  60. return ret - (ret > 0);
  61. }
  62. /* Return estimated callee growth after inlining EDGE. */
  63. static inline int
  64. estimate_edge_growth (struct cgraph_edge *edge)
  65. {
  66. gcc_checking_assert (ipa_call_summaries->get (edge)->call_stmt_size
  67. || !edge->callee->analyzed);
  68. return (estimate_edge_size (edge)
  69. - ipa_call_summaries->get (edge)->call_stmt_size);
  70. }
  71. /* Return estimated callee runtime increase after inlining
  72. EDGE. */
  73. static inline sreal
  74. estimate_edge_time (struct cgraph_edge *edge, sreal *nonspec_time = NULL)
  75. {
  76. sreal ret;
  77. if ((int)edge_growth_cache.length () <= edge->uid
  78. || !edge_growth_cache[edge->uid].size)
  79. return do_estimate_edge_time (edge);
  80. if (nonspec_time)
  81. *nonspec_time = edge_growth_cache[edge->uid].nonspec_time;
  82. return edge_growth_cache[edge->uid].time;
  83. }
  84. /* Return estimated callee runtime increase after inlining
  85. EDGE. */
  86. static inline ipa_hints
  87. estimate_edge_hints (struct cgraph_edge *edge)
  88. {
  89. ipa_hints ret;
  90. if ((int)edge_growth_cache.length () <= edge->uid
  91. || !(ret = edge_growth_cache[edge->uid].hints))
  92. return do_estimate_edge_hints (edge);
  93. return ret - 1;
  94. }
  95. /* Reset cached value for EDGE. */
  96. static inline void
  97. reset_edge_growth_cache (struct cgraph_edge *edge)
  98. {
  99. if ((int)edge_growth_cache.length () > edge->uid)
  100. {
  101. struct edge_growth_cache_entry zero (0, 0, 0, 0);
  102. edge_growth_cache[edge->uid] = zero;
  103. }
  104. }
  105. #endif /* GCC_IPA_INLINE_H */