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