tree-ssa-alias.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Tree based alias analysis and alias oracle.
  2. Copyright (C) 2008-2019 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. struct ao_ref
  57. {
  58. /* The original full memory reference tree or NULL_TREE if that is
  59. not available. */
  60. tree ref;
  61. /* The following fields are the decomposed reference as returned
  62. by get_ref_base_and_extent. */
  63. /* The base object of the memory reference or NULL_TREE if all of
  64. the following fields are not yet computed. */
  65. tree base;
  66. /* The offset relative to the base. */
  67. poly_int64 offset;
  68. /* The size of the access. */
  69. poly_int64 size;
  70. /* The maximum possible extent of the access or -1 if unconstrained. */
  71. poly_int64 max_size;
  72. /* The alias set of the access or -1 if not yet computed. */
  73. alias_set_type ref_alias_set;
  74. /* The alias set of the base object or -1 if not yet computed. */
  75. alias_set_type base_alias_set;
  76. /* Whether the memory is considered a volatile access. */
  77. bool volatile_p;
  78. bool max_size_known_p () const;
  79. };
  80. /* Return true if the maximum size is known, rather than the special -1
  81. marker. */
  82. inline bool
  83. ao_ref::max_size_known_p () const
  84. {
  85. return known_size_p (max_size);
  86. }
  87. /* In tree-ssa-alias.c */
  88. extern void ao_ref_init (ao_ref *, tree);
  89. extern void ao_ref_init_from_ptr_and_size (ao_ref *, tree, tree);
  90. extern tree ao_ref_base (ao_ref *);
  91. extern alias_set_type ao_ref_alias_set (ao_ref *);
  92. extern alias_set_type ao_ref_base_alias_set (ao_ref *);
  93. extern bool ptr_deref_may_alias_global_p (tree);
  94. extern bool ptr_derefs_may_alias_p (tree, tree);
  95. extern bool ptrs_compare_unequal (tree, tree);
  96. extern bool ref_may_alias_global_p (tree);
  97. extern bool ref_may_alias_global_p (ao_ref *);
  98. extern bool refs_may_alias_p (tree, tree, bool = true);
  99. extern bool refs_may_alias_p_1 (ao_ref *, ao_ref *, bool);
  100. extern bool refs_anti_dependent_p (tree, tree);
  101. extern bool refs_output_dependent_p (tree, tree);
  102. extern bool ref_maybe_used_by_stmt_p (gimple *, tree, bool = true);
  103. extern bool ref_maybe_used_by_stmt_p (gimple *, ao_ref *, bool = true);
  104. extern bool stmt_may_clobber_global_p (gimple *);
  105. extern bool stmt_may_clobber_ref_p (gimple *, tree, bool = true);
  106. extern bool stmt_may_clobber_ref_p_1 (gimple *, ao_ref *, bool = true);
  107. extern bool call_may_clobber_ref_p (gcall *, tree);
  108. extern bool call_may_clobber_ref_p_1 (gcall *, ao_ref *);
  109. extern bool stmt_kills_ref_p (gimple *, tree);
  110. extern bool stmt_kills_ref_p (gimple *, ao_ref *);
  111. extern tree get_continuation_for_phi (gimple *, ao_ref *, bool,
  112. unsigned int &, bitmap *, bool,
  113. void *(*)(ao_ref *, tree, void *, bool *),
  114. void *);
  115. extern void *walk_non_aliased_vuses (ao_ref *, tree, bool,
  116. void *(*)(ao_ref *, tree, void *),
  117. void *(*)(ao_ref *, tree, void *, bool *),
  118. tree (*)(tree), unsigned &, void *);
  119. extern int walk_aliased_vdefs (ao_ref *, tree,
  120. bool (*)(ao_ref *, tree, void *),
  121. void *, bitmap *,
  122. bool *function_entry_reached = NULL,
  123. unsigned int limit = 0);
  124. extern void dump_alias_info (FILE *);
  125. extern void debug_alias_info (void);
  126. extern void dump_points_to_solution (FILE *, struct pt_solution *);
  127. extern void debug (pt_solution &ref);
  128. extern void debug (pt_solution *ptr);
  129. extern void dump_points_to_info_for (FILE *, tree);
  130. extern void debug_points_to_info_for (tree);
  131. extern void dump_alias_stats (FILE *);
  132. /* In tree-ssa-structalias.c */
  133. extern unsigned int compute_may_aliases (void);
  134. extern bool pt_solution_empty_p (struct pt_solution *);
  135. extern bool pt_solution_singleton_or_null_p (struct pt_solution *, unsigned *);
  136. extern bool pt_solution_includes_global (struct pt_solution *);
  137. extern bool pt_solution_includes (struct pt_solution *, const_tree);
  138. extern bool pt_solutions_intersect (struct pt_solution *, struct pt_solution *);
  139. extern void pt_solution_reset (struct pt_solution *);
  140. extern void pt_solution_set (struct pt_solution *, bitmap, bool);
  141. extern void pt_solution_set_var (struct pt_solution *, tree);
  142. extern void dump_pta_stats (FILE *);
  143. extern GTY(()) struct pt_solution ipa_escaped_pt;
  144. /* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
  145. overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
  146. range is open-ended. Otherwise return false. */
  147. static inline bool
  148. ranges_overlap_p (HOST_WIDE_INT pos1,
  149. unsigned HOST_WIDE_INT size1,
  150. HOST_WIDE_INT pos2,
  151. unsigned HOST_WIDE_INT size2)
  152. {
  153. if (size1 == 0 || size2 == 0)
  154. return false;
  155. if (pos1 >= pos2
  156. && (size2 == (unsigned HOST_WIDE_INT)-1
  157. || pos1 < (pos2 + (HOST_WIDE_INT) size2)))
  158. return true;
  159. if (pos2 >= pos1
  160. && (size1 == (unsigned HOST_WIDE_INT)-1
  161. || pos2 < (pos1 + (HOST_WIDE_INT) size1)))
  162. return true;
  163. return false;
  164. }
  165. #endif /* TREE_SSA_ALIAS_H */