]>
Commit | Line | Data |
---|---|---|
9ae8ffe7 | 1 | /* Alias analysis for GNU C |
1afdf91c RH |
2 | Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
3 | Free Software Foundation, Inc. | |
9ae8ffe7 JL |
4 | Contributed by John Carr (jfc@mit.edu). |
5 | ||
1322177d | 6 | This file is part of GCC. |
9ae8ffe7 | 7 | |
1322177d LB |
8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 2, or (at your option) any later | |
11 | version. | |
9ae8ffe7 | 12 | |
1322177d LB |
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
9ae8ffe7 JL |
17 | |
18 | You should have received a copy of the GNU General Public License | |
1322177d LB |
19 | along with GCC; see the file COPYING. If not, write to the Free |
20 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
21 | 02111-1307, USA. */ | |
9ae8ffe7 JL |
22 | |
23 | #include "config.h" | |
670ee920 | 24 | #include "system.h" |
4977bab6 ZW |
25 | #include "coretypes.h" |
26 | #include "tm.h" | |
9ae8ffe7 | 27 | #include "rtl.h" |
7790df19 | 28 | #include "tree.h" |
6baf1cc8 | 29 | #include "tm_p.h" |
49ad7cfa | 30 | #include "function.h" |
9ae8ffe7 JL |
31 | #include "expr.h" |
32 | #include "regs.h" | |
33 | #include "hard-reg-set.h" | |
e004f2f7 | 34 | #include "basic-block.h" |
9ae8ffe7 | 35 | #include "flags.h" |
264fac34 | 36 | #include "output.h" |
2e107e9e | 37 | #include "toplev.h" |
eab5c70a | 38 | #include "cselib.h" |
3932261a | 39 | #include "splay-tree.h" |
ac606739 | 40 | #include "ggc.h" |
d23c55c2 | 41 | #include "langhooks.h" |
0d446150 | 42 | #include "timevar.h" |
ab780373 | 43 | #include "target.h" |
b255a036 | 44 | #include "cgraph.h" |
9ddb66ca | 45 | #include "varray.h" |
3932261a MM |
46 | |
47 | /* The alias sets assigned to MEMs assist the back-end in determining | |
48 | which MEMs can alias which other MEMs. In general, two MEMs in | |
ac3d9668 RK |
49 | different alias sets cannot alias each other, with one important |
50 | exception. Consider something like: | |
3932261a | 51 | |
01d28c3f | 52 | struct S { int i; double d; }; |
3932261a MM |
53 | |
54 | a store to an `S' can alias something of either type `int' or type | |
55 | `double'. (However, a store to an `int' cannot alias a `double' | |
56 | and vice versa.) We indicate this via a tree structure that looks | |
57 | like: | |
58 | struct S | |
59 | / \ | |
60 | / \ | |
61 | |/_ _\| | |
62 | int double | |
63 | ||
ac3d9668 RK |
64 | (The arrows are directed and point downwards.) |
65 | In this situation we say the alias set for `struct S' is the | |
66 | `superset' and that those for `int' and `double' are `subsets'. | |
67 | ||
3bdf5ad1 RK |
68 | To see whether two alias sets can point to the same memory, we must |
69 | see if either alias set is a subset of the other. We need not trace | |
95bd1dd7 | 70 | past immediate descendants, however, since we propagate all |
3bdf5ad1 | 71 | grandchildren up one level. |
3932261a MM |
72 | |
73 | Alias set zero is implicitly a superset of all other alias sets. | |
74 | However, this is no actual entry for alias set zero. It is an | |
75 | error to attempt to explicitly construct a subset of zero. */ | |
76 | ||
d4b60170 RK |
77 | typedef struct alias_set_entry |
78 | { | |
3932261a | 79 | /* The alias set number, as stored in MEM_ALIAS_SET. */ |
3bdf5ad1 | 80 | HOST_WIDE_INT alias_set; |
3932261a MM |
81 | |
82 | /* The children of the alias set. These are not just the immediate | |
95bd1dd7 | 83 | children, but, in fact, all descendants. So, if we have: |
3932261a | 84 | |
ca7fd9cd | 85 | struct T { struct S s; float f; } |
3932261a MM |
86 | |
87 | continuing our example above, the children here will be all of | |
88 | `int', `double', `float', and `struct S'. */ | |
89 | splay_tree children; | |
2bf105ab RK |
90 | |
91 | /* Nonzero if would have a child of zero: this effectively makes this | |
92 | alias set the same as alias set zero. */ | |
93 | int has_zero_child; | |
d4b60170 | 94 | } *alias_set_entry; |
9ae8ffe7 | 95 | |
4682ae04 AJ |
96 | static int rtx_equal_for_memref_p (rtx, rtx); |
97 | static rtx find_symbolic_term (rtx); | |
4682ae04 AJ |
98 | static int memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT); |
99 | static void record_set (rtx, rtx, void *); | |
100 | static int base_alias_check (rtx, rtx, enum machine_mode, | |
101 | enum machine_mode); | |
102 | static rtx find_base_value (rtx); | |
103 | static int mems_in_disjoint_alias_sets_p (rtx, rtx); | |
104 | static int insert_subset_children (splay_tree_node, void*); | |
105 | static tree find_base_decl (tree); | |
106 | static alias_set_entry get_alias_set_entry (HOST_WIDE_INT); | |
107 | static rtx fixed_scalar_and_varying_struct_p (rtx, rtx, rtx, rtx, | |
108 | int (*) (rtx, int)); | |
109 | static int aliases_everything_p (rtx); | |
110 | static bool nonoverlapping_component_refs_p (tree, tree); | |
111 | static tree decl_for_component_ref (tree); | |
112 | static rtx adjust_offset_for_component_ref (tree, rtx); | |
113 | static int nonoverlapping_memrefs_p (rtx, rtx); | |
d2399d75 | 114 | static int write_dependence_p (rtx, rtx, int, int); |
4682ae04 AJ |
115 | |
116 | static int nonlocal_mentioned_p_1 (rtx *, void *); | |
117 | static int nonlocal_mentioned_p (rtx); | |
118 | static int nonlocal_referenced_p_1 (rtx *, void *); | |
119 | static int nonlocal_referenced_p (rtx); | |
120 | static int nonlocal_set_p_1 (rtx *, void *); | |
121 | static int nonlocal_set_p (rtx); | |
122 | static void memory_modified_1 (rtx, rtx, void *); | |
9ae8ffe7 JL |
123 | |
124 | /* Set up all info needed to perform alias analysis on memory references. */ | |
125 | ||
d4b60170 | 126 | /* Returns the size in bytes of the mode of X. */ |
9ae8ffe7 JL |
127 | #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X))) |
128 | ||
41472af8 | 129 | /* Returns nonzero if MEM1 and MEM2 do not alias because they are in |
264fac34 MM |
130 | different alias sets. We ignore alias sets in functions making use |
131 | of variable arguments because the va_arg macros on some systems are | |
132 | not legal ANSI C. */ | |
133 | #define DIFFERENT_ALIAS_SETS_P(MEM1, MEM2) \ | |
3932261a | 134 | mems_in_disjoint_alias_sets_p (MEM1, MEM2) |
41472af8 | 135 | |
ea64ef27 | 136 | /* Cap the number of passes we make over the insns propagating alias |
ac3d9668 | 137 | information through set chains. 10 is a completely arbitrary choice. */ |
ea64ef27 | 138 | #define MAX_ALIAS_LOOP_PASSES 10 |
ca7fd9cd | 139 | |
9ae8ffe7 JL |
140 | /* reg_base_value[N] gives an address to which register N is related. |
141 | If all sets after the first add or subtract to the current value | |
142 | or otherwise modify it so it does not point to a different top level | |
143 | object, reg_base_value[N] is equal to the address part of the source | |
2a2c8203 JC |
144 | of the first set. |
145 | ||
146 | A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF. ADDRESS | |
147 | expressions represent certain special values: function arguments and | |
ca7fd9cd | 148 | the stack, frame, and argument pointers. |
b3b5ad95 JL |
149 | |
150 | The contents of an ADDRESS is not normally used, the mode of the | |
151 | ADDRESS determines whether the ADDRESS is a function argument or some | |
152 | other special value. Pointer equality, not rtx_equal_p, determines whether | |
153 | two ADDRESS expressions refer to the same base address. | |
154 | ||
155 | The only use of the contents of an ADDRESS is for determining if the | |
156 | current function performs nonlocal memory memory references for the | |
157 | purposes of marking the function as a constant function. */ | |
2a2c8203 | 158 | |
e2500fed | 159 | static GTY((length ("reg_base_value_size"))) rtx *reg_base_value; |
ac606739 | 160 | static rtx *new_reg_base_value; |
d4b60170 RK |
161 | static unsigned int reg_base_value_size; /* size of reg_base_value array */ |
162 | ||
bf1660a6 JL |
163 | /* Static hunks of RTL used by the aliasing code; these are initialized |
164 | once per function to avoid unnecessary RTL allocations. */ | |
165 | static GTY (()) rtx static_reg_base_value[FIRST_PSEUDO_REGISTER]; | |
166 | ||
9ae8ffe7 | 167 | #define REG_BASE_VALUE(X) \ |
fb6754f0 BS |
168 | (REGNO (X) < reg_base_value_size \ |
169 | ? reg_base_value[REGNO (X)] : 0) | |
9ae8ffe7 | 170 | |
de12be17 JC |
171 | /* Vector of known invariant relationships between registers. Set in |
172 | loop unrolling. Indexed by register number, if nonzero the value | |
173 | is an expression describing this register in terms of another. | |
174 | ||
175 | The length of this array is REG_BASE_VALUE_SIZE. | |
176 | ||
177 | Because this array contains only pseudo registers it has no effect | |
178 | after reload. */ | |
179 | static rtx *alias_invariant; | |
180 | ||
c13e8210 MM |
181 | /* Vector indexed by N giving the initial (unchanging) value known for |
182 | pseudo-register N. This array is initialized in | |
183 | init_alias_analysis, and does not change until end_alias_analysis | |
184 | is called. */ | |
9ae8ffe7 JL |
185 | rtx *reg_known_value; |
186 | ||
187 | /* Indicates number of valid entries in reg_known_value. */ | |
770ae6cc | 188 | static unsigned int reg_known_value_size; |
9ae8ffe7 JL |
189 | |
190 | /* Vector recording for each reg_known_value whether it is due to a | |
191 | REG_EQUIV note. Future passes (viz., reload) may replace the | |
192 | pseudo with the equivalent expression and so we account for the | |
ac3d9668 RK |
193 | dependences that would be introduced if that happens. |
194 | ||
195 | The REG_EQUIV notes created in assign_parms may mention the arg | |
196 | pointer, and there are explicit insns in the RTL that modify the | |
197 | arg pointer. Thus we must ensure that such insns don't get | |
198 | scheduled across each other because that would invalidate the | |
199 | REG_EQUIV notes. One could argue that the REG_EQUIV notes are | |
200 | wrong, but solving the problem in the scheduler will likely give | |
201 | better code, so we do it here. */ | |
9ae8ffe7 JL |
202 | char *reg_known_equiv_p; |
203 | ||
2a2c8203 JC |
204 | /* True when scanning insns from the start of the rtl to the |
205 | NOTE_INSN_FUNCTION_BEG note. */ | |
83bbd9b6 | 206 | static bool copying_arguments; |
9ae8ffe7 | 207 | |
3932261a | 208 | /* The splay-tree used to store the various alias set entries. */ |
9ddb66ca | 209 | varray_type alias_sets; |
ac3d9668 | 210 | \f |
3932261a MM |
211 | /* Returns a pointer to the alias set entry for ALIAS_SET, if there is |
212 | such an entry, or NULL otherwise. */ | |
213 | ||
9ddb66ca | 214 | static inline alias_set_entry |
4682ae04 | 215 | get_alias_set_entry (HOST_WIDE_INT alias_set) |
3932261a | 216 | { |
9ddb66ca | 217 | return (alias_set_entry)VARRAY_GENERIC_PTR (alias_sets, alias_set); |
3932261a MM |
218 | } |
219 | ||
ac3d9668 RK |
220 | /* Returns nonzero if the alias sets for MEM1 and MEM2 are such that |
221 | the two MEMs cannot alias each other. */ | |
3932261a | 222 | |
9ddb66ca | 223 | static inline int |
4682ae04 | 224 | mems_in_disjoint_alias_sets_p (rtx mem1, rtx mem2) |
3932261a | 225 | { |
ca7fd9cd | 226 | #ifdef ENABLE_CHECKING |
3932261a MM |
227 | /* Perform a basic sanity check. Namely, that there are no alias sets |
228 | if we're not using strict aliasing. This helps to catch bugs | |
229 | whereby someone uses PUT_CODE, but doesn't clear MEM_ALIAS_SET, or | |
230 | where a MEM is allocated in some way other than by the use of | |
231 | gen_rtx_MEM, and the MEM_ALIAS_SET is not cleared. If we begin to | |
232 | use alias sets to indicate that spilled registers cannot alias each | |
233 | other, we might need to remove this check. */ | |
d4b60170 RK |
234 | if (! flag_strict_aliasing |
235 | && (MEM_ALIAS_SET (mem1) != 0 || MEM_ALIAS_SET (mem2) != 0)) | |
3932261a MM |
236 | abort (); |
237 | #endif | |
238 | ||
1da68f56 RK |
239 | return ! alias_sets_conflict_p (MEM_ALIAS_SET (mem1), MEM_ALIAS_SET (mem2)); |
240 | } | |
3932261a | 241 | |
1da68f56 RK |
242 | /* Insert the NODE into the splay tree given by DATA. Used by |
243 | record_alias_subset via splay_tree_foreach. */ | |
244 | ||
245 | static int | |
4682ae04 | 246 | insert_subset_children (splay_tree_node node, void *data) |
1da68f56 RK |
247 | { |
248 | splay_tree_insert ((splay_tree) data, node->key, node->value); | |
249 | ||
250 | return 0; | |
251 | } | |
252 | ||
253 | /* Return 1 if the two specified alias sets may conflict. */ | |
254 | ||
255 | int | |
4682ae04 | 256 | alias_sets_conflict_p (HOST_WIDE_INT set1, HOST_WIDE_INT set2) |
1da68f56 RK |
257 | { |
258 | alias_set_entry ase; | |
259 | ||
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; | |
3932261a | 266 | |
3bdf5ad1 | 267 | /* See if the first alias set is a subset of the second. */ |
1da68f56 | 268 | ase = get_alias_set_entry (set1); |
2bf105ab RK |
269 | if (ase != 0 |
270 | && (ase->has_zero_child | |
271 | || splay_tree_lookup (ase->children, | |
1da68f56 RK |
272 | (splay_tree_key) set2))) |
273 | return 1; | |
3932261a MM |
274 | |
275 | /* Now do the same, but with the alias sets reversed. */ | |
1da68f56 | 276 | ase = get_alias_set_entry (set2); |
2bf105ab RK |
277 | if (ase != 0 |
278 | && (ase->has_zero_child | |
279 | || splay_tree_lookup (ase->children, | |
1da68f56 RK |
280 | (splay_tree_key) set1))) |
281 | return 1; | |
3932261a | 282 | |
1da68f56 | 283 | /* The two alias sets are distinct and neither one is the |
3932261a | 284 | child of the other. Therefore, they cannot alias. */ |
1da68f56 | 285 | return 0; |
3932261a | 286 | } |
1da68f56 RK |
287 | \f |
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. */ | |
3932261a | 291 | |
1da68f56 | 292 | int |
4682ae04 | 293 | readonly_fields_p (tree type) |
3932261a | 294 | { |
1da68f56 RK |
295 | tree field; |
296 | ||
297 | if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE | |
298 | && TREE_CODE (type) != QUAL_UNION_TYPE) | |
299 | return 0; | |
300 | ||
301 | for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field)) | |
302 | if (TREE_CODE (field) == FIELD_DECL | |
303 | && (TREE_READONLY (field) | |
304 | || readonly_fields_p (TREE_TYPE (field)))) | |
305 | return 1; | |
3932261a MM |
306 | |
307 | return 0; | |
308 | } | |
3bdf5ad1 | 309 | \f |
1da68f56 RK |
310 | /* Return 1 if any MEM object of type T1 will always conflict (using the |
311 | dependency routines in this file) with any MEM object of type T2. | |
312 | This is used when allocating temporary storage. If T1 and/or T2 are | |
313 | NULL_TREE, it means we know nothing about the storage. */ | |
314 | ||
315 | int | |
4682ae04 | 316 | objects_must_conflict_p (tree t1, tree t2) |
1da68f56 | 317 | { |
82d610ec RK |
318 | HOST_WIDE_INT set1, set2; |
319 | ||
e8ea2809 RK |
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. */ | |
981a4c34 | 323 | if (t1 == 0 && t2 == 0) |
e8ea2809 RK |
324 | return 0; |
325 | ||
66cce54d RH |
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)) | |
a3b88570 MM |
330 | || (t1 != 0 && lang_hooks.honor_readonly && TYPE_READONLY (t1)) |
331 | || (t2 != 0 && lang_hooks.honor_readonly && TYPE_READONLY (t2))) | |
66cce54d RH |
332 | return 0; |
333 | ||
1da68f56 RK |
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; | |
339 | ||
82d610ec RK |
340 | set1 = t1 ? get_alias_set (t1) : 0; |
341 | set2 = t2 ? get_alias_set (t2) : 0; | |
1da68f56 | 342 | |
82d610ec RK |
343 | /* Otherwise they conflict if they have no alias set or the same. We |
344 | can't simply use alias_sets_conflict_p here, because we must make | |
345 | sure that every subtype of t1 will conflict with every subtype of | |
346 | t2 for which a pair of subobjects of these respective subtypes | |
347 | overlaps on the stack. */ | |
348 | return set1 == 0 || set2 == 0 || set1 == set2; | |
1da68f56 RK |
349 | } |
350 | \f | |
3bdf5ad1 RK |
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, | |
f5143c46 | 354 | NULL_TREE is returned. */ |
3bdf5ad1 RK |
355 | |
356 | static tree | |
4682ae04 | 357 | find_base_decl (tree t) |
3bdf5ad1 RK |
358 | { |
359 | tree d0, d1, d2; | |
360 | ||
361 | if (t == 0 || t == error_mark_node || ! POINTER_TYPE_P (TREE_TYPE (t))) | |
362 | return 0; | |
363 | ||
364 | /* If this is a declaration, return it. */ | |
365 | if (TREE_CODE_CLASS (TREE_CODE (t)) == 'd') | |
366 | return t; | |
367 | ||
368 | /* Handle general expressions. It would be nice to deal with | |
369 | COMPONENT_REFs here. If we could tell that `a' and `b' were the | |
370 | same, then `a->f' and `b->f' are also the same. */ | |
371 | switch (TREE_CODE_CLASS (TREE_CODE (t))) | |
372 | { | |
373 | case '1': | |
374 | return find_base_decl (TREE_OPERAND (t, 0)); | |
375 | ||
376 | case '2': | |
377 | /* Return 0 if found in neither or both are the same. */ | |
378 | d0 = find_base_decl (TREE_OPERAND (t, 0)); | |
379 | d1 = find_base_decl (TREE_OPERAND (t, 1)); | |
380 | if (d0 == d1) | |
381 | return d0; | |
382 | else if (d0 == 0) | |
383 | return d1; | |
384 | else if (d1 == 0) | |
385 | return d0; | |
386 | else | |
387 | return 0; | |
388 | ||
389 | case '3': | |
390 | d0 = find_base_decl (TREE_OPERAND (t, 0)); | |
391 | d1 = find_base_decl (TREE_OPERAND (t, 1)); | |
3bdf5ad1 RK |
392 | d2 = find_base_decl (TREE_OPERAND (t, 2)); |
393 | ||
394 | /* Set any nonzero values from the last, then from the first. */ | |
395 | if (d1 == 0) d1 = d2; | |
396 | if (d0 == 0) d0 = d1; | |
397 | if (d1 == 0) d1 = d0; | |
398 | if (d2 == 0) d2 = d1; | |
399 | ||
400 | /* At this point all are nonzero or all are zero. If all three are the | |
401 | same, return it. Otherwise, return zero. */ | |
402 | return (d0 == d1 && d1 == d2) ? d0 : 0; | |
403 | ||
404 | default: | |
405 | return 0; | |
406 | } | |
407 | } | |
408 | ||
6e24b709 RK |
409 | /* Return 1 if all the nested component references handled by |
410 | get_inner_reference in T are such that we can address the object in T. */ | |
411 | ||
10b76d73 | 412 | int |
4682ae04 | 413 | can_address_p (tree t) |
6e24b709 RK |
414 | { |
415 | /* If we're at the end, it is vacuously addressable. */ | |
416 | if (! handled_component_p (t)) | |
417 | return 1; | |
418 | ||
419 | /* Bitfields are never addressable. */ | |
420 | else if (TREE_CODE (t) == BIT_FIELD_REF) | |
421 | return 0; | |
422 | ||
8ac61af7 RK |
423 | /* Fields are addressable unless they are marked as nonaddressable or |
424 | the containing type has alias set 0. */ | |
6e24b709 RK |
425 | else if (TREE_CODE (t) == COMPONENT_REF |
426 | && ! DECL_NONADDRESSABLE_P (TREE_OPERAND (t, 1)) | |
8ac61af7 | 427 | && get_alias_set (TREE_TYPE (TREE_OPERAND (t, 0))) != 0 |
6e24b709 RK |
428 | && can_address_p (TREE_OPERAND (t, 0))) |
429 | return 1; | |
430 | ||
8ac61af7 | 431 | /* Likewise for arrays. */ |
b4e3fabb | 432 | else if ((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) |
6e24b709 | 433 | && ! TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t, 0))) |
8ac61af7 | 434 | && get_alias_set (TREE_TYPE (TREE_OPERAND (t, 0))) != 0 |
6e24b709 RK |
435 | && can_address_p (TREE_OPERAND (t, 0))) |
436 | return 1; | |
437 | ||
438 | return 0; | |
439 | } | |
440 | ||
3bdf5ad1 RK |
441 | /* Return the alias set for T, which may be either a type or an |
442 | expression. Call language-specific routine for help, if needed. */ | |
443 | ||
444 | HOST_WIDE_INT | |
4682ae04 | 445 | get_alias_set (tree t) |
3bdf5ad1 RK |
446 | { |
447 | HOST_WIDE_INT set; | |
3bdf5ad1 RK |
448 | |
449 | /* If we're not doing any alias analysis, just assume everything | |
450 | aliases everything else. Also return 0 if this or its type is | |
451 | an error. */ | |
452 | if (! flag_strict_aliasing || t == error_mark_node | |
453 | || (! TYPE_P (t) | |
454 | && (TREE_TYPE (t) == 0 || TREE_TYPE (t) == error_mark_node))) | |
455 | return 0; | |
456 | ||
457 | /* We can be passed either an expression or a type. This and the | |
f47e9b4e RK |
458 | language-specific routine may make mutually-recursive calls to each other |
459 | to figure out what to do. At each juncture, we see if this is a tree | |
460 | that the language may need to handle specially. First handle things that | |
738cc472 | 461 | aren't types. */ |
f824e5c3 | 462 | if (! TYPE_P (t)) |
3bdf5ad1 | 463 | { |
738cc472 RK |
464 | tree inner = t; |
465 | tree placeholder_ptr = 0; | |
466 | ||
8ac61af7 RK |
467 | /* Remove any nops, then give the language a chance to do |
468 | something with this tree before we look at it. */ | |
469 | STRIP_NOPS (t); | |
470 | set = (*lang_hooks.get_alias_set) (t); | |
471 | if (set != -1) | |
472 | return set; | |
473 | ||
738cc472 | 474 | /* First see if the actual object referenced is an INDIRECT_REF from a |
8ac61af7 | 475 | restrict-qualified pointer or a "void *". Replace |
738cc472 | 476 | PLACEHOLDER_EXPRs. */ |
8ac61af7 | 477 | while (TREE_CODE (inner) == PLACEHOLDER_EXPR |
738cc472 RK |
478 | || handled_component_p (inner)) |
479 | { | |
480 | if (TREE_CODE (inner) == PLACEHOLDER_EXPR) | |
481 | inner = find_placeholder (inner, &placeholder_ptr); | |
482 | else | |
483 | inner = TREE_OPERAND (inner, 0); | |
8ac61af7 RK |
484 | |
485 | STRIP_NOPS (inner); | |
738cc472 RK |
486 | } |
487 | ||
488 | /* Check for accesses through restrict-qualified pointers. */ | |
489 | if (TREE_CODE (inner) == INDIRECT_REF) | |
490 | { | |
491 | tree decl = find_base_decl (TREE_OPERAND (inner, 0)); | |
492 | ||
493 | if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl)) | |
494 | { | |
e5837c07 | 495 | /* If we haven't computed the actual alias set, do it now. */ |
738cc472 RK |
496 | if (DECL_POINTER_ALIAS_SET (decl) == -2) |
497 | { | |
498 | /* No two restricted pointers can point at the same thing. | |
499 | However, a restricted pointer can point at the same thing | |
500 | as an unrestricted pointer, if that unrestricted pointer | |
501 | is based on the restricted pointer. So, we make the | |
502 | alias set for the restricted pointer a subset of the | |
503 | alias set for the type pointed to by the type of the | |
504 | decl. */ | |
505 | HOST_WIDE_INT pointed_to_alias_set | |
506 | = get_alias_set (TREE_TYPE (TREE_TYPE (decl))); | |
507 | ||
508 | if (pointed_to_alias_set == 0) | |
509 | /* It's not legal to make a subset of alias set zero. */ | |
e7844ffb | 510 | DECL_POINTER_ALIAS_SET (decl) = 0; |
738cc472 RK |
511 | else |
512 | { | |
513 | DECL_POINTER_ALIAS_SET (decl) = new_alias_set (); | |
ca7fd9cd KH |
514 | record_alias_subset (pointed_to_alias_set, |
515 | DECL_POINTER_ALIAS_SET (decl)); | |
738cc472 RK |
516 | } |
517 | } | |
518 | ||
519 | /* We use the alias set indicated in the declaration. */ | |
520 | return DECL_POINTER_ALIAS_SET (decl); | |
521 | } | |
522 | ||
523 | /* If we have an INDIRECT_REF via a void pointer, we don't | |
524 | know anything about what that might alias. */ | |
525 | else if (TREE_CODE (TREE_TYPE (inner)) == VOID_TYPE) | |
526 | return 0; | |
527 | } | |
528 | ||
529 | /* Otherwise, pick up the outermost object that we could have a pointer | |
530 | to, processing conversion and PLACEHOLDER_EXPR as above. */ | |
531 | placeholder_ptr = 0; | |
8ac61af7 | 532 | while (TREE_CODE (t) == PLACEHOLDER_EXPR |
f47e9b4e RK |
533 | || (handled_component_p (t) && ! can_address_p (t))) |
534 | { | |
f47e9b4e | 535 | if (TREE_CODE (t) == PLACEHOLDER_EXPR) |
738cc472 | 536 | t = find_placeholder (t, &placeholder_ptr); |
f47e9b4e RK |
537 | else |
538 | t = TREE_OPERAND (t, 0); | |
f824e5c3 | 539 | |
8ac61af7 RK |
540 | STRIP_NOPS (t); |
541 | } | |
f824e5c3 | 542 | |
738cc472 RK |
543 | /* If we've already determined the alias set for a decl, just return |
544 | it. This is necessary for C++ anonymous unions, whose component | |
545 | variables don't look like union members (boo!). */ | |
5755cd38 JM |
546 | if (TREE_CODE (t) == VAR_DECL |
547 | && DECL_RTL_SET_P (t) && GET_CODE (DECL_RTL (t)) == MEM) | |
548 | return MEM_ALIAS_SET (DECL_RTL (t)); | |
549 | ||
f824e5c3 RK |
550 | /* Now all we care about is the type. */ |
551 | t = TREE_TYPE (t); | |
3bdf5ad1 RK |
552 | } |
553 | ||
3bdf5ad1 RK |
554 | /* Variant qualifiers don't affect the alias set, so get the main |
555 | variant. If this is a type with a known alias set, return it. */ | |
556 | t = TYPE_MAIN_VARIANT (t); | |
738cc472 | 557 | if (TYPE_ALIAS_SET_KNOWN_P (t)) |
3bdf5ad1 RK |
558 | return TYPE_ALIAS_SET (t); |
559 | ||
560 | /* See if the language has special handling for this type. */ | |
8ac61af7 RK |
561 | set = (*lang_hooks.get_alias_set) (t); |
562 | if (set != -1) | |
738cc472 | 563 | return set; |
2bf105ab | 564 | |
3bdf5ad1 RK |
565 | /* There are no objects of FUNCTION_TYPE, so there's no point in |
566 | using up an alias set for them. (There are, of course, pointers | |
567 | and references to functions, but that's different.) */ | |
568 | else if (TREE_CODE (t) == FUNCTION_TYPE) | |
569 | set = 0; | |
74d86f4f RH |
570 | |
571 | /* Unless the language specifies otherwise, let vector types alias | |
572 | their components. This avoids some nasty type punning issues in | |
573 | normal usage. And indeed lets vectors be treated more like an | |
574 | array slice. */ | |
575 | else if (TREE_CODE (t) == VECTOR_TYPE) | |
576 | set = get_alias_set (TREE_TYPE (t)); | |
577 | ||
3bdf5ad1 RK |
578 | else |
579 | /* Otherwise make a new alias set for this type. */ | |
580 | set = new_alias_set (); | |
581 | ||
582 | TYPE_ALIAS_SET (t) = set; | |
2bf105ab RK |
583 | |
584 | /* If this is an aggregate type, we must record any component aliasing | |
585 | information. */ | |
1d79fd2c | 586 | if (AGGREGATE_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE) |
2bf105ab RK |
587 | record_component_aliases (t); |
588 | ||
3bdf5ad1 RK |
589 | return set; |
590 | } | |
591 | ||
592 | /* Return a brand-new alias set. */ | |
593 | ||
594 | HOST_WIDE_INT | |
4682ae04 | 595 | new_alias_set (void) |
3bdf5ad1 RK |
596 | { |
597 | static HOST_WIDE_INT last_alias_set; | |
598 | ||
599 | if (flag_strict_aliasing) | |
9ddb66ca | 600 | { |
3416f5c2 JH |
601 | if (!alias_sets) |
602 | VARRAY_GENERIC_PTR_INIT (alias_sets, 10, "alias sets"); | |
603 | else | |
604 | VARRAY_GROW (alias_sets, last_alias_set + 2); | |
9ddb66ca JH |
605 | return ++last_alias_set; |
606 | } | |
3bdf5ad1 RK |
607 | else |
608 | return 0; | |
609 | } | |
3932261a | 610 | |
01d28c3f JM |
611 | /* Indicate that things in SUBSET can alias things in SUPERSET, but that |
612 | not everything that aliases SUPERSET also aliases SUBSET. For example, | |
613 | in C, a store to an `int' can alias a load of a structure containing an | |
614 | `int', and vice versa. But it can't alias a load of a 'double' member | |
615 | of the same structure. Here, the structure would be the SUPERSET and | |
616 | `int' the SUBSET. This relationship is also described in the comment at | |
617 | the beginning of this file. | |
618 | ||
619 | This function should be called only once per SUPERSET/SUBSET pair. | |
3932261a MM |
620 | |
621 | It is illegal for SUPERSET to be zero; everything is implicitly a | |
622 | subset of alias set zero. */ | |
623 | ||
624 | void | |
4682ae04 | 625 | record_alias_subset (HOST_WIDE_INT superset, HOST_WIDE_INT subset) |
3932261a MM |
626 | { |
627 | alias_set_entry superset_entry; | |
628 | alias_set_entry subset_entry; | |
629 | ||
f47e9b4e RK |
630 | /* It is possible in complex type situations for both sets to be the same, |
631 | in which case we can ignore this operation. */ | |
632 | if (superset == subset) | |
633 | return; | |
634 | ||
3932261a MM |
635 | if (superset == 0) |
636 | abort (); | |
637 | ||
638 | superset_entry = get_alias_set_entry (superset); | |
ca7fd9cd | 639 | if (superset_entry == 0) |
3932261a MM |
640 | { |
641 | /* Create an entry for the SUPERSET, so that we have a place to | |
642 | attach the SUBSET. */ | |
703ad42b | 643 | superset_entry = xmalloc (sizeof (struct alias_set_entry)); |
3932261a | 644 | superset_entry->alias_set = superset; |
ca7fd9cd | 645 | superset_entry->children |
30f72379 | 646 | = splay_tree_new (splay_tree_compare_ints, 0, 0); |
570eb5c8 | 647 | superset_entry->has_zero_child = 0; |
9ddb66ca | 648 | VARRAY_GENERIC_PTR (alias_sets, superset) = superset_entry; |
3932261a MM |
649 | } |
650 | ||
2bf105ab RK |
651 | if (subset == 0) |
652 | superset_entry->has_zero_child = 1; | |
653 | else | |
654 | { | |
655 | subset_entry = get_alias_set_entry (subset); | |
656 | /* If there is an entry for the subset, enter all of its children | |
657 | (if they are not already present) as children of the SUPERSET. */ | |
ca7fd9cd | 658 | if (subset_entry) |
2bf105ab RK |
659 | { |
660 | if (subset_entry->has_zero_child) | |
661 | superset_entry->has_zero_child = 1; | |
d4b60170 | 662 | |
2bf105ab RK |
663 | splay_tree_foreach (subset_entry->children, insert_subset_children, |
664 | superset_entry->children); | |
665 | } | |
3932261a | 666 | |
2bf105ab | 667 | /* Enter the SUBSET itself as a child of the SUPERSET. */ |
ca7fd9cd | 668 | splay_tree_insert (superset_entry->children, |
2bf105ab RK |
669 | (splay_tree_key) subset, 0); |
670 | } | |
3932261a MM |
671 | } |
672 | ||
a0c33338 RK |
673 | /* Record that component types of TYPE, if any, are part of that type for |
674 | aliasing purposes. For record types, we only record component types | |
675 | for fields that are marked addressable. For array types, we always | |
676 | record the component types, so the front end should not call this | |
677 | function if the individual component aren't addressable. */ | |
678 | ||
679 | void | |
4682ae04 | 680 | record_component_aliases (tree type) |
a0c33338 | 681 | { |
3bdf5ad1 | 682 | HOST_WIDE_INT superset = get_alias_set (type); |
a0c33338 RK |
683 | tree field; |
684 | ||
685 | if (superset == 0) | |
686 | return; | |
687 | ||
688 | switch (TREE_CODE (type)) | |
689 | { | |
690 | case ARRAY_TYPE: | |
2bf105ab RK |
691 | if (! TYPE_NONALIASED_COMPONENT (type)) |
692 | record_alias_subset (superset, get_alias_set (TREE_TYPE (type))); | |
a0c33338 RK |
693 | break; |
694 | ||
695 | case RECORD_TYPE: | |
696 | case UNION_TYPE: | |
697 | case QUAL_UNION_TYPE: | |
6614fd40 | 698 | /* Recursively record aliases for the base classes, if there are any. */ |
61eece67 | 699 | if (TYPE_BINFO (type) != NULL && TYPE_BINFO_BASETYPES (type) != NULL) |
ca7fd9cd KH |
700 | { |
701 | int i; | |
702 | for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); i++) | |
703 | { | |
704 | tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type), i); | |
705 | record_alias_subset (superset, | |
61eece67 | 706 | get_alias_set (BINFO_TYPE (binfo))); |
ca7fd9cd KH |
707 | } |
708 | } | |
a0c33338 | 709 | for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field)) |
b16a49a1 | 710 | if (TREE_CODE (field) == FIELD_DECL && ! DECL_NONADDRESSABLE_P (field)) |
2bf105ab | 711 | record_alias_subset (superset, get_alias_set (TREE_TYPE (field))); |
a0c33338 RK |
712 | break; |
713 | ||
1d79fd2c JW |
714 | case COMPLEX_TYPE: |
715 | record_alias_subset (superset, get_alias_set (TREE_TYPE (type))); | |
716 | break; | |
717 | ||
a0c33338 RK |
718 | default: |
719 | break; | |
720 | } | |
721 | } | |
722 | ||
3bdf5ad1 RK |
723 | /* Allocate an alias set for use in storing and reading from the varargs |
724 | spill area. */ | |
725 | ||
726 | HOST_WIDE_INT | |
4682ae04 | 727 | get_varargs_alias_set (void) |
3bdf5ad1 RK |
728 | { |
729 | static HOST_WIDE_INT set = -1; | |
730 | ||
731 | if (set == -1) | |
732 | set = new_alias_set (); | |
733 | ||
734 | return set; | |
735 | } | |
736 | ||
737 | /* Likewise, but used for the fixed portions of the frame, e.g., register | |
738 | save areas. */ | |
739 | ||
740 | HOST_WIDE_INT | |
4682ae04 | 741 | get_frame_alias_set (void) |
3bdf5ad1 RK |
742 | { |
743 | static HOST_WIDE_INT set = -1; | |
744 | ||
745 | if (set == -1) | |
746 | set = new_alias_set (); | |
747 | ||
748 | return set; | |
749 | } | |
750 | ||
2a2c8203 JC |
751 | /* Inside SRC, the source of a SET, find a base address. */ |
752 | ||
9ae8ffe7 | 753 | static rtx |
4682ae04 | 754 | find_base_value (rtx src) |
9ae8ffe7 | 755 | { |
713f41f9 | 756 | unsigned int regno; |
0aacc8ed | 757 | |
9ae8ffe7 JL |
758 | switch (GET_CODE (src)) |
759 | { | |
760 | case SYMBOL_REF: | |
761 | case LABEL_REF: | |
762 | return src; | |
763 | ||
764 | case REG: | |
fb6754f0 | 765 | regno = REGNO (src); |
d4b60170 | 766 | /* At the start of a function, argument registers have known base |
2a2c8203 JC |
767 | values which may be lost later. Returning an ADDRESS |
768 | expression here allows optimization based on argument values | |
769 | even when the argument registers are used for other purposes. */ | |
713f41f9 BS |
770 | if (regno < FIRST_PSEUDO_REGISTER && copying_arguments) |
771 | return new_reg_base_value[regno]; | |
73774bc7 | 772 | |
eaf407a5 | 773 | /* If a pseudo has a known base value, return it. Do not do this |
9b462c42 RH |
774 | for non-fixed hard regs since it can result in a circular |
775 | dependency chain for registers which have values at function entry. | |
eaf407a5 JL |
776 | |
777 | The test above is not sufficient because the scheduler may move | |
778 | a copy out of an arg reg past the NOTE_INSN_FUNCTION_BEGIN. */ | |
9b462c42 | 779 | if ((regno >= FIRST_PSEUDO_REGISTER || fixed_regs[regno]) |
83bbd9b6 RH |
780 | && regno < reg_base_value_size) |
781 | { | |
782 | /* If we're inside init_alias_analysis, use new_reg_base_value | |
783 | to reduce the number of relaxation iterations. */ | |
1afdf91c RH |
784 | if (new_reg_base_value && new_reg_base_value[regno] |
785 | && REG_N_SETS (regno) == 1) | |
83bbd9b6 RH |
786 | return new_reg_base_value[regno]; |
787 | ||
788 | if (reg_base_value[regno]) | |
789 | return reg_base_value[regno]; | |
790 | } | |
73774bc7 | 791 | |
e3f049a8 | 792 | return 0; |
9ae8ffe7 JL |
793 | |
794 | case MEM: | |
795 | /* Check for an argument passed in memory. Only record in the | |
796 | copying-arguments block; it is too hard to track changes | |
797 | otherwise. */ | |
798 | if (copying_arguments | |
799 | && (XEXP (src, 0) == arg_pointer_rtx | |
800 | || (GET_CODE (XEXP (src, 0)) == PLUS | |
801 | && XEXP (XEXP (src, 0), 0) == arg_pointer_rtx))) | |
38a448ca | 802 | return gen_rtx_ADDRESS (VOIDmode, src); |
9ae8ffe7 JL |
803 | return 0; |
804 | ||
805 | case CONST: | |
806 | src = XEXP (src, 0); | |
807 | if (GET_CODE (src) != PLUS && GET_CODE (src) != MINUS) | |
808 | break; | |
d4b60170 | 809 | |
ec5c56db | 810 | /* ... fall through ... */ |
2a2c8203 | 811 | |
9ae8ffe7 JL |
812 | case PLUS: |
813 | case MINUS: | |
2a2c8203 | 814 | { |
ec907dd8 JL |
815 | rtx temp, src_0 = XEXP (src, 0), src_1 = XEXP (src, 1); |
816 | ||
0134bf2d DE |
817 | /* If either operand is a REG that is a known pointer, then it |
818 | is the base. */ | |
819 | if (REG_P (src_0) && REG_POINTER (src_0)) | |
820 | return find_base_value (src_0); | |
821 | if (REG_P (src_1) && REG_POINTER (src_1)) | |
822 | return find_base_value (src_1); | |
823 | ||
ec907dd8 JL |
824 | /* If either operand is a REG, then see if we already have |
825 | a known value for it. */ | |
0134bf2d | 826 | if (REG_P (src_0)) |
ec907dd8 JL |
827 | { |
828 | temp = find_base_value (src_0); | |
d4b60170 | 829 | if (temp != 0) |
ec907dd8 JL |
830 | src_0 = temp; |
831 | } | |
832 | ||
0134bf2d | 833 | if (REG_P (src_1)) |
ec907dd8 JL |
834 | { |
835 | temp = find_base_value (src_1); | |
d4b60170 | 836 | if (temp!= 0) |
ec907dd8 JL |
837 | src_1 = temp; |
838 | } | |
2a2c8203 | 839 | |
0134bf2d DE |
840 | /* If either base is named object or a special address |
841 | (like an argument or stack reference), then use it for the | |
842 | base term. */ | |
843 | if (src_0 != 0 | |
844 | && (GET_CODE (src_0) == SYMBOL_REF | |
845 | || GET_CODE (src_0) == LABEL_REF | |
846 | || (GET_CODE (src_0) == ADDRESS | |
847 | && GET_MODE (src_0) != VOIDmode))) | |
848 | return src_0; | |
849 | ||
850 | if (src_1 != 0 | |
851 | && (GET_CODE (src_1) == SYMBOL_REF | |
852 | || GET_CODE (src_1) == LABEL_REF | |
853 | || (GET_CODE (src_1) == ADDRESS | |
854 | && GET_MODE (src_1) != VOIDmode))) | |
855 | return src_1; | |
856 | ||
d4b60170 | 857 | /* Guess which operand is the base address: |
ec907dd8 JL |
858 | If either operand is a symbol, then it is the base. If |
859 | either operand is a CONST_INT, then the other is the base. */ | |
d4b60170 | 860 | if (GET_CODE (src_1) == CONST_INT || CONSTANT_P (src_0)) |
2a2c8203 | 861 | return find_base_value (src_0); |
d4b60170 | 862 | else if (GET_CODE (src_0) == CONST_INT || CONSTANT_P (src_1)) |
ec907dd8 JL |
863 | return find_base_value (src_1); |
864 | ||
9ae8ffe7 | 865 | return 0; |
2a2c8203 JC |
866 | } |
867 | ||
868 | case LO_SUM: | |
869 | /* The standard form is (lo_sum reg sym) so look only at the | |
870 | second operand. */ | |
871 | return find_base_value (XEXP (src, 1)); | |
9ae8ffe7 JL |
872 | |
873 | case AND: | |
874 | /* If the second operand is constant set the base | |
ec5c56db | 875 | address to the first operand. */ |
2a2c8203 JC |
876 | if (GET_CODE (XEXP (src, 1)) == CONST_INT && INTVAL (XEXP (src, 1)) != 0) |
877 | return find_base_value (XEXP (src, 0)); | |
9ae8ffe7 JL |
878 | return 0; |
879 | ||
61f0131c R |
880 | case TRUNCATE: |
881 | if (GET_MODE_SIZE (GET_MODE (src)) < GET_MODE_SIZE (Pmode)) | |
882 | break; | |
883 | /* Fall through. */ | |
9ae8ffe7 | 884 | case HIGH: |
d288e53d DE |
885 | case PRE_INC: |
886 | case PRE_DEC: | |
887 | case POST_INC: | |
888 | case POST_DEC: | |
889 | case PRE_MODIFY: | |
890 | case POST_MODIFY: | |
2a2c8203 | 891 | return find_base_value (XEXP (src, 0)); |
1d300e19 | 892 | |
0aacc8ed RK |
893 | case ZERO_EXTEND: |
894 | case SIGN_EXTEND: /* used for NT/Alpha pointers */ | |
895 | { | |
896 | rtx temp = find_base_value (XEXP (src, 0)); | |
897 | ||
5ae6cd0d | 898 | if (temp != 0 && CONSTANT_P (temp)) |
0aacc8ed | 899 | temp = convert_memory_address (Pmode, temp); |
0aacc8ed RK |
900 | |
901 | return temp; | |
902 | } | |
903 | ||
1d300e19 KG |
904 | default: |
905 | break; | |
9ae8ffe7 JL |
906 | } |
907 | ||
908 | return 0; | |
909 | } | |
910 | ||
911 | /* Called from init_alias_analysis indirectly through note_stores. */ | |
912 | ||
d4b60170 | 913 | /* While scanning insns to find base values, reg_seen[N] is nonzero if |
9ae8ffe7 JL |
914 | register N has been set in this function. */ |
915 | static char *reg_seen; | |
916 | ||
13309a5f JC |
917 | /* Addresses which are known not to alias anything else are identified |
918 | by a unique integer. */ | |
ec907dd8 JL |
919 | static int unique_id; |
920 | ||
2a2c8203 | 921 | static void |
4682ae04 | 922 | record_set (rtx dest, rtx set, void *data ATTRIBUTE_UNUSED) |
9ae8ffe7 | 923 | { |
b3694847 | 924 | unsigned regno; |
9ae8ffe7 | 925 | rtx src; |
c28b4e40 | 926 | int n; |
9ae8ffe7 JL |
927 | |
928 | if (GET_CODE (dest) != REG) | |
929 | return; | |
930 | ||
fb6754f0 | 931 | regno = REGNO (dest); |
9ae8ffe7 | 932 | |
ac606739 GS |
933 | if (regno >= reg_base_value_size) |
934 | abort (); | |
935 | ||
c28b4e40 JW |
936 | /* If this spans multiple hard registers, then we must indicate that every |
937 | register has an unusable value. */ | |
938 | if (regno < FIRST_PSEUDO_REGISTER) | |
939 | n = HARD_REGNO_NREGS (regno, GET_MODE (dest)); | |
940 | else | |
941 | n = 1; | |
942 | if (n != 1) | |
943 | { | |
944 | while (--n >= 0) | |
945 | { | |
946 | reg_seen[regno + n] = 1; | |
947 | new_reg_base_value[regno + n] = 0; | |
948 | } | |
949 | return; | |
950 | } | |
951 | ||
9ae8ffe7 JL |
952 | if (set) |
953 | { | |
954 | /* A CLOBBER wipes out any old value but does not prevent a previously | |
955 | unset register from acquiring a base address (i.e. reg_seen is not | |
956 | set). */ | |
957 | if (GET_CODE (set) == CLOBBER) | |
958 | { | |
ec907dd8 | 959 | new_reg_base_value[regno] = 0; |
9ae8ffe7 JL |
960 | return; |
961 | } | |
962 | src = SET_SRC (set); | |
963 | } | |
964 | else | |
965 | { | |
9ae8ffe7 JL |
966 | if (reg_seen[regno]) |
967 | { | |
ec907dd8 | 968 | new_reg_base_value[regno] = 0; |
9ae8ffe7 JL |
969 | return; |
970 | } | |
971 | reg_seen[regno] = 1; | |
38a448ca RH |
972 | new_reg_base_value[regno] = gen_rtx_ADDRESS (Pmode, |
973 | GEN_INT (unique_id++)); | |
9ae8ffe7 JL |
974 | return; |
975 | } | |
976 | ||
977 | /* This is not the first set. If the new value is not related to the | |
978 | old value, forget the base value. Note that the following code is | |
979 | not detected: | |
980 | extern int x, y; int *p = &x; p += (&y-&x); | |
981 | ANSI C does not allow computing the difference of addresses | |
982 | of distinct top level objects. */ | |
ec907dd8 | 983 | if (new_reg_base_value[regno]) |
9ae8ffe7 JL |
984 | switch (GET_CODE (src)) |
985 | { | |
2a2c8203 | 986 | case LO_SUM: |
9ae8ffe7 JL |
987 | case MINUS: |
988 | if (XEXP (src, 0) != dest && XEXP (src, 1) != dest) | |
ec907dd8 | 989 | new_reg_base_value[regno] = 0; |
9ae8ffe7 | 990 | break; |
61f0131c R |
991 | case PLUS: |
992 | /* If the value we add in the PLUS is also a valid base value, | |
993 | this might be the actual base value, and the original value | |
994 | an index. */ | |
995 | { | |
996 | rtx other = NULL_RTX; | |
997 | ||
998 | if (XEXP (src, 0) == dest) | |
999 | other = XEXP (src, 1); | |
1000 | else if (XEXP (src, 1) == dest) | |
1001 | other = XEXP (src, 0); | |
1002 | ||
1003 | if (! other || find_base_value (other)) | |
1004 | new_reg_base_value[regno] = 0; | |
1005 | break; | |
1006 | } | |
9ae8ffe7 JL |
1007 | case AND: |
1008 | if (XEXP (src, 0) != dest || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
ec907dd8 | 1009 | new_reg_base_value[regno] = 0; |
9ae8ffe7 | 1010 | break; |
9ae8ffe7 | 1011 | default: |
ec907dd8 | 1012 | new_reg_base_value[regno] = 0; |
9ae8ffe7 JL |
1013 | break; |
1014 | } | |
1015 | /* If this is the first set of a register, record the value. */ | |
1016 | else if ((regno >= FIRST_PSEUDO_REGISTER || ! fixed_regs[regno]) | |
ec907dd8 JL |
1017 | && ! reg_seen[regno] && new_reg_base_value[regno] == 0) |
1018 | new_reg_base_value[regno] = find_base_value (src); | |
9ae8ffe7 JL |
1019 | |
1020 | reg_seen[regno] = 1; | |
1021 | } | |
1022 | ||
ac3d9668 RK |
1023 | /* Called from loop optimization when a new pseudo-register is |
1024 | created. It indicates that REGNO is being set to VAL. f INVARIANT | |
1025 | is true then this value also describes an invariant relationship | |
1026 | which can be used to deduce that two registers with unknown values | |
1027 | are different. */ | |
d4b60170 | 1028 | |
9ae8ffe7 | 1029 | void |
4682ae04 | 1030 | record_base_value (unsigned int regno, rtx val, int invariant) |
9ae8ffe7 | 1031 | { |
ac3d9668 | 1032 | if (regno >= reg_base_value_size) |
9ae8ffe7 | 1033 | return; |
de12be17 | 1034 | |
de12be17 JC |
1035 | if (invariant && alias_invariant) |
1036 | alias_invariant[regno] = val; | |
1037 | ||
9ae8ffe7 JL |
1038 | if (GET_CODE (val) == REG) |
1039 | { | |
fb6754f0 BS |
1040 | if (REGNO (val) < reg_base_value_size) |
1041 | reg_base_value[regno] = reg_base_value[REGNO (val)]; | |
d4b60170 | 1042 | |
9ae8ffe7 JL |
1043 | return; |
1044 | } | |
d4b60170 | 1045 | |
9ae8ffe7 JL |
1046 | reg_base_value[regno] = find_base_value (val); |
1047 | } | |
1048 | ||
43fe47ca JW |
1049 | /* Clear alias info for a register. This is used if an RTL transformation |
1050 | changes the value of a register. This is used in flow by AUTO_INC_DEC | |
1051 | optimizations. We don't need to clear reg_base_value, since flow only | |
1052 | changes the offset. */ | |
1053 | ||
1054 | void | |
4682ae04 | 1055 | clear_reg_alias_info (rtx reg) |
43fe47ca | 1056 | { |
4e1a4144 JW |
1057 | unsigned int regno = REGNO (reg); |
1058 | ||
1059 | if (regno < reg_known_value_size && regno >= FIRST_PSEUDO_REGISTER) | |
1060 | reg_known_value[regno] = reg; | |
43fe47ca JW |
1061 | } |
1062 | ||
db048faf MM |
1063 | /* Returns a canonical version of X, from the point of view alias |
1064 | analysis. (For example, if X is a MEM whose address is a register, | |
1065 | and the register has a known value (say a SYMBOL_REF), then a MEM | |
1066 | whose address is the SYMBOL_REF is returned.) */ | |
1067 | ||
1068 | rtx | |
4682ae04 | 1069 | canon_rtx (rtx x) |
9ae8ffe7 JL |
1070 | { |
1071 | /* Recursively look for equivalences. */ | |
fb6754f0 BS |
1072 | if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER |
1073 | && REGNO (x) < reg_known_value_size) | |
1074 | return reg_known_value[REGNO (x)] == x | |
1075 | ? x : canon_rtx (reg_known_value[REGNO (x)]); | |
9ae8ffe7 JL |
1076 | else if (GET_CODE (x) == PLUS) |
1077 | { | |
1078 | rtx x0 = canon_rtx (XEXP (x, 0)); | |
1079 | rtx x1 = canon_rtx (XEXP (x, 1)); | |
1080 | ||
1081 | if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1)) | |
1082 | { | |
9ae8ffe7 | 1083 | if (GET_CODE (x0) == CONST_INT) |
ed8908e7 | 1084 | return plus_constant (x1, INTVAL (x0)); |
9ae8ffe7 | 1085 | else if (GET_CODE (x1) == CONST_INT) |
ed8908e7 | 1086 | return plus_constant (x0, INTVAL (x1)); |
38a448ca | 1087 | return gen_rtx_PLUS (GET_MODE (x), x0, x1); |
9ae8ffe7 JL |
1088 | } |
1089 | } | |
d4b60170 | 1090 | |
9ae8ffe7 JL |
1091 | /* This gives us much better alias analysis when called from |
1092 | the loop optimizer. Note we want to leave the original | |
1093 | MEM alone, but need to return the canonicalized MEM with | |
1094 | all the flags with their original values. */ | |
1095 | else if (GET_CODE (x) == MEM) | |
f1ec5147 | 1096 | x = replace_equiv_address_nv (x, canon_rtx (XEXP (x, 0))); |
d4b60170 | 1097 | |
9ae8ffe7 JL |
1098 | return x; |
1099 | } | |
1100 | ||
1101 | /* Return 1 if X and Y are identical-looking rtx's. | |
45183e03 | 1102 | Expect that X and Y has been already canonicalized. |
9ae8ffe7 JL |
1103 | |
1104 | We use the data in reg_known_value above to see if two registers with | |
1105 | different numbers are, in fact, equivalent. */ | |
1106 | ||
1107 | static int | |
4682ae04 | 1108 | rtx_equal_for_memref_p (rtx x, rtx y) |
9ae8ffe7 | 1109 | { |
b3694847 SS |
1110 | int i; |
1111 | int j; | |
1112 | enum rtx_code code; | |
1113 | const char *fmt; | |
9ae8ffe7 JL |
1114 | |
1115 | if (x == 0 && y == 0) | |
1116 | return 1; | |
1117 | if (x == 0 || y == 0) | |
1118 | return 0; | |
d4b60170 | 1119 | |
9ae8ffe7 JL |
1120 | if (x == y) |
1121 | return 1; | |
1122 | ||
1123 | code = GET_CODE (x); | |
1124 | /* Rtx's of different codes cannot be equal. */ | |
1125 | if (code != GET_CODE (y)) | |
1126 | return 0; | |
1127 | ||
1128 | /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. | |
1129 | (REG:SI x) and (REG:HI x) are NOT equivalent. */ | |
1130 | ||
1131 | if (GET_MODE (x) != GET_MODE (y)) | |
1132 | return 0; | |
1133 | ||
db048faf MM |
1134 | /* Some RTL can be compared without a recursive examination. */ |
1135 | switch (code) | |
1136 | { | |
ab59db3c BS |
1137 | case VALUE: |
1138 | return CSELIB_VAL_PTR (x) == CSELIB_VAL_PTR (y); | |
1139 | ||
db048faf MM |
1140 | case REG: |
1141 | return REGNO (x) == REGNO (y); | |
1142 | ||
1143 | case LABEL_REF: | |
1144 | return XEXP (x, 0) == XEXP (y, 0); | |
ca7fd9cd | 1145 | |
db048faf MM |
1146 | case SYMBOL_REF: |
1147 | return XSTR (x, 0) == XSTR (y, 0); | |
1148 | ||
1149 | case CONST_INT: | |
1150 | case CONST_DOUBLE: | |
1151 | /* There's no need to compare the contents of CONST_DOUBLEs or | |
1152 | CONST_INTs because pointer equality is a good enough | |
1153 | comparison for these nodes. */ | |
1154 | return 0; | |
1155 | ||
1156 | case ADDRESSOF: | |
831ecbd4 | 1157 | return (XINT (x, 1) == XINT (y, 1) |
45183e03 | 1158 | && rtx_equal_for_memref_p (XEXP (x, 0), |
4682ae04 | 1159 | XEXP (y, 0))); |
db048faf MM |
1160 | |
1161 | default: | |
1162 | break; | |
1163 | } | |
9ae8ffe7 | 1164 | |
45183e03 JH |
1165 | /* canon_rtx knows how to handle plus. No need to canonicalize. */ |
1166 | if (code == PLUS) | |
9ae8ffe7 JL |
1167 | return ((rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 0)) |
1168 | && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 1))) | |
1169 | || (rtx_equal_for_memref_p (XEXP (x, 0), XEXP (y, 1)) | |
1170 | && rtx_equal_for_memref_p (XEXP (x, 1), XEXP (y, 0)))); | |
45183e03 JH |
1171 | /* For commutative operations, the RTX match if the operand match in any |
1172 | order. Also handle the simple binary and unary cases without a loop. */ | |
1173 | if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c') | |
1174 | { | |
1175 | rtx xop0 = canon_rtx (XEXP (x, 0)); | |
1176 | rtx yop0 = canon_rtx (XEXP (y, 0)); | |
1177 | rtx yop1 = canon_rtx (XEXP (y, 1)); | |
1178 | ||
1179 | return ((rtx_equal_for_memref_p (xop0, yop0) | |
1180 | && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)), yop1)) | |
1181 | || (rtx_equal_for_memref_p (xop0, yop1) | |
1182 | && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)), yop0))); | |
1183 | } | |
9ae8ffe7 | 1184 | else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == '2') |
45183e03 JH |
1185 | { |
1186 | return (rtx_equal_for_memref_p (canon_rtx (XEXP (x, 0)), | |
4682ae04 | 1187 | canon_rtx (XEXP (y, 0))) |
45183e03 JH |
1188 | && rtx_equal_for_memref_p (canon_rtx (XEXP (x, 1)), |
1189 | canon_rtx (XEXP (y, 1)))); | |
1190 | } | |
9ae8ffe7 | 1191 | else if (GET_RTX_CLASS (code) == '1') |
45183e03 | 1192 | return rtx_equal_for_memref_p (canon_rtx (XEXP (x, 0)), |
4682ae04 | 1193 | canon_rtx (XEXP (y, 0))); |
9ae8ffe7 JL |
1194 | |
1195 | /* Compare the elements. If any pair of corresponding elements | |
de12be17 JC |
1196 | fail to match, return 0 for the whole things. |
1197 | ||
1198 | Limit cases to types which actually appear in addresses. */ | |
9ae8ffe7 JL |
1199 | |
1200 | fmt = GET_RTX_FORMAT (code); | |
1201 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1202 | { | |
1203 | switch (fmt[i]) | |
1204 | { | |
9ae8ffe7 JL |
1205 | case 'i': |
1206 | if (XINT (x, i) != XINT (y, i)) | |
1207 | return 0; | |
1208 | break; | |
1209 | ||
9ae8ffe7 JL |
1210 | case 'E': |
1211 | /* Two vectors must have the same length. */ | |
1212 | if (XVECLEN (x, i) != XVECLEN (y, i)) | |
1213 | return 0; | |
1214 | ||
1215 | /* And the corresponding elements must match. */ | |
1216 | for (j = 0; j < XVECLEN (x, i); j++) | |
45183e03 JH |
1217 | if (rtx_equal_for_memref_p (canon_rtx (XVECEXP (x, i, j)), |
1218 | canon_rtx (XVECEXP (y, i, j))) == 0) | |
9ae8ffe7 JL |
1219 | return 0; |
1220 | break; | |
1221 | ||
1222 | case 'e': | |
45183e03 JH |
1223 | if (rtx_equal_for_memref_p (canon_rtx (XEXP (x, i)), |
1224 | canon_rtx (XEXP (y, i))) == 0) | |
9ae8ffe7 JL |
1225 | return 0; |
1226 | break; | |
1227 | ||
3237ac18 AH |
1228 | /* This can happen for asm operands. */ |
1229 | case 's': | |
1230 | if (strcmp (XSTR (x, i), XSTR (y, i))) | |
1231 | return 0; | |
1232 | break; | |
1233 | ||
aee21ba9 JL |
1234 | /* This can happen for an asm which clobbers memory. */ |
1235 | case '0': | |
1236 | break; | |
1237 | ||
9ae8ffe7 JL |
1238 | /* It is believed that rtx's at this level will never |
1239 | contain anything but integers and other rtx's, | |
1240 | except for within LABEL_REFs and SYMBOL_REFs. */ | |
1241 | default: | |
1242 | abort (); | |
1243 | } | |
1244 | } | |
1245 | return 1; | |
1246 | } | |
1247 | ||
1248 | /* Given an rtx X, find a SYMBOL_REF or LABEL_REF within | |
1249 | X and return it, or return 0 if none found. */ | |
1250 | ||
1251 | static rtx | |
4682ae04 | 1252 | find_symbolic_term (rtx x) |
9ae8ffe7 | 1253 | { |
b3694847 SS |
1254 | int i; |
1255 | enum rtx_code code; | |
1256 | const char *fmt; | |
9ae8ffe7 JL |
1257 | |
1258 | code = GET_CODE (x); | |
1259 | if (code == SYMBOL_REF || code == LABEL_REF) | |
1260 | return x; | |
1261 | if (GET_RTX_CLASS (code) == 'o') | |
1262 | return 0; | |
1263 | ||
1264 | fmt = GET_RTX_FORMAT (code); | |
1265 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1266 | { | |
1267 | rtx t; | |
1268 | ||
1269 | if (fmt[i] == 'e') | |
1270 | { | |
1271 | t = find_symbolic_term (XEXP (x, i)); | |
1272 | if (t != 0) | |
1273 | return t; | |
1274 | } | |
1275 | else if (fmt[i] == 'E') | |
1276 | break; | |
1277 | } | |
1278 | return 0; | |
1279 | } | |
1280 | ||
94f24ddc | 1281 | rtx |
4682ae04 | 1282 | find_base_term (rtx x) |
9ae8ffe7 | 1283 | { |
eab5c70a BS |
1284 | cselib_val *val; |
1285 | struct elt_loc_list *l; | |
1286 | ||
b949ea8b JW |
1287 | #if defined (FIND_BASE_TERM) |
1288 | /* Try machine-dependent ways to find the base term. */ | |
1289 | x = FIND_BASE_TERM (x); | |
1290 | #endif | |
1291 | ||
9ae8ffe7 JL |
1292 | switch (GET_CODE (x)) |
1293 | { | |
1294 | case REG: | |
1295 | return REG_BASE_VALUE (x); | |
1296 | ||
d288e53d DE |
1297 | case TRUNCATE: |
1298 | if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (Pmode)) | |
ca7fd9cd | 1299 | return 0; |
d288e53d | 1300 | /* Fall through. */ |
9ae8ffe7 | 1301 | case HIGH: |
6d849a2a JL |
1302 | case PRE_INC: |
1303 | case PRE_DEC: | |
1304 | case POST_INC: | |
1305 | case POST_DEC: | |
d288e53d DE |
1306 | case PRE_MODIFY: |
1307 | case POST_MODIFY: | |
6d849a2a JL |
1308 | return find_base_term (XEXP (x, 0)); |
1309 | ||
1abade85 RK |
1310 | case ZERO_EXTEND: |
1311 | case SIGN_EXTEND: /* Used for Alpha/NT pointers */ | |
1312 | { | |
1313 | rtx temp = find_base_term (XEXP (x, 0)); | |
1314 | ||
5ae6cd0d | 1315 | if (temp != 0 && CONSTANT_P (temp)) |
1abade85 | 1316 | temp = convert_memory_address (Pmode, temp); |
1abade85 RK |
1317 | |
1318 | return temp; | |
1319 | } | |
1320 | ||
eab5c70a BS |
1321 | case VALUE: |
1322 | val = CSELIB_VAL_PTR (x); | |
1323 | for (l = val->locs; l; l = l->next) | |
1324 | if ((x = find_base_term (l->loc)) != 0) | |
1325 | return x; | |
1326 | return 0; | |
1327 | ||
9ae8ffe7 JL |
1328 | case CONST: |
1329 | x = XEXP (x, 0); | |
1330 | if (GET_CODE (x) != PLUS && GET_CODE (x) != MINUS) | |
1331 | return 0; | |
938d968e | 1332 | /* Fall through. */ |
9ae8ffe7 JL |
1333 | case LO_SUM: |
1334 | case PLUS: | |
1335 | case MINUS: | |
1336 | { | |
3c567fae JL |
1337 | rtx tmp1 = XEXP (x, 0); |
1338 | rtx tmp2 = XEXP (x, 1); | |
1339 | ||
f5143c46 | 1340 | /* This is a little bit tricky since we have to determine which of |
3c567fae JL |
1341 | the two operands represents the real base address. Otherwise this |
1342 | routine may return the index register instead of the base register. | |
1343 | ||
1344 | That may cause us to believe no aliasing was possible, when in | |
1345 | fact aliasing is possible. | |
1346 | ||
1347 | We use a few simple tests to guess the base register. Additional | |
1348 | tests can certainly be added. For example, if one of the operands | |
1349 | is a shift or multiply, then it must be the index register and the | |
1350 | other operand is the base register. */ | |
ca7fd9cd | 1351 | |
b949ea8b JW |
1352 | if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2)) |
1353 | return find_base_term (tmp2); | |
1354 | ||
3c567fae JL |
1355 | /* If either operand is known to be a pointer, then use it |
1356 | to determine the base term. */ | |
3502dc9c | 1357 | if (REG_P (tmp1) && REG_POINTER (tmp1)) |
3c567fae JL |
1358 | return find_base_term (tmp1); |
1359 | ||
3502dc9c | 1360 | if (REG_P (tmp2) && REG_POINTER (tmp2)) |
3c567fae JL |
1361 | return find_base_term (tmp2); |
1362 | ||
1363 | /* Neither operand was known to be a pointer. Go ahead and find the | |
1364 | base term for both operands. */ | |
1365 | tmp1 = find_base_term (tmp1); | |
1366 | tmp2 = find_base_term (tmp2); | |
1367 | ||
1368 | /* If either base term is named object or a special address | |
1369 | (like an argument or stack reference), then use it for the | |
1370 | base term. */ | |
d4b60170 | 1371 | if (tmp1 != 0 |
3c567fae JL |
1372 | && (GET_CODE (tmp1) == SYMBOL_REF |
1373 | || GET_CODE (tmp1) == LABEL_REF | |
1374 | || (GET_CODE (tmp1) == ADDRESS | |
1375 | && GET_MODE (tmp1) != VOIDmode))) | |
1376 | return tmp1; | |
1377 | ||
d4b60170 | 1378 | if (tmp2 != 0 |
3c567fae JL |
1379 | && (GET_CODE (tmp2) == SYMBOL_REF |
1380 | || GET_CODE (tmp2) == LABEL_REF | |
1381 | || (GET_CODE (tmp2) == ADDRESS | |
1382 | && GET_MODE (tmp2) != VOIDmode))) | |
1383 | return tmp2; | |
1384 | ||
1385 | /* We could not determine which of the two operands was the | |
1386 | base register and which was the index. So we can determine | |
1387 | nothing from the base alias check. */ | |
1388 | return 0; | |
9ae8ffe7 JL |
1389 | } |
1390 | ||
1391 | case AND: | |
d288e53d DE |
1392 | if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) != 0) |
1393 | return find_base_term (XEXP (x, 0)); | |
9ae8ffe7 JL |
1394 | return 0; |
1395 | ||
1396 | case SYMBOL_REF: | |
1397 | case LABEL_REF: | |
1398 | return x; | |
1399 | ||
d982e46e | 1400 | case ADDRESSOF: |
bb07060a | 1401 | return REG_BASE_VALUE (frame_pointer_rtx); |
d982e46e | 1402 | |
9ae8ffe7 JL |
1403 | default: |
1404 | return 0; | |
1405 | } | |
1406 | } | |
1407 | ||
1408 | /* Return 0 if the addresses X and Y are known to point to different | |
1409 | objects, 1 if they might be pointers to the same object. */ | |
1410 | ||
1411 | static int | |
4682ae04 AJ |
1412 | base_alias_check (rtx x, rtx y, enum machine_mode x_mode, |
1413 | enum machine_mode y_mode) | |
9ae8ffe7 JL |
1414 | { |
1415 | rtx x_base = find_base_term (x); | |
1416 | rtx y_base = find_base_term (y); | |
1417 | ||
1c72c7f6 JC |
1418 | /* If the address itself has no known base see if a known equivalent |
1419 | value has one. If either address still has no known base, nothing | |
1420 | is known about aliasing. */ | |
1421 | if (x_base == 0) | |
1422 | { | |
1423 | rtx x_c; | |
d4b60170 | 1424 | |
1c72c7f6 JC |
1425 | if (! flag_expensive_optimizations || (x_c = canon_rtx (x)) == x) |
1426 | return 1; | |
d4b60170 | 1427 | |
1c72c7f6 JC |
1428 | x_base = find_base_term (x_c); |
1429 | if (x_base == 0) | |
1430 | return 1; | |
1431 | } | |
9ae8ffe7 | 1432 | |
1c72c7f6 JC |
1433 | if (y_base == 0) |
1434 | { | |
1435 | rtx y_c; | |
1436 | if (! flag_expensive_optimizations || (y_c = canon_rtx (y)) == y) | |
1437 | return 1; | |
d4b60170 | 1438 | |
1c72c7f6 JC |
1439 | y_base = find_base_term (y_c); |
1440 | if (y_base == 0) | |
1441 | return 1; | |
1442 | } | |
1443 | ||
1444 | /* If the base addresses are equal nothing is known about aliasing. */ | |
1445 | if (rtx_equal_p (x_base, y_base)) | |
9ae8ffe7 JL |
1446 | return 1; |
1447 | ||
ca7fd9cd | 1448 | /* The base addresses of the read and write are different expressions. |
56ee9281 RH |
1449 | If they are both symbols and they are not accessed via AND, there is |
1450 | no conflict. We can bring knowledge of object alignment into play | |
1451 | here. For example, on alpha, "char a, b;" can alias one another, | |
1452 | though "char a; long b;" cannot. */ | |
9ae8ffe7 | 1453 | if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS) |
c02f035f | 1454 | { |
56ee9281 RH |
1455 | if (GET_CODE (x) == AND && GET_CODE (y) == AND) |
1456 | return 1; | |
1457 | if (GET_CODE (x) == AND | |
1458 | && (GET_CODE (XEXP (x, 1)) != CONST_INT | |
8fa2140d | 1459 | || (int) GET_MODE_UNIT_SIZE (y_mode) < -INTVAL (XEXP (x, 1)))) |
56ee9281 RH |
1460 | return 1; |
1461 | if (GET_CODE (y) == AND | |
1462 | && (GET_CODE (XEXP (y, 1)) != CONST_INT | |
8fa2140d | 1463 | || (int) GET_MODE_UNIT_SIZE (x_mode) < -INTVAL (XEXP (y, 1)))) |
56ee9281 | 1464 | return 1; |
b2972551 JL |
1465 | /* Differing symbols never alias. */ |
1466 | return 0; | |
c02f035f | 1467 | } |
9ae8ffe7 JL |
1468 | |
1469 | /* If one address is a stack reference there can be no alias: | |
1470 | stack references using different base registers do not alias, | |
1471 | a stack reference can not alias a parameter, and a stack reference | |
1472 | can not alias a global. */ | |
1473 | if ((GET_CODE (x_base) == ADDRESS && GET_MODE (x_base) == Pmode) | |
1474 | || (GET_CODE (y_base) == ADDRESS && GET_MODE (y_base) == Pmode)) | |
1475 | return 0; | |
1476 | ||
1477 | if (! flag_argument_noalias) | |
1478 | return 1; | |
1479 | ||
1480 | if (flag_argument_noalias > 1) | |
1481 | return 0; | |
1482 | ||
ec5c56db | 1483 | /* Weak noalias assertion (arguments are distinct, but may match globals). */ |
9ae8ffe7 JL |
1484 | return ! (GET_MODE (x_base) == VOIDmode && GET_MODE (y_base) == VOIDmode); |
1485 | } | |
1486 | ||
eab5c70a BS |
1487 | /* Convert the address X into something we can use. This is done by returning |
1488 | it unchanged unless it is a value; in the latter case we call cselib to get | |
1489 | a more useful rtx. */ | |
3bdf5ad1 | 1490 | |
a13d4ebf | 1491 | rtx |
4682ae04 | 1492 | get_addr (rtx x) |
eab5c70a BS |
1493 | { |
1494 | cselib_val *v; | |
1495 | struct elt_loc_list *l; | |
1496 | ||
1497 | if (GET_CODE (x) != VALUE) | |
1498 | return x; | |
1499 | v = CSELIB_VAL_PTR (x); | |
1500 | for (l = v->locs; l; l = l->next) | |
1501 | if (CONSTANT_P (l->loc)) | |
1502 | return l->loc; | |
1503 | for (l = v->locs; l; l = l->next) | |
1504 | if (GET_CODE (l->loc) != REG && GET_CODE (l->loc) != MEM) | |
1505 | return l->loc; | |
1506 | if (v->locs) | |
1507 | return v->locs->loc; | |
1508 | return x; | |
1509 | } | |
1510 | ||
39cec1ac MH |
1511 | /* Return the address of the (N_REFS + 1)th memory reference to ADDR |
1512 | where SIZE is the size in bytes of the memory reference. If ADDR | |
1513 | is not modified by the memory reference then ADDR is returned. */ | |
1514 | ||
1515 | rtx | |
4682ae04 | 1516 | addr_side_effect_eval (rtx addr, int size, int n_refs) |
39cec1ac MH |
1517 | { |
1518 | int offset = 0; | |
ca7fd9cd | 1519 | |
39cec1ac MH |
1520 | switch (GET_CODE (addr)) |
1521 | { | |
1522 | case PRE_INC: | |
1523 | offset = (n_refs + 1) * size; | |
1524 | break; | |
1525 | case PRE_DEC: | |
1526 | offset = -(n_refs + 1) * size; | |
1527 | break; | |
1528 | case POST_INC: | |
1529 | offset = n_refs * size; | |
1530 | break; | |
1531 | case POST_DEC: | |
1532 | offset = -n_refs * size; | |
1533 | break; | |
1534 | ||
1535 | default: | |
1536 | return addr; | |
1537 | } | |
ca7fd9cd | 1538 | |
39cec1ac | 1539 | if (offset) |
45183e03 JH |
1540 | addr = gen_rtx_PLUS (GET_MODE (addr), XEXP (addr, 0), |
1541 | GEN_INT (offset)); | |
39cec1ac MH |
1542 | else |
1543 | addr = XEXP (addr, 0); | |
45183e03 | 1544 | addr = canon_rtx (addr); |
39cec1ac MH |
1545 | |
1546 | return addr; | |
1547 | } | |
1548 | ||
9ae8ffe7 JL |
1549 | /* Return nonzero if X and Y (memory addresses) could reference the |
1550 | same location in memory. C is an offset accumulator. When | |
1551 | C is nonzero, we are testing aliases between X and Y + C. | |
1552 | XSIZE is the size in bytes of the X reference, | |
1553 | similarly YSIZE is the size in bytes for Y. | |
45183e03 | 1554 | Expect that canon_rtx has been already called for X and Y. |
9ae8ffe7 JL |
1555 | |
1556 | If XSIZE or YSIZE is zero, we do not know the amount of memory being | |
1557 | referenced (the reference was BLKmode), so make the most pessimistic | |
1558 | assumptions. | |
1559 | ||
c02f035f RH |
1560 | If XSIZE or YSIZE is negative, we may access memory outside the object |
1561 | being referenced as a side effect. This can happen when using AND to | |
1562 | align memory references, as is done on the Alpha. | |
1563 | ||
9ae8ffe7 | 1564 | Nice to notice that varying addresses cannot conflict with fp if no |
0211b6ab | 1565 | local variables had their addresses taken, but that's too hard now. */ |
9ae8ffe7 | 1566 | |
9ae8ffe7 | 1567 | static int |
4682ae04 | 1568 | memrefs_conflict_p (int xsize, rtx x, int ysize, rtx y, HOST_WIDE_INT c) |
9ae8ffe7 | 1569 | { |
eab5c70a BS |
1570 | if (GET_CODE (x) == VALUE) |
1571 | x = get_addr (x); | |
1572 | if (GET_CODE (y) == VALUE) | |
1573 | y = get_addr (y); | |
9ae8ffe7 JL |
1574 | if (GET_CODE (x) == HIGH) |
1575 | x = XEXP (x, 0); | |
1576 | else if (GET_CODE (x) == LO_SUM) | |
1577 | x = XEXP (x, 1); | |
1578 | else | |
45183e03 | 1579 | x = addr_side_effect_eval (x, xsize, 0); |
9ae8ffe7 JL |
1580 | if (GET_CODE (y) == HIGH) |
1581 | y = XEXP (y, 0); | |
1582 | else if (GET_CODE (y) == LO_SUM) | |
1583 | y = XEXP (y, 1); | |
1584 | else | |
45183e03 | 1585 | y = addr_side_effect_eval (y, ysize, 0); |
9ae8ffe7 JL |
1586 | |
1587 | if (rtx_equal_for_memref_p (x, y)) | |
1588 | { | |
c02f035f | 1589 | if (xsize <= 0 || ysize <= 0) |
9ae8ffe7 JL |
1590 | return 1; |
1591 | if (c >= 0 && xsize > c) | |
1592 | return 1; | |
1593 | if (c < 0 && ysize+c > 0) | |
1594 | return 1; | |
1595 | return 0; | |
1596 | } | |
1597 | ||
6e73e666 JC |
1598 | /* This code used to check for conflicts involving stack references and |
1599 | globals but the base address alias code now handles these cases. */ | |
9ae8ffe7 JL |
1600 | |
1601 | if (GET_CODE (x) == PLUS) | |
1602 | { | |
1603 | /* The fact that X is canonicalized means that this | |
1604 | PLUS rtx is canonicalized. */ | |
1605 | rtx x0 = XEXP (x, 0); | |
1606 | rtx x1 = XEXP (x, 1); | |
1607 | ||
1608 | if (GET_CODE (y) == PLUS) | |
1609 | { | |
1610 | /* The fact that Y is canonicalized means that this | |
1611 | PLUS rtx is canonicalized. */ | |
1612 | rtx y0 = XEXP (y, 0); | |
1613 | rtx y1 = XEXP (y, 1); | |
1614 | ||
1615 | if (rtx_equal_for_memref_p (x1, y1)) | |
1616 | return memrefs_conflict_p (xsize, x0, ysize, y0, c); | |
1617 | if (rtx_equal_for_memref_p (x0, y0)) | |
1618 | return memrefs_conflict_p (xsize, x1, ysize, y1, c); | |
1619 | if (GET_CODE (x1) == CONST_INT) | |
63be02db JM |
1620 | { |
1621 | if (GET_CODE (y1) == CONST_INT) | |
1622 | return memrefs_conflict_p (xsize, x0, ysize, y0, | |
1623 | c - INTVAL (x1) + INTVAL (y1)); | |
1624 | else | |
1625 | return memrefs_conflict_p (xsize, x0, ysize, y, | |
1626 | c - INTVAL (x1)); | |
1627 | } | |
9ae8ffe7 JL |
1628 | else if (GET_CODE (y1) == CONST_INT) |
1629 | return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1)); | |
1630 | ||
6e73e666 | 1631 | return 1; |
9ae8ffe7 JL |
1632 | } |
1633 | else if (GET_CODE (x1) == CONST_INT) | |
1634 | return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1)); | |
1635 | } | |
1636 | else if (GET_CODE (y) == PLUS) | |
1637 | { | |
1638 | /* The fact that Y is canonicalized means that this | |
1639 | PLUS rtx is canonicalized. */ | |
1640 | rtx y0 = XEXP (y, 0); | |
1641 | rtx y1 = XEXP (y, 1); | |
1642 | ||
1643 | if (GET_CODE (y1) == CONST_INT) | |
1644 | return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1)); | |
1645 | else | |
1646 | return 1; | |
1647 | } | |
1648 | ||
1649 | if (GET_CODE (x) == GET_CODE (y)) | |
1650 | switch (GET_CODE (x)) | |
1651 | { | |
1652 | case MULT: | |
1653 | { | |
1654 | /* Handle cases where we expect the second operands to be the | |
1655 | same, and check only whether the first operand would conflict | |
1656 | or not. */ | |
1657 | rtx x0, y0; | |
1658 | rtx x1 = canon_rtx (XEXP (x, 1)); | |
1659 | rtx y1 = canon_rtx (XEXP (y, 1)); | |
1660 | if (! rtx_equal_for_memref_p (x1, y1)) | |
1661 | return 1; | |
1662 | x0 = canon_rtx (XEXP (x, 0)); | |
1663 | y0 = canon_rtx (XEXP (y, 0)); | |
1664 | if (rtx_equal_for_memref_p (x0, y0)) | |
1665 | return (xsize == 0 || ysize == 0 | |
1666 | || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0)); | |
1667 | ||
1668 | /* Can't properly adjust our sizes. */ | |
1669 | if (GET_CODE (x1) != CONST_INT) | |
1670 | return 1; | |
1671 | xsize /= INTVAL (x1); | |
1672 | ysize /= INTVAL (x1); | |
1673 | c /= INTVAL (x1); | |
1674 | return memrefs_conflict_p (xsize, x0, ysize, y0, c); | |
1675 | } | |
1d300e19 | 1676 | |
de12be17 JC |
1677 | case REG: |
1678 | /* Are these registers known not to be equal? */ | |
1679 | if (alias_invariant) | |
1680 | { | |
e51712db | 1681 | unsigned int r_x = REGNO (x), r_y = REGNO (y); |
de12be17 JC |
1682 | rtx i_x, i_y; /* invariant relationships of X and Y */ |
1683 | ||
1684 | i_x = r_x >= reg_base_value_size ? 0 : alias_invariant[r_x]; | |
1685 | i_y = r_y >= reg_base_value_size ? 0 : alias_invariant[r_y]; | |
1686 | ||
1687 | if (i_x == 0 && i_y == 0) | |
1688 | break; | |
1689 | ||
1690 | if (! memrefs_conflict_p (xsize, i_x ? i_x : x, | |
1691 | ysize, i_y ? i_y : y, c)) | |
1692 | return 0; | |
1693 | } | |
1694 | break; | |
1695 | ||
1d300e19 KG |
1696 | default: |
1697 | break; | |
9ae8ffe7 JL |
1698 | } |
1699 | ||
1700 | /* Treat an access through an AND (e.g. a subword access on an Alpha) | |
ca7fd9cd | 1701 | as an access with indeterminate size. Assume that references |
56ee9281 RH |
1702 | besides AND are aligned, so if the size of the other reference is |
1703 | at least as large as the alignment, assume no other overlap. */ | |
9ae8ffe7 | 1704 | if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT) |
56ee9281 | 1705 | { |
02e3377d | 1706 | if (GET_CODE (y) == AND || ysize < -INTVAL (XEXP (x, 1))) |
56ee9281 | 1707 | xsize = -1; |
45183e03 | 1708 | return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)), ysize, y, c); |
56ee9281 | 1709 | } |
9ae8ffe7 | 1710 | if (GET_CODE (y) == AND && GET_CODE (XEXP (y, 1)) == CONST_INT) |
c02f035f | 1711 | { |
56ee9281 | 1712 | /* ??? If we are indexing far enough into the array/structure, we |
ca7fd9cd | 1713 | may yet be able to determine that we can not overlap. But we |
c02f035f | 1714 | also need to that we are far enough from the end not to overlap |
56ee9281 | 1715 | a following reference, so we do nothing with that for now. */ |
02e3377d | 1716 | if (GET_CODE (x) == AND || xsize < -INTVAL (XEXP (y, 1))) |
56ee9281 | 1717 | ysize = -1; |
45183e03 | 1718 | return memrefs_conflict_p (xsize, x, ysize, canon_rtx (XEXP (y, 0)), c); |
c02f035f | 1719 | } |
9ae8ffe7 | 1720 | |
b24ea077 JW |
1721 | if (GET_CODE (x) == ADDRESSOF) |
1722 | { | |
1723 | if (y == frame_pointer_rtx | |
1724 | || GET_CODE (y) == ADDRESSOF) | |
1725 | return xsize <= 0 || ysize <= 0; | |
1726 | } | |
1727 | if (GET_CODE (y) == ADDRESSOF) | |
1728 | { | |
1729 | if (x == frame_pointer_rtx) | |
1730 | return xsize <= 0 || ysize <= 0; | |
1731 | } | |
d982e46e | 1732 | |
9ae8ffe7 JL |
1733 | if (CONSTANT_P (x)) |
1734 | { | |
1735 | if (GET_CODE (x) == CONST_INT && GET_CODE (y) == CONST_INT) | |
1736 | { | |
1737 | c += (INTVAL (y) - INTVAL (x)); | |
c02f035f | 1738 | return (xsize <= 0 || ysize <= 0 |
9ae8ffe7 JL |
1739 | || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0)); |
1740 | } | |
1741 | ||
1742 | if (GET_CODE (x) == CONST) | |
1743 | { | |
1744 | if (GET_CODE (y) == CONST) | |
1745 | return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)), | |
1746 | ysize, canon_rtx (XEXP (y, 0)), c); | |
1747 | else | |
1748 | return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)), | |
1749 | ysize, y, c); | |
1750 | } | |
1751 | if (GET_CODE (y) == CONST) | |
1752 | return memrefs_conflict_p (xsize, x, ysize, | |
1753 | canon_rtx (XEXP (y, 0)), c); | |
1754 | ||
1755 | if (CONSTANT_P (y)) | |
b949ea8b | 1756 | return (xsize <= 0 || ysize <= 0 |
c02f035f | 1757 | || (rtx_equal_for_memref_p (x, y) |
b949ea8b | 1758 | && ((c >= 0 && xsize > c) || (c < 0 && ysize+c > 0)))); |
9ae8ffe7 JL |
1759 | |
1760 | return 1; | |
1761 | } | |
1762 | return 1; | |
1763 | } | |
1764 | ||
1765 | /* Functions to compute memory dependencies. | |
1766 | ||
1767 | Since we process the insns in execution order, we can build tables | |
1768 | to keep track of what registers are fixed (and not aliased), what registers | |
1769 | are varying in known ways, and what registers are varying in unknown | |
1770 | ways. | |
1771 | ||
1772 | If both memory references are volatile, then there must always be a | |
1773 | dependence between the two references, since their order can not be | |
1774 | changed. A volatile and non-volatile reference can be interchanged | |
ca7fd9cd | 1775 | though. |
9ae8ffe7 | 1776 | |
dc1618bc RK |
1777 | A MEM_IN_STRUCT reference at a non-AND varying address can never |
1778 | conflict with a non-MEM_IN_STRUCT reference at a fixed address. We | |
1779 | also must allow AND addresses, because they may generate accesses | |
1780 | outside the object being referenced. This is used to generate | |
1781 | aligned addresses from unaligned addresses, for instance, the alpha | |
1782 | storeqi_unaligned pattern. */ | |
9ae8ffe7 JL |
1783 | |
1784 | /* Read dependence: X is read after read in MEM takes place. There can | |
1785 | only be a dependence here if both reads are volatile. */ | |
1786 | ||
1787 | int | |
4682ae04 | 1788 | read_dependence (rtx mem, rtx x) |
9ae8ffe7 JL |
1789 | { |
1790 | return MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem); | |
1791 | } | |
1792 | ||
c6df88cb MM |
1793 | /* Returns MEM1 if and only if MEM1 is a scalar at a fixed address and |
1794 | MEM2 is a reference to a structure at a varying address, or returns | |
1795 | MEM2 if vice versa. Otherwise, returns NULL_RTX. If a non-NULL | |
1796 | value is returned MEM1 and MEM2 can never alias. VARIES_P is used | |
1797 | to decide whether or not an address may vary; it should return | |
eab5c70a BS |
1798 | nonzero whenever variation is possible. |
1799 | MEM1_ADDR and MEM2_ADDR are the addresses of MEM1 and MEM2. */ | |
ca7fd9cd | 1800 | |
2c72b78f | 1801 | static rtx |
4682ae04 AJ |
1802 | fixed_scalar_and_varying_struct_p (rtx mem1, rtx mem2, rtx mem1_addr, |
1803 | rtx mem2_addr, | |
1804 | int (*varies_p) (rtx, int)) | |
ca7fd9cd | 1805 | { |
3e0abe15 GK |
1806 | if (! flag_strict_aliasing) |
1807 | return NULL_RTX; | |
1808 | ||
ca7fd9cd | 1809 | if (MEM_SCALAR_P (mem1) && MEM_IN_STRUCT_P (mem2) |
e38fe8e0 | 1810 | && !varies_p (mem1_addr, 1) && varies_p (mem2_addr, 1)) |
c6df88cb MM |
1811 | /* MEM1 is a scalar at a fixed address; MEM2 is a struct at a |
1812 | varying address. */ | |
1813 | return mem1; | |
1814 | ||
ca7fd9cd | 1815 | if (MEM_IN_STRUCT_P (mem1) && MEM_SCALAR_P (mem2) |
e38fe8e0 | 1816 | && varies_p (mem1_addr, 1) && !varies_p (mem2_addr, 1)) |
c6df88cb MM |
1817 | /* MEM2 is a scalar at a fixed address; MEM1 is a struct at a |
1818 | varying address. */ | |
1819 | return mem2; | |
1820 | ||
1821 | return NULL_RTX; | |
1822 | } | |
1823 | ||
1824 | /* Returns nonzero if something about the mode or address format MEM1 | |
1825 | indicates that it might well alias *anything*. */ | |
1826 | ||
2c72b78f | 1827 | static int |
4682ae04 | 1828 | aliases_everything_p (rtx mem) |
c6df88cb | 1829 | { |
c6df88cb MM |
1830 | if (GET_CODE (XEXP (mem, 0)) == AND) |
1831 | /* If the address is an AND, its very hard to know at what it is | |
1832 | actually pointing. */ | |
1833 | return 1; | |
ca7fd9cd | 1834 | |
c6df88cb MM |
1835 | return 0; |
1836 | } | |
1837 | ||
998d7deb RH |
1838 | /* Return true if we can determine that the fields referenced cannot |
1839 | overlap for any pair of objects. */ | |
1840 | ||
1841 | static bool | |
4682ae04 | 1842 | nonoverlapping_component_refs_p (tree x, tree y) |
998d7deb RH |
1843 | { |
1844 | tree fieldx, fieldy, typex, typey, orig_y; | |
1845 | ||
1846 | do | |
1847 | { | |
1848 | /* The comparison has to be done at a common type, since we don't | |
d6a7951f | 1849 | know how the inheritance hierarchy works. */ |
998d7deb RH |
1850 | orig_y = y; |
1851 | do | |
1852 | { | |
1853 | fieldx = TREE_OPERAND (x, 1); | |
1854 | typex = DECL_FIELD_CONTEXT (fieldx); | |
1855 | ||
1856 | y = orig_y; | |
1857 | do | |
1858 | { | |
1859 | fieldy = TREE_OPERAND (y, 1); | |
1860 | typey = DECL_FIELD_CONTEXT (fieldy); | |
1861 | ||
1862 | if (typex == typey) | |
1863 | goto found; | |
1864 | ||
1865 | y = TREE_OPERAND (y, 0); | |
1866 | } | |
1867 | while (y && TREE_CODE (y) == COMPONENT_REF); | |
1868 | ||
1869 | x = TREE_OPERAND (x, 0); | |
1870 | } | |
1871 | while (x && TREE_CODE (x) == COMPONENT_REF); | |
1872 | ||
1873 | /* Never found a common type. */ | |
1874 | return false; | |
1875 | ||
1876 | found: | |
1877 | /* If we're left with accessing different fields of a structure, | |
1878 | then no overlap. */ | |
1879 | if (TREE_CODE (typex) == RECORD_TYPE | |
1880 | && fieldx != fieldy) | |
1881 | return true; | |
1882 | ||
1883 | /* The comparison on the current field failed. If we're accessing | |
1884 | a very nested structure, look at the next outer level. */ | |
1885 | x = TREE_OPERAND (x, 0); | |
1886 | y = TREE_OPERAND (y, 0); | |
1887 | } | |
1888 | while (x && y | |
1889 | && TREE_CODE (x) == COMPONENT_REF | |
1890 | && TREE_CODE (y) == COMPONENT_REF); | |
ca7fd9cd | 1891 | |
998d7deb RH |
1892 | return false; |
1893 | } | |
1894 | ||
1895 | /* Look at the bottom of the COMPONENT_REF list for a DECL, and return it. */ | |
1896 | ||
1897 | static tree | |
4682ae04 | 1898 | decl_for_component_ref (tree x) |
998d7deb RH |
1899 | { |
1900 | do | |
1901 | { | |
1902 | x = TREE_OPERAND (x, 0); | |
1903 | } | |
1904 | while (x && TREE_CODE (x) == COMPONENT_REF); | |
1905 | ||
1906 | return x && DECL_P (x) ? x : NULL_TREE; | |
1907 | } | |
1908 | ||
1909 | /* Walk up the COMPONENT_REF list and adjust OFFSET to compensate for the | |
1910 | offset of the field reference. */ | |
1911 | ||
1912 | static rtx | |
4682ae04 | 1913 | adjust_offset_for_component_ref (tree x, rtx offset) |
998d7deb RH |
1914 | { |
1915 | HOST_WIDE_INT ioffset; | |
1916 | ||
1917 | if (! offset) | |
1918 | return NULL_RTX; | |
1919 | ||
1920 | ioffset = INTVAL (offset); | |
ca7fd9cd | 1921 | do |
998d7deb RH |
1922 | { |
1923 | tree field = TREE_OPERAND (x, 1); | |
1924 | ||
1925 | if (! host_integerp (DECL_FIELD_OFFSET (field), 1)) | |
1926 | return NULL_RTX; | |
1927 | ioffset += (tree_low_cst (DECL_FIELD_OFFSET (field), 1) | |
1928 | + (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1) | |
1929 | / BITS_PER_UNIT)); | |
1930 | ||
1931 | x = TREE_OPERAND (x, 0); | |
1932 | } | |
1933 | while (x && TREE_CODE (x) == COMPONENT_REF); | |
1934 | ||
1935 | return GEN_INT (ioffset); | |
1936 | } | |
1937 | ||
95bd1dd7 | 1938 | /* Return nonzero if we can determine the exprs corresponding to memrefs |
a4311dfe RK |
1939 | X and Y and they do not overlap. */ |
1940 | ||
1941 | static int | |
4682ae04 | 1942 | nonoverlapping_memrefs_p (rtx x, rtx y) |
a4311dfe | 1943 | { |
998d7deb | 1944 | tree exprx = MEM_EXPR (x), expry = MEM_EXPR (y); |
a4311dfe RK |
1945 | rtx rtlx, rtly; |
1946 | rtx basex, basey; | |
998d7deb | 1947 | rtx moffsetx, moffsety; |
a4311dfe RK |
1948 | HOST_WIDE_INT offsetx = 0, offsety = 0, sizex, sizey, tem; |
1949 | ||
998d7deb RH |
1950 | /* Unless both have exprs, we can't tell anything. */ |
1951 | if (exprx == 0 || expry == 0) | |
1952 | return 0; | |
1953 | ||
1954 | /* If both are field references, we may be able to determine something. */ | |
1955 | if (TREE_CODE (exprx) == COMPONENT_REF | |
1956 | && TREE_CODE (expry) == COMPONENT_REF | |
1957 | && nonoverlapping_component_refs_p (exprx, expry)) | |
1958 | return 1; | |
1959 | ||
1960 | /* If the field reference test failed, look at the DECLs involved. */ | |
1961 | moffsetx = MEM_OFFSET (x); | |
1962 | if (TREE_CODE (exprx) == COMPONENT_REF) | |
1963 | { | |
1964 | tree t = decl_for_component_ref (exprx); | |
1965 | if (! t) | |
1966 | return 0; | |
1967 | moffsetx = adjust_offset_for_component_ref (exprx, moffsetx); | |
1968 | exprx = t; | |
1969 | } | |
c67a1cf6 RH |
1970 | else if (TREE_CODE (exprx) == INDIRECT_REF) |
1971 | { | |
1972 | exprx = TREE_OPERAND (exprx, 0); | |
1973 | if (flag_argument_noalias < 2 | |
1974 | || TREE_CODE (exprx) != PARM_DECL) | |
1975 | return 0; | |
1976 | } | |
1977 | ||
998d7deb RH |
1978 | moffsety = MEM_OFFSET (y); |
1979 | if (TREE_CODE (expry) == COMPONENT_REF) | |
1980 | { | |
1981 | tree t = decl_for_component_ref (expry); | |
1982 | if (! t) | |
1983 | return 0; | |
1984 | moffsety = adjust_offset_for_component_ref (expry, moffsety); | |
1985 | expry = t; | |
1986 | } | |
c67a1cf6 RH |
1987 | else if (TREE_CODE (expry) == INDIRECT_REF) |
1988 | { | |
1989 | expry = TREE_OPERAND (expry, 0); | |
1990 | if (flag_argument_noalias < 2 | |
1991 | || TREE_CODE (expry) != PARM_DECL) | |
1992 | return 0; | |
1993 | } | |
998d7deb RH |
1994 | |
1995 | if (! DECL_P (exprx) || ! DECL_P (expry)) | |
a4311dfe RK |
1996 | return 0; |
1997 | ||
998d7deb RH |
1998 | rtlx = DECL_RTL (exprx); |
1999 | rtly = DECL_RTL (expry); | |
a4311dfe | 2000 | |
1edcd60b RK |
2001 | /* If either RTL is not a MEM, it must be a REG or CONCAT, meaning they |
2002 | can't overlap unless they are the same because we never reuse that part | |
2003 | of the stack frame used for locals for spilled pseudos. */ | |
2004 | if ((GET_CODE (rtlx) != MEM || GET_CODE (rtly) != MEM) | |
2005 | && ! rtx_equal_p (rtlx, rtly)) | |
a4311dfe RK |
2006 | return 1; |
2007 | ||
2008 | /* Get the base and offsets of both decls. If either is a register, we | |
2009 | know both are and are the same, so use that as the base. The only | |
2010 | we can avoid overlap is if we can deduce that they are nonoverlapping | |
2011 | pieces of that decl, which is very rare. */ | |
1edcd60b | 2012 | basex = GET_CODE (rtlx) == MEM ? XEXP (rtlx, 0) : rtlx; |
a4311dfe RK |
2013 | if (GET_CODE (basex) == PLUS && GET_CODE (XEXP (basex, 1)) == CONST_INT) |
2014 | offsetx = INTVAL (XEXP (basex, 1)), basex = XEXP (basex, 0); | |
2015 | ||
1edcd60b | 2016 | basey = GET_CODE (rtly) == MEM ? XEXP (rtly, 0) : rtly; |
a4311dfe RK |
2017 | if (GET_CODE (basey) == PLUS && GET_CODE (XEXP (basey, 1)) == CONST_INT) |
2018 | offsety = INTVAL (XEXP (basey, 1)), basey = XEXP (basey, 0); | |
2019 | ||
d746694a | 2020 | /* If the bases are different, we know they do not overlap if both |
ca7fd9cd | 2021 | are constants or if one is a constant and the other a pointer into the |
d746694a RK |
2022 | stack frame. Otherwise a different base means we can't tell if they |
2023 | overlap or not. */ | |
2024 | if (! rtx_equal_p (basex, basey)) | |
ca7fd9cd KH |
2025 | return ((CONSTANT_P (basex) && CONSTANT_P (basey)) |
2026 | || (CONSTANT_P (basex) && REG_P (basey) | |
2027 | && REGNO_PTR_FRAME_P (REGNO (basey))) | |
2028 | || (CONSTANT_P (basey) && REG_P (basex) | |
2029 | && REGNO_PTR_FRAME_P (REGNO (basex)))); | |
a4311dfe | 2030 | |
998d7deb | 2031 | sizex = (GET_CODE (rtlx) != MEM ? (int) GET_MODE_SIZE (GET_MODE (rtlx)) |
a4311dfe RK |
2032 | : MEM_SIZE (rtlx) ? INTVAL (MEM_SIZE (rtlx)) |
2033 | : -1); | |
998d7deb | 2034 | sizey = (GET_CODE (rtly) != MEM ? (int) GET_MODE_SIZE (GET_MODE (rtly)) |
a4311dfe RK |
2035 | : MEM_SIZE (rtly) ? INTVAL (MEM_SIZE (rtly)) : |
2036 | -1); | |
2037 | ||
0af5bc3e RK |
2038 | /* If we have an offset for either memref, it can update the values computed |
2039 | above. */ | |
998d7deb RH |
2040 | if (moffsetx) |
2041 | offsetx += INTVAL (moffsetx), sizex -= INTVAL (moffsetx); | |
2042 | if (moffsety) | |
2043 | offsety += INTVAL (moffsety), sizey -= INTVAL (moffsety); | |
a4311dfe | 2044 | |
0af5bc3e | 2045 | /* If a memref has both a size and an offset, we can use the smaller size. |
efc981bb | 2046 | We can't do this if the offset isn't known because we must view this |
0af5bc3e | 2047 | memref as being anywhere inside the DECL's MEM. */ |
998d7deb | 2048 | if (MEM_SIZE (x) && moffsetx) |
a4311dfe | 2049 | sizex = INTVAL (MEM_SIZE (x)); |
998d7deb | 2050 | if (MEM_SIZE (y) && moffsety) |
a4311dfe RK |
2051 | sizey = INTVAL (MEM_SIZE (y)); |
2052 | ||
2053 | /* Put the values of the memref with the lower offset in X's values. */ | |
2054 | if (offsetx > offsety) | |
2055 | { | |
2056 | tem = offsetx, offsetx = offsety, offsety = tem; | |
2057 | tem = sizex, sizex = sizey, sizey = tem; | |
2058 | } | |
2059 | ||
2060 | /* If we don't know the size of the lower-offset value, we can't tell | |
2061 | if they conflict. Otherwise, we do the test. */ | |
a6f7c915 | 2062 | return sizex >= 0 && offsety >= offsetx + sizex; |
a4311dfe RK |
2063 | } |
2064 | ||
9ae8ffe7 JL |
2065 | /* True dependence: X is read after store in MEM takes place. */ |
2066 | ||
2067 | int | |
4682ae04 AJ |
2068 | true_dependence (rtx mem, enum machine_mode mem_mode, rtx x, |
2069 | int (*varies) (rtx, int)) | |
9ae8ffe7 | 2070 | { |
b3694847 | 2071 | rtx x_addr, mem_addr; |
49982682 | 2072 | rtx base; |
9ae8ffe7 JL |
2073 | |
2074 | if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem)) | |
2075 | return 1; | |
2076 | ||
c4484b8f RH |
2077 | /* (mem:BLK (scratch)) is a special mechanism to conflict with everything. |
2078 | This is used in epilogue deallocation functions. */ | |
2079 | if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH) | |
2080 | return 1; | |
2081 | if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH) | |
2082 | return 1; | |
2083 | ||
41472af8 MM |
2084 | if (DIFFERENT_ALIAS_SETS_P (x, mem)) |
2085 | return 0; | |
2086 | ||
b949ea8b JW |
2087 | /* Unchanging memory can't conflict with non-unchanging memory. |
2088 | A non-unchanging read can conflict with a non-unchanging write. | |
2089 | An unchanging read can conflict with an unchanging write since | |
2090 | there may be a single store to this address to initialize it. | |
ec569656 RK |
2091 | Note that an unchanging store can conflict with a non-unchanging read |
2092 | since we have to make conservative assumptions when we have a | |
2093 | record with readonly fields and we are copying the whole thing. | |
b949ea8b JW |
2094 | Just fall through to the code below to resolve potential conflicts. |
2095 | This won't handle all cases optimally, but the possible performance | |
2096 | loss should be negligible. */ | |
ec569656 | 2097 | if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem)) |
9ae8ffe7 JL |
2098 | return 0; |
2099 | ||
a4311dfe RK |
2100 | if (nonoverlapping_memrefs_p (mem, x)) |
2101 | return 0; | |
2102 | ||
56ee9281 RH |
2103 | if (mem_mode == VOIDmode) |
2104 | mem_mode = GET_MODE (mem); | |
2105 | ||
eab5c70a BS |
2106 | x_addr = get_addr (XEXP (x, 0)); |
2107 | mem_addr = get_addr (XEXP (mem, 0)); | |
2108 | ||
55efb413 JW |
2109 | base = find_base_term (x_addr); |
2110 | if (base && (GET_CODE (base) == LABEL_REF | |
2111 | || (GET_CODE (base) == SYMBOL_REF | |
2112 | && CONSTANT_POOL_ADDRESS_P (base)))) | |
2113 | return 0; | |
2114 | ||
eab5c70a | 2115 | if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode)) |
1c72c7f6 JC |
2116 | return 0; |
2117 | ||
eab5c70a BS |
2118 | x_addr = canon_rtx (x_addr); |
2119 | mem_addr = canon_rtx (mem_addr); | |
6e73e666 | 2120 | |
0211b6ab JW |
2121 | if (! memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr, |
2122 | SIZE_FOR_MODE (x), x_addr, 0)) | |
2123 | return 0; | |
2124 | ||
c6df88cb | 2125 | if (aliases_everything_p (x)) |
0211b6ab JW |
2126 | return 1; |
2127 | ||
f5143c46 | 2128 | /* We cannot use aliases_everything_p to test MEM, since we must look |
c6df88cb MM |
2129 | at MEM_MODE, rather than GET_MODE (MEM). */ |
2130 | if (mem_mode == QImode || GET_CODE (mem_addr) == AND) | |
a13d4ebf AM |
2131 | return 1; |
2132 | ||
2133 | /* In true_dependence we also allow BLKmode to alias anything. Why | |
2134 | don't we do this in anti_dependence and output_dependence? */ | |
2135 | if (mem_mode == BLKmode || GET_MODE (x) == BLKmode) | |
2136 | return 1; | |
2137 | ||
2138 | return ! fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr, | |
2139 | varies); | |
2140 | } | |
2141 | ||
2142 | /* Canonical true dependence: X is read after store in MEM takes place. | |
ca7fd9cd KH |
2143 | Variant of true_dependence which assumes MEM has already been |
2144 | canonicalized (hence we no longer do that here). | |
2145 | The mem_addr argument has been added, since true_dependence computed | |
a13d4ebf AM |
2146 | this value prior to canonicalizing. */ |
2147 | ||
2148 | int | |
4682ae04 AJ |
2149 | canon_true_dependence (rtx mem, enum machine_mode mem_mode, rtx mem_addr, |
2150 | rtx x, int (*varies) (rtx, int)) | |
a13d4ebf | 2151 | { |
b3694847 | 2152 | rtx x_addr; |
a13d4ebf AM |
2153 | |
2154 | if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem)) | |
2155 | return 1; | |
2156 | ||
0fe854a7 RH |
2157 | /* (mem:BLK (scratch)) is a special mechanism to conflict with everything. |
2158 | This is used in epilogue deallocation functions. */ | |
2159 | if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH) | |
2160 | return 1; | |
2161 | if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH) | |
2162 | return 1; | |
2163 | ||
a13d4ebf AM |
2164 | if (DIFFERENT_ALIAS_SETS_P (x, mem)) |
2165 | return 0; | |
2166 | ||
2167 | /* If X is an unchanging read, then it can't possibly conflict with any | |
2168 | non-unchanging store. It may conflict with an unchanging write though, | |
2169 | because there may be a single store to this address to initialize it. | |
2170 | Just fall through to the code below to resolve the case where we have | |
2171 | both an unchanging read and an unchanging write. This won't handle all | |
2172 | cases optimally, but the possible performance loss should be | |
2173 | negligible. */ | |
2174 | if (RTX_UNCHANGING_P (x) && ! RTX_UNCHANGING_P (mem)) | |
2175 | return 0; | |
2176 | ||
a4311dfe RK |
2177 | if (nonoverlapping_memrefs_p (x, mem)) |
2178 | return 0; | |
2179 | ||
a13d4ebf AM |
2180 | x_addr = get_addr (XEXP (x, 0)); |
2181 | ||
2182 | if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode)) | |
2183 | return 0; | |
2184 | ||
2185 | x_addr = canon_rtx (x_addr); | |
2186 | if (! memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr, | |
2187 | SIZE_FOR_MODE (x), x_addr, 0)) | |
2188 | return 0; | |
2189 | ||
2190 | if (aliases_everything_p (x)) | |
2191 | return 1; | |
2192 | ||
f5143c46 | 2193 | /* We cannot use aliases_everything_p to test MEM, since we must look |
a13d4ebf AM |
2194 | at MEM_MODE, rather than GET_MODE (MEM). */ |
2195 | if (mem_mode == QImode || GET_CODE (mem_addr) == AND) | |
c6df88cb | 2196 | return 1; |
0211b6ab | 2197 | |
c6df88cb MM |
2198 | /* In true_dependence we also allow BLKmode to alias anything. Why |
2199 | don't we do this in anti_dependence and output_dependence? */ | |
2200 | if (mem_mode == BLKmode || GET_MODE (x) == BLKmode) | |
2201 | return 1; | |
0211b6ab | 2202 | |
eab5c70a BS |
2203 | return ! fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr, |
2204 | varies); | |
9ae8ffe7 JL |
2205 | } |
2206 | ||
da7d8304 | 2207 | /* Returns nonzero if a write to X might alias a previous read from |
83a00410 | 2208 | (or, if WRITEP is nonzero, a write to) MEM. If CONSTP is nonzero, |
d2399d75 | 2209 | honor the RTX_UNCHANGING_P flags on X and MEM. */ |
9ae8ffe7 | 2210 | |
2c72b78f | 2211 | static int |
d2399d75 | 2212 | write_dependence_p (rtx mem, rtx x, int writep, int constp) |
9ae8ffe7 | 2213 | { |
6e73e666 | 2214 | rtx x_addr, mem_addr; |
c6df88cb | 2215 | rtx fixed_scalar; |
49982682 | 2216 | rtx base; |
6e73e666 | 2217 | |
9ae8ffe7 JL |
2218 | if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem)) |
2219 | return 1; | |
2220 | ||
c4484b8f RH |
2221 | /* (mem:BLK (scratch)) is a special mechanism to conflict with everything. |
2222 | This is used in epilogue deallocation functions. */ | |
2223 | if (GET_MODE (x) == BLKmode && GET_CODE (XEXP (x, 0)) == SCRATCH) | |
2224 | return 1; | |
2225 | if (GET_MODE (mem) == BLKmode && GET_CODE (XEXP (mem, 0)) == SCRATCH) | |
2226 | return 1; | |
2227 | ||
eab5c70a BS |
2228 | if (DIFFERENT_ALIAS_SETS_P (x, mem)) |
2229 | return 0; | |
2230 | ||
d2399d75 RS |
2231 | if (constp) |
2232 | { | |
2233 | /* Unchanging memory can't conflict with non-unchanging memory. */ | |
2234 | if (RTX_UNCHANGING_P (x) != RTX_UNCHANGING_P (mem)) | |
2235 | return 0; | |
b949ea8b | 2236 | |
d2399d75 RS |
2237 | /* If MEM is an unchanging read, then it can't possibly conflict with |
2238 | the store to X, because there is at most one store to MEM, and it | |
2239 | must have occurred somewhere before MEM. */ | |
2240 | if (! writep && RTX_UNCHANGING_P (mem)) | |
2241 | return 0; | |
2242 | } | |
55efb413 | 2243 | |
a4311dfe RK |
2244 | if (nonoverlapping_memrefs_p (x, mem)) |
2245 | return 0; | |
2246 | ||
55efb413 JW |
2247 | x_addr = get_addr (XEXP (x, 0)); |
2248 | mem_addr = get_addr (XEXP (mem, 0)); | |
2249 | ||
49982682 JW |
2250 | if (! writep) |
2251 | { | |
55efb413 | 2252 | base = find_base_term (mem_addr); |
49982682 JW |
2253 | if (base && (GET_CODE (base) == LABEL_REF |
2254 | || (GET_CODE (base) == SYMBOL_REF | |
2255 | && CONSTANT_POOL_ADDRESS_P (base)))) | |
2256 | return 0; | |
2257 | } | |
2258 | ||
eab5c70a BS |
2259 | if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), |
2260 | GET_MODE (mem))) | |
41472af8 MM |
2261 | return 0; |
2262 | ||
eab5c70a BS |
2263 | x_addr = canon_rtx (x_addr); |
2264 | mem_addr = canon_rtx (mem_addr); | |
6e73e666 | 2265 | |
c6df88cb MM |
2266 | if (!memrefs_conflict_p (SIZE_FOR_MODE (mem), mem_addr, |
2267 | SIZE_FOR_MODE (x), x_addr, 0)) | |
2268 | return 0; | |
2269 | ||
ca7fd9cd | 2270 | fixed_scalar |
eab5c70a BS |
2271 | = fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr, |
2272 | rtx_addr_varies_p); | |
2273 | ||
c6df88cb MM |
2274 | return (!(fixed_scalar == mem && !aliases_everything_p (x)) |
2275 | && !(fixed_scalar == x && !aliases_everything_p (mem))); | |
2276 | } | |
2277 | ||
2278 | /* Anti dependence: X is written after read in MEM takes place. */ | |
2279 | ||
2280 | int | |
4682ae04 | 2281 | anti_dependence (rtx mem, rtx x) |
c6df88cb | 2282 | { |
d2399d75 | 2283 | return write_dependence_p (mem, x, /*writep=*/0, /*constp*/1); |
9ae8ffe7 JL |
2284 | } |
2285 | ||
2286 | /* Output dependence: X is written after store in MEM takes place. */ | |
2287 | ||
2288 | int | |
4682ae04 | 2289 | output_dependence (rtx mem, rtx x) |
9ae8ffe7 | 2290 | { |
d2399d75 RS |
2291 | return write_dependence_p (mem, x, /*writep=*/1, /*constp*/1); |
2292 | } | |
2293 | ||
2294 | /* Unchanging anti dependence: Like anti_dependence but ignores | |
2295 | the UNCHANGING_RTX_P property on const variable references. */ | |
2296 | ||
2297 | int | |
2298 | unchanging_anti_dependence (rtx mem, rtx x) | |
2299 | { | |
2300 | return write_dependence_p (mem, x, /*writep=*/0, /*constp*/0); | |
9ae8ffe7 | 2301 | } |
c14b9960 JW |
2302 | \f |
2303 | /* A subroutine of nonlocal_mentioned_p, returns 1 if *LOC mentions | |
2304 | something which is not local to the function and is not constant. */ | |
7790df19 JW |
2305 | |
2306 | static int | |
4682ae04 | 2307 | nonlocal_mentioned_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED) |
7790df19 | 2308 | { |
c14b9960 | 2309 | rtx x = *loc; |
7790df19 | 2310 | rtx base; |
7790df19 JW |
2311 | int regno; |
2312 | ||
c14b9960 JW |
2313 | if (! x) |
2314 | return 0; | |
7790df19 | 2315 | |
c14b9960 | 2316 | switch (GET_CODE (x)) |
7790df19 JW |
2317 | { |
2318 | case SUBREG: | |
2319 | if (GET_CODE (SUBREG_REG (x)) == REG) | |
2320 | { | |
2321 | /* Global registers are not local. */ | |
2322 | if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER | |
ddef6bc7 | 2323 | && global_regs[subreg_regno (x)]) |
7790df19 JW |
2324 | return 1; |
2325 | return 0; | |
2326 | } | |
2327 | break; | |
2328 | ||
2329 | case REG: | |
2330 | regno = REGNO (x); | |
2331 | /* Global registers are not local. */ | |
2332 | if (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]) | |
2333 | return 1; | |
2334 | return 0; | |
2335 | ||
2336 | case SCRATCH: | |
2337 | case PC: | |
2338 | case CC0: | |
2339 | case CONST_INT: | |
2340 | case CONST_DOUBLE: | |
69ef87e2 | 2341 | case CONST_VECTOR: |
7790df19 JW |
2342 | case CONST: |
2343 | case LABEL_REF: | |
2344 | return 0; | |
2345 | ||
2346 | case SYMBOL_REF: | |
2347 | /* Constants in the function's constants pool are constant. */ | |
2348 | if (CONSTANT_POOL_ADDRESS_P (x)) | |
2349 | return 0; | |
2350 | return 1; | |
2351 | ||
2352 | case CALL: | |
bf6d9fd7 | 2353 | /* Non-constant calls and recursion are not local. */ |
7790df19 JW |
2354 | return 1; |
2355 | ||
2356 | case MEM: | |
2357 | /* Be overly conservative and consider any volatile memory | |
2358 | reference as not local. */ | |
2359 | if (MEM_VOLATILE_P (x)) | |
2360 | return 1; | |
2361 | base = find_base_term (XEXP (x, 0)); | |
2362 | if (base) | |
2363 | { | |
b3b5ad95 JL |
2364 | /* A Pmode ADDRESS could be a reference via the structure value |
2365 | address or static chain. Such memory references are nonlocal. | |
2366 | ||
2367 | Thus, we have to examine the contents of the ADDRESS to find | |
2368 | out if this is a local reference or not. */ | |
2369 | if (GET_CODE (base) == ADDRESS | |
2370 | && GET_MODE (base) == Pmode | |
2371 | && (XEXP (base, 0) == stack_pointer_rtx | |
2372 | || XEXP (base, 0) == arg_pointer_rtx | |
2373 | #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
2374 | || XEXP (base, 0) == hard_frame_pointer_rtx | |
2375 | #endif | |
2376 | || XEXP (base, 0) == frame_pointer_rtx)) | |
7790df19 JW |
2377 | return 0; |
2378 | /* Constants in the function's constant pool are constant. */ | |
2379 | if (GET_CODE (base) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (base)) | |
2380 | return 0; | |
2381 | } | |
2382 | return 1; | |
2383 | ||
bf6d9fd7 | 2384 | case UNSPEC_VOLATILE: |
7790df19 | 2385 | case ASM_INPUT: |
7790df19 JW |
2386 | return 1; |
2387 | ||
bf6d9fd7 JW |
2388 | case ASM_OPERANDS: |
2389 | if (MEM_VOLATILE_P (x)) | |
2390 | return 1; | |
2391 | ||
5d3cc252 | 2392 | /* Fall through. */ |
bf6d9fd7 | 2393 | |
7790df19 JW |
2394 | default: |
2395 | break; | |
2396 | } | |
2397 | ||
c14b9960 JW |
2398 | return 0; |
2399 | } | |
2400 | ||
da7d8304 | 2401 | /* Returns nonzero if X might mention something which is not |
c14b9960 | 2402 | local to the function and is not constant. */ |
7790df19 | 2403 | |
c14b9960 | 2404 | static int |
4682ae04 | 2405 | nonlocal_mentioned_p (rtx x) |
c14b9960 | 2406 | { |
c14b9960 JW |
2407 | if (INSN_P (x)) |
2408 | { | |
2409 | if (GET_CODE (x) == CALL_INSN) | |
2410 | { | |
2411 | if (! CONST_OR_PURE_CALL_P (x)) | |
2412 | return 1; | |
2413 | x = CALL_INSN_FUNCTION_USAGE (x); | |
2414 | if (x == 0) | |
2415 | return 0; | |
ca7fd9cd | 2416 | } |
c14b9960 | 2417 | else |
ca7fd9cd | 2418 | x = PATTERN (x); |
c14b9960 JW |
2419 | } |
2420 | ||
2421 | return for_each_rtx (&x, nonlocal_mentioned_p_1, NULL); | |
2422 | } | |
2423 | ||
2424 | /* A subroutine of nonlocal_referenced_p, returns 1 if *LOC references | |
2425 | something which is not local to the function and is not constant. */ | |
2426 | ||
2427 | static int | |
4682ae04 | 2428 | nonlocal_referenced_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED) |
c14b9960 JW |
2429 | { |
2430 | rtx x = *loc; | |
2431 | ||
2432 | if (! x) | |
2433 | return 0; | |
2434 | ||
2435 | switch (GET_CODE (x)) | |
2436 | { | |
2437 | case MEM: | |
2438 | case REG: | |
2439 | case SYMBOL_REF: | |
2440 | case SUBREG: | |
2441 | return nonlocal_mentioned_p (x); | |
2442 | ||
2443 | case CALL: | |
2444 | /* Non-constant calls and recursion are not local. */ | |
2445 | return 1; | |
2446 | ||
2447 | case SET: | |
2448 | if (nonlocal_mentioned_p (SET_SRC (x))) | |
2449 | return 1; | |
2450 | ||
2451 | if (GET_CODE (SET_DEST (x)) == MEM) | |
2452 | return nonlocal_mentioned_p (XEXP (SET_DEST (x), 0)); | |
2453 | ||
2454 | /* If the destination is anything other than a CC0, PC, | |
2455 | MEM, REG, or a SUBREG of a REG that occupies all of | |
2456 | the REG, then X references nonlocal memory if it is | |
2457 | mentioned in the destination. */ | |
2458 | if (GET_CODE (SET_DEST (x)) != CC0 | |
2459 | && GET_CODE (SET_DEST (x)) != PC | |
2460 | && GET_CODE (SET_DEST (x)) != REG | |
2461 | && ! (GET_CODE (SET_DEST (x)) == SUBREG | |
2462 | && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG | |
2463 | && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x)))) | |
2464 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) | |
2465 | == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x))) | |
2466 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))) | |
2467 | return nonlocal_mentioned_p (SET_DEST (x)); | |
2468 | return 0; | |
2469 | ||
2470 | case CLOBBER: | |
2471 | if (GET_CODE (XEXP (x, 0)) == MEM) | |
2472 | return nonlocal_mentioned_p (XEXP (XEXP (x, 0), 0)); | |
2473 | return 0; | |
2474 | ||
2475 | case USE: | |
2476 | return nonlocal_mentioned_p (XEXP (x, 0)); | |
2477 | ||
2478 | case ASM_INPUT: | |
2479 | case UNSPEC_VOLATILE: | |
2480 | return 1; | |
2481 | ||
2482 | case ASM_OPERANDS: | |
2483 | if (MEM_VOLATILE_P (x)) | |
2484 | return 1; | |
2485 | ||
5d3cc252 | 2486 | /* Fall through. */ |
c14b9960 JW |
2487 | |
2488 | default: | |
2489 | break; | |
2490 | } | |
2491 | ||
2492 | return 0; | |
2493 | } | |
2494 | ||
da7d8304 | 2495 | /* Returns nonzero if X might reference something which is not |
c14b9960 JW |
2496 | local to the function and is not constant. */ |
2497 | ||
2498 | static int | |
4682ae04 | 2499 | nonlocal_referenced_p (rtx x) |
c14b9960 | 2500 | { |
c14b9960 JW |
2501 | if (INSN_P (x)) |
2502 | { | |
2503 | if (GET_CODE (x) == CALL_INSN) | |
2504 | { | |
2505 | if (! CONST_OR_PURE_CALL_P (x)) | |
2506 | return 1; | |
2507 | x = CALL_INSN_FUNCTION_USAGE (x); | |
2508 | if (x == 0) | |
2509 | return 0; | |
ca7fd9cd | 2510 | } |
c14b9960 | 2511 | else |
ca7fd9cd | 2512 | x = PATTERN (x); |
c14b9960 JW |
2513 | } |
2514 | ||
2515 | return for_each_rtx (&x, nonlocal_referenced_p_1, NULL); | |
2516 | } | |
2517 | ||
2518 | /* A subroutine of nonlocal_set_p, returns 1 if *LOC sets | |
2519 | something which is not local to the function and is not constant. */ | |
2520 | ||
2521 | static int | |
4682ae04 | 2522 | nonlocal_set_p_1 (rtx *loc, void *data ATTRIBUTE_UNUSED) |
c14b9960 JW |
2523 | { |
2524 | rtx x = *loc; | |
2525 | ||
2526 | if (! x) | |
2527 | return 0; | |
2528 | ||
2529 | switch (GET_CODE (x)) | |
2530 | { | |
2531 | case CALL: | |
2532 | /* Non-constant calls and recursion are not local. */ | |
2533 | return 1; | |
2534 | ||
2535 | case PRE_INC: | |
2536 | case PRE_DEC: | |
2537 | case POST_INC: | |
2538 | case POST_DEC: | |
2539 | case PRE_MODIFY: | |
2540 | case POST_MODIFY: | |
2541 | return nonlocal_mentioned_p (XEXP (x, 0)); | |
2542 | ||
2543 | case SET: | |
2544 | if (nonlocal_mentioned_p (SET_DEST (x))) | |
2545 | return 1; | |
2546 | return nonlocal_set_p (SET_SRC (x)); | |
2547 | ||
2548 | case CLOBBER: | |
2549 | return nonlocal_mentioned_p (XEXP (x, 0)); | |
2550 | ||
2551 | case USE: | |
2552 | return 0; | |
2553 | ||
2554 | case ASM_INPUT: | |
2555 | case UNSPEC_VOLATILE: | |
2556 | return 1; | |
2557 | ||
2558 | case ASM_OPERANDS: | |
2559 | if (MEM_VOLATILE_P (x)) | |
2560 | return 1; | |
2561 | ||
5d3cc252 | 2562 | /* Fall through. */ |
c14b9960 JW |
2563 | |
2564 | default: | |
2565 | break; | |
2566 | } | |
7790df19 JW |
2567 | |
2568 | return 0; | |
2569 | } | |
2570 | ||
da7d8304 | 2571 | /* Returns nonzero if X might set something which is not |
c14b9960 JW |
2572 | local to the function and is not constant. */ |
2573 | ||
2574 | static int | |
4682ae04 | 2575 | nonlocal_set_p (rtx x) |
c14b9960 | 2576 | { |
c14b9960 JW |
2577 | if (INSN_P (x)) |
2578 | { | |
2579 | if (GET_CODE (x) == CALL_INSN) | |
2580 | { | |
2581 | if (! CONST_OR_PURE_CALL_P (x)) | |
2582 | return 1; | |
2583 | x = CALL_INSN_FUNCTION_USAGE (x); | |
2584 | if (x == 0) | |
2585 | return 0; | |
ca7fd9cd | 2586 | } |
c14b9960 | 2587 | else |
ca7fd9cd | 2588 | x = PATTERN (x); |
c14b9960 JW |
2589 | } |
2590 | ||
2591 | return for_each_rtx (&x, nonlocal_set_p_1, NULL); | |
2592 | } | |
2593 | ||
c57ddcf1 | 2594 | /* Mark the function if it is pure or constant. */ |
7790df19 JW |
2595 | |
2596 | void | |
4682ae04 | 2597 | mark_constant_function (void) |
7790df19 JW |
2598 | { |
2599 | rtx insn; | |
c14b9960 | 2600 | int nonlocal_memory_referenced; |
7790df19 | 2601 | |
ab780373 | 2602 | if (TREE_READONLY (current_function_decl) |
bf6d9fd7 | 2603 | || DECL_IS_PURE (current_function_decl) |
7790df19 | 2604 | || TREE_THIS_VOLATILE (current_function_decl) |
ab780373 RH |
2605 | || current_function_has_nonlocal_goto |
2606 | || !(*targetm.binds_local_p) (current_function_decl)) | |
7790df19 JW |
2607 | return; |
2608 | ||
e004f2f7 | 2609 | /* A loop might not return which counts as a side effect. */ |
0ecf09f9 | 2610 | if (mark_dfs_back_edges ()) |
e004f2f7 JW |
2611 | return; |
2612 | ||
c14b9960 | 2613 | nonlocal_memory_referenced = 0; |
bf6d9fd7 JW |
2614 | |
2615 | init_alias_analysis (); | |
2616 | ||
c14b9960 | 2617 | /* Determine if this is a constant or pure function. */ |
7790df19 JW |
2618 | |
2619 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
c14b9960 JW |
2620 | { |
2621 | if (! INSN_P (insn)) | |
2622 | continue; | |
bf6d9fd7 | 2623 | |
c14b9960 JW |
2624 | if (nonlocal_set_p (insn) || global_reg_mentioned_p (insn) |
2625 | || volatile_refs_p (PATTERN (insn))) | |
ca7fd9cd | 2626 | break; |
7790df19 | 2627 | |
c14b9960 JW |
2628 | if (! nonlocal_memory_referenced) |
2629 | nonlocal_memory_referenced = nonlocal_referenced_p (insn); | |
2630 | } | |
ca7fd9cd | 2631 | |
c14b9960 | 2632 | end_alias_analysis (); |
ca7fd9cd | 2633 | |
7790df19 | 2634 | /* Mark the function. */ |
ca7fd9cd | 2635 | |
c14b9960 JW |
2636 | if (insn) |
2637 | ; | |
2638 | else if (nonlocal_memory_referenced) | |
c57ddcf1 RS |
2639 | { |
2640 | cgraph_rtl_info (current_function_decl)->pure_function = 1; | |
2641 | DECL_IS_PURE (current_function_decl) = 1; | |
2642 | } | |
c14b9960 | 2643 | else |
c57ddcf1 RS |
2644 | { |
2645 | cgraph_rtl_info (current_function_decl)->const_function = 1; | |
2646 | TREE_READONLY (current_function_decl) = 1; | |
2647 | } | |
7790df19 | 2648 | } |
c14b9960 | 2649 | \f |
6e73e666 | 2650 | |
6e73e666 | 2651 | void |
4682ae04 | 2652 | init_alias_once (void) |
6e73e666 | 2653 | { |
b3694847 | 2654 | int i; |
6e73e666 JC |
2655 | |
2656 | #ifndef OUTGOING_REGNO | |
2657 | #define OUTGOING_REGNO(N) N | |
2658 | #endif | |
2659 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
2660 | /* Check whether this register can hold an incoming pointer | |
2661 | argument. FUNCTION_ARG_REGNO_P tests outgoing register | |
ec5c56db | 2662 | numbers, so translate if necessary due to register windows. */ |
6e73e666 JC |
2663 | if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i)) |
2664 | && HARD_REGNO_MODE_OK (i, Pmode)) | |
bf1660a6 JL |
2665 | static_reg_base_value[i] |
2666 | = gen_rtx_ADDRESS (VOIDmode, gen_rtx_REG (Pmode, i)); | |
2667 | ||
bf1660a6 JL |
2668 | static_reg_base_value[STACK_POINTER_REGNUM] |
2669 | = gen_rtx_ADDRESS (Pmode, stack_pointer_rtx); | |
2670 | static_reg_base_value[ARG_POINTER_REGNUM] | |
2671 | = gen_rtx_ADDRESS (Pmode, arg_pointer_rtx); | |
2672 | static_reg_base_value[FRAME_POINTER_REGNUM] | |
2673 | = gen_rtx_ADDRESS (Pmode, frame_pointer_rtx); | |
2674 | #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
2675 | static_reg_base_value[HARD_FRAME_POINTER_REGNUM] | |
2676 | = gen_rtx_ADDRESS (Pmode, hard_frame_pointer_rtx); | |
2677 | #endif | |
2678 | } | |
2679 | ||
7b52eede JH |
2680 | /* Set MEMORY_MODIFIED when X modifies DATA (that is assumed |
2681 | to be memory reference. */ | |
2682 | static bool memory_modified; | |
2683 | static void | |
4682ae04 | 2684 | memory_modified_1 (rtx x, rtx pat ATTRIBUTE_UNUSED, void *data) |
7b52eede JH |
2685 | { |
2686 | if (GET_CODE (x) == MEM) | |
2687 | { | |
2688 | if (anti_dependence (x, (rtx)data) || output_dependence (x, (rtx)data)) | |
2689 | memory_modified = true; | |
2690 | } | |
2691 | } | |
2692 | ||
2693 | ||
2694 | /* Return true when INSN possibly modify memory contents of MEM | |
2695 | (ie address can be modified). */ | |
2696 | bool | |
4682ae04 | 2697 | memory_modified_in_insn_p (rtx mem, rtx insn) |
7b52eede JH |
2698 | { |
2699 | if (!INSN_P (insn)) | |
2700 | return false; | |
2701 | memory_modified = false; | |
2702 | note_stores (PATTERN (insn), memory_modified_1, mem); | |
2703 | return memory_modified; | |
2704 | } | |
2705 | ||
c13e8210 MM |
2706 | /* Initialize the aliasing machinery. Initialize the REG_KNOWN_VALUE |
2707 | array. */ | |
2708 | ||
9ae8ffe7 | 2709 | void |
4682ae04 | 2710 | init_alias_analysis (void) |
9ae8ffe7 JL |
2711 | { |
2712 | int maxreg = max_reg_num (); | |
ea64ef27 | 2713 | int changed, pass; |
b3694847 SS |
2714 | int i; |
2715 | unsigned int ui; | |
2716 | rtx insn; | |
9ae8ffe7 | 2717 | |
0d446150 JH |
2718 | timevar_push (TV_ALIAS_ANALYSIS); |
2719 | ||
9ae8ffe7 JL |
2720 | reg_known_value_size = maxreg; |
2721 | ||
ca7fd9cd | 2722 | reg_known_value |
e05e2395 MM |
2723 | = (rtx *) xcalloc ((maxreg - FIRST_PSEUDO_REGISTER), sizeof (rtx)) |
2724 | - FIRST_PSEUDO_REGISTER; | |
ca7fd9cd | 2725 | reg_known_equiv_p |
e05e2395 | 2726 | = (char*) xcalloc ((maxreg - FIRST_PSEUDO_REGISTER), sizeof (char)) |
9ae8ffe7 | 2727 | - FIRST_PSEUDO_REGISTER; |
9ae8ffe7 | 2728 | |
6e73e666 JC |
2729 | /* Overallocate reg_base_value to allow some growth during loop |
2730 | optimization. Loop unrolling can create a large number of | |
2731 | registers. */ | |
2732 | reg_base_value_size = maxreg * 2; | |
703ad42b | 2733 | reg_base_value = ggc_alloc_cleared (reg_base_value_size * sizeof (rtx)); |
ac606739 | 2734 | |
703ad42b KG |
2735 | new_reg_base_value = xmalloc (reg_base_value_size * sizeof (rtx)); |
2736 | reg_seen = xmalloc (reg_base_value_size); | |
b17d5d7c | 2737 | if (! reload_completed && flag_old_unroll_loops) |
de12be17 | 2738 | { |
ac606739 | 2739 | /* ??? Why are we realloc'ing if we're just going to zero it? */ |
703ad42b KG |
2740 | alias_invariant = xrealloc (alias_invariant, |
2741 | reg_base_value_size * sizeof (rtx)); | |
2742 | memset (alias_invariant, 0, reg_base_value_size * sizeof (rtx)); | |
de12be17 | 2743 | } |
ec907dd8 JL |
2744 | |
2745 | /* The basic idea is that each pass through this loop will use the | |
2746 | "constant" information from the previous pass to propagate alias | |
2747 | information through another level of assignments. | |
2748 | ||
2749 | This could get expensive if the assignment chains are long. Maybe | |
2750 | we should throttle the number of iterations, possibly based on | |
6e73e666 | 2751 | the optimization level or flag_expensive_optimizations. |
ec907dd8 JL |
2752 | |
2753 | We could propagate more information in the first pass by making use | |
2754 | of REG_N_SETS to determine immediately that the alias information | |
ea64ef27 JL |
2755 | for a pseudo is "constant". |
2756 | ||
2757 | A program with an uninitialized variable can cause an infinite loop | |
2758 | here. Instead of doing a full dataflow analysis to detect such problems | |
2759 | we just cap the number of iterations for the loop. | |
2760 | ||
2761 | The state of the arrays for the set chain in question does not matter | |
2762 | since the program has undefined behavior. */ | |
6e73e666 | 2763 | |
ea64ef27 | 2764 | pass = 0; |
6e73e666 | 2765 | do |
ec907dd8 JL |
2766 | { |
2767 | /* Assume nothing will change this iteration of the loop. */ | |
2768 | changed = 0; | |
2769 | ||
ec907dd8 JL |
2770 | /* We want to assign the same IDs each iteration of this loop, so |
2771 | start counting from zero each iteration of the loop. */ | |
2772 | unique_id = 0; | |
2773 | ||
f5143c46 | 2774 | /* We're at the start of the function each iteration through the |
ec907dd8 | 2775 | loop, so we're copying arguments. */ |
83bbd9b6 | 2776 | copying_arguments = true; |
9ae8ffe7 | 2777 | |
6e73e666 | 2778 | /* Wipe the potential alias information clean for this pass. */ |
703ad42b | 2779 | memset (new_reg_base_value, 0, reg_base_value_size * sizeof (rtx)); |
8072f69c | 2780 | |
6e73e666 | 2781 | /* Wipe the reg_seen array clean. */ |
703ad42b | 2782 | memset (reg_seen, 0, reg_base_value_size); |
9ae8ffe7 | 2783 | |
6e73e666 JC |
2784 | /* Mark all hard registers which may contain an address. |
2785 | The stack, frame and argument pointers may contain an address. | |
2786 | An argument register which can hold a Pmode value may contain | |
2787 | an address even if it is not in BASE_REGS. | |
8072f69c | 2788 | |
6e73e666 JC |
2789 | The address expression is VOIDmode for an argument and |
2790 | Pmode for other registers. */ | |
2791 | ||
7f243674 JL |
2792 | memcpy (new_reg_base_value, static_reg_base_value, |
2793 | FIRST_PSEUDO_REGISTER * sizeof (rtx)); | |
6e73e666 | 2794 | |
ec907dd8 JL |
2795 | /* Walk the insns adding values to the new_reg_base_value array. */ |
2796 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
9ae8ffe7 | 2797 | { |
2c3c49de | 2798 | if (INSN_P (insn)) |
ec907dd8 | 2799 | { |
6e73e666 | 2800 | rtx note, set; |
efc9bd41 RK |
2801 | |
2802 | #if defined (HAVE_prologue) || defined (HAVE_epilogue) | |
f5143c46 | 2803 | /* The prologue/epilogue insns are not threaded onto the |
657959ca JL |
2804 | insn chain until after reload has completed. Thus, |
2805 | there is no sense wasting time checking if INSN is in | |
2806 | the prologue/epilogue until after reload has completed. */ | |
2807 | if (reload_completed | |
2808 | && prologue_epilogue_contains (insn)) | |
efc9bd41 RK |
2809 | continue; |
2810 | #endif | |
2811 | ||
ec907dd8 JL |
2812 | /* If this insn has a noalias note, process it, Otherwise, |
2813 | scan for sets. A simple set will have no side effects | |
ec5c56db | 2814 | which could change the base value of any other register. */ |
6e73e666 | 2815 | |
ec907dd8 | 2816 | if (GET_CODE (PATTERN (insn)) == SET |
efc9bd41 RK |
2817 | && REG_NOTES (insn) != 0 |
2818 | && find_reg_note (insn, REG_NOALIAS, NULL_RTX)) | |
84832317 | 2819 | record_set (SET_DEST (PATTERN (insn)), NULL_RTX, NULL); |
ec907dd8 | 2820 | else |
84832317 | 2821 | note_stores (PATTERN (insn), record_set, NULL); |
6e73e666 JC |
2822 | |
2823 | set = single_set (insn); | |
2824 | ||
2825 | if (set != 0 | |
2826 | && GET_CODE (SET_DEST (set)) == REG | |
fb6754f0 | 2827 | && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER) |
6e73e666 | 2828 | { |
fb6754f0 | 2829 | unsigned int regno = REGNO (SET_DEST (set)); |
713f41f9 BS |
2830 | rtx src = SET_SRC (set); |
2831 | ||
2832 | if (REG_NOTES (insn) != 0 | |
2833 | && (((note = find_reg_note (insn, REG_EQUAL, 0)) != 0 | |
2834 | && REG_N_SETS (regno) == 1) | |
2835 | || (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != 0) | |
2836 | && GET_CODE (XEXP (note, 0)) != EXPR_LIST | |
bb2cf916 | 2837 | && ! rtx_varies_p (XEXP (note, 0), 1) |
713f41f9 BS |
2838 | && ! reg_overlap_mentioned_p (SET_DEST (set), XEXP (note, 0))) |
2839 | { | |
2840 | reg_known_value[regno] = XEXP (note, 0); | |
2841 | reg_known_equiv_p[regno] = REG_NOTE_KIND (note) == REG_EQUIV; | |
2842 | } | |
2843 | else if (REG_N_SETS (regno) == 1 | |
2844 | && GET_CODE (src) == PLUS | |
2845 | && GET_CODE (XEXP (src, 0)) == REG | |
fb6754f0 BS |
2846 | && REGNO (XEXP (src, 0)) >= FIRST_PSEUDO_REGISTER |
2847 | && (reg_known_value[REGNO (XEXP (src, 0))]) | |
713f41f9 BS |
2848 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
2849 | { | |
2850 | rtx op0 = XEXP (src, 0); | |
bb2cf916 | 2851 | op0 = reg_known_value[REGNO (op0)]; |
713f41f9 | 2852 | reg_known_value[regno] |
ed8908e7 | 2853 | = plus_constant (op0, INTVAL (XEXP (src, 1))); |
713f41f9 BS |
2854 | reg_known_equiv_p[regno] = 0; |
2855 | } | |
2856 | else if (REG_N_SETS (regno) == 1 | |
2857 | && ! rtx_varies_p (src, 1)) | |
2858 | { | |
2859 | reg_known_value[regno] = src; | |
2860 | reg_known_equiv_p[regno] = 0; | |
2861 | } | |
6e73e666 | 2862 | } |
ec907dd8 JL |
2863 | } |
2864 | else if (GET_CODE (insn) == NOTE | |
2865 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG) | |
83bbd9b6 | 2866 | copying_arguments = false; |
6e73e666 | 2867 | } |
ec907dd8 | 2868 | |
6e73e666 | 2869 | /* Now propagate values from new_reg_base_value to reg_base_value. */ |
e51712db | 2870 | for (ui = 0; ui < reg_base_value_size; ui++) |
6e73e666 | 2871 | { |
e51712db KG |
2872 | if (new_reg_base_value[ui] |
2873 | && new_reg_base_value[ui] != reg_base_value[ui] | |
2874 | && ! rtx_equal_p (new_reg_base_value[ui], reg_base_value[ui])) | |
ec907dd8 | 2875 | { |
e51712db | 2876 | reg_base_value[ui] = new_reg_base_value[ui]; |
6e73e666 | 2877 | changed = 1; |
ec907dd8 | 2878 | } |
9ae8ffe7 | 2879 | } |
9ae8ffe7 | 2880 | } |
6e73e666 | 2881 | while (changed && ++pass < MAX_ALIAS_LOOP_PASSES); |
9ae8ffe7 JL |
2882 | |
2883 | /* Fill in the remaining entries. */ | |
2884 | for (i = FIRST_PSEUDO_REGISTER; i < maxreg; i++) | |
2885 | if (reg_known_value[i] == 0) | |
2886 | reg_known_value[i] = regno_reg_rtx[i]; | |
2887 | ||
9ae8ffe7 JL |
2888 | /* Simplify the reg_base_value array so that no register refers to |
2889 | another register, except to special registers indirectly through | |
2890 | ADDRESS expressions. | |
2891 | ||
2892 | In theory this loop can take as long as O(registers^2), but unless | |
2893 | there are very long dependency chains it will run in close to linear | |
ea64ef27 JL |
2894 | time. |
2895 | ||
2896 | This loop may not be needed any longer now that the main loop does | |
2897 | a better job at propagating alias information. */ | |
2898 | pass = 0; | |
9ae8ffe7 JL |
2899 | do |
2900 | { | |
2901 | changed = 0; | |
ea64ef27 | 2902 | pass++; |
e51712db | 2903 | for (ui = 0; ui < reg_base_value_size; ui++) |
9ae8ffe7 | 2904 | { |
e51712db | 2905 | rtx base = reg_base_value[ui]; |
9ae8ffe7 JL |
2906 | if (base && GET_CODE (base) == REG) |
2907 | { | |
fb6754f0 | 2908 | unsigned int base_regno = REGNO (base); |
e51712db KG |
2909 | if (base_regno == ui) /* register set from itself */ |
2910 | reg_base_value[ui] = 0; | |
9ae8ffe7 | 2911 | else |
e51712db | 2912 | reg_base_value[ui] = reg_base_value[base_regno]; |
9ae8ffe7 JL |
2913 | changed = 1; |
2914 | } | |
2915 | } | |
2916 | } | |
ea64ef27 | 2917 | while (changed && pass < MAX_ALIAS_LOOP_PASSES); |
9ae8ffe7 | 2918 | |
e05e2395 MM |
2919 | /* Clean up. */ |
2920 | free (new_reg_base_value); | |
ec907dd8 | 2921 | new_reg_base_value = 0; |
e05e2395 | 2922 | free (reg_seen); |
9ae8ffe7 | 2923 | reg_seen = 0; |
0d446150 | 2924 | timevar_pop (TV_ALIAS_ANALYSIS); |
9ae8ffe7 JL |
2925 | } |
2926 | ||
2927 | void | |
4682ae04 | 2928 | end_alias_analysis (void) |
9ae8ffe7 | 2929 | { |
e05e2395 | 2930 | free (reg_known_value + FIRST_PSEUDO_REGISTER); |
9ae8ffe7 | 2931 | reg_known_value = 0; |
ac606739 | 2932 | reg_known_value_size = 0; |
e05e2395 MM |
2933 | free (reg_known_equiv_p + FIRST_PSEUDO_REGISTER); |
2934 | reg_known_equiv_p = 0; | |
e2500fed | 2935 | reg_base_value = 0; |
9ae8ffe7 | 2936 | reg_base_value_size = 0; |
de12be17 JC |
2937 | if (alias_invariant) |
2938 | { | |
ac606739 | 2939 | free (alias_invariant); |
de12be17 JC |
2940 | alias_invariant = 0; |
2941 | } | |
9ae8ffe7 | 2942 | } |
e2500fed GK |
2943 | |
2944 | #include "gt-alias.h" |