tree-inline.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Tree inlining hooks and declarations.
  2. Copyright (C) 2001-2019 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. struct cgraph_edge;
  19. /* Indicate the desired behavior wrt call graph edges. We can either
  20. duplicate the edge (inlining, cloning), move the edge (versioning,
  21. parallelization), or move the edges of the clones (saving). */
  22. enum copy_body_cge_which
  23. {
  24. CB_CGE_DUPLICATE,
  25. CB_CGE_MOVE,
  26. CB_CGE_MOVE_CLONES
  27. };
  28. typedef int_hash <unsigned short, 0> dependence_hash;
  29. /* Data required for function body duplication. */
  30. struct copy_body_data
  31. {
  32. /* FUNCTION_DECL for function being inlined, or in general the
  33. source function providing the original trees. */
  34. tree src_fn;
  35. /* FUNCTION_DECL for function being inlined into, or in general
  36. the destination function receiving the new trees. */
  37. tree dst_fn;
  38. /* Callgraph node of the source function. */
  39. struct cgraph_node *src_node;
  40. /* Callgraph node of the destination function. */
  41. struct cgraph_node *dst_node;
  42. /* struct function for function being inlined. Usually this is the same
  43. as DECL_STRUCT_FUNCTION (src_fn), but can be different if saved_cfg
  44. and saved_eh are in use. */
  45. struct function *src_cfun;
  46. /* The VAR_DECL for the return value. */
  47. tree retvar;
  48. /* The map from local declarations in the inlined function to
  49. equivalents in the function into which it is being inlined. */
  50. hash_map<tree, tree> *decl_map;
  51. /* Create a new decl to replace DECL in the destination function. */
  52. tree (*copy_decl) (tree, struct copy_body_data *);
  53. /* Current BLOCK. */
  54. tree block;
  55. /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL
  56. is not. */
  57. gcall *call_stmt;
  58. /* > 0 if we are remapping a type currently. */
  59. int remapping_type_depth;
  60. /* Exception landing pad the inlined call lies in. */
  61. int eh_lp_nr;
  62. /* Maps region and landing pad structures from the function being copied
  63. to duplicates created within the function we inline into. */
  64. hash_map<void *, void *> *eh_map;
  65. /* We use the same mechanism do all sorts of different things. Rather
  66. than enumerating the different cases, we categorize the behavior
  67. in the various situations. */
  68. /* What to do with call graph edges. */
  69. enum copy_body_cge_which transform_call_graph_edges;
  70. /* True if a new CFG should be created. False for inlining, true for
  71. everything else. */
  72. bool transform_new_cfg;
  73. /* True if RETURN_EXPRs should be transformed to just the contained
  74. MODIFY_EXPR. The branch semantics of the return will be handled
  75. by manipulating the CFG rather than a statement. */
  76. bool transform_return_to_modify;
  77. /* True if the parameters of the source function are transformed.
  78. Only true for inlining. */
  79. bool transform_parameter;
  80. /* True if this statement will need to be regimplified. */
  81. bool regimplify;
  82. /* True if trees may not be unshared. */
  83. bool do_not_unshare;
  84. /* True if trees should not be folded during the copying. */
  85. bool do_not_fold;
  86. /* True if new declarations may not be created during type remapping. */
  87. bool prevent_decl_creation_for_types;
  88. /* True if the location information will need to be reset. */
  89. bool reset_location;
  90. /* Replace error_mark_node as upper bound of array types with
  91. an uninitialized VAR_DECL temporary. */
  92. bool adjust_array_error_bounds;
  93. /* Usually copy_decl callback always creates new decls, in that case
  94. we want to remap all variably_modified_type_p types. If this flag
  95. is set, remap_type will do further checks to see if remap_decl
  96. of any decls mentioned in the type will remap to anything but itself
  97. and only in that case will actually remap the type. */
  98. bool dont_remap_vla_if_no_change;
  99. /* A function to be called when duplicating BLOCK nodes. */
  100. void (*transform_lang_insert_block) (tree);
  101. /* Statements that might be possibly folded. */
  102. hash_set<gimple *> *statements_to_fold;
  103. /* Entry basic block to currently copied body. */
  104. basic_block entry_bb;
  105. /* For partial function versioning, bitmap of bbs to be copied,
  106. otherwise NULL. */
  107. bitmap blocks_to_copy;
  108. /* Debug statements that need processing. */
  109. vec<gdebug *> debug_stmts;
  110. /* A map from local declarations in the inlined function to
  111. equivalents in the function into which it is being inlined, where
  112. the originals have been mapped to a value rather than to a
  113. variable. */
  114. hash_map<tree, tree> *debug_map;
  115. /* A map from the inlined functions dependence info cliques to
  116. equivalents in the function into which it is being inlined. */
  117. hash_map<dependence_hash, unsigned short> *dependence_map;
  118. /* A list of addressable local variables remapped into the caller
  119. when inlining a call within an OpenMP SIMD-on-SIMT loop. */
  120. vec<tree> *dst_simt_vars;
  121. /* If clobbers for local variables from the inline function
  122. that need to live in memory should be added to EH landing pads
  123. outside of the inlined function, this should be the number
  124. of basic blocks in the caller before inlining. Zero otherwise. */
  125. int add_clobbers_to_eh_landing_pads;
  126. };
  127. /* Weights of constructions for estimate_num_insns. */
  128. struct eni_weights
  129. {
  130. /* Cost per call. */
  131. unsigned call_cost;
  132. /* Cost per indirect call. */
  133. unsigned indirect_call_cost;
  134. /* Cost per call to a target specific builtin */
  135. unsigned target_builtin_call_cost;
  136. /* Cost of "expensive" div and mod operations. */
  137. unsigned div_mod_cost;
  138. /* Cost for omp construct. */
  139. unsigned omp_cost;
  140. /* Cost for tm transaction. */
  141. unsigned tm_cost;
  142. /* Cost of return. */
  143. unsigned return_cost;
  144. /* True when time of statement should be estimated. Thus, the
  145. cost of a switch statement is logarithmic rather than linear in number
  146. of cases. */
  147. bool time_based;
  148. };
  149. /* Weights that estimate_num_insns uses for heuristics in inlining. */
  150. extern eni_weights eni_inlining_weights;
  151. /* Weights that estimate_num_insns uses to estimate the size of the
  152. produced code. */
  153. extern eni_weights eni_size_weights;
  154. /* Weights that estimate_num_insns uses to estimate the time necessary
  155. to execute the produced code. */
  156. extern eni_weights eni_time_weights;
  157. /* Function prototypes. */
  158. void init_inline_once (void);
  159. extern tree copy_tree_body_r (tree *, int *, void *);
  160. extern void insert_decl_map (copy_body_data *, tree, tree);
  161. unsigned int optimize_inline_calls (tree);
  162. tree maybe_inline_call_in_expr (tree);
  163. bool tree_inlinable_function_p (tree);
  164. tree copy_tree_r (tree *, int *, void *);
  165. tree copy_decl_no_change (tree decl, copy_body_data *id);
  166. int estimate_move_cost (tree type, bool);
  167. int estimate_num_insns (gimple *, eni_weights *);
  168. int estimate_num_insns_fn (tree, eni_weights *);
  169. int estimate_num_insns_seq (gimple_seq, eni_weights *);
  170. bool tree_versionable_function_p (tree);
  171. extern tree remap_decl (tree decl, copy_body_data *id);
  172. extern tree remap_type (tree type, copy_body_data *id);
  173. extern gimple_seq copy_gimple_seq_and_replace_locals (gimple_seq seq);
  174. extern bool debug_find_tree (tree, tree);
  175. extern tree copy_fn (tree, tree&, tree&);
  176. extern const char *copy_forbidden (struct function *fun);
  177. extern tree copy_decl_for_dup_finish (copy_body_data *id, tree decl, tree copy);
  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 */