tree-ssa-alias.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* Tree based alias analysis and alias oracle.
  2. Copyright (C) 2008-2020 Free Software Foundation, Inc.
  3. Contributed by Richard Guenther <rguenther@suse.de>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) 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 TREE_SSA_ALIAS_H
  17. #define TREE_SSA_ALIAS_H
  18. /* The points-to solution.
  19. The points-to solution is a union of pt_vars and the abstract
  20. sets specified by the flags. */
  21. struct GTY(()) pt_solution
  22. {
  23. /* Nonzero if points-to analysis couldn't determine where this pointer
  24. is pointing to. */
  25. unsigned int anything : 1;
  26. /* Nonzero if the points-to set includes any global memory. Note that
  27. even if this is zero pt_vars can still include global variables. */
  28. unsigned int nonlocal : 1;
  29. /* Nonzero if the points-to set includes the local escaped solution by
  30. reference. */
  31. unsigned int escaped : 1;
  32. /* Nonzero if the points-to set includes the IPA escaped solution by
  33. reference. */
  34. unsigned int ipa_escaped : 1;
  35. /* Nonzero if the points-to set includes 'nothing', the points-to set
  36. includes memory at address NULL. */
  37. unsigned int null : 1;
  38. /* Nonzero if the vars bitmap includes a variable included in 'nonlocal'. */
  39. unsigned int vars_contains_nonlocal : 1;
  40. /* Nonzero if the vars bitmap includes a variable included in 'escaped'. */
  41. unsigned int vars_contains_escaped : 1;
  42. /* Nonzero if the vars bitmap includes a anonymous heap variable that
  43. escaped the function and thus became global. */
  44. unsigned int vars_contains_escaped_heap : 1;
  45. /* Nonzero if the vars bitmap includes a anonymous variable used to
  46. represent storage pointed to by a restrict qualified pointer. */
  47. unsigned int vars_contains_restrict : 1;
  48. /* Nonzero if the vars bitmap includes an interposable variable. */
  49. unsigned int vars_contains_interposable : 1;
  50. /* Set of variables that this pointer may point to. */
  51. bitmap vars;
  52. };
  53. /* Simplified and cached information about a memory reference tree.
  54. Used by the alias-oracle internally and externally in alternate
  55. interfaces. */
  56. class ao_ref
  57. {
  58. public:
  59. /* The original full memory reference tree or NULL_TREE if that is
  60. not available. */
  61. tree ref;
  62. /* The following fields are the decomposed reference as returned
  63. by get_ref_base_and_extent. */
  64. /* The base object of the memory reference or NULL_TREE if all of
  65. the following fields are not yet computed. */
  66. tree base;
  67. /* The offset relative to the base. */
  68. poly_int64 offset;
  69. /* The size of the access. */
  70. poly_int64 size;
  71. /* The maximum possible extent of the access or -1 if unconstrained. */
  72. poly_int64 max_size;
  73. /* The alias set of the access or -1 if not yet computed. */
  74. alias_set_type ref_alias_set;
  75. /* The alias set of the base object or -1 if not yet computed. */
  76. alias_set_type base_alias_set;
  77. /* Whether the memory is considered a volatile access. */
  78. bool volatile_p;
  79. bool max_size_known_p () const;
  80. };
  81. /* Return true if the maximum size is known, rather than the special -1
  82. marker. */
  83. inline bool
  84. ao_ref::max_size_known_p () const
  85. {
  86. return known_size_p (max_size);
  87. }
  88. /* In tree-ssa-alias.c */
  89. extern void ao_ref_init (ao_ref *, tree);
  90. extern void ao_ref_init_from_ptr_and_size (ao_ref *, tree, tree);
  91. extern tree ao_ref_base (ao_ref *);
  92. extern alias_set_type ao_ref_alias_set (ao_ref *);
  93. extern alias_set_type ao_ref_base_alias_set (ao_ref *);
  94. extern bool ptr_deref_may_alias_global_p (tree);
  95. extern bool ptr_derefs_may_alias_p (tree, tree);
  96. extern bool ptrs_compare_unequal (tree, tree);
  97. extern bool ref_may_alias_global_p (tree);
  98. extern bool ref_may_alias_global_p (ao_ref *);
  99. extern bool refs_may_alias_p (tree, tree, bool = true);
  100. extern bool refs_may_alias_p_1 (ao_ref *, ao_ref *, bool);
  101. extern bool refs_anti_dependent_p (tree, tree);
  102. extern bool refs_output_dependent_p (tree, tree);
  103. extern bool ref_maybe_used_by_stmt_p (gimple *, tree, bool = true);
  104. extern bool ref_maybe_used_by_stmt_p (gimple *, ao_ref *, bool = true);
  105. extern bool stmt_may_clobber_global_p (gimple *);
  106. extern bool stmt_may_clobber_ref_p (gimple *, tree, bool = true);
  107. extern bool stmt_may_clobber_ref_p_1 (gimple *, ao_ref *, bool = true);
  108. extern bool call_may_clobber_ref_p (gcall *, tree);
  109. extern bool call_may_clobber_ref_p_1 (gcall *, ao_ref *);
  110. extern bool stmt_kills_ref_p (gimple *, tree);
  111. extern bool stmt_kills_ref_p (gimple *, ao_ref *);
  112. enum translate_flags
  113. { TR_TRANSLATE, TR_VALUEIZE_AND_DISAMBIGUATE, TR_DISAMBIGUATE };
  114. extern tree get_continuation_for_phi (gimple *, ao_ref *, bool,
  115. unsigned int &, bitmap *, bool,
  116. void *(*)(ao_ref *, tree, void *,
  117. translate_flags *),
  118. void *, translate_flags
  119. = TR_VALUEIZE_AND_DISAMBIGUATE);
  120. extern void *walk_non_aliased_vuses (ao_ref *, tree, bool,
  121. void *(*)(ao_ref *, tree, void *),
  122. void *(*)(ao_ref *, tree, void *,
  123. translate_flags *),
  124. tree (*)(tree), unsigned &, void *);
  125. extern int walk_aliased_vdefs (ao_ref *, tree,
  126. bool (*)(ao_ref *, tree, void *),
  127. void *, bitmap *,
  128. bool *function_entry_reached = NULL,
  129. unsigned int limit = 0);
  130. extern void dump_alias_info (FILE *);
  131. extern void debug_alias_info (void);
  132. extern void dump_points_to_solution (FILE *, struct pt_solution *);
  133. extern void debug (pt_solution &ref);
  134. extern void debug (pt_solution *ptr);
  135. extern void dump_points_to_info_for (FILE *, tree);
  136. extern void debug_points_to_info_for (tree);
  137. extern void dump_alias_stats (FILE *);
  138. /* In tree-ssa-structalias.c */
  139. extern unsigned int compute_may_aliases (void);
  140. extern bool pt_solution_empty_p (const pt_solution *);
  141. extern bool pt_solution_singleton_or_null_p (struct pt_solution *, unsigned *);
  142. extern bool pt_solution_includes_global (struct pt_solution *);
  143. extern bool pt_solution_includes (struct pt_solution *, const_tree);
  144. extern bool pt_solutions_intersect (struct pt_solution *, struct pt_solution *);
  145. extern void pt_solution_reset (struct pt_solution *);
  146. extern void pt_solution_set (struct pt_solution *, bitmap, bool);
  147. extern void pt_solution_set_var (struct pt_solution *, tree);
  148. extern void dump_pta_stats (FILE *);
  149. extern GTY(()) struct pt_solution ipa_escaped_pt;
  150. /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
  151. overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
  152. range is open-ended. Otherwise return false. */
  153. static inline bool
  154. ranges_overlap_p (HOST_WIDE_INT pos1,
  155. unsigned HOST_WIDE_INT size1,
  156. HOST_WIDE_INT pos2,
  157. unsigned HOST_WIDE_INT size2)
  158. {
  159. if (size1 == 0 || size2 == 0)
  160. return false;
  161. if (pos1 >= pos2
  162. && (size2 == (unsigned HOST_WIDE_INT)-1
  163. || pos1 < (pos2 + (HOST_WIDE_INT) size2)))
  164. return true;
  165. if (pos2 >= pos1
  166. && (size1 == (unsigned HOST_WIDE_INT)-1
  167. || pos2 < (pos1 + (HOST_WIDE_INT) size1)))
  168. return true;
  169. return false;
  170. }
  171. #endif /* TREE_SSA_ALIAS_H */