tree-inline.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Tree inlining hooks and declarations.
  2. Copyright (C) 2001-2015 Free Software Foundation, Inc.
  3. Contributed by Alexandre Oliva <aoliva@redhat.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License 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_TREE_INLINE_H
  17. #define GCC_TREE_INLINE_H
  18. #include "hash-map.h"
  19. #include "hash-set.h"
  20. struct cgraph_edge;
  21. /* Indicate the desired behavior wrt call graph edges. We can either
  22. duplicate the edge (inlining, cloning), move the edge (versioning,
  23. parallelization), or move the edges of the clones (saving). */
  24. enum copy_body_cge_which
  25. {
  26. CB_CGE_DUPLICATE,
  27. CB_CGE_MOVE,
  28. CB_CGE_MOVE_CLONES
  29. };
  30. struct dependence_hasher : default_hashmap_traits
  31. {
  32. template<typename T>
  33. static void
  34. mark_deleted (T &e)
  35. { gcc_unreachable (); }
  36. template<typename T>
  37. static void
  38. mark_empty (T &e)
  39. { e.m_key = 0; }
  40. template<typename T>
  41. static bool
  42. is_deleted (T &)
  43. { return false; }
  44. template<typename T> static bool is_empty (T &e) { return e.m_key == 0; }
  45. };
  46. /* Data required for function body duplication. */
  47. struct copy_body_data
  48. {
  49. /* FUNCTION_DECL for function being inlined, or in general the
  50. source function providing the original trees. */
  51. tree src_fn;
  52. /* FUNCTION_DECL for function being inlined into, or in general
  53. the destination function receiving the new trees. */
  54. tree dst_fn;
  55. /* Callgraph node of the source function. */
  56. struct cgraph_node *src_node;
  57. /* Callgraph node of the destination function. */
  58. struct cgraph_node *dst_node;
  59. /* struct function for function being inlined. Usually this is the same
  60. as DECL_STRUCT_FUNCTION (src_fn), but can be different if saved_cfg
  61. and saved_eh are in use. */
  62. struct function *src_cfun;
  63. /* The VAR_DECL for the return value. */
  64. tree retvar;
  65. /* The VAR_DECL for the return bounds. */
  66. tree retbnd;
  67. /* Assign statements that need bounds copy. */
  68. vec<gimple> assign_stmts;
  69. /* The map from local declarations in the inlined function to
  70. equivalents in the function into which it is being inlined. */
  71. hash_map<tree, tree> *decl_map;
  72. /* Create a new decl to replace DECL in the destination function. */
  73. tree (*copy_decl) (tree, struct copy_body_data *);
  74. /* Current BLOCK. */
  75. tree block;
  76. /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL
  77. is not. */
  78. gimple call_stmt;
  79. /* Exception landing pad the inlined call lies in. */
  80. int eh_lp_nr;
  81. /* Maps region and landing pad structures from the function being copied
  82. to duplicates created within the function we inline into. */
  83. hash_map<void *, void *> *eh_map;
  84. /* We use the same mechanism do all sorts of different things. Rather
  85. than enumerating the different cases, we categorize the behavior
  86. in the various situations. */
  87. /* What to do with call graph edges. */
  88. enum copy_body_cge_which transform_call_graph_edges;
  89. /* True if a new CFG should be created. False for inlining, true for
  90. everything else. */
  91. bool transform_new_cfg;
  92. /* True if RETURN_EXPRs should be transformed to just the contained
  93. MODIFY_EXPR. The branch semantics of the return will be handled
  94. by manipulating the CFG rather than a statement. */
  95. bool transform_return_to_modify;
  96. /* True if the parameters of the source function are transformed.
  97. Only true for inlining. */
  98. bool transform_parameter;
  99. /* True if this statement will need to be regimplified. */
  100. bool regimplify;
  101. /* True if trees should not be unshared. */
  102. bool do_not_unshare;
  103. /* > 0 if we are remapping a type currently. */
  104. int remapping_type_depth;
  105. /* A function to be called when duplicating BLOCK nodes. */
  106. void (*transform_lang_insert_block) (tree);
  107. /* Statements that might be possibly folded. */
  108. hash_set<gimple> *statements_to_fold;
  109. /* Entry basic block to currently copied body. */
  110. basic_block entry_bb;
  111. /* For partial function versioning, bitmap of bbs to be copied,
  112. otherwise NULL. */
  113. bitmap blocks_to_copy;
  114. /* Debug statements that need processing. */
  115. vec<gdebug *> debug_stmts;
  116. /* A map from local declarations in the inlined function to
  117. equivalents in the function into which it is being inlined, where
  118. the originals have been mapped to a value rather than to a
  119. variable. */
  120. hash_map<tree, tree> *debug_map;
  121. /* Cilk keywords currently need to replace some variables that
  122. ordinary nested functions do not. */
  123. bool remap_var_for_cilk;
  124. /* A map from the inlined functions dependence info cliques to
  125. equivalents in the function into which it is being inlined. */
  126. hash_map<unsigned short, unsigned short, dependence_hasher> *dependence_map;
  127. };
  128. /* Weights of constructions for estimate_num_insns. */
  129. typedef struct eni_weights_d
  130. {
  131. /* Cost per call. */
  132. unsigned call_cost;
  133. /* Cost per indirect call. */
  134. unsigned indirect_call_cost;
  135. /* Cost per call to a target specific builtin */
  136. unsigned target_builtin_call_cost;
  137. /* Cost of "expensive" div and mod operations. */
  138. unsigned div_mod_cost;
  139. /* Cost for omp construct. */
  140. unsigned omp_cost;
  141. /* Cost for tm transaction. */
  142. unsigned tm_cost;
  143. /* Cost of return. */
  144. unsigned return_cost;
  145. /* True when time of statement should be estimated. Thus, the
  146. cost of a switch statement is logarithmic rather than linear in number
  147. of cases. */
  148. bool time_based;
  149. } eni_weights;
  150. /* Weights that estimate_num_insns uses for heuristics in inlining. */
  151. extern eni_weights eni_inlining_weights;
  152. /* Weights that estimate_num_insns uses to estimate the size of the
  153. produced code. */
  154. extern eni_weights eni_size_weights;
  155. /* Weights that estimate_num_insns uses to estimate the time necessary
  156. to execute the produced code. */
  157. extern eni_weights eni_time_weights;
  158. /* Function prototypes. */
  159. void init_inline_once (void);
  160. extern tree copy_tree_body_r (tree *, int *, void *);
  161. extern void insert_decl_map (copy_body_data *, tree, tree);
  162. unsigned int optimize_inline_calls (tree);
  163. tree maybe_inline_call_in_expr (tree);
  164. bool tree_inlinable_function_p (tree);
  165. tree copy_tree_r (tree *, int *, void *);
  166. tree copy_decl_no_change (tree decl, copy_body_data *id);
  167. int estimate_move_cost (tree type, bool);
  168. int estimate_num_insns (gimple, eni_weights *);
  169. int estimate_num_insns_fn (tree, eni_weights *);
  170. int count_insns_seq (gimple_seq, eni_weights *);
  171. bool tree_versionable_function_p (tree);
  172. extern tree remap_decl (tree decl, copy_body_data *id);
  173. extern tree remap_type (tree type, copy_body_data *id);
  174. extern gimple_seq copy_gimple_seq_and_replace_locals (gimple_seq seq);
  175. extern bool debug_find_tree (tree, tree);
  176. extern tree copy_fn (tree, tree&, tree&);
  177. extern const char *copy_forbidden (struct function *fun, tree fndecl);
  178. /* This is in tree-inline.c since the routine uses
  179. data structures from the inliner. */
  180. extern tree build_duplicate_type (tree);
  181. #endif /* GCC_TREE_INLINE_H */