ipa-inline.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Inlining decision heuristics.
  2. Copyright (C) 2003-2019 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 call_summary<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 free_growth_caches (void);
  41. /* In ipa-inline.c */
  42. unsigned int early_inliner (function *fun);
  43. bool inline_account_function_p (struct cgraph_node *node);
  44. /* In ipa-inline-transform.c */
  45. bool inline_call (struct cgraph_edge *, bool, vec<cgraph_edge *> *, int *, bool,
  46. bool *callee_removed = NULL);
  47. unsigned int inline_transform (struct cgraph_node *);
  48. void clone_inlined_nodes (struct cgraph_edge *e, bool, bool, int *);
  49. extern int ncalls_inlined;
  50. extern int nfunctions_inlined;
  51. /* Return estimated size of the inline sequence of EDGE. */
  52. static inline int
  53. estimate_edge_size (struct cgraph_edge *edge)
  54. {
  55. edge_growth_cache_entry *entry;
  56. if (edge_growth_cache == NULL
  57. || (entry = edge_growth_cache->get (edge)) == NULL
  58. || entry->size == 0)
  59. return do_estimate_edge_size (edge);
  60. return entry->size - (entry->size > 0);
  61. }
  62. /* Return estimated callee growth after inlining EDGE. */
  63. static inline int
  64. estimate_edge_growth (struct cgraph_edge *edge)
  65. {
  66. ipa_call_summary *s = ipa_call_summaries->get (edge);
  67. gcc_checking_assert (s->call_stmt_size || !edge->callee->analyzed);
  68. return (estimate_edge_size (edge) - s->call_stmt_size);
  69. }
  70. /* Return estimated callee runtime increase after inlining
  71. EDGE. */
  72. static inline sreal
  73. estimate_edge_time (struct cgraph_edge *edge, sreal *nonspec_time = NULL)
  74. {
  75. edge_growth_cache_entry *entry;
  76. if (edge_growth_cache == NULL
  77. || (entry = edge_growth_cache->get (edge)) == NULL
  78. || entry->time == 0)
  79. return do_estimate_edge_time (edge);
  80. if (nonspec_time)
  81. *nonspec_time = edge_growth_cache->get (edge)->nonspec_time;
  82. return entry->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. edge_growth_cache_entry *entry;
  90. if (edge_growth_cache == NULL
  91. || (entry = edge_growth_cache->get (edge)) == NULL
  92. || entry->hints == 0)
  93. return do_estimate_edge_hints (edge);
  94. return entry->hints - 1;
  95. }
  96. #endif /* GCC_IPA_INLINE_H */