Daily bump.
[official-gcc.git] / gcc / alias.c
blob29da8ffafb3f38a0bb3c5c6a1279a6a14983f9a9
1 /* Alias analysis for GNU C
2 Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by John Carr (jfc@mit.edu).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "tm_p.h"
27 #include "function.h"
28 #include "expr.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "basic-block.h"
32 #include "flags.h"
33 #include "output.h"
34 #include "toplev.h"
35 #include "cselib.h"
36 #include "splay-tree.h"
37 #include "ggc.h"
38 #include "langhooks.h"
40 /* The alias sets assigned to MEMs assist the back-end in determining
41 which MEMs can alias which other MEMs. In general, two MEMs in
42 different alias sets cannot alias each other, with one important
43 exception. Consider something like:
45 struct S {int i; double d; };
47 a store to an `S' can alias something of either type `int' or type
48 `double'. (However, a store to an `int' cannot alias a `double'
49 and vice versa.) We indicate this via a tree structure that looks
50 like:
51 struct S
52 / \
53 / \
54 |/_ _\|
55 int double
57 (The arrows are directed and point downwards.)
58 In this situation we say the alias set for `struct S' is the
59 `superset' and that those for `int' and `double' are `subsets'.
61 To see whether two alias sets can point to the same memory, we must
62 see if either alias set is a subset of the other. We need not trace
63 past immediate descendents, however, since we propagate all
64 grandchildren up one level.
66 Alias set zero is implicitly a superset of all other alias sets.
67 However, this is no actual entry for alias set zero. It is an
68 error to attempt to explicitly construct a subset of zero. */
70 typedef struct alias_set_entry
72 /* The alias set number, as stored in MEM_ALIAS_SET. */
73 HOST_WIDE_INT alias_set;
75 /* The children of the alias set. These are not just the immediate
76 children, but, in fact, all descendents. So, if we have:
78 struct T { struct S s; float f; }
80 continuing our example above, the children here will be all of
81 `int', `double', `float', and `struct S'. */
82 splay_tree children;
84 /* Nonzero if would have a child of zero: this effectively makes this
85 alias set the same as alias set zero. */
86 int has_zero_child;
87 } *alias_set_entry;
89 static int rtx_equal_for_memref_p PARAMS ((rtx, rtx));
90 static rtx find_symbolic_term PARAMS ((rtx));
91 rtx get_addr PARAMS ((rtx));
92 static int memrefs_conflict_p PARAMS ((int, rtx, int, rtx,
93 HOST_WIDE_INT));
94 static void record_set PARAMS ((rtx, rtx, void *));
95 static rtx find_base_term PARAMS ((rtx));
96 static int base_alias_check PARAMS ((rtx, rtx, enum machine_mode,
97 enum machine_mode));
98 static rtx find_base_value PARAMS ((rtx));
99 static int mems_in_disjoint_alias_sets_p PARAMS ((rtx, rtx));
100 static int insert_subset_children PARAMS ((splay_tree_node, void*));
101 static tree find_base_decl PARAMS ((tree));
102 static alias_set_entry get_alias_set_entry PARAMS ((HOST_WIDE_INT));
103 static rtx fixed_scalar_and_varying_struct_p PARAMS ((rtx, rtx, rtx, rtx,
104 int (*) (rtx, int)));
105 static int aliases_everything_p PARAMS ((rtx));
106 static bool nonoverlapping_component_refs_p PARAMS ((tree, tree));
107 static tree decl_for_component_ref PARAMS ((tree));
108 static rtx adjust_offset_for_component_ref PARAMS ((tree, rtx));
109 static int nonoverlapping_memrefs_p PARAMS ((rtx, rtx));
110 static int write_dependence_p PARAMS ((rtx, rtx, int));
112 static int nonlocal_mentioned_p_1 PARAMS ((rtx *, void *));
113 static int nonlocal_mentioned_p PARAMS ((rtx));
114 static int nonlocal_referenced_p_1 PARAMS ((rtx *, void *));
115 static int nonlocal_referenced_p PARAMS ((rtx));
116 static int nonlocal_set_p_1 PARAMS ((rtx *, void *));
117 static int nonlocal_set_p PARAMS ((rtx));
119 /* Set up all info needed to perform alias analysis on memory references. */
121 /* Returns the size in bytes of the mode of X. */
122 #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
124 /* Returns nonzero if MEM1 and MEM2 do not alias because they are in
125 different alias sets. We ignore alias sets in functions making use
126 of variable arguments because the va_arg macros on some systems are
127 not legal ANSI C. */
128 #define DIFFERENT_ALIAS_SETS_P(MEM1, MEM2) \
129 mems_in_disjoint_alias_sets_p (MEM1, MEM2)
131 /* Cap the number of passes we make over the insns propagating alias
132 information through set chains. 10 is a completely arbitrary choice. */
133 #define MAX_ALIAS_LOOP_PASSES 10
135 /* reg_base_value[N] gives an address to which register N is related.
136 If all sets after the first add or subtract to the current value
137 or otherwise modify it so it does not point to a different top level
138 object, reg_base_value[N] is equal to the address part of the source
139 of the first set.
141 A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF. ADDRESS
142 expressions represent certain special values: function arguments and
143 the stack, frame, and argument pointers.
145 The contents of an ADDRESS is not normally used, the mode of the
146 ADDRESS determines whether the ADDRESS is a function argument or some
147 other special value. Pointer equality, not rtx_equal_p, determines whether
148 two ADDRESS expressions refer to the same base address.
150 The only use of the contents of an ADDRESS is for determining if the
151 current function performs nonlocal memory memory references for the
152 purposes of marking the function as a constant function. */
154 static rtx *reg_base_value;
155 static rtx *new_reg_base_value;
156 static unsigned int reg_base_value_size; /* size of reg_base_value array */
158 #define REG_BASE_VALUE(X) \
159 (REGNO (X) < reg_base_value_size \
160 ? reg_base_value[REGNO (X)] : 0)
162 /* Vector of known invariant relationships between registers. Set in
163 loop unrolling. Indexed by register number, if nonzero the value
164 is an expression describing this register in terms of another.
166 The length of this array is REG_BASE_VALUE_SIZE.
168 Because this array contains only pseudo registers it has no effect
169 after reload. */
170 static rtx *alias_invariant;
172 /* Vector indexed by N giving the initial (unchanging) value known for
173 pseudo-register N. This array is initialized in
174 init_alias_analysis, and does not change until end_alias_analysis
175 is called. */
176 rtx *reg_known_value;
178 /* Indicates number of valid entries in reg_known_value. */
179 static unsigned int reg_known_value_size;
181 /* Vector recording for each reg_known_value whether it is due to a
182 REG_EQUIV note. Future passes (viz., reload) may replace the
183 pseudo with the equivalent expression and so we account for the
184 dependences that would be introduced if that happens.
186 The REG_EQUIV notes created in assign_parms may mention the arg
187 pointer, and there are explicit insns in the RTL that modify the
188 arg pointer. Thus we must ensure that such insns don't get
189 scheduled across each other because that would invalidate the
190 REG_EQUIV notes. One could argue that the REG_EQUIV notes are
191 wrong, but solving the problem in the scheduler will likely give
192 better code, so we do it here. */
193 char *reg_known_equiv_p;
195 /* True when scanning insns from the start of the rtl to the
196 NOTE_INSN_FUNCTION_BEG note. */
197 static int copying_arguments;
199 /* The splay-tree used to store the various alias set entries. */
200 static splay_tree alias_sets;
202 /* Returns a pointer to the alias set entry for ALIAS_SET, if there is
203 such an entry, or NULL otherwise. */
205 static alias_set_entry
206 get_alias_set_entry (alias_set)
207 HOST_WIDE_INT alias_set;
209 splay_tree_node sn
210 = splay_tree_lookup (alias_sets, (splay_tree_key) alias_set);
212 return sn != 0 ? ((alias_set_entry) sn->value) : 0;
215 /* Returns nonzero if the alias sets for MEM1 and MEM2 are such that
216 the two MEMs cannot alias each other. */
218 static int
219 mems_in_disjoint_alias_sets_p (mem1, mem2)
220 rtx mem1;
221 rtx mem2;
223 #ifdef ENABLE_CHECKING
224 /* Perform a basic sanity check. Namely, that there are no alias sets
225 if we're not using strict aliasing. This helps to catch bugs
226 whereby someone uses PUT_CODE, but doesn't clear MEM_ALIAS_SET, or
227 where a MEM is allocated in some way other than by the use of
228 gen_rtx_MEM, and the MEM_ALIAS_SET is not cleared. If we begin to
229 use alias sets to indicate that spilled registers cannot alias each
230 other, we might need to remove this check. */
231 if (! flag_strict_aliasing
232 && (MEM_ALIAS_SET (mem1) != 0 || MEM_ALIAS_SET (mem2) != 0))
233 abort ();
234 #endif
236 return ! alias_sets_conflict_p (MEM_ALIAS_SET (mem1), MEM_ALIAS_SET (mem2));
239 /* Insert the NODE into the splay tree given by DATA. Used by
240 record_alias_subset via splay_tree_foreach. */
242 static int
243 insert_subset_children (node, data)
244 splay_tree_node node;
245 void *data;
247 splay_tree_insert ((splay_tree) data, node->key, node->value);
249 return 0;
252 /* Return 1 if the two specified alias sets may conflict. */
255 alias_sets_conflict_p (set1, set2)
256 HOST_WIDE_INT set1, set2;
258 alias_set_entry ase;
260 /* If have no alias set information for one of the operands, we have
261 to assume it can alias anything. */
262 if (set1 == 0 || set2 == 0
263 /* If the two alias sets are the same, they may alias. */
264 || set1 == set2)
265 return 1;
267 /* See if the first alias set is a subset of the second. */
268 ase = get_alias_set_entry (set1);
269 if (ase != 0
270 && (ase->has_zero_child
271 || splay_tree_lookup (ase->children,
272 (splay_tree_key) set2)))
273 return 1;
275 /* Now do the same, but with the alias sets reversed. */
276 ase = get_alias_set_entry (set2);
277 if (ase != 0
278 && (ase->has_zero_child
279 || splay_tree_lookup (ase->children,
280 (splay_tree_key) set1)))
281 return 1;
283 /* The two alias sets are distinct and neither one is the
284 child of the other. Therefore, they cannot alias. */
285 return 0;
288 /* Return 1 if TYPE is a RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE and has
289 has any readonly fields. If any of the fields have types that
290 contain readonly fields, return true as well. */
293 readonly_fields_p (type)
294 tree type;
296 tree field;
298 if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
299 && TREE_CODE (type) != QUAL_UNION_TYPE)
300 return 0;
302 for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
303 if (TREE_CODE (field) == FIELD_DECL
304 && (TREE_READONLY (field)
305 || readonly_fields_p (TREE_TYPE (field))))
306 return 1;
308 return 0;
311 /* Return 1 if any MEM object of type T1 will always conflict (using the
312 dependency routines in this file) with any MEM object of type T2.
313 This is used when allocating temporary storage. If T1 and/or T2 are
314 NULL_TREE, it means we know nothing about the storage. */
317 objects_must_conflict_p (t1, t2)
318 tree t1, t2;
320 /* If neither has a type specified, we don't know if they'll conflict
321 because we may be using them to store objects of various types, for
322 example the argument and local variables areas of inlined functions. */
323 if (t1 == 0 && t2 == 0)
324 return 0;
326 /* If one or the other has readonly fields or is readonly,
327 then they may not conflict. */
328 if ((t1 != 0 && readonly_fields_p (t1))
329 || (t2 != 0 && readonly_fields_p (t2))
330 || (t1 != 0 && TYPE_READONLY (t1))
331 || (t2 != 0 && TYPE_READONLY (t2)))
332 return 0;
334 /* If they are the same type, they must conflict. */
335 if (t1 == t2
336 /* Likewise if both are volatile. */
337 || (t1 != 0 && TYPE_VOLATILE (t1) && t2 != 0 && TYPE_VOLATILE (t2)))
338 return 1;
340 /* If one is aggregate and the other is scalar then they may not
341 conflict. */
342 if ((t1 != 0 && AGGREGATE_TYPE_P (t1))
343 != (t2 != 0 && AGGREGATE_TYPE_P (t2)))
344 return 0;
346 /* Otherwise they conflict only if the alias sets conflict. */
347 return alias_sets_conflict_p (t1 ? get_alias_set (t1) : 0,
348 t2 ? get_alias_set (t2) : 0);
351 /* T is an expression with pointer type. Find the DECL on which this
352 expression is based. (For example, in `a[i]' this would be `a'.)
353 If there is no such DECL, or a unique decl cannot be determined,
354 NULL_TREE is returned. */
356 static tree
357 find_base_decl (t)
358 tree t;
360 tree d0, d1, d2;
362 if (t == 0 || t == error_mark_node || ! POINTER_TYPE_P (TREE_TYPE (t)))
363 return 0;
365 /* If this is a declaration, return it. */
366 if (TREE_CODE_CLASS (TREE_CODE (t)) == 'd')
367 return t;
369 /* Handle general expressions. It would be nice to deal with
370 COMPONENT_REFs here. If we could tell that `a' and `b' were the
371 same, then `a->f' and `b->f' are also the same. */
372 switch (TREE_CODE_CLASS (TREE_CODE (t)))
374 case '1':
375 return find_base_decl (TREE_OPERAND (t, 0));
377 case '2':
378 /* Return 0 if found in neither or both are the same. */
379 d0 = find_base_decl (TREE_OPERAND (t, 0));
380 d1 = find_base_decl (TREE_OPERAND (t, 1));
381 if (d0 == d1)
382 return d0;
383 else if (d0 == 0)
384 return d1;
385 else if (d1 == 0)
386 return d0;
387 else
388 return 0;
390 case '3':
391 d0 = find_base_decl (TREE_OPERAND (t, 0));
392 d1 = find_base_decl (TREE_OPERAND (t, 1));
393 d2 = find_base_decl (TREE_OPERAND (t, 2));
395 /* Set any nonzero values from the last, then from the first. */
396 if (d1 == 0) d1 = d2;
397 if (d0 == 0) d0 = d1;
398 if (d1 == 0) d1 = d0;
399 if (d2 == 0) d2 = d1;
401 /* At this point all are nonzero or all are zero. If all three are the
402 same, return it. Otherwise, return zero. */
403 return (d0 == d1 && d1 == d2) ? d0 : 0;
405 default:
406 return 0;
410 /* Return 1 if all the nested component references handled by
411 get_inner_reference in T are such that we can address the object in T. */
414 can_address_p (t)
415 tree t;
417 /* If we're at the end, it is vacuously addressable. */
418 if (! handled_component_p (t))
419 return 1;
421 /* Bitfields are never addressable. */
422 else if (TREE_CODE (t) == BIT_FIELD_REF)
423 return 0;
425 /* Fields are addressable unless they are marked as nonaddressable or
426 the containing type has alias set 0. */
427 else if (TREE_CODE (t) == COMPONENT_REF
428 && ! DECL_NONADDRESSABLE_P (TREE_OPERAND (t, 1))
429 && get_alias_set (TREE_TYPE (TREE_OPERAND (t, 0))) != 0
430 && can_address_p (TREE_OPERAND (t, 0)))
431 return 1;
433 /* Likewise for arrays. */
434 else if ((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
435 && ! TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t, 0)))
436 && get_alias_set (TREE_TYPE (TREE_OPERAND (t, 0))) != 0
437 && can_address_p (TREE_OPERAND (t, 0)))
438 return 1;
440 return 0;
443 /* Return the alias set for T, which may be either a type or an
444 expression. Call language-specific routine for help, if needed. */
446 HOST_WIDE_INT
447 get_alias_set (t)
448 tree t;
450 HOST_WIDE_INT set;
452 /* If we're not doing any alias analysis, just assume everything
453 aliases everything else. Also return 0 if this or its type is
454 an error. */
455 if (! flag_strict_aliasing || t == error_mark_node
456 || (! TYPE_P (t)
457 && (TREE_TYPE (t) == 0 || TREE_TYPE (t) == error_mark_node)))
458 return 0;
460 /* We can be passed either an expression or a type. This and the
461 language-specific routine may make mutually-recursive calls to each other
462 to figure out what to do. At each juncture, we see if this is a tree
463 that the language may need to handle specially. First handle things that
464 aren't types. */
465 if (! TYPE_P (t))
467 tree inner = t;
468 tree placeholder_ptr = 0;
470 /* Remove any nops, then give the language a chance to do
471 something with this tree before we look at it. */
472 STRIP_NOPS (t);
473 set = (*lang_hooks.get_alias_set) (t);
474 if (set != -1)
475 return set;
477 /* First see if the actual object referenced is an INDIRECT_REF from a
478 restrict-qualified pointer or a "void *". Replace
479 PLACEHOLDER_EXPRs. */
480 while (TREE_CODE (inner) == PLACEHOLDER_EXPR
481 || handled_component_p (inner))
483 if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
484 inner = find_placeholder (inner, &placeholder_ptr);
485 else
486 inner = TREE_OPERAND (inner, 0);
488 STRIP_NOPS (inner);
491 /* Check for accesses through restrict-qualified pointers. */
492 if (TREE_CODE (inner) == INDIRECT_REF)
494 tree decl = find_base_decl (TREE_OPERAND (inner, 0));
496 if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
498 /* If we haven't computed the actual alias set, do it now. */
499 if (DECL_POINTER_ALIAS_SET (decl) == -2)
501 /* No two restricted pointers can point at the same thing.
502 However, a restricted pointer can point at the same thing
503 as an unrestricted pointer, if that unrestricted pointer
504 is based on the restricted pointer. So, we make the
505 alias set for the restricted pointer a subset of the
506 alias set for the type pointed to by the type of the
507 decl. */
508 HOST_WIDE_INT pointed_to_alias_set
509 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
511 if (pointed_to_alias_set == 0)
512 /* It's not legal to make a subset of alias set zero. */
514 else
516 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
517 record_alias_subset (pointed_to_alias_set,
518 DECL_POINTER_ALIAS_SET (decl));
522 /* We use the alias set indicated in the declaration. */
523 return DECL_POINTER_ALIAS_SET (decl);
526 /* If we have an INDIRECT_REF via a void pointer, we don't
527 know anything about what that might alias. */
528 else if (TREE_CODE (TREE_TYPE (inner)) == VOID_TYPE)
529 return 0;
532 /* Otherwise, pick up the outermost object that we could have a pointer
533 to, processing conversion and PLACEHOLDER_EXPR as above. */
534 placeholder_ptr = 0;
535 while (TREE_CODE (t) == PLACEHOLDER_EXPR
536 || (handled_component_p (t) && ! can_address_p (t)))
538 if (TREE_CODE (t) == PLACEHOLDER_EXPR)
539 t = find_placeholder (t, &placeholder_ptr);
540 else
541 t = TREE_OPERAND (t, 0);
543 STRIP_NOPS (t);
546 /* If we've already determined the alias set for a decl, just return
547 it. This is necessary for C++ anonymous unions, whose component
548 variables don't look like union members (boo!). */
549 if (TREE_CODE (t) == VAR_DECL
550 && DECL_RTL_SET_P (t) && GET_CODE (DECL_RTL (t)) == MEM)
551 return MEM_ALIAS_SET (DECL_RTL (t));
553 /* Now all we care about is the type. */
554 t = TREE_TYPE (t);
557 /* Variant qualifiers don't affect the alias set, so get the main
558 variant. If this is a type with a known alias set, return it. */
559 t = TYPE_MAIN_VARIANT (t);
560 if (TYPE_ALIAS_SET_KNOWN_P (t))
561 return TYPE_ALIAS_SET (t);
563 /* See if the language has special handling for this type. */
564 set = (*lang_hooks.get_alias_set) (t);
565 if (set != -1)
566 return set;
568 /* There are no objects of FUNCTION_TYPE, so there's no point in
569 using up an alias set for them. (There are, of course, pointers
570 and references to functions, but that's different.) */
571 else if (TREE_CODE (t) == FUNCTION_TYPE)
572 set = 0;
573 else
574 /* Otherwise make a new alias set for this type. */
575 set = new_alias_set ();
577 TYPE_ALIAS_SET (t) = set;
579 /* If this is an aggregate type, we must record any component aliasing
580 information. */
581 if (AGGREGATE_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
582 record_component_aliases (t);
584 return set;
587 /* Return a brand-new alias set. */
589 HOST_WIDE_INT
590 new_alias_set ()
592 static HOST_WIDE_INT last_alias_set;
594 if (flag_strict_aliasing)
595 return ++last_alias_set;
596 else
597 return 0;
600 /* Indicate that things in SUBSET can alias things in SUPERSET, but
601 not vice versa. For example, in C, a store to an `int' can alias a
602 structure containing an `int', but not vice versa. Here, the
603 structure would be the SUPERSET and `int' the SUBSET. This
604 function should be called only once per SUPERSET/SUBSET pair.
606 It is illegal for SUPERSET to be zero; everything is implicitly a
607 subset of alias set zero. */
609 void
610 record_alias_subset (superset, subset)
611 HOST_WIDE_INT superset;
612 HOST_WIDE_INT subset;
614 alias_set_entry superset_entry;
615 alias_set_entry subset_entry;
617 /* It is possible in complex type situations for both sets to be the same,
618 in which case we can ignore this operation. */
619 if (superset == subset)
620 return;
622 if (superset == 0)
623 abort ();
625 superset_entry = get_alias_set_entry (superset);
626 if (superset_entry == 0)
628 /* Create an entry for the SUPERSET, so that we have a place to
629 attach the SUBSET. */
630 superset_entry
631 = (alias_set_entry) xmalloc (sizeof (struct alias_set_entry));
632 superset_entry->alias_set = superset;
633 superset_entry->children
634 = splay_tree_new (splay_tree_compare_ints, 0, 0);
635 superset_entry->has_zero_child = 0;
636 splay_tree_insert (alias_sets, (splay_tree_key) superset,
637 (splay_tree_value) superset_entry);
640 if (subset == 0)
641 superset_entry->has_zero_child = 1;
642 else
644 subset_entry = get_alias_set_entry (subset);
645 /* If there is an entry for the subset, enter all of its children
646 (if they are not already present) as children of the SUPERSET. */
647 if (subset_entry)
649 if (subset_entry->has_zero_child)
650 superset_entry->has_zero_child = 1;
652 splay_tree_foreach (subset_entry->children, insert_subset_children,
653 superset_entry->children);
656 /* Enter the SUBSET itself as a child of the SUPERSET. */
657 splay_tree_insert (superset_entry->children,
658 (splay_tree_key) subset, 0);
662 /* Record that component types of TYPE, if any, are part of that type for
663 aliasing purposes. For record types, we only record component types
664 for fields that are marked addressable. For array types, we always
665 record the component types, so the front end should not call this
666 function if the individual component aren't addressable. */
668 void
669 record_component_aliases (type)
670 tree type;
672 HOST_WIDE_INT superset = get_alias_set (type);
673 tree field;
675 if (superset == 0)
676 return;
678 switch (TREE_CODE (type))
680 case ARRAY_TYPE:
681 if (! TYPE_NONALIASED_COMPONENT (type))
682 record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
683 break;
685 case RECORD_TYPE:
686 case UNION_TYPE:
687 case QUAL_UNION_TYPE:
688 /* Recursively record aliases for the base classes, if there are any */
689 if (TYPE_BINFO (type) != NULL && TYPE_BINFO_BASETYPES (type) != NULL)
691 int i;
692 for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); i++)
694 tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type), i);
695 record_alias_subset (superset,
696 get_alias_set (BINFO_TYPE (binfo)));
699 for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
700 if (TREE_CODE (field) == FIELD_DECL && ! DECL_NONADDRESSABLE_P (field))
701 record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
702 break;
704 case COMPLEX_TYPE:
705 record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
706 break;
708 default:
709 break;
713 /* Allocate an alias set for use in storing and reading from the varargs
714 spill area. */
716 HOST_WIDE_INT
717 get_varargs_alias_set ()
719 static HOST_WIDE_INT set = -1;
721 if (set == -1)
722 set = new_alias_set ();
724 return set;
727 /* Likewise, but used for the fixed portions of the frame, e.g., register
728 save areas. */
730 HOST_WIDE_INT
731 get_frame_alias_set ()
733 static HOST_WIDE_INT set = -1;
735 if (set == -1)
736 set = new_alias_set ();
738 return set;
741 /* Inside SRC, the source of a SET, find a base address. */
743 static rtx
744 find_base_value (src)
745 rtx src;
747 unsigned int regno;
749 switch (GET_CODE (src))
751 case SYMBOL_REF:
752 case LABEL_REF:
753 return src;
755 case REG:
756 regno = REGNO (src);
757 /* At the start of a function, argument registers have known base
758 values which may be lost later. Returning an ADDRESS
759 expression here allows optimization based on argument values
760 even when the argument registers are used for other purposes. */
761 if (regno < FIRST_PSEUDO_REGISTER && copying_arguments)
762 return new_reg_base_value[regno];
764 /* If a pseudo has a known base value, return it. Do not do this
765 for non-fixed hard regs since it can result in a circular
766 dependency chain for registers which have values at function entry.
768 The test above is not sufficient because the scheduler may move
769 a copy out of an arg reg past the NOTE_INSN_FUNCTION_BEGIN. */
770 if ((regno >= FIRST_PSEUDO_REGISTER || fixed_regs[regno])
771 && regno < reg_base_value_size
772 && reg_base_value[regno])
773 return reg_base_value[regno];
775 return src;
777 case MEM:
778 /* Check for an argument passed in memory. Only record in the
779 copying-arguments block; it is too hard to track changes
780 otherwise. */
781 if (copying_arguments
782 && (XEXP (src, 0) == arg_pointer_rtx
783 || (GET_CODE (XEXP (src, 0)) == PLUS
784 && XEXP (XEXP (src, 0), 0) == arg_pointer_rtx)))
785 return gen_rtx_ADDRESS (VOIDmode, src);
786 return 0;
788 case CONST:
789 src = XEXP (src, 0);
790 if (GET_CODE (src) != PLUS && GET_CODE (src) != MINUS)
791 break;
793 /* ... fall through ... */
795 case PLUS:
796 case MINUS:
798 rtx temp, src_0 = XEXP (src, 0), src_1 = XEXP (src, 1);
800 /* If either operand is a REG that is a known pointer, then it
801 is the base. */
802 if (REG_P (src_0) && REG_POINTER (src_0))
803 return find_base_value (src_0);
804 if (REG_P (src_1) && REG_POINTER (src_1))
805 return find_base_value (src_1);
807 /* If either operand is a REG, then see if we already have
808 a known value for it. */
809 if (REG_P (src_0))
811 temp = find_base_value (src_0);
812 if (temp != 0)
813 src_0 = temp;
816 if (REG_P (src_1))
818 temp = find_base_value (src_1);
819 if (temp!= 0)
820 src_1 = temp;
823 /* If either base is named object or a special address
824 (like an argument or stack reference), then use it for the
825 base term. */
826 if (src_0 != 0
827 && (GET_CODE (src_0) == SYMBOL_REF
828 || GET_CODE (src_0) == LABEL_REF
829 || (GET_CODE (src_0) == ADDRESS
830 && GET_MODE (src_0) != VOIDmode)))
831 return src_0;
833 if (src_1 != 0
834 && (GET_CODE (src_1) == SYMBOL_REF
835 || GET_CODE (src_1) == LABEL_REF
836 || (GET_CODE (src_1) == ADDRESS
837 && GET_MODE (src_1) != VOIDmode)))
838 return src_1;
840 /* Guess which operand is the base address:
841 If either operand is a symbol, then it is the base. If
842 either operand is a CONST_INT, then the other is the base. */
843 if (GET_CODE (src_1) == CONST_INT || CONSTANT_P (src_0))
844 return find_base_value (src_0);
845 else if (GET_CODE (src_0) == CONST_INT || CONSTANT_P (src_1))
846 return find_base_value (src_1);
848 return 0;
851 case LO_SUM:
852 /* The standard form is (lo_sum reg sym) so look only at the
853 second operand. */
854 return find_base_value (XEXP (src, 1));
856 case AND:
857 /* If the second operand is constant set the base
858 address to the first operand. */
859 if (GET_CODE (XEXP (src, 1)) == CONST_INT && INTVAL (XEXP (src, 1)) != 0)
860 return find_base_value (XEXP (src, 0));
861 return 0;
863 case TRUNCATE:
864 if (GET_MODE_SIZE (GET_MODE (src)) < GET_MODE_SIZE (Pmode))
865 break;
866 /* Fall through. */
867 case HIGH:
868 case PRE_INC:
869 case PRE_DEC:
870 case POST_INC:
871 case POST_DEC:
872 case PRE_MODIFY:
873 case POST_MODIFY:
874 return find_base_value (XEXP (src, 0));
876 case ZERO_EXTEND:
877 case SIGN_EXTEND: /* used for NT/Alpha pointers */
879 rtx temp = find_base_value (XEXP (src, 0));
881 #ifdef POINTERS_EXTEND_UNSIGNED
882 if (temp != 0 && CONSTANT_P (temp) && GET_MODE (temp) != Pmode)
883 temp = convert_memory_address (Pmode, temp);
884 #endif
886 return temp;
889 default:
890 break;
893 return 0;
896 /* Called from init_alias_analysis indirectly through note_stores. */
898 /* While scanning insns to find base values, reg_seen[N] is nonzero if
899 register N has been set in this function. */
900 static char *reg_seen;
902 /* Addresses which are known not to alias anything else are identified
903 by a unique integer. */
904 static int unique_id;
906 static void
907 record_set (dest, set, data)
908 rtx dest, set;
909 void *data ATTRIBUTE_UNUSED;
911 unsigned regno;
912 rtx src;
914 if (GET_CODE (dest) != REG)
915 return;
917 regno = REGNO (dest);
919 if (regno >= reg_base_value_size)
920 abort ();
922 if (set)
924 /* A CLOBBER wipes out any old value but does not prevent a previously
925 unset register from acquiring a base address (i.e. reg_seen is not
926 set). */
927 if (GET_CODE (set) == CLOBBER)
929 new_reg_base_value[regno] = 0;
930 return;
932 src = SET_SRC (set);
934 else
936 if (reg_seen[regno])
938 new_reg_base_value[regno] = 0;
939 return;
941 reg_seen[regno] = 1;
942 new_reg_base_value[regno] = gen_rtx_ADDRESS (Pmode,
943 GEN_INT (unique_id++));
944 return;
947 /* This is not the first set. If the new value is not related to the
948 old value, forget the base value. Note that the following code is
949 not detected:
950 extern int x, y; int *p = &x; p += (&y-&x);
951 ANSI C does not allow computing the difference of addresses
952 of distinct top level objects. */
953 if (new_reg_base_value[regno])
954 switch (GET_CODE (src))
956 case LO_SUM:
957 case MINUS:
958 if (XEXP (src, 0) != dest && XEXP (src, 1) != dest)
959 new_reg_base_value[regno] = 0;
960 break;
961 case PLUS:
962 /* If the value we add in the PLUS is also a valid base value,
963 this might be the actual base value, and the original value
964 an index. */
966 rtx other = NULL_RTX;
968 if (XEXP (src, 0) == dest)
969 other = XEXP (src, 1);
970 else if (XEXP (src, 1) == dest)
971 other = XEXP (src, 0);
973 if (! other || find_base_value (other))
974 new_reg_base_value[regno] = 0;
975 break;
977 case AND:
978 if (XEXP (src, 0) != dest || GET_CODE (XEXP (src, 1)) != CONST_INT)
979 new_reg_base_value[regno] = 0;
980 break;
981 default:
982 new_reg_base_value[regno] = 0;
983 break;
985 /* If this is the first set of a register, record the value. */
986 else if ((regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
987 && ! reg_seen[regno] && new_reg_base_value[regno] == 0)
988 new_reg_base_value[regno] = find_base_value (src);
990 reg_seen[regno] = 1;
993 /* Called from loop optimization when a new pseudo-register is
994 created. It indicates that REGNO is being set to VAL. f INVARIANT
995 is true then this value also describes an invariant relationship
996 which can be used to deduce that two registers with unknown values
997 are different. */
999 void
1000 record_base_value (regno, val, invariant)
1001 unsigned int regno;
1002 rtx val;
1003 int invariant;
1005 if (regno >= reg_base_value_size)
1006 return;
1008 if (invariant && alias_invariant)
1009 alias_invariant[regno] = val;
1011 if (GET_CODE (val) == REG)
1013 if (REGNO (val) < reg_base_value_size)
1014 reg_base_value[regno] = reg_base_value[REGNO (val)];
1016 return;
1019 reg_base_value[regno] = find_base_value (val);
1022 /* Clear alias info for a register. This is used if an RTL transformation
1023 changes the value of a register. This is used in flow by AUTO_INC_DEC
1024 optimizations. We don't need to clear reg_base_value, since flow only
1025 changes the offset. */
1027 void
1028 clear_reg_alias_info (reg)
1029 rtx reg;
1031 unsigned int regno = REGNO (reg);
1033 if (regno < reg_known_value_size && regno >= FIRST_PSEUDO_REGISTER)
1034 reg_known_value[regno] = reg;
1037 /* Returns a canonical version of X, from the point of view alias
1038 analysis. (For example, if X is a MEM whose address is a register,
1039 and the register has a known value (say a SYMBOL_REF), then a MEM
1040 whose address is the SYMBOL_REF is returned.) */
1043 canon_rtx (x)
1044 rtx x;
1046 /* Recursively look for equivalences. */
1047 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
1048 && REGNO (x) < reg_known_value_size)
1049 return reg_known_value[REGNO (x)] == x
1050 ? x : canon_rtx (reg_known_value[REGNO (x)]);
1051 else if (GET_CODE (x) == PLUS)
1053 rtx x0 = canon_rtx (XEXP (x, 0));
1054 rtx x1 = canon_rtx (XEXP (x, 1));
1056 if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1))
1058 if (GET_CODE (x0) == CONST_INT)
1059 return plus_constant (x1, INTVAL (x0));
1060 else if (GET_CODE (x1) == CONST_INT)
1061 return plus_constant (x0, INTVAL (x1));
1062 return gen_rtx_PLUS (GET_MODE (x), x0, x1);
1066 /* This gives us much better alias analysis when called from
1067 the loop optimizer. Note we want to leave the original
1068 MEM alone, but need to return the canonicalized MEM with
1069 all the flags with their original values. */
1070 else if (GET_CODE (x) == MEM)
1071 x = replace_equiv_address_nv (x, canon_rtx (XEXP (x, 0)));
1073 return x;
1076 /* Return 1 if X and Y are identical-looking rtx's.
1078 We use the data in reg_known_value above to see if two registers with
1079 different numbers are, in fact, equivalent. */
1081 static int
1082 rtx_equal_for_memref_p (x, y)
1083 rtx x, y;
1085 int i;
1086 int j;
1087 enum rtx_code code;
1088 const char *fmt;
1090 if (x == 0 && y == 0)
1091 return 1;
1092 if (x == 0 || y == 0)
1093 return 0;
1095 x = canon_rtx (x);
1096 y = canon_rtx (y);
1098 if (x == y)
1099 return 1;
1101 code = GET_CODE (x);
1102 /* Rtx's of different codes cannot be equal. */
1103 if (code != GET_CODE (y))
1104 return 0;
1106 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
1107 (REG:SI x) and (REG:HI x) are NOT equivalent. */
1109 if (GET_MODE (x) != GET_MODE (y))
1110 return 0;
1112 /* Some RTL can be compared without a recursive examination. */
1113 switch (code)
1115 case VALUE:
1116 return CSELIB_VAL_PTR (x) == CSELIB_VAL_PTR (y);
1118 case REG:
1119 return REGNO (x) == REGNO (y);
1121 case LABEL_REF:
1122 return XEXP (x, 0) == XEXP (y, 0);
1124 case SYMBOL_REF:
1125 return XSTR (x, 0) == XSTR (y, 0);
1127 case CONST_INT:
1128 case CONST_DOUBLE:
1129 /* There's no need to compare the contents of CONST_DOUBLEs or
1130 CONST_INTs because pointer equality is a good enough
1131 comparison for these nodes. */
1132 return 0;
1134 case ADDRESSOF:
1135 return (XINT (x, 1) == XINT (y, 1)
1136 && rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0)));
1138 default:
1139 break;
1142 /* For commutative operations, the RTX match if the operand match in any
1143 order. Also handle the simple binary and unary cases without a loop. */
1144 if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
1145 return ((rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
1146 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)))
1147 || (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 1))
1148 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 0))));
1149 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
1150 return (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
1151 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)));
1152 else if (GET_RTX_CLASS (code) == '1')
1153 return rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0));
1155 /* Compare the elements. If any pair of corresponding elements
1156 fail to match, return 0 for the whole things.
1158 Limit cases to types which actually appear in addresses. */
1160 fmt = GET_RTX_FORMAT (code);
1161 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1163 switch (fmt[i])
1165 case 'i':
1166 if (XINT (x, i) != XINT (y, i))
1167 return 0;
1168 break;
1170 case 'E':
1171 /* Two vectors must have the same length. */
1172 if (XVECLEN (x, i) != XVECLEN (y, i))
1173 return 0;
1175 /* And the corresponding elements must match. */
1176 for (j = 0; j < XVECLEN (x, i); j++)
1177 if (rtx_equal_for_memref_p (XVECEXP (x, i, j),
1178 XVECEXP (y, i, j)) == 0)
1179 return 0;
1180 break;
1182 case 'e':
1183 if (rtx_equal_for_memref_p (XEXP (x, i), XEXP (y, i)) == 0)
1184 return 0;
1185 break;
1187 /* This can happen for asm operands. */
1188 case 's':
1189 if (strcmp (XSTR (x, i), XSTR (y, i)))
1190 return 0;
1191 break;
1193 /* This can happen for an asm which clobbers memory. */
1194 case '0':
1195 break;
1197 /* It is believed that rtx's at this level will never
1198 contain anything but integers and other rtx's,
1199 except for within LABEL_REFs and SYMBOL_REFs. */
1200 default:
1201 abort ();
1204 return 1;
1207 /* Given an rtx X, find a SYMBOL_REF or LABEL_REF within
1208 X and return it, or return 0 if none found. */
1210 static rtx
1211 find_symbolic_term (x)
1212 rtx x;
1214 int i;
1215 enum rtx_code code;
1216 const char *fmt;
1218 code = GET_CODE (x);
1219 if (code == SYMBOL_REF || code == LABEL_REF)
1220 return x;
1221 if (GET_RTX_CLASS (code) == 'o')
1222 return 0;
1224 fmt = GET_RTX_FORMAT (code);
1225 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1227 rtx t;
1229 if (fmt[i] == 'e')
1231 t = find_symbolic_term (XEXP (x, i));
1232 if (t != 0)
1233 return t;
1235 else if (fmt[i] == 'E')
1236 break;
1238 return 0;
1241 static rtx
1242 find_base_term (x)
1243 rtx x;
1245 cselib_val *val;
1246 struct elt_loc_list *l;
1248 #if defined (FIND_BASE_TERM)
1249 /* Try machine-dependent ways to find the base term. */
1250 x = FIND_BASE_TERM (x);
1251 #endif
1253 switch (GET_CODE (x))
1255 case REG:
1256 return REG_BASE_VALUE (x);
1258 case TRUNCATE:
1259 if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode))
1260 return 0;
1261 /* Fall through. */
1262 case HIGH:
1263 case PRE_INC:
1264 case PRE_DEC:
1265 case POST_INC:
1266 case POST_DEC:
1267 case PRE_MODIFY:
1268 case POST_MODIFY:
1269 return find_base_term (XEXP (x, 0));
1271 case ZERO_EXTEND:
1272 case SIGN_EXTEND: /* Used for Alpha/NT pointers */
1274 rtx temp = find_base_term (XEXP (x, 0));
1276 #ifdef POINTERS_EXTEND_UNSIGNED
1277 if (temp != 0 && CONSTANT_P (temp) && GET_MODE (temp) != Pmode)
1278 temp = convert_memory_address (Pmode, temp);
1279 #endif
1281 return temp;
1284 case VALUE:
1285 val = CSELIB_VAL_PTR (x);
1286 for (l = val->locs; l; l = l->next)
1287 if ((x = find_base_term (l->loc)) != 0)
1288 return x;
1289 return 0;
1291 case CONST:
1292 x = XEXP (x, 0);
1293 if (GET_CODE (x) != PLUS && GET_CODE (x) != MINUS)
1294 return 0;
1295 /* fall through */
1296 case LO_SUM:
1297 case PLUS:
1298 case MINUS:
1300 rtx tmp1 = XEXP (x, 0);
1301 rtx tmp2 = XEXP (x, 1);
1303 /* This is a little bit tricky since we have to determine which of
1304 the two operands represents the real base address. Otherwise this
1305 routine may return the index register instead of the base register.
1307 That may cause us to believe no aliasing was possible, when in
1308 fact aliasing is possible.
1310 We use a few simple tests to guess the base register. Additional
1311 tests can certainly be added. For example, if one of the operands
1312 is a shift or multiply, then it must be the index register and the
1313 other operand is the base register. */
1315 if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2))
1316 return find_base_term (tmp2);
1318 /* If either operand is known to be a pointer, then use it
1319 to determine the base term. */
1320 if (REG_P (tmp1) && REG_POINTER (tmp1))
1321 return find_base_term (tmp1);
1323 if (REG_P (tmp2) && REG_POINTER (tmp2))
1324 return find_base_term (tmp2);
1326 /* Neither operand was known to be a pointer. Go ahead and find the
1327 base term for both operands. */
1328 tmp1 = find_base_term (tmp1);
1329 tmp2 = find_base_term (tmp2);
1331 /* If either base term is named object or a special address
1332 (like an argument or stack reference), then use it for the
1333 base term. */
1334 if (tmp1 != 0
1335 && (GET_CODE (tmp1) == SYMBOL_REF
1336 || GET_CODE (tmp1) == LABEL_REF
1337 || (GET_CODE (tmp1) == ADDRESS
1338 && GET_MODE (tmp1) != VOIDmode)))
1339 return tmp1;
1341 if (tmp2 != 0
1342 && (GET_CODE (tmp2) == SYMBOL_REF
1343 || GET_CODE (tmp2) == LABEL_REF
1344 || (GET_CODE (tmp2) == ADDRESS
1345 && GET_MODE (tmp2) != VOIDmode)))
1346 return tmp2;
1348 /* We could not determine which of the two operands was the
1349 base register and which was the index. So we can determine
1350 nothing from the base alias check. */
1351 return 0;
1354 case AND:
1355 if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) != 0)
1356 return find_base_term (XEXP (x, 0));
1357 return 0;
1359 case SYMBOL_REF:
1360 case LABEL_REF:
1361 return x;
1363 case ADDRESSOF:
1364 return REG_BASE_VALUE (frame_pointer_rtx);
1366 default:
1367 return 0;
1371 /* Return 0 if the addresses X and Y are known to point to different
1372 objects, 1 if they might be pointers to the same object. */
1374 static int
1375 base_alias_check (x, y, x_mode, y_mode)
1376 rtx x, y;
1377 enum machine_mode x_mode, y_mode;
1379 rtx x_base = find_base_term (x);
1380 rtx y_base = find_base_term (y);
1382 /* If the address itself has no known base see if a known equivalent
1383 value has one. If either address still has no known base, nothing
1384 is known about aliasing. */
1385 if (x_base == 0)
1387 rtx x_c;
1389 if (! flag_expensive_optimizations || (x_c = canon_rtx (x)) == x)
1390 return 1;
1392 x_base = find_base_term (x_c);
1393 if (x_base == 0)
1394 return 1;
1397 if (y_base == 0)
1399 rtx y_c;
1400 if (! flag_expensive_optimizations || (y_c = canon_rtx (y)) == y)
1401 return 1;
1403 y_base = find_base_term (y_c);
1404 if (y_base == 0)
1405 return 1;
1408 /* If the base addresses are equal nothing is known about aliasing. */
1409 if (rtx_equal_p (x_base, y_base))
1410 return 1;
1412 /* The base addresses of the read and write are different expressions.
1413 If they are both symbols and they are not accessed via AND, there is
1414 no conflict. We can bring knowledge of object alignment into play
1415 here. For example, on alpha, "char a, b;" can alias one another,
1416 though "char a; long b;" cannot. */
1417 if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS)
1419 if (GET_CODE (x) == AND && GET_CODE (y) == AND)
1420 return 1;
1421 if (GET_CODE (x) == AND
1422 && (GET_CODE (XEXP (x, 1)) != CONST_INT
1423 || (int) GET_MODE_UNIT_SIZE (y_mode) < -INTVAL (XEXP (x, 1))))
1424 return 1;
1425 if (GET_CODE (y) == AND
1426 && (GET_CODE (XEXP (y, 1)) != CONST_INT
1427 || (int) GET_MODE_UNIT_SIZE (x_mode) < -INTVAL (XEXP (y, 1))))
1428 return 1;
1429 /* Differing symbols never alias. */
1430 return 0;
1433 /* If one address is a stack reference there can be no alias:
1434 stack references using different base registers do not alias,
1435 a stack reference can not alias a parameter, and a stack reference
1436 can not alias a global. */
1437 if ((GET_CODE (x_base) == ADDRESS && GET_MODE (x_base) == Pmode)
1438 || (GET_CODE (y_base) == ADDRESS && GET_MODE (y_base) == Pmode))
1439 return 0;
1441 if (! flag_argument_noalias)
1442 return 1;
1444 if (flag_argument_noalias > 1)
1445 return 0;
1447 /* Weak noalias assertion (arguments are distinct, but may match globals). */
1448 return ! (GET_MODE (x_base) == VOIDmode && GET_MODE (y_base) == VOIDmode);
1451 /* Convert the address X into something we can use. This is done by returning
1452 it unchanged unless it is a value; in the latter case we call cselib to get
1453 a more useful rtx. */
1456 get_addr (x)
1457 rtx x;
1459 cselib_val *v;
1460 struct elt_loc_list *l;
1462 if (GET_CODE (x) != VALUE)
1463 return x;
1464 v = CSELIB_VAL_PTR (x);
1465 for (l = v->locs; l; l = l->next)
1466 if (CONSTANT_P (l->loc))
1467 return l->loc;
1468 for (l = v->locs; l; l = l->next)
1469 if (GET_CODE (l->loc) != REG && GET_CODE (l->loc) != MEM)
1470 return l->loc;
1471 if (v->locs)
1472 return v->locs->loc;
1473 return x;
1476 /* Return the address of the (N_REFS + 1)th memory reference to ADDR
1477 where SIZE is the size in bytes of the memory reference. If ADDR
1478 is not modified by the memory reference then ADDR is returned. */
1481 addr_side_effect_eval (addr, size, n_refs)
1482 rtx addr;
1483 int size;
1484 int n_refs;
1486 int offset = 0;
1488 switch (GET_CODE (addr))
1490 case PRE_INC:
1491 offset = (n_refs + 1) * size;
1492 break;
1493 case PRE_DEC:
1494 offset = -(n_refs + 1) * size;
1495 break;
1496 case POST_INC:
1497 offset = n_refs * size;
1498 break;
1499 case POST_DEC:
1500 offset = -n_refs * size;
1501 break;
1503 default:
1504 return addr;
1507 if (offset)
1508 addr = gen_rtx_PLUS (GET_MODE (addr), XEXP (addr, 0), GEN_INT (offset));
1509 else
1510 addr = XEXP (addr, 0);
1512 return addr;
1515 /* Return nonzero if X and Y (memory addresses) could reference the
1516 same location in memory. C is an offset accumulator. When
1517 C is nonzero, we are testing aliases between X and Y + C.
1518 XSIZE is the size in bytes of the X reference,
1519 similarly YSIZE is the size in bytes for Y.
1521 If XSIZE or YSIZE is zero, we do not know the amount of memory being
1522 referenced (the reference was BLKmode), so make the most pessimistic
1523 assumptions.
1525 If XSIZE or YSIZE is negative, we may access memory outside the object
1526 being referenced as a side effect. This can happen when using AND to
1527 align memory references, as is done on the Alpha.
1529 Nice to notice that varying addresses cannot conflict with fp if no
1530 local variables had their addresses taken, but that's too hard now. */
1532 static int
1533 memrefs_conflict_p (xsize, x, ysize, y, c)
1534 rtx x, y;
1535 int xsize, ysize;
1536 HOST_WIDE_INT c;
1538 if (GET_CODE (x) == VALUE)
1539 x = get_addr (x);
1540 if (GET_CODE (y) == VALUE)
1541 y = get_addr (y);
1542 if (GET_CODE (x) == HIGH)
1543 x = XEXP (x, 0);
1544 else if (GET_CODE (x) == LO_SUM)
1545 x = XEXP (x, 1);
1546 else
1547 x = canon_rtx (addr_side_effect_eval (x, xsize, 0));
1548 if (GET_CODE (y) == HIGH)
1549 y = XEXP (y, 0);
1550 else if (GET_CODE (y) == LO_SUM)
1551 y = XEXP (y, 1);
1552 else
1553 y = canon_rtx (addr_side_effect_eval (y, ysize, 0));
1555 if (rtx_equal_for_memref_p (x, y))
1557 if (xsize <= 0 || ysize <= 0)
1558 return 1;
1559 if (c >= 0 && xsize > c)
1560 return 1;
1561 if (c < 0 && ysize+c > 0)
1562 return 1;
1563 return 0;
1566 /* This code used to check for conflicts involving stack references and
1567 globals but the base address alias code now handles these cases. */
1569 if (GET_CODE (x) == PLUS)
1571 /* The fact that X is canonicalized means that this
1572 PLUS rtx is canonicalized. */
1573 rtx x0 = XEXP (x, 0);
1574 rtx x1 = XEXP (x, 1);
1576 if (GET_CODE (y) == PLUS)
1578 /* The fact that Y is canonicalized means that this
1579 PLUS rtx is canonicalized. */
1580 rtx y0 = XEXP (y, 0);
1581 rtx y1 = XEXP (y, 1);
1583 if (rtx_equal_for_memref_p (x1, y1))
1584 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
1585 if (rtx_equal_for_memref_p (x0, y0))
1586 return memrefs_conflict_p (xsize, x1, ysize, y1, c);
1587 if (GET_CODE (x1) == CONST_INT)
1589 if (GET_CODE (y1) == CONST_INT)
1590 return memrefs_conflict_p (xsize, x0, ysize, y0,
1591 c - INTVAL (x1) + INTVAL (y1));
1592 else
1593 return memrefs_conflict_p (xsize, x0, ysize, y,
1594 c - INTVAL (x1));
1596 else if (GET_CODE (y1) == CONST_INT)
1597 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
1599 return 1;
1601 else if (GET_CODE (x1) == CONST_INT)
1602 return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
1604 else if (GET_CODE (y) == PLUS)
1606 /* The fact that Y is canonicalized means that this
1607 PLUS rtx is canonicalized. */
1608 rtx y0 = XEXP (y, 0);
1609 rtx y1 = XEXP (y, 1);
1611 if (GET_CODE (y1) == CONST_INT)
1612 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
1613 else
1614 return 1;
1617 if (GET_CODE (x) == GET_CODE (y))
1618 switch (GET_CODE (x))
1620 case MULT:
1622 /* Handle cases where we expect the second operands to be the
1623 same, and check only whether the first operand would conflict
1624 or not. */
1625 rtx x0, y0;
1626 rtx x1 = canon_rtx (XEXP (x, 1));
1627 rtx y1 = canon_rtx (XEXP (y, 1));
1628 if (! rtx_equal_for_memref_p (x1, y1))
1629 return 1;
1630 x0 = canon_rtx (XEXP (x, 0));
1631 y0 = canon_rtx (XEXP (y, 0));
1632 if (rtx_equal_for_memref_p (x0, y0))
1633 return (xsize == 0 || ysize == 0
1634 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
1636 /* Can't properly adjust our sizes. */
1637 if (GET_CODE (x1) != CONST_INT)
1638 return 1;
1639 xsize /= INTVAL (x1);
1640 ysize /= INTVAL (x1);
1641 c /= INTVAL (x1);
1642 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
1645 case REG:
1646 /* Are these registers known not to be equal? */
1647 if (alias_invariant)
1649 unsigned int r_x = REGNO (x), r_y = REGNO (y);
1650 rtx i_x, i_y; /* invariant relationships of X and Y */
1652 i_x = r_x >= reg_base_value_size ? 0 : alias_invariant[r_x];
1653 i_y = r_y >= reg_base_value_size ? 0 : alias_invariant[r_y];
1655 if (i_x == 0 && i_y == 0)
1656 break;
1658 if (! memrefs_conflict_p (xsize, i_x ? i_x : x,
1659 ysize, i_y ? i_y : y, c))
1660 return 0;
1662 break;
1664 default:
1665 break;
1668 /* Treat an access through an AND (e.g. a subword access on an Alpha)
1669 as an access with indeterminate size. Assume that references
1670 besides AND are aligned, so if the size of the other reference is
1671 at least as large as the alignment, assume no other overlap. */
1672 if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT)
1674 if (GET_CODE (y) == AND || ysize < -INTVAL (XEXP (x, 1)))
1675 xsize = -1;
1676 return memrefs_conflict_p (xsize, XEXP (x, 0), ysize, y, c);
1678 if (GET_CODE (y) == AND && GET_CODE (XEXP (y, 1)) == CONST_INT)
1680 /* ??? If we are indexing far enough into the array/structure, we
1681 may yet be able to determine that we can not overlap. But we
1682 also need to that we are far enough from the end not to overlap
1683 a following reference, so we do nothing with that for now. */
1684 if (GET_CODE (x) == AND || xsize < -INTVAL (XEXP (y, 1)))
1685 ysize = -1;
1686 return memrefs_conflict_p (xsize, x, ysize, XEXP (y, 0), c);
1689 if (GET_CODE (x) == ADDRESSOF)
1691 if (y == frame_pointer_rtx
1692 || GET_CODE (y) == ADDRESSOF)
1693 return xsize <= 0 || ysize <= 0;
1695 if (GET_CODE (y) == ADDRESSOF)
1697 if (x == frame_pointer_rtx)
1698 return xsize <= 0 || ysize <= 0;
1701 if (CONSTANT_P (x))
1703 if (GET_CODE (x) == CONST_INT && GET_CODE (y) == CONST_INT)
1705 c += (INTVAL (y) - INTVAL (x));
1706 return (xsize <= 0 || ysize <= 0
1707 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
1710 if (GET_CODE (x) == CONST)
1712 if (GET_CODE (y) == CONST)
1713 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
1714 ysize, canon_rtx (XEXP (y, 0)), c);
1715 else
1716 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
1717 ysize, y, c);
1719 if (GET_CODE (y) == CONST)
1720 return memrefs_conflict_p (xsize, x, ysize,
1721 canon_rtx (XEXP (y, 0)), c);
1723 if (CONSTANT_P (y))
1724 return (xsize <= 0 || ysize <= 0
1725 || (rtx_equal_for_memref_p (x, y)
1726 && ((c >= 0 && xsize > c) || (c < 0 && ysize+c > 0))));
1728 return 1;
1730 return 1;
1733 /* Functions to compute memory dependencies.
1735 Since we process the insns in execution order, we can build tables
1736 to keep track of what registers are fixed (and not aliased), what registers
1737 are varying in known ways, and what registers are varying in unknown
1738 ways.
1740 If both memory references are volatile, then there must always be a
1741 dependence between the two references, since their order can not be
1742 changed. A volatile and non-volatile reference can be interchanged
1743 though.
1745 A MEM_IN_STRUCT reference at a non-AND varying address can never
1746 conflict with a non-MEM_IN_STRUCT reference at a fixed address. We
1747 also must allow AND addresses, because they may generate accesses
1748 outside the object being referenced. This is used to generate
1749 aligned addresses from unaligned addresses, for instance, the alpha
1750 storeqi_unaligned pattern. */
1752 /* Read dependence: X is read after read in MEM takes place. There can
1753 only be a dependence here if both reads are volatile. */
1756 read_dependence (mem, x)
1757 rtx mem;
1758 rtx x;
1760 return MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem);
1763 /* Returns MEM1 if and only if MEM1 is a scalar at a fixed address and
1764 MEM2 is a reference to a structure at a varying address, or returns
1765 MEM2 if vice versa. Otherwise, returns NULL_RTX. If a non-NULL
1766 value is returned MEM1 and MEM2 can never alias. VARIES_P is used
1767 to decide whether or not an address may vary; it should return
1768 nonzero whenever variation is possible.
1769 MEM1_ADDR and MEM2_ADDR are the addresses of MEM1 and MEM2. */
1771 static rtx
1772 fixed_scalar_and_varying_struct_p (mem1, mem2, mem1_addr, mem2_addr, varies_p)
1773 rtx mem1, mem2;
1774 rtx mem1_addr, mem2_addr;
1775 int (*varies_p) PARAMS ((rtx, int));
1777 if (! flag_strict_aliasing)
1778 return NULL_RTX;
1780 if (MEM_SCALAR_P (mem1) && MEM_IN_STRUCT_P (mem2)
1781 && !varies_p (mem1_addr, 1) && varies_p (mem2_addr, 1))
1782 /* MEM1 is a scalar at a fixed address; MEM2 is a struct at a
1783 varying address. */
1784 return mem1;
1786 if (MEM_IN_STRUCT_P (mem1) && MEM_SCALAR_P (mem2)
1787 && varies_p (mem1_addr, 1) && !varies_p (mem2_addr, 1))
1788 /* MEM2 is a scalar at a fixed address; MEM1 is a struct at a
1789 varying address. */
1790 return mem2;
1792 return NULL_RTX;
1795 /* Returns nonzero if something about the mode or address format MEM1
1796 indicates that it might well alias *anything*. */
1798 static int
1799 aliases_everything_p (mem)
1800 rtx mem;
1802 if (GET_CODE (XEXP (mem, 0)) == AND)
1803 /* If the address is an AND, its very hard to know at what it is
1804 actually pointing. */
1805 return 1;
1807 return 0;
1810 /* Return true if we can determine that the fields referenced cannot
1811 overlap for any pair of objects. */
1813 static bool
1814 nonoverlapping_component_refs_p (x, y)
1815 tree x, y;
1817 tree fieldx, fieldy, typex, typey, orig_y;
1821 /* The comparison has to be done at a common type, since we don't
1822 know how the inheritance hierarchy works. */
1823 orig_y = y;
1826 fieldx = TREE_OPERAND (x, 1);
1827 typex = DECL_FIELD_CONTEXT (fieldx);
1829 y = orig_y;
1832 fieldy = TREE_OPERAND (y, 1);
1833 typey = DECL_FIELD_CONTEXT (fieldy);
1835 if (typex == typey)
1836 goto found;
1838 y = TREE_OPERAND (y, 0);
1840 while (y && TREE_CODE (y) == COMPONENT_REF);
1842 x = TREE_OPERAND (x, 0);
1844 while (x && TREE_CODE (x) == COMPONENT_REF);
1846 /* Never found a common type. */
1847 return false;
1849 found:
1850 /* If we're left with accessing different fields of a structure,
1851 then no overlap. */
1852 if (TREE_CODE (typex) == RECORD_TYPE
1853 && fieldx != fieldy)
1854 return true;
1856 /* The comparison on the current field failed. If we're accessing
1857 a very nested structure, look at the next outer level. */
1858 x = TREE_OPERAND (x, 0);
1859 y = TREE_OPERAND (y, 0);
1861 while (x && y
1862 && TREE_CODE (x) == COMPONENT_REF
1863 && TREE_CODE (y) == COMPONENT_REF);
1865 return false;
1868 /* Look at the bottom of the COMPONENT_REF list for a DECL, and return it. */
1870 static tree
1871 decl_for_component_ref (x)
1872 tree x;
1876 x = TREE_OPERAND (x, 0);
1878 while (x && TREE_CODE (x) == COMPONENT_REF);
1880 return x && DECL_P (x) ? x : NULL_TREE;
1883 /* Walk up the COMPONENT_REF list and adjust OFFSET to compensate for the
1884 offset of the field reference. */
1886 static rtx
1887 adjust_offset_for_component_ref (x, offset)
1888 tree x;
1889 rtx offset;
1891 HOST_WIDE_INT ioffset;
1893 if (! offset)
1894 return NULL_RTX;
1896 ioffset = INTVAL (offset);
1899 tree field = TREE_OPERAND (x, 1);
1901 if (! host_integerp (DECL_FIELD_OFFSET (field), 1))
1902 return NULL_RTX;
1903 ioffset += (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
1904 + (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
1905 / BITS_PER_UNIT));
1907 x = TREE_OPERAND (x, 0);
1909 while (x && TREE_CODE (x) == COMPONENT_REF);
1911 return GEN_INT (ioffset);
1914 /* Return nonzero if we can deterimine the exprs corresponding to memrefs
1915 X and Y and they do not overlap. */
1917 static int
1918 nonoverlapping_memrefs_p (x, y)
1919 rtx x, y;
1921 tree exprx = MEM_EXPR (x), expry = MEM_EXPR (y);
1922 rtx rtlx, rtly;
1923 rtx basex, basey;
1924 rtx moffsetx, moffsety;
1925 HOST_WIDE_INT offsetx = 0, offsety = 0, sizex, sizey, tem;
1927 /* Unless both have exprs, we can't tell anything. */
1928 if (exprx == 0 || expry == 0)
1929 return 0;
1931 /* If both are field references, we may be able to determine something. */
1932 if (TREE_CODE (exprx) == COMPONENT_REF
1933 && TREE_CODE (expry) == COMPONENT_REF
1934 && nonoverlapping_component_refs_p (exprx, expry))
1935 return 1;
1937 /* If the field reference test failed, look at the DECLs involved. */
1938 moffsetx = MEM_OFFSET (x);
1939 if (TREE_CODE (exprx) == COMPONENT_REF)
1941 tree t = decl_for_component_ref (exprx);
1942 if (! t)
1943 return 0;
1944 moffsetx = adjust_offset_for_component_ref (exprx, moffsetx);
1945 exprx = t;
1947 moffsety = MEM_OFFSET (y);
1948 if (TREE_CODE (expry) == COMPONENT_REF)
1950 tree t = decl_for_component_ref (expry);
1951 if (! t)
1952 return 0;
1953 moffsety = adjust_offset_for_component_ref (expry, moffsety);
1954 expry = t;
1957 if (! DECL_P (exprx) || ! DECL_P (expry))
1958 return 0;
1960 rtlx = DECL_RTL (exprx);
1961 rtly = DECL_RTL (expry);
1963 /* If either RTL is not a MEM, it must be a REG or CONCAT, meaning they
1964 can't overlap unless they are the same because we never reuse that part
1965 of the stack frame used for locals for spilled pseudos. */
1966 if ((GET_CODE (rtlx) != MEM || GET_CODE (rtly) != MEM)
1967 && ! rtx_equal_p (rtlx, rtly))
1968 return 1;
1970 /* Get the base and offsets of both decls. If either is a register, we
1971 know both are and are the same, so use that as the base. The only
1972 we can avoid overlap is if we can deduce that they are nonoverlapping
1973 pieces of that decl, which is very rare. */
1974 basex = GET_CODE (rtlx) == MEM ? XEXP (rtlx, 0) : rtlx;
1975 if (GET_CODE (basex) == PLUS && GET_CODE (XEXP (basex, 1)) == CONST_INT)
1976 offsetx = INTVAL (XEXP (basex, 1)), basex = XEXP (basex, 0);
1978 basey = GET_CODE (rtly) == MEM ? XEXP (rtly, 0) : rtly;
1979 if (GET_CODE (basey) == PLUS && GET_CODE (XEXP (basey, 1)) == CONST_INT)
1980 offsety = INTVAL (XEXP (basey, 1)), basey = XEXP (basey, 0);
1982 /* If the bases are different, we know they do not overlap if both
1983 are constants or if one is a constant and the other a pointer into the
1984 stack frame. Otherwise a different base means we can't tell if they
1985 overlap or not. */
1986 if (! rtx_equal_p (basex, basey))
1987 return ((CONSTANT_P (basex) && CONSTANT_P (basey))
1988 || (CONSTANT_P (basex) && REG_P (basey)
1989 && REGNO_PTR_FRAME_P (REGNO (basey)))
1990 || (CONSTANT_P (basey) && REG_P (basex)
1991 && REGNO_PTR_FRAME_P (REGNO (basex))));
1993 sizex = (GET_CODE (rtlx) != MEM ? (int) GET_MODE_SIZE (GET_MODE (rtlx))
1994 : MEM_SIZE (rtlx) ? INTVAL (MEM_SIZE (rtlx))
1995 : -1);
1996 sizey = (GET_CODE (rtly) != MEM ? (int) GET_MODE_SIZE (GET_MODE (rtly))
1997 : MEM_SIZE (rtly) ? INTVAL (MEM_SIZE (rtly)) :
1998 -1);
2000 /* If we have an offset for either memref, it can update the values computed
2001 above. */
2002 if (moffsetx)
2003 offsetx += INTVAL (moffsetx), sizex -= INTVAL (moffsetx);
2004 if (moffsety)
2005 offsety += INTVAL (moffsety), sizey -= INTVAL (moffsety);
2007 /* If a memref has both a size and an offset, we can use the smaller size.
2008 We can't do this if the offset isn't known because we must view this
2009 memref as being anywhere inside the DECL's MEM. */
2010 if (MEM_SIZE (x) && moffsetx)
2011 sizex = INTVAL (MEM_SIZE (x));
2012 if (MEM_SIZE (y) && moffsety)
2013 sizey = INTVAL (MEM_SIZE (y));
2015 /* Put the values of the memref with the lower offset in X's values. */
2016 if (offsetx > offsety)
2018 tem = offsetx, offsetx = offsety, offsety = tem;
2019 tem = sizex, sizex = sizey, sizey = tem;
2022 /* If we don't know the size of the lower-offset value, we can't tell
2023 if they conflict. Otherwise, we do the test. */
2024 return sizex >= 0 && offsety > offsetx + sizex;
2027 /* True dependence: X is read after store in MEM takes place. */
2030 true_dependence (mem, mem_mode, x, varies)
2031 rtx mem;
2032 enum machine_mode mem_mode;
2033 rtx x;
2034 int (*varies) PARAMS ((rtx, int));
2036 rtx x_addr, mem_addr;
2037 rtx base;
2039 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2040 return 1;
2042 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2043 This is used in epilogue deallocation functions. */
2044 if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH)
2045 return 1;
2046 if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH)
2047 return 1;
2049 if (DIFFERENT_ALIAS_SETS_P (x, mem))
2050 return 0;
2052 /* Unchanging memory can't conflict with non-unchanging memory.
2053 A non-unchanging read can conflict with a non-unchanging write.
2054 An unchanging read can conflict with an unchanging write since
2055 there may be a single store to this address to initialize it.
2056 Note that an unchanging store can conflict with a non-unchanging read
2057 since we have to make conservative assumptions when we have a
2058 record with readonly fields and we are copying the whole thing.
2059 Just fall through to the code below to resolve potential conflicts.
2060 This won't handle all cases optimally, but the possible performance
2061 loss should be negligible. */
2062 if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem))
2063 return 0;
2065 if (nonoverlapping_memrefs_p (mem, x))
2066 return 0;
2068 if (mem_mode == VOIDmode)
2069 mem_mode = GET_MODE (mem);
2071 x_addr = get_addr (XEXP (x, 0));
2072 mem_addr = get_addr (XEXP (mem, 0));
2074 base = find_base_term (x_addr);
2075 if (base && (GET_CODE (base) == LABEL_REF
2076 || (GET_CODE (base) == SYMBOL_REF
2077 && CONSTANT_POOL_ADDRESS_P (base))))
2078 return 0;
2080 if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode))
2081 return 0;
2083 x_addr = canon_rtx (x_addr);
2084 mem_addr = canon_rtx (mem_addr);
2086 if (! memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr,
2087 SIZE_FOR_MODE (x), x_addr, 0))
2088 return 0;
2090 if (aliases_everything_p (x))
2091 return 1;
2093 /* We cannot use aliases_everything_p to test MEM, since we must look
2094 at MEM_MODE, rather than GET_MODE (MEM). */
2095 if (mem_mode == QImode || GET_CODE (mem_addr) == AND)
2096 return 1;
2098 /* In true_dependence we also allow BLKmode to alias anything. Why
2099 don't we do this in anti_dependence and output_dependence? */
2100 if (mem_mode == BLKmode || GET_MODE (x) == BLKmode)
2101 return 1;
2103 return ! fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr,
2104 varies);
2107 /* Canonical true dependence: X is read after store in MEM takes place.
2108 Variant of true_dependence which assumes MEM has already been
2109 canonicalized (hence we no longer do that here).
2110 The mem_addr argument has been added, since true_dependence computed
2111 this value prior to canonicalizing. */
2114 canon_true_dependence (mem, mem_mode, mem_addr, x, varies)
2115 rtx mem, mem_addr, x;
2116 enum machine_mode mem_mode;
2117 int (*varies) PARAMS ((rtx, int));
2119 rtx x_addr;
2121 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2122 return 1;
2124 if (DIFFERENT_ALIAS_SETS_P (x, mem))
2125 return 0;
2127 /* If X is an unchanging read, then it can't possibly conflict with any
2128 non-unchanging store. It may conflict with an unchanging write though,
2129 because there may be a single store to this address to initialize it.
2130 Just fall through to the code below to resolve the case where we have
2131 both an unchanging read and an unchanging write. This won't handle all
2132 cases optimally, but the possible performance loss should be
2133 negligible. */
2134 if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem))
2135 return 0;
2137 if (nonoverlapping_memrefs_p (x, mem))
2138 return 0;
2140 x_addr = get_addr (XEXP (x, 0));
2142 if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode))
2143 return 0;
2145 x_addr = canon_rtx (x_addr);
2146 if (! memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr,
2147 SIZE_FOR_MODE (x), x_addr, 0))
2148 return 0;
2150 if (aliases_everything_p (x))
2151 return 1;
2153 /* We cannot use aliases_everything_p to test MEM, since we must look
2154 at MEM_MODE, rather than GET_MODE (MEM). */
2155 if (mem_mode == QImode || GET_CODE (mem_addr) == AND)
2156 return 1;
2158 /* In true_dependence we also allow BLKmode to alias anything. Why
2159 don't we do this in anti_dependence and output_dependence? */
2160 if (mem_mode == BLKmode || GET_MODE (x) == BLKmode)
2161 return 1;
2163 return ! fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr,
2164 varies);
2167 /* Returns non-zero if a write to X might alias a previous read from
2168 (or, if WRITEP is non-zero, a write to) MEM. */
2170 static int
2171 write_dependence_p (mem, x, writep)
2172 rtx mem;
2173 rtx x;
2174 int writep;
2176 rtx x_addr, mem_addr;
2177 rtx fixed_scalar;
2178 rtx base;
2180 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
2181 return 1;
2183 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2184 This is used in epilogue deallocation functions. */
2185 if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH)
2186 return 1;
2187 if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH)
2188 return 1;
2190 if (DIFFERENT_ALIAS_SETS_P (x, mem))
2191 return 0;
2193 /* Unchanging memory can't conflict with non-unchanging memory. */
2194 if (RTX_UNCHANGING_P (x) != RTX_UNCHANGING_P (mem))
2195 return 0;
2197 /* If MEM is an unchanging read, then it can't possibly conflict with
2198 the store to X, because there is at most one store to MEM, and it must
2199 have occurred somewhere before MEM. */
2200 if (! writep && RTX_UNCHANGING_P (mem))
2201 return 0;
2203 if (nonoverlapping_memrefs_p (x, mem))
2204 return 0;
2206 x_addr = get_addr (XEXP (x, 0));
2207 mem_addr = get_addr (XEXP (mem, 0));
2209 if (! writep)
2211 base = find_base_term (mem_addr);
2212 if (base && (GET_CODE (base) == LABEL_REF
2213 || (GET_CODE (base) == SYMBOL_REF
2214 && CONSTANT_POOL_ADDRESS_P (base))))
2215 return 0;
2218 if (! base_alias_check (x_addr, mem_addr, GET_MODE (x),
2219 GET_MODE (mem)))
2220 return 0;
2222 x_addr = canon_rtx (x_addr);
2223 mem_addr = canon_rtx (mem_addr);
2225 if (!memrefs_conflict_p (SIZE_FOR_MODE (mem), mem_addr,
2226 SIZE_FOR_MODE (x), x_addr, 0))
2227 return 0;
2229 fixed_scalar
2230 = fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr,
2231 rtx_addr_varies_p);
2233 return (!(fixed_scalar == mem && !aliases_everything_p (x))
2234 && !(fixed_scalar == x && !aliases_everything_p (mem)));
2237 /* Anti dependence: X is written after read in MEM takes place. */
2240 anti_dependence (mem, x)
2241 rtx mem;
2242 rtx x;
2244 return write_dependence_p (mem, x, /*writep=*/0);
2247 /* Output dependence: X is written after store in MEM takes place. */
2250 output_dependence (mem, x)
2251 rtx mem;
2252 rtx x;
2254 return write_dependence_p (mem, x, /*writep=*/1);
2257 /* A subroutine of nonlocal_mentioned_p, returns 1 if *LOC mentions
2258 something which is not local to the function and is not constant. */
2260 static int
2261 nonlocal_mentioned_p_1 (loc, data)
2262 rtx *loc;
2263 void *data ATTRIBUTE_UNUSED;
2265 rtx x = *loc;
2266 rtx base;
2267 int regno;
2269 if (! x)
2270 return 0;
2272 switch (GET_CODE (x))
2274 case SUBREG:
2275 if (GET_CODE (SUBREG_REG (x)) == REG)
2277 /* Global registers are not local. */
2278 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER
2279 && global_regs[subreg_regno (x)])
2280 return 1;
2281 return 0;
2283 break;
2285 case REG:
2286 regno = REGNO (x);
2287 /* Global registers are not local. */
2288 if (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
2289 return 1;
2290 return 0;
2292 case SCRATCH:
2293 case PC:
2294 case CC0:
2295 case CONST_INT:
2296 case CONST_DOUBLE:
2297 case CONST_VECTOR:
2298 case CONST:
2299 case LABEL_REF:
2300 return 0;
2302 case SYMBOL_REF:
2303 /* Constants in the function's constants pool are constant. */
2304 if (CONSTANT_POOL_ADDRESS_P (x))
2305 return 0;
2306 return 1;
2308 case CALL:
2309 /* Non-constant calls and recursion are not local. */
2310 return 1;
2312 case MEM:
2313 /* Be overly conservative and consider any volatile memory
2314 reference as not local. */
2315 if (MEM_VOLATILE_P (x))
2316 return 1;
2317 base = find_base_term (XEXP (x, 0));
2318 if (base)
2320 /* A Pmode ADDRESS could be a reference via the structure value
2321 address or static chain. Such memory references are nonlocal.
2323 Thus, we have to examine the contents of the ADDRESS to find
2324 out if this is a local reference or not. */
2325 if (GET_CODE (base) == ADDRESS
2326 && GET_MODE (base) == Pmode
2327 && (XEXP (base, 0) == stack_pointer_rtx
2328 || XEXP (base, 0) == arg_pointer_rtx
2329 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2330 || XEXP (base, 0) == hard_frame_pointer_rtx
2331 #endif
2332 || XEXP (base, 0) == frame_pointer_rtx))
2333 return 0;
2334 /* Constants in the function's constant pool are constant. */
2335 if (GET_CODE (base) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (base))
2336 return 0;
2338 return 1;
2340 case UNSPEC_VOLATILE:
2341 case ASM_INPUT:
2342 return 1;
2344 case ASM_OPERANDS:
2345 if (MEM_VOLATILE_P (x))
2346 return 1;
2348 /* FALLTHROUGH */
2350 default:
2351 break;
2354 return 0;
2357 /* Returns non-zero if X might mention something which is not
2358 local to the function and is not constant. */
2360 static int
2361 nonlocal_mentioned_p (x)
2362 rtx x;
2365 if (INSN_P (x))
2367 if (GET_CODE (x) == CALL_INSN)
2369 if (! CONST_OR_PURE_CALL_P (x))
2370 return 1;
2371 x = CALL_INSN_FUNCTION_USAGE (x);
2372 if (x == 0)
2373 return 0;
2375 else
2376 x = PATTERN (x);
2379 return for_each_rtx (&x, nonlocal_mentioned_p_1, NULL);
2382 /* A subroutine of nonlocal_referenced_p, returns 1 if *LOC references
2383 something which is not local to the function and is not constant. */
2385 static int
2386 nonlocal_referenced_p_1 (loc, data)
2387 rtx *loc;
2388 void *data ATTRIBUTE_UNUSED;
2390 rtx x = *loc;
2392 if (! x)
2393 return 0;
2395 switch (GET_CODE (x))
2397 case MEM:
2398 case REG:
2399 case SYMBOL_REF:
2400 case SUBREG:
2401 return nonlocal_mentioned_p (x);
2403 case CALL:
2404 /* Non-constant calls and recursion are not local. */
2405 return 1;
2407 case SET:
2408 if (nonlocal_mentioned_p (SET_SRC (x)))
2409 return 1;
2411 if (GET_CODE (SET_DEST (x)) == MEM)
2412 return nonlocal_mentioned_p (XEXP (SET_DEST (x), 0));
2414 /* If the destination is anything other than a CC0, PC,
2415 MEM, REG, or a SUBREG of a REG that occupies all of
2416 the REG, then X references nonlocal memory if it is
2417 mentioned in the destination. */
2418 if (GET_CODE (SET_DEST (x)) != CC0
2419 && GET_CODE (SET_DEST (x)) != PC
2420 && GET_CODE (SET_DEST (x)) != REG
2421 && ! (GET_CODE (SET_DEST (x)) == SUBREG
2422 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
2423 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
2424 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
2425 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2426 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
2427 return nonlocal_mentioned_p (SET_DEST (x));
2428 return 0;
2430 case CLOBBER:
2431 if (GET_CODE (XEXP (x, 0)) == MEM)
2432 return nonlocal_mentioned_p (XEXP (XEXP (x, 0), 0));
2433 return 0;
2435 case USE:
2436 return nonlocal_mentioned_p (XEXP (x, 0));
2438 case ASM_INPUT:
2439 case UNSPEC_VOLATILE:
2440 return 1;
2442 case ASM_OPERANDS:
2443 if (MEM_VOLATILE_P (x))
2444 return 1;
2446 /* FALLTHROUGH */
2448 default:
2449 break;
2452 return 0;
2455 /* Returns non-zero if X might reference something which is not
2456 local to the function and is not constant. */
2458 static int
2459 nonlocal_referenced_p (x)
2460 rtx x;
2463 if (INSN_P (x))
2465 if (GET_CODE (x) == CALL_INSN)
2467 if (! CONST_OR_PURE_CALL_P (x))
2468 return 1;
2469 x = CALL_INSN_FUNCTION_USAGE (x);
2470 if (x == 0)
2471 return 0;
2473 else
2474 x = PATTERN (x);
2477 return for_each_rtx (&x, nonlocal_referenced_p_1, NULL);
2480 /* A subroutine of nonlocal_set_p, returns 1 if *LOC sets
2481 something which is not local to the function and is not constant. */
2483 static int
2484 nonlocal_set_p_1 (loc, data)
2485 rtx *loc;
2486 void *data ATTRIBUTE_UNUSED;
2488 rtx x = *loc;
2490 if (! x)
2491 return 0;
2493 switch (GET_CODE (x))
2495 case CALL:
2496 /* Non-constant calls and recursion are not local. */
2497 return 1;
2499 case PRE_INC:
2500 case PRE_DEC:
2501 case POST_INC:
2502 case POST_DEC:
2503 case PRE_MODIFY:
2504 case POST_MODIFY:
2505 return nonlocal_mentioned_p (XEXP (x, 0));
2507 case SET:
2508 if (nonlocal_mentioned_p (SET_DEST (x)))
2509 return 1;
2510 return nonlocal_set_p (SET_SRC (x));
2512 case CLOBBER:
2513 return nonlocal_mentioned_p (XEXP (x, 0));
2515 case USE:
2516 return 0;
2518 case ASM_INPUT:
2519 case UNSPEC_VOLATILE:
2520 return 1;
2522 case ASM_OPERANDS:
2523 if (MEM_VOLATILE_P (x))
2524 return 1;
2526 /* FALLTHROUGH */
2528 default:
2529 break;
2532 return 0;
2535 /* Returns non-zero if X might set something which is not
2536 local to the function and is not constant. */
2538 static int
2539 nonlocal_set_p (x)
2540 rtx x;
2543 if (INSN_P (x))
2545 if (GET_CODE (x) == CALL_INSN)
2547 if (! CONST_OR_PURE_CALL_P (x))
2548 return 1;
2549 x = CALL_INSN_FUNCTION_USAGE (x);
2550 if (x == 0)
2551 return 0;
2553 else
2554 x = PATTERN (x);
2557 return for_each_rtx (&x, nonlocal_set_p_1, NULL);
2560 /* Mark the function if it is constant. */
2562 void
2563 mark_constant_function ()
2565 rtx insn;
2566 int nonlocal_memory_referenced;
2568 if (TREE_PUBLIC (current_function_decl)
2569 || TREE_READONLY (current_function_decl)
2570 || DECL_IS_PURE (current_function_decl)
2571 || TREE_THIS_VOLATILE (current_function_decl)
2572 || TYPE_MODE (TREE_TYPE (current_function_decl)) == VOIDmode
2573 || current_function_has_nonlocal_goto)
2574 return;
2576 /* A loop might not return which counts as a side effect. */
2577 if (mark_dfs_back_edges ())
2578 return;
2580 nonlocal_memory_referenced = 0;
2582 init_alias_analysis ();
2584 /* Determine if this is a constant or pure function. */
2586 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2588 if (! INSN_P (insn))
2589 continue;
2591 if (nonlocal_set_p (insn) || global_reg_mentioned_p (insn)
2592 || volatile_refs_p (PATTERN (insn)))
2593 break;
2595 if (! nonlocal_memory_referenced)
2596 nonlocal_memory_referenced = nonlocal_referenced_p (insn);
2599 end_alias_analysis ();
2601 /* Mark the function. */
2603 if (insn)
2605 else if (nonlocal_memory_referenced)
2606 DECL_IS_PURE (current_function_decl) = 1;
2607 else
2608 TREE_READONLY (current_function_decl) = 1;
2612 static HARD_REG_SET argument_registers;
2614 void
2615 init_alias_once ()
2617 int i;
2619 #ifndef OUTGOING_REGNO
2620 #define OUTGOING_REGNO(N) N
2621 #endif
2622 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2623 /* Check whether this register can hold an incoming pointer
2624 argument. FUNCTION_ARG_REGNO_P tests outgoing register
2625 numbers, so translate if necessary due to register windows. */
2626 if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i))
2627 && HARD_REGNO_MODE_OK (i, Pmode))
2628 SET_HARD_REG_BIT (argument_registers, i);
2630 alias_sets = splay_tree_new (splay_tree_compare_ints, 0, 0);
2633 /* Initialize the aliasing machinery. Initialize the REG_KNOWN_VALUE
2634 array. */
2636 void
2637 init_alias_analysis ()
2639 int maxreg = max_reg_num ();
2640 int changed, pass;
2641 int i;
2642 unsigned int ui;
2643 rtx insn;
2645 reg_known_value_size = maxreg;
2647 reg_known_value
2648 = (rtx *) xcalloc ((maxreg - FIRST_PSEUDO_REGISTER), sizeof (rtx))
2649 - FIRST_PSEUDO_REGISTER;
2650 reg_known_equiv_p
2651 = (char*) xcalloc ((maxreg - FIRST_PSEUDO_REGISTER), sizeof (char))
2652 - FIRST_PSEUDO_REGISTER;
2654 /* Overallocate reg_base_value to allow some growth during loop
2655 optimization. Loop unrolling can create a large number of
2656 registers. */
2657 reg_base_value_size = maxreg * 2;
2658 reg_base_value = (rtx *) xcalloc (reg_base_value_size, sizeof (rtx));
2659 ggc_add_rtx_root (reg_base_value, reg_base_value_size);
2661 new_reg_base_value = (rtx *) xmalloc (reg_base_value_size * sizeof (rtx));
2662 reg_seen = (char *) xmalloc (reg_base_value_size);
2663 if (! reload_completed && flag_unroll_loops)
2665 /* ??? Why are we realloc'ing if we're just going to zero it? */
2666 alias_invariant = (rtx *)xrealloc (alias_invariant,
2667 reg_base_value_size * sizeof (rtx));
2668 memset ((char *)alias_invariant, 0, reg_base_value_size * sizeof (rtx));
2671 /* The basic idea is that each pass through this loop will use the
2672 "constant" information from the previous pass to propagate alias
2673 information through another level of assignments.
2675 This could get expensive if the assignment chains are long. Maybe
2676 we should throttle the number of iterations, possibly based on
2677 the optimization level or flag_expensive_optimizations.
2679 We could propagate more information in the first pass by making use
2680 of REG_N_SETS to determine immediately that the alias information
2681 for a pseudo is "constant".
2683 A program with an uninitialized variable can cause an infinite loop
2684 here. Instead of doing a full dataflow analysis to detect such problems
2685 we just cap the number of iterations for the loop.
2687 The state of the arrays for the set chain in question does not matter
2688 since the program has undefined behavior. */
2690 pass = 0;
2693 /* Assume nothing will change this iteration of the loop. */
2694 changed = 0;
2696 /* We want to assign the same IDs each iteration of this loop, so
2697 start counting from zero each iteration of the loop. */
2698 unique_id = 0;
2700 /* We're at the start of the function each iteration through the
2701 loop, so we're copying arguments. */
2702 copying_arguments = 1;
2704 /* Wipe the potential alias information clean for this pass. */
2705 memset ((char *) new_reg_base_value, 0, reg_base_value_size * sizeof (rtx));
2707 /* Wipe the reg_seen array clean. */
2708 memset ((char *) reg_seen, 0, reg_base_value_size);
2710 /* Mark all hard registers which may contain an address.
2711 The stack, frame and argument pointers may contain an address.
2712 An argument register which can hold a Pmode value may contain
2713 an address even if it is not in BASE_REGS.
2715 The address expression is VOIDmode for an argument and
2716 Pmode for other registers. */
2718 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2719 if (TEST_HARD_REG_BIT (argument_registers, i))
2720 new_reg_base_value[i] = gen_rtx_ADDRESS (VOIDmode,
2721 gen_rtx_REG (Pmode, i));
2723 new_reg_base_value[STACK_POINTER_REGNUM]
2724 = gen_rtx_ADDRESS (Pmode, stack_pointer_rtx);
2725 new_reg_base_value[ARG_POINTER_REGNUM]
2726 = gen_rtx_ADDRESS (Pmode, arg_pointer_rtx);
2727 new_reg_base_value[FRAME_POINTER_REGNUM]
2728 = gen_rtx_ADDRESS (Pmode, frame_pointer_rtx);
2729 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2730 new_reg_base_value[HARD_FRAME_POINTER_REGNUM]
2731 = gen_rtx_ADDRESS (Pmode, hard_frame_pointer_rtx);
2732 #endif
2734 /* Walk the insns adding values to the new_reg_base_value array. */
2735 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2737 if (INSN_P (insn))
2739 rtx note, set;
2741 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
2742 /* The prologue/epilogue insns are not threaded onto the
2743 insn chain until after reload has completed. Thus,
2744 there is no sense wasting time checking if INSN is in
2745 the prologue/epilogue until after reload has completed. */
2746 if (reload_completed
2747 && prologue_epilogue_contains (insn))
2748 continue;
2749 #endif
2751 /* If this insn has a noalias note, process it, Otherwise,
2752 scan for sets. A simple set will have no side effects
2753 which could change the base value of any other register. */
2755 if (GET_CODE (PATTERN (insn)) == SET
2756 && REG_NOTES (insn) != 0
2757 && find_reg_note (insn, REG_NOALIAS, NULL_RTX))
2758 record_set (SET_DEST (PATTERN (insn)), NULL_RTX, NULL);
2759 else
2760 note_stores (PATTERN (insn), record_set, NULL);
2762 set = single_set (insn);
2764 if (set != 0
2765 && GET_CODE (SET_DEST (set)) == REG
2766 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER)
2768 unsigned int regno = REGNO (SET_DEST (set));
2769 rtx src = SET_SRC (set);
2771 if (REG_NOTES (insn) != 0
2772 && (((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
2773 && REG_N_SETS (regno) == 1)
2774 || (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0)
2775 && GET_CODE (XEXP (note, 0)) != EXPR_LIST
2776 && ! rtx_varies_p (XEXP (note, 0), 1)
2777 && ! reg_overlap_mentioned_p (SET_DEST (set), XEXP (note, 0)))
2779 reg_known_value[regno] = XEXP (note, 0);
2780 reg_known_equiv_p[regno] = REG_NOTE_KIND (note) == REG_EQUIV;
2782 else if (REG_N_SETS (regno) == 1
2783 && GET_CODE (src) == PLUS
2784 && GET_CODE (XEXP (src, 0)) == REG
2785 && REGNO (XEXP (src, 0)) >= FIRST_PSEUDO_REGISTER
2786 && (reg_known_value[REGNO (XEXP (src, 0))])
2787 && GET_CODE (XEXP (src, 1)) == CONST_INT)
2789 rtx op0 = XEXP (src, 0);
2790 op0 = reg_known_value[REGNO (op0)];
2791 reg_known_value[regno]
2792 = plus_constant (op0, INTVAL (XEXP (src, 1)));
2793 reg_known_equiv_p[regno] = 0;
2795 else if (REG_N_SETS (regno) == 1
2796 && ! rtx_varies_p (src, 1))
2798 reg_known_value[regno] = src;
2799 reg_known_equiv_p[regno] = 0;
2803 else if (GET_CODE (insn) == NOTE
2804 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
2805 copying_arguments = 0;
2808 /* Now propagate values from new_reg_base_value to reg_base_value. */
2809 for (ui = 0; ui < reg_base_value_size; ui++)
2811 if (new_reg_base_value[ui]
2812 && new_reg_base_value[ui] != reg_base_value[ui]
2813 && ! rtx_equal_p (new_reg_base_value[ui], reg_base_value[ui]))
2815 reg_base_value[ui] = new_reg_base_value[ui];
2816 changed = 1;
2820 while (changed && ++pass < MAX_ALIAS_LOOP_PASSES);
2822 /* Fill in the remaining entries. */
2823 for (i = FIRST_PSEUDO_REGISTER; i < maxreg; i++)
2824 if (reg_known_value[i] == 0)
2825 reg_known_value[i] = regno_reg_rtx[i];
2827 /* Simplify the reg_base_value array so that no register refers to
2828 another register, except to special registers indirectly through
2829 ADDRESS expressions.
2831 In theory this loop can take as long as O(registers^2), but unless
2832 there are very long dependency chains it will run in close to linear
2833 time.
2835 This loop may not be needed any longer now that the main loop does
2836 a better job at propagating alias information. */
2837 pass = 0;
2840 changed = 0;
2841 pass++;
2842 for (ui = 0; ui < reg_base_value_size; ui++)
2844 rtx base = reg_base_value[ui];
2845 if (base && GET_CODE (base) == REG)
2847 unsigned int base_regno = REGNO (base);
2848 if (base_regno == ui) /* register set from itself */
2849 reg_base_value[ui] = 0;
2850 else
2851 reg_base_value[ui] = reg_base_value[base_regno];
2852 changed = 1;
2856 while (changed && pass < MAX_ALIAS_LOOP_PASSES);
2858 /* Clean up. */
2859 free (new_reg_base_value);
2860 new_reg_base_value = 0;
2861 free (reg_seen);
2862 reg_seen = 0;
2865 void
2866 end_alias_analysis ()
2868 free (reg_known_value + FIRST_PSEUDO_REGISTER);
2869 reg_known_value = 0;
2870 reg_known_value_size = 0;
2871 free (reg_known_equiv_p + FIRST_PSEUDO_REGISTER);
2872 reg_known_equiv_p = 0;
2873 if (reg_base_value)
2875 ggc_del_root (reg_base_value);
2876 free (reg_base_value);
2877 reg_base_value = 0;
2879 reg_base_value_size = 0;
2880 if (alias_invariant)
2882 free (alias_invariant);
2883 alias_invariant = 0;