ipa-utils.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* Utilities for ipa analysis.
  2. Copyright (C) 2004-2015 Free Software Foundation, Inc.
  3. Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
  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_UTILS_H
  17. #define GCC_IPA_UTILS_H
  18. struct ipa_dfs_info {
  19. int dfn_number;
  20. int low_link;
  21. /* This field will have the samy value for any two nodes in the same strongly
  22. connected component. */
  23. int scc_no;
  24. bool new_node;
  25. bool on_stack;
  26. struct cgraph_node* next_cycle;
  27. PTR aux;
  28. };
  29. /* In ipa-utils.c */
  30. void ipa_print_order (FILE*, const char *, struct cgraph_node**, int);
  31. int ipa_reduced_postorder (struct cgraph_node **, bool, bool,
  32. bool (*ignore_edge) (struct cgraph_edge *));
  33. void ipa_free_postorder_info (void);
  34. vec<cgraph_node *> ipa_get_nodes_in_cycle (struct cgraph_node *);
  35. bool ipa_edge_within_scc (struct cgraph_edge *);
  36. int ipa_reverse_postorder (struct cgraph_node **);
  37. tree get_base_var (tree);
  38. void ipa_merge_profiles (struct cgraph_node *dst,
  39. struct cgraph_node *src, bool preserve_body = false);
  40. bool recursive_call_p (tree, tree);
  41. /* In ipa-profile.c */
  42. bool ipa_propagate_frequency (struct cgraph_node *node);
  43. /* In ipa-devirt.c */
  44. struct odr_type_d;
  45. typedef odr_type_d *odr_type;
  46. void build_type_inheritance_graph (void);
  47. void update_type_inheritance_graph (void);
  48. vec <cgraph_node *>
  49. possible_polymorphic_call_targets (tree, HOST_WIDE_INT,
  50. ipa_polymorphic_call_context,
  51. bool *copletep = NULL,
  52. void **cache_token = NULL,
  53. bool speuclative = false);
  54. odr_type get_odr_type (tree, bool insert = false);
  55. bool possible_polymorphic_call_target_p (tree ref, gimple stmt, struct cgraph_node *n);
  56. void dump_possible_polymorphic_call_targets (FILE *, tree, HOST_WIDE_INT,
  57. const ipa_polymorphic_call_context &);
  58. bool possible_polymorphic_call_target_p (tree, HOST_WIDE_INT,
  59. const ipa_polymorphic_call_context &,
  60. struct cgraph_node *);
  61. tree method_class_type (const_tree);
  62. tree inlined_polymorphic_ctor_dtor_block_p (tree, bool);
  63. bool decl_maybe_in_construction_p (tree, tree, gimple, tree);
  64. tree vtable_pointer_value_to_binfo (const_tree);
  65. bool vtable_pointer_value_to_vtable (const_tree, tree *, unsigned HOST_WIDE_INT *);
  66. tree subbinfo_with_vtable_at_offset (tree, unsigned HOST_WIDE_INT, tree);
  67. void compare_virtual_tables (varpool_node *, varpool_node *);
  68. bool type_all_derivations_known_p (const_tree);
  69. bool type_known_to_have_no_deriavations_p (tree);
  70. bool contains_polymorphic_type_p (const_tree);
  71. void register_odr_type (tree);
  72. bool types_must_be_same_for_odr (tree, tree);
  73. bool types_odr_comparable (tree, tree, bool strict = false);
  74. cgraph_node *try_speculative_devirtualization (tree, HOST_WIDE_INT,
  75. ipa_polymorphic_call_context);
  76. /* Return vector containing possible targets of polymorphic call E.
  77. If COMPLETEP is non-NULL, store true if the list is complete.
  78. CACHE_TOKEN (if non-NULL) will get stored to an unique ID of entry
  79. in the target cache. If user needs to visit every target list
  80. just once, it can memoize them.
  81. Returned vector is placed into cache. It is NOT caller's responsibility
  82. to free it. The vector can be freed on cgraph_remove_node call if
  83. the particular node is a virtual function present in the cache. */
  84. inline vec <cgraph_node *>
  85. possible_polymorphic_call_targets (struct cgraph_edge *e,
  86. bool *completep = NULL,
  87. void **cache_token = NULL,
  88. bool speculative = false)
  89. {
  90. ipa_polymorphic_call_context context(e);
  91. return possible_polymorphic_call_targets (e->indirect_info->otr_type,
  92. e->indirect_info->otr_token,
  93. context,
  94. completep, cache_token,
  95. speculative);
  96. }
  97. /* Same as above but taking OBJ_TYPE_REF as an parameter. */
  98. inline vec <cgraph_node *>
  99. possible_polymorphic_call_targets (tree ref,
  100. gimple call,
  101. bool *completep = NULL,
  102. void **cache_token = NULL)
  103. {
  104. ipa_polymorphic_call_context context (current_function_decl, ref, call);
  105. return possible_polymorphic_call_targets (obj_type_ref_class (ref),
  106. tree_to_uhwi
  107. (OBJ_TYPE_REF_TOKEN (ref)),
  108. context,
  109. completep, cache_token);
  110. }
  111. /* Dump possible targets of a polymorphic call E into F. */
  112. inline void
  113. dump_possible_polymorphic_call_targets (FILE *f, struct cgraph_edge *e)
  114. {
  115. ipa_polymorphic_call_context context(e);
  116. dump_possible_polymorphic_call_targets (f, e->indirect_info->otr_type,
  117. e->indirect_info->otr_token,
  118. context);
  119. }
  120. /* Return true if N can be possibly target of a polymorphic call of
  121. E. */
  122. inline bool
  123. possible_polymorphic_call_target_p (struct cgraph_edge *e,
  124. struct cgraph_node *n)
  125. {
  126. ipa_polymorphic_call_context context(e);
  127. return possible_polymorphic_call_target_p (e->indirect_info->otr_type,
  128. e->indirect_info->otr_token,
  129. context, n);
  130. }
  131. /* Return true of T is type with One Definition Rule info attached.
  132. It means that either it is anonymous type or it has assembler name
  133. set. */
  134. static inline bool
  135. odr_type_p (const_tree t)
  136. {
  137. if (type_in_anonymous_namespace_p (t))
  138. return true;
  139. /* We do not have this information when not in LTO, but we do not need
  140. to care, since it is used only for type merging. */
  141. gcc_assert (in_lto_p || flag_lto);
  142. return (TYPE_NAME (t)
  143. && (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t))));
  144. }
  145. /* Return true if BINFO corresponds to a type with virtual methods.
  146. Every type has several BINFOs. One is the BINFO associated by the type
  147. while other represents bases of derived types. The BINFOs representing
  148. bases do not have BINFO_VTABLE pointer set when this is the single
  149. inheritance (because vtables are shared). Look up the BINFO of type
  150. and check presence of its vtable. */
  151. inline bool
  152. polymorphic_type_binfo_p (const_tree binfo)
  153. {
  154. /* See if BINFO's type has an virtual table associtated with it.
  155. Check is defensive because of Java FE produces BINFOs
  156. without BINFO_TYPE set. */
  157. return (BINFO_TYPE (binfo) && TYPE_BINFO (BINFO_TYPE (binfo))
  158. && BINFO_VTABLE (TYPE_BINFO (BINFO_TYPE (binfo))));
  159. }
  160. #endif /* GCC_IPA_UTILS_H */