1 /* Alias analysis for GNU C
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by John Carr (jfc@mit.edu).
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC 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 GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "hard-reg-set.h"
29 static rtx canon_rtx PROTO((rtx));
30 static int rtx_equal_for_memref_p PROTO((rtx, rtx));
31 static rtx find_symbolic_term PROTO((rtx));
32 static int memrefs_conflict_p PROTO((int, rtx, int, rtx,
35 /* Set up all info needed to perform alias analysis on memory references. */
37 #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
39 /* reg_base_value[N] gives an address to which register N is related.
40 If all sets after the first add or subtract to the current value
41 or otherwise modify it so it does not point to a different top level
42 object, reg_base_value[N] is equal to the address part of the source
45 A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF. ADDRESS
46 expressions represent certain special values: function arguments and
47 the stack, frame, and argument pointers. The contents of an address
48 expression are not used (but they are descriptive for debugging);
49 only the address and mode matter. Pointer equality, not rtx_equal_p,
50 determines whether two ADDRESS expressions refer to the same base
51 address. The mode determines whether it is a function argument or
52 other special value. */
55 unsigned int reg_base_value_size; /* size of reg_base_value array */
56 #define REG_BASE_VALUE(X) \
57 (REGNO (X) < reg_base_value_size ? reg_base_value[REGNO (X)] : 0)
59 /* Vector indexed by N giving the initial (unchanging) value known
60 for pseudo-register N. */
63 /* Indicates number of valid entries in reg_known_value. */
64 static int reg_known_value_size;
66 /* Vector recording for each reg_known_value whether it is due to a
67 REG_EQUIV note. Future passes (viz., reload) may replace the
68 pseudo with the equivalent expression and so we account for the
69 dependences that would be introduced if that happens. */
70 /* ??? This is a problem only on the Convex. The REG_EQUIV notes created in
71 assign_parms mention the arg pointer, and there are explicit insns in the
72 RTL that modify the arg pointer. Thus we must ensure that such insns don't
73 get scheduled across each other because that would invalidate the REG_EQUIV
74 notes. One could argue that the REG_EQUIV notes are wrong, but solving
75 the problem in the scheduler will likely give better code, so we do it
77 char *reg_known_equiv_p;
79 /* True when scanning insns from the start of the rtl to the
80 NOTE_INSN_FUNCTION_BEG note. */
82 static int copying_arguments;
84 /* Inside SRC, the source of a SET, find a base address. */
90 switch (GET_CODE (src))
97 /* At the start of a function argument registers have known base
98 values which may be lost later. Returning an ADDRESS
99 expression here allows optimization based on argument values
100 even when the argument registers are used for other purposes. */
101 if (REGNO (src) < FIRST_PSEUDO_REGISTER && copying_arguments)
102 return reg_base_value[REGNO (src)];
106 /* Check for an argument passed in memory. Only record in the
107 copying-arguments block; it is too hard to track changes
109 if (copying_arguments
110 && (XEXP (src, 0) == arg_pointer_rtx
111 || (GET_CODE (XEXP (src, 0)) == PLUS
112 && XEXP (XEXP (src, 0), 0) == arg_pointer_rtx)))
113 return gen_rtx (ADDRESS, VOIDmode, src);
118 if (GET_CODE (src) != PLUS && GET_CODE (src) != MINUS)
125 rtx src_0 = XEXP (src, 0), src_1 = XEXP (src, 1);
127 /* Guess which operand is the base address.
129 If the first operand is a symbol or the second operand is
130 an integer, the first operand is the base address. Else if
131 either operand is a register marked as a pointer, it is the
134 if (GET_CODE (src_1) == CONST_INT
135 || GET_CODE (src_0) == SYMBOL_REF
136 || GET_CODE (src_0) == LABEL_REF
137 || GET_CODE (src_0) == CONST)
138 return find_base_value (src_0);
140 if (GET_CODE (src_0) == REG && REGNO_POINTER_FLAG (REGNO (src_0)))
141 return find_base_value (src_0);
143 if (GET_CODE (src_1) == REG && REGNO_POINTER_FLAG (REGNO (src_1)))
144 return find_base_value (src_1);
150 /* The standard form is (lo_sum reg sym) so look only at the
152 return find_base_value (XEXP (src, 1));
155 /* If the second operand is constant set the base
156 address to the first operand. */
157 if (GET_CODE (XEXP (src, 1)) == CONST_INT && INTVAL (XEXP (src, 1)) != 0)
158 return find_base_value (XEXP (src, 0));
162 return find_base_value (XEXP (src, 0));
168 /* Called from init_alias_analysis indirectly through note_stores. */
170 /* while scanning insns to find base values, reg_seen[N] is nonzero if
171 register N has been set in this function. */
172 static char *reg_seen;
175 record_set (dest, set)
181 if (GET_CODE (dest) != REG)
184 regno = REGNO (dest);
188 /* A CLOBBER wipes out any old value but does not prevent a previously
189 unset register from acquiring a base address (i.e. reg_seen is not
191 if (GET_CODE (set) == CLOBBER)
193 reg_base_value[regno] = 0;
200 static int unique_id;
203 reg_base_value[regno] = 0;
207 reg_base_value[regno] = gen_rtx (ADDRESS, Pmode,
208 GEN_INT (unique_id++));
212 /* This is not the first set. If the new value is not related to the
213 old value, forget the base value. Note that the following code is
215 extern int x, y; int *p = &x; p += (&y-&x);
216 ANSI C does not allow computing the difference of addresses
217 of distinct top level objects. */
218 if (reg_base_value[regno])
219 switch (GET_CODE (src))
224 if (XEXP (src, 0) != dest && XEXP (src, 1) != dest)
225 reg_base_value[regno] = 0;
228 if (XEXP (src, 0) != dest || GET_CODE (XEXP (src, 1)) != CONST_INT)
229 reg_base_value[regno] = 0;
232 reg_base_value[regno] = 0;
235 /* If this is the first set of a register, record the value. */
236 else if ((regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno])
237 && ! reg_seen[regno] && reg_base_value[regno] == 0)
238 reg_base_value[regno] = find_base_value (src);
243 /* Called from loop optimization when a new pseudo-register is created. */
245 record_base_value (regno, val)
249 if (!flag_alias_check || regno >= reg_base_value_size)
251 if (GET_CODE (val) == REG)
253 if (REGNO (val) < reg_base_value_size)
254 reg_base_value[regno] = reg_base_value[REGNO (val)];
257 reg_base_value[regno] = find_base_value (val);
264 /* Recursively look for equivalences. */
265 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
266 && REGNO (x) < reg_known_value_size)
267 return reg_known_value[REGNO (x)] == x
268 ? x : canon_rtx (reg_known_value[REGNO (x)]);
269 else if (GET_CODE (x) == PLUS)
271 rtx x0 = canon_rtx (XEXP (x, 0));
272 rtx x1 = canon_rtx (XEXP (x, 1));
274 if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1))
276 /* We can tolerate LO_SUMs being offset here; these
277 rtl are used for nothing other than comparisons. */
278 if (GET_CODE (x0) == CONST_INT)
279 return plus_constant_for_output (x1, INTVAL (x0));
280 else if (GET_CODE (x1) == CONST_INT)
281 return plus_constant_for_output (x0, INTVAL (x1));
282 return gen_rtx (PLUS, GET_MODE (x), x0, x1);
285 /* This gives us much better alias analysis when called from
286 the loop optimizer. Note we want to leave the original
287 MEM alone, but need to return the canonicalized MEM with
288 all the flags with their original values. */
289 else if (GET_CODE (x) == MEM)
291 rtx addr = canon_rtx (XEXP (x, 0));
292 if (addr != XEXP (x, 0))
294 rtx new = gen_rtx (MEM, GET_MODE (x), addr);
295 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
296 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
297 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
304 /* Return 1 if X and Y are identical-looking rtx's.
306 We use the data in reg_known_value above to see if two registers with
307 different numbers are, in fact, equivalent. */
310 rtx_equal_for_memref_p (x, y)
315 register enum rtx_code code;
318 if (x == 0 && y == 0)
320 if (x == 0 || y == 0)
329 /* Rtx's of different codes cannot be equal. */
330 if (code != GET_CODE (y))
333 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
334 (REG:SI x) and (REG:HI x) are NOT equivalent. */
336 if (GET_MODE (x) != GET_MODE (y))
339 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
342 return REGNO (x) == REGNO (y);
343 if (code == LABEL_REF)
344 return XEXP (x, 0) == XEXP (y, 0);
345 if (code == SYMBOL_REF)
346 return XSTR (x, 0) == XSTR (y, 0);
348 /* For commutative operations, the RTX match if the operand match in any
349 order. Also handle the simple binary and unary cases without a loop. */
350 if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c')
351 return ((rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
352 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)))
353 || (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 1))
354 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 0))));
355 else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2')
356 return (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0))
357 && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1)));
358 else if (GET_RTX_CLASS (code) == '1')
359 return rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0));
361 /* Compare the elements. If any pair of corresponding elements
362 fail to match, return 0 for the whole things. */
364 fmt = GET_RTX_FORMAT (code);
365 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
370 if (XWINT (x, i) != XWINT (y, i))
376 if (XINT (x, i) != XINT (y, i))
382 /* Two vectors must have the same length. */
383 if (XVECLEN (x, i) != XVECLEN (y, i))
386 /* And the corresponding elements must match. */
387 for (j = 0; j < XVECLEN (x, i); j++)
388 if (rtx_equal_for_memref_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
393 if (rtx_equal_for_memref_p (XEXP (x, i), XEXP (y, i)) == 0)
399 if (strcmp (XSTR (x, i), XSTR (y, i)))
404 /* These are just backpointers, so they don't matter. */
410 /* It is believed that rtx's at this level will never
411 contain anything but integers and other rtx's,
412 except for within LABEL_REFs and SYMBOL_REFs. */
420 /* Given an rtx X, find a SYMBOL_REF or LABEL_REF within
421 X and return it, or return 0 if none found. */
424 find_symbolic_term (x)
428 register enum rtx_code code;
432 if (code == SYMBOL_REF || code == LABEL_REF)
434 if (GET_RTX_CLASS (code) == 'o')
437 fmt = GET_RTX_FORMAT (code);
438 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
444 t = find_symbolic_term (XEXP (x, i));
448 else if (fmt[i] == 'E')
458 switch (GET_CODE (x))
461 return REG_BASE_VALUE (x);
464 return find_base_term (XEXP (x, 0));
468 if (GET_CODE (x) != PLUS && GET_CODE (x) != MINUS)
475 rtx tmp = find_base_term (XEXP (x, 0));
478 return find_base_term (XEXP (x, 1));
482 if (GET_CODE (XEXP (x, 0)) == REG && GET_CODE (XEXP (x, 1)) == CONST_INT)
483 return REG_BASE_VALUE (XEXP (x, 0));
495 /* Return 0 if the addresses X and Y are known to point to different
496 objects, 1 if they might be pointers to the same object. */
499 base_alias_check (x, y)
502 rtx x_base = find_base_term (x);
503 rtx y_base = find_base_term (y);
505 /* If either base address is unknown or the base addresses are equal,
506 nothing is known about aliasing. */
508 if (x_base == 0 || y_base == 0 || rtx_equal_p (x_base, y_base))
511 /* The base addresses of the read and write are different
512 expressions. If they are both symbols and they are not accessed
513 via AND, there is no conflict. */
514 /* XXX: We can bring knowledge of object alignment and offset into
515 play here. For example, on alpha, "char a, b;" can alias one
516 another, though "char a; long b;" cannot. Similarly, offsets
517 into strutures may be brought into play. Given "char a, b[40];",
518 a and b[1] may overlap, but a and b[20] do not. */
519 if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS)
521 return GET_CODE (x) == AND || GET_CODE (y) == AND;
524 /* If one address is a stack reference there can be no alias:
525 stack references using different base registers do not alias,
526 a stack reference can not alias a parameter, and a stack reference
527 can not alias a global. */
528 if ((GET_CODE (x_base) == ADDRESS && GET_MODE (x_base) == Pmode)
529 || (GET_CODE (y_base) == ADDRESS && GET_MODE (y_base) == Pmode))
532 if (! flag_argument_noalias)
535 if (flag_argument_noalias > 1)
538 /* Weak noalias assertion (arguments are distinct, but may match globals). */
539 return ! (GET_MODE (x_base) == VOIDmode && GET_MODE (y_base) == VOIDmode);
542 /* Return nonzero if X and Y (memory addresses) could reference the
543 same location in memory. C is an offset accumulator. When
544 C is nonzero, we are testing aliases between X and Y + C.
545 XSIZE is the size in bytes of the X reference,
546 similarly YSIZE is the size in bytes for Y.
548 If XSIZE or YSIZE is zero, we do not know the amount of memory being
549 referenced (the reference was BLKmode), so make the most pessimistic
552 If XSIZE or YSIZE is negative, we may access memory outside the object
553 being referenced as a side effect. This can happen when using AND to
554 align memory references, as is done on the Alpha.
556 We recognize the following cases of non-conflicting memory:
558 (1) addresses involving the frame pointer cannot conflict
559 with addresses involving static variables.
560 (2) static variables with different addresses cannot conflict.
562 Nice to notice that varying addresses cannot conflict with fp if no
563 local variables had their addresses taken, but that's too hard now. */
567 memrefs_conflict_p (xsize, x, ysize, y, c)
572 if (GET_CODE (x) == HIGH)
574 else if (GET_CODE (x) == LO_SUM)
578 if (GET_CODE (y) == HIGH)
580 else if (GET_CODE (y) == LO_SUM)
585 if (rtx_equal_for_memref_p (x, y))
587 if (xsize <= 0 || ysize <= 0)
589 if (c >= 0 && xsize > c)
591 if (c < 0 && ysize+c > 0)
596 if (y == frame_pointer_rtx || y == hard_frame_pointer_rtx
597 || y == stack_pointer_rtx)
601 y = x; ysize = xsize;
602 x = t; xsize = tsize;
605 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
606 || x == stack_pointer_rtx)
613 if (GET_CODE (y) == PLUS
614 && canon_rtx (XEXP (y, 0)) == x
615 && (y1 = canon_rtx (XEXP (y, 1)))
616 && GET_CODE (y1) == CONST_INT)
619 return (xsize <= 0 || ysize <= 0
620 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
623 if (GET_CODE (y) == PLUS
624 && (y1 = canon_rtx (XEXP (y, 0)))
631 if (GET_CODE (x) == PLUS)
633 /* The fact that X is canonicalized means that this
634 PLUS rtx is canonicalized. */
635 rtx x0 = XEXP (x, 0);
636 rtx x1 = XEXP (x, 1);
638 if (GET_CODE (y) == PLUS)
640 /* The fact that Y is canonicalized means that this
641 PLUS rtx is canonicalized. */
642 rtx y0 = XEXP (y, 0);
643 rtx y1 = XEXP (y, 1);
645 if (rtx_equal_for_memref_p (x1, y1))
646 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
647 if (rtx_equal_for_memref_p (x0, y0))
648 return memrefs_conflict_p (xsize, x1, ysize, y1, c);
649 if (GET_CODE (x1) == CONST_INT)
650 if (GET_CODE (y1) == CONST_INT)
651 return memrefs_conflict_p (xsize, x0, ysize, y0,
652 c - INTVAL (x1) + INTVAL (y1));
654 return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
655 else if (GET_CODE (y1) == CONST_INT)
656 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
658 /* Handle case where we cannot understand iteration operators,
659 but we notice that the base addresses are distinct objects. */
660 /* ??? Is this still necessary? */
661 x = find_symbolic_term (x);
664 y = find_symbolic_term (y);
667 return rtx_equal_for_memref_p (x, y);
669 else if (GET_CODE (x1) == CONST_INT)
670 return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
672 else if (GET_CODE (y) == PLUS)
674 /* The fact that Y is canonicalized means that this
675 PLUS rtx is canonicalized. */
676 rtx y0 = XEXP (y, 0);
677 rtx y1 = XEXP (y, 1);
679 if (GET_CODE (y1) == CONST_INT)
680 return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
685 if (GET_CODE (x) == GET_CODE (y))
686 switch (GET_CODE (x))
690 /* Handle cases where we expect the second operands to be the
691 same, and check only whether the first operand would conflict
694 rtx x1 = canon_rtx (XEXP (x, 1));
695 rtx y1 = canon_rtx (XEXP (y, 1));
696 if (! rtx_equal_for_memref_p (x1, y1))
698 x0 = canon_rtx (XEXP (x, 0));
699 y0 = canon_rtx (XEXP (y, 0));
700 if (rtx_equal_for_memref_p (x0, y0))
701 return (xsize == 0 || ysize == 0
702 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
704 /* Can't properly adjust our sizes. */
705 if (GET_CODE (x1) != CONST_INT)
707 xsize /= INTVAL (x1);
708 ysize /= INTVAL (x1);
710 return memrefs_conflict_p (xsize, x0, ysize, y0, c);
714 /* Treat an access through an AND (e.g. a subword access on an Alpha)
715 as an access with indeterminate size. */
716 if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT)
717 return memrefs_conflict_p (-1, XEXP (x, 0), ysize, y, c);
718 if (GET_CODE (y) == AND && GET_CODE (XEXP (y, 1)) == CONST_INT)
720 /* XXX: If we are indexing far enough into the array/structure, we
721 may yet be able to determine that we can not overlap. But we
722 also need to that we are far enough from the end not to overlap
723 a following reference, so we do nothing for now. */
724 return memrefs_conflict_p (xsize, x, -1, XEXP (y, 0), c);
729 if (GET_CODE (x) == CONST_INT && GET_CODE (y) == CONST_INT)
731 c += (INTVAL (y) - INTVAL (x));
732 return (xsize <= 0 || ysize <= 0
733 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
736 if (GET_CODE (x) == CONST)
738 if (GET_CODE (y) == CONST)
739 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
740 ysize, canon_rtx (XEXP (y, 0)), c);
742 return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
745 if (GET_CODE (y) == CONST)
746 return memrefs_conflict_p (xsize, x, ysize,
747 canon_rtx (XEXP (y, 0)), c);
750 return (xsize < 0 || ysize < 0
751 || (rtx_equal_for_memref_p (x, y)
752 && (xsize == 0 || ysize == 0
753 || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0))));
760 /* Functions to compute memory dependencies.
762 Since we process the insns in execution order, we can build tables
763 to keep track of what registers are fixed (and not aliased), what registers
764 are varying in known ways, and what registers are varying in unknown
767 If both memory references are volatile, then there must always be a
768 dependence between the two references, since their order can not be
769 changed. A volatile and non-volatile reference can be interchanged
772 A MEM_IN_STRUCT reference at a non-QImode non-AND varying address can never
773 conflict with a non-MEM_IN_STRUCT reference at a fixed address. We must
774 allow QImode aliasing because the ANSI C standard allows character
775 pointers to alias anything. We are assuming that characters are
776 always QImode here. We also must allow AND addresses, because they may
777 generate accesses outside the object being referenced. This is used to
778 generate aligned addresses from unaligned addresses, for instance, the
779 alpha storeqi_unaligned pattern. */
781 /* Read dependence: X is read after read in MEM takes place. There can
782 only be a dependence here if both reads are volatile. */
785 read_dependence (mem, x)
789 return MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem);
792 /* True dependence: X is read after store in MEM takes place. */
795 true_dependence (mem, mem_mode, x, varies)
797 enum machine_mode mem_mode;
801 rtx x_addr, mem_addr;
803 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
806 x_addr = XEXP (x, 0);
807 mem_addr = XEXP (mem, 0);
809 if (flag_alias_check && ! base_alias_check (x_addr, mem_addr))
812 /* If X is an unchanging read, then it can't possibly conflict with any
813 non-unchanging store. It may conflict with an unchanging write though,
814 because there may be a single store to this address to initialize it.
815 Just fall through to the code below to resolve the case where we have
816 both an unchanging read and an unchanging write. This won't handle all
817 cases optimally, but the possible performance loss should be
819 if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem))
822 x_addr = canon_rtx (x_addr);
823 mem_addr = canon_rtx (mem_addr);
824 if (mem_mode == VOIDmode)
825 mem_mode = GET_MODE (mem);
827 if (! memrefs_conflict_p (mem_mode, mem_addr, SIZE_FOR_MODE (x), x_addr, 0))
830 /* If both references are struct references, or both are not, nothing
831 is known about aliasing.
833 If either reference is QImode or BLKmode, ANSI C permits aliasing.
835 If both addresses are constant, or both are not, nothing is known
837 if (MEM_IN_STRUCT_P (x) == MEM_IN_STRUCT_P (mem)
838 || mem_mode == QImode || mem_mode == BLKmode
839 || GET_MODE (x) == QImode || GET_MODE (x) == BLKmode
840 || GET_CODE (x_addr) == AND || GET_CODE (mem_addr) == AND
841 || varies (x_addr) == varies (mem_addr))
844 /* One memory reference is to a constant address, one is not.
845 One is to a structure, the other is not.
847 If either memory reference is a variable structure the other is a
848 fixed scalar and there is no aliasing. */
849 if ((MEM_IN_STRUCT_P (mem) && varies (mem_addr))
850 || (MEM_IN_STRUCT_P (x) && varies (x_addr)))
856 /* Anti dependence: X is written after read in MEM takes place. */
859 anti_dependence (mem, x)
863 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
866 if (flag_alias_check && ! base_alias_check (XEXP (x, 0), XEXP (mem, 0)))
869 /* If MEM is an unchanging read, then it can't possibly conflict with
870 the store to X, because there is at most one store to MEM, and it must
871 have occurred somewhere before MEM. */
873 mem = canon_rtx (mem);
874 if (RTX_UNCHANGING_P (mem))
877 return (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
878 SIZE_FOR_MODE (x), XEXP (x, 0), 0)
879 && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
880 && GET_MODE (mem) != QImode
881 && GET_CODE (XEXP (mem, 0)) != AND
882 && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
883 && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
884 && GET_MODE (x) != QImode
885 && GET_CODE (XEXP (x, 0)) != AND
886 && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem)));
889 /* Output dependence: X is written after store in MEM takes place. */
892 output_dependence (mem, x)
896 if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
899 if (flag_alias_check && !base_alias_check (XEXP (x, 0), XEXP (mem, 0)))
903 mem = canon_rtx (mem);
904 return (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
905 SIZE_FOR_MODE (x), XEXP (x, 0), 0)
906 && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
907 && GET_MODE (mem) != QImode
908 && GET_CODE (XEXP (mem, 0)) != AND
909 && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
910 && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
911 && GET_MODE (x) != QImode
912 && GET_CODE (XEXP (x, 0)) != AND
913 && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem)));
917 init_alias_analysis ()
919 int maxreg = max_reg_num ();
926 reg_known_value_size = maxreg;
929 = (rtx *) oballoc ((maxreg - FIRST_PSEUDO_REGISTER) * sizeof (rtx))
930 - FIRST_PSEUDO_REGISTER;
932 oballoc (maxreg - FIRST_PSEUDO_REGISTER) - FIRST_PSEUDO_REGISTER;
933 bzero ((char *) (reg_known_value + FIRST_PSEUDO_REGISTER),
934 (maxreg-FIRST_PSEUDO_REGISTER) * sizeof (rtx));
935 bzero (reg_known_equiv_p + FIRST_PSEUDO_REGISTER,
936 (maxreg - FIRST_PSEUDO_REGISTER) * sizeof (char));
938 if (flag_alias_check)
940 /* Overallocate reg_base_value to allow some growth during loop
941 optimization. Loop unrolling can create a large number of
943 reg_base_value_size = maxreg * 2;
944 reg_base_value = (rtx *)oballoc (reg_base_value_size * sizeof (rtx));
945 reg_seen = (char *)alloca (reg_base_value_size);
946 bzero ((char *) reg_base_value, reg_base_value_size * sizeof (rtx));
947 bzero (reg_seen, reg_base_value_size);
949 /* Mark all hard registers which may contain an address.
950 The stack, frame and argument pointers may contain an address.
951 An argument register which can hold a Pmode value may contain
952 an address even if it is not in BASE_REGS.
954 The address expression is VOIDmode for an argument and
955 Pmode for other registers. */
956 #ifndef OUTGOING_REGNO
957 #define OUTGOING_REGNO(N) N
959 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
960 /* Check whether this register can hold an incoming pointer
961 argument. FUNCTION_ARG_REGNO_P tests outgoing register
962 numbers, so translate if necessary due to register windows. */
963 if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i)) && HARD_REGNO_MODE_OK (i, Pmode))
964 reg_base_value[i] = gen_rtx (ADDRESS, VOIDmode,
965 gen_rtx (REG, Pmode, i));
967 reg_base_value[STACK_POINTER_REGNUM]
968 = gen_rtx (ADDRESS, Pmode, stack_pointer_rtx);
969 reg_base_value[ARG_POINTER_REGNUM]
970 = gen_rtx (ADDRESS, Pmode, arg_pointer_rtx);
971 reg_base_value[FRAME_POINTER_REGNUM]
972 = gen_rtx (ADDRESS, Pmode, frame_pointer_rtx);
973 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
974 reg_base_value[HARD_FRAME_POINTER_REGNUM]
975 = gen_rtx (ADDRESS, Pmode, hard_frame_pointer_rtx);
979 copying_arguments = 1;
980 /* Fill in the entries with known constant values. */
981 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
983 if (flag_alias_check && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
985 /* If this insn has a noalias note, process it, Otherwise,
986 scan for sets. A simple set will have no side effects
987 which could change the base value of any other register. */
989 if (GET_CODE (PATTERN (insn)) == SET
990 && (noalias_note = find_reg_note (insn, REG_NOALIAS, NULL_RTX)))
991 record_set (SET_DEST (PATTERN (insn)), 0);
993 note_stores (PATTERN (insn), record_set);
995 else if (GET_CODE (insn) == NOTE
996 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
997 copying_arguments = 0;
999 if ((set = single_set (insn)) != 0
1000 && GET_CODE (SET_DEST (set)) == REG
1001 && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
1002 && (((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
1003 && REG_N_SETS (REGNO (SET_DEST (set))) == 1)
1004 || (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0)
1005 && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
1007 int regno = REGNO (SET_DEST (set));
1008 reg_known_value[regno] = XEXP (note, 0);
1009 reg_known_equiv_p[regno] = REG_NOTE_KIND (note) == REG_EQUIV;
1013 /* Fill in the remaining entries. */
1014 for (i = FIRST_PSEUDO_REGISTER; i < maxreg; i++)
1015 if (reg_known_value[i] == 0)
1016 reg_known_value[i] = regno_reg_rtx[i];
1018 if (! flag_alias_check)
1021 /* Simplify the reg_base_value array so that no register refers to
1022 another register, except to special registers indirectly through
1023 ADDRESS expressions.
1025 In theory this loop can take as long as O(registers^2), but unless
1026 there are very long dependency chains it will run in close to linear
1031 for (i = 0; i < reg_base_value_size; i++)
1033 rtx base = reg_base_value[i];
1034 if (base && GET_CODE (base) == REG)
1036 int base_regno = REGNO (base);
1037 if (base_regno == i) /* register set from itself */
1038 reg_base_value[i] = 0;
1040 reg_base_value[i] = reg_base_value[base_regno];
1051 end_alias_analysis ()
1053 reg_known_value = 0;
1055 reg_base_value_size = 0;