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