GCC Middle and Back End API Reference
tree-ssa-structalias.h
Go to the documentation of this file.
1/* Tree based points-to analysis
2 Copyright (C) 2005-2025 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
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/* NOTE: This file declares the internal interface of the points-to analyzer.
22 Outward-facing function declarations can be found in tree-ssa-alias.h. */
23
24#ifndef TREE_SSA_STRUCTALIAS_H
25#define TREE_SSA_STRUCTALIAS_H
26
27namespace pointer_analysis {
28
30
31/* Static IDs for the special variables. Variable ID zero is unused
32 and used as terminator for the sub-variable chain. */
33enum { nothing_id = 1, anything_id = 2, string_id = 3,
36
37/* Use 0x8000... as special unknown offset. */
38#define UNKNOWN_OFFSET HOST_WIDE_INT_MIN
39
40/* An expression that appears in a constraint. */
41
43{
44 /* Constraint type. */
46
47 /* Variable we are referring to in the constraint. */
48 unsigned int var;
49
50 /* Offset, in bits, of this constraint from the beginning of
51 variables it ends up referring to.
52
53 IOW, in a deref constraint, we would deref, get the result set,
54 then add OFFSET to each member. */
55 HOST_WIDE_INT offset;
56};
57typedef struct constraint_expr ce_s;
58
59/* Our set constraints are made up of two constraint expressions, one
60 LHS, and one RHS.
61
62 As described in the introduction in tree-ssa-structalias.cc, our set
63 constraints each represent an operation between set valued variables.
64*/
66{
69};
70typedef struct constraint *constraint_t;
71
73{
74 /* ID of this variable. */
75 unsigned int id;
76
77 /* True if this is a variable created by the constraint analysis, such as
78 heap variables and constraints we had to break up. */
79 unsigned int is_artificial_var : 1;
80
81 /* True if this is a special variable whose solution set should not be
82 changed. */
83 unsigned int is_special_var : 1;
84
85 /* True for variables whose size is not known or variable. */
86 unsigned int is_unknown_size_var : 1;
87
88 /* True for (sub-)fields that represent a whole variable. */
89 unsigned int is_full_var : 1;
90
91 /* True if this is a heap variable. */
92 unsigned int is_heap_var : 1;
93
94 /* True if this is a register variable. */
95 unsigned int is_reg_var : 1;
96
97 /* True if this field may contain pointers. */
98 unsigned int may_have_pointers : 1;
99
100 /* True if this field has only restrict qualified pointers. */
101 unsigned int only_restrict_pointers : 1;
102
103 /* True if this represents a heap var created for a restrict qualified
104 pointer. */
105 unsigned int is_restrict_var : 1;
106
107 /* True if this represents a global variable. */
108 unsigned int is_global_var : 1;
109
110 /* True if this represents a module escape point for IPA analysis. */
111 unsigned int is_ipa_escape_point : 1;
112
113 /* True if this represents a IPA function info. */
114 unsigned int is_fn_info : 1;
115
116 /* True if this appears as RHS in a ADDRESSOF constraint. */
117 unsigned int address_taken : 1;
118
119 /* ??? Store somewhere better. */
120 unsigned short ruid;
121
122 /* The ID of the variable for the next field in this structure
123 or zero for the last field in this structure. */
124 unsigned next;
125
126 /* The ID of the variable for the first field in this structure. */
127 unsigned head;
128
129 /* Offset of this variable, in bits, from the base variable. */
130 unsigned HOST_WIDE_INT offset;
131
132 /* Size of the variable, in bits. */
133 unsigned HOST_WIDE_INT size;
134
135 /* Full size of the base variable, in bits. */
136 unsigned HOST_WIDE_INT fullsize;
137
138 /* In IPA mode the shadow UID in case the variable needs to be duplicated in
139 the final points-to solution because it reaches its containing
140 function recursively. Zero if none is needed. */
141 unsigned int shadow_var_uid;
142
143 /* Name of this variable. */
144 const char *name;
145
146 /* Tree that this variable is associated with. */
148
149 /* Points-to set for this variable. */
151
152 /* Old points-to set for this variable. */
154};
155typedef struct variable_info *varinfo_t;
156
158{
159 unsigned int total_vars;
160 unsigned int nonpointer_vars;
163 unsigned int iterations;
164 unsigned int num_edges;
165 unsigned int num_implicit_edges;
166 unsigned int num_avoided_edges;
168};
169
170extern struct constraint_stats stats;
171
174
177extern unsigned int *var_rep;
178
179
180/* Return the varmap element N. */
181
182inline varinfo_t
183get_varinfo (unsigned int n)
184{
185 return varmap[n];
186}
187
188/* Return the next variable in the list of sub-variables of VI
189 or NULL if VI is the last sub-variable. */
190
191inline varinfo_t
193{
194 return get_varinfo (vi->next);
195}
196
198 unsigned HOST_WIDE_INT offset);
200 unsigned HOST_WIDE_INT offset);
201void dump_constraint (FILE *file, constraint_t c);
202void dump_constraints (FILE *file, int from);
203void dump_solution_for_var (FILE *file, unsigned int var);
204void dump_sa_stats (FILE *outfile);
205void dump_sa_points_to_info (FILE *outfile);
206void dump_varinfo (FILE *file, varinfo_t vi);
207void dump_varmap (FILE *file);
209void debug_constraints (void);
210void debug_solution_for_var (unsigned int);
211void debug_sa_points_to_info (void);
213void debug_varmap (void);
214
215} // namespace pointer_analysis
216
217#endif /* TREE_SSA_STRUCTALIAS_H */
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
Definition pta-andersen.cc:2454
void dump_sa_stats(FILE *outfile)
Definition tree-ssa-structalias.cc:390
varinfo_t vi_next(varinfo_t vi)
Definition tree-ssa-structalias.h:192
unsigned int * var_rep
Definition tree-ssa-structalias.cc:229
DEBUG_FUNCTION void debug_varinfo(varinfo_t vi)
Definition tree-ssa-structalias.cc:506
void dump_solution_for_var(FILE *file, unsigned int var)
Definition tree-ssa-structalias.cc:358
void dump_varmap(FILE *file)
Definition tree-ssa-structalias.cc:514
void dump_varinfo(FILE *file, varinfo_t vi)
Definition tree-ssa-structalias.cc:436
vec< varinfo_t > varmap
Definition tree-ssa-structalias.cc:217
void dump_sa_points_to_info(FILE *outfile)
Definition tree-ssa-structalias.cc:411
DEBUG_FUNCTION void debug_constraints(void)
Definition tree-ssa-structalias.cc:350
constraint_expr_type
Definition tree-ssa-structalias.h:29
@ SCALAR
Definition tree-ssa-structalias.h:29
@ ADDRESSOF
Definition tree-ssa-structalias.h:29
@ DEREF
Definition tree-ssa-structalias.h:29
bitmap_obstack oldpta_obstack
Definition tree-ssa-structalias.cc:213
@ escaped_id
Definition tree-ssa-structalias.h:34
@ integer_id
Definition tree-ssa-structalias.h:35
@ nonlocal_id
Definition tree-ssa-structalias.h:34
@ nothing_id
Definition tree-ssa-structalias.h:33
@ storedanything_id
Definition tree-ssa-structalias.h:35
@ anything_id
Definition tree-ssa-structalias.h:33
@ escaped_return_id
Definition tree-ssa-structalias.h:34
@ string_id
Definition tree-ssa-structalias.h:33
void dump_constraints(FILE *file, int from)
Definition tree-ssa-structalias.cc:335
vec< constraint_t > constraints
Definition tree-ssa-structalias.cc:220
varinfo_t first_or_preceding_vi_for_offset(varinfo_t start, unsigned HOST_WIDE_INT offset)
Definition tree-ssa-structalias.cc:269
void dump_constraint(FILE *file, constraint_t c)
Definition tree-ssa-structalias.cc:294
struct variable_info * varinfo_t
Definition tree-ssa-structalias.h:155
DEBUG_FUNCTION void debug_sa_points_to_info(void)
Definition tree-ssa-structalias.cc:428
DEBUG_FUNCTION void debug_solution_for_var(unsigned int var)
Definition tree-ssa-structalias.cc:382
bitmap_obstack pta_obstack
Definition tree-ssa-structalias.cc:210
struct constraint * constraint_t
Definition tree-ssa-structalias.h:70
struct constraint_stats stats
Definition tree-ssa-structalias.cc:231
varinfo_t first_vi_for_offset(varinfo_t start, unsigned HOST_WIDE_INT offset)
Definition tree-ssa-structalias.cc:237
DEBUG_FUNCTION void debug_constraint(constraint_t c)
Definition tree-ssa-structalias.cc:326
varinfo_t get_varinfo(unsigned int n)
Definition tree-ssa-structalias.h:183
DEBUG_FUNCTION void debug_varmap(void)
Definition tree-ssa-structalias.cc:533
struct constraint_expr ce_s
Definition tree-ssa-structalias.h:57
Definition bitmap.h:294
Definition tree-ssa-structalias.h:43
HOST_WIDE_INT offset
Definition tree-ssa-structalias.h:55
constraint_expr_type type
Definition tree-ssa-structalias.h:45
unsigned int var
Definition tree-ssa-structalias.h:48
Definition tree-ssa-structalias.h:158
unsigned int iterations
Definition tree-ssa-structalias.h:163
unsigned int num_implicit_edges
Definition tree-ssa-structalias.h:165
unsigned int num_avoided_edges
Definition tree-ssa-structalias.h:166
unsigned int unified_vars_dynamic
Definition tree-ssa-structalias.h:162
unsigned int nonpointer_vars
Definition tree-ssa-structalias.h:160
unsigned int total_vars
Definition tree-ssa-structalias.h:159
unsigned int points_to_sets_created
Definition tree-ssa-structalias.h:167
unsigned int num_edges
Definition tree-ssa-structalias.h:164
unsigned int unified_vars_static
Definition tree-ssa-structalias.h:161
Definition tree-ssa-structalias.h:66
struct constraint_expr lhs
Definition tree-ssa-structalias.h:67
struct constraint_expr rhs
Definition tree-ssa-structalias.h:68
Definition tree-ssa-structalias.h:73
const char * name
Definition tree-ssa-structalias.h:144
unsigned short ruid
Definition tree-ssa-structalias.h:120
unsigned int only_restrict_pointers
Definition tree-ssa-structalias.h:101
unsigned int is_full_var
Definition tree-ssa-structalias.h:89
unsigned int is_ipa_escape_point
Definition tree-ssa-structalias.h:111
tree decl
Definition tree-ssa-structalias.h:147
unsigned int may_have_pointers
Definition tree-ssa-structalias.h:98
unsigned int shadow_var_uid
Definition tree-ssa-structalias.h:141
unsigned int is_special_var
Definition tree-ssa-structalias.h:83
unsigned HOST_WIDE_INT fullsize
Definition tree-ssa-structalias.h:136
unsigned int is_fn_info
Definition tree-ssa-structalias.h:114
bitmap solution
Definition tree-ssa-structalias.h:150
unsigned HOST_WIDE_INT size
Definition tree-ssa-structalias.h:133
unsigned int is_reg_var
Definition tree-ssa-structalias.h:95
unsigned int address_taken
Definition tree-ssa-structalias.h:117
unsigned int is_global_var
Definition tree-ssa-structalias.h:108
unsigned int is_artificial_var
Definition tree-ssa-structalias.h:79
unsigned int is_unknown_size_var
Definition tree-ssa-structalias.h:86
unsigned int id
Definition tree-ssa-structalias.h:75
unsigned HOST_WIDE_INT offset
Definition tree-ssa-structalias.h:130
bitmap oldsolution
Definition tree-ssa-structalias.h:153
unsigned int is_heap_var
Definition tree-ssa-structalias.h:92
unsigned head
Definition tree-ssa-structalias.h:127
unsigned int is_restrict_var
Definition tree-ssa-structalias.h:105
unsigned next
Definition tree-ssa-structalias.h:124
Definition vec.h:450