1 /* Tree based points-to analysis
2 Copyright (C) 2005-2013 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
5 This file is part of GCC.
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.
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.
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/>. */
23 #include "coretypes.h"
29 #include "basic-block.h"
31 #include "tree-flow.h"
32 #include "tree-inline.h"
33 #include "diagnostic-core.h"
38 #include "tree-pass.h"
39 #include "alloc-pool.h"
40 #include "splay-tree.h"
44 #include "pointer-set.h"
46 /* The idea behind this analyzer is to generate set constraints from the
47 program, then solve the resulting constraints in order to generate the
50 Set constraints are a way of modeling program analysis problems that
51 involve sets. They consist of an inclusion constraint language,
52 describing the variables (each variable is a set) and operations that
53 are involved on the variables, and a set of rules that derive facts
54 from these operations. To solve a system of set constraints, you derive
55 all possible facts under the rules, which gives you the correct sets
58 See "Efficient Field-sensitive pointer analysis for C" by "David
59 J. Pearce and Paul H. J. Kelly and Chris Hankin, at
60 http://citeseer.ist.psu.edu/pearce04efficient.html
62 Also see "Ultra-fast Aliasing Analysis using CLA: A Million Lines
63 of C Code in a Second" by ""Nevin Heintze and Olivier Tardieu" at
64 http://citeseer.ist.psu.edu/heintze01ultrafast.html
66 There are three types of real constraint expressions, DEREF,
67 ADDRESSOF, and SCALAR. Each constraint expression consists
68 of a constraint type, a variable, and an offset.
70 SCALAR is a constraint expression type used to represent x, whether
71 it appears on the LHS or the RHS of a statement.
72 DEREF is a constraint expression type used to represent *x, whether
73 it appears on the LHS or the RHS of a statement.
74 ADDRESSOF is a constraint expression used to represent &x, whether
75 it appears on the LHS or the RHS of a statement.
77 Each pointer variable in the program is assigned an integer id, and
78 each field of a structure variable is assigned an integer id as well.
80 Structure variables are linked to their list of fields through a "next
81 field" in each variable that points to the next field in offset
83 Each variable for a structure field has
85 1. "size", that tells the size in bits of that field.
86 2. "fullsize, that tells the size in bits of the entire structure.
87 3. "offset", that tells the offset in bits from the beginning of the
88 structure to this field.
100 foo.a -> id 1, size 32, offset 0, fullsize 64, next foo.b
101 foo.b -> id 2, size 32, offset 32, fullsize 64, next NULL
102 bar -> id 3, size 32, offset 0, fullsize 32, next NULL
105 In order to solve the system of set constraints, the following is
108 1. Each constraint variable x has a solution set associated with it,
111 2. Constraints are separated into direct, copy, and complex.
112 Direct constraints are ADDRESSOF constraints that require no extra
113 processing, such as P = &Q
114 Copy constraints are those of the form P = Q.
115 Complex constraints are all the constraints involving dereferences
116 and offsets (including offsetted copies).
118 3. All direct constraints of the form P = &Q are processed, such
119 that Q is added to Sol(P)
121 4. All complex constraints for a given constraint variable are stored in a
122 linked list attached to that variable's node.
124 5. A directed graph is built out of the copy constraints. Each
125 constraint variable is a node in the graph, and an edge from
126 Q to P is added for each copy constraint of the form P = Q
128 6. The graph is then walked, and solution sets are
129 propagated along the copy edges, such that an edge from Q to P
130 causes Sol(P) <- Sol(P) union Sol(Q).
132 7. As we visit each node, all complex constraints associated with
133 that node are processed by adding appropriate copy edges to the graph, or the
134 appropriate variables to the solution set.
136 8. The process of walking the graph is iterated until no solution
139 Prior to walking the graph in steps 6 and 7, We perform static
140 cycle elimination on the constraint graph, as well
141 as off-line variable substitution.
143 TODO: Adding offsets to pointer-to-structures can be handled (IE not punted
144 on and turned into anything), but isn't. You can just see what offset
145 inside the pointed-to struct it's going to access.
147 TODO: Constant bounded arrays can be handled as if they were structs of the
148 same number of elements.
150 TODO: Modeling heap and incoming pointers becomes much better if we
151 add fields to them as we discover them, which we could do.
153 TODO: We could handle unions, but to be honest, it's probably not
154 worth the pain or slowdown. */
156 /* IPA-PTA optimizations possible.
158 When the indirect function called is ANYTHING we can add disambiguation
159 based on the function signatures (or simply the parameter count which
160 is the varinfo size). We also do not need to consider functions that
161 do not have their address taken.
163 The is_global_var bit which marks escape points is overly conservative
164 in IPA mode. Split it to is_escape_point and is_global_var - only
165 externally visible globals are escape points in IPA mode. This is
166 also needed to fix the pt_solution_includes_global predicate
167 (and thus ptr_deref_may_alias_global_p).
169 The way we introduce DECL_PT_UID to avoid fixing up all points-to
170 sets in the translation unit when we copy a DECL during inlining
171 pessimizes precision. The advantage is that the DECL_PT_UID keeps
172 compile-time and memory usage overhead low - the points-to sets
173 do not grow or get unshared as they would during a fixup phase.
174 An alternative solution is to delay IPA PTA until after all
175 inlining transformations have been applied.
177 The way we propagate clobber/use information isn't optimized.
178 It should use a new complex constraint that properly filters
179 out local variables of the callee (though that would make
180 the sets invalid after inlining). OTOH we might as well
181 admit defeat to WHOPR and simply do all the clobber/use analysis
182 and propagation after PTA finished but before we threw away
183 points-to information for memory variables. WHOPR and PTA
184 do not play along well anyway - the whole constraint solving
185 would need to be done in WPA phase and it will be very interesting
186 to apply the results to local SSA names during LTRANS phase.
188 We probably should compute a per-function unit-ESCAPE solution
189 propagating it simply like the clobber / uses solutions. The
190 solution can go alongside the non-IPA espaced solution and be
191 used to query which vars escape the unit through a function.
193 We never put function decls in points-to sets so we do not
194 keep the set of called functions for indirect calls.
196 And probably more. */
198 static bool use_field_sensitive
= true;
199 static int in_ipa_mode
= 0;
201 /* Used for predecessor bitmaps. */
202 static bitmap_obstack predbitmap_obstack
;
204 /* Used for points-to sets. */
205 static bitmap_obstack pta_obstack
;
207 /* Used for oldsolution members of variables. */
208 static bitmap_obstack oldpta_obstack
;
210 /* Used for per-solver-iteration bitmaps. */
211 static bitmap_obstack iteration_obstack
;
213 static unsigned int create_variable_info_for (tree
, const char *);
214 typedef struct constraint_graph
*constraint_graph_t
;
215 static void unify_nodes (constraint_graph_t
, unsigned int, unsigned int, bool);
218 typedef struct constraint
*constraint_t
;
221 #define EXECUTE_IF_IN_NONNULL_BITMAP(a, b, c, d) \
223 EXECUTE_IF_SET_IN_BITMAP (a, b, c, d)
225 static struct constraint_stats
227 unsigned int total_vars
;
228 unsigned int nonpointer_vars
;
229 unsigned int unified_vars_static
;
230 unsigned int unified_vars_dynamic
;
231 unsigned int iterations
;
232 unsigned int num_edges
;
233 unsigned int num_implicit_edges
;
234 unsigned int points_to_sets_created
;
239 /* ID of this variable */
242 /* True if this is a variable created by the constraint analysis, such as
243 heap variables and constraints we had to break up. */
244 unsigned int is_artificial_var
: 1;
246 /* True if this is a special variable whose solution set should not be
248 unsigned int is_special_var
: 1;
250 /* True for variables whose size is not known or variable. */
251 unsigned int is_unknown_size_var
: 1;
253 /* True for (sub-)fields that represent a whole variable. */
254 unsigned int is_full_var
: 1;
256 /* True if this is a heap variable. */
257 unsigned int is_heap_var
: 1;
259 /* True if this field may contain pointers. */
260 unsigned int may_have_pointers
: 1;
262 /* True if this field has only restrict qualified pointers. */
263 unsigned int only_restrict_pointers
: 1;
265 /* True if this represents a global variable. */
266 unsigned int is_global_var
: 1;
268 /* True if this represents a IPA function info. */
269 unsigned int is_fn_info
: 1;
271 /* A link to the variable for the next field in this structure. */
272 struct variable_info
*next
;
274 /* Offset of this variable, in bits, from the base variable */
275 unsigned HOST_WIDE_INT offset
;
277 /* Size of the variable, in bits. */
278 unsigned HOST_WIDE_INT size
;
280 /* Full size of the base variable, in bits. */
281 unsigned HOST_WIDE_INT fullsize
;
283 /* Name of this variable */
286 /* Tree that this variable is associated with. */
289 /* Points-to set for this variable. */
292 /* Old points-to set for this variable. */
295 typedef struct variable_info
*varinfo_t
;
297 static varinfo_t
first_vi_for_offset (varinfo_t
, unsigned HOST_WIDE_INT
);
298 static varinfo_t
first_or_preceding_vi_for_offset (varinfo_t
,
299 unsigned HOST_WIDE_INT
);
300 static varinfo_t
lookup_vi_for_tree (tree
);
301 static inline bool type_can_have_subvars (const_tree
);
303 /* Pool of variable info structures. */
304 static alloc_pool variable_info_pool
;
306 /* Map varinfo to final pt_solution. */
307 static pointer_map_t
*final_solutions
;
308 struct obstack final_solutions_obstack
;
310 /* Table of variable info structures for constraint variables.
311 Indexed directly by variable info id. */
312 static vec
<varinfo_t
> varmap
;
314 /* Return the varmap element N */
316 static inline varinfo_t
317 get_varinfo (unsigned int n
)
322 /* Static IDs for the special variables. */
323 enum { nothing_id
= 0, anything_id
= 1, readonly_id
= 2,
324 escaped_id
= 3, nonlocal_id
= 4,
325 storedanything_id
= 5, integer_id
= 6 };
327 /* Return a new variable info structure consisting for a variable
328 named NAME, and using constraint graph node NODE. Append it
329 to the vector of variable info structures. */
332 new_var_info (tree t
, const char *name
)
334 unsigned index
= varmap
.length ();
335 varinfo_t ret
= (varinfo_t
) pool_alloc (variable_info_pool
);
340 /* Vars without decl are artificial and do not have sub-variables. */
341 ret
->is_artificial_var
= (t
== NULL_TREE
);
342 ret
->is_special_var
= false;
343 ret
->is_unknown_size_var
= false;
344 ret
->is_full_var
= (t
== NULL_TREE
);
345 ret
->is_heap_var
= false;
346 ret
->may_have_pointers
= true;
347 ret
->only_restrict_pointers
= false;
348 ret
->is_global_var
= (t
== NULL_TREE
);
349 ret
->is_fn_info
= false;
351 ret
->is_global_var
= (is_global_var (t
)
352 /* We have to treat even local register variables
354 || (TREE_CODE (t
) == VAR_DECL
355 && DECL_HARD_REGISTER (t
)));
356 ret
->solution
= BITMAP_ALLOC (&pta_obstack
);
357 ret
->oldsolution
= NULL
;
362 varmap
.safe_push (ret
);
368 /* A map mapping call statements to per-stmt variables for uses
369 and clobbers specific to the call. */
370 struct pointer_map_t
*call_stmt_vars
;
372 /* Lookup or create the variable for the call statement CALL. */
375 get_call_vi (gimple call
)
380 slot_p
= pointer_map_insert (call_stmt_vars
, call
);
382 return (varinfo_t
) *slot_p
;
384 vi
= new_var_info (NULL_TREE
, "CALLUSED");
388 vi
->is_full_var
= true;
390 vi
->next
= vi2
= new_var_info (NULL_TREE
, "CALLCLOBBERED");
394 vi2
->is_full_var
= true;
396 *slot_p
= (void *) vi
;
400 /* Lookup the variable for the call statement CALL representing
401 the uses. Returns NULL if there is nothing special about this call. */
404 lookup_call_use_vi (gimple call
)
408 slot_p
= pointer_map_contains (call_stmt_vars
, call
);
410 return (varinfo_t
) *slot_p
;
415 /* Lookup the variable for the call statement CALL representing
416 the clobbers. Returns NULL if there is nothing special about this call. */
419 lookup_call_clobber_vi (gimple call
)
421 varinfo_t uses
= lookup_call_use_vi (call
);
428 /* Lookup or create the variable for the call statement CALL representing
432 get_call_use_vi (gimple call
)
434 return get_call_vi (call
);
437 /* Lookup or create the variable for the call statement CALL representing
440 static varinfo_t ATTRIBUTE_UNUSED
441 get_call_clobber_vi (gimple call
)
443 return get_call_vi (call
)->next
;
447 typedef enum {SCALAR
, DEREF
, ADDRESSOF
} constraint_expr_type
;
449 /* An expression that appears in a constraint. */
451 struct constraint_expr
453 /* Constraint type. */
454 constraint_expr_type type
;
456 /* Variable we are referring to in the constraint. */
459 /* Offset, in bits, of this constraint from the beginning of
460 variables it ends up referring to.
462 IOW, in a deref constraint, we would deref, get the result set,
463 then add OFFSET to each member. */
464 HOST_WIDE_INT offset
;
467 /* Use 0x8000... as special unknown offset. */
468 #define UNKNOWN_OFFSET ((HOST_WIDE_INT)-1 << (HOST_BITS_PER_WIDE_INT-1))
470 typedef struct constraint_expr ce_s
;
471 static void get_constraint_for_1 (tree
, vec
<ce_s
> *, bool, bool);
472 static void get_constraint_for (tree
, vec
<ce_s
> *);
473 static void get_constraint_for_rhs (tree
, vec
<ce_s
> *);
474 static void do_deref (vec
<ce_s
> *);
476 /* Our set constraints are made up of two constraint expressions, one
479 As described in the introduction, our set constraints each represent an
480 operation between set valued variables.
484 struct constraint_expr lhs
;
485 struct constraint_expr rhs
;
488 /* List of constraints that we use to build the constraint graph from. */
490 static vec
<constraint_t
> constraints
;
491 static alloc_pool constraint_pool
;
493 /* The constraint graph is represented as an array of bitmaps
494 containing successor nodes. */
496 struct constraint_graph
498 /* Size of this graph, which may be different than the number of
499 nodes in the variable map. */
502 /* Explicit successors of each node. */
505 /* Implicit predecessors of each node (Used for variable
507 bitmap
*implicit_preds
;
509 /* Explicit predecessors of each node (Used for variable substitution). */
512 /* Indirect cycle representatives, or -1 if the node has no indirect
514 int *indirect_cycles
;
516 /* Representative node for a node. rep[a] == a unless the node has
520 /* Equivalence class representative for a label. This is used for
521 variable substitution. */
524 /* Pointer equivalence label for a node. All nodes with the same
525 pointer equivalence label can be unified together at some point
526 (either during constraint optimization or after the constraint
530 /* Pointer equivalence representative for a label. This is used to
531 handle nodes that are pointer equivalent but not location
532 equivalent. We can unite these once the addressof constraints
533 are transformed into initial points-to sets. */
536 /* Pointer equivalence label for each node, used during variable
538 unsigned int *pointer_label
;
540 /* Location equivalence label for each node, used during location
541 equivalence finding. */
542 unsigned int *loc_label
;
544 /* Pointed-by set for each node, used during location equivalence
545 finding. This is pointed-by rather than pointed-to, because it
546 is constructed using the predecessor graph. */
549 /* Points to sets for pointer equivalence. This is *not* the actual
550 points-to sets for nodes. */
553 /* Bitmap of nodes where the bit is set if the node is a direct
554 node. Used for variable substitution. */
555 sbitmap direct_nodes
;
557 /* Bitmap of nodes where the bit is set if the node is address
558 taken. Used for variable substitution. */
559 bitmap address_taken
;
561 /* Vector of complex constraints for each graph node. Complex
562 constraints are those involving dereferences or offsets that are
564 vec
<constraint_t
> *complex;
567 static constraint_graph_t graph
;
569 /* During variable substitution and the offline version of indirect
570 cycle finding, we create nodes to represent dereferences and
571 address taken constraints. These represent where these start and
573 #define FIRST_REF_NODE (varmap).length ()
574 #define LAST_REF_NODE (FIRST_REF_NODE + (FIRST_REF_NODE - 1))
576 /* Return the representative node for NODE, if NODE has been unioned
578 This function performs path compression along the way to finding
579 the representative. */
582 find (unsigned int node
)
584 gcc_assert (node
< graph
->size
);
585 if (graph
->rep
[node
] != node
)
586 return graph
->rep
[node
] = find (graph
->rep
[node
]);
590 /* Union the TO and FROM nodes to the TO nodes.
591 Note that at some point in the future, we may want to do
592 union-by-rank, in which case we are going to have to return the
593 node we unified to. */
596 unite (unsigned int to
, unsigned int from
)
598 gcc_assert (to
< graph
->size
&& from
< graph
->size
);
599 if (to
!= from
&& graph
->rep
[from
] != to
)
601 graph
->rep
[from
] = to
;
607 /* Create a new constraint consisting of LHS and RHS expressions. */
610 new_constraint (const struct constraint_expr lhs
,
611 const struct constraint_expr rhs
)
613 constraint_t ret
= (constraint_t
) pool_alloc (constraint_pool
);
619 /* Print out constraint C to FILE. */
622 dump_constraint (FILE *file
, constraint_t c
)
624 if (c
->lhs
.type
== ADDRESSOF
)
626 else if (c
->lhs
.type
== DEREF
)
628 fprintf (file
, "%s", get_varinfo (c
->lhs
.var
)->name
);
629 if (c
->lhs
.offset
== UNKNOWN_OFFSET
)
630 fprintf (file
, " + UNKNOWN");
631 else if (c
->lhs
.offset
!= 0)
632 fprintf (file
, " + " HOST_WIDE_INT_PRINT_DEC
, c
->lhs
.offset
);
633 fprintf (file
, " = ");
634 if (c
->rhs
.type
== ADDRESSOF
)
636 else if (c
->rhs
.type
== DEREF
)
638 fprintf (file
, "%s", get_varinfo (c
->rhs
.var
)->name
);
639 if (c
->rhs
.offset
== UNKNOWN_OFFSET
)
640 fprintf (file
, " + UNKNOWN");
641 else if (c
->rhs
.offset
!= 0)
642 fprintf (file
, " + " HOST_WIDE_INT_PRINT_DEC
, c
->rhs
.offset
);
646 void debug_constraint (constraint_t
);
647 void debug_constraints (void);
648 void debug_constraint_graph (void);
649 void debug_solution_for_var (unsigned int);
650 void debug_sa_points_to_info (void);
652 /* Print out constraint C to stderr. */
655 debug_constraint (constraint_t c
)
657 dump_constraint (stderr
, c
);
658 fprintf (stderr
, "\n");
661 /* Print out all constraints to FILE */
664 dump_constraints (FILE *file
, int from
)
668 for (i
= from
; constraints
.iterate (i
, &c
); i
++)
671 dump_constraint (file
, c
);
672 fprintf (file
, "\n");
676 /* Print out all constraints to stderr. */
679 debug_constraints (void)
681 dump_constraints (stderr
, 0);
684 /* Print the constraint graph in dot format. */
687 dump_constraint_graph (FILE *file
)
691 /* Only print the graph if it has already been initialized: */
695 /* Prints the header of the dot file: */
696 fprintf (file
, "strict digraph {\n");
697 fprintf (file
, " node [\n shape = box\n ]\n");
698 fprintf (file
, " edge [\n fontsize = \"12\"\n ]\n");
699 fprintf (file
, "\n // List of nodes and complex constraints in "
700 "the constraint graph:\n");
702 /* The next lines print the nodes in the graph together with the
703 complex constraints attached to them. */
704 for (i
= 0; i
< graph
->size
; i
++)
708 if (i
< FIRST_REF_NODE
)
709 fprintf (file
, "\"%s\"", get_varinfo (i
)->name
);
711 fprintf (file
, "\"*%s\"", get_varinfo (i
- FIRST_REF_NODE
)->name
);
712 if (graph
->complex[i
].exists ())
716 fprintf (file
, " [label=\"\\N\\n");
717 for (j
= 0; graph
->complex[i
].iterate (j
, &c
); ++j
)
719 dump_constraint (file
, c
);
720 fprintf (file
, "\\l");
722 fprintf (file
, "\"]");
724 fprintf (file
, ";\n");
727 /* Go over the edges. */
728 fprintf (file
, "\n // Edges in the constraint graph:\n");
729 for (i
= 0; i
< graph
->size
; i
++)
735 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->succs
[i
], 0, j
, bi
)
737 unsigned to
= find (j
);
740 if (i
< FIRST_REF_NODE
)
741 fprintf (file
, "\"%s\"", get_varinfo (i
)->name
);
743 fprintf (file
, "\"*%s\"", get_varinfo (i
- FIRST_REF_NODE
)->name
);
744 fprintf (file
, " -> ");
745 if (to
< FIRST_REF_NODE
)
746 fprintf (file
, "\"%s\"", get_varinfo (to
)->name
);
748 fprintf (file
, "\"*%s\"", get_varinfo (to
- FIRST_REF_NODE
)->name
);
749 fprintf (file
, ";\n");
753 /* Prints the tail of the dot file. */
754 fprintf (file
, "}\n");
757 /* Print out the constraint graph to stderr. */
760 debug_constraint_graph (void)
762 dump_constraint_graph (stderr
);
767 The solver is a simple worklist solver, that works on the following
770 sbitmap changed_nodes = all zeroes;
772 For each node that is not already collapsed:
774 set bit in changed nodes
776 while (changed_count > 0)
778 compute topological ordering for constraint graph
780 find and collapse cycles in the constraint graph (updating
781 changed if necessary)
783 for each node (n) in the graph in topological order:
786 Process each complex constraint associated with the node,
787 updating changed if necessary.
789 For each outgoing edge from n, propagate the solution from n to
790 the destination of the edge, updating changed as necessary.
794 /* Return true if two constraint expressions A and B are equal. */
797 constraint_expr_equal (struct constraint_expr a
, struct constraint_expr b
)
799 return a
.type
== b
.type
&& a
.var
== b
.var
&& a
.offset
== b
.offset
;
802 /* Return true if constraint expression A is less than constraint expression
803 B. This is just arbitrary, but consistent, in order to give them an
807 constraint_expr_less (struct constraint_expr a
, struct constraint_expr b
)
809 if (a
.type
== b
.type
)
812 return a
.offset
< b
.offset
;
814 return a
.var
< b
.var
;
817 return a
.type
< b
.type
;
820 /* Return true if constraint A is less than constraint B. This is just
821 arbitrary, but consistent, in order to give them an ordering. */
824 constraint_less (const constraint_t
&a
, const constraint_t
&b
)
826 if (constraint_expr_less (a
->lhs
, b
->lhs
))
828 else if (constraint_expr_less (b
->lhs
, a
->lhs
))
831 return constraint_expr_less (a
->rhs
, b
->rhs
);
834 /* Return true if two constraints A and B are equal. */
837 constraint_equal (struct constraint a
, struct constraint b
)
839 return constraint_expr_equal (a
.lhs
, b
.lhs
)
840 && constraint_expr_equal (a
.rhs
, b
.rhs
);
844 /* Find a constraint LOOKFOR in the sorted constraint vector VEC */
847 constraint_vec_find (vec
<constraint_t
> vec
,
848 struct constraint lookfor
)
856 place
= vec
.lower_bound (&lookfor
, constraint_less
);
857 if (place
>= vec
.length ())
860 if (!constraint_equal (*found
, lookfor
))
865 /* Union two constraint vectors, TO and FROM. Put the result in TO. */
868 constraint_set_union (vec
<constraint_t
> *to
,
869 vec
<constraint_t
> *from
)
874 FOR_EACH_VEC_ELT (*from
, i
, c
)
876 if (constraint_vec_find (*to
, *c
) == NULL
)
878 unsigned int place
= to
->lower_bound (c
, constraint_less
);
879 to
->safe_insert (place
, c
);
884 /* Expands the solution in SET to all sub-fields of variables included.
885 Union the expanded result into RESULT. */
888 solution_set_expand (bitmap result
, bitmap set
)
894 /* In a first pass record all variables we need to add all
895 sub-fields off. This avoids quadratic behavior. */
896 EXECUTE_IF_SET_IN_BITMAP (set
, 0, j
, bi
)
898 varinfo_t v
= get_varinfo (j
);
899 if (v
->is_artificial_var
902 v
= lookup_vi_for_tree (v
->decl
);
904 vars
= BITMAP_ALLOC (NULL
);
905 bitmap_set_bit (vars
, v
->id
);
908 /* In the second pass now do the addition to the solution and
909 to speed up solving add it to the delta as well. */
912 EXECUTE_IF_SET_IN_BITMAP (vars
, 0, j
, bi
)
914 varinfo_t v
= get_varinfo (j
);
915 for (; v
!= NULL
; v
= v
->next
)
916 bitmap_set_bit (result
, v
->id
);
922 /* Take a solution set SET, add OFFSET to each member of the set, and
923 overwrite SET with the result when done. */
926 solution_set_add (bitmap set
, HOST_WIDE_INT offset
)
928 bitmap result
= BITMAP_ALLOC (&iteration_obstack
);
932 /* If the offset is unknown we have to expand the solution to
934 if (offset
== UNKNOWN_OFFSET
)
936 solution_set_expand (set
, set
);
940 EXECUTE_IF_SET_IN_BITMAP (set
, 0, i
, bi
)
942 varinfo_t vi
= get_varinfo (i
);
944 /* If this is a variable with just one field just set its bit
946 if (vi
->is_artificial_var
947 || vi
->is_unknown_size_var
949 bitmap_set_bit (result
, i
);
952 unsigned HOST_WIDE_INT fieldoffset
= vi
->offset
+ offset
;
954 /* If the offset makes the pointer point to before the
955 variable use offset zero for the field lookup. */
957 && fieldoffset
> vi
->offset
)
961 vi
= first_or_preceding_vi_for_offset (vi
, fieldoffset
);
963 bitmap_set_bit (result
, vi
->id
);
964 /* If the result is not exactly at fieldoffset include the next
965 field as well. See get_constraint_for_ptr_offset for more
967 if (vi
->offset
!= fieldoffset
969 bitmap_set_bit (result
, vi
->next
->id
);
973 bitmap_copy (set
, result
);
974 BITMAP_FREE (result
);
977 /* Union solution sets TO and FROM, and add INC to each member of FROM in the
981 set_union_with_increment (bitmap to
, bitmap from
, HOST_WIDE_INT inc
)
984 return bitmap_ior_into (to
, from
);
990 tmp
= BITMAP_ALLOC (&iteration_obstack
);
991 bitmap_copy (tmp
, from
);
992 solution_set_add (tmp
, inc
);
993 res
= bitmap_ior_into (to
, tmp
);
999 /* Insert constraint C into the list of complex constraints for graph
1003 insert_into_complex (constraint_graph_t graph
,
1004 unsigned int var
, constraint_t c
)
1006 vec
<constraint_t
> complex = graph
->complex[var
];
1007 unsigned int place
= complex.lower_bound (c
, constraint_less
);
1009 /* Only insert constraints that do not already exist. */
1010 if (place
>= complex.length ()
1011 || !constraint_equal (*c
, *complex[place
]))
1012 graph
->complex[var
].safe_insert (place
, c
);
1016 /* Condense two variable nodes into a single variable node, by moving
1017 all associated info from SRC to TO. */
1020 merge_node_constraints (constraint_graph_t graph
, unsigned int to
,
1026 gcc_assert (find (from
) == to
);
1028 /* Move all complex constraints from src node into to node */
1029 FOR_EACH_VEC_ELT (graph
->complex[from
], i
, c
)
1031 /* In complex constraints for node src, we may have either
1032 a = *src, and *src = a, or an offseted constraint which are
1033 always added to the rhs node's constraints. */
1035 if (c
->rhs
.type
== DEREF
)
1037 else if (c
->lhs
.type
== DEREF
)
1042 constraint_set_union (&graph
->complex[to
], &graph
->complex[from
]);
1043 graph
->complex[from
].release ();
1047 /* Remove edges involving NODE from GRAPH. */
1050 clear_edges_for_node (constraint_graph_t graph
, unsigned int node
)
1052 if (graph
->succs
[node
])
1053 BITMAP_FREE (graph
->succs
[node
]);
1056 /* Merge GRAPH nodes FROM and TO into node TO. */
1059 merge_graph_nodes (constraint_graph_t graph
, unsigned int to
,
1062 if (graph
->indirect_cycles
[from
] != -1)
1064 /* If we have indirect cycles with the from node, and we have
1065 none on the to node, the to node has indirect cycles from the
1066 from node now that they are unified.
1067 If indirect cycles exist on both, unify the nodes that they
1068 are in a cycle with, since we know they are in a cycle with
1070 if (graph
->indirect_cycles
[to
] == -1)
1071 graph
->indirect_cycles
[to
] = graph
->indirect_cycles
[from
];
1074 /* Merge all the successor edges. */
1075 if (graph
->succs
[from
])
1077 if (!graph
->succs
[to
])
1078 graph
->succs
[to
] = BITMAP_ALLOC (&pta_obstack
);
1079 bitmap_ior_into (graph
->succs
[to
],
1080 graph
->succs
[from
]);
1083 clear_edges_for_node (graph
, from
);
1087 /* Add an indirect graph edge to GRAPH, going from TO to FROM if
1088 it doesn't exist in the graph already. */
1091 add_implicit_graph_edge (constraint_graph_t graph
, unsigned int to
,
1097 if (!graph
->implicit_preds
[to
])
1098 graph
->implicit_preds
[to
] = BITMAP_ALLOC (&predbitmap_obstack
);
1100 if (bitmap_set_bit (graph
->implicit_preds
[to
], from
))
1101 stats
.num_implicit_edges
++;
1104 /* Add a predecessor graph edge to GRAPH, going from TO to FROM if
1105 it doesn't exist in the graph already.
1106 Return false if the edge already existed, true otherwise. */
1109 add_pred_graph_edge (constraint_graph_t graph
, unsigned int to
,
1112 if (!graph
->preds
[to
])
1113 graph
->preds
[to
] = BITMAP_ALLOC (&predbitmap_obstack
);
1114 bitmap_set_bit (graph
->preds
[to
], from
);
1117 /* Add a graph edge to GRAPH, going from FROM to TO if
1118 it doesn't exist in the graph already.
1119 Return false if the edge already existed, true otherwise. */
1122 add_graph_edge (constraint_graph_t graph
, unsigned int to
,
1133 if (!graph
->succs
[from
])
1134 graph
->succs
[from
] = BITMAP_ALLOC (&pta_obstack
);
1135 if (bitmap_set_bit (graph
->succs
[from
], to
))
1138 if (to
< FIRST_REF_NODE
&& from
< FIRST_REF_NODE
)
1146 /* Return true if {DEST.SRC} is an existing graph edge in GRAPH. */
1149 valid_graph_edge (constraint_graph_t graph
, unsigned int src
,
1152 return (graph
->succs
[dest
]
1153 && bitmap_bit_p (graph
->succs
[dest
], src
));
1156 /* Initialize the constraint graph structure to contain SIZE nodes. */
1159 init_graph (unsigned int size
)
1163 graph
= XCNEW (struct constraint_graph
);
1165 graph
->succs
= XCNEWVEC (bitmap
, graph
->size
);
1166 graph
->indirect_cycles
= XNEWVEC (int, graph
->size
);
1167 graph
->rep
= XNEWVEC (unsigned int, graph
->size
);
1168 /* ??? Macros do not support template types with multiple arguments,
1169 so we use a typedef to work around it. */
1170 typedef vec
<constraint_t
> vec_constraint_t_heap
;
1171 graph
->complex = XCNEWVEC (vec_constraint_t_heap
, size
);
1172 graph
->pe
= XCNEWVEC (unsigned int, graph
->size
);
1173 graph
->pe_rep
= XNEWVEC (int, graph
->size
);
1175 for (j
= 0; j
< graph
->size
; j
++)
1178 graph
->pe_rep
[j
] = -1;
1179 graph
->indirect_cycles
[j
] = -1;
1183 /* Build the constraint graph, adding only predecessor edges right now. */
1186 build_pred_graph (void)
1192 graph
->implicit_preds
= XCNEWVEC (bitmap
, graph
->size
);
1193 graph
->preds
= XCNEWVEC (bitmap
, graph
->size
);
1194 graph
->pointer_label
= XCNEWVEC (unsigned int, graph
->size
);
1195 graph
->loc_label
= XCNEWVEC (unsigned int, graph
->size
);
1196 graph
->pointed_by
= XCNEWVEC (bitmap
, graph
->size
);
1197 graph
->points_to
= XCNEWVEC (bitmap
, graph
->size
);
1198 graph
->eq_rep
= XNEWVEC (int, graph
->size
);
1199 graph
->direct_nodes
= sbitmap_alloc (graph
->size
);
1200 graph
->address_taken
= BITMAP_ALLOC (&predbitmap_obstack
);
1201 bitmap_clear (graph
->direct_nodes
);
1203 for (j
= 0; j
< FIRST_REF_NODE
; j
++)
1205 if (!get_varinfo (j
)->is_special_var
)
1206 bitmap_set_bit (graph
->direct_nodes
, j
);
1209 for (j
= 0; j
< graph
->size
; j
++)
1210 graph
->eq_rep
[j
] = -1;
1212 for (j
= 0; j
< varmap
.length (); j
++)
1213 graph
->indirect_cycles
[j
] = -1;
1215 FOR_EACH_VEC_ELT (constraints
, i
, c
)
1217 struct constraint_expr lhs
= c
->lhs
;
1218 struct constraint_expr rhs
= c
->rhs
;
1219 unsigned int lhsvar
= lhs
.var
;
1220 unsigned int rhsvar
= rhs
.var
;
1222 if (lhs
.type
== DEREF
)
1225 if (rhs
.offset
== 0 && lhs
.offset
== 0 && rhs
.type
== SCALAR
)
1226 add_pred_graph_edge (graph
, FIRST_REF_NODE
+ lhsvar
, rhsvar
);
1228 else if (rhs
.type
== DEREF
)
1231 if (rhs
.offset
== 0 && lhs
.offset
== 0 && lhs
.type
== SCALAR
)
1232 add_pred_graph_edge (graph
, lhsvar
, FIRST_REF_NODE
+ rhsvar
);
1234 bitmap_clear_bit (graph
->direct_nodes
, lhsvar
);
1236 else if (rhs
.type
== ADDRESSOF
)
1241 if (graph
->points_to
[lhsvar
] == NULL
)
1242 graph
->points_to
[lhsvar
] = BITMAP_ALLOC (&predbitmap_obstack
);
1243 bitmap_set_bit (graph
->points_to
[lhsvar
], rhsvar
);
1245 if (graph
->pointed_by
[rhsvar
] == NULL
)
1246 graph
->pointed_by
[rhsvar
] = BITMAP_ALLOC (&predbitmap_obstack
);
1247 bitmap_set_bit (graph
->pointed_by
[rhsvar
], lhsvar
);
1249 /* Implicitly, *x = y */
1250 add_implicit_graph_edge (graph
, FIRST_REF_NODE
+ lhsvar
, rhsvar
);
1252 /* All related variables are no longer direct nodes. */
1253 bitmap_clear_bit (graph
->direct_nodes
, rhsvar
);
1254 v
= get_varinfo (rhsvar
);
1255 if (!v
->is_full_var
)
1257 v
= lookup_vi_for_tree (v
->decl
);
1260 bitmap_clear_bit (graph
->direct_nodes
, v
->id
);
1265 bitmap_set_bit (graph
->address_taken
, rhsvar
);
1267 else if (lhsvar
> anything_id
1268 && lhsvar
!= rhsvar
&& lhs
.offset
== 0 && rhs
.offset
== 0)
1271 add_pred_graph_edge (graph
, lhsvar
, rhsvar
);
1272 /* Implicitly, *x = *y */
1273 add_implicit_graph_edge (graph
, FIRST_REF_NODE
+ lhsvar
,
1274 FIRST_REF_NODE
+ rhsvar
);
1276 else if (lhs
.offset
!= 0 || rhs
.offset
!= 0)
1278 if (rhs
.offset
!= 0)
1279 bitmap_clear_bit (graph
->direct_nodes
, lhs
.var
);
1280 else if (lhs
.offset
!= 0)
1281 bitmap_clear_bit (graph
->direct_nodes
, rhs
.var
);
1286 /* Build the constraint graph, adding successor edges. */
1289 build_succ_graph (void)
1294 FOR_EACH_VEC_ELT (constraints
, i
, c
)
1296 struct constraint_expr lhs
;
1297 struct constraint_expr rhs
;
1298 unsigned int lhsvar
;
1299 unsigned int rhsvar
;
1306 lhsvar
= find (lhs
.var
);
1307 rhsvar
= find (rhs
.var
);
1309 if (lhs
.type
== DEREF
)
1311 if (rhs
.offset
== 0 && lhs
.offset
== 0 && rhs
.type
== SCALAR
)
1312 add_graph_edge (graph
, FIRST_REF_NODE
+ lhsvar
, rhsvar
);
1314 else if (rhs
.type
== DEREF
)
1316 if (rhs
.offset
== 0 && lhs
.offset
== 0 && lhs
.type
== SCALAR
)
1317 add_graph_edge (graph
, lhsvar
, FIRST_REF_NODE
+ rhsvar
);
1319 else if (rhs
.type
== ADDRESSOF
)
1322 gcc_assert (find (rhs
.var
) == rhs
.var
);
1323 bitmap_set_bit (get_varinfo (lhsvar
)->solution
, rhsvar
);
1325 else if (lhsvar
> anything_id
1326 && lhsvar
!= rhsvar
&& lhs
.offset
== 0 && rhs
.offset
== 0)
1328 add_graph_edge (graph
, lhsvar
, rhsvar
);
1332 /* Add edges from STOREDANYTHING to all non-direct nodes that can
1333 receive pointers. */
1334 t
= find (storedanything_id
);
1335 for (i
= integer_id
+ 1; i
< FIRST_REF_NODE
; ++i
)
1337 if (!bitmap_bit_p (graph
->direct_nodes
, i
)
1338 && get_varinfo (i
)->may_have_pointers
)
1339 add_graph_edge (graph
, find (i
), t
);
1342 /* Everything stored to ANYTHING also potentially escapes. */
1343 add_graph_edge (graph
, find (escaped_id
), t
);
1347 /* Changed variables on the last iteration. */
1348 static bitmap changed
;
1350 /* Strongly Connected Component visitation info. */
1357 unsigned int *node_mapping
;
1359 vec
<unsigned> scc_stack
;
1363 /* Recursive routine to find strongly connected components in GRAPH.
1364 SI is the SCC info to store the information in, and N is the id of current
1365 graph node we are processing.
1367 This is Tarjan's strongly connected component finding algorithm, as
1368 modified by Nuutila to keep only non-root nodes on the stack.
1369 The algorithm can be found in "On finding the strongly connected
1370 connected components in a directed graph" by Esko Nuutila and Eljas
1371 Soisalon-Soininen, in Information Processing Letters volume 49,
1372 number 1, pages 9-14. */
1375 scc_visit (constraint_graph_t graph
, struct scc_info
*si
, unsigned int n
)
1379 unsigned int my_dfs
;
1381 bitmap_set_bit (si
->visited
, n
);
1382 si
->dfs
[n
] = si
->current_index
++;
1383 my_dfs
= si
->dfs
[n
];
1385 /* Visit all the successors. */
1386 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->succs
[n
], 0, i
, bi
)
1390 if (i
> LAST_REF_NODE
)
1394 if (bitmap_bit_p (si
->deleted
, w
))
1397 if (!bitmap_bit_p (si
->visited
, w
))
1398 scc_visit (graph
, si
, w
);
1400 unsigned int t
= find (w
);
1401 unsigned int nnode
= find (n
);
1402 gcc_assert (nnode
== n
);
1404 if (si
->dfs
[t
] < si
->dfs
[nnode
])
1405 si
->dfs
[n
] = si
->dfs
[t
];
1409 /* See if any components have been identified. */
1410 if (si
->dfs
[n
] == my_dfs
)
1412 if (si
->scc_stack
.length () > 0
1413 && si
->dfs
[si
->scc_stack
.last ()] >= my_dfs
)
1415 bitmap scc
= BITMAP_ALLOC (NULL
);
1416 unsigned int lowest_node
;
1419 bitmap_set_bit (scc
, n
);
1421 while (si
->scc_stack
.length () != 0
1422 && si
->dfs
[si
->scc_stack
.last ()] >= my_dfs
)
1424 unsigned int w
= si
->scc_stack
.pop ();
1426 bitmap_set_bit (scc
, w
);
1429 lowest_node
= bitmap_first_set_bit (scc
);
1430 gcc_assert (lowest_node
< FIRST_REF_NODE
);
1432 /* Collapse the SCC nodes into a single node, and mark the
1434 EXECUTE_IF_SET_IN_BITMAP (scc
, 0, i
, bi
)
1436 if (i
< FIRST_REF_NODE
)
1438 if (unite (lowest_node
, i
))
1439 unify_nodes (graph
, lowest_node
, i
, false);
1443 unite (lowest_node
, i
);
1444 graph
->indirect_cycles
[i
- FIRST_REF_NODE
] = lowest_node
;
1448 bitmap_set_bit (si
->deleted
, n
);
1451 si
->scc_stack
.safe_push (n
);
1454 /* Unify node FROM into node TO, updating the changed count if
1455 necessary when UPDATE_CHANGED is true. */
1458 unify_nodes (constraint_graph_t graph
, unsigned int to
, unsigned int from
,
1459 bool update_changed
)
1462 gcc_assert (to
!= from
&& find (to
) == to
);
1463 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1464 fprintf (dump_file
, "Unifying %s to %s\n",
1465 get_varinfo (from
)->name
,
1466 get_varinfo (to
)->name
);
1469 stats
.unified_vars_dynamic
++;
1471 stats
.unified_vars_static
++;
1473 merge_graph_nodes (graph
, to
, from
);
1474 merge_node_constraints (graph
, to
, from
);
1476 /* Mark TO as changed if FROM was changed. If TO was already marked
1477 as changed, decrease the changed count. */
1480 && bitmap_bit_p (changed
, from
))
1482 bitmap_clear_bit (changed
, from
);
1483 bitmap_set_bit (changed
, to
);
1485 if (get_varinfo (from
)->solution
)
1487 /* If the solution changes because of the merging, we need to mark
1488 the variable as changed. */
1489 if (bitmap_ior_into (get_varinfo (to
)->solution
,
1490 get_varinfo (from
)->solution
))
1493 bitmap_set_bit (changed
, to
);
1496 BITMAP_FREE (get_varinfo (from
)->solution
);
1497 if (get_varinfo (from
)->oldsolution
)
1498 BITMAP_FREE (get_varinfo (from
)->oldsolution
);
1500 if (stats
.iterations
> 0
1501 && get_varinfo (to
)->oldsolution
)
1502 BITMAP_FREE (get_varinfo (to
)->oldsolution
);
1504 if (valid_graph_edge (graph
, to
, to
))
1506 if (graph
->succs
[to
])
1507 bitmap_clear_bit (graph
->succs
[to
], to
);
1511 /* Information needed to compute the topological ordering of a graph. */
1515 /* sbitmap of visited nodes. */
1517 /* Array that stores the topological order of the graph, *in
1519 vec
<unsigned> topo_order
;
1523 /* Initialize and return a topological info structure. */
1525 static struct topo_info
*
1526 init_topo_info (void)
1528 size_t size
= graph
->size
;
1529 struct topo_info
*ti
= XNEW (struct topo_info
);
1530 ti
->visited
= sbitmap_alloc (size
);
1531 bitmap_clear (ti
->visited
);
1532 ti
->topo_order
.create (1);
1537 /* Free the topological sort info pointed to by TI. */
1540 free_topo_info (struct topo_info
*ti
)
1542 sbitmap_free (ti
->visited
);
1543 ti
->topo_order
.release ();
1547 /* Visit the graph in topological order, and store the order in the
1548 topo_info structure. */
1551 topo_visit (constraint_graph_t graph
, struct topo_info
*ti
,
1557 bitmap_set_bit (ti
->visited
, n
);
1559 if (graph
->succs
[n
])
1560 EXECUTE_IF_SET_IN_BITMAP (graph
->succs
[n
], 0, j
, bi
)
1562 if (!bitmap_bit_p (ti
->visited
, j
))
1563 topo_visit (graph
, ti
, j
);
1566 ti
->topo_order
.safe_push (n
);
1569 /* Process a constraint C that represents x = *(y + off), using DELTA as the
1570 starting solution for y. */
1573 do_sd_constraint (constraint_graph_t graph
, constraint_t c
,
1576 unsigned int lhs
= c
->lhs
.var
;
1578 bitmap sol
= get_varinfo (lhs
)->solution
;
1581 HOST_WIDE_INT roffset
= c
->rhs
.offset
;
1583 /* Our IL does not allow this. */
1584 gcc_assert (c
->lhs
.offset
== 0);
1586 /* If the solution of Y contains anything it is good enough to transfer
1588 if (bitmap_bit_p (delta
, anything_id
))
1590 flag
|= bitmap_set_bit (sol
, anything_id
);
1594 /* If we do not know at with offset the rhs is dereferenced compute
1595 the reachability set of DELTA, conservatively assuming it is
1596 dereferenced at all valid offsets. */
1597 if (roffset
== UNKNOWN_OFFSET
)
1599 solution_set_expand (delta
, delta
);
1600 /* No further offset processing is necessary. */
1604 /* For each variable j in delta (Sol(y)), add
1605 an edge in the graph from j to x, and union Sol(j) into Sol(x). */
1606 EXECUTE_IF_SET_IN_BITMAP (delta
, 0, j
, bi
)
1608 varinfo_t v
= get_varinfo (j
);
1609 HOST_WIDE_INT fieldoffset
= v
->offset
+ roffset
;
1613 fieldoffset
= v
->offset
;
1614 else if (roffset
!= 0)
1615 v
= first_vi_for_offset (v
, fieldoffset
);
1616 /* If the access is outside of the variable we can ignore it. */
1624 /* Adding edges from the special vars is pointless.
1625 They don't have sets that can change. */
1626 if (get_varinfo (t
)->is_special_var
)
1627 flag
|= bitmap_ior_into (sol
, get_varinfo (t
)->solution
);
1628 /* Merging the solution from ESCAPED needlessly increases
1629 the set. Use ESCAPED as representative instead. */
1630 else if (v
->id
== escaped_id
)
1631 flag
|= bitmap_set_bit (sol
, escaped_id
);
1632 else if (v
->may_have_pointers
1633 && add_graph_edge (graph
, lhs
, t
))
1634 flag
|= bitmap_ior_into (sol
, get_varinfo (t
)->solution
);
1636 /* If the variable is not exactly at the requested offset
1637 we have to include the next one. */
1638 if (v
->offset
== (unsigned HOST_WIDE_INT
)fieldoffset
1643 fieldoffset
= v
->offset
;
1649 /* If the LHS solution changed, mark the var as changed. */
1652 get_varinfo (lhs
)->solution
= sol
;
1653 bitmap_set_bit (changed
, lhs
);
1657 /* Process a constraint C that represents *(x + off) = y using DELTA
1658 as the starting solution for x. */
1661 do_ds_constraint (constraint_t c
, bitmap delta
)
1663 unsigned int rhs
= c
->rhs
.var
;
1664 bitmap sol
= get_varinfo (rhs
)->solution
;
1667 HOST_WIDE_INT loff
= c
->lhs
.offset
;
1668 bool escaped_p
= false;
1670 /* Our IL does not allow this. */
1671 gcc_assert (c
->rhs
.offset
== 0);
1673 /* If the solution of y contains ANYTHING simply use the ANYTHING
1674 solution. This avoids needlessly increasing the points-to sets. */
1675 if (bitmap_bit_p (sol
, anything_id
))
1676 sol
= get_varinfo (find (anything_id
))->solution
;
1678 /* If the solution for x contains ANYTHING we have to merge the
1679 solution of y into all pointer variables which we do via
1681 if (bitmap_bit_p (delta
, anything_id
))
1683 unsigned t
= find (storedanything_id
);
1684 if (add_graph_edge (graph
, t
, rhs
))
1686 if (bitmap_ior_into (get_varinfo (t
)->solution
, sol
))
1687 bitmap_set_bit (changed
, t
);
1692 /* If we do not know at with offset the rhs is dereferenced compute
1693 the reachability set of DELTA, conservatively assuming it is
1694 dereferenced at all valid offsets. */
1695 if (loff
== UNKNOWN_OFFSET
)
1697 solution_set_expand (delta
, delta
);
1701 /* For each member j of delta (Sol(x)), add an edge from y to j and
1702 union Sol(y) into Sol(j) */
1703 EXECUTE_IF_SET_IN_BITMAP (delta
, 0, j
, bi
)
1705 varinfo_t v
= get_varinfo (j
);
1707 HOST_WIDE_INT fieldoffset
= v
->offset
+ loff
;
1710 fieldoffset
= v
->offset
;
1712 v
= first_vi_for_offset (v
, fieldoffset
);
1713 /* If the access is outside of the variable we can ignore it. */
1719 if (v
->may_have_pointers
)
1721 /* If v is a global variable then this is an escape point. */
1722 if (v
->is_global_var
1725 t
= find (escaped_id
);
1726 if (add_graph_edge (graph
, t
, rhs
)
1727 && bitmap_ior_into (get_varinfo (t
)->solution
, sol
))
1728 bitmap_set_bit (changed
, t
);
1729 /* Enough to let rhs escape once. */
1733 if (v
->is_special_var
)
1737 if (add_graph_edge (graph
, t
, rhs
)
1738 && bitmap_ior_into (get_varinfo (t
)->solution
, sol
))
1739 bitmap_set_bit (changed
, t
);
1742 /* If the variable is not exactly at the requested offset
1743 we have to include the next one. */
1744 if (v
->offset
== (unsigned HOST_WIDE_INT
)fieldoffset
1749 fieldoffset
= v
->offset
;
1755 /* Handle a non-simple (simple meaning requires no iteration),
1756 constraint (IE *x = &y, x = *y, *x = y, and x = y with offsets involved). */
1759 do_complex_constraint (constraint_graph_t graph
, constraint_t c
, bitmap delta
)
1761 if (c
->lhs
.type
== DEREF
)
1763 if (c
->rhs
.type
== ADDRESSOF
)
1770 do_ds_constraint (c
, delta
);
1773 else if (c
->rhs
.type
== DEREF
)
1776 if (!(get_varinfo (c
->lhs
.var
)->is_special_var
))
1777 do_sd_constraint (graph
, c
, delta
);
1785 gcc_assert (c
->rhs
.type
== SCALAR
&& c
->lhs
.type
== SCALAR
);
1786 solution
= get_varinfo (c
->rhs
.var
)->solution
;
1787 tmp
= get_varinfo (c
->lhs
.var
)->solution
;
1789 flag
= set_union_with_increment (tmp
, solution
, c
->rhs
.offset
);
1793 get_varinfo (c
->lhs
.var
)->solution
= tmp
;
1794 bitmap_set_bit (changed
, c
->lhs
.var
);
1799 /* Initialize and return a new SCC info structure. */
1801 static struct scc_info
*
1802 init_scc_info (size_t size
)
1804 struct scc_info
*si
= XNEW (struct scc_info
);
1807 si
->current_index
= 0;
1808 si
->visited
= sbitmap_alloc (size
);
1809 bitmap_clear (si
->visited
);
1810 si
->deleted
= sbitmap_alloc (size
);
1811 bitmap_clear (si
->deleted
);
1812 si
->node_mapping
= XNEWVEC (unsigned int, size
);
1813 si
->dfs
= XCNEWVEC (unsigned int, size
);
1815 for (i
= 0; i
< size
; i
++)
1816 si
->node_mapping
[i
] = i
;
1818 si
->scc_stack
.create (1);
1822 /* Free an SCC info structure pointed to by SI */
1825 free_scc_info (struct scc_info
*si
)
1827 sbitmap_free (si
->visited
);
1828 sbitmap_free (si
->deleted
);
1829 free (si
->node_mapping
);
1831 si
->scc_stack
.release ();
1836 /* Find indirect cycles in GRAPH that occur, using strongly connected
1837 components, and note them in the indirect cycles map.
1839 This technique comes from Ben Hardekopf and Calvin Lin,
1840 "It Pays to be Lazy: Fast and Accurate Pointer Analysis for Millions of
1841 Lines of Code", submitted to PLDI 2007. */
1844 find_indirect_cycles (constraint_graph_t graph
)
1847 unsigned int size
= graph
->size
;
1848 struct scc_info
*si
= init_scc_info (size
);
1850 for (i
= 0; i
< MIN (LAST_REF_NODE
, size
); i
++ )
1851 if (!bitmap_bit_p (si
->visited
, i
) && find (i
) == i
)
1852 scc_visit (graph
, si
, i
);
1857 /* Compute a topological ordering for GRAPH, and store the result in the
1858 topo_info structure TI. */
1861 compute_topo_order (constraint_graph_t graph
,
1862 struct topo_info
*ti
)
1865 unsigned int size
= graph
->size
;
1867 for (i
= 0; i
!= size
; ++i
)
1868 if (!bitmap_bit_p (ti
->visited
, i
) && find (i
) == i
)
1869 topo_visit (graph
, ti
, i
);
1872 /* Structure used to for hash value numbering of pointer equivalence
1875 typedef struct equiv_class_label
1878 unsigned int equivalence_class
;
1880 } *equiv_class_label_t
;
1881 typedef const struct equiv_class_label
*const_equiv_class_label_t
;
1883 /* A hashtable for mapping a bitmap of labels->pointer equivalence
1885 static htab_t pointer_equiv_class_table
;
1887 /* A hashtable for mapping a bitmap of labels->location equivalence
1889 static htab_t location_equiv_class_table
;
1891 /* Hash function for a equiv_class_label_t */
1894 equiv_class_label_hash (const void *p
)
1896 const_equiv_class_label_t
const ecl
= (const_equiv_class_label_t
) p
;
1897 return ecl
->hashcode
;
1900 /* Equality function for two equiv_class_label_t's. */
1903 equiv_class_label_eq (const void *p1
, const void *p2
)
1905 const_equiv_class_label_t
const eql1
= (const_equiv_class_label_t
) p1
;
1906 const_equiv_class_label_t
const eql2
= (const_equiv_class_label_t
) p2
;
1907 return (eql1
->hashcode
== eql2
->hashcode
1908 && bitmap_equal_p (eql1
->labels
, eql2
->labels
));
1911 /* Lookup a equivalence class in TABLE by the bitmap of LABELS with
1912 hash HAS it contains. Sets *REF_LABELS to the bitmap LABELS
1913 is equivalent to. */
1915 static equiv_class_label
*
1916 equiv_class_lookup_or_add (htab_t table
, bitmap labels
)
1918 equiv_class_label
**slot
;
1919 equiv_class_label ecl
;
1921 ecl
.labels
= labels
;
1922 ecl
.hashcode
= bitmap_hash (labels
);
1923 slot
= (equiv_class_label
**) htab_find_slot_with_hash (table
, &ecl
,
1924 ecl
.hashcode
, INSERT
);
1927 *slot
= XNEW (struct equiv_class_label
);
1928 (*slot
)->labels
= labels
;
1929 (*slot
)->hashcode
= ecl
.hashcode
;
1930 (*slot
)->equivalence_class
= 0;
1936 /* Perform offline variable substitution.
1938 This is a worst case quadratic time way of identifying variables
1939 that must have equivalent points-to sets, including those caused by
1940 static cycles, and single entry subgraphs, in the constraint graph.
1942 The technique is described in "Exploiting Pointer and Location
1943 Equivalence to Optimize Pointer Analysis. In the 14th International
1944 Static Analysis Symposium (SAS), August 2007." It is known as the
1945 "HU" algorithm, and is equivalent to value numbering the collapsed
1946 constraint graph including evaluating unions.
1948 The general method of finding equivalence classes is as follows:
1949 Add fake nodes (REF nodes) and edges for *a = b and a = *b constraints.
1950 Initialize all non-REF nodes to be direct nodes.
1951 For each constraint a = a U {b}, we set pts(a) = pts(a) u {fresh
1953 For each constraint containing the dereference, we also do the same
1956 We then compute SCC's in the graph and unify nodes in the same SCC,
1959 For each non-collapsed node x:
1960 Visit all unvisited explicit incoming edges.
1961 Ignoring all non-pointers, set pts(x) = Union of pts(a) for y
1963 Lookup the equivalence class for pts(x).
1964 If we found one, equivalence_class(x) = found class.
1965 Otherwise, equivalence_class(x) = new class, and new_class is
1966 added to the lookup table.
1968 All direct nodes with the same equivalence class can be replaced
1969 with a single representative node.
1970 All unlabeled nodes (label == 0) are not pointers and all edges
1971 involving them can be eliminated.
1972 We perform these optimizations during rewrite_constraints
1974 In addition to pointer equivalence class finding, we also perform
1975 location equivalence class finding. This is the set of variables
1976 that always appear together in points-to sets. We use this to
1977 compress the size of the points-to sets. */
1979 /* Current maximum pointer equivalence class id. */
1980 static int pointer_equiv_class
;
1982 /* Current maximum location equivalence class id. */
1983 static int location_equiv_class
;
1985 /* Recursive routine to find strongly connected components in GRAPH,
1986 and label it's nodes with DFS numbers. */
1989 condense_visit (constraint_graph_t graph
, struct scc_info
*si
, unsigned int n
)
1993 unsigned int my_dfs
;
1995 gcc_assert (si
->node_mapping
[n
] == n
);
1996 bitmap_set_bit (si
->visited
, n
);
1997 si
->dfs
[n
] = si
->current_index
++;
1998 my_dfs
= si
->dfs
[n
];
2000 /* Visit all the successors. */
2001 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->preds
[n
], 0, i
, bi
)
2003 unsigned int w
= si
->node_mapping
[i
];
2005 if (bitmap_bit_p (si
->deleted
, w
))
2008 if (!bitmap_bit_p (si
->visited
, w
))
2009 condense_visit (graph
, si
, w
);
2011 unsigned int t
= si
->node_mapping
[w
];
2012 unsigned int nnode
= si
->node_mapping
[n
];
2013 gcc_assert (nnode
== n
);
2015 if (si
->dfs
[t
] < si
->dfs
[nnode
])
2016 si
->dfs
[n
] = si
->dfs
[t
];
2020 /* Visit all the implicit predecessors. */
2021 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->implicit_preds
[n
], 0, i
, bi
)
2023 unsigned int w
= si
->node_mapping
[i
];
2025 if (bitmap_bit_p (si
->deleted
, w
))
2028 if (!bitmap_bit_p (si
->visited
, w
))
2029 condense_visit (graph
, si
, w
);
2031 unsigned int t
= si
->node_mapping
[w
];
2032 unsigned int nnode
= si
->node_mapping
[n
];
2033 gcc_assert (nnode
== n
);
2035 if (si
->dfs
[t
] < si
->dfs
[nnode
])
2036 si
->dfs
[n
] = si
->dfs
[t
];
2040 /* See if any components have been identified. */
2041 if (si
->dfs
[n
] == my_dfs
)
2043 while (si
->scc_stack
.length () != 0
2044 && si
->dfs
[si
->scc_stack
.last ()] >= my_dfs
)
2046 unsigned int w
= si
->scc_stack
.pop ();
2047 si
->node_mapping
[w
] = n
;
2049 if (!bitmap_bit_p (graph
->direct_nodes
, w
))
2050 bitmap_clear_bit (graph
->direct_nodes
, n
);
2052 /* Unify our nodes. */
2053 if (graph
->preds
[w
])
2055 if (!graph
->preds
[n
])
2056 graph
->preds
[n
] = BITMAP_ALLOC (&predbitmap_obstack
);
2057 bitmap_ior_into (graph
->preds
[n
], graph
->preds
[w
]);
2059 if (graph
->implicit_preds
[w
])
2061 if (!graph
->implicit_preds
[n
])
2062 graph
->implicit_preds
[n
] = BITMAP_ALLOC (&predbitmap_obstack
);
2063 bitmap_ior_into (graph
->implicit_preds
[n
],
2064 graph
->implicit_preds
[w
]);
2066 if (graph
->points_to
[w
])
2068 if (!graph
->points_to
[n
])
2069 graph
->points_to
[n
] = BITMAP_ALLOC (&predbitmap_obstack
);
2070 bitmap_ior_into (graph
->points_to
[n
],
2071 graph
->points_to
[w
]);
2074 bitmap_set_bit (si
->deleted
, n
);
2077 si
->scc_stack
.safe_push (n
);
2080 /* Label pointer equivalences. */
2083 label_visit (constraint_graph_t graph
, struct scc_info
*si
, unsigned int n
)
2085 unsigned int i
, first_pred
;
2088 bitmap_set_bit (si
->visited
, n
);
2090 /* Label and union our incoming edges's points to sets. */
2092 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->preds
[n
], 0, i
, bi
)
2094 unsigned int w
= si
->node_mapping
[i
];
2095 if (!bitmap_bit_p (si
->visited
, w
))
2096 label_visit (graph
, si
, w
);
2098 /* Skip unused edges */
2099 if (w
== n
|| graph
->pointer_label
[w
] == 0)
2102 if (graph
->points_to
[w
])
2104 if (!graph
->points_to
[n
])
2106 if (first_pred
== -1U)
2110 graph
->points_to
[n
] = BITMAP_ALLOC (&predbitmap_obstack
);
2111 bitmap_ior (graph
->points_to
[n
],
2112 graph
->points_to
[first_pred
],
2113 graph
->points_to
[w
]);
2117 bitmap_ior_into(graph
->points_to
[n
], graph
->points_to
[w
]);
2121 /* Indirect nodes get fresh variables and a new pointer equiv class. */
2122 if (!bitmap_bit_p (graph
->direct_nodes
, n
))
2124 if (!graph
->points_to
[n
])
2126 graph
->points_to
[n
] = BITMAP_ALLOC (&predbitmap_obstack
);
2127 if (first_pred
!= -1U)
2128 bitmap_copy (graph
->points_to
[n
], graph
->points_to
[first_pred
]);
2130 bitmap_set_bit (graph
->points_to
[n
], FIRST_REF_NODE
+ n
);
2131 graph
->pointer_label
[n
] = pointer_equiv_class
++;
2132 equiv_class_label_t ecl
;
2133 ecl
= equiv_class_lookup_or_add (pointer_equiv_class_table
,
2134 graph
->points_to
[n
]);
2135 ecl
->equivalence_class
= graph
->pointer_label
[n
];
2139 /* If there was only a single non-empty predecessor the pointer equiv
2140 class is the same. */
2141 if (!graph
->points_to
[n
])
2143 if (first_pred
!= -1U)
2145 graph
->pointer_label
[n
] = graph
->pointer_label
[first_pred
];
2146 graph
->points_to
[n
] = graph
->points_to
[first_pred
];
2151 if (!bitmap_empty_p (graph
->points_to
[n
]))
2153 equiv_class_label_t ecl
;
2154 ecl
= equiv_class_lookup_or_add (pointer_equiv_class_table
,
2155 graph
->points_to
[n
]);
2156 if (ecl
->equivalence_class
== 0)
2157 ecl
->equivalence_class
= pointer_equiv_class
++;
2160 BITMAP_FREE (graph
->points_to
[n
]);
2161 graph
->points_to
[n
] = ecl
->labels
;
2163 graph
->pointer_label
[n
] = ecl
->equivalence_class
;
2167 /* Perform offline variable substitution, discovering equivalence
2168 classes, and eliminating non-pointer variables. */
2170 static struct scc_info
*
2171 perform_var_substitution (constraint_graph_t graph
)
2174 unsigned int size
= graph
->size
;
2175 struct scc_info
*si
= init_scc_info (size
);
2177 bitmap_obstack_initialize (&iteration_obstack
);
2178 pointer_equiv_class_table
= htab_create (511, equiv_class_label_hash
,
2179 equiv_class_label_eq
, free
);
2180 location_equiv_class_table
= htab_create (511, equiv_class_label_hash
,
2181 equiv_class_label_eq
, free
);
2182 pointer_equiv_class
= 1;
2183 location_equiv_class
= 1;
2185 /* Condense the nodes, which means to find SCC's, count incoming
2186 predecessors, and unite nodes in SCC's. */
2187 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2188 if (!bitmap_bit_p (si
->visited
, si
->node_mapping
[i
]))
2189 condense_visit (graph
, si
, si
->node_mapping
[i
]);
2191 bitmap_clear (si
->visited
);
2192 /* Actually the label the nodes for pointer equivalences */
2193 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2194 if (!bitmap_bit_p (si
->visited
, si
->node_mapping
[i
]))
2195 label_visit (graph
, si
, si
->node_mapping
[i
]);
2197 /* Calculate location equivalence labels. */
2198 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2204 if (!graph
->pointed_by
[i
])
2206 pointed_by
= BITMAP_ALLOC (&iteration_obstack
);
2208 /* Translate the pointed-by mapping for pointer equivalence
2210 EXECUTE_IF_SET_IN_BITMAP (graph
->pointed_by
[i
], 0, j
, bi
)
2212 bitmap_set_bit (pointed_by
,
2213 graph
->pointer_label
[si
->node_mapping
[j
]]);
2215 /* The original pointed_by is now dead. */
2216 BITMAP_FREE (graph
->pointed_by
[i
]);
2218 /* Look up the location equivalence label if one exists, or make
2220 equiv_class_label_t ecl
;
2221 ecl
= equiv_class_lookup_or_add (location_equiv_class_table
, pointed_by
);
2222 if (ecl
->equivalence_class
== 0)
2223 ecl
->equivalence_class
= location_equiv_class
++;
2226 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2227 fprintf (dump_file
, "Found location equivalence for node %s\n",
2228 get_varinfo (i
)->name
);
2229 BITMAP_FREE (pointed_by
);
2231 graph
->loc_label
[i
] = ecl
->equivalence_class
;
2235 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2236 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2238 unsigned j
= si
->node_mapping
[i
];
2241 fprintf (dump_file
, "%s node id %d ",
2242 bitmap_bit_p (graph
->direct_nodes
, i
)
2243 ? "Direct" : "Indirect", i
);
2244 if (i
< FIRST_REF_NODE
)
2245 fprintf (dump_file
, "\"%s\"", get_varinfo (i
)->name
);
2247 fprintf (dump_file
, "\"*%s\"",
2248 get_varinfo (i
- FIRST_REF_NODE
)->name
);
2249 fprintf (dump_file
, " mapped to SCC leader node id %d ", j
);
2250 if (j
< FIRST_REF_NODE
)
2251 fprintf (dump_file
, "\"%s\"\n", get_varinfo (j
)->name
);
2253 fprintf (dump_file
, "\"*%s\"\n",
2254 get_varinfo (j
- FIRST_REF_NODE
)->name
);
2259 "Equivalence classes for %s node id %d ",
2260 bitmap_bit_p (graph
->direct_nodes
, i
)
2261 ? "direct" : "indirect", i
);
2262 if (i
< FIRST_REF_NODE
)
2263 fprintf (dump_file
, "\"%s\"", get_varinfo (i
)->name
);
2265 fprintf (dump_file
, "\"*%s\"",
2266 get_varinfo (i
- FIRST_REF_NODE
)->name
);
2268 ": pointer %d, location %d\n",
2269 graph
->pointer_label
[i
], graph
->loc_label
[i
]);
2273 /* Quickly eliminate our non-pointer variables. */
2275 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2277 unsigned int node
= si
->node_mapping
[i
];
2279 if (graph
->pointer_label
[node
] == 0)
2281 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2283 "%s is a non-pointer variable, eliminating edges.\n",
2284 get_varinfo (node
)->name
);
2285 stats
.nonpointer_vars
++;
2286 clear_edges_for_node (graph
, node
);
2293 /* Free information that was only necessary for variable
2297 free_var_substitution_info (struct scc_info
*si
)
2300 free (graph
->pointer_label
);
2301 free (graph
->loc_label
);
2302 free (graph
->pointed_by
);
2303 free (graph
->points_to
);
2304 free (graph
->eq_rep
);
2305 sbitmap_free (graph
->direct_nodes
);
2306 htab_delete (pointer_equiv_class_table
);
2307 htab_delete (location_equiv_class_table
);
2308 bitmap_obstack_release (&iteration_obstack
);
2311 /* Return an existing node that is equivalent to NODE, which has
2312 equivalence class LABEL, if one exists. Return NODE otherwise. */
2315 find_equivalent_node (constraint_graph_t graph
,
2316 unsigned int node
, unsigned int label
)
2318 /* If the address version of this variable is unused, we can
2319 substitute it for anything else with the same label.
2320 Otherwise, we know the pointers are equivalent, but not the
2321 locations, and we can unite them later. */
2323 if (!bitmap_bit_p (graph
->address_taken
, node
))
2325 gcc_assert (label
< graph
->size
);
2327 if (graph
->eq_rep
[label
] != -1)
2329 /* Unify the two variables since we know they are equivalent. */
2330 if (unite (graph
->eq_rep
[label
], node
))
2331 unify_nodes (graph
, graph
->eq_rep
[label
], node
, false);
2332 return graph
->eq_rep
[label
];
2336 graph
->eq_rep
[label
] = node
;
2337 graph
->pe_rep
[label
] = node
;
2342 gcc_assert (label
< graph
->size
);
2343 graph
->pe
[node
] = label
;
2344 if (graph
->pe_rep
[label
] == -1)
2345 graph
->pe_rep
[label
] = node
;
2351 /* Unite pointer equivalent but not location equivalent nodes in
2352 GRAPH. This may only be performed once variable substitution is
2356 unite_pointer_equivalences (constraint_graph_t graph
)
2360 /* Go through the pointer equivalences and unite them to their
2361 representative, if they aren't already. */
2362 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
2364 unsigned int label
= graph
->pe
[i
];
2367 int label_rep
= graph
->pe_rep
[label
];
2369 if (label_rep
== -1)
2372 label_rep
= find (label_rep
);
2373 if (label_rep
>= 0 && unite (label_rep
, find (i
)))
2374 unify_nodes (graph
, label_rep
, i
, false);
2379 /* Move complex constraints to the GRAPH nodes they belong to. */
2382 move_complex_constraints (constraint_graph_t graph
)
2387 FOR_EACH_VEC_ELT (constraints
, i
, c
)
2391 struct constraint_expr lhs
= c
->lhs
;
2392 struct constraint_expr rhs
= c
->rhs
;
2394 if (lhs
.type
== DEREF
)
2396 insert_into_complex (graph
, lhs
.var
, c
);
2398 else if (rhs
.type
== DEREF
)
2400 if (!(get_varinfo (lhs
.var
)->is_special_var
))
2401 insert_into_complex (graph
, rhs
.var
, c
);
2403 else if (rhs
.type
!= ADDRESSOF
&& lhs
.var
> anything_id
2404 && (lhs
.offset
!= 0 || rhs
.offset
!= 0))
2406 insert_into_complex (graph
, rhs
.var
, c
);
2413 /* Optimize and rewrite complex constraints while performing
2414 collapsing of equivalent nodes. SI is the SCC_INFO that is the
2415 result of perform_variable_substitution. */
2418 rewrite_constraints (constraint_graph_t graph
,
2419 struct scc_info
*si
)
2425 for (j
= 0; j
< graph
->size
; j
++)
2426 gcc_assert (find (j
) == j
);
2428 FOR_EACH_VEC_ELT (constraints
, i
, c
)
2430 struct constraint_expr lhs
= c
->lhs
;
2431 struct constraint_expr rhs
= c
->rhs
;
2432 unsigned int lhsvar
= find (lhs
.var
);
2433 unsigned int rhsvar
= find (rhs
.var
);
2434 unsigned int lhsnode
, rhsnode
;
2435 unsigned int lhslabel
, rhslabel
;
2437 lhsnode
= si
->node_mapping
[lhsvar
];
2438 rhsnode
= si
->node_mapping
[rhsvar
];
2439 lhslabel
= graph
->pointer_label
[lhsnode
];
2440 rhslabel
= graph
->pointer_label
[rhsnode
];
2442 /* See if it is really a non-pointer variable, and if so, ignore
2446 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2449 fprintf (dump_file
, "%s is a non-pointer variable,"
2450 "ignoring constraint:",
2451 get_varinfo (lhs
.var
)->name
);
2452 dump_constraint (dump_file
, c
);
2453 fprintf (dump_file
, "\n");
2455 constraints
[i
] = NULL
;
2461 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2464 fprintf (dump_file
, "%s is a non-pointer variable,"
2465 "ignoring constraint:",
2466 get_varinfo (rhs
.var
)->name
);
2467 dump_constraint (dump_file
, c
);
2468 fprintf (dump_file
, "\n");
2470 constraints
[i
] = NULL
;
2474 lhsvar
= find_equivalent_node (graph
, lhsvar
, lhslabel
);
2475 rhsvar
= find_equivalent_node (graph
, rhsvar
, rhslabel
);
2476 c
->lhs
.var
= lhsvar
;
2477 c
->rhs
.var
= rhsvar
;
2482 /* Eliminate indirect cycles involving NODE. Return true if NODE was
2483 part of an SCC, false otherwise. */
2486 eliminate_indirect_cycles (unsigned int node
)
2488 if (graph
->indirect_cycles
[node
] != -1
2489 && !bitmap_empty_p (get_varinfo (node
)->solution
))
2492 vec
<unsigned> queue
= vNULL
;
2494 unsigned int to
= find (graph
->indirect_cycles
[node
]);
2497 /* We can't touch the solution set and call unify_nodes
2498 at the same time, because unify_nodes is going to do
2499 bitmap unions into it. */
2501 EXECUTE_IF_SET_IN_BITMAP (get_varinfo (node
)->solution
, 0, i
, bi
)
2503 if (find (i
) == i
&& i
!= to
)
2506 queue
.safe_push (i
);
2511 queue
.iterate (queuepos
, &i
);
2514 unify_nodes (graph
, to
, i
, true);
2522 /* Solve the constraint graph GRAPH using our worklist solver.
2523 This is based on the PW* family of solvers from the "Efficient Field
2524 Sensitive Pointer Analysis for C" paper.
2525 It works by iterating over all the graph nodes, processing the complex
2526 constraints and propagating the copy constraints, until everything stops
2527 changed. This corresponds to steps 6-8 in the solving list given above. */
2530 solve_graph (constraint_graph_t graph
)
2532 unsigned int size
= graph
->size
;
2536 changed
= BITMAP_ALLOC (NULL
);
2538 /* Mark all initial non-collapsed nodes as changed. */
2539 for (i
= 0; i
< size
; i
++)
2541 varinfo_t ivi
= get_varinfo (i
);
2542 if (find (i
) == i
&& !bitmap_empty_p (ivi
->solution
)
2543 && ((graph
->succs
[i
] && !bitmap_empty_p (graph
->succs
[i
]))
2544 || graph
->complex[i
].length () > 0))
2545 bitmap_set_bit (changed
, i
);
2548 /* Allocate a bitmap to be used to store the changed bits. */
2549 pts
= BITMAP_ALLOC (&pta_obstack
);
2551 while (!bitmap_empty_p (changed
))
2554 struct topo_info
*ti
= init_topo_info ();
2557 bitmap_obstack_initialize (&iteration_obstack
);
2559 compute_topo_order (graph
, ti
);
2561 while (ti
->topo_order
.length () != 0)
2564 i
= ti
->topo_order
.pop ();
2566 /* If this variable is not a representative, skip it. */
2570 /* In certain indirect cycle cases, we may merge this
2571 variable to another. */
2572 if (eliminate_indirect_cycles (i
) && find (i
) != i
)
2575 /* If the node has changed, we need to process the
2576 complex constraints and outgoing edges again. */
2577 if (bitmap_clear_bit (changed
, i
))
2582 vec
<constraint_t
> complex = graph
->complex[i
];
2583 varinfo_t vi
= get_varinfo (i
);
2584 bool solution_empty
;
2586 /* Compute the changed set of solution bits. */
2587 if (vi
->oldsolution
)
2588 bitmap_and_compl (pts
, vi
->solution
, vi
->oldsolution
);
2590 bitmap_copy (pts
, vi
->solution
);
2592 if (bitmap_empty_p (pts
))
2595 if (vi
->oldsolution
)
2596 bitmap_ior_into (vi
->oldsolution
, pts
);
2599 vi
->oldsolution
= BITMAP_ALLOC (&oldpta_obstack
);
2600 bitmap_copy (vi
->oldsolution
, pts
);
2603 solution
= vi
->solution
;
2604 solution_empty
= bitmap_empty_p (solution
);
2606 /* Process the complex constraints */
2607 FOR_EACH_VEC_ELT (complex, j
, c
)
2609 /* XXX: This is going to unsort the constraints in
2610 some cases, which will occasionally add duplicate
2611 constraints during unification. This does not
2612 affect correctness. */
2613 c
->lhs
.var
= find (c
->lhs
.var
);
2614 c
->rhs
.var
= find (c
->rhs
.var
);
2616 /* The only complex constraint that can change our
2617 solution to non-empty, given an empty solution,
2618 is a constraint where the lhs side is receiving
2619 some set from elsewhere. */
2620 if (!solution_empty
|| c
->lhs
.type
!= DEREF
)
2621 do_complex_constraint (graph
, c
, pts
);
2624 solution_empty
= bitmap_empty_p (solution
);
2626 if (!solution_empty
)
2629 unsigned eff_escaped_id
= find (escaped_id
);
2631 /* Propagate solution to all successors. */
2632 EXECUTE_IF_IN_NONNULL_BITMAP (graph
->succs
[i
],
2638 unsigned int to
= find (j
);
2639 tmp
= get_varinfo (to
)->solution
;
2642 /* Don't try to propagate to ourselves. */
2646 /* If we propagate from ESCAPED use ESCAPED as
2648 if (i
== eff_escaped_id
)
2649 flag
= bitmap_set_bit (tmp
, escaped_id
);
2651 flag
= set_union_with_increment (tmp
, pts
, 0);
2655 get_varinfo (to
)->solution
= tmp
;
2656 bitmap_set_bit (changed
, to
);
2662 free_topo_info (ti
);
2663 bitmap_obstack_release (&iteration_obstack
);
2667 BITMAP_FREE (changed
);
2668 bitmap_obstack_release (&oldpta_obstack
);
2671 /* Map from trees to variable infos. */
2672 static struct pointer_map_t
*vi_for_tree
;
2675 /* Insert ID as the variable id for tree T in the vi_for_tree map. */
2678 insert_vi_for_tree (tree t
, varinfo_t vi
)
2680 void **slot
= pointer_map_insert (vi_for_tree
, t
);
2682 gcc_assert (*slot
== NULL
);
2686 /* Find the variable info for tree T in VI_FOR_TREE. If T does not
2687 exist in the map, return NULL, otherwise, return the varinfo we found. */
2690 lookup_vi_for_tree (tree t
)
2692 void **slot
= pointer_map_contains (vi_for_tree
, t
);
2696 return (varinfo_t
) *slot
;
2699 /* Return a printable name for DECL */
2702 alias_get_name (tree decl
)
2704 const char *res
= NULL
;
2706 int num_printed
= 0;
2711 if (TREE_CODE (decl
) == SSA_NAME
)
2713 res
= get_name (decl
);
2715 num_printed
= asprintf (&temp
, "%s_%u", res
, SSA_NAME_VERSION (decl
));
2717 num_printed
= asprintf (&temp
, "_%u", SSA_NAME_VERSION (decl
));
2718 if (num_printed
> 0)
2720 res
= ggc_strdup (temp
);
2724 else if (DECL_P (decl
))
2726 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
2727 res
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2730 res
= get_name (decl
);
2733 num_printed
= asprintf (&temp
, "D.%u", DECL_UID (decl
));
2734 if (num_printed
> 0)
2736 res
= ggc_strdup (temp
);
2748 /* Find the variable id for tree T in the map.
2749 If T doesn't exist in the map, create an entry for it and return it. */
2752 get_vi_for_tree (tree t
)
2754 void **slot
= pointer_map_contains (vi_for_tree
, t
);
2756 return get_varinfo (create_variable_info_for (t
, alias_get_name (t
)));
2758 return (varinfo_t
) *slot
;
2761 /* Get a scalar constraint expression for a new temporary variable. */
2763 static struct constraint_expr
2764 new_scalar_tmp_constraint_exp (const char *name
)
2766 struct constraint_expr tmp
;
2769 vi
= new_var_info (NULL_TREE
, name
);
2773 vi
->is_full_var
= 1;
2782 /* Get a constraint expression vector from an SSA_VAR_P node.
2783 If address_p is true, the result will be taken its address of. */
2786 get_constraint_for_ssa_var (tree t
, vec
<ce_s
> *results
, bool address_p
)
2788 struct constraint_expr cexpr
;
2791 /* We allow FUNCTION_DECLs here even though it doesn't make much sense. */
2792 gcc_assert (TREE_CODE (t
) == SSA_NAME
|| DECL_P (t
));
2794 /* For parameters, get at the points-to set for the actual parm
2796 if (TREE_CODE (t
) == SSA_NAME
2797 && SSA_NAME_IS_DEFAULT_DEF (t
)
2798 && (TREE_CODE (SSA_NAME_VAR (t
)) == PARM_DECL
2799 || TREE_CODE (SSA_NAME_VAR (t
)) == RESULT_DECL
))
2801 get_constraint_for_ssa_var (SSA_NAME_VAR (t
), results
, address_p
);
2805 /* For global variables resort to the alias target. */
2806 if (TREE_CODE (t
) == VAR_DECL
2807 && (TREE_STATIC (t
) || DECL_EXTERNAL (t
)))
2809 struct varpool_node
*node
= varpool_get_node (t
);
2810 if (node
&& node
->alias
)
2812 node
= varpool_variable_node (node
, NULL
);
2813 t
= node
->symbol
.decl
;
2817 vi
= get_vi_for_tree (t
);
2819 cexpr
.type
= SCALAR
;
2821 /* If we determine the result is "anything", and we know this is readonly,
2822 say it points to readonly memory instead. */
2823 if (cexpr
.var
== anything_id
&& TREE_READONLY (t
))
2826 cexpr
.type
= ADDRESSOF
;
2827 cexpr
.var
= readonly_id
;
2830 /* If we are not taking the address of the constraint expr, add all
2831 sub-fiels of the variable as well. */
2833 && !vi
->is_full_var
)
2835 for (; vi
; vi
= vi
->next
)
2838 results
->safe_push (cexpr
);
2843 results
->safe_push (cexpr
);
2846 /* Process constraint T, performing various simplifications and then
2847 adding it to our list of overall constraints. */
2850 process_constraint (constraint_t t
)
2852 struct constraint_expr rhs
= t
->rhs
;
2853 struct constraint_expr lhs
= t
->lhs
;
2855 gcc_assert (rhs
.var
< varmap
.length ());
2856 gcc_assert (lhs
.var
< varmap
.length ());
2858 /* If we didn't get any useful constraint from the lhs we get
2859 &ANYTHING as fallback from get_constraint_for. Deal with
2860 it here by turning it into *ANYTHING. */
2861 if (lhs
.type
== ADDRESSOF
2862 && lhs
.var
== anything_id
)
2865 /* ADDRESSOF on the lhs is invalid. */
2866 gcc_assert (lhs
.type
!= ADDRESSOF
);
2868 /* We shouldn't add constraints from things that cannot have pointers.
2869 It's not completely trivial to avoid in the callers, so do it here. */
2870 if (rhs
.type
!= ADDRESSOF
2871 && !get_varinfo (rhs
.var
)->may_have_pointers
)
2874 /* Likewise adding to the solution of a non-pointer var isn't useful. */
2875 if (!get_varinfo (lhs
.var
)->may_have_pointers
)
2878 /* This can happen in our IR with things like n->a = *p */
2879 if (rhs
.type
== DEREF
&& lhs
.type
== DEREF
&& rhs
.var
!= anything_id
)
2881 /* Split into tmp = *rhs, *lhs = tmp */
2882 struct constraint_expr tmplhs
;
2883 tmplhs
= new_scalar_tmp_constraint_exp ("doubledereftmp");
2884 process_constraint (new_constraint (tmplhs
, rhs
));
2885 process_constraint (new_constraint (lhs
, tmplhs
));
2887 else if (rhs
.type
== ADDRESSOF
&& lhs
.type
== DEREF
)
2889 /* Split into tmp = &rhs, *lhs = tmp */
2890 struct constraint_expr tmplhs
;
2891 tmplhs
= new_scalar_tmp_constraint_exp ("derefaddrtmp");
2892 process_constraint (new_constraint (tmplhs
, rhs
));
2893 process_constraint (new_constraint (lhs
, tmplhs
));
2897 gcc_assert (rhs
.type
!= ADDRESSOF
|| rhs
.offset
== 0);
2898 constraints
.safe_push (t
);
2903 /* Return the position, in bits, of FIELD_DECL from the beginning of its
2906 static HOST_WIDE_INT
2907 bitpos_of_field (const tree fdecl
)
2909 if (!host_integerp (DECL_FIELD_OFFSET (fdecl
), 0)
2910 || !host_integerp (DECL_FIELD_BIT_OFFSET (fdecl
), 0))
2913 return (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (fdecl
)) * BITS_PER_UNIT
2914 + TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (fdecl
)));
2918 /* Get constraint expressions for offsetting PTR by OFFSET. Stores the
2919 resulting constraint expressions in *RESULTS. */
2922 get_constraint_for_ptr_offset (tree ptr
, tree offset
,
2925 struct constraint_expr c
;
2927 HOST_WIDE_INT rhsoffset
;
2929 /* If we do not do field-sensitive PTA adding offsets to pointers
2930 does not change the points-to solution. */
2931 if (!use_field_sensitive
)
2933 get_constraint_for_rhs (ptr
, results
);
2937 /* If the offset is not a non-negative integer constant that fits
2938 in a HOST_WIDE_INT, we have to fall back to a conservative
2939 solution which includes all sub-fields of all pointed-to
2940 variables of ptr. */
2941 if (offset
== NULL_TREE
2942 || TREE_CODE (offset
) != INTEGER_CST
)
2943 rhsoffset
= UNKNOWN_OFFSET
;
2946 /* Sign-extend the offset. */
2947 double_int soffset
= tree_to_double_int (offset
)
2948 .sext (TYPE_PRECISION (TREE_TYPE (offset
)));
2949 if (!soffset
.fits_shwi ())
2950 rhsoffset
= UNKNOWN_OFFSET
;
2953 /* Make sure the bit-offset also fits. */
2954 HOST_WIDE_INT rhsunitoffset
= soffset
.low
;
2955 rhsoffset
= rhsunitoffset
* BITS_PER_UNIT
;
2956 if (rhsunitoffset
!= rhsoffset
/ BITS_PER_UNIT
)
2957 rhsoffset
= UNKNOWN_OFFSET
;
2961 get_constraint_for_rhs (ptr
, results
);
2965 /* As we are eventually appending to the solution do not use
2966 vec::iterate here. */
2967 n
= results
->length ();
2968 for (j
= 0; j
< n
; j
++)
2972 curr
= get_varinfo (c
.var
);
2974 if (c
.type
== ADDRESSOF
2975 /* If this varinfo represents a full variable just use it. */
2976 && curr
->is_full_var
)
2978 else if (c
.type
== ADDRESSOF
2979 /* If we do not know the offset add all subfields. */
2980 && rhsoffset
== UNKNOWN_OFFSET
)
2982 varinfo_t temp
= lookup_vi_for_tree (curr
->decl
);
2985 struct constraint_expr c2
;
2987 c2
.type
= ADDRESSOF
;
2989 if (c2
.var
!= c
.var
)
2990 results
->safe_push (c2
);
2995 else if (c
.type
== ADDRESSOF
)
2998 unsigned HOST_WIDE_INT offset
= curr
->offset
+ rhsoffset
;
3000 /* Search the sub-field which overlaps with the
3001 pointed-to offset. If the result is outside of the variable
3002 we have to provide a conservative result, as the variable is
3003 still reachable from the resulting pointer (even though it
3004 technically cannot point to anything). The last and first
3005 sub-fields are such conservative results.
3006 ??? If we always had a sub-field for &object + 1 then
3007 we could represent this in a more precise way. */
3009 && curr
->offset
< offset
)
3011 temp
= first_or_preceding_vi_for_offset (curr
, offset
);
3013 /* If the found variable is not exactly at the pointed to
3014 result, we have to include the next variable in the
3015 solution as well. Otherwise two increments by offset / 2
3016 do not result in the same or a conservative superset
3018 if (temp
->offset
!= offset
3019 && temp
->next
!= NULL
)
3021 struct constraint_expr c2
;
3022 c2
.var
= temp
->next
->id
;
3023 c2
.type
= ADDRESSOF
;
3025 results
->safe_push (c2
);
3031 c
.offset
= rhsoffset
;
3038 /* Given a COMPONENT_REF T, return the constraint_expr vector for it.
3039 If address_p is true the result will be taken its address of.
3040 If lhs_p is true then the constraint expression is assumed to be used
3044 get_constraint_for_component_ref (tree t
, vec
<ce_s
> *results
,
3045 bool address_p
, bool lhs_p
)
3048 HOST_WIDE_INT bitsize
= -1;
3049 HOST_WIDE_INT bitmaxsize
= -1;
3050 HOST_WIDE_INT bitpos
;
3053 /* Some people like to do cute things like take the address of
3056 while (handled_component_p (forzero
)
3057 || INDIRECT_REF_P (forzero
)
3058 || TREE_CODE (forzero
) == MEM_REF
)
3059 forzero
= TREE_OPERAND (forzero
, 0);
3061 if (CONSTANT_CLASS_P (forzero
) && integer_zerop (forzero
))
3063 struct constraint_expr temp
;
3066 temp
.var
= integer_id
;
3068 results
->safe_push (temp
);
3072 /* Handle type-punning through unions. If we are extracting a pointer
3073 from a union via a possibly type-punning access that pointer
3074 points to anything, similar to a conversion of an integer to
3080 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
3081 u
= TREE_OPERAND (u
, 0))
3082 if (TREE_CODE (u
) == COMPONENT_REF
3083 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
3085 struct constraint_expr temp
;
3088 temp
.var
= anything_id
;
3089 temp
.type
= ADDRESSOF
;
3090 results
->safe_push (temp
);
3095 t
= get_ref_base_and_extent (t
, &bitpos
, &bitsize
, &bitmaxsize
);
3097 /* Pretend to take the address of the base, we'll take care of
3098 adding the required subset of sub-fields below. */
3099 get_constraint_for_1 (t
, results
, true, lhs_p
);
3100 gcc_assert (results
->length () == 1);
3101 struct constraint_expr
&result
= results
->last ();
3103 if (result
.type
== SCALAR
3104 && get_varinfo (result
.var
)->is_full_var
)
3105 /* For single-field vars do not bother about the offset. */
3107 else if (result
.type
== SCALAR
)
3109 /* In languages like C, you can access one past the end of an
3110 array. You aren't allowed to dereference it, so we can
3111 ignore this constraint. When we handle pointer subtraction,
3112 we may have to do something cute here. */
3114 if ((unsigned HOST_WIDE_INT
)bitpos
< get_varinfo (result
.var
)->fullsize
3117 /* It's also not true that the constraint will actually start at the
3118 right offset, it may start in some padding. We only care about
3119 setting the constraint to the first actual field it touches, so
3121 struct constraint_expr cexpr
= result
;
3125 for (curr
= get_varinfo (cexpr
.var
); curr
; curr
= curr
->next
)
3127 if (ranges_overlap_p (curr
->offset
, curr
->size
,
3128 bitpos
, bitmaxsize
))
3130 cexpr
.var
= curr
->id
;
3131 results
->safe_push (cexpr
);
3136 /* If we are going to take the address of this field then
3137 to be able to compute reachability correctly add at least
3138 the last field of the variable. */
3139 if (address_p
&& results
->length () == 0)
3141 curr
= get_varinfo (cexpr
.var
);
3142 while (curr
->next
!= NULL
)
3144 cexpr
.var
= curr
->id
;
3145 results
->safe_push (cexpr
);
3147 else if (results
->length () == 0)
3148 /* Assert that we found *some* field there. The user couldn't be
3149 accessing *only* padding. */
3150 /* Still the user could access one past the end of an array
3151 embedded in a struct resulting in accessing *only* padding. */
3152 /* Or accessing only padding via type-punning to a type
3153 that has a filed just in padding space. */
3155 cexpr
.type
= SCALAR
;
3156 cexpr
.var
= anything_id
;
3158 results
->safe_push (cexpr
);
3161 else if (bitmaxsize
== 0)
3163 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3164 fprintf (dump_file
, "Access to zero-sized part of variable,"
3168 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3169 fprintf (dump_file
, "Access to past the end of variable, ignoring\n");
3171 else if (result
.type
== DEREF
)
3173 /* If we do not know exactly where the access goes say so. Note
3174 that only for non-structure accesses we know that we access
3175 at most one subfiled of any variable. */
3177 || bitsize
!= bitmaxsize
3178 || AGGREGATE_TYPE_P (TREE_TYPE (orig_t
))
3179 || result
.offset
== UNKNOWN_OFFSET
)
3180 result
.offset
= UNKNOWN_OFFSET
;
3182 result
.offset
+= bitpos
;
3184 else if (result
.type
== ADDRESSOF
)
3186 /* We can end up here for component references on a
3187 VIEW_CONVERT_EXPR <>(&foobar). */
3188 result
.type
= SCALAR
;
3189 result
.var
= anything_id
;
3197 /* Dereference the constraint expression CONS, and return the result.
3198 DEREF (ADDRESSOF) = SCALAR
3199 DEREF (SCALAR) = DEREF
3200 DEREF (DEREF) = (temp = DEREF1; result = DEREF(temp))
3201 This is needed so that we can handle dereferencing DEREF constraints. */
3204 do_deref (vec
<ce_s
> *constraints
)
3206 struct constraint_expr
*c
;
3209 FOR_EACH_VEC_ELT (*constraints
, i
, c
)
3211 if (c
->type
== SCALAR
)
3213 else if (c
->type
== ADDRESSOF
)
3215 else if (c
->type
== DEREF
)
3217 struct constraint_expr tmplhs
;
3218 tmplhs
= new_scalar_tmp_constraint_exp ("dereftmp");
3219 process_constraint (new_constraint (tmplhs
, *c
));
3220 c
->var
= tmplhs
.var
;
3227 /* Given a tree T, return the constraint expression for taking the
3231 get_constraint_for_address_of (tree t
, vec
<ce_s
> *results
)
3233 struct constraint_expr
*c
;
3236 get_constraint_for_1 (t
, results
, true, true);
3238 FOR_EACH_VEC_ELT (*results
, i
, c
)
3240 if (c
->type
== DEREF
)
3243 c
->type
= ADDRESSOF
;
3247 /* Given a tree T, return the constraint expression for it. */
3250 get_constraint_for_1 (tree t
, vec
<ce_s
> *results
, bool address_p
,
3253 struct constraint_expr temp
;
3255 /* x = integer is all glommed to a single variable, which doesn't
3256 point to anything by itself. That is, of course, unless it is an
3257 integer constant being treated as a pointer, in which case, we
3258 will return that this is really the addressof anything. This
3259 happens below, since it will fall into the default case. The only
3260 case we know something about an integer treated like a pointer is
3261 when it is the NULL pointer, and then we just say it points to
3264 Do not do that if -fno-delete-null-pointer-checks though, because
3265 in that case *NULL does not fail, so it _should_ alias *anything.
3266 It is not worth adding a new option or renaming the existing one,
3267 since this case is relatively obscure. */
3268 if ((TREE_CODE (t
) == INTEGER_CST
3269 && integer_zerop (t
))
3270 /* The only valid CONSTRUCTORs in gimple with pointer typed
3271 elements are zero-initializer. But in IPA mode we also
3272 process global initializers, so verify at least. */
3273 || (TREE_CODE (t
) == CONSTRUCTOR
3274 && CONSTRUCTOR_NELTS (t
) == 0))
3276 if (flag_delete_null_pointer_checks
)
3277 temp
.var
= nothing_id
;
3279 temp
.var
= nonlocal_id
;
3280 temp
.type
= ADDRESSOF
;
3282 results
->safe_push (temp
);
3286 /* String constants are read-only. */
3287 if (TREE_CODE (t
) == STRING_CST
)
3289 temp
.var
= readonly_id
;
3292 results
->safe_push (temp
);
3296 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
3298 case tcc_expression
:
3300 switch (TREE_CODE (t
))
3303 get_constraint_for_address_of (TREE_OPERAND (t
, 0), results
);
3311 switch (TREE_CODE (t
))
3315 struct constraint_expr cs
;
3317 get_constraint_for_ptr_offset (TREE_OPERAND (t
, 0),
3318 TREE_OPERAND (t
, 1), results
);
3321 /* If we are not taking the address then make sure to process
3322 all subvariables we might access. */
3326 cs
= results
->last ();
3327 if (cs
.type
== DEREF
3328 && type_can_have_subvars (TREE_TYPE (t
)))
3330 /* For dereferences this means we have to defer it
3332 results
->last ().offset
= UNKNOWN_OFFSET
;
3335 if (cs
.type
!= SCALAR
)
3338 vi
= get_varinfo (cs
.var
);
3340 if (!vi
->is_full_var
3343 unsigned HOST_WIDE_INT size
;
3344 if (host_integerp (TYPE_SIZE (TREE_TYPE (t
)), 1))
3345 size
= TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (t
)));
3348 for (; curr
; curr
= curr
->next
)
3350 if (curr
->offset
- vi
->offset
< size
)
3353 results
->safe_push (cs
);
3362 case ARRAY_RANGE_REF
:
3364 get_constraint_for_component_ref (t
, results
, address_p
, lhs_p
);
3366 case VIEW_CONVERT_EXPR
:
3367 get_constraint_for_1 (TREE_OPERAND (t
, 0), results
, address_p
,
3370 /* We are missing handling for TARGET_MEM_REF here. */
3375 case tcc_exceptional
:
3377 switch (TREE_CODE (t
))
3381 get_constraint_for_ssa_var (t
, results
, address_p
);
3388 vec
<ce_s
> tmp
= vNULL
;
3389 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t
), i
, val
)
3391 struct constraint_expr
*rhsp
;
3393 get_constraint_for_1 (val
, &tmp
, address_p
, lhs_p
);
3394 FOR_EACH_VEC_ELT (tmp
, j
, rhsp
)
3395 results
->safe_push (*rhsp
);
3399 /* We do not know whether the constructor was complete,
3400 so technically we have to add &NOTHING or &ANYTHING
3401 like we do for an empty constructor as well. */
3408 case tcc_declaration
:
3410 get_constraint_for_ssa_var (t
, results
, address_p
);
3415 /* We cannot refer to automatic variables through constants. */
3416 temp
.type
= ADDRESSOF
;
3417 temp
.var
= nonlocal_id
;
3419 results
->safe_push (temp
);
3425 /* The default fallback is a constraint from anything. */
3426 temp
.type
= ADDRESSOF
;
3427 temp
.var
= anything_id
;
3429 results
->safe_push (temp
);
3432 /* Given a gimple tree T, return the constraint expression vector for it. */
3435 get_constraint_for (tree t
, vec
<ce_s
> *results
)
3437 gcc_assert (results
->length () == 0);
3439 get_constraint_for_1 (t
, results
, false, true);
3442 /* Given a gimple tree T, return the constraint expression vector for it
3443 to be used as the rhs of a constraint. */
3446 get_constraint_for_rhs (tree t
, vec
<ce_s
> *results
)
3448 gcc_assert (results
->length () == 0);
3450 get_constraint_for_1 (t
, results
, false, false);
3454 /* Efficiently generates constraints from all entries in *RHSC to all
3455 entries in *LHSC. */
3458 process_all_all_constraints (vec
<ce_s
> lhsc
,
3461 struct constraint_expr
*lhsp
, *rhsp
;
3464 if (lhsc
.length () <= 1 || rhsc
.length () <= 1)
3466 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
3467 FOR_EACH_VEC_ELT (rhsc
, j
, rhsp
)
3468 process_constraint (new_constraint (*lhsp
, *rhsp
));
3472 struct constraint_expr tmp
;
3473 tmp
= new_scalar_tmp_constraint_exp ("allalltmp");
3474 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
3475 process_constraint (new_constraint (tmp
, *rhsp
));
3476 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
3477 process_constraint (new_constraint (*lhsp
, tmp
));
3481 /* Handle aggregate copies by expanding into copies of the respective
3482 fields of the structures. */
3485 do_structure_copy (tree lhsop
, tree rhsop
)
3487 struct constraint_expr
*lhsp
, *rhsp
;
3488 vec
<ce_s
> lhsc
= vNULL
;
3489 vec
<ce_s
> rhsc
= vNULL
;
3492 get_constraint_for (lhsop
, &lhsc
);
3493 get_constraint_for_rhs (rhsop
, &rhsc
);
3496 if (lhsp
->type
== DEREF
3497 || (lhsp
->type
== ADDRESSOF
&& lhsp
->var
== anything_id
)
3498 || rhsp
->type
== DEREF
)
3500 if (lhsp
->type
== DEREF
)
3502 gcc_assert (lhsc
.length () == 1);
3503 lhsp
->offset
= UNKNOWN_OFFSET
;
3505 if (rhsp
->type
== DEREF
)
3507 gcc_assert (rhsc
.length () == 1);
3508 rhsp
->offset
= UNKNOWN_OFFSET
;
3510 process_all_all_constraints (lhsc
, rhsc
);
3512 else if (lhsp
->type
== SCALAR
3513 && (rhsp
->type
== SCALAR
3514 || rhsp
->type
== ADDRESSOF
))
3516 HOST_WIDE_INT lhssize
, lhsmaxsize
, lhsoffset
;
3517 HOST_WIDE_INT rhssize
, rhsmaxsize
, rhsoffset
;
3519 get_ref_base_and_extent (lhsop
, &lhsoffset
, &lhssize
, &lhsmaxsize
);
3520 get_ref_base_and_extent (rhsop
, &rhsoffset
, &rhssize
, &rhsmaxsize
);
3521 for (j
= 0; lhsc
.iterate (j
, &lhsp
);)
3523 varinfo_t lhsv
, rhsv
;
3525 lhsv
= get_varinfo (lhsp
->var
);
3526 rhsv
= get_varinfo (rhsp
->var
);
3527 if (lhsv
->may_have_pointers
3528 && (lhsv
->is_full_var
3529 || rhsv
->is_full_var
3530 || ranges_overlap_p (lhsv
->offset
+ rhsoffset
, lhsv
->size
,
3531 rhsv
->offset
+ lhsoffset
, rhsv
->size
)))
3532 process_constraint (new_constraint (*lhsp
, *rhsp
));
3533 if (!rhsv
->is_full_var
3534 && (lhsv
->is_full_var
3535 || (lhsv
->offset
+ rhsoffset
+ lhsv
->size
3536 > rhsv
->offset
+ lhsoffset
+ rhsv
->size
)))
3539 if (k
>= rhsc
.length ())
3553 /* Create constraints ID = { rhsc }. */
3556 make_constraints_to (unsigned id
, vec
<ce_s
> rhsc
)
3558 struct constraint_expr
*c
;
3559 struct constraint_expr includes
;
3563 includes
.offset
= 0;
3564 includes
.type
= SCALAR
;
3566 FOR_EACH_VEC_ELT (rhsc
, j
, c
)
3567 process_constraint (new_constraint (includes
, *c
));
3570 /* Create a constraint ID = OP. */
3573 make_constraint_to (unsigned id
, tree op
)
3575 vec
<ce_s
> rhsc
= vNULL
;
3576 get_constraint_for_rhs (op
, &rhsc
);
3577 make_constraints_to (id
, rhsc
);
3581 /* Create a constraint ID = &FROM. */
3584 make_constraint_from (varinfo_t vi
, int from
)
3586 struct constraint_expr lhs
, rhs
;
3594 rhs
.type
= ADDRESSOF
;
3595 process_constraint (new_constraint (lhs
, rhs
));
3598 /* Create a constraint ID = FROM. */
3601 make_copy_constraint (varinfo_t vi
, int from
)
3603 struct constraint_expr lhs
, rhs
;
3612 process_constraint (new_constraint (lhs
, rhs
));
3615 /* Make constraints necessary to make OP escape. */
3618 make_escape_constraint (tree op
)
3620 make_constraint_to (escaped_id
, op
);
3623 /* Add constraints to that the solution of VI is transitively closed. */
3626 make_transitive_closure_constraints (varinfo_t vi
)
3628 struct constraint_expr lhs
, rhs
;
3637 process_constraint (new_constraint (lhs
, rhs
));
3639 /* VAR = VAR + UNKNOWN; */
3645 rhs
.offset
= UNKNOWN_OFFSET
;
3646 process_constraint (new_constraint (lhs
, rhs
));
3649 /* Temporary storage for fake var decls. */
3650 struct obstack fake_var_decl_obstack
;
3652 /* Build a fake VAR_DECL acting as referrer to a DECL_UID. */
3655 build_fake_var_decl (tree type
)
3657 tree decl
= (tree
) XOBNEW (&fake_var_decl_obstack
, struct tree_var_decl
);
3658 memset (decl
, 0, sizeof (struct tree_var_decl
));
3659 TREE_SET_CODE (decl
, VAR_DECL
);
3660 TREE_TYPE (decl
) = type
;
3661 DECL_UID (decl
) = allocate_decl_uid ();
3662 SET_DECL_PT_UID (decl
, -1);
3663 layout_decl (decl
, 0);
3667 /* Create a new artificial heap variable with NAME.
3668 Return the created variable. */
3671 make_heapvar (const char *name
)
3676 heapvar
= build_fake_var_decl (ptr_type_node
);
3677 DECL_EXTERNAL (heapvar
) = 1;
3679 vi
= new_var_info (heapvar
, name
);
3680 vi
->is_artificial_var
= true;
3681 vi
->is_heap_var
= true;
3682 vi
->is_unknown_size_var
= true;
3686 vi
->is_full_var
= true;
3687 insert_vi_for_tree (heapvar
, vi
);
3692 /* Create a new artificial heap variable with NAME and make a
3693 constraint from it to LHS. Set flags according to a tag used
3694 for tracking restrict pointers. */
3697 make_constraint_from_restrict (varinfo_t lhs
, const char *name
)
3699 varinfo_t vi
= make_heapvar (name
);
3700 vi
->is_global_var
= 1;
3701 vi
->may_have_pointers
= 1;
3702 make_constraint_from (lhs
, vi
->id
);
3706 /* Create a new artificial heap variable with NAME and make a
3707 constraint from it to LHS. Set flags according to a tag used
3708 for tracking restrict pointers and make the artificial heap
3709 point to global memory. */
3712 make_constraint_from_global_restrict (varinfo_t lhs
, const char *name
)
3714 varinfo_t vi
= make_constraint_from_restrict (lhs
, name
);
3715 make_copy_constraint (vi
, nonlocal_id
);
3719 /* In IPA mode there are varinfos for different aspects of reach
3720 function designator. One for the points-to set of the return
3721 value, one for the variables that are clobbered by the function,
3722 one for its uses and one for each parameter (including a single
3723 glob for remaining variadic arguments). */
3725 enum { fi_clobbers
= 1, fi_uses
= 2,
3726 fi_static_chain
= 3, fi_result
= 4, fi_parm_base
= 5 };
3728 /* Get a constraint for the requested part of a function designator FI
3729 when operating in IPA mode. */
3731 static struct constraint_expr
3732 get_function_part_constraint (varinfo_t fi
, unsigned part
)
3734 struct constraint_expr c
;
3736 gcc_assert (in_ipa_mode
);
3738 if (fi
->id
== anything_id
)
3740 /* ??? We probably should have a ANYFN special variable. */
3741 c
.var
= anything_id
;
3745 else if (TREE_CODE (fi
->decl
) == FUNCTION_DECL
)
3747 varinfo_t ai
= first_vi_for_offset (fi
, part
);
3751 c
.var
= anything_id
;
3765 /* For non-IPA mode, generate constraints necessary for a call on the
3769 handle_rhs_call (gimple stmt
, vec
<ce_s
> *results
)
3771 struct constraint_expr rhsc
;
3773 bool returns_uses
= false;
3775 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
3777 tree arg
= gimple_call_arg (stmt
, i
);
3778 int flags
= gimple_call_arg_flags (stmt
, i
);
3780 /* If the argument is not used we can ignore it. */
3781 if (flags
& EAF_UNUSED
)
3784 /* As we compute ESCAPED context-insensitive we do not gain
3785 any precision with just EAF_NOCLOBBER but not EAF_NOESCAPE
3786 set. The argument would still get clobbered through the
3788 if ((flags
& EAF_NOCLOBBER
)
3789 && (flags
& EAF_NOESCAPE
))
3791 varinfo_t uses
= get_call_use_vi (stmt
);
3792 if (!(flags
& EAF_DIRECT
))
3794 varinfo_t tem
= new_var_info (NULL_TREE
, "callarg");
3795 make_constraint_to (tem
->id
, arg
);
3796 make_transitive_closure_constraints (tem
);
3797 make_copy_constraint (uses
, tem
->id
);
3800 make_constraint_to (uses
->id
, arg
);
3801 returns_uses
= true;
3803 else if (flags
& EAF_NOESCAPE
)
3805 struct constraint_expr lhs
, rhs
;
3806 varinfo_t uses
= get_call_use_vi (stmt
);
3807 varinfo_t clobbers
= get_call_clobber_vi (stmt
);
3808 varinfo_t tem
= new_var_info (NULL_TREE
, "callarg");
3809 make_constraint_to (tem
->id
, arg
);
3810 if (!(flags
& EAF_DIRECT
))
3811 make_transitive_closure_constraints (tem
);
3812 make_copy_constraint (uses
, tem
->id
);
3813 make_copy_constraint (clobbers
, tem
->id
);
3814 /* Add *tem = nonlocal, do not add *tem = callused as
3815 EAF_NOESCAPE parameters do not escape to other parameters
3816 and all other uses appear in NONLOCAL as well. */
3821 rhs
.var
= nonlocal_id
;
3823 process_constraint (new_constraint (lhs
, rhs
));
3824 returns_uses
= true;
3827 make_escape_constraint (arg
);
3830 /* If we added to the calls uses solution make sure we account for
3831 pointers to it to be returned. */
3834 rhsc
.var
= get_call_use_vi (stmt
)->id
;
3837 results
->safe_push (rhsc
);
3840 /* The static chain escapes as well. */
3841 if (gimple_call_chain (stmt
))
3842 make_escape_constraint (gimple_call_chain (stmt
));
3844 /* And if we applied NRV the address of the return slot escapes as well. */
3845 if (gimple_call_return_slot_opt_p (stmt
)
3846 && gimple_call_lhs (stmt
) != NULL_TREE
3847 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
3849 vec
<ce_s
> tmpc
= vNULL
;
3850 struct constraint_expr lhsc
, *c
;
3851 get_constraint_for_address_of (gimple_call_lhs (stmt
), &tmpc
);
3852 lhsc
.var
= escaped_id
;
3855 FOR_EACH_VEC_ELT (tmpc
, i
, c
)
3856 process_constraint (new_constraint (lhsc
, *c
));
3860 /* Regular functions return nonlocal memory. */
3861 rhsc
.var
= nonlocal_id
;
3864 results
->safe_push (rhsc
);
3867 /* For non-IPA mode, generate constraints necessary for a call
3868 that returns a pointer and assigns it to LHS. This simply makes
3869 the LHS point to global and escaped variables. */
3872 handle_lhs_call (gimple stmt
, tree lhs
, int flags
, vec
<ce_s
> rhsc
,
3875 vec
<ce_s
> lhsc
= vNULL
;
3877 get_constraint_for (lhs
, &lhsc
);
3878 /* If the store is to a global decl make sure to
3879 add proper escape constraints. */
3880 lhs
= get_base_address (lhs
);
3883 && is_global_var (lhs
))
3885 struct constraint_expr tmpc
;
3886 tmpc
.var
= escaped_id
;
3889 lhsc
.safe_push (tmpc
);
3892 /* If the call returns an argument unmodified override the rhs
3894 flags
= gimple_call_return_flags (stmt
);
3895 if (flags
& ERF_RETURNS_ARG
3896 && (flags
& ERF_RETURN_ARG_MASK
) < gimple_call_num_args (stmt
))
3900 arg
= gimple_call_arg (stmt
, flags
& ERF_RETURN_ARG_MASK
);
3901 get_constraint_for (arg
, &rhsc
);
3902 process_all_all_constraints (lhsc
, rhsc
);
3905 else if (flags
& ERF_NOALIAS
)
3908 struct constraint_expr tmpc
;
3910 vi
= make_heapvar ("HEAP");
3911 /* We delay marking allocated storage global until we know if
3913 DECL_EXTERNAL (vi
->decl
) = 0;
3914 vi
->is_global_var
= 0;
3915 /* If this is not a real malloc call assume the memory was
3916 initialized and thus may point to global memory. All
3917 builtin functions with the malloc attribute behave in a sane way. */
3919 || DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_NORMAL
)
3920 make_constraint_from (vi
, nonlocal_id
);
3923 tmpc
.type
= ADDRESSOF
;
3924 rhsc
.safe_push (tmpc
);
3925 process_all_all_constraints (lhsc
, rhsc
);
3929 process_all_all_constraints (lhsc
, rhsc
);
3934 /* For non-IPA mode, generate constraints necessary for a call of a
3935 const function that returns a pointer in the statement STMT. */
3938 handle_const_call (gimple stmt
, vec
<ce_s
> *results
)
3940 struct constraint_expr rhsc
;
3943 /* Treat nested const functions the same as pure functions as far
3944 as the static chain is concerned. */
3945 if (gimple_call_chain (stmt
))
3947 varinfo_t uses
= get_call_use_vi (stmt
);
3948 make_transitive_closure_constraints (uses
);
3949 make_constraint_to (uses
->id
, gimple_call_chain (stmt
));
3950 rhsc
.var
= uses
->id
;
3953 results
->safe_push (rhsc
);
3956 /* May return arguments. */
3957 for (k
= 0; k
< gimple_call_num_args (stmt
); ++k
)
3959 tree arg
= gimple_call_arg (stmt
, k
);
3960 vec
<ce_s
> argc
= vNULL
;
3962 struct constraint_expr
*argp
;
3963 get_constraint_for_rhs (arg
, &argc
);
3964 FOR_EACH_VEC_ELT (argc
, i
, argp
)
3965 results
->safe_push (*argp
);
3969 /* May return addresses of globals. */
3970 rhsc
.var
= nonlocal_id
;
3972 rhsc
.type
= ADDRESSOF
;
3973 results
->safe_push (rhsc
);
3976 /* For non-IPA mode, generate constraints necessary for a call to a
3977 pure function in statement STMT. */
3980 handle_pure_call (gimple stmt
, vec
<ce_s
> *results
)
3982 struct constraint_expr rhsc
;
3984 varinfo_t uses
= NULL
;
3986 /* Memory reached from pointer arguments is call-used. */
3987 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
3989 tree arg
= gimple_call_arg (stmt
, i
);
3992 uses
= get_call_use_vi (stmt
);
3993 make_transitive_closure_constraints (uses
);
3995 make_constraint_to (uses
->id
, arg
);
3998 /* The static chain is used as well. */
3999 if (gimple_call_chain (stmt
))
4003 uses
= get_call_use_vi (stmt
);
4004 make_transitive_closure_constraints (uses
);
4006 make_constraint_to (uses
->id
, gimple_call_chain (stmt
));
4009 /* Pure functions may return call-used and nonlocal memory. */
4012 rhsc
.var
= uses
->id
;
4015 results
->safe_push (rhsc
);
4017 rhsc
.var
= nonlocal_id
;
4020 results
->safe_push (rhsc
);
4024 /* Return the varinfo for the callee of CALL. */
4027 get_fi_for_callee (gimple call
)
4029 tree decl
, fn
= gimple_call_fn (call
);
4031 if (fn
&& TREE_CODE (fn
) == OBJ_TYPE_REF
)
4032 fn
= OBJ_TYPE_REF_EXPR (fn
);
4034 /* If we can directly resolve the function being called, do so.
4035 Otherwise, it must be some sort of indirect expression that
4036 we should still be able to handle. */
4037 decl
= gimple_call_addr_fndecl (fn
);
4039 return get_vi_for_tree (decl
);
4041 /* If the function is anything other than a SSA name pointer we have no
4042 clue and should be getting ANYFN (well, ANYTHING for now). */
4043 if (!fn
|| TREE_CODE (fn
) != SSA_NAME
)
4044 return get_varinfo (anything_id
);
4046 if (SSA_NAME_IS_DEFAULT_DEF (fn
)
4047 && (TREE_CODE (SSA_NAME_VAR (fn
)) == PARM_DECL
4048 || TREE_CODE (SSA_NAME_VAR (fn
)) == RESULT_DECL
))
4049 fn
= SSA_NAME_VAR (fn
);
4051 return get_vi_for_tree (fn
);
4054 /* Create constraints for the builtin call T. Return true if the call
4055 was handled, otherwise false. */
4058 find_func_aliases_for_builtin_call (gimple t
)
4060 tree fndecl
= gimple_call_fndecl (t
);
4061 vec
<ce_s
> lhsc
= vNULL
;
4062 vec
<ce_s
> rhsc
= vNULL
;
4065 if (gimple_call_builtin_p (t
, BUILT_IN_NORMAL
))
4066 /* ??? All builtins that are handled here need to be handled
4067 in the alias-oracle query functions explicitly! */
4068 switch (DECL_FUNCTION_CODE (fndecl
))
4070 /* All the following functions return a pointer to the same object
4071 as their first argument points to. The functions do not add
4072 to the ESCAPED solution. The functions make the first argument
4073 pointed to memory point to what the second argument pointed to
4074 memory points to. */
4075 case BUILT_IN_STRCPY
:
4076 case BUILT_IN_STRNCPY
:
4077 case BUILT_IN_BCOPY
:
4078 case BUILT_IN_MEMCPY
:
4079 case BUILT_IN_MEMMOVE
:
4080 case BUILT_IN_MEMPCPY
:
4081 case BUILT_IN_STPCPY
:
4082 case BUILT_IN_STPNCPY
:
4083 case BUILT_IN_STRCAT
:
4084 case BUILT_IN_STRNCAT
:
4085 case BUILT_IN_STRCPY_CHK
:
4086 case BUILT_IN_STRNCPY_CHK
:
4087 case BUILT_IN_MEMCPY_CHK
:
4088 case BUILT_IN_MEMMOVE_CHK
:
4089 case BUILT_IN_MEMPCPY_CHK
:
4090 case BUILT_IN_STPCPY_CHK
:
4091 case BUILT_IN_STPNCPY_CHK
:
4092 case BUILT_IN_STRCAT_CHK
:
4093 case BUILT_IN_STRNCAT_CHK
:
4094 case BUILT_IN_TM_MEMCPY
:
4095 case BUILT_IN_TM_MEMMOVE
:
4097 tree res
= gimple_call_lhs (t
);
4098 tree dest
= gimple_call_arg (t
, (DECL_FUNCTION_CODE (fndecl
)
4099 == BUILT_IN_BCOPY
? 1 : 0));
4100 tree src
= gimple_call_arg (t
, (DECL_FUNCTION_CODE (fndecl
)
4101 == BUILT_IN_BCOPY
? 0 : 1));
4102 if (res
!= NULL_TREE
)
4104 get_constraint_for (res
, &lhsc
);
4105 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_MEMPCPY
4106 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_STPCPY
4107 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_STPNCPY
4108 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_MEMPCPY_CHK
4109 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_STPCPY_CHK
4110 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_STPNCPY_CHK
)
4111 get_constraint_for_ptr_offset (dest
, NULL_TREE
, &rhsc
);
4113 get_constraint_for (dest
, &rhsc
);
4114 process_all_all_constraints (lhsc
, rhsc
);
4118 get_constraint_for_ptr_offset (dest
, NULL_TREE
, &lhsc
);
4119 get_constraint_for_ptr_offset (src
, NULL_TREE
, &rhsc
);
4122 process_all_all_constraints (lhsc
, rhsc
);
4127 case BUILT_IN_MEMSET
:
4128 case BUILT_IN_MEMSET_CHK
:
4129 case BUILT_IN_TM_MEMSET
:
4131 tree res
= gimple_call_lhs (t
);
4132 tree dest
= gimple_call_arg (t
, 0);
4135 struct constraint_expr ac
;
4136 if (res
!= NULL_TREE
)
4138 get_constraint_for (res
, &lhsc
);
4139 get_constraint_for (dest
, &rhsc
);
4140 process_all_all_constraints (lhsc
, rhsc
);
4144 get_constraint_for_ptr_offset (dest
, NULL_TREE
, &lhsc
);
4146 if (flag_delete_null_pointer_checks
4147 && integer_zerop (gimple_call_arg (t
, 1)))
4149 ac
.type
= ADDRESSOF
;
4150 ac
.var
= nothing_id
;
4155 ac
.var
= integer_id
;
4158 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
4159 process_constraint (new_constraint (*lhsp
, ac
));
4163 case BUILT_IN_ASSUME_ALIGNED
:
4165 tree res
= gimple_call_lhs (t
);
4166 tree dest
= gimple_call_arg (t
, 0);
4167 if (res
!= NULL_TREE
)
4169 get_constraint_for (res
, &lhsc
);
4170 get_constraint_for (dest
, &rhsc
);
4171 process_all_all_constraints (lhsc
, rhsc
);
4177 /* All the following functions do not return pointers, do not
4178 modify the points-to sets of memory reachable from their
4179 arguments and do not add to the ESCAPED solution. */
4180 case BUILT_IN_SINCOS
:
4181 case BUILT_IN_SINCOSF
:
4182 case BUILT_IN_SINCOSL
:
4183 case BUILT_IN_FREXP
:
4184 case BUILT_IN_FREXPF
:
4185 case BUILT_IN_FREXPL
:
4186 case BUILT_IN_GAMMA_R
:
4187 case BUILT_IN_GAMMAF_R
:
4188 case BUILT_IN_GAMMAL_R
:
4189 case BUILT_IN_LGAMMA_R
:
4190 case BUILT_IN_LGAMMAF_R
:
4191 case BUILT_IN_LGAMMAL_R
:
4193 case BUILT_IN_MODFF
:
4194 case BUILT_IN_MODFL
:
4195 case BUILT_IN_REMQUO
:
4196 case BUILT_IN_REMQUOF
:
4197 case BUILT_IN_REMQUOL
:
4200 case BUILT_IN_STRDUP
:
4201 case BUILT_IN_STRNDUP
:
4202 if (gimple_call_lhs (t
))
4204 handle_lhs_call (t
, gimple_call_lhs (t
), gimple_call_flags (t
),
4206 get_constraint_for_ptr_offset (gimple_call_lhs (t
),
4208 get_constraint_for_ptr_offset (gimple_call_arg (t
, 0),
4212 process_all_all_constraints (lhsc
, rhsc
);
4218 /* Trampolines are special - they set up passing the static
4220 case BUILT_IN_INIT_TRAMPOLINE
:
4222 tree tramp
= gimple_call_arg (t
, 0);
4223 tree nfunc
= gimple_call_arg (t
, 1);
4224 tree frame
= gimple_call_arg (t
, 2);
4226 struct constraint_expr lhs
, *rhsp
;
4229 varinfo_t nfi
= NULL
;
4230 gcc_assert (TREE_CODE (nfunc
) == ADDR_EXPR
);
4231 nfi
= lookup_vi_for_tree (TREE_OPERAND (nfunc
, 0));
4234 lhs
= get_function_part_constraint (nfi
, fi_static_chain
);
4235 get_constraint_for (frame
, &rhsc
);
4236 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
4237 process_constraint (new_constraint (lhs
, *rhsp
));
4240 /* Make the frame point to the function for
4241 the trampoline adjustment call. */
4242 get_constraint_for (tramp
, &lhsc
);
4244 get_constraint_for (nfunc
, &rhsc
);
4245 process_all_all_constraints (lhsc
, rhsc
);
4252 /* Else fallthru to generic handling which will let
4253 the frame escape. */
4256 case BUILT_IN_ADJUST_TRAMPOLINE
:
4258 tree tramp
= gimple_call_arg (t
, 0);
4259 tree res
= gimple_call_lhs (t
);
4260 if (in_ipa_mode
&& res
)
4262 get_constraint_for (res
, &lhsc
);
4263 get_constraint_for (tramp
, &rhsc
);
4265 process_all_all_constraints (lhsc
, rhsc
);
4271 CASE_BUILT_IN_TM_STORE (1):
4272 CASE_BUILT_IN_TM_STORE (2):
4273 CASE_BUILT_IN_TM_STORE (4):
4274 CASE_BUILT_IN_TM_STORE (8):
4275 CASE_BUILT_IN_TM_STORE (FLOAT
):
4276 CASE_BUILT_IN_TM_STORE (DOUBLE
):
4277 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
4278 CASE_BUILT_IN_TM_STORE (M64
):
4279 CASE_BUILT_IN_TM_STORE (M128
):
4280 CASE_BUILT_IN_TM_STORE (M256
):
4282 tree addr
= gimple_call_arg (t
, 0);
4283 tree src
= gimple_call_arg (t
, 1);
4285 get_constraint_for (addr
, &lhsc
);
4287 get_constraint_for (src
, &rhsc
);
4288 process_all_all_constraints (lhsc
, rhsc
);
4293 CASE_BUILT_IN_TM_LOAD (1):
4294 CASE_BUILT_IN_TM_LOAD (2):
4295 CASE_BUILT_IN_TM_LOAD (4):
4296 CASE_BUILT_IN_TM_LOAD (8):
4297 CASE_BUILT_IN_TM_LOAD (FLOAT
):
4298 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
4299 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
4300 CASE_BUILT_IN_TM_LOAD (M64
):
4301 CASE_BUILT_IN_TM_LOAD (M128
):
4302 CASE_BUILT_IN_TM_LOAD (M256
):
4304 tree dest
= gimple_call_lhs (t
);
4305 tree addr
= gimple_call_arg (t
, 0);
4307 get_constraint_for (dest
, &lhsc
);
4308 get_constraint_for (addr
, &rhsc
);
4310 process_all_all_constraints (lhsc
, rhsc
);
4315 /* Variadic argument handling needs to be handled in IPA
4317 case BUILT_IN_VA_START
:
4319 tree valist
= gimple_call_arg (t
, 0);
4320 struct constraint_expr rhs
, *lhsp
;
4322 get_constraint_for (valist
, &lhsc
);
4324 /* The va_list gets access to pointers in variadic
4325 arguments. Which we know in the case of IPA analysis
4326 and otherwise are just all nonlocal variables. */
4329 fi
= lookup_vi_for_tree (cfun
->decl
);
4330 rhs
= get_function_part_constraint (fi
, ~0);
4331 rhs
.type
= ADDRESSOF
;
4335 rhs
.var
= nonlocal_id
;
4336 rhs
.type
= ADDRESSOF
;
4339 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
4340 process_constraint (new_constraint (*lhsp
, rhs
));
4342 /* va_list is clobbered. */
4343 make_constraint_to (get_call_clobber_vi (t
)->id
, valist
);
4346 /* va_end doesn't have any effect that matters. */
4347 case BUILT_IN_VA_END
:
4349 /* Alternate return. Simply give up for now. */
4350 case BUILT_IN_RETURN
:
4354 || !(fi
= get_vi_for_tree (cfun
->decl
)))
4355 make_constraint_from (get_varinfo (escaped_id
), anything_id
);
4356 else if (in_ipa_mode
4359 struct constraint_expr lhs
, rhs
;
4360 lhs
= get_function_part_constraint (fi
, fi_result
);
4361 rhs
.var
= anything_id
;
4364 process_constraint (new_constraint (lhs
, rhs
));
4368 /* printf-style functions may have hooks to set pointers to
4369 point to somewhere into the generated string. Leave them
4370 for a later excercise... */
4372 /* Fallthru to general call handling. */;
4378 /* Create constraints for the call T. */
4381 find_func_aliases_for_call (gimple t
)
4383 tree fndecl
= gimple_call_fndecl (t
);
4384 vec
<ce_s
> lhsc
= vNULL
;
4385 vec
<ce_s
> rhsc
= vNULL
;
4388 if (fndecl
!= NULL_TREE
4389 && DECL_BUILT_IN (fndecl
)
4390 && find_func_aliases_for_builtin_call (t
))
4393 fi
= get_fi_for_callee (t
);
4395 || (fndecl
&& !fi
->is_fn_info
))
4397 vec
<ce_s
> rhsc
= vNULL
;
4398 int flags
= gimple_call_flags (t
);
4400 /* Const functions can return their arguments and addresses
4401 of global memory but not of escaped memory. */
4402 if (flags
& (ECF_CONST
|ECF_NOVOPS
))
4404 if (gimple_call_lhs (t
))
4405 handle_const_call (t
, &rhsc
);
4407 /* Pure functions can return addresses in and of memory
4408 reachable from their arguments, but they are not an escape
4409 point for reachable memory of their arguments. */
4410 else if (flags
& (ECF_PURE
|ECF_LOOPING_CONST_OR_PURE
))
4411 handle_pure_call (t
, &rhsc
);
4413 handle_rhs_call (t
, &rhsc
);
4414 if (gimple_call_lhs (t
))
4415 handle_lhs_call (t
, gimple_call_lhs (t
), flags
, rhsc
, fndecl
);
4423 /* Assign all the passed arguments to the appropriate incoming
4424 parameters of the function. */
4425 for (j
= 0; j
< gimple_call_num_args (t
); j
++)
4427 struct constraint_expr lhs
;
4428 struct constraint_expr
*rhsp
;
4429 tree arg
= gimple_call_arg (t
, j
);
4431 get_constraint_for_rhs (arg
, &rhsc
);
4432 lhs
= get_function_part_constraint (fi
, fi_parm_base
+ j
);
4433 while (rhsc
.length () != 0)
4435 rhsp
= &rhsc
.last ();
4436 process_constraint (new_constraint (lhs
, *rhsp
));
4441 /* If we are returning a value, assign it to the result. */
4442 lhsop
= gimple_call_lhs (t
);
4445 struct constraint_expr rhs
;
4446 struct constraint_expr
*lhsp
;
4448 get_constraint_for (lhsop
, &lhsc
);
4449 rhs
= get_function_part_constraint (fi
, fi_result
);
4451 && DECL_RESULT (fndecl
)
4452 && DECL_BY_REFERENCE (DECL_RESULT (fndecl
)))
4454 vec
<ce_s
> tem
= vNULL
;
4455 tem
.safe_push (rhs
);
4460 FOR_EACH_VEC_ELT (lhsc
, j
, lhsp
)
4461 process_constraint (new_constraint (*lhsp
, rhs
));
4464 /* If we pass the result decl by reference, honor that. */
4467 && DECL_RESULT (fndecl
)
4468 && DECL_BY_REFERENCE (DECL_RESULT (fndecl
)))
4470 struct constraint_expr lhs
;
4471 struct constraint_expr
*rhsp
;
4473 get_constraint_for_address_of (lhsop
, &rhsc
);
4474 lhs
= get_function_part_constraint (fi
, fi_result
);
4475 FOR_EACH_VEC_ELT (rhsc
, j
, rhsp
)
4476 process_constraint (new_constraint (lhs
, *rhsp
));
4480 /* If we use a static chain, pass it along. */
4481 if (gimple_call_chain (t
))
4483 struct constraint_expr lhs
;
4484 struct constraint_expr
*rhsp
;
4486 get_constraint_for (gimple_call_chain (t
), &rhsc
);
4487 lhs
= get_function_part_constraint (fi
, fi_static_chain
);
4488 FOR_EACH_VEC_ELT (rhsc
, j
, rhsp
)
4489 process_constraint (new_constraint (lhs
, *rhsp
));
4494 /* Walk statement T setting up aliasing constraints according to the
4495 references found in T. This function is the main part of the
4496 constraint builder. AI points to auxiliary alias information used
4497 when building alias sets and computing alias grouping heuristics. */
4500 find_func_aliases (gimple origt
)
4503 vec
<ce_s
> lhsc
= vNULL
;
4504 vec
<ce_s
> rhsc
= vNULL
;
4505 struct constraint_expr
*c
;
4508 /* Now build constraints expressions. */
4509 if (gimple_code (t
) == GIMPLE_PHI
)
4514 /* For a phi node, assign all the arguments to
4516 get_constraint_for (gimple_phi_result (t
), &lhsc
);
4517 for (i
= 0; i
< gimple_phi_num_args (t
); i
++)
4519 tree strippedrhs
= PHI_ARG_DEF (t
, i
);
4521 STRIP_NOPS (strippedrhs
);
4522 get_constraint_for_rhs (gimple_phi_arg_def (t
, i
), &rhsc
);
4524 FOR_EACH_VEC_ELT (lhsc
, j
, c
)
4526 struct constraint_expr
*c2
;
4527 while (rhsc
.length () > 0)
4530 process_constraint (new_constraint (*c
, *c2
));
4536 /* In IPA mode, we need to generate constraints to pass call
4537 arguments through their calls. There are two cases,
4538 either a GIMPLE_CALL returning a value, or just a plain
4539 GIMPLE_CALL when we are not.
4541 In non-ipa mode, we need to generate constraints for each
4542 pointer passed by address. */
4543 else if (is_gimple_call (t
))
4544 find_func_aliases_for_call (t
);
4546 /* Otherwise, just a regular assignment statement. Only care about
4547 operations with pointer result, others are dealt with as escape
4548 points if they have pointer operands. */
4549 else if (is_gimple_assign (t
))
4551 /* Otherwise, just a regular assignment statement. */
4552 tree lhsop
= gimple_assign_lhs (t
);
4553 tree rhsop
= (gimple_num_ops (t
) == 2) ? gimple_assign_rhs1 (t
) : NULL
;
4555 if (rhsop
&& TREE_CLOBBER_P (rhsop
))
4556 /* Ignore clobbers, they don't actually store anything into
4559 else if (rhsop
&& AGGREGATE_TYPE_P (TREE_TYPE (lhsop
)))
4560 do_structure_copy (lhsop
, rhsop
);
4563 enum tree_code code
= gimple_assign_rhs_code (t
);
4565 get_constraint_for (lhsop
, &lhsc
);
4567 if (code
== POINTER_PLUS_EXPR
)
4568 get_constraint_for_ptr_offset (gimple_assign_rhs1 (t
),
4569 gimple_assign_rhs2 (t
), &rhsc
);
4570 else if (code
== BIT_AND_EXPR
4571 && TREE_CODE (gimple_assign_rhs2 (t
)) == INTEGER_CST
)
4573 /* Aligning a pointer via a BIT_AND_EXPR is offsetting
4574 the pointer. Handle it by offsetting it by UNKNOWN. */
4575 get_constraint_for_ptr_offset (gimple_assign_rhs1 (t
),
4578 else if ((CONVERT_EXPR_CODE_P (code
)
4579 && !(POINTER_TYPE_P (gimple_expr_type (t
))
4580 && !POINTER_TYPE_P (TREE_TYPE (rhsop
))))
4581 || gimple_assign_single_p (t
))
4582 get_constraint_for_rhs (rhsop
, &rhsc
);
4583 else if (code
== COND_EXPR
)
4585 /* The result is a merge of both COND_EXPR arms. */
4586 vec
<ce_s
> tmp
= vNULL
;
4587 struct constraint_expr
*rhsp
;
4589 get_constraint_for_rhs (gimple_assign_rhs2 (t
), &rhsc
);
4590 get_constraint_for_rhs (gimple_assign_rhs3 (t
), &tmp
);
4591 FOR_EACH_VEC_ELT (tmp
, i
, rhsp
)
4592 rhsc
.safe_push (*rhsp
);
4595 else if (truth_value_p (code
))
4596 /* Truth value results are not pointer (parts). Or at least
4597 very very unreasonable obfuscation of a part. */
4601 /* All other operations are merges. */
4602 vec
<ce_s
> tmp
= vNULL
;
4603 struct constraint_expr
*rhsp
;
4605 get_constraint_for_rhs (gimple_assign_rhs1 (t
), &rhsc
);
4606 for (i
= 2; i
< gimple_num_ops (t
); ++i
)
4608 get_constraint_for_rhs (gimple_op (t
, i
), &tmp
);
4609 FOR_EACH_VEC_ELT (tmp
, j
, rhsp
)
4610 rhsc
.safe_push (*rhsp
);
4615 process_all_all_constraints (lhsc
, rhsc
);
4617 /* If there is a store to a global variable the rhs escapes. */
4618 if ((lhsop
= get_base_address (lhsop
)) != NULL_TREE
4620 && is_global_var (lhsop
)
4622 || DECL_EXTERNAL (lhsop
) || TREE_PUBLIC (lhsop
)))
4623 make_escape_constraint (rhsop
);
4625 /* Handle escapes through return. */
4626 else if (gimple_code (t
) == GIMPLE_RETURN
4627 && gimple_return_retval (t
) != NULL_TREE
)
4631 || !(fi
= get_vi_for_tree (cfun
->decl
)))
4632 make_escape_constraint (gimple_return_retval (t
));
4633 else if (in_ipa_mode
4636 struct constraint_expr lhs
;
4637 struct constraint_expr
*rhsp
;
4640 lhs
= get_function_part_constraint (fi
, fi_result
);
4641 get_constraint_for_rhs (gimple_return_retval (t
), &rhsc
);
4642 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
4643 process_constraint (new_constraint (lhs
, *rhsp
));
4646 /* Handle asms conservatively by adding escape constraints to everything. */
4647 else if (gimple_code (t
) == GIMPLE_ASM
)
4649 unsigned i
, noutputs
;
4650 const char **oconstraints
;
4651 const char *constraint
;
4652 bool allows_mem
, allows_reg
, is_inout
;
4654 noutputs
= gimple_asm_noutputs (t
);
4655 oconstraints
= XALLOCAVEC (const char *, noutputs
);
4657 for (i
= 0; i
< noutputs
; ++i
)
4659 tree link
= gimple_asm_output_op (t
, i
);
4660 tree op
= TREE_VALUE (link
);
4662 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
4663 oconstraints
[i
] = constraint
;
4664 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
4665 &allows_reg
, &is_inout
);
4667 /* A memory constraint makes the address of the operand escape. */
4668 if (!allows_reg
&& allows_mem
)
4669 make_escape_constraint (build_fold_addr_expr (op
));
4671 /* The asm may read global memory, so outputs may point to
4672 any global memory. */
4675 vec
<ce_s
> lhsc
= vNULL
;
4676 struct constraint_expr rhsc
, *lhsp
;
4678 get_constraint_for (op
, &lhsc
);
4679 rhsc
.var
= nonlocal_id
;
4682 FOR_EACH_VEC_ELT (lhsc
, j
, lhsp
)
4683 process_constraint (new_constraint (*lhsp
, rhsc
));
4687 for (i
= 0; i
< gimple_asm_ninputs (t
); ++i
)
4689 tree link
= gimple_asm_input_op (t
, i
);
4690 tree op
= TREE_VALUE (link
);
4692 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link
)));
4694 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0, oconstraints
,
4695 &allows_mem
, &allows_reg
);
4697 /* A memory constraint makes the address of the operand escape. */
4698 if (!allows_reg
&& allows_mem
)
4699 make_escape_constraint (build_fold_addr_expr (op
));
4700 /* Strictly we'd only need the constraint to ESCAPED if
4701 the asm clobbers memory, otherwise using something
4702 along the lines of per-call clobbers/uses would be enough. */
4704 make_escape_constraint (op
);
4713 /* Create a constraint adding to the clobber set of FI the memory
4714 pointed to by PTR. */
4717 process_ipa_clobber (varinfo_t fi
, tree ptr
)
4719 vec
<ce_s
> ptrc
= vNULL
;
4720 struct constraint_expr
*c
, lhs
;
4722 get_constraint_for_rhs (ptr
, &ptrc
);
4723 lhs
= get_function_part_constraint (fi
, fi_clobbers
);
4724 FOR_EACH_VEC_ELT (ptrc
, i
, c
)
4725 process_constraint (new_constraint (lhs
, *c
));
4729 /* Walk statement T setting up clobber and use constraints according to the
4730 references found in T. This function is a main part of the
4731 IPA constraint builder. */
4734 find_func_clobbers (gimple origt
)
4737 vec
<ce_s
> lhsc
= vNULL
;
4738 vec
<ce_s
> rhsc
= vNULL
;
4741 /* Add constraints for clobbered/used in IPA mode.
4742 We are not interested in what automatic variables are clobbered
4743 or used as we only use the information in the caller to which
4744 they do not escape. */
4745 gcc_assert (in_ipa_mode
);
4747 /* If the stmt refers to memory in any way it better had a VUSE. */
4748 if (gimple_vuse (t
) == NULL_TREE
)
4751 /* We'd better have function information for the current function. */
4752 fi
= lookup_vi_for_tree (cfun
->decl
);
4753 gcc_assert (fi
!= NULL
);
4755 /* Account for stores in assignments and calls. */
4756 if (gimple_vdef (t
) != NULL_TREE
4757 && gimple_has_lhs (t
))
4759 tree lhs
= gimple_get_lhs (t
);
4761 while (handled_component_p (tem
))
4762 tem
= TREE_OPERAND (tem
, 0);
4764 && !auto_var_in_fn_p (tem
, cfun
->decl
))
4765 || INDIRECT_REF_P (tem
)
4766 || (TREE_CODE (tem
) == MEM_REF
4767 && !(TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
4769 (TREE_OPERAND (TREE_OPERAND (tem
, 0), 0), cfun
->decl
))))
4771 struct constraint_expr lhsc
, *rhsp
;
4773 lhsc
= get_function_part_constraint (fi
, fi_clobbers
);
4774 get_constraint_for_address_of (lhs
, &rhsc
);
4775 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
4776 process_constraint (new_constraint (lhsc
, *rhsp
));
4781 /* Account for uses in assigments and returns. */
4782 if (gimple_assign_single_p (t
)
4783 || (gimple_code (t
) == GIMPLE_RETURN
4784 && gimple_return_retval (t
) != NULL_TREE
))
4786 tree rhs
= (gimple_assign_single_p (t
)
4787 ? gimple_assign_rhs1 (t
) : gimple_return_retval (t
));
4789 while (handled_component_p (tem
))
4790 tem
= TREE_OPERAND (tem
, 0);
4792 && !auto_var_in_fn_p (tem
, cfun
->decl
))
4793 || INDIRECT_REF_P (tem
)
4794 || (TREE_CODE (tem
) == MEM_REF
4795 && !(TREE_CODE (TREE_OPERAND (tem
, 0)) == ADDR_EXPR
4797 (TREE_OPERAND (TREE_OPERAND (tem
, 0), 0), cfun
->decl
))))
4799 struct constraint_expr lhs
, *rhsp
;
4801 lhs
= get_function_part_constraint (fi
, fi_uses
);
4802 get_constraint_for_address_of (rhs
, &rhsc
);
4803 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
4804 process_constraint (new_constraint (lhs
, *rhsp
));
4809 if (is_gimple_call (t
))
4811 varinfo_t cfi
= NULL
;
4812 tree decl
= gimple_call_fndecl (t
);
4813 struct constraint_expr lhs
, rhs
;
4816 /* For builtins we do not have separate function info. For those
4817 we do not generate escapes for we have to generate clobbers/uses. */
4818 if (gimple_call_builtin_p (t
, BUILT_IN_NORMAL
))
4819 switch (DECL_FUNCTION_CODE (decl
))
4821 /* The following functions use and clobber memory pointed to
4822 by their arguments. */
4823 case BUILT_IN_STRCPY
:
4824 case BUILT_IN_STRNCPY
:
4825 case BUILT_IN_BCOPY
:
4826 case BUILT_IN_MEMCPY
:
4827 case BUILT_IN_MEMMOVE
:
4828 case BUILT_IN_MEMPCPY
:
4829 case BUILT_IN_STPCPY
:
4830 case BUILT_IN_STPNCPY
:
4831 case BUILT_IN_STRCAT
:
4832 case BUILT_IN_STRNCAT
:
4833 case BUILT_IN_STRCPY_CHK
:
4834 case BUILT_IN_STRNCPY_CHK
:
4835 case BUILT_IN_MEMCPY_CHK
:
4836 case BUILT_IN_MEMMOVE_CHK
:
4837 case BUILT_IN_MEMPCPY_CHK
:
4838 case BUILT_IN_STPCPY_CHK
:
4839 case BUILT_IN_STPNCPY_CHK
:
4840 case BUILT_IN_STRCAT_CHK
:
4841 case BUILT_IN_STRNCAT_CHK
:
4843 tree dest
= gimple_call_arg (t
, (DECL_FUNCTION_CODE (decl
)
4844 == BUILT_IN_BCOPY
? 1 : 0));
4845 tree src
= gimple_call_arg (t
, (DECL_FUNCTION_CODE (decl
)
4846 == BUILT_IN_BCOPY
? 0 : 1));
4848 struct constraint_expr
*rhsp
, *lhsp
;
4849 get_constraint_for_ptr_offset (dest
, NULL_TREE
, &lhsc
);
4850 lhs
= get_function_part_constraint (fi
, fi_clobbers
);
4851 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
4852 process_constraint (new_constraint (lhs
, *lhsp
));
4854 get_constraint_for_ptr_offset (src
, NULL_TREE
, &rhsc
);
4855 lhs
= get_function_part_constraint (fi
, fi_uses
);
4856 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
4857 process_constraint (new_constraint (lhs
, *rhsp
));
4861 /* The following function clobbers memory pointed to by
4863 case BUILT_IN_MEMSET
:
4864 case BUILT_IN_MEMSET_CHK
:
4866 tree dest
= gimple_call_arg (t
, 0);
4869 get_constraint_for_ptr_offset (dest
, NULL_TREE
, &lhsc
);
4870 lhs
= get_function_part_constraint (fi
, fi_clobbers
);
4871 FOR_EACH_VEC_ELT (lhsc
, i
, lhsp
)
4872 process_constraint (new_constraint (lhs
, *lhsp
));
4876 /* The following functions clobber their second and third
4878 case BUILT_IN_SINCOS
:
4879 case BUILT_IN_SINCOSF
:
4880 case BUILT_IN_SINCOSL
:
4882 process_ipa_clobber (fi
, gimple_call_arg (t
, 1));
4883 process_ipa_clobber (fi
, gimple_call_arg (t
, 2));
4886 /* The following functions clobber their second argument. */
4887 case BUILT_IN_FREXP
:
4888 case BUILT_IN_FREXPF
:
4889 case BUILT_IN_FREXPL
:
4890 case BUILT_IN_LGAMMA_R
:
4891 case BUILT_IN_LGAMMAF_R
:
4892 case BUILT_IN_LGAMMAL_R
:
4893 case BUILT_IN_GAMMA_R
:
4894 case BUILT_IN_GAMMAF_R
:
4895 case BUILT_IN_GAMMAL_R
:
4897 case BUILT_IN_MODFF
:
4898 case BUILT_IN_MODFL
:
4900 process_ipa_clobber (fi
, gimple_call_arg (t
, 1));
4903 /* The following functions clobber their third argument. */
4904 case BUILT_IN_REMQUO
:
4905 case BUILT_IN_REMQUOF
:
4906 case BUILT_IN_REMQUOL
:
4908 process_ipa_clobber (fi
, gimple_call_arg (t
, 2));
4911 /* The following functions neither read nor clobber memory. */
4912 case BUILT_IN_ASSUME_ALIGNED
:
4915 /* Trampolines are of no interest to us. */
4916 case BUILT_IN_INIT_TRAMPOLINE
:
4917 case BUILT_IN_ADJUST_TRAMPOLINE
:
4919 case BUILT_IN_VA_START
:
4920 case BUILT_IN_VA_END
:
4922 /* printf-style functions may have hooks to set pointers to
4923 point to somewhere into the generated string. Leave them
4924 for a later excercise... */
4926 /* Fallthru to general call handling. */;
4929 /* Parameters passed by value are used. */
4930 lhs
= get_function_part_constraint (fi
, fi_uses
);
4931 for (i
= 0; i
< gimple_call_num_args (t
); i
++)
4933 struct constraint_expr
*rhsp
;
4934 tree arg
= gimple_call_arg (t
, i
);
4936 if (TREE_CODE (arg
) == SSA_NAME
4937 || is_gimple_min_invariant (arg
))
4940 get_constraint_for_address_of (arg
, &rhsc
);
4941 FOR_EACH_VEC_ELT (rhsc
, j
, rhsp
)
4942 process_constraint (new_constraint (lhs
, *rhsp
));
4946 /* Build constraints for propagating clobbers/uses along the
4948 cfi
= get_fi_for_callee (t
);
4949 if (cfi
->id
== anything_id
)
4951 if (gimple_vdef (t
))
4952 make_constraint_from (first_vi_for_offset (fi
, fi_clobbers
),
4954 make_constraint_from (first_vi_for_offset (fi
, fi_uses
),
4959 /* For callees without function info (that's external functions),
4960 ESCAPED is clobbered and used. */
4961 if (gimple_call_fndecl (t
)
4962 && !cfi
->is_fn_info
)
4966 if (gimple_vdef (t
))
4967 make_copy_constraint (first_vi_for_offset (fi
, fi_clobbers
),
4969 make_copy_constraint (first_vi_for_offset (fi
, fi_uses
), escaped_id
);
4971 /* Also honor the call statement use/clobber info. */
4972 if ((vi
= lookup_call_clobber_vi (t
)) != NULL
)
4973 make_copy_constraint (first_vi_for_offset (fi
, fi_clobbers
),
4975 if ((vi
= lookup_call_use_vi (t
)) != NULL
)
4976 make_copy_constraint (first_vi_for_offset (fi
, fi_uses
),
4981 /* Otherwise the caller clobbers and uses what the callee does.
4982 ??? This should use a new complex constraint that filters
4983 local variables of the callee. */
4984 if (gimple_vdef (t
))
4986 lhs
= get_function_part_constraint (fi
, fi_clobbers
);
4987 rhs
= get_function_part_constraint (cfi
, fi_clobbers
);
4988 process_constraint (new_constraint (lhs
, rhs
));
4990 lhs
= get_function_part_constraint (fi
, fi_uses
);
4991 rhs
= get_function_part_constraint (cfi
, fi_uses
);
4992 process_constraint (new_constraint (lhs
, rhs
));
4994 else if (gimple_code (t
) == GIMPLE_ASM
)
4996 /* ??? Ick. We can do better. */
4997 if (gimple_vdef (t
))
4998 make_constraint_from (first_vi_for_offset (fi
, fi_clobbers
),
5000 make_constraint_from (first_vi_for_offset (fi
, fi_uses
),
5008 /* Find the first varinfo in the same variable as START that overlaps with
5009 OFFSET. Return NULL if we can't find one. */
5012 first_vi_for_offset (varinfo_t start
, unsigned HOST_WIDE_INT offset
)
5014 /* If the offset is outside of the variable, bail out. */
5015 if (offset
>= start
->fullsize
)
5018 /* If we cannot reach offset from start, lookup the first field
5019 and start from there. */
5020 if (start
->offset
> offset
)
5021 start
= lookup_vi_for_tree (start
->decl
);
5025 /* We may not find a variable in the field list with the actual
5026 offset when when we have glommed a structure to a variable.
5027 In that case, however, offset should still be within the size
5029 if (offset
>= start
->offset
5030 && (offset
- start
->offset
) < start
->size
)
5039 /* Find the first varinfo in the same variable as START that overlaps with
5040 OFFSET. If there is no such varinfo the varinfo directly preceding
5041 OFFSET is returned. */
5044 first_or_preceding_vi_for_offset (varinfo_t start
,
5045 unsigned HOST_WIDE_INT offset
)
5047 /* If we cannot reach offset from start, lookup the first field
5048 and start from there. */
5049 if (start
->offset
> offset
)
5050 start
= lookup_vi_for_tree (start
->decl
);
5052 /* We may not find a variable in the field list with the actual
5053 offset when when we have glommed a structure to a variable.
5054 In that case, however, offset should still be within the size
5056 If we got beyond the offset we look for return the field
5057 directly preceding offset which may be the last field. */
5059 && offset
>= start
->offset
5060 && !((offset
- start
->offset
) < start
->size
))
5061 start
= start
->next
;
5067 /* This structure is used during pushing fields onto the fieldstack
5068 to track the offset of the field, since bitpos_of_field gives it
5069 relative to its immediate containing type, and we want it relative
5070 to the ultimate containing object. */
5074 /* Offset from the base of the base containing object to this field. */
5075 HOST_WIDE_INT offset
;
5077 /* Size, in bits, of the field. */
5078 unsigned HOST_WIDE_INT size
;
5080 unsigned has_unknown_size
: 1;
5082 unsigned must_have_pointers
: 1;
5084 unsigned may_have_pointers
: 1;
5086 unsigned only_restrict_pointers
: 1;
5088 typedef struct fieldoff fieldoff_s
;
5091 /* qsort comparison function for two fieldoff's PA and PB */
5094 fieldoff_compare (const void *pa
, const void *pb
)
5096 const fieldoff_s
*foa
= (const fieldoff_s
*)pa
;
5097 const fieldoff_s
*fob
= (const fieldoff_s
*)pb
;
5098 unsigned HOST_WIDE_INT foasize
, fobsize
;
5100 if (foa
->offset
< fob
->offset
)
5102 else if (foa
->offset
> fob
->offset
)
5105 foasize
= foa
->size
;
5106 fobsize
= fob
->size
;
5107 if (foasize
< fobsize
)
5109 else if (foasize
> fobsize
)
5114 /* Sort a fieldstack according to the field offset and sizes. */
5116 sort_fieldstack (vec
<fieldoff_s
> fieldstack
)
5118 fieldstack
.qsort (fieldoff_compare
);
5121 /* Return true if T is a type that can have subvars. */
5124 type_can_have_subvars (const_tree t
)
5126 /* Aggregates without overlapping fields can have subvars. */
5127 return TREE_CODE (t
) == RECORD_TYPE
;
5130 /* Return true if V is a tree that we can have subvars for.
5131 Normally, this is any aggregate type. Also complex
5132 types which are not gimple registers can have subvars. */
5135 var_can_have_subvars (const_tree v
)
5137 /* Volatile variables should never have subvars. */
5138 if (TREE_THIS_VOLATILE (v
))
5141 /* Non decls or memory tags can never have subvars. */
5145 return type_can_have_subvars (TREE_TYPE (v
));
5148 /* Return true if T is a type that does contain pointers. */
5151 type_must_have_pointers (tree type
)
5153 if (POINTER_TYPE_P (type
))
5156 if (TREE_CODE (type
) == ARRAY_TYPE
)
5157 return type_must_have_pointers (TREE_TYPE (type
));
5159 /* A function or method can have pointers as arguments, so track
5160 those separately. */
5161 if (TREE_CODE (type
) == FUNCTION_TYPE
5162 || TREE_CODE (type
) == METHOD_TYPE
)
5169 field_must_have_pointers (tree t
)
5171 return type_must_have_pointers (TREE_TYPE (t
));
5174 /* Given a TYPE, and a vector of field offsets FIELDSTACK, push all
5175 the fields of TYPE onto fieldstack, recording their offsets along
5178 OFFSET is used to keep track of the offset in this entire
5179 structure, rather than just the immediately containing structure.
5180 Returns false if the caller is supposed to handle the field we
5184 push_fields_onto_fieldstack (tree type
, vec
<fieldoff_s
> *fieldstack
,
5185 HOST_WIDE_INT offset
)
5188 bool empty_p
= true;
5190 if (TREE_CODE (type
) != RECORD_TYPE
)
5193 /* If the vector of fields is growing too big, bail out early.
5194 Callers check for vec::length <= MAX_FIELDS_FOR_FIELD_SENSITIVE, make
5196 if (fieldstack
->length () > MAX_FIELDS_FOR_FIELD_SENSITIVE
)
5199 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
5200 if (TREE_CODE (field
) == FIELD_DECL
)
5203 HOST_WIDE_INT foff
= bitpos_of_field (field
);
5205 if (!var_can_have_subvars (field
)
5206 || TREE_CODE (TREE_TYPE (field
)) == QUAL_UNION_TYPE
5207 || TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
5209 else if (!push_fields_onto_fieldstack
5210 (TREE_TYPE (field
), fieldstack
, offset
+ foff
)
5211 && (DECL_SIZE (field
)
5212 && !integer_zerop (DECL_SIZE (field
))))
5213 /* Empty structures may have actual size, like in C++. So
5214 see if we didn't push any subfields and the size is
5215 nonzero, push the field onto the stack. */
5220 fieldoff_s
*pair
= NULL
;
5221 bool has_unknown_size
= false;
5222 bool must_have_pointers_p
;
5224 if (!fieldstack
->is_empty ())
5225 pair
= &fieldstack
->last ();
5227 /* If there isn't anything at offset zero, create sth. */
5229 && offset
+ foff
!= 0)
5231 fieldoff_s e
= {0, offset
+ foff
, false, false, false, false};
5232 pair
= fieldstack
->safe_push (e
);
5235 if (!DECL_SIZE (field
)
5236 || !host_integerp (DECL_SIZE (field
), 1))
5237 has_unknown_size
= true;
5239 /* If adjacent fields do not contain pointers merge them. */
5240 must_have_pointers_p
= field_must_have_pointers (field
);
5242 && !has_unknown_size
5243 && !must_have_pointers_p
5244 && !pair
->must_have_pointers
5245 && !pair
->has_unknown_size
5246 && pair
->offset
+ (HOST_WIDE_INT
)pair
->size
== offset
+ foff
)
5248 pair
->size
+= TREE_INT_CST_LOW (DECL_SIZE (field
));
5253 e
.offset
= offset
+ foff
;
5254 e
.has_unknown_size
= has_unknown_size
;
5255 if (!has_unknown_size
)
5256 e
.size
= TREE_INT_CST_LOW (DECL_SIZE (field
));
5259 e
.must_have_pointers
= must_have_pointers_p
;
5260 e
.may_have_pointers
= true;
5261 e
.only_restrict_pointers
5262 = (!has_unknown_size
5263 && POINTER_TYPE_P (TREE_TYPE (field
))
5264 && TYPE_RESTRICT (TREE_TYPE (field
)));
5265 fieldstack
->safe_push (e
);
5275 /* Count the number of arguments DECL has, and set IS_VARARGS to true
5276 if it is a varargs function. */
5279 count_num_arguments (tree decl
, bool *is_varargs
)
5281 unsigned int num
= 0;
5284 /* Capture named arguments for K&R functions. They do not
5285 have a prototype and thus no TYPE_ARG_TYPES. */
5286 for (t
= DECL_ARGUMENTS (decl
); t
; t
= DECL_CHAIN (t
))
5289 /* Check if the function has variadic arguments. */
5290 for (t
= TYPE_ARG_TYPES (TREE_TYPE (decl
)); t
; t
= TREE_CHAIN (t
))
5291 if (TREE_VALUE (t
) == void_type_node
)
5299 /* Creation function node for DECL, using NAME, and return the index
5300 of the variable we've created for the function. */
5303 create_function_info_for (tree decl
, const char *name
)
5305 struct function
*fn
= DECL_STRUCT_FUNCTION (decl
);
5306 varinfo_t vi
, prev_vi
;
5309 bool is_varargs
= false;
5310 unsigned int num_args
= count_num_arguments (decl
, &is_varargs
);
5312 /* Create the variable info. */
5314 vi
= new_var_info (decl
, name
);
5317 vi
->fullsize
= fi_parm_base
+ num_args
;
5319 vi
->may_have_pointers
= false;
5322 insert_vi_for_tree (vi
->decl
, vi
);
5326 /* Create a variable for things the function clobbers and one for
5327 things the function uses. */
5329 varinfo_t clobbervi
, usevi
;
5330 const char *newname
;
5333 asprintf (&tempname
, "%s.clobber", name
);
5334 newname
= ggc_strdup (tempname
);
5337 clobbervi
= new_var_info (NULL
, newname
);
5338 clobbervi
->offset
= fi_clobbers
;
5339 clobbervi
->size
= 1;
5340 clobbervi
->fullsize
= vi
->fullsize
;
5341 clobbervi
->is_full_var
= true;
5342 clobbervi
->is_global_var
= false;
5343 gcc_assert (prev_vi
->offset
< clobbervi
->offset
);
5344 prev_vi
->next
= clobbervi
;
5345 prev_vi
= clobbervi
;
5347 asprintf (&tempname
, "%s.use", name
);
5348 newname
= ggc_strdup (tempname
);
5351 usevi
= new_var_info (NULL
, newname
);
5352 usevi
->offset
= fi_uses
;
5354 usevi
->fullsize
= vi
->fullsize
;
5355 usevi
->is_full_var
= true;
5356 usevi
->is_global_var
= false;
5357 gcc_assert (prev_vi
->offset
< usevi
->offset
);
5358 prev_vi
->next
= usevi
;
5362 /* And one for the static chain. */
5363 if (fn
->static_chain_decl
!= NULL_TREE
)
5366 const char *newname
;
5369 asprintf (&tempname
, "%s.chain", name
);
5370 newname
= ggc_strdup (tempname
);
5373 chainvi
= new_var_info (fn
->static_chain_decl
, newname
);
5374 chainvi
->offset
= fi_static_chain
;
5376 chainvi
->fullsize
= vi
->fullsize
;
5377 chainvi
->is_full_var
= true;
5378 chainvi
->is_global_var
= false;
5379 gcc_assert (prev_vi
->offset
< chainvi
->offset
);
5380 prev_vi
->next
= chainvi
;
5382 insert_vi_for_tree (fn
->static_chain_decl
, chainvi
);
5385 /* Create a variable for the return var. */
5386 if (DECL_RESULT (decl
) != NULL
5387 || !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl
))))
5390 const char *newname
;
5392 tree resultdecl
= decl
;
5394 if (DECL_RESULT (decl
))
5395 resultdecl
= DECL_RESULT (decl
);
5397 asprintf (&tempname
, "%s.result", name
);
5398 newname
= ggc_strdup (tempname
);
5401 resultvi
= new_var_info (resultdecl
, newname
);
5402 resultvi
->offset
= fi_result
;
5404 resultvi
->fullsize
= vi
->fullsize
;
5405 resultvi
->is_full_var
= true;
5406 if (DECL_RESULT (decl
))
5407 resultvi
->may_have_pointers
= true;
5408 gcc_assert (prev_vi
->offset
< resultvi
->offset
);
5409 prev_vi
->next
= resultvi
;
5411 if (DECL_RESULT (decl
))
5412 insert_vi_for_tree (DECL_RESULT (decl
), resultvi
);
5415 /* Set up variables for each argument. */
5416 arg
= DECL_ARGUMENTS (decl
);
5417 for (i
= 0; i
< num_args
; i
++)
5420 const char *newname
;
5422 tree argdecl
= decl
;
5427 asprintf (&tempname
, "%s.arg%d", name
, i
);
5428 newname
= ggc_strdup (tempname
);
5431 argvi
= new_var_info (argdecl
, newname
);
5432 argvi
->offset
= fi_parm_base
+ i
;
5434 argvi
->is_full_var
= true;
5435 argvi
->fullsize
= vi
->fullsize
;
5437 argvi
->may_have_pointers
= true;
5438 gcc_assert (prev_vi
->offset
< argvi
->offset
);
5439 prev_vi
->next
= argvi
;
5443 insert_vi_for_tree (arg
, argvi
);
5444 arg
= DECL_CHAIN (arg
);
5448 /* Add one representative for all further args. */
5452 const char *newname
;
5456 asprintf (&tempname
, "%s.varargs", name
);
5457 newname
= ggc_strdup (tempname
);
5460 /* We need sth that can be pointed to for va_start. */
5461 decl
= build_fake_var_decl (ptr_type_node
);
5463 argvi
= new_var_info (decl
, newname
);
5464 argvi
->offset
= fi_parm_base
+ num_args
;
5466 argvi
->is_full_var
= true;
5467 argvi
->is_heap_var
= true;
5468 argvi
->fullsize
= vi
->fullsize
;
5469 gcc_assert (prev_vi
->offset
< argvi
->offset
);
5470 prev_vi
->next
= argvi
;
5478 /* Return true if FIELDSTACK contains fields that overlap.
5479 FIELDSTACK is assumed to be sorted by offset. */
5482 check_for_overlaps (vec
<fieldoff_s
> fieldstack
)
5484 fieldoff_s
*fo
= NULL
;
5486 HOST_WIDE_INT lastoffset
= -1;
5488 FOR_EACH_VEC_ELT (fieldstack
, i
, fo
)
5490 if (fo
->offset
== lastoffset
)
5492 lastoffset
= fo
->offset
;
5497 /* Create a varinfo structure for NAME and DECL, and add it to VARMAP.
5498 This will also create any varinfo structures necessary for fields
5502 create_variable_info_for_1 (tree decl
, const char *name
)
5504 varinfo_t vi
, newvi
;
5505 tree decl_type
= TREE_TYPE (decl
);
5506 tree declsize
= DECL_P (decl
) ? DECL_SIZE (decl
) : TYPE_SIZE (decl_type
);
5507 vec
<fieldoff_s
> fieldstack
= vNULL
;
5512 || !host_integerp (declsize
, 1))
5514 vi
= new_var_info (decl
, name
);
5518 vi
->is_unknown_size_var
= true;
5519 vi
->is_full_var
= true;
5520 vi
->may_have_pointers
= true;
5524 /* Collect field information. */
5525 if (use_field_sensitive
5526 && var_can_have_subvars (decl
)
5527 /* ??? Force us to not use subfields for global initializers
5528 in IPA mode. Else we'd have to parse arbitrary initializers. */
5530 && is_global_var (decl
)
5531 && DECL_INITIAL (decl
)))
5533 fieldoff_s
*fo
= NULL
;
5534 bool notokay
= false;
5537 push_fields_onto_fieldstack (decl_type
, &fieldstack
, 0);
5539 for (i
= 0; !notokay
&& fieldstack
.iterate (i
, &fo
); i
++)
5540 if (fo
->has_unknown_size
5547 /* We can't sort them if we have a field with a variable sized type,
5548 which will make notokay = true. In that case, we are going to return
5549 without creating varinfos for the fields anyway, so sorting them is a
5553 sort_fieldstack (fieldstack
);
5554 /* Due to some C++ FE issues, like PR 22488, we might end up
5555 what appear to be overlapping fields even though they,
5556 in reality, do not overlap. Until the C++ FE is fixed,
5557 we will simply disable field-sensitivity for these cases. */
5558 notokay
= check_for_overlaps (fieldstack
);
5562 fieldstack
.release ();
5565 /* If we didn't end up collecting sub-variables create a full
5566 variable for the decl. */
5567 if (fieldstack
.length () <= 1
5568 || fieldstack
.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE
)
5570 vi
= new_var_info (decl
, name
);
5572 vi
->may_have_pointers
= true;
5573 vi
->fullsize
= TREE_INT_CST_LOW (declsize
);
5574 vi
->size
= vi
->fullsize
;
5575 vi
->is_full_var
= true;
5576 fieldstack
.release ();
5580 vi
= new_var_info (decl
, name
);
5581 vi
->fullsize
= TREE_INT_CST_LOW (declsize
);
5582 for (i
= 0, newvi
= vi
;
5583 fieldstack
.iterate (i
, &fo
);
5584 ++i
, newvi
= newvi
->next
)
5586 const char *newname
= "NULL";
5591 asprintf (&tempname
, "%s." HOST_WIDE_INT_PRINT_DEC
5592 "+" HOST_WIDE_INT_PRINT_DEC
, name
, fo
->offset
, fo
->size
);
5593 newname
= ggc_strdup (tempname
);
5596 newvi
->name
= newname
;
5597 newvi
->offset
= fo
->offset
;
5598 newvi
->size
= fo
->size
;
5599 newvi
->fullsize
= vi
->fullsize
;
5600 newvi
->may_have_pointers
= fo
->may_have_pointers
;
5601 newvi
->only_restrict_pointers
= fo
->only_restrict_pointers
;
5602 if (i
+ 1 < fieldstack
.length ())
5603 newvi
->next
= new_var_info (decl
, name
);
5606 fieldstack
.release ();
5612 create_variable_info_for (tree decl
, const char *name
)
5614 varinfo_t vi
= create_variable_info_for_1 (decl
, name
);
5615 unsigned int id
= vi
->id
;
5617 insert_vi_for_tree (decl
, vi
);
5619 if (TREE_CODE (decl
) != VAR_DECL
)
5622 /* Create initial constraints for globals. */
5623 for (; vi
; vi
= vi
->next
)
5625 if (!vi
->may_have_pointers
5626 || !vi
->is_global_var
)
5629 /* Mark global restrict qualified pointers. */
5630 if ((POINTER_TYPE_P (TREE_TYPE (decl
))
5631 && TYPE_RESTRICT (TREE_TYPE (decl
)))
5632 || vi
->only_restrict_pointers
)
5634 make_constraint_from_global_restrict (vi
, "GLOBAL_RESTRICT");
5638 /* In non-IPA mode the initializer from nonlocal is all we need. */
5640 || DECL_HARD_REGISTER (decl
))
5641 make_copy_constraint (vi
, nonlocal_id
);
5643 /* In IPA mode parse the initializer and generate proper constraints
5647 struct varpool_node
*vnode
= varpool_get_node (decl
);
5649 /* For escaped variables initialize them from nonlocal. */
5650 if (!varpool_all_refs_explicit_p (vnode
))
5651 make_copy_constraint (vi
, nonlocal_id
);
5653 /* If this is a global variable with an initializer and we are in
5654 IPA mode generate constraints for it. */
5655 if (DECL_INITIAL (decl
)
5658 vec
<ce_s
> rhsc
= vNULL
;
5659 struct constraint_expr lhs
, *rhsp
;
5661 get_constraint_for_rhs (DECL_INITIAL (decl
), &rhsc
);
5665 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
5666 process_constraint (new_constraint (lhs
, *rhsp
));
5667 /* If this is a variable that escapes from the unit
5668 the initializer escapes as well. */
5669 if (!varpool_all_refs_explicit_p (vnode
))
5671 lhs
.var
= escaped_id
;
5674 FOR_EACH_VEC_ELT (rhsc
, i
, rhsp
)
5675 process_constraint (new_constraint (lhs
, *rhsp
));
5685 /* Print out the points-to solution for VAR to FILE. */
5688 dump_solution_for_var (FILE *file
, unsigned int var
)
5690 varinfo_t vi
= get_varinfo (var
);
5694 /* Dump the solution for unified vars anyway, this avoids difficulties
5695 in scanning dumps in the testsuite. */
5696 fprintf (file
, "%s = { ", vi
->name
);
5697 vi
= get_varinfo (find (var
));
5698 EXECUTE_IF_SET_IN_BITMAP (vi
->solution
, 0, i
, bi
)
5699 fprintf (file
, "%s ", get_varinfo (i
)->name
);
5700 fprintf (file
, "}");
5702 /* But note when the variable was unified. */
5704 fprintf (file
, " same as %s", vi
->name
);
5706 fprintf (file
, "\n");
5709 /* Print the points-to solution for VAR to stdout. */
5712 debug_solution_for_var (unsigned int var
)
5714 dump_solution_for_var (stdout
, var
);
5717 /* Create varinfo structures for all of the variables in the
5718 function for intraprocedural mode. */
5721 intra_create_variable_infos (void)
5725 /* For each incoming pointer argument arg, create the constraint ARG
5726 = NONLOCAL or a dummy variable if it is a restrict qualified
5727 passed-by-reference argument. */
5728 for (t
= DECL_ARGUMENTS (current_function_decl
); t
; t
= DECL_CHAIN (t
))
5730 varinfo_t p
= get_vi_for_tree (t
);
5732 /* For restrict qualified pointers to objects passed by
5733 reference build a real representative for the pointed-to object.
5734 Treat restrict qualified references the same. */
5735 if (TYPE_RESTRICT (TREE_TYPE (t
))
5736 && ((DECL_BY_REFERENCE (t
) && POINTER_TYPE_P (TREE_TYPE (t
)))
5737 || TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
5738 && !type_contains_placeholder_p (TREE_TYPE (TREE_TYPE (t
))))
5740 struct constraint_expr lhsc
, rhsc
;
5742 tree heapvar
= build_fake_var_decl (TREE_TYPE (TREE_TYPE (t
)));
5743 DECL_EXTERNAL (heapvar
) = 1;
5744 vi
= create_variable_info_for_1 (heapvar
, "PARM_NOALIAS");
5745 insert_vi_for_tree (heapvar
, vi
);
5750 rhsc
.type
= ADDRESSOF
;
5752 process_constraint (new_constraint (lhsc
, rhsc
));
5753 for (; vi
; vi
= vi
->next
)
5754 if (vi
->may_have_pointers
)
5756 if (vi
->only_restrict_pointers
)
5757 make_constraint_from_global_restrict (vi
, "GLOBAL_RESTRICT");
5759 make_copy_constraint (vi
, nonlocal_id
);
5764 if (POINTER_TYPE_P (TREE_TYPE (t
))
5765 && TYPE_RESTRICT (TREE_TYPE (t
)))
5766 make_constraint_from_global_restrict (p
, "PARM_RESTRICT");
5769 for (; p
; p
= p
->next
)
5771 if (p
->only_restrict_pointers
)
5772 make_constraint_from_global_restrict (p
, "PARM_RESTRICT");
5773 else if (p
->may_have_pointers
)
5774 make_constraint_from (p
, nonlocal_id
);
5779 /* Add a constraint for a result decl that is passed by reference. */
5780 if (DECL_RESULT (cfun
->decl
)
5781 && DECL_BY_REFERENCE (DECL_RESULT (cfun
->decl
)))
5783 varinfo_t p
, result_vi
= get_vi_for_tree (DECL_RESULT (cfun
->decl
));
5785 for (p
= result_vi
; p
; p
= p
->next
)
5786 make_constraint_from (p
, nonlocal_id
);
5789 /* Add a constraint for the incoming static chain parameter. */
5790 if (cfun
->static_chain_decl
!= NULL_TREE
)
5792 varinfo_t p
, chain_vi
= get_vi_for_tree (cfun
->static_chain_decl
);
5794 for (p
= chain_vi
; p
; p
= p
->next
)
5795 make_constraint_from (p
, nonlocal_id
);
5799 /* Structure used to put solution bitmaps in a hashtable so they can
5800 be shared among variables with the same points-to set. */
5802 typedef struct shared_bitmap_info
5806 } *shared_bitmap_info_t
;
5807 typedef const struct shared_bitmap_info
*const_shared_bitmap_info_t
;
5809 static htab_t shared_bitmap_table
;
5811 /* Hash function for a shared_bitmap_info_t */
5814 shared_bitmap_hash (const void *p
)
5816 const_shared_bitmap_info_t
const bi
= (const_shared_bitmap_info_t
) p
;
5817 return bi
->hashcode
;
5820 /* Equality function for two shared_bitmap_info_t's. */
5823 shared_bitmap_eq (const void *p1
, const void *p2
)
5825 const_shared_bitmap_info_t
const sbi1
= (const_shared_bitmap_info_t
) p1
;
5826 const_shared_bitmap_info_t
const sbi2
= (const_shared_bitmap_info_t
) p2
;
5827 return bitmap_equal_p (sbi1
->pt_vars
, sbi2
->pt_vars
);
5830 /* Lookup a bitmap in the shared bitmap hashtable, and return an already
5831 existing instance if there is one, NULL otherwise. */
5834 shared_bitmap_lookup (bitmap pt_vars
)
5837 struct shared_bitmap_info sbi
;
5839 sbi
.pt_vars
= pt_vars
;
5840 sbi
.hashcode
= bitmap_hash (pt_vars
);
5842 slot
= htab_find_slot_with_hash (shared_bitmap_table
, &sbi
,
5843 sbi
.hashcode
, NO_INSERT
);
5847 return ((shared_bitmap_info_t
) *slot
)->pt_vars
;
5851 /* Add a bitmap to the shared bitmap hashtable. */
5854 shared_bitmap_add (bitmap pt_vars
)
5857 shared_bitmap_info_t sbi
= XNEW (struct shared_bitmap_info
);
5859 sbi
->pt_vars
= pt_vars
;
5860 sbi
->hashcode
= bitmap_hash (pt_vars
);
5862 slot
= htab_find_slot_with_hash (shared_bitmap_table
, sbi
,
5863 sbi
->hashcode
, INSERT
);
5864 gcc_assert (!*slot
);
5865 *slot
= (void *) sbi
;
5869 /* Set bits in INTO corresponding to the variable uids in solution set FROM. */
5872 set_uids_in_ptset (bitmap into
, bitmap from
, struct pt_solution
*pt
)
5877 EXECUTE_IF_SET_IN_BITMAP (from
, 0, i
, bi
)
5879 varinfo_t vi
= get_varinfo (i
);
5881 /* The only artificial variables that are allowed in a may-alias
5882 set are heap variables. */
5883 if (vi
->is_artificial_var
&& !vi
->is_heap_var
)
5886 if (TREE_CODE (vi
->decl
) == VAR_DECL
5887 || TREE_CODE (vi
->decl
) == PARM_DECL
5888 || TREE_CODE (vi
->decl
) == RESULT_DECL
)
5890 /* If we are in IPA mode we will not recompute points-to
5891 sets after inlining so make sure they stay valid. */
5893 && !DECL_PT_UID_SET_P (vi
->decl
))
5894 SET_DECL_PT_UID (vi
->decl
, DECL_UID (vi
->decl
));
5896 /* Add the decl to the points-to set. Note that the points-to
5897 set contains global variables. */
5898 bitmap_set_bit (into
, DECL_PT_UID (vi
->decl
));
5899 if (vi
->is_global_var
)
5900 pt
->vars_contains_global
= true;
5906 /* Compute the points-to solution *PT for the variable VI. */
5908 static struct pt_solution
5909 find_what_var_points_to (varinfo_t orig_vi
)
5913 bitmap finished_solution
;
5917 struct pt_solution
*pt
;
5919 /* This variable may have been collapsed, let's get the real
5921 vi
= get_varinfo (find (orig_vi
->id
));
5923 /* See if we have already computed the solution and return it. */
5924 slot
= pointer_map_insert (final_solutions
, vi
);
5926 return *(struct pt_solution
*)*slot
;
5928 *slot
= pt
= XOBNEW (&final_solutions_obstack
, struct pt_solution
);
5929 memset (pt
, 0, sizeof (struct pt_solution
));
5931 /* Translate artificial variables into SSA_NAME_PTR_INFO
5933 EXECUTE_IF_SET_IN_BITMAP (vi
->solution
, 0, i
, bi
)
5935 varinfo_t vi
= get_varinfo (i
);
5937 if (vi
->is_artificial_var
)
5939 if (vi
->id
== nothing_id
)
5941 else if (vi
->id
== escaped_id
)
5944 pt
->ipa_escaped
= 1;
5948 else if (vi
->id
== nonlocal_id
)
5950 else if (vi
->is_heap_var
)
5951 /* We represent heapvars in the points-to set properly. */
5953 else if (vi
->id
== readonly_id
)
5956 else if (vi
->id
== anything_id
5957 || vi
->id
== integer_id
)
5962 /* Instead of doing extra work, simply do not create
5963 elaborate points-to information for pt_anything pointers. */
5967 /* Share the final set of variables when possible. */
5968 finished_solution
= BITMAP_GGC_ALLOC ();
5969 stats
.points_to_sets_created
++;
5971 set_uids_in_ptset (finished_solution
, vi
->solution
, pt
);
5972 result
= shared_bitmap_lookup (finished_solution
);
5975 shared_bitmap_add (finished_solution
);
5976 pt
->vars
= finished_solution
;
5981 bitmap_clear (finished_solution
);
5987 /* Given a pointer variable P, fill in its points-to set. */
5990 find_what_p_points_to (tree p
)
5992 struct ptr_info_def
*pi
;
5996 /* For parameters, get at the points-to set for the actual parm
5998 if (TREE_CODE (p
) == SSA_NAME
5999 && SSA_NAME_IS_DEFAULT_DEF (p
)
6000 && (TREE_CODE (SSA_NAME_VAR (p
)) == PARM_DECL
6001 || TREE_CODE (SSA_NAME_VAR (p
)) == RESULT_DECL
))
6002 lookup_p
= SSA_NAME_VAR (p
);
6004 vi
= lookup_vi_for_tree (lookup_p
);
6008 pi
= get_ptr_info (p
);
6009 pi
->pt
= find_what_var_points_to (vi
);
6013 /* Query statistics for points-to solutions. */
6016 unsigned HOST_WIDE_INT pt_solution_includes_may_alias
;
6017 unsigned HOST_WIDE_INT pt_solution_includes_no_alias
;
6018 unsigned HOST_WIDE_INT pt_solutions_intersect_may_alias
;
6019 unsigned HOST_WIDE_INT pt_solutions_intersect_no_alias
;
6023 dump_pta_stats (FILE *s
)
6025 fprintf (s
, "\nPTA query stats:\n");
6026 fprintf (s
, " pt_solution_includes: "
6027 HOST_WIDE_INT_PRINT_DEC
" disambiguations, "
6028 HOST_WIDE_INT_PRINT_DEC
" queries\n",
6029 pta_stats
.pt_solution_includes_no_alias
,
6030 pta_stats
.pt_solution_includes_no_alias
6031 + pta_stats
.pt_solution_includes_may_alias
);
6032 fprintf (s
, " pt_solutions_intersect: "
6033 HOST_WIDE_INT_PRINT_DEC
" disambiguations, "
6034 HOST_WIDE_INT_PRINT_DEC
" queries\n",
6035 pta_stats
.pt_solutions_intersect_no_alias
,
6036 pta_stats
.pt_solutions_intersect_no_alias
6037 + pta_stats
.pt_solutions_intersect_may_alias
);
6041 /* Reset the points-to solution *PT to a conservative default
6042 (point to anything). */
6045 pt_solution_reset (struct pt_solution
*pt
)
6047 memset (pt
, 0, sizeof (struct pt_solution
));
6048 pt
->anything
= true;
6051 /* Set the points-to solution *PT to point only to the variables
6052 in VARS. VARS_CONTAINS_GLOBAL specifies whether that contains
6053 global variables and VARS_CONTAINS_RESTRICT specifies whether
6054 it contains restrict tag variables. */
6057 pt_solution_set (struct pt_solution
*pt
, bitmap vars
, bool vars_contains_global
)
6059 memset (pt
, 0, sizeof (struct pt_solution
));
6061 pt
->vars_contains_global
= vars_contains_global
;
6064 /* Set the points-to solution *PT to point only to the variable VAR. */
6067 pt_solution_set_var (struct pt_solution
*pt
, tree var
)
6069 memset (pt
, 0, sizeof (struct pt_solution
));
6070 pt
->vars
= BITMAP_GGC_ALLOC ();
6071 bitmap_set_bit (pt
->vars
, DECL_PT_UID (var
));
6072 pt
->vars_contains_global
= is_global_var (var
);
6075 /* Computes the union of the points-to solutions *DEST and *SRC and
6076 stores the result in *DEST. This changes the points-to bitmap
6077 of *DEST and thus may not be used if that might be shared.
6078 The points-to bitmap of *SRC and *DEST will not be shared after
6079 this function if they were not before. */
6082 pt_solution_ior_into (struct pt_solution
*dest
, struct pt_solution
*src
)
6084 dest
->anything
|= src
->anything
;
6087 pt_solution_reset (dest
);
6091 dest
->nonlocal
|= src
->nonlocal
;
6092 dest
->escaped
|= src
->escaped
;
6093 dest
->ipa_escaped
|= src
->ipa_escaped
;
6094 dest
->null
|= src
->null
;
6095 dest
->vars_contains_global
|= src
->vars_contains_global
;
6100 dest
->vars
= BITMAP_GGC_ALLOC ();
6101 bitmap_ior_into (dest
->vars
, src
->vars
);
6104 /* Return true if the points-to solution *PT is empty. */
6107 pt_solution_empty_p (struct pt_solution
*pt
)
6114 && !bitmap_empty_p (pt
->vars
))
6117 /* If the solution includes ESCAPED, check if that is empty. */
6119 && !pt_solution_empty_p (&cfun
->gimple_df
->escaped
))
6122 /* If the solution includes ESCAPED, check if that is empty. */
6124 && !pt_solution_empty_p (&ipa_escaped_pt
))
6130 /* Return true if the points-to solution *PT only point to a single var, and
6131 return the var uid in *UID. */
6134 pt_solution_singleton_p (struct pt_solution
*pt
, unsigned *uid
)
6136 if (pt
->anything
|| pt
->nonlocal
|| pt
->escaped
|| pt
->ipa_escaped
6137 || pt
->null
|| pt
->vars
== NULL
6138 || !bitmap_single_bit_set_p (pt
->vars
))
6141 *uid
= bitmap_first_set_bit (pt
->vars
);
6145 /* Return true if the points-to solution *PT includes global memory. */
6148 pt_solution_includes_global (struct pt_solution
*pt
)
6152 || pt
->vars_contains_global
)
6156 return pt_solution_includes_global (&cfun
->gimple_df
->escaped
);
6158 if (pt
->ipa_escaped
)
6159 return pt_solution_includes_global (&ipa_escaped_pt
);
6161 /* ??? This predicate is not correct for the IPA-PTA solution
6162 as we do not properly distinguish between unit escape points
6163 and global variables. */
6164 if (cfun
->gimple_df
->ipa_pta
)
6170 /* Return true if the points-to solution *PT includes the variable
6171 declaration DECL. */
6174 pt_solution_includes_1 (struct pt_solution
*pt
, const_tree decl
)
6180 && is_global_var (decl
))
6184 && bitmap_bit_p (pt
->vars
, DECL_PT_UID (decl
)))
6187 /* If the solution includes ESCAPED, check it. */
6189 && pt_solution_includes_1 (&cfun
->gimple_df
->escaped
, decl
))
6192 /* If the solution includes ESCAPED, check it. */
6194 && pt_solution_includes_1 (&ipa_escaped_pt
, decl
))
6201 pt_solution_includes (struct pt_solution
*pt
, const_tree decl
)
6203 bool res
= pt_solution_includes_1 (pt
, decl
);
6205 ++pta_stats
.pt_solution_includes_may_alias
;
6207 ++pta_stats
.pt_solution_includes_no_alias
;
6211 /* Return true if both points-to solutions PT1 and PT2 have a non-empty
6215 pt_solutions_intersect_1 (struct pt_solution
*pt1
, struct pt_solution
*pt2
)
6217 if (pt1
->anything
|| pt2
->anything
)
6220 /* If either points to unknown global memory and the other points to
6221 any global memory they alias. */
6224 || pt2
->vars_contains_global
))
6226 && pt1
->vars_contains_global
))
6229 /* Check the escaped solution if required. */
6230 if ((pt1
->escaped
|| pt2
->escaped
)
6231 && !pt_solution_empty_p (&cfun
->gimple_df
->escaped
))
6233 /* If both point to escaped memory and that solution
6234 is not empty they alias. */
6235 if (pt1
->escaped
&& pt2
->escaped
)
6238 /* If either points to escaped memory see if the escaped solution
6239 intersects with the other. */
6241 && pt_solutions_intersect_1 (&cfun
->gimple_df
->escaped
, pt2
))
6243 && pt_solutions_intersect_1 (&cfun
->gimple_df
->escaped
, pt1
)))
6247 /* Check the escaped solution if required.
6248 ??? Do we need to check the local against the IPA escaped sets? */
6249 if ((pt1
->ipa_escaped
|| pt2
->ipa_escaped
)
6250 && !pt_solution_empty_p (&ipa_escaped_pt
))
6252 /* If both point to escaped memory and that solution
6253 is not empty they alias. */
6254 if (pt1
->ipa_escaped
&& pt2
->ipa_escaped
)
6257 /* If either points to escaped memory see if the escaped solution
6258 intersects with the other. */
6259 if ((pt1
->ipa_escaped
6260 && pt_solutions_intersect_1 (&ipa_escaped_pt
, pt2
))
6261 || (pt2
->ipa_escaped
6262 && pt_solutions_intersect_1 (&ipa_escaped_pt
, pt1
)))
6266 /* Now both pointers alias if their points-to solution intersects. */
6269 && bitmap_intersect_p (pt1
->vars
, pt2
->vars
));
6273 pt_solutions_intersect (struct pt_solution
*pt1
, struct pt_solution
*pt2
)
6275 bool res
= pt_solutions_intersect_1 (pt1
, pt2
);
6277 ++pta_stats
.pt_solutions_intersect_may_alias
;
6279 ++pta_stats
.pt_solutions_intersect_no_alias
;
6284 /* Dump points-to information to OUTFILE. */
6287 dump_sa_points_to_info (FILE *outfile
)
6291 fprintf (outfile
, "\nPoints-to sets\n\n");
6293 if (dump_flags
& TDF_STATS
)
6295 fprintf (outfile
, "Stats:\n");
6296 fprintf (outfile
, "Total vars: %d\n", stats
.total_vars
);
6297 fprintf (outfile
, "Non-pointer vars: %d\n",
6298 stats
.nonpointer_vars
);
6299 fprintf (outfile
, "Statically unified vars: %d\n",
6300 stats
.unified_vars_static
);
6301 fprintf (outfile
, "Dynamically unified vars: %d\n",
6302 stats
.unified_vars_dynamic
);
6303 fprintf (outfile
, "Iterations: %d\n", stats
.iterations
);
6304 fprintf (outfile
, "Number of edges: %d\n", stats
.num_edges
);
6305 fprintf (outfile
, "Number of implicit edges: %d\n",
6306 stats
.num_implicit_edges
);
6309 for (i
= 0; i
< varmap
.length (); i
++)
6311 varinfo_t vi
= get_varinfo (i
);
6312 if (!vi
->may_have_pointers
)
6314 dump_solution_for_var (outfile
, i
);
6319 /* Debug points-to information to stderr. */
6322 debug_sa_points_to_info (void)
6324 dump_sa_points_to_info (stderr
);
6328 /* Initialize the always-existing constraint variables for NULL
6329 ANYTHING, READONLY, and INTEGER */
6332 init_base_vars (void)
6334 struct constraint_expr lhs
, rhs
;
6335 varinfo_t var_anything
;
6336 varinfo_t var_nothing
;
6337 varinfo_t var_readonly
;
6338 varinfo_t var_escaped
;
6339 varinfo_t var_nonlocal
;
6340 varinfo_t var_storedanything
;
6341 varinfo_t var_integer
;
6343 /* Create the NULL variable, used to represent that a variable points
6345 var_nothing
= new_var_info (NULL_TREE
, "NULL");
6346 gcc_assert (var_nothing
->id
== nothing_id
);
6347 var_nothing
->is_artificial_var
= 1;
6348 var_nothing
->offset
= 0;
6349 var_nothing
->size
= ~0;
6350 var_nothing
->fullsize
= ~0;
6351 var_nothing
->is_special_var
= 1;
6352 var_nothing
->may_have_pointers
= 0;
6353 var_nothing
->is_global_var
= 0;
6355 /* Create the ANYTHING variable, used to represent that a variable
6356 points to some unknown piece of memory. */
6357 var_anything
= new_var_info (NULL_TREE
, "ANYTHING");
6358 gcc_assert (var_anything
->id
== anything_id
);
6359 var_anything
->is_artificial_var
= 1;
6360 var_anything
->size
= ~0;
6361 var_anything
->offset
= 0;
6362 var_anything
->next
= NULL
;
6363 var_anything
->fullsize
= ~0;
6364 var_anything
->is_special_var
= 1;
6366 /* Anything points to anything. This makes deref constraints just
6367 work in the presence of linked list and other p = *p type loops,
6368 by saying that *ANYTHING = ANYTHING. */
6370 lhs
.var
= anything_id
;
6372 rhs
.type
= ADDRESSOF
;
6373 rhs
.var
= anything_id
;
6376 /* This specifically does not use process_constraint because
6377 process_constraint ignores all anything = anything constraints, since all
6378 but this one are redundant. */
6379 constraints
.safe_push (new_constraint (lhs
, rhs
));
6381 /* Create the READONLY variable, used to represent that a variable
6382 points to readonly memory. */
6383 var_readonly
= new_var_info (NULL_TREE
, "READONLY");
6384 gcc_assert (var_readonly
->id
== readonly_id
);
6385 var_readonly
->is_artificial_var
= 1;
6386 var_readonly
->offset
= 0;
6387 var_readonly
->size
= ~0;
6388 var_readonly
->fullsize
= ~0;
6389 var_readonly
->next
= NULL
;
6390 var_readonly
->is_special_var
= 1;
6392 /* readonly memory points to anything, in order to make deref
6393 easier. In reality, it points to anything the particular
6394 readonly variable can point to, but we don't track this
6397 lhs
.var
= readonly_id
;
6399 rhs
.type
= ADDRESSOF
;
6400 rhs
.var
= readonly_id
; /* FIXME */
6402 process_constraint (new_constraint (lhs
, rhs
));
6404 /* Create the ESCAPED variable, used to represent the set of escaped
6406 var_escaped
= new_var_info (NULL_TREE
, "ESCAPED");
6407 gcc_assert (var_escaped
->id
== escaped_id
);
6408 var_escaped
->is_artificial_var
= 1;
6409 var_escaped
->offset
= 0;
6410 var_escaped
->size
= ~0;
6411 var_escaped
->fullsize
= ~0;
6412 var_escaped
->is_special_var
= 0;
6414 /* Create the NONLOCAL variable, used to represent the set of nonlocal
6416 var_nonlocal
= new_var_info (NULL_TREE
, "NONLOCAL");
6417 gcc_assert (var_nonlocal
->id
== nonlocal_id
);
6418 var_nonlocal
->is_artificial_var
= 1;
6419 var_nonlocal
->offset
= 0;
6420 var_nonlocal
->size
= ~0;
6421 var_nonlocal
->fullsize
= ~0;
6422 var_nonlocal
->is_special_var
= 1;
6424 /* ESCAPED = *ESCAPED, because escaped is may-deref'd at calls, etc. */
6426 lhs
.var
= escaped_id
;
6429 rhs
.var
= escaped_id
;
6431 process_constraint (new_constraint (lhs
, rhs
));
6433 /* ESCAPED = ESCAPED + UNKNOWN_OFFSET, because if a sub-field escapes the
6434 whole variable escapes. */
6436 lhs
.var
= escaped_id
;
6439 rhs
.var
= escaped_id
;
6440 rhs
.offset
= UNKNOWN_OFFSET
;
6441 process_constraint (new_constraint (lhs
, rhs
));
6443 /* *ESCAPED = NONLOCAL. This is true because we have to assume
6444 everything pointed to by escaped points to what global memory can
6447 lhs
.var
= escaped_id
;
6450 rhs
.var
= nonlocal_id
;
6452 process_constraint (new_constraint (lhs
, rhs
));
6454 /* NONLOCAL = &NONLOCAL, NONLOCAL = &ESCAPED. This is true because
6455 global memory may point to global memory and escaped memory. */
6457 lhs
.var
= nonlocal_id
;
6459 rhs
.type
= ADDRESSOF
;
6460 rhs
.var
= nonlocal_id
;
6462 process_constraint (new_constraint (lhs
, rhs
));
6463 rhs
.type
= ADDRESSOF
;
6464 rhs
.var
= escaped_id
;
6466 process_constraint (new_constraint (lhs
, rhs
));
6468 /* Create the STOREDANYTHING variable, used to represent the set of
6469 variables stored to *ANYTHING. */
6470 var_storedanything
= new_var_info (NULL_TREE
, "STOREDANYTHING");
6471 gcc_assert (var_storedanything
->id
== storedanything_id
);
6472 var_storedanything
->is_artificial_var
= 1;
6473 var_storedanything
->offset
= 0;
6474 var_storedanything
->size
= ~0;
6475 var_storedanything
->fullsize
= ~0;
6476 var_storedanything
->is_special_var
= 0;
6478 /* Create the INTEGER variable, used to represent that a variable points
6479 to what an INTEGER "points to". */
6480 var_integer
= new_var_info (NULL_TREE
, "INTEGER");
6481 gcc_assert (var_integer
->id
== integer_id
);
6482 var_integer
->is_artificial_var
= 1;
6483 var_integer
->size
= ~0;
6484 var_integer
->fullsize
= ~0;
6485 var_integer
->offset
= 0;
6486 var_integer
->next
= NULL
;
6487 var_integer
->is_special_var
= 1;
6489 /* INTEGER = ANYTHING, because we don't know where a dereference of
6490 a random integer will point to. */
6492 lhs
.var
= integer_id
;
6494 rhs
.type
= ADDRESSOF
;
6495 rhs
.var
= anything_id
;
6497 process_constraint (new_constraint (lhs
, rhs
));
6500 /* Initialize things necessary to perform PTA */
6503 init_alias_vars (void)
6505 use_field_sensitive
= (MAX_FIELDS_FOR_FIELD_SENSITIVE
> 1);
6507 bitmap_obstack_initialize (&pta_obstack
);
6508 bitmap_obstack_initialize (&oldpta_obstack
);
6509 bitmap_obstack_initialize (&predbitmap_obstack
);
6511 constraint_pool
= create_alloc_pool ("Constraint pool",
6512 sizeof (struct constraint
), 30);
6513 variable_info_pool
= create_alloc_pool ("Variable info pool",
6514 sizeof (struct variable_info
), 30);
6515 constraints
.create (8);
6517 vi_for_tree
= pointer_map_create ();
6518 call_stmt_vars
= pointer_map_create ();
6520 memset (&stats
, 0, sizeof (stats
));
6521 shared_bitmap_table
= htab_create (511, shared_bitmap_hash
,
6522 shared_bitmap_eq
, free
);
6525 gcc_obstack_init (&fake_var_decl_obstack
);
6527 final_solutions
= pointer_map_create ();
6528 gcc_obstack_init (&final_solutions_obstack
);
6531 /* Remove the REF and ADDRESS edges from GRAPH, as well as all the
6532 predecessor edges. */
6535 remove_preds_and_fake_succs (constraint_graph_t graph
)
6539 /* Clear the implicit ref and address nodes from the successor
6541 for (i
= 0; i
< FIRST_REF_NODE
; i
++)
6543 if (graph
->succs
[i
])
6544 bitmap_clear_range (graph
->succs
[i
], FIRST_REF_NODE
,
6545 FIRST_REF_NODE
* 2);
6548 /* Free the successor list for the non-ref nodes. */
6549 for (i
= FIRST_REF_NODE
; i
< graph
->size
; i
++)
6551 if (graph
->succs
[i
])
6552 BITMAP_FREE (graph
->succs
[i
]);
6555 /* Now reallocate the size of the successor list as, and blow away
6556 the predecessor bitmaps. */
6557 graph
->size
= varmap
.length ();
6558 graph
->succs
= XRESIZEVEC (bitmap
, graph
->succs
, graph
->size
);
6560 free (graph
->implicit_preds
);
6561 graph
->implicit_preds
= NULL
;
6562 free (graph
->preds
);
6563 graph
->preds
= NULL
;
6564 bitmap_obstack_release (&predbitmap_obstack
);
6567 /* Solve the constraint set. */
6570 solve_constraints (void)
6572 struct scc_info
*si
;
6576 "\nCollapsing static cycles and doing variable "
6579 init_graph (varmap
.length () * 2);
6582 fprintf (dump_file
, "Building predecessor graph\n");
6583 build_pred_graph ();
6586 fprintf (dump_file
, "Detecting pointer and location "
6588 si
= perform_var_substitution (graph
);
6591 fprintf (dump_file
, "Rewriting constraints and unifying "
6593 rewrite_constraints (graph
, si
);
6595 build_succ_graph ();
6597 free_var_substitution_info (si
);
6599 /* Attach complex constraints to graph nodes. */
6600 move_complex_constraints (graph
);
6603 fprintf (dump_file
, "Uniting pointer but not location equivalent "
6605 unite_pointer_equivalences (graph
);
6608 fprintf (dump_file
, "Finding indirect cycles\n");
6609 find_indirect_cycles (graph
);
6611 /* Implicit nodes and predecessors are no longer necessary at this
6613 remove_preds_and_fake_succs (graph
);
6615 if (dump_file
&& (dump_flags
& TDF_GRAPH
))
6617 fprintf (dump_file
, "\n\n// The constraint graph before solve-graph "
6618 "in dot format:\n");
6619 dump_constraint_graph (dump_file
);
6620 fprintf (dump_file
, "\n\n");
6624 fprintf (dump_file
, "Solving graph\n");
6626 solve_graph (graph
);
6628 if (dump_file
&& (dump_flags
& TDF_GRAPH
))
6630 fprintf (dump_file
, "\n\n// The constraint graph after solve-graph "
6631 "in dot format:\n");
6632 dump_constraint_graph (dump_file
);
6633 fprintf (dump_file
, "\n\n");
6637 dump_sa_points_to_info (dump_file
);
6640 /* Create points-to sets for the current function. See the comments
6641 at the start of the file for an algorithmic overview. */
6644 compute_points_to_sets (void)
6650 timevar_push (TV_TREE_PTA
);
6654 intra_create_variable_infos ();
6656 /* Now walk all statements and build the constraint set. */
6659 gimple_stmt_iterator gsi
;
6661 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
6663 gimple phi
= gsi_stmt (gsi
);
6665 if (! virtual_operand_p (gimple_phi_result (phi
)))
6666 find_func_aliases (phi
);
6669 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
6671 gimple stmt
= gsi_stmt (gsi
);
6673 find_func_aliases (stmt
);
6679 fprintf (dump_file
, "Points-to analysis\n\nConstraints:\n\n");
6680 dump_constraints (dump_file
, 0);
6683 /* From the constraints compute the points-to sets. */
6684 solve_constraints ();
6686 /* Compute the points-to set for ESCAPED used for call-clobber analysis. */
6687 cfun
->gimple_df
->escaped
= find_what_var_points_to (get_varinfo (escaped_id
));
6689 /* Make sure the ESCAPED solution (which is used as placeholder in
6690 other solutions) does not reference itself. This simplifies
6691 points-to solution queries. */
6692 cfun
->gimple_df
->escaped
.escaped
= 0;
6694 /* Mark escaped HEAP variables as global. */
6695 FOR_EACH_VEC_ELT (varmap
, i
, vi
)
6697 && !vi
->is_global_var
)
6698 DECL_EXTERNAL (vi
->decl
) = vi
->is_global_var
6699 = pt_solution_includes (&cfun
->gimple_df
->escaped
, vi
->decl
);
6701 /* Compute the points-to sets for pointer SSA_NAMEs. */
6702 for (i
= 0; i
< num_ssa_names
; ++i
)
6704 tree ptr
= ssa_name (i
);
6706 && POINTER_TYPE_P (TREE_TYPE (ptr
)))
6707 find_what_p_points_to (ptr
);
6710 /* Compute the call-used/clobbered sets. */
6713 gimple_stmt_iterator gsi
;
6715 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
6717 gimple stmt
= gsi_stmt (gsi
);
6718 struct pt_solution
*pt
;
6719 if (!is_gimple_call (stmt
))
6722 pt
= gimple_call_use_set (stmt
);
6723 if (gimple_call_flags (stmt
) & ECF_CONST
)
6724 memset (pt
, 0, sizeof (struct pt_solution
));
6725 else if ((vi
= lookup_call_use_vi (stmt
)) != NULL
)
6727 *pt
= find_what_var_points_to (vi
);
6728 /* Escaped (and thus nonlocal) variables are always
6729 implicitly used by calls. */
6730 /* ??? ESCAPED can be empty even though NONLOCAL
6737 /* If there is nothing special about this call then
6738 we have made everything that is used also escape. */
6739 *pt
= cfun
->gimple_df
->escaped
;
6743 pt
= gimple_call_clobber_set (stmt
);
6744 if (gimple_call_flags (stmt
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
6745 memset (pt
, 0, sizeof (struct pt_solution
));
6746 else if ((vi
= lookup_call_clobber_vi (stmt
)) != NULL
)
6748 *pt
= find_what_var_points_to (vi
);
6749 /* Escaped (and thus nonlocal) variables are always
6750 implicitly clobbered by calls. */
6751 /* ??? ESCAPED can be empty even though NONLOCAL
6758 /* If there is nothing special about this call then
6759 we have made everything that is used also escape. */
6760 *pt
= cfun
->gimple_df
->escaped
;
6766 timevar_pop (TV_TREE_PTA
);
6770 /* Delete created points-to sets. */
6773 delete_points_to_sets (void)
6777 htab_delete (shared_bitmap_table
);
6778 if (dump_file
&& (dump_flags
& TDF_STATS
))
6779 fprintf (dump_file
, "Points to sets created:%d\n",
6780 stats
.points_to_sets_created
);
6782 pointer_map_destroy (vi_for_tree
);
6783 pointer_map_destroy (call_stmt_vars
);
6784 bitmap_obstack_release (&pta_obstack
);
6785 constraints
.release ();
6787 for (i
= 0; i
< graph
->size
; i
++)
6788 graph
->complex[i
].release ();
6789 free (graph
->complex);
6792 free (graph
->succs
);
6794 free (graph
->pe_rep
);
6795 free (graph
->indirect_cycles
);
6799 free_alloc_pool (variable_info_pool
);
6800 free_alloc_pool (constraint_pool
);
6802 obstack_free (&fake_var_decl_obstack
, NULL
);
6804 pointer_map_destroy (final_solutions
);
6805 obstack_free (&final_solutions_obstack
, NULL
);
6809 /* Compute points-to information for every SSA_NAME pointer in the
6810 current function and compute the transitive closure of escaped
6811 variables to re-initialize the call-clobber states of local variables. */
6814 compute_may_aliases (void)
6816 if (cfun
->gimple_df
->ipa_pta
)
6820 fprintf (dump_file
, "\nNot re-computing points-to information "
6821 "because IPA points-to information is available.\n\n");
6823 /* But still dump what we have remaining it. */
6824 dump_alias_info (dump_file
);
6830 /* For each pointer P_i, determine the sets of variables that P_i may
6831 point-to. Compute the reachability set of escaped and call-used
6833 compute_points_to_sets ();
6835 /* Debugging dumps. */
6837 dump_alias_info (dump_file
);
6839 /* Deallocate memory used by aliasing data structures and the internal
6840 points-to solution. */
6841 delete_points_to_sets ();
6843 gcc_assert (!need_ssa_update_p (cfun
));
6849 gate_tree_pta (void)
6851 return flag_tree_pta
;
6854 /* A dummy pass to cause points-to information to be computed via
6855 TODO_rebuild_alias. */
6857 struct gimple_opt_pass pass_build_alias
=
6862 OPTGROUP_NONE
, /* optinfo_flags */
6863 gate_tree_pta
, /* gate */
6867 0, /* static_pass_number */
6868 TV_NONE
, /* tv_id */
6869 PROP_cfg
| PROP_ssa
, /* properties_required */
6870 0, /* properties_provided */
6871 0, /* properties_destroyed */
6872 0, /* todo_flags_start */
6873 TODO_rebuild_alias
/* todo_flags_finish */
6877 /* A dummy pass to cause points-to information to be computed via
6878 TODO_rebuild_alias. */
6880 struct gimple_opt_pass pass_build_ealias
=
6884 "ealias", /* name */
6885 OPTGROUP_NONE
, /* optinfo_flags */
6886 gate_tree_pta
, /* gate */
6890 0, /* static_pass_number */
6891 TV_NONE
, /* tv_id */
6892 PROP_cfg
| PROP_ssa
, /* properties_required */
6893 0, /* properties_provided */
6894 0, /* properties_destroyed */
6895 0, /* todo_flags_start */
6896 TODO_rebuild_alias
/* todo_flags_finish */
6901 /* Return true if we should execute IPA PTA. */
6907 /* Don't bother doing anything if the program has errors. */
6911 /* IPA PTA solutions for ESCAPED. */
6912 struct pt_solution ipa_escaped_pt
6913 = { true, false, false, false, false, false, NULL
};
6915 /* Associate node with varinfo DATA. Worker for
6916 cgraph_for_node_and_aliases. */
6918 associate_varinfo_to_alias (struct cgraph_node
*node
, void *data
)
6920 if (node
->alias
|| node
->thunk
.thunk_p
)
6921 insert_vi_for_tree (node
->symbol
.decl
, (varinfo_t
)data
);
6925 /* Execute the driver for IPA PTA. */
6927 ipa_pta_execute (void)
6929 struct cgraph_node
*node
;
6930 struct varpool_node
*var
;
6937 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
6939 dump_symtab (dump_file
);
6940 fprintf (dump_file
, "\n");
6943 /* Build the constraints. */
6944 FOR_EACH_DEFINED_FUNCTION (node
)
6947 /* Nodes without a body are not interesting. Especially do not
6948 visit clones at this point for now - we get duplicate decls
6949 there for inline clones at least. */
6950 if (!cgraph_function_with_gimple_body_p (node
))
6953 gcc_assert (!node
->clone_of
);
6955 vi
= create_function_info_for (node
->symbol
.decl
,
6956 alias_get_name (node
->symbol
.decl
));
6957 cgraph_for_node_and_aliases (node
, associate_varinfo_to_alias
, vi
, true);
6960 /* Create constraints for global variables and their initializers. */
6961 FOR_EACH_VARIABLE (var
)
6966 get_vi_for_tree (var
->symbol
.decl
);
6972 "Generating constraints for global initializers\n\n");
6973 dump_constraints (dump_file
, 0);
6974 fprintf (dump_file
, "\n");
6976 from
= constraints
.length ();
6978 FOR_EACH_DEFINED_FUNCTION (node
)
6980 struct function
*func
;
6983 /* Nodes without a body are not interesting. */
6984 if (!cgraph_function_with_gimple_body_p (node
))
6990 "Generating constraints for %s", cgraph_node_name (node
));
6991 if (DECL_ASSEMBLER_NAME_SET_P (node
->symbol
.decl
))
6992 fprintf (dump_file
, " (%s)",
6994 (DECL_ASSEMBLER_NAME (node
->symbol
.decl
)));
6995 fprintf (dump_file
, "\n");
6998 func
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
7001 /* For externally visible or attribute used annotated functions use
7002 local constraints for their arguments.
7003 For local functions we see all callers and thus do not need initial
7004 constraints for parameters. */
7005 if (node
->symbol
.used_from_other_partition
7006 || node
->symbol
.externally_visible
7007 || node
->symbol
.force_output
)
7009 intra_create_variable_infos ();
7011 /* We also need to make function return values escape. Nothing
7012 escapes by returning from main though. */
7013 if (!MAIN_NAME_P (DECL_NAME (node
->symbol
.decl
)))
7016 fi
= lookup_vi_for_tree (node
->symbol
.decl
);
7017 rvi
= first_vi_for_offset (fi
, fi_result
);
7018 if (rvi
&& rvi
->offset
== fi_result
)
7020 struct constraint_expr includes
;
7021 struct constraint_expr var
;
7022 includes
.var
= escaped_id
;
7023 includes
.offset
= 0;
7024 includes
.type
= SCALAR
;
7028 process_constraint (new_constraint (includes
, var
));
7033 /* Build constriants for the function body. */
7034 FOR_EACH_BB_FN (bb
, func
)
7036 gimple_stmt_iterator gsi
;
7038 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
);
7041 gimple phi
= gsi_stmt (gsi
);
7043 if (! virtual_operand_p (gimple_phi_result (phi
)))
7044 find_func_aliases (phi
);
7047 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
7049 gimple stmt
= gsi_stmt (gsi
);
7051 find_func_aliases (stmt
);
7052 find_func_clobbers (stmt
);
7060 fprintf (dump_file
, "\n");
7061 dump_constraints (dump_file
, from
);
7062 fprintf (dump_file
, "\n");
7064 from
= constraints
.length ();
7067 /* From the constraints compute the points-to sets. */
7068 solve_constraints ();
7070 /* Compute the global points-to sets for ESCAPED.
7071 ??? Note that the computed escape set is not correct
7072 for the whole unit as we fail to consider graph edges to
7073 externally visible functions. */
7074 ipa_escaped_pt
= find_what_var_points_to (get_varinfo (escaped_id
));
7076 /* Make sure the ESCAPED solution (which is used as placeholder in
7077 other solutions) does not reference itself. This simplifies
7078 points-to solution queries. */
7079 ipa_escaped_pt
.ipa_escaped
= 0;
7081 /* Assign the points-to sets to the SSA names in the unit. */
7082 FOR_EACH_DEFINED_FUNCTION (node
)
7085 struct function
*fn
;
7089 struct pt_solution uses
, clobbers
;
7090 struct cgraph_edge
*e
;
7092 /* Nodes without a body are not interesting. */
7093 if (!cgraph_function_with_gimple_body_p (node
))
7096 fn
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
7098 /* Compute the points-to sets for pointer SSA_NAMEs. */
7099 FOR_EACH_VEC_ELT (*fn
->gimple_df
->ssa_names
, i
, ptr
)
7102 && POINTER_TYPE_P (TREE_TYPE (ptr
)))
7103 find_what_p_points_to (ptr
);
7106 /* Compute the call-use and call-clobber sets for all direct calls. */
7107 fi
= lookup_vi_for_tree (node
->symbol
.decl
);
7108 gcc_assert (fi
->is_fn_info
);
7110 = find_what_var_points_to (first_vi_for_offset (fi
, fi_clobbers
));
7111 uses
= find_what_var_points_to (first_vi_for_offset (fi
, fi_uses
));
7112 for (e
= node
->callers
; e
; e
= e
->next_caller
)
7117 *gimple_call_clobber_set (e
->call_stmt
) = clobbers
;
7118 *gimple_call_use_set (e
->call_stmt
) = uses
;
7121 /* Compute the call-use and call-clobber sets for indirect calls
7122 and calls to external functions. */
7123 FOR_EACH_BB_FN (bb
, fn
)
7125 gimple_stmt_iterator gsi
;
7127 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
7129 gimple stmt
= gsi_stmt (gsi
);
7130 struct pt_solution
*pt
;
7134 if (!is_gimple_call (stmt
))
7137 /* Handle direct calls to external functions. */
7138 decl
= gimple_call_fndecl (stmt
);
7140 && (!(fi
= lookup_vi_for_tree (decl
))
7141 || !fi
->is_fn_info
))
7143 pt
= gimple_call_use_set (stmt
);
7144 if (gimple_call_flags (stmt
) & ECF_CONST
)
7145 memset (pt
, 0, sizeof (struct pt_solution
));
7146 else if ((vi
= lookup_call_use_vi (stmt
)) != NULL
)
7148 *pt
= find_what_var_points_to (vi
);
7149 /* Escaped (and thus nonlocal) variables are always
7150 implicitly used by calls. */
7151 /* ??? ESCAPED can be empty even though NONLOCAL
7154 pt
->ipa_escaped
= 1;
7158 /* If there is nothing special about this call then
7159 we have made everything that is used also escape. */
7160 *pt
= ipa_escaped_pt
;
7164 pt
= gimple_call_clobber_set (stmt
);
7165 if (gimple_call_flags (stmt
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
7166 memset (pt
, 0, sizeof (struct pt_solution
));
7167 else if ((vi
= lookup_call_clobber_vi (stmt
)) != NULL
)
7169 *pt
= find_what_var_points_to (vi
);
7170 /* Escaped (and thus nonlocal) variables are always
7171 implicitly clobbered by calls. */
7172 /* ??? ESCAPED can be empty even though NONLOCAL
7175 pt
->ipa_escaped
= 1;
7179 /* If there is nothing special about this call then
7180 we have made everything that is used also escape. */
7181 *pt
= ipa_escaped_pt
;
7186 /* Handle indirect calls. */
7188 && (fi
= get_fi_for_callee (stmt
)))
7190 /* We need to accumulate all clobbers/uses of all possible
7192 fi
= get_varinfo (find (fi
->id
));
7193 /* If we cannot constrain the set of functions we'll end up
7194 calling we end up using/clobbering everything. */
7195 if (bitmap_bit_p (fi
->solution
, anything_id
)
7196 || bitmap_bit_p (fi
->solution
, nonlocal_id
)
7197 || bitmap_bit_p (fi
->solution
, escaped_id
))
7199 pt_solution_reset (gimple_call_clobber_set (stmt
));
7200 pt_solution_reset (gimple_call_use_set (stmt
));
7206 struct pt_solution
*uses
, *clobbers
;
7208 uses
= gimple_call_use_set (stmt
);
7209 clobbers
= gimple_call_clobber_set (stmt
);
7210 memset (uses
, 0, sizeof (struct pt_solution
));
7211 memset (clobbers
, 0, sizeof (struct pt_solution
));
7212 EXECUTE_IF_SET_IN_BITMAP (fi
->solution
, 0, i
, bi
)
7214 struct pt_solution sol
;
7216 vi
= get_varinfo (i
);
7217 if (!vi
->is_fn_info
)
7219 /* ??? We could be more precise here? */
7221 uses
->ipa_escaped
= 1;
7222 clobbers
->nonlocal
= 1;
7223 clobbers
->ipa_escaped
= 1;
7227 if (!uses
->anything
)
7229 sol
= find_what_var_points_to
7230 (first_vi_for_offset (vi
, fi_uses
));
7231 pt_solution_ior_into (uses
, &sol
);
7233 if (!clobbers
->anything
)
7235 sol
= find_what_var_points_to
7236 (first_vi_for_offset (vi
, fi_clobbers
));
7237 pt_solution_ior_into (clobbers
, &sol
);
7245 fn
->gimple_df
->ipa_pta
= true;
7248 delete_points_to_sets ();
7255 struct simple_ipa_opt_pass pass_ipa_pta
=
7260 OPTGROUP_NONE
, /* optinfo_flags */
7261 gate_ipa_pta
, /* gate */
7262 ipa_pta_execute
, /* execute */
7265 0, /* static_pass_number */
7266 TV_IPA_PTA
, /* tv_id */
7267 0, /* properties_required */
7268 0, /* properties_provided */
7269 0, /* properties_destroyed */
7270 0, /* todo_flags_start */
7271 TODO_update_ssa
/* todo_flags_finish */