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-2026 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 a readonly object like a
47 STRING_CST that does not have an underlying declaration but will
48 end up in the constant pool. */
49 unsigned int const_pool : 1;
50
51 /* Nonzero if the vars bitmap includes a variable included in 'nonlocal'. */
52 unsigned int vars_contains_nonlocal : 1;
53 /* Nonzero if the vars bitmap includes a local automatic variable. */
54 unsigned int vars_contains_auto : 1;
55 /* Nonzero if the vars bitmap includes a variable included in 'escaped'. */
56 unsigned int vars_contains_escaped : 1;
57 /* Nonzero if the vars bitmap includes a anonymous heap variable that
58 escaped the function and thus became global. */
60 /* Nonzero if the vars bitmap includes a anonymous variable used to
61 represent storage pointed to by a restrict qualified pointer. */
62 unsigned int vars_contains_restrict : 1;
63 /* Nonzero if the vars bitmap includes an interposable variable. */
65
66 /* Set of variables that this pointer may point to. */
68};
69
70
71/* Simplified and cached information about a memory reference tree.
72 Used by the alias-oracle internally and externally in alternate
73 interfaces. */
74class ao_ref
75{
76public:
77 /* The original full memory reference tree or NULL_TREE if that is
78 not available. */
80
81 /* The following fields are the decomposed reference as returned
82 by get_ref_base_and_extent. */
83 /* The base object of the memory reference or NULL_TREE if all of
84 the following fields are not yet computed. */
86 /* The offset relative to the base. */
88 /* The size of the access. */
90 /* The maximum possible extent of the access or -1 if unconstrained. */
92
93 /* The alias set of the access or -1 if not yet computed. */
95
96 /* The alias set of the base object or -1 if not yet computed. */
98
99 /* Whether the memory is considered a volatile access. */
101
102 bool max_size_known_p () const;
103};
104
105/* Return true if the maximum size is known, rather than the special -1
106 marker. */
107
108inline bool
110{
111 return known_size_p (max_size);
112}
113
114/* In tree-ssa-alias.cc */
115extern void ao_ref_init (ao_ref *, tree);
117extern void ao_ref_init_from_ptr_and_range (ao_ref *, tree, bool,
119 poly_int64);
120extern tree ao_ref_base (ao_ref *);
125extern bool ao_ref_alignment (ao_ref *, unsigned int *,
126 unsigned HOST_WIDE_INT *);
127extern bool ptr_deref_may_alias_global_p (tree, bool);
128extern bool ptr_deref_may_alias_auto_p (tree);
129extern bool ptr_derefs_may_alias_p (tree, tree);
130extern bool ptrs_compare_unequal (tree, tree);
131extern bool ref_may_alias_global_p (tree, bool);
132extern bool ref_may_alias_global_p (ao_ref *, bool);
133extern bool refs_may_alias_p (tree, tree, bool = true);
134extern bool refs_may_alias_p_1 (ao_ref *, ao_ref *, bool);
135extern bool refs_anti_dependent_p (tree, tree);
136extern bool refs_output_dependent_p (tree, tree);
137extern bool ref_maybe_used_by_stmt_p (gimple *, tree, bool = true);
138extern bool ref_maybe_used_by_stmt_p (gimple *, ao_ref *, bool = true);
139extern bool stmt_may_clobber_global_p (gimple *, bool);
140extern bool stmt_may_clobber_ref_p (gimple *, tree, bool = true);
141extern bool stmt_may_clobber_ref_p_1 (gimple *, ao_ref *, bool = true);
142extern bool call_may_clobber_ref_p (gcall *, tree, bool = true);
143extern bool call_may_clobber_ref_p_1 (gcall *, ao_ref *, bool = true);
144extern bool stmt_kills_ref_p (gimple *, tree);
145extern bool stmt_kills_ref_p (gimple *, ao_ref *);
147
151 unsigned int &, bitmap *,
152 void *(*)(ao_ref *, tree, void *,
154 void *,
155 bool (*)(edge, void *) = nullptr,
158extern void *walk_non_aliased_vuses (ao_ref *, tree, bool,
159 void *(*)(ao_ref *, tree, void *),
160 void *(*)(ao_ref *, tree, void *,
162 bool (*)(edge, void *),
163 tree (*)(tree), unsigned &, void *);
164extern int walk_aliased_vdefs (ao_ref *, tree,
165 bool (*)(ao_ref *, tree, void *),
166 void *, bitmap *,
167 bool *function_entry_reached = NULL,
168 unsigned int limit = 0);
169extern void dump_alias_info (FILE *);
170extern void debug_alias_info (void);
171extern void dump_points_to_solution (FILE *, const pt_solution *);
172extern void debug (pt_solution &ref);
173extern void debug (pt_solution *ptr);
174extern void dump_points_to_info_for (FILE *, tree);
175extern void debug_points_to_info_for (tree);
176extern void dump_alias_stats (FILE *);
177
178
179/* In tree-ssa-structalias.cc */
180extern unsigned int compute_may_aliases (void);
181extern bool pt_solution_empty_p (const pt_solution *);
182extern bool pt_solution_singleton_or_null_p (const pt_solution *, unsigned *);
183extern bool pt_solution_includes_global (const pt_solution *, bool);
184extern bool pt_solution_includes_auto (const pt_solution *);
185extern bool pt_solution_includes (const pt_solution *, const_tree);
186extern bool pt_solution_includes_const_pool (const pt_solution *);
187extern bool pt_solutions_intersect (const pt_solution *, const pt_solution *);
188extern void pt_solution_reset (struct pt_solution *);
189extern void pt_solution_set (struct pt_solution *, bitmap, bool);
190extern void pt_solution_set_var (struct pt_solution *, tree);
191
192extern void dump_pta_stats (FILE *);
193
194extern GTY(()) struct pt_solution ipa_escaped_pt;
195
196/* Return true, if the two ranges [POS1, SIZE1] and [POS2, SIZE2]
197 overlap. SIZE1 and/or SIZE2 can be (unsigned)-1 in which case the
198 range is open-ended. Otherwise return false. */
199
200inline bool
201ranges_overlap_p (HOST_WIDE_INT pos1,
202 unsigned HOST_WIDE_INT size1,
203 HOST_WIDE_INT pos2,
204 unsigned HOST_WIDE_INT size2)
205{
206 if (size1 == 0 || size2 == 0)
207 return false;
208 if (pos1 >= pos2
209 && (size2 == (unsigned HOST_WIDE_INT)-1
210 || pos1 < (pos2 + (HOST_WIDE_INT) size2)))
211 return true;
212 if (pos2 >= pos1
213 && (size1 == (unsigned HOST_WIDE_INT)-1
214 || pos2 < (pos1 + (HOST_WIDE_INT) size1)))
215 return true;
216
217 return false;
218}
219
220
221
222#endif /* TREE_SSA_ALIAS_H */
Definition tree-ssa-alias.h:75
poly_int64 offset
Definition tree-ssa-alias.h:87
bool volatile_p
Definition tree-ssa-alias.h:100
tree base
Definition tree-ssa-alias.h:85
poly_int64 size
Definition tree-ssa-alias.h:89
tree ref
Definition tree-ssa-alias.h:79
alias_set_type ref_alias_set
Definition tree-ssa-alias.h:94
poly_int64 max_size
Definition tree-ssa-alias.h:91
alias_set_type base_alias_set
Definition tree-ssa-alias.h:97
bool max_size_known_p() const
Definition tree-ssa-alias.h:109
bool debug
Definition collect-utils.cc:34
class edge_def * edge
Definition coretypes.h:356
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:353
poly_int< NUM_POLY_INT_COEFFS, HOST_WIDE_INT > poly_int64
Definition poly-int-types.h:24
Definition gimple.h:356
Definition gimple.h:225
Definition gimple.h:465
Definition tree-ssa-alias.h:29
unsigned int vars_contains_escaped
Definition tree-ssa-alias.h:56
bitmap vars
Definition tree-ssa-alias.h:67
unsigned int vars_contains_interposable
Definition tree-ssa-alias.h:64
unsigned int vars_contains_auto
Definition tree-ssa-alias.h:54
unsigned int vars_contains_escaped_heap
Definition tree-ssa-alias.h:59
unsigned int nonlocal
Definition tree-ssa-alias.h:36
unsigned int vars_contains_restrict
Definition tree-ssa-alias.h:62
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:49
unsigned int vars_contains_nonlocal
Definition tree-ssa-alias.h:52
unsigned int anything
Definition tree-ssa-alias.h:32
#define NULL
Definition system.h:55
bool stmt_may_clobber_ref_p(gimple *stmt, tree ref, bool tbaa_p)
Definition tree-ssa-alias.cc:3331
bool refs_anti_dependent_p(tree load, tree store)
Definition tree-ssa-alias.cc:2626
void dump_points_to_info_for(FILE *file, tree ptr)
Definition tree-ssa-alias.cc:750
tree ao_ref_base_alias_ptr_type(ao_ref *ref)
Definition tree-ssa-alias.cc:839
bool ptr_derefs_may_alias_p(tree ptr1, tree ptr2)
Definition tree-ssa-alias.cc:341
int walk_aliased_vdefs(ao_ref *ref, tree vdef, bool(*walker)(ao_ref *, tree, void *), void *data, bitmap *visited, bool *function_entry_reached, unsigned int limit)
Definition tree-ssa-alias.cc:4127
bool ptr_deref_may_alias_global_p(tree ptr, bool escaped_local_p)
Definition tree-ssa-alias.cc:221
DEBUG_FUNCTION void debug_points_to_info_for(tree var)
Definition tree-ssa-alias.cc:768
void dump_alias_info(FILE *file)
Definition tree-ssa-alias.cc:615
tree get_continuation_for_phi(gphi *phi, ao_ref *ref, bool tbaa_p, unsigned int &limit, bitmap *visited, void *(*translate)(ao_ref *, tree, void *, translate_flags *), void *data, bool(*is_backedge)(edge, void *), translate_flags disambiguate_only)
Definition tree-ssa-alias.cc:3861
bool call_may_clobber_ref_p(gcall *call, tree ref, bool tbaa_p)
Definition tree-ssa-alias.cc:3280
DEBUG_FUNCTION void debug_alias_info(void)
Definition tree-ssa-alias.cc:663
bool stmt_may_clobber_global_p(gimple *stmt, bool escaped_local_p)
Definition tree-ssa-alias.cc:582
bool ref_can_have_store_data_races(tree ref)
Definition tree-ssa-alias.cc:3735
alias_set_type ao_ref_alias_set(ao_ref *ref)
Definition tree-ssa-alias.cc:825
bool ptrs_compare_unequal(tree ptr1, tree ptr2)
Definition tree-ssa-alias.cc:447
bool stmt_may_clobber_ref_p_1(gimple *stmt, ao_ref *ref, bool tbaa_p)
Definition tree-ssa-alias.cc:3298
void ao_ref_init_from_ptr_and_size(ao_ref *ref, tree ptr, tree size)
Definition tree-ssa-alias.cc:962
alias_set_type ao_ref_base_alias_set(ao_ref *ref)
Definition tree-ssa-alias.cc:806
bool ao_ref_alignment(ao_ref *ref, unsigned int *align, unsigned HOST_WIDE_INT *bitpos)
Definition tree-ssa-alias.cc:871
bool ref_may_alias_global_p(ao_ref *ref, bool escaped_local_p)
Definition tree-ssa-alias.cc:564
tree ao_ref_base(ao_ref *ref)
Definition tree-ssa-alias.cc:792
void dump_alias_stats(FILE *s)
Definition tree-ssa-alias.cc:135
bool call_may_clobber_ref_p_1(gcall *call, ao_ref *ref, bool tbaa_p)
Definition tree-ssa-alias.cc:3114
bool refs_output_dependent_p(tree store1, tree store2)
Definition tree-ssa-alias.cc:2638
bool refs_may_alias_p(tree ref1, tree ref2, bool tbaa_p)
Definition tree-ssa-alias.cc:2614
tree ao_ref_alias_ptr_type(ao_ref *ref)
Definition tree-ssa-alias.cc:858
bool stmt_kills_ref_p(gimple *stmt, ao_ref *ref)
Definition tree-ssa-alias.cc:3463
bool refs_may_alias_p_1(ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
Definition tree-ssa-alias.cc:2595
bool ptr_deref_may_alias_auto_p(tree ptr)
Definition tree-ssa-alias.cc:245
void dump_points_to_solution(FILE *file, const pt_solution *pt)
Definition tree-ssa-alias.cc:672
void * walk_non_aliased_vuses(ao_ref *ref, tree vuse, bool tbaa_p, void *(*walker)(ao_ref *, tree, void *), void *(*translate)(ao_ref *, tree, void *, translate_flags *), bool(*is_backedge)(edge, void *), tree(*valueize)(tree), unsigned &limit, void *data)
Definition tree-ssa-alias.cc:3965
void ao_ref_init(ao_ref *r, tree ref)
Definition tree-ssa-alias.cc:777
bool ref_maybe_used_by_stmt_p(gimple *stmt, ao_ref *ref, bool tbaa_p)
Definition tree-ssa-alias.cc:3059
void ao_ref_init_from_ptr_and_range(ao_ref *ref, tree ptr, bool range_known, poly_int64 offset, poly_int64 size, poly_int64 max_size)
Definition tree-ssa-alias.cc:898
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:201
struct pt_solution ipa_escaped_pt
Definition tree-ssa-structalias.cc:1831
translate_flags
Definition tree-ssa-alias.h:149
@ TR_VALUEIZE_AND_DISAMBIGUATE
Definition tree-ssa-alias.h:149
@ TR_TRANSLATE
Definition tree-ssa-alias.h:149
@ TR_DISAMBIGUATE
Definition tree-ssa-alias.h:149
void pt_solution_set(struct pt_solution *, bitmap, bool)
Definition tree-ssa-structalias.cc:1000
unsigned int compute_may_aliases(void)
Definition tree-ssa-structalias.cc:1714
bool pt_solution_includes_const_pool(const pt_solution *)
Definition tree-ssa-structalias.cc:1194
void dump_pta_stats(FILE *)
Definition tree-ssa-structalias.cc:966
bool pt_solution_includes(const pt_solution *, const_tree)
Definition tree-ssa-structalias.cc:1180
bool pt_solution_singleton_or_null_p(const pt_solution *, unsigned *)
Definition tree-ssa-structalias.cc:1086
void pt_solution_set_var(struct pt_solution *, tree)
Definition tree-ssa-structalias.cc:1014
bool pt_solution_includes_global(const pt_solution *, bool)
Definition tree-ssa-structalias.cc:1102
void pt_solution_reset(struct pt_solution *)
Definition tree-ssa-structalias.cc:988
bool pt_solutions_intersect(const pt_solution *, const pt_solution *)
Definition tree-ssa-structalias.cc:1255
bool pt_solution_includes_auto(const pt_solution *)
Definition tree-ssa-structalias.cc:1132
bool pt_solution_empty_p(const pt_solution *)
Definition tree-ssa-structalias.cc:1059