1 /* Common subexpression elimination library for GNU compiler.
2 Copyright (C) 1987-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
34 #include "function-abi.h"
37 /* A list of cselib_val structures. */
40 struct elt_list
*next
;
44 static bool cselib_record_memory
;
45 static bool cselib_preserve_constants
;
46 static bool cselib_any_perm_equivs
;
47 static inline void promote_debug_loc (struct elt_loc_list
*l
);
48 static struct elt_list
*new_elt_list (struct elt_list
*, cselib_val
*);
49 static void new_elt_loc_list (cselib_val
*, rtx
);
50 static void unchain_one_value (cselib_val
*);
51 static void unchain_one_elt_list (struct elt_list
**);
52 static void unchain_one_elt_loc_list (struct elt_loc_list
**);
53 static void remove_useless_values (void);
54 static unsigned int cselib_hash_rtx (rtx
, int, machine_mode
);
55 static cselib_val
*new_cselib_val (unsigned int, machine_mode
, rtx
);
56 static void add_mem_for_addr (cselib_val
*, cselib_val
*, rtx
);
57 static cselib_val
*cselib_lookup_mem (rtx
, int);
58 static void cselib_invalidate_regno (unsigned int, machine_mode
);
59 static void cselib_invalidate_mem (rtx
);
60 static void cselib_record_set (rtx
, cselib_val
*, cselib_val
*);
61 static void cselib_record_sets (rtx_insn
*);
62 static rtx
autoinc_split (rtx
, rtx
*, machine_mode
);
64 #define PRESERVED_VALUE_P(RTX) \
65 (RTL_FLAG_CHECK1 ("PRESERVED_VALUE_P", (RTX), VALUE)->unchanging)
67 #define SP_BASED_VALUE_P(RTX) \
68 (RTL_FLAG_CHECK1 ("SP_BASED_VALUE_P", (RTX), VALUE)->jump)
70 #define SP_DERIVED_VALUE_P(RTX) \
71 (RTL_FLAG_CHECK1 ("SP_DERIVED_VALUE_P", (RTX), VALUE)->call)
73 struct expand_value_data
76 cselib_expand_callback callback
;
81 static rtx
cselib_expand_value_rtx_1 (rtx
, struct expand_value_data
*, int);
83 /* There are three ways in which cselib can look up an rtx:
84 - for a REG, the reg_values table (which is indexed by regno) is used
85 - for a MEM, we recursively look up its address and then follow the
86 addr_list of that value
87 - for everything else, we compute a hash value and go through the hash
88 table. Since different rtx's can still have the same hash value,
89 this involves walking the table entries for a given value and comparing
90 the locations of the entries with the rtx we are looking up. */
92 struct cselib_hasher
: nofree_ptr_hash
<cselib_val
>
95 /* The rtx value and its mode (needed separately for constant
99 /* The mode of the contaning MEM, if any, otherwise VOIDmode. */
100 machine_mode memmode
;
102 typedef key
*compare_type
;
103 static inline hashval_t
hash (const cselib_val
*);
104 static inline bool equal (const cselib_val
*, const key
*);
107 /* The hash function for our hash table. The value is always computed with
108 cselib_hash_rtx when adding an element; this function just extracts the
109 hash value from a cselib_val structure. */
112 cselib_hasher::hash (const cselib_val
*v
)
117 /* The equality test for our hash table. The first argument V is a table
118 element (i.e. a cselib_val), while the second arg X is an rtx. We know
119 that all callers of htab_find_slot_with_hash will wrap CONST_INTs into a
120 CONST of an appropriate mode. */
123 cselib_hasher::equal (const cselib_val
*v
, const key
*x_arg
)
125 struct elt_loc_list
*l
;
127 machine_mode mode
= x_arg
->mode
;
128 machine_mode memmode
= x_arg
->memmode
;
130 if (mode
!= GET_MODE (v
->val_rtx
))
133 if (GET_CODE (x
) == VALUE
)
134 return x
== v
->val_rtx
;
136 if (SP_DERIVED_VALUE_P (v
->val_rtx
) && GET_MODE (x
) == Pmode
)
139 if (autoinc_split (x
, &xoff
, memmode
) == v
->val_rtx
&& xoff
== NULL_RTX
)
143 /* We don't guarantee that distinct rtx's have different hash values,
144 so we need to do a comparison. */
145 for (l
= v
->locs
; l
; l
= l
->next
)
146 if (rtx_equal_for_cselib_1 (l
->loc
, x
, memmode
, 0))
148 promote_debug_loc (l
);
155 /* A table that enables us to look up elts by their value. */
156 static hash_table
<cselib_hasher
> *cselib_hash_table
;
158 /* A table to hold preserved values. */
159 static hash_table
<cselib_hasher
> *cselib_preserved_hash_table
;
161 /* This is a global so we don't have to pass this through every function.
162 It is used in new_elt_loc_list to set SETTING_INSN. */
163 static rtx_insn
*cselib_current_insn
;
165 /* The unique id that the next create value will take. */
166 static unsigned int next_uid
;
168 /* The number of registers we had when the varrays were last resized. */
169 static unsigned int cselib_nregs
;
171 /* Count values without known locations, or with only locations that
172 wouldn't have been known except for debug insns. Whenever this
173 grows too big, we remove these useless values from the table.
175 Counting values with only debug values is a bit tricky. We don't
176 want to increment n_useless_values when we create a value for a
177 debug insn, for this would get n_useless_values out of sync, but we
178 want increment it if all locs in the list that were ever referenced
179 in nondebug insns are removed from the list.
181 In the general case, once we do that, we'd have to stop accepting
182 nondebug expressions in the loc list, to avoid having two values
183 equivalent that, without debug insns, would have been made into
184 separate values. However, because debug insns never introduce
185 equivalences themselves (no assignments), the only means for
186 growing loc lists is through nondebug assignments. If the locs
187 also happen to be referenced in debug insns, it will work just fine.
189 A consequence of this is that there's at most one debug-only loc in
190 each loc list. If we keep it in the first entry, testing whether
191 we have a debug-only loc list takes O(1).
193 Furthermore, since any additional entry in a loc list containing a
194 debug loc would have to come from an assignment (nondebug) that
195 references both the initial debug loc and the newly-equivalent loc,
196 the initial debug loc would be promoted to a nondebug loc, and the
197 loc list would not contain debug locs any more.
199 So the only case we have to be careful with in order to keep
200 n_useless_values in sync between debug and nondebug compilations is
201 to avoid incrementing n_useless_values when removing the single loc
202 from a value that turns out to not appear outside debug values. We
203 increment n_useless_debug_values instead, and leave such values
204 alone until, for other reasons, we garbage-collect useless
206 static int n_useless_values
;
207 static int n_useless_debug_values
;
209 /* Count values whose locs have been taken exclusively from debug
210 insns for the entire life of the value. */
211 static int n_debug_values
;
213 /* Number of useless values before we remove them from the hash table. */
214 #define MAX_USELESS_VALUES 32
216 /* This table maps from register number to values. It does not
217 contain pointers to cselib_val structures, but rather elt_lists.
218 The purpose is to be able to refer to the same register in
219 different modes. The first element of the list defines the mode in
220 which the register was set; if the mode is unknown or the value is
221 no longer valid in that mode, ELT will be NULL for the first
223 static struct elt_list
**reg_values
;
224 static unsigned int reg_values_size
;
225 #define REG_VALUES(i) reg_values[i]
227 /* The largest number of hard regs used by any entry added to the
228 REG_VALUES table. Cleared on each cselib_clear_table() invocation. */
229 static unsigned int max_value_regs
;
231 /* Here the set of indices I with REG_VALUES(I) != 0 is saved. This is used
232 in cselib_clear_table() for fast emptying. */
233 static unsigned int *used_regs
;
234 static unsigned int n_used_regs
;
236 /* We pass this to cselib_invalidate_mem to invalidate all of
237 memory for a non-const call instruction. */
238 static GTY(()) rtx callmem
;
240 /* Set by discard_useless_locs if it deleted the last location of any
242 static int values_became_useless
;
244 /* Used as stop element of the containing_mem list so we can check
245 presence in the list by checking the next pointer. */
246 static cselib_val dummy_val
;
248 /* If non-NULL, value of the eliminated arg_pointer_rtx or frame_pointer_rtx
249 that is constant through the whole function and should never be
251 static cselib_val
*cfa_base_preserved_val
;
252 static unsigned int cfa_base_preserved_regno
= INVALID_REGNUM
;
254 /* Used to list all values that contain memory reference.
255 May or may not contain the useless values - the list is compacted
256 each time memory is invalidated. */
257 static cselib_val
*first_containing_mem
= &dummy_val
;
259 static object_allocator
<elt_list
> elt_list_pool ("elt_list");
260 static object_allocator
<elt_loc_list
> elt_loc_list_pool ("elt_loc_list");
261 static object_allocator
<cselib_val
> cselib_val_pool ("cselib_val_list");
263 static pool_allocator
value_pool ("value", RTX_CODE_SIZE (VALUE
));
265 /* If nonnull, cselib will call this function before freeing useless
266 VALUEs. A VALUE is deemed useless if its "locs" field is null. */
267 void (*cselib_discard_hook
) (cselib_val
*);
269 /* If nonnull, cselib will call this function before recording sets or
270 even clobbering outputs of INSN. All the recorded sets will be
271 represented in the array sets[n_sets]. new_val_min can be used to
272 tell whether values present in sets are introduced by this
274 void (*cselib_record_sets_hook
) (rtx_insn
*insn
, struct cselib_set
*sets
,
279 /* Allocate a struct elt_list and fill in its two elements with the
282 static inline struct elt_list
*
283 new_elt_list (struct elt_list
*next
, cselib_val
*elt
)
285 elt_list
*el
= elt_list_pool
.allocate ();
291 /* Allocate a struct elt_loc_list with LOC and prepend it to VAL's loc
295 new_elt_loc_list (cselib_val
*val
, rtx loc
)
297 struct elt_loc_list
*el
, *next
= val
->locs
;
299 gcc_checking_assert (!next
|| !next
->setting_insn
300 || !DEBUG_INSN_P (next
->setting_insn
)
301 || cselib_current_insn
== next
->setting_insn
);
303 /* If we're creating the first loc in a debug insn context, we've
304 just created a debug value. Count it. */
305 if (!next
&& cselib_current_insn
&& DEBUG_INSN_P (cselib_current_insn
))
308 val
= canonical_cselib_val (val
);
311 if (GET_CODE (loc
) == VALUE
)
313 loc
= canonical_cselib_val (CSELIB_VAL_PTR (loc
))->val_rtx
;
315 gcc_checking_assert (PRESERVED_VALUE_P (loc
)
316 == PRESERVED_VALUE_P (val
->val_rtx
));
318 if (val
->val_rtx
== loc
)
320 else if (val
->uid
> CSELIB_VAL_PTR (loc
)->uid
)
322 /* Reverse the insertion. */
323 new_elt_loc_list (CSELIB_VAL_PTR (loc
), val
->val_rtx
);
327 gcc_checking_assert (val
->uid
< CSELIB_VAL_PTR (loc
)->uid
);
329 if (CSELIB_VAL_PTR (loc
)->locs
)
331 /* Bring all locs from LOC to VAL. */
332 for (el
= CSELIB_VAL_PTR (loc
)->locs
; el
->next
; el
= el
->next
)
334 /* Adjust values that have LOC as canonical so that VAL
335 becomes their canonical. */
336 if (el
->loc
&& GET_CODE (el
->loc
) == VALUE
)
338 gcc_checking_assert (CSELIB_VAL_PTR (el
->loc
)->locs
->loc
340 CSELIB_VAL_PTR (el
->loc
)->locs
->loc
= val
->val_rtx
;
343 el
->next
= val
->locs
;
344 next
= val
->locs
= CSELIB_VAL_PTR (loc
)->locs
;
347 if (CSELIB_VAL_PTR (loc
)->addr_list
)
349 /* Bring in addr_list into canonical node. */
350 struct elt_list
*last
= CSELIB_VAL_PTR (loc
)->addr_list
;
353 last
->next
= val
->addr_list
;
354 val
->addr_list
= CSELIB_VAL_PTR (loc
)->addr_list
;
355 CSELIB_VAL_PTR (loc
)->addr_list
= NULL
;
358 if (CSELIB_VAL_PTR (loc
)->next_containing_mem
!= NULL
359 && val
->next_containing_mem
== NULL
)
361 /* Add VAL to the containing_mem list after LOC. LOC will
362 be removed when we notice it doesn't contain any
364 val
->next_containing_mem
= CSELIB_VAL_PTR (loc
)->next_containing_mem
;
365 CSELIB_VAL_PTR (loc
)->next_containing_mem
= val
;
368 /* Chain LOC back to VAL. */
369 el
= elt_loc_list_pool
.allocate ();
370 el
->loc
= val
->val_rtx
;
371 el
->setting_insn
= cselib_current_insn
;
373 CSELIB_VAL_PTR (loc
)->locs
= el
;
376 el
= elt_loc_list_pool
.allocate ();
378 el
->setting_insn
= cselib_current_insn
;
383 /* Promote loc L to a nondebug cselib_current_insn if L is marked as
384 originating from a debug insn, maintaining the debug values
388 promote_debug_loc (struct elt_loc_list
*l
)
390 if (l
&& l
->setting_insn
&& DEBUG_INSN_P (l
->setting_insn
)
391 && (!cselib_current_insn
|| !DEBUG_INSN_P (cselib_current_insn
)))
394 l
->setting_insn
= cselib_current_insn
;
395 if (cselib_preserve_constants
&& l
->next
)
397 gcc_assert (l
->next
->setting_insn
398 && DEBUG_INSN_P (l
->next
->setting_insn
)
400 l
->next
->setting_insn
= cselib_current_insn
;
403 gcc_assert (!l
->next
);
407 /* The elt_list at *PL is no longer needed. Unchain it and free its
411 unchain_one_elt_list (struct elt_list
**pl
)
413 struct elt_list
*l
= *pl
;
416 elt_list_pool
.remove (l
);
419 /* Likewise for elt_loc_lists. */
422 unchain_one_elt_loc_list (struct elt_loc_list
**pl
)
424 struct elt_loc_list
*l
= *pl
;
427 elt_loc_list_pool
.remove (l
);
430 /* Likewise for cselib_vals. This also frees the addr_list associated with
434 unchain_one_value (cselib_val
*v
)
437 unchain_one_elt_list (&v
->addr_list
);
439 cselib_val_pool
.remove (v
);
442 /* Remove all entries from the hash table. Also used during
446 cselib_clear_table (void)
448 cselib_reset_table (1);
451 /* Return TRUE if V is a constant, a function invariant or a VALUE
452 equivalence; FALSE otherwise. */
455 invariant_or_equiv_p (cselib_val
*v
)
457 struct elt_loc_list
*l
;
459 if (v
== cfa_base_preserved_val
)
462 /* Keep VALUE equivalences around. */
463 for (l
= v
->locs
; l
; l
= l
->next
)
464 if (GET_CODE (l
->loc
) == VALUE
)
468 && v
->locs
->next
== NULL
)
470 if (CONSTANT_P (v
->locs
->loc
)
471 && (GET_CODE (v
->locs
->loc
) != CONST
472 || !references_value_p (v
->locs
->loc
, 0)))
474 /* Although a debug expr may be bound to different expressions,
475 we can preserve it as if it was constant, to get unification
476 and proper merging within var-tracking. */
477 if (GET_CODE (v
->locs
->loc
) == DEBUG_EXPR
478 || GET_CODE (v
->locs
->loc
) == DEBUG_IMPLICIT_PTR
479 || GET_CODE (v
->locs
->loc
) == ENTRY_VALUE
480 || GET_CODE (v
->locs
->loc
) == DEBUG_PARAMETER_REF
)
483 /* (plus (value V) (const_int C)) is invariant iff V is invariant. */
484 if (GET_CODE (v
->locs
->loc
) == PLUS
485 && CONST_INT_P (XEXP (v
->locs
->loc
, 1))
486 && GET_CODE (XEXP (v
->locs
->loc
, 0)) == VALUE
487 && invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (v
->locs
->loc
, 0))))
494 /* Remove from hash table all VALUEs except constants, function
495 invariants and VALUE equivalences. */
498 preserve_constants_and_equivs (cselib_val
**x
, void *info ATTRIBUTE_UNUSED
)
502 if (invariant_or_equiv_p (v
))
504 cselib_hasher::key lookup
= {
505 GET_MODE (v
->val_rtx
), v
->val_rtx
, VOIDmode
508 = cselib_preserved_hash_table
->find_slot_with_hash (&lookup
,
514 cselib_hash_table
->clear_slot (x
);
519 /* Remove all entries from the hash table, arranging for the next
520 value to be numbered NUM. */
523 cselib_reset_table (unsigned int num
)
529 if (cfa_base_preserved_val
)
531 unsigned int regno
= cfa_base_preserved_regno
;
532 unsigned int new_used_regs
= 0;
533 for (i
= 0; i
< n_used_regs
; i
++)
534 if (used_regs
[i
] == regno
)
540 REG_VALUES (used_regs
[i
]) = 0;
541 gcc_assert (new_used_regs
== 1);
542 n_used_regs
= new_used_regs
;
543 used_regs
[0] = regno
;
545 = hard_regno_nregs (regno
,
546 GET_MODE (cfa_base_preserved_val
->locs
->loc
));
548 /* If cfa_base is sp + const_int, need to preserve also the
549 SP_DERIVED_VALUE_P value. */
550 for (struct elt_loc_list
*l
= cfa_base_preserved_val
->locs
;
552 if (GET_CODE (l
->loc
) == PLUS
553 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
554 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
555 && CONST_INT_P (XEXP (l
->loc
, 1)))
557 if (! invariant_or_equiv_p (CSELIB_VAL_PTR (XEXP (l
->loc
, 0))))
559 rtx val
= cfa_base_preserved_val
->val_rtx
;
560 rtx_insn
*save_cselib_current_insn
= cselib_current_insn
;
561 cselib_current_insn
= l
->setting_insn
;
562 new_elt_loc_list (CSELIB_VAL_PTR (XEXP (l
->loc
, 0)),
563 plus_constant (Pmode
, val
,
564 -UINTVAL (XEXP (l
->loc
, 1))));
565 cselib_current_insn
= save_cselib_current_insn
;
572 for (i
= 0; i
< n_used_regs
; i
++)
573 REG_VALUES (used_regs
[i
]) = 0;
577 if (cselib_preserve_constants
)
578 cselib_hash_table
->traverse
<void *, preserve_constants_and_equivs
> (NULL
);
581 cselib_hash_table
->empty ();
582 gcc_checking_assert (!cselib_any_perm_equivs
);
585 n_useless_values
= 0;
586 n_useless_debug_values
= 0;
591 first_containing_mem
= &dummy_val
;
594 /* Return the number of the next value that will be generated. */
597 cselib_get_next_uid (void)
602 /* Search for X, whose hashcode is HASH, in CSELIB_HASH_TABLE,
603 INSERTing if requested. When X is part of the address of a MEM,
604 MEMMODE should specify the mode of the MEM. */
607 cselib_find_slot (machine_mode mode
, rtx x
, hashval_t hash
,
608 enum insert_option insert
, machine_mode memmode
)
610 cselib_val
**slot
= NULL
;
611 cselib_hasher::key lookup
= { mode
, x
, memmode
};
612 if (cselib_preserve_constants
)
613 slot
= cselib_preserved_hash_table
->find_slot_with_hash (&lookup
, hash
,
616 slot
= cselib_hash_table
->find_slot_with_hash (&lookup
, hash
, insert
);
620 /* Return true if X contains a VALUE rtx. If ONLY_USELESS is set, we
621 only return true for values which point to a cselib_val whose value
622 element has been set to zero, which implies the cselib_val will be
626 references_value_p (const_rtx x
, int only_useless
)
628 const enum rtx_code code
= GET_CODE (x
);
629 const char *fmt
= GET_RTX_FORMAT (code
);
632 if (GET_CODE (x
) == VALUE
634 || (CSELIB_VAL_PTR (x
)->locs
== 0 && !PRESERVED_VALUE_P (x
))))
637 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
639 if (fmt
[i
] == 'e' && references_value_p (XEXP (x
, i
), only_useless
))
641 else if (fmt
[i
] == 'E')
642 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
643 if (references_value_p (XVECEXP (x
, i
, j
), only_useless
))
650 /* Return true if V is a useless VALUE and can be discarded as such. */
653 cselib_useless_value_p (cselib_val
*v
)
656 && !PRESERVED_VALUE_P (v
->val_rtx
)
657 && !SP_DERIVED_VALUE_P (v
->val_rtx
));
660 /* For all locations found in X, delete locations that reference useless
661 values (i.e. values without any location). Called through
665 discard_useless_locs (cselib_val
**x
, void *info ATTRIBUTE_UNUSED
)
668 struct elt_loc_list
**p
= &v
->locs
;
669 bool had_locs
= v
->locs
!= NULL
;
670 rtx_insn
*setting_insn
= v
->locs
? v
->locs
->setting_insn
: NULL
;
674 if (references_value_p ((*p
)->loc
, 1))
675 unchain_one_elt_loc_list (p
);
680 if (had_locs
&& cselib_useless_value_p (v
))
682 if (setting_insn
&& DEBUG_INSN_P (setting_insn
))
683 n_useless_debug_values
++;
686 values_became_useless
= 1;
691 /* If X is a value with no locations, remove it from the hashtable. */
694 discard_useless_values (cselib_val
**x
, void *info ATTRIBUTE_UNUSED
)
698 if (v
->locs
== 0 && cselib_useless_value_p (v
))
700 if (cselib_discard_hook
)
701 cselib_discard_hook (v
);
703 CSELIB_VAL_PTR (v
->val_rtx
) = NULL
;
704 cselib_hash_table
->clear_slot (x
);
705 unchain_one_value (v
);
712 /* Clean out useless values (i.e. those which no longer have locations
713 associated with them) from the hash table. */
716 remove_useless_values (void)
720 /* First pass: eliminate locations that reference the value. That in
721 turn can make more values useless. */
724 values_became_useless
= 0;
725 cselib_hash_table
->traverse
<void *, discard_useless_locs
> (NULL
);
727 while (values_became_useless
);
729 /* Second pass: actually remove the values. */
731 p
= &first_containing_mem
;
732 for (v
= *p
; v
!= &dummy_val
; v
= v
->next_containing_mem
)
733 if (v
->locs
&& v
== canonical_cselib_val (v
))
736 p
= &(*p
)->next_containing_mem
;
740 n_useless_values
+= n_useless_debug_values
;
741 n_debug_values
-= n_useless_debug_values
;
742 n_useless_debug_values
= 0;
744 cselib_hash_table
->traverse
<void *, discard_useless_values
> (NULL
);
746 gcc_assert (!n_useless_values
);
749 /* Arrange for a value to not be removed from the hash table even if
750 it becomes useless. */
753 cselib_preserve_value (cselib_val
*v
)
755 PRESERVED_VALUE_P (v
->val_rtx
) = 1;
758 /* Test whether a value is preserved. */
761 cselib_preserved_value_p (cselib_val
*v
)
763 return PRESERVED_VALUE_P (v
->val_rtx
);
766 /* Arrange for a REG value to be assumed constant through the whole function,
767 never invalidated and preserved across cselib_reset_table calls. */
770 cselib_preserve_cfa_base_value (cselib_val
*v
, unsigned int regno
)
772 if (cselib_preserve_constants
774 && REG_P (v
->locs
->loc
))
776 cfa_base_preserved_val
= v
;
777 cfa_base_preserved_regno
= regno
;
781 /* Clean all non-constant expressions in the hash table, but retain
785 cselib_preserve_only_values (void)
789 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
790 cselib_invalidate_regno (i
, reg_raw_mode
[i
]);
792 cselib_invalidate_mem (callmem
);
794 remove_useless_values ();
796 gcc_assert (first_containing_mem
== &dummy_val
);
799 /* Arrange for a value to be marked as based on stack pointer
800 for find_base_term purposes. */
803 cselib_set_value_sp_based (cselib_val
*v
)
805 SP_BASED_VALUE_P (v
->val_rtx
) = 1;
808 /* Test whether a value is based on stack pointer for
809 find_base_term purposes. */
812 cselib_sp_based_value_p (cselib_val
*v
)
814 return SP_BASED_VALUE_P (v
->val_rtx
);
817 /* Return the mode in which a register was last set. If X is not a
818 register, return its mode. If the mode in which the register was
819 set is not known, or the value was already clobbered, return
823 cselib_reg_set_mode (const_rtx x
)
828 if (REG_VALUES (REGNO (x
)) == NULL
829 || REG_VALUES (REGNO (x
))->elt
== NULL
)
832 return GET_MODE (REG_VALUES (REGNO (x
))->elt
->val_rtx
);
835 /* If x is a PLUS or an autoinc operation, expand the operation,
836 storing the offset, if any, in *OFF. */
839 autoinc_split (rtx x
, rtx
*off
, machine_mode memmode
)
841 switch (GET_CODE (x
))
849 if (memmode
== VOIDmode
)
852 *off
= gen_int_mode (-GET_MODE_SIZE (memmode
), GET_MODE (x
));
857 if (memmode
== VOIDmode
)
860 *off
= gen_int_mode (GET_MODE_SIZE (memmode
), GET_MODE (x
));
878 if (GET_MODE (x
) == Pmode
879 && (REG_P (x
) || MEM_P (x
) || GET_CODE (x
) == VALUE
)
880 && (*off
== NULL_RTX
|| CONST_INT_P (*off
)))
883 if (GET_CODE (x
) == VALUE
)
884 e
= CSELIB_VAL_PTR (x
);
886 e
= cselib_lookup (x
, GET_MODE (x
), 0, memmode
);
889 if (SP_DERIVED_VALUE_P (e
->val_rtx
)
890 && (*off
== NULL_RTX
|| *off
== const0_rtx
))
895 for (struct elt_loc_list
*l
= e
->locs
; l
; l
= l
->next
)
896 if (GET_CODE (l
->loc
) == PLUS
897 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
898 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
899 && CONST_INT_P (XEXP (l
->loc
, 1)))
901 if (*off
== NULL_RTX
)
902 *off
= XEXP (l
->loc
, 1);
904 *off
= plus_constant (Pmode
, *off
,
905 INTVAL (XEXP (l
->loc
, 1)));
906 if (*off
== const0_rtx
)
908 return XEXP (l
->loc
, 0);
915 /* Return nonzero if we can prove that X and Y contain the same value,
916 taking our gathered information into account. MEMMODE holds the
917 mode of the enclosing MEM, if any, as required to deal with autoinc
918 addressing modes. If X and Y are not (known to be) part of
919 addresses, MEMMODE should be VOIDmode. */
922 rtx_equal_for_cselib_1 (rtx x
, rtx y
, machine_mode memmode
, int depth
)
928 if (REG_P (x
) || MEM_P (x
))
930 cselib_val
*e
= cselib_lookup (x
, GET_MODE (x
), 0, memmode
);
936 if (REG_P (y
) || MEM_P (y
))
938 cselib_val
*e
= cselib_lookup (y
, GET_MODE (y
), 0, memmode
);
947 if (GET_CODE (x
) == VALUE
)
949 cselib_val
*e
= canonical_cselib_val (CSELIB_VAL_PTR (x
));
950 struct elt_loc_list
*l
;
952 if (GET_CODE (y
) == VALUE
)
953 return e
== canonical_cselib_val (CSELIB_VAL_PTR (y
));
955 if ((SP_DERIVED_VALUE_P (x
)
956 || SP_DERIVED_VALUE_P (e
->val_rtx
))
957 && GET_MODE (y
) == Pmode
)
960 rtx yr
= autoinc_split (y
, &yoff
, memmode
);
961 if ((yr
== x
|| yr
== e
->val_rtx
) && yoff
== NULL_RTX
)
968 for (l
= e
->locs
; l
; l
= l
->next
)
972 /* Avoid infinite recursion. We know we have the canonical
973 value, so we can just skip any values in the equivalence
975 if (REG_P (t
) || MEM_P (t
) || GET_CODE (t
) == VALUE
)
977 else if (rtx_equal_for_cselib_1 (t
, y
, memmode
, depth
+ 1))
983 else if (GET_CODE (y
) == VALUE
)
985 cselib_val
*e
= canonical_cselib_val (CSELIB_VAL_PTR (y
));
986 struct elt_loc_list
*l
;
988 if ((SP_DERIVED_VALUE_P (y
)
989 || SP_DERIVED_VALUE_P (e
->val_rtx
))
990 && GET_MODE (x
) == Pmode
)
993 rtx xr
= autoinc_split (x
, &xoff
, memmode
);
994 if ((xr
== y
|| xr
== e
->val_rtx
) && xoff
== NULL_RTX
)
1001 for (l
= e
->locs
; l
; l
= l
->next
)
1005 if (REG_P (t
) || MEM_P (t
) || GET_CODE (t
) == VALUE
)
1007 else if (rtx_equal_for_cselib_1 (x
, t
, memmode
, depth
+ 1))
1014 if (GET_MODE (x
) != GET_MODE (y
))
1017 if (GET_CODE (x
) != GET_CODE (y
)
1018 || (GET_CODE (x
) == PLUS
1019 && GET_MODE (x
) == Pmode
1020 && CONST_INT_P (XEXP (x
, 1))
1021 && CONST_INT_P (XEXP (y
, 1))))
1023 rtx xorig
= x
, yorig
= y
;
1024 rtx xoff
= NULL
, yoff
= NULL
;
1026 x
= autoinc_split (x
, &xoff
, memmode
);
1027 y
= autoinc_split (y
, &yoff
, memmode
);
1029 /* Don't recurse if nothing changed. */
1030 if (x
!= xorig
|| y
!= yorig
)
1035 if (xoff
&& !rtx_equal_for_cselib_1 (xoff
, yoff
, memmode
, depth
))
1038 return rtx_equal_for_cselib_1 (x
, y
, memmode
, depth
);
1041 if (GET_CODE (xorig
) != GET_CODE (yorig
))
1045 /* These won't be handled correctly by the code below. */
1046 switch (GET_CODE (x
))
1053 if (!same_vector_encodings_p (x
, y
))
1057 case DEBUG_IMPLICIT_PTR
:
1058 return DEBUG_IMPLICIT_PTR_DECL (x
)
1059 == DEBUG_IMPLICIT_PTR_DECL (y
);
1061 case DEBUG_PARAMETER_REF
:
1062 return DEBUG_PARAMETER_REF_DECL (x
)
1063 == DEBUG_PARAMETER_REF_DECL (y
);
1066 /* ENTRY_VALUEs are function invariant, it is thus undesirable to
1067 use rtx_equal_for_cselib_1 to compare the operands. */
1068 return rtx_equal_p (ENTRY_VALUE_EXP (x
), ENTRY_VALUE_EXP (y
));
1071 return label_ref_label (x
) == label_ref_label (y
);
1074 return REGNO (x
) == REGNO (y
);
1077 /* We have to compare any autoinc operations in the addresses
1078 using this MEM's mode. */
1079 return rtx_equal_for_cselib_1 (XEXP (x
, 0), XEXP (y
, 0), GET_MODE (x
),
1086 code
= GET_CODE (x
);
1087 fmt
= GET_RTX_FORMAT (code
);
1089 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1096 if (XWINT (x
, i
) != XWINT (y
, i
))
1102 if (XINT (x
, i
) != XINT (y
, i
))
1107 if (maybe_ne (SUBREG_BYTE (x
), SUBREG_BYTE (y
)))
1113 /* Two vectors must have the same length. */
1114 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
1117 /* And the corresponding elements must match. */
1118 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1119 if (! rtx_equal_for_cselib_1 (XVECEXP (x
, i
, j
),
1120 XVECEXP (y
, i
, j
), memmode
, depth
))
1126 && targetm
.commutative_p (x
, UNKNOWN
)
1127 && rtx_equal_for_cselib_1 (XEXP (x
, 1), XEXP (y
, 0), memmode
,
1129 && rtx_equal_for_cselib_1 (XEXP (x
, 0), XEXP (y
, 1), memmode
,
1132 if (! rtx_equal_for_cselib_1 (XEXP (x
, i
), XEXP (y
, i
), memmode
,
1139 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
1144 /* These are just backpointers, so they don't matter. */
1151 /* It is believed that rtx's at this level will never
1152 contain anything but integers and other rtx's,
1153 except for within LABEL_REFs and SYMBOL_REFs. */
1161 /* Wrapper for rtx_equal_for_cselib_p to determine whether a SET is
1162 truly redundant, taking into account aliasing information. */
1164 cselib_redundant_set_p (rtx set
)
1166 gcc_assert (GET_CODE (set
) == SET
);
1167 rtx dest
= SET_DEST (set
);
1168 if (cselib_reg_set_mode (dest
) != GET_MODE (dest
))
1171 if (!rtx_equal_for_cselib_p (dest
, SET_SRC (set
)))
1174 while (GET_CODE (dest
) == SUBREG
1175 || GET_CODE (dest
) == ZERO_EXTRACT
1176 || GET_CODE (dest
) == STRICT_LOW_PART
)
1177 dest
= XEXP (dest
, 0);
1179 if (!flag_strict_aliasing
|| !MEM_P (dest
))
1182 /* For a store we need to check that suppressing it will not change
1183 the effective alias set. */
1184 rtx dest_addr
= XEXP (dest
, 0);
1186 /* Lookup the equivalents to the original dest (rather than just the
1188 cselib_val
*src_val
= cselib_lookup (SET_DEST (set
),
1189 GET_MODE (SET_DEST (set
)),
1194 /* Walk the list of source equivalents to find the MEM accessing
1195 the same location. */
1196 for (elt_loc_list
*l
= src_val
->locs
; l
; l
= l
->next
)
1198 rtx src_equiv
= l
->loc
;
1199 while (GET_CODE (src_equiv
) == SUBREG
1200 || GET_CODE (src_equiv
) == ZERO_EXTRACT
1201 || GET_CODE (src_equiv
) == STRICT_LOW_PART
)
1202 src_equiv
= XEXP (src_equiv
, 0);
1204 if (MEM_P (src_equiv
))
1206 /* Match the MEMs by comparing the addresses. We can
1207 only remove the later store if the earlier aliases at
1208 least all the accesses of the later one. */
1209 if (rtx_equal_for_cselib_1 (dest_addr
, XEXP (src_equiv
, 0),
1210 GET_MODE (dest
), 0))
1211 return mems_same_for_tbaa_p (src_equiv
, dest
);
1216 /* We failed to find a recorded value in the cselib history, so try
1217 the source of this set; this catches cases such as *p = *q when p
1218 and q have the same value. */
1219 rtx src
= SET_SRC (set
);
1220 while (GET_CODE (src
) == SUBREG
)
1221 src
= XEXP (src
, 0);
1224 && rtx_equal_for_cselib_1 (dest_addr
, XEXP (src
, 0), GET_MODE (dest
), 0))
1225 return mems_same_for_tbaa_p (src
, dest
);
1230 /* Helper function for cselib_hash_rtx. Arguments like for cselib_hash_rtx,
1231 except that it hashes (plus:P x c). */
1234 cselib_hash_plus_const_int (rtx x
, HOST_WIDE_INT c
, int create
,
1235 machine_mode memmode
)
1237 cselib_val
*e
= cselib_lookup (x
, GET_MODE (x
), create
, memmode
);
1241 if (! SP_DERIVED_VALUE_P (e
->val_rtx
))
1242 for (struct elt_loc_list
*l
= e
->locs
; l
; l
= l
->next
)
1243 if (GET_CODE (l
->loc
) == PLUS
1244 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
1245 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
1246 && CONST_INT_P (XEXP (l
->loc
, 1)))
1248 e
= CSELIB_VAL_PTR (XEXP (l
->loc
, 0));
1249 c
= trunc_int_for_mode (c
+ UINTVAL (XEXP (l
->loc
, 1)), Pmode
);
1255 unsigned hash
= (unsigned) PLUS
+ (unsigned) GET_MODE (x
);
1257 unsigned int tem_hash
= (unsigned) CONST_INT
+ (unsigned) VOIDmode
;
1258 tem_hash
+= ((unsigned) CONST_INT
<< 7) + (unsigned HOST_WIDE_INT
) c
;
1260 tem_hash
= (unsigned int) CONST_INT
;
1262 return hash
? hash
: 1 + (unsigned int) PLUS
;
1265 /* Hash an rtx. Return 0 if we couldn't hash the rtx.
1266 For registers and memory locations, we look up their cselib_val structure
1267 and return its VALUE element.
1268 Possible reasons for return 0 are: the object is volatile, or we couldn't
1269 find a register or memory location in the table and CREATE is zero. If
1270 CREATE is nonzero, table elts are created for regs and mem.
1271 N.B. this hash function returns the same hash value for RTXes that
1272 differ only in the order of operands, thus it is suitable for comparisons
1273 that take commutativity into account.
1274 If we wanted to also support associative rules, we'd have to use a different
1275 strategy to avoid returning spurious 0, e.g. return ~(~0U >> 1) .
1276 MEMMODE indicates the mode of an enclosing MEM, and it's only
1277 used to compute autoinc values.
1278 We used to have a MODE argument for hashing for CONST_INTs, but that
1279 didn't make sense, since it caused spurious hash differences between
1280 (set (reg:SI 1) (const_int))
1281 (plus:SI (reg:SI 2) (reg:SI 1))
1283 (plus:SI (reg:SI 2) (const_int))
1284 If the mode is important in any context, it must be checked specifically
1285 in a comparison anyway, since relying on hash differences is unsafe. */
1288 cselib_hash_rtx (rtx x
, int create
, machine_mode memmode
)
1295 unsigned int hash
= 0;
1297 code
= GET_CODE (x
);
1298 hash
+= (unsigned) code
+ (unsigned) GET_MODE (x
);
1303 e
= CSELIB_VAL_PTR (x
);
1308 e
= cselib_lookup (x
, GET_MODE (x
), create
, memmode
);
1315 hash
+= ((unsigned) DEBUG_EXPR
<< 7)
1316 + DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
));
1317 return hash
? hash
: (unsigned int) DEBUG_EXPR
;
1319 case DEBUG_IMPLICIT_PTR
:
1320 hash
+= ((unsigned) DEBUG_IMPLICIT_PTR
<< 7)
1321 + DECL_UID (DEBUG_IMPLICIT_PTR_DECL (x
));
1322 return hash
? hash
: (unsigned int) DEBUG_IMPLICIT_PTR
;
1324 case DEBUG_PARAMETER_REF
:
1325 hash
+= ((unsigned) DEBUG_PARAMETER_REF
<< 7)
1326 + DECL_UID (DEBUG_PARAMETER_REF_DECL (x
));
1327 return hash
? hash
: (unsigned int) DEBUG_PARAMETER_REF
;
1330 /* ENTRY_VALUEs are function invariant, thus try to avoid
1331 recursing on argument if ENTRY_VALUE is one of the
1332 forms emitted by expand_debug_expr, otherwise
1333 ENTRY_VALUE hash would depend on the current value
1334 in some register or memory. */
1335 if (REG_P (ENTRY_VALUE_EXP (x
)))
1336 hash
+= (unsigned int) REG
1337 + (unsigned int) GET_MODE (ENTRY_VALUE_EXP (x
))
1338 + (unsigned int) REGNO (ENTRY_VALUE_EXP (x
));
1339 else if (MEM_P (ENTRY_VALUE_EXP (x
))
1340 && REG_P (XEXP (ENTRY_VALUE_EXP (x
), 0)))
1341 hash
+= (unsigned int) MEM
1342 + (unsigned int) GET_MODE (XEXP (ENTRY_VALUE_EXP (x
), 0))
1343 + (unsigned int) REGNO (XEXP (ENTRY_VALUE_EXP (x
), 0));
1345 hash
+= cselib_hash_rtx (ENTRY_VALUE_EXP (x
), create
, memmode
);
1346 return hash
? hash
: (unsigned int) ENTRY_VALUE
;
1349 hash
+= ((unsigned) CONST_INT
<< 7) + UINTVAL (x
);
1350 return hash
? hash
: (unsigned int) CONST_INT
;
1352 case CONST_WIDE_INT
:
1353 for (i
= 0; i
< CONST_WIDE_INT_NUNITS (x
); i
++)
1354 hash
+= CONST_WIDE_INT_ELT (x
, i
);
1357 case CONST_POLY_INT
:
1361 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
1362 h
.add_wide_int (CONST_POLY_INT_COEFFS (x
)[i
]);
1367 /* This is like the general case, except that it only counts
1368 the integers representing the constant. */
1369 hash
+= (unsigned) code
+ (unsigned) GET_MODE (x
);
1370 if (TARGET_SUPPORTS_WIDE_INT
== 0 && GET_MODE (x
) == VOIDmode
)
1371 hash
+= ((unsigned) CONST_DOUBLE_LOW (x
)
1372 + (unsigned) CONST_DOUBLE_HIGH (x
));
1374 hash
+= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
1375 return hash
? hash
: (unsigned int) CONST_DOUBLE
;
1378 hash
+= (unsigned int) code
+ (unsigned int) GET_MODE (x
);
1379 hash
+= fixed_hash (CONST_FIXED_VALUE (x
));
1380 return hash
? hash
: (unsigned int) CONST_FIXED
;
1387 units
= const_vector_encoded_nelts (x
);
1389 for (i
= 0; i
< units
; ++i
)
1391 elt
= CONST_VECTOR_ENCODED_ELT (x
, i
);
1392 hash
+= cselib_hash_rtx (elt
, 0, memmode
);
1398 /* Assume there is only one rtx object for any given label. */
1400 /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
1401 differences and differences between each stage's debugging dumps. */
1402 hash
+= (((unsigned int) LABEL_REF
<< 7)
1403 + CODE_LABEL_NUMBER (label_ref_label (x
)));
1404 return hash
? hash
: (unsigned int) LABEL_REF
;
1408 /* Don't hash on the symbol's address to avoid bootstrap differences.
1409 Different hash values may cause expressions to be recorded in
1410 different orders and thus different registers to be used in the
1411 final assembler. This also avoids differences in the dump files
1412 between various stages. */
1414 const unsigned char *p
= (const unsigned char *) XSTR (x
, 0);
1417 h
+= (h
<< 7) + *p
++; /* ??? revisit */
1419 hash
+= ((unsigned int) SYMBOL_REF
<< 7) + h
;
1420 return hash
? hash
: (unsigned int) SYMBOL_REF
;
1425 /* We can't compute these without knowing the MEM mode. */
1426 gcc_assert (memmode
!= VOIDmode
);
1427 offset
= GET_MODE_SIZE (memmode
);
1428 if (code
== PRE_DEC
)
1430 /* Adjust the hash so that (mem:MEMMODE (pre_* (reg))) hashes
1431 like (mem:MEMMODE (plus (reg) (const_int I))). */
1432 if (GET_MODE (x
) == Pmode
1433 && (REG_P (XEXP (x
, 0))
1434 || MEM_P (XEXP (x
, 0))
1435 || GET_CODE (XEXP (x
, 0)) == VALUE
))
1438 if (offset
.is_constant (&c
))
1439 return cselib_hash_plus_const_int (XEXP (x
, 0),
1440 trunc_int_for_mode (c
, Pmode
),
1443 hash
= ((unsigned) PLUS
+ (unsigned) GET_MODE (x
)
1444 + cselib_hash_rtx (XEXP (x
, 0), create
, memmode
)
1445 + cselib_hash_rtx (gen_int_mode (offset
, GET_MODE (x
)),
1447 return hash
? hash
: 1 + (unsigned) PLUS
;
1450 gcc_assert (memmode
!= VOIDmode
);
1451 return cselib_hash_rtx (XEXP (x
, 1), create
, memmode
);
1456 gcc_assert (memmode
!= VOIDmode
);
1457 return cselib_hash_rtx (XEXP (x
, 0), create
, memmode
);
1461 case UNSPEC_VOLATILE
:
1465 if (MEM_VOLATILE_P (x
))
1471 if (GET_MODE (x
) == Pmode
1472 && (REG_P (XEXP (x
, 0))
1473 || MEM_P (XEXP (x
, 0))
1474 || GET_CODE (XEXP (x
, 0)) == VALUE
)
1475 && CONST_INT_P (XEXP (x
, 1)))
1476 return cselib_hash_plus_const_int (XEXP (x
, 0), INTVAL (XEXP (x
, 1)),
1484 i
= GET_RTX_LENGTH (code
) - 1;
1485 fmt
= GET_RTX_FORMAT (code
);
1492 rtx tem
= XEXP (x
, i
);
1493 unsigned int tem_hash
= cselib_hash_rtx (tem
, create
, memmode
);
1502 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1504 unsigned int tem_hash
1505 = cselib_hash_rtx (XVECEXP (x
, i
, j
), create
, memmode
);
1516 const unsigned char *p
= (const unsigned char *) XSTR (x
, i
);
1525 hash
+= XINT (x
, i
);
1529 hash
+= constant_lower_bound (SUBREG_BYTE (x
));
1542 return hash
? hash
: 1 + (unsigned int) GET_CODE (x
);
1545 /* Create a new value structure for VALUE and initialize it. The mode of the
1548 static inline cselib_val
*
1549 new_cselib_val (unsigned int hash
, machine_mode mode
, rtx x
)
1551 cselib_val
*e
= cselib_val_pool
.allocate ();
1554 gcc_assert (next_uid
);
1557 e
->uid
= next_uid
++;
1558 /* We use an alloc pool to allocate this RTL construct because it
1559 accounts for about 8% of the overall memory usage. We know
1560 precisely when we can have VALUE RTXen (when cselib is active)
1561 so we don't need to put them in garbage collected memory.
1562 ??? Why should a VALUE be an RTX in the first place? */
1563 e
->val_rtx
= (rtx_def
*) value_pool
.allocate ();
1564 memset (e
->val_rtx
, 0, RTX_HDR_SIZE
);
1565 PUT_CODE (e
->val_rtx
, VALUE
);
1566 PUT_MODE (e
->val_rtx
, mode
);
1567 CSELIB_VAL_PTR (e
->val_rtx
) = e
;
1570 e
->next_containing_mem
= 0;
1572 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1574 fprintf (dump_file
, "cselib value %u:%u ", e
->uid
, hash
);
1575 if (flag_dump_noaddr
|| flag_dump_unnumbered
)
1576 fputs ("# ", dump_file
);
1578 fprintf (dump_file
, "%p ", (void*)e
);
1579 print_rtl_single (dump_file
, x
);
1580 fputc ('\n', dump_file
);
1586 /* ADDR_ELT is a value that is used as address. MEM_ELT is the value that
1587 contains the data at this address. X is a MEM that represents the
1588 value. Update the two value structures to represent this situation. */
1591 add_mem_for_addr (cselib_val
*addr_elt
, cselib_val
*mem_elt
, rtx x
)
1593 addr_elt
= canonical_cselib_val (addr_elt
);
1594 mem_elt
= canonical_cselib_val (mem_elt
);
1596 /* Avoid duplicates. */
1597 addr_space_t as
= MEM_ADDR_SPACE (x
);
1598 for (elt_loc_list
*l
= mem_elt
->locs
; l
; l
= l
->next
)
1600 && CSELIB_VAL_PTR (XEXP (l
->loc
, 0)) == addr_elt
1601 && MEM_ADDR_SPACE (l
->loc
) == as
)
1603 promote_debug_loc (l
);
1607 addr_elt
->addr_list
= new_elt_list (addr_elt
->addr_list
, mem_elt
);
1608 new_elt_loc_list (mem_elt
,
1609 replace_equiv_address_nv (x
, addr_elt
->val_rtx
));
1610 if (mem_elt
->next_containing_mem
== NULL
)
1612 mem_elt
->next_containing_mem
= first_containing_mem
;
1613 first_containing_mem
= mem_elt
;
1617 /* Subroutine of cselib_lookup. Return a value for X, which is a MEM rtx.
1618 If CREATE, make a new one if we haven't seen it before. */
1621 cselib_lookup_mem (rtx x
, int create
)
1623 machine_mode mode
= GET_MODE (x
);
1624 machine_mode addr_mode
;
1627 cselib_val
*mem_elt
;
1629 if (MEM_VOLATILE_P (x
) || mode
== BLKmode
1630 || !cselib_record_memory
1631 || (FLOAT_MODE_P (mode
) && flag_float_store
))
1634 addr_mode
= GET_MODE (XEXP (x
, 0));
1635 if (addr_mode
== VOIDmode
)
1638 /* Look up the value for the address. */
1639 addr
= cselib_lookup (XEXP (x
, 0), addr_mode
, create
, mode
);
1642 addr
= canonical_cselib_val (addr
);
1644 /* Find a value that describes a value of our mode at that address. */
1645 addr_space_t as
= MEM_ADDR_SPACE (x
);
1646 for (elt_list
*l
= addr
->addr_list
; l
; l
= l
->next
)
1647 if (GET_MODE (l
->elt
->val_rtx
) == mode
)
1649 for (elt_loc_list
*l2
= l
->elt
->locs
; l2
; l2
= l2
->next
)
1650 if (MEM_P (l2
->loc
) && MEM_ADDR_SPACE (l2
->loc
) == as
)
1652 promote_debug_loc (l
->elt
->locs
);
1660 mem_elt
= new_cselib_val (next_uid
, mode
, x
);
1661 add_mem_for_addr (addr
, mem_elt
, x
);
1662 slot
= cselib_find_slot (mode
, x
, mem_elt
->hash
, INSERT
, VOIDmode
);
1667 /* Search through the possible substitutions in P. We prefer a non reg
1668 substitution because this allows us to expand the tree further. If
1669 we find, just a reg, take the lowest regno. There may be several
1670 non-reg results, we just take the first one because they will all
1671 expand to the same place. */
1674 expand_loc (struct elt_loc_list
*p
, struct expand_value_data
*evd
,
1677 rtx reg_result
= NULL
;
1678 unsigned int regno
= UINT_MAX
;
1679 struct elt_loc_list
*p_in
= p
;
1681 for (; p
; p
= p
->next
)
1683 /* Return these right away to avoid returning stack pointer based
1684 expressions for frame pointer and vice versa, which is something
1685 that would confuse DSE. See the comment in cselib_expand_value_rtx_1
1686 for more details. */
1688 && (REGNO (p
->loc
) == STACK_POINTER_REGNUM
1689 || REGNO (p
->loc
) == FRAME_POINTER_REGNUM
1690 || REGNO (p
->loc
) == HARD_FRAME_POINTER_REGNUM
1691 || REGNO (p
->loc
) == cfa_base_preserved_regno
))
1693 /* Avoid infinite recursion trying to expand a reg into a
1695 if ((REG_P (p
->loc
))
1696 && (REGNO (p
->loc
) < regno
)
1697 && !bitmap_bit_p (evd
->regs_active
, REGNO (p
->loc
)))
1699 reg_result
= p
->loc
;
1700 regno
= REGNO (p
->loc
);
1702 /* Avoid infinite recursion and do not try to expand the
1704 else if (GET_CODE (p
->loc
) == VALUE
1705 && CSELIB_VAL_PTR (p
->loc
)->locs
== p_in
)
1707 else if (!REG_P (p
->loc
))
1710 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1712 print_inline_rtx (dump_file
, p
->loc
, 0);
1713 fprintf (dump_file
, "\n");
1715 if (GET_CODE (p
->loc
) == LO_SUM
1716 && GET_CODE (XEXP (p
->loc
, 1)) == SYMBOL_REF
1718 && (note
= find_reg_note (p
->setting_insn
, REG_EQUAL
, NULL_RTX
))
1719 && XEXP (note
, 0) == XEXP (p
->loc
, 1))
1720 return XEXP (p
->loc
, 1);
1721 result
= cselib_expand_value_rtx_1 (p
->loc
, evd
, max_depth
- 1);
1728 if (regno
!= UINT_MAX
)
1731 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1732 fprintf (dump_file
, "r%d\n", regno
);
1734 result
= cselib_expand_value_rtx_1 (reg_result
, evd
, max_depth
- 1);
1739 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1743 print_inline_rtx (dump_file
, reg_result
, 0);
1744 fprintf (dump_file
, "\n");
1747 fprintf (dump_file
, "NULL\n");
1753 /* Forward substitute and expand an expression out to its roots.
1754 This is the opposite of common subexpression. Because local value
1755 numbering is such a weak optimization, the expanded expression is
1756 pretty much unique (not from a pointer equals point of view but
1757 from a tree shape point of view.
1759 This function returns NULL if the expansion fails. The expansion
1760 will fail if there is no value number for one of the operands or if
1761 one of the operands has been overwritten between the current insn
1762 and the beginning of the basic block. For instance x has no
1768 REGS_ACTIVE is a scratch bitmap that should be clear when passing in.
1769 It is clear on return. */
1772 cselib_expand_value_rtx (rtx orig
, bitmap regs_active
, int max_depth
)
1774 struct expand_value_data evd
;
1776 evd
.regs_active
= regs_active
;
1777 evd
.callback
= NULL
;
1778 evd
.callback_arg
= NULL
;
1781 return cselib_expand_value_rtx_1 (orig
, &evd
, max_depth
);
1784 /* Same as cselib_expand_value_rtx, but using a callback to try to
1785 resolve some expressions. The CB function should return ORIG if it
1786 can't or does not want to deal with a certain RTX. Any other
1787 return value, including NULL, will be used as the expansion for
1788 VALUE, without any further changes. */
1791 cselib_expand_value_rtx_cb (rtx orig
, bitmap regs_active
, int max_depth
,
1792 cselib_expand_callback cb
, void *data
)
1794 struct expand_value_data evd
;
1796 evd
.regs_active
= regs_active
;
1798 evd
.callback_arg
= data
;
1801 return cselib_expand_value_rtx_1 (orig
, &evd
, max_depth
);
1804 /* Similar to cselib_expand_value_rtx_cb, but no rtxs are actually copied
1805 or simplified. Useful to find out whether cselib_expand_value_rtx_cb
1806 would return NULL or non-NULL, without allocating new rtx. */
1809 cselib_dummy_expand_value_rtx_cb (rtx orig
, bitmap regs_active
, int max_depth
,
1810 cselib_expand_callback cb
, void *data
)
1812 struct expand_value_data evd
;
1814 evd
.regs_active
= regs_active
;
1816 evd
.callback_arg
= data
;
1819 return cselib_expand_value_rtx_1 (orig
, &evd
, max_depth
) != NULL
;
1822 /* Internal implementation of cselib_expand_value_rtx and
1823 cselib_expand_value_rtx_cb. */
1826 cselib_expand_value_rtx_1 (rtx orig
, struct expand_value_data
*evd
,
1832 const char *format_ptr
;
1835 code
= GET_CODE (orig
);
1837 /* For the context of dse, if we end up expand into a huge tree, we
1838 will not have a useful address, so we might as well just give up
1847 struct elt_list
*l
= REG_VALUES (REGNO (orig
));
1849 if (l
&& l
->elt
== NULL
)
1851 for (; l
; l
= l
->next
)
1852 if (GET_MODE (l
->elt
->val_rtx
) == GET_MODE (orig
))
1855 unsigned regno
= REGNO (orig
);
1857 /* The only thing that we are not willing to do (this
1858 is requirement of dse and if others potential uses
1859 need this function we should add a parm to control
1860 it) is that we will not substitute the
1861 STACK_POINTER_REGNUM, FRAME_POINTER or the
1864 These expansions confuses the code that notices that
1865 stores into the frame go dead at the end of the
1866 function and that the frame is not effected by calls
1867 to subroutines. If you allow the
1868 STACK_POINTER_REGNUM substitution, then dse will
1869 think that parameter pushing also goes dead which is
1870 wrong. If you allow the FRAME_POINTER or the
1871 HARD_FRAME_POINTER then you lose the opportunity to
1872 make the frame assumptions. */
1873 if (regno
== STACK_POINTER_REGNUM
1874 || regno
== FRAME_POINTER_REGNUM
1875 || regno
== HARD_FRAME_POINTER_REGNUM
1876 || regno
== cfa_base_preserved_regno
)
1879 bitmap_set_bit (evd
->regs_active
, regno
);
1881 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1882 fprintf (dump_file
, "expanding: r%d into: ", regno
);
1884 result
= expand_loc (l
->elt
->locs
, evd
, max_depth
);
1885 bitmap_clear_bit (evd
->regs_active
, regno
);
1900 /* SCRATCH must be shared because they represent distinct values. */
1903 if (REG_P (XEXP (orig
, 0)) && HARD_REGISTER_NUM_P (REGNO (XEXP (orig
, 0))))
1908 if (shared_const_p (orig
))
1918 subreg
= evd
->callback (orig
, evd
->regs_active
, max_depth
,
1924 subreg
= cselib_expand_value_rtx_1 (SUBREG_REG (orig
), evd
,
1928 scopy
= simplify_gen_subreg (GET_MODE (orig
), subreg
,
1929 GET_MODE (SUBREG_REG (orig
)),
1930 SUBREG_BYTE (orig
));
1932 || (GET_CODE (scopy
) == SUBREG
1933 && !REG_P (SUBREG_REG (scopy
))
1934 && !MEM_P (SUBREG_REG (scopy
))))
1944 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
1946 fputs ("\nexpanding ", dump_file
);
1947 print_rtl_single (dump_file
, orig
);
1948 fputs (" into...", dump_file
);
1953 result
= evd
->callback (orig
, evd
->regs_active
, max_depth
,
1960 result
= expand_loc (CSELIB_VAL_PTR (orig
)->locs
, evd
, max_depth
);
1966 return evd
->callback (orig
, evd
->regs_active
, max_depth
,
1974 /* Copy the various flags, fields, and other information. We assume
1975 that all fields need copying, and then clear the fields that should
1976 not be copied. That is the sensible default behavior, and forces
1977 us to explicitly document why we are *not* copying a flag. */
1981 copy
= shallow_copy_rtx (orig
);
1983 format_ptr
= GET_RTX_FORMAT (code
);
1985 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
1986 switch (*format_ptr
++)
1989 if (XEXP (orig
, i
) != NULL
)
1991 rtx result
= cselib_expand_value_rtx_1 (XEXP (orig
, i
), evd
,
1996 XEXP (copy
, i
) = result
;
2002 if (XVEC (orig
, i
) != NULL
)
2005 XVEC (copy
, i
) = rtvec_alloc (XVECLEN (orig
, i
));
2006 for (j
= 0; j
< XVECLEN (orig
, i
); j
++)
2008 rtx result
= cselib_expand_value_rtx_1 (XVECEXP (orig
, i
, j
),
2009 evd
, max_depth
- 1);
2013 XVECEXP (copy
, i
, j
) = result
;
2027 /* These are left unchanged. */
2037 mode
= GET_MODE (copy
);
2038 /* If an operand has been simplified into CONST_INT, which doesn't
2039 have a mode and the mode isn't derivable from whole rtx's mode,
2040 try simplify_*_operation first with mode from original's operand
2041 and as a fallback wrap CONST_INT into gen_rtx_CONST. */
2043 switch (GET_RTX_CLASS (code
))
2046 if (CONST_INT_P (XEXP (copy
, 0))
2047 && GET_MODE (XEXP (orig
, 0)) != VOIDmode
)
2049 scopy
= simplify_unary_operation (code
, mode
, XEXP (copy
, 0),
2050 GET_MODE (XEXP (orig
, 0)));
2055 case RTX_COMM_ARITH
:
2057 /* These expressions can derive operand modes from the whole rtx's mode. */
2060 case RTX_BITFIELD_OPS
:
2061 if (CONST_INT_P (XEXP (copy
, 0))
2062 && GET_MODE (XEXP (orig
, 0)) != VOIDmode
)
2064 scopy
= simplify_ternary_operation (code
, mode
,
2065 GET_MODE (XEXP (orig
, 0)),
2066 XEXP (copy
, 0), XEXP (copy
, 1),
2073 case RTX_COMM_COMPARE
:
2074 if (CONST_INT_P (XEXP (copy
, 0))
2075 && GET_MODE (XEXP (copy
, 1)) == VOIDmode
2076 && (GET_MODE (XEXP (orig
, 0)) != VOIDmode
2077 || GET_MODE (XEXP (orig
, 1)) != VOIDmode
))
2079 scopy
= simplify_relational_operation (code
, mode
,
2080 (GET_MODE (XEXP (orig
, 0))
2082 ? GET_MODE (XEXP (orig
, 0))
2083 : GET_MODE (XEXP (orig
, 1)),
2093 scopy
= simplify_rtx (copy
);
2099 /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
2100 with VALUE expressions. This way, it becomes independent of changes
2101 to registers and memory.
2102 X isn't actually modified; if modifications are needed, new rtl is
2103 allocated. However, the return value can share rtl with X.
2104 If X is within a MEM, MEMMODE must be the mode of the MEM. */
2107 cselib_subst_to_values (rtx x
, machine_mode memmode
)
2109 enum rtx_code code
= GET_CODE (x
);
2110 const char *fmt
= GET_RTX_FORMAT (code
);
2120 l
= REG_VALUES (REGNO (x
));
2121 if (l
&& l
->elt
== NULL
)
2123 for (; l
; l
= l
->next
)
2124 if (GET_MODE (l
->elt
->val_rtx
) == GET_MODE (x
))
2125 return l
->elt
->val_rtx
;
2130 e
= cselib_lookup_mem (x
, 0);
2131 /* This used to happen for autoincrements, but we deal with them
2132 properly now. Remove the if stmt for the next release. */
2135 /* Assign a value that doesn't match any other. */
2136 e
= new_cselib_val (next_uid
, GET_MODE (x
), x
);
2141 e
= cselib_lookup (x
, GET_MODE (x
), 0, memmode
);
2151 gcc_assert (memmode
!= VOIDmode
);
2152 offset
= GET_MODE_SIZE (memmode
);
2153 if (code
== PRE_DEC
)
2155 return cselib_subst_to_values (plus_constant (GET_MODE (x
),
2156 XEXP (x
, 0), offset
),
2160 gcc_assert (memmode
!= VOIDmode
);
2161 return cselib_subst_to_values (XEXP (x
, 1), memmode
);
2166 gcc_assert (memmode
!= VOIDmode
);
2167 return cselib_subst_to_values (XEXP (x
, 0), memmode
);
2170 if (GET_MODE (x
) == Pmode
&& CONST_INT_P (XEXP (x
, 1)))
2172 rtx t
= cselib_subst_to_values (XEXP (x
, 0), memmode
);
2173 if (GET_CODE (t
) == VALUE
)
2175 if (SP_DERIVED_VALUE_P (t
) && XEXP (x
, 1) == const0_rtx
)
2177 for (struct elt_loc_list
*l
= CSELIB_VAL_PTR (t
)->locs
;
2179 if (GET_CODE (l
->loc
) == PLUS
2180 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
2181 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
2182 && CONST_INT_P (XEXP (l
->loc
, 1)))
2183 return plus_constant (Pmode
, l
->loc
, INTVAL (XEXP (x
, 1)));
2185 if (t
!= XEXP (x
, 0))
2187 copy
= shallow_copy_rtx (x
);
2197 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2201 rtx t
= cselib_subst_to_values (XEXP (x
, i
), memmode
);
2203 if (t
!= XEXP (x
, i
))
2206 copy
= shallow_copy_rtx (x
);
2210 else if (fmt
[i
] == 'E')
2214 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2216 rtx t
= cselib_subst_to_values (XVECEXP (x
, i
, j
), memmode
);
2218 if (t
!= XVECEXP (x
, i
, j
))
2220 if (XVEC (x
, i
) == XVEC (copy
, i
))
2223 copy
= shallow_copy_rtx (x
);
2224 XVEC (copy
, i
) = shallow_copy_rtvec (XVEC (x
, i
));
2226 XVECEXP (copy
, i
, j
) = t
;
2235 /* Wrapper for cselib_subst_to_values, that indicates X is in INSN. */
2238 cselib_subst_to_values_from_insn (rtx x
, machine_mode memmode
, rtx_insn
*insn
)
2241 gcc_assert (!cselib_current_insn
);
2242 cselib_current_insn
= insn
;
2243 ret
= cselib_subst_to_values (x
, memmode
);
2244 cselib_current_insn
= NULL
;
2248 /* Look up the rtl expression X in our tables and return the value it
2249 has. If CREATE is zero, we return NULL if we don't know the value.
2250 Otherwise, we create a new one if possible, using mode MODE if X
2251 doesn't have a mode (i.e. because it's a constant). When X is part
2252 of an address, MEMMODE should be the mode of the enclosing MEM if
2253 we're tracking autoinc expressions. */
2256 cselib_lookup_1 (rtx x
, machine_mode mode
,
2257 int create
, machine_mode memmode
)
2261 unsigned int hashval
;
2263 if (GET_MODE (x
) != VOIDmode
)
2264 mode
= GET_MODE (x
);
2266 if (GET_CODE (x
) == VALUE
)
2267 return CSELIB_VAL_PTR (x
);
2272 unsigned int i
= REGNO (x
);
2275 if (l
&& l
->elt
== NULL
)
2277 for (; l
; l
= l
->next
)
2278 if (mode
== GET_MODE (l
->elt
->val_rtx
))
2280 promote_debug_loc (l
->elt
->locs
);
2287 if (i
< FIRST_PSEUDO_REGISTER
)
2289 unsigned int n
= hard_regno_nregs (i
, mode
);
2291 if (n
> max_value_regs
)
2295 e
= new_cselib_val (next_uid
, GET_MODE (x
), x
);
2296 if (GET_MODE (x
) == Pmode
&& x
== stack_pointer_rtx
)
2297 SP_DERIVED_VALUE_P (e
->val_rtx
) = 1;
2298 new_elt_loc_list (e
, x
);
2300 scalar_int_mode int_mode
;
2301 if (REG_VALUES (i
) == 0)
2303 /* Maintain the invariant that the first entry of
2304 REG_VALUES, if present, must be the value used to set the
2305 register, or NULL. */
2306 used_regs
[n_used_regs
++] = i
;
2307 REG_VALUES (i
) = new_elt_list (REG_VALUES (i
), NULL
);
2309 else if (cselib_preserve_constants
2310 && is_int_mode (mode
, &int_mode
))
2312 /* During var-tracking, try harder to find equivalences
2313 for SUBREGs. If a setter sets say a DImode register
2314 and user uses that register only in SImode, add a lowpart
2316 struct elt_list
*lwider
= NULL
;
2317 scalar_int_mode lmode
;
2319 if (l
&& l
->elt
== NULL
)
2321 for (; l
; l
= l
->next
)
2322 if (is_int_mode (GET_MODE (l
->elt
->val_rtx
), &lmode
)
2323 && GET_MODE_SIZE (lmode
) > GET_MODE_SIZE (int_mode
)
2325 || partial_subreg_p (lmode
,
2326 GET_MODE (lwider
->elt
->val_rtx
))))
2328 struct elt_loc_list
*el
;
2329 if (i
< FIRST_PSEUDO_REGISTER
2330 && hard_regno_nregs (i
, lmode
) != 1)
2332 for (el
= l
->elt
->locs
; el
; el
= el
->next
)
2333 if (!REG_P (el
->loc
))
2340 rtx sub
= lowpart_subreg (int_mode
, lwider
->elt
->val_rtx
,
2341 GET_MODE (lwider
->elt
->val_rtx
));
2343 new_elt_loc_list (e
, sub
);
2346 REG_VALUES (i
)->next
= new_elt_list (REG_VALUES (i
)->next
, e
);
2347 slot
= cselib_find_slot (mode
, x
, e
->hash
, INSERT
, memmode
);
2353 return cselib_lookup_mem (x
, create
);
2355 hashval
= cselib_hash_rtx (x
, create
, memmode
);
2356 /* Can't even create if hashing is not possible. */
2360 slot
= cselib_find_slot (mode
, x
, hashval
,
2361 create
? INSERT
: NO_INSERT
, memmode
);
2365 e
= (cselib_val
*) *slot
;
2369 e
= new_cselib_val (hashval
, mode
, x
);
2371 /* We have to fill the slot before calling cselib_subst_to_values:
2372 the hash table is inconsistent until we do so, and
2373 cselib_subst_to_values will need to do lookups. */
2375 rtx v
= cselib_subst_to_values (x
, memmode
);
2377 /* If cselib_preserve_constants, we might get a SP_DERIVED_VALUE_P
2378 VALUE that isn't in the hash tables anymore. */
2379 if (GET_CODE (v
) == VALUE
&& SP_DERIVED_VALUE_P (v
) && PRESERVED_VALUE_P (v
))
2380 PRESERVED_VALUE_P (e
->val_rtx
) = 1;
2382 new_elt_loc_list (e
, v
);
2386 /* Wrapper for cselib_lookup, that indicates X is in INSN. */
2389 cselib_lookup_from_insn (rtx x
, machine_mode mode
,
2390 int create
, machine_mode memmode
, rtx_insn
*insn
)
2394 gcc_assert (!cselib_current_insn
);
2395 cselib_current_insn
= insn
;
2397 ret
= cselib_lookup (x
, mode
, create
, memmode
);
2399 cselib_current_insn
= NULL
;
2404 /* Wrapper for cselib_lookup_1, that logs the lookup result and
2405 maintains invariants related with debug insns. */
2408 cselib_lookup (rtx x
, machine_mode mode
,
2409 int create
, machine_mode memmode
)
2411 cselib_val
*ret
= cselib_lookup_1 (x
, mode
, create
, memmode
);
2413 /* ??? Should we return NULL if we're not to create an entry, the
2414 found loc is a debug loc and cselib_current_insn is not DEBUG?
2415 If so, we should also avoid converting val to non-DEBUG; probably
2416 easiest setting cselib_current_insn to NULL before the call
2419 if (dump_file
&& (dump_flags
& TDF_CSELIB
))
2421 fputs ("cselib lookup ", dump_file
);
2422 print_inline_rtx (dump_file
, x
, 2);
2423 fprintf (dump_file
, " => %u:%u\n",
2425 ret
? ret
->hash
: 0);
2431 /* Invalidate the value at *L, which is part of REG_VALUES (REGNO). */
2434 cselib_invalidate_regno_val (unsigned int regno
, struct elt_list
**l
)
2436 cselib_val
*v
= (*l
)->elt
;
2437 if (*l
== REG_VALUES (regno
))
2439 /* Maintain the invariant that the first entry of
2440 REG_VALUES, if present, must be the value used to set
2441 the register, or NULL. This is also nice because
2442 then we won't push the same regno onto user_regs
2448 unchain_one_elt_list (l
);
2450 v
= canonical_cselib_val (v
);
2452 bool had_locs
= v
->locs
!= NULL
;
2453 rtx_insn
*setting_insn
= v
->locs
? v
->locs
->setting_insn
: NULL
;
2455 /* Now, we clear the mapping from value to reg. It must exist, so
2456 this code will crash intentionally if it doesn't. */
2457 for (elt_loc_list
**p
= &v
->locs
; ; p
= &(*p
)->next
)
2461 if (REG_P (x
) && REGNO (x
) == regno
)
2463 unchain_one_elt_loc_list (p
);
2468 if (had_locs
&& cselib_useless_value_p (v
))
2470 if (setting_insn
&& DEBUG_INSN_P (setting_insn
))
2471 n_useless_debug_values
++;
2477 /* Invalidate any entries in reg_values that overlap REGNO. This is called
2478 if REGNO is changing. MODE is the mode of the assignment to REGNO, which
2479 is used to determine how many hard registers are being changed. If MODE
2480 is VOIDmode, then only REGNO is being changed; this is used when
2481 invalidating call clobbered registers across a call. */
2484 cselib_invalidate_regno (unsigned int regno
, machine_mode mode
)
2486 unsigned int endregno
;
2489 /* If we see pseudos after reload, something is _wrong_. */
2490 gcc_assert (!reload_completed
|| regno
< FIRST_PSEUDO_REGISTER
2491 || reg_renumber
[regno
] < 0);
2493 /* Determine the range of registers that must be invalidated. For
2494 pseudos, only REGNO is affected. For hard regs, we must take MODE
2495 into account, and we must also invalidate lower register numbers
2496 if they contain values that overlap REGNO. */
2497 if (regno
< FIRST_PSEUDO_REGISTER
)
2499 gcc_assert (mode
!= VOIDmode
);
2501 if (regno
< max_value_regs
)
2504 i
= regno
- max_value_regs
;
2506 endregno
= end_hard_regno (mode
, regno
);
2511 endregno
= regno
+ 1;
2514 for (; i
< endregno
; i
++)
2516 struct elt_list
**l
= ®_VALUES (i
);
2518 /* Go through all known values for this reg; if it overlaps the range
2519 we're invalidating, remove the value. */
2522 cselib_val
*v
= (*l
)->elt
;
2523 unsigned int this_last
= i
;
2525 if (i
< FIRST_PSEUDO_REGISTER
&& v
!= NULL
)
2526 this_last
= end_hard_regno (GET_MODE (v
->val_rtx
), i
) - 1;
2528 if (this_last
< regno
|| v
== NULL
2529 || (v
== cfa_base_preserved_val
2530 && i
== cfa_base_preserved_regno
))
2536 /* We have an overlap. */
2537 cselib_invalidate_regno_val (i
, l
);
2542 /* Invalidate any locations in the table which are changed because of a
2543 store to MEM_RTX. If this is called because of a non-const call
2544 instruction, MEM_RTX is (mem:BLK const0_rtx). */
2547 cselib_invalidate_mem (rtx mem_rtx
)
2549 cselib_val
**vp
, *v
, *next
;
2553 mem_addr
= canon_rtx (get_addr (XEXP (mem_rtx
, 0)));
2554 mem_rtx
= canon_rtx (mem_rtx
);
2556 vp
= &first_containing_mem
;
2557 for (v
= *vp
; v
!= &dummy_val
; v
= next
)
2559 bool has_mem
= false;
2560 struct elt_loc_list
**p
= &v
->locs
;
2561 bool had_locs
= v
->locs
!= NULL
;
2562 rtx_insn
*setting_insn
= v
->locs
? v
->locs
->setting_insn
: NULL
;
2568 struct elt_list
**mem_chain
;
2570 /* MEMs may occur in locations only at the top level; below
2571 that every MEM or REG is substituted by its VALUE. */
2577 if (num_mems
< param_max_cselib_memory_locations
2578 && ! canon_anti_dependence (x
, false, mem_rtx
,
2579 GET_MODE (mem_rtx
), mem_addr
))
2587 /* This one overlaps. */
2588 /* We must have a mapping from this MEM's address to the
2589 value (E). Remove that, too. */
2590 addr
= cselib_lookup (XEXP (x
, 0), VOIDmode
, 0, GET_MODE (x
));
2591 addr
= canonical_cselib_val (addr
);
2592 gcc_checking_assert (v
== canonical_cselib_val (v
));
2593 mem_chain
= &addr
->addr_list
;
2596 cselib_val
*canon
= canonical_cselib_val ((*mem_chain
)->elt
);
2600 unchain_one_elt_list (mem_chain
);
2604 /* Record canonicalized elt. */
2605 (*mem_chain
)->elt
= canon
;
2607 mem_chain
= &(*mem_chain
)->next
;
2610 unchain_one_elt_loc_list (p
);
2613 if (had_locs
&& cselib_useless_value_p (v
))
2615 if (setting_insn
&& DEBUG_INSN_P (setting_insn
))
2616 n_useless_debug_values
++;
2621 next
= v
->next_containing_mem
;
2625 vp
= &(*vp
)->next_containing_mem
;
2628 v
->next_containing_mem
= NULL
;
2633 /* Invalidate DEST. */
2636 cselib_invalidate_rtx (rtx dest
)
2638 while (GET_CODE (dest
) == SUBREG
2639 || GET_CODE (dest
) == ZERO_EXTRACT
2640 || GET_CODE (dest
) == STRICT_LOW_PART
)
2641 dest
= XEXP (dest
, 0);
2644 cselib_invalidate_regno (REGNO (dest
), GET_MODE (dest
));
2645 else if (MEM_P (dest
))
2646 cselib_invalidate_mem (dest
);
2649 /* A wrapper for cselib_invalidate_rtx to be called via note_stores. */
2652 cselib_invalidate_rtx_note_stores (rtx dest
, const_rtx
,
2653 void *data ATTRIBUTE_UNUSED
)
2655 cselib_invalidate_rtx (dest
);
2658 /* Record the result of a SET instruction. DEST is being set; the source
2659 contains the value described by SRC_ELT. If DEST is a MEM, DEST_ADDR_ELT
2660 describes its address. */
2663 cselib_record_set (rtx dest
, cselib_val
*src_elt
, cselib_val
*dest_addr_elt
)
2665 if (src_elt
== 0 || side_effects_p (dest
))
2670 unsigned int dreg
= REGNO (dest
);
2671 if (dreg
< FIRST_PSEUDO_REGISTER
)
2673 unsigned int n
= REG_NREGS (dest
);
2675 if (n
> max_value_regs
)
2679 if (REG_VALUES (dreg
) == 0)
2681 used_regs
[n_used_regs
++] = dreg
;
2682 REG_VALUES (dreg
) = new_elt_list (REG_VALUES (dreg
), src_elt
);
2686 /* The register should have been invalidated. */
2687 gcc_assert (REG_VALUES (dreg
)->elt
== 0);
2688 REG_VALUES (dreg
)->elt
= src_elt
;
2691 if (cselib_useless_value_p (src_elt
))
2693 new_elt_loc_list (src_elt
, dest
);
2695 else if (MEM_P (dest
) && dest_addr_elt
!= 0
2696 && cselib_record_memory
)
2698 if (cselib_useless_value_p (src_elt
))
2700 add_mem_for_addr (dest_addr_elt
, src_elt
, dest
);
2704 /* Make ELT and X's VALUE equivalent to each other at INSN. */
2707 cselib_add_permanent_equiv (cselib_val
*elt
, rtx x
, rtx_insn
*insn
)
2710 rtx_insn
*save_cselib_current_insn
= cselib_current_insn
;
2712 gcc_checking_assert (elt
);
2713 gcc_checking_assert (PRESERVED_VALUE_P (elt
->val_rtx
));
2714 gcc_checking_assert (!side_effects_p (x
));
2716 cselib_current_insn
= insn
;
2718 nelt
= cselib_lookup (x
, GET_MODE (elt
->val_rtx
), 1, VOIDmode
);
2722 cselib_any_perm_equivs
= true;
2724 if (!PRESERVED_VALUE_P (nelt
->val_rtx
))
2725 cselib_preserve_value (nelt
);
2727 new_elt_loc_list (nelt
, elt
->val_rtx
);
2730 cselib_current_insn
= save_cselib_current_insn
;
2733 /* Return TRUE if any permanent equivalences have been recorded since
2734 the table was last initialized. */
2736 cselib_have_permanent_equivalences (void)
2738 return cselib_any_perm_equivs
;
2741 /* Record stack_pointer_rtx to be equal to
2742 (plus:P cfa_base_preserved_val offset). Used by var-tracking
2743 at the start of basic blocks for !frame_pointer_needed functions. */
2746 cselib_record_sp_cfa_base_equiv (HOST_WIDE_INT offset
, rtx_insn
*insn
)
2748 rtx sp_derived_value
= NULL_RTX
;
2749 for (struct elt_loc_list
*l
= cfa_base_preserved_val
->locs
; l
; l
= l
->next
)
2750 if (GET_CODE (l
->loc
) == VALUE
2751 && SP_DERIVED_VALUE_P (l
->loc
))
2753 sp_derived_value
= l
->loc
;
2756 else if (GET_CODE (l
->loc
) == PLUS
2757 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
2758 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
2759 && CONST_INT_P (XEXP (l
->loc
, 1)))
2761 sp_derived_value
= XEXP (l
->loc
, 0);
2762 offset
= offset
+ UINTVAL (XEXP (l
->loc
, 1));
2765 if (sp_derived_value
== NULL_RTX
)
2768 = cselib_lookup_from_insn (plus_constant (Pmode
, sp_derived_value
, offset
),
2769 Pmode
, 1, VOIDmode
, insn
);
2772 PRESERVED_VALUE_P (val
->val_rtx
) = 1;
2773 cselib_record_set (stack_pointer_rtx
, val
, NULL
);
2777 /* Return true if V is SP_DERIVED_VALUE_P (or SP_DERIVED_VALUE_P + CONST_INT)
2778 that can be expressed using cfa_base_preserved_val + CONST_INT. */
2781 cselib_sp_derived_value_p (cselib_val
*v
)
2783 if (!SP_DERIVED_VALUE_P (v
->val_rtx
))
2784 for (struct elt_loc_list
*l
= v
->locs
; l
; l
= l
->next
)
2785 if (GET_CODE (l
->loc
) == PLUS
2786 && GET_CODE (XEXP (l
->loc
, 0)) == VALUE
2787 && SP_DERIVED_VALUE_P (XEXP (l
->loc
, 0))
2788 && CONST_INT_P (XEXP (l
->loc
, 1)))
2789 v
= CSELIB_VAL_PTR (XEXP (l
->loc
, 0));
2790 if (!SP_DERIVED_VALUE_P (v
->val_rtx
))
2792 for (struct elt_loc_list
*l
= v
->locs
; l
; l
= l
->next
)
2793 if (l
->loc
== cfa_base_preserved_val
->val_rtx
)
2795 else if (GET_CODE (l
->loc
) == PLUS
2796 && XEXP (l
->loc
, 0) == cfa_base_preserved_val
->val_rtx
2797 && CONST_INT_P (XEXP (l
->loc
, 1)))
2802 /* There is no good way to determine how many elements there can be
2803 in a PARALLEL. Since it's fairly cheap, use a really large number. */
2804 #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
2806 struct cselib_record_autoinc_data
2808 struct cselib_set
*sets
;
2812 /* Callback for for_each_inc_dec. Records in ARG the SETs implied by
2813 autoinc RTXs: SRC plus SRCOFF if non-NULL is stored in DEST. */
2816 cselib_record_autoinc_cb (rtx mem ATTRIBUTE_UNUSED
, rtx op ATTRIBUTE_UNUSED
,
2817 rtx dest
, rtx src
, rtx srcoff
, void *arg
)
2819 struct cselib_record_autoinc_data
*data
;
2820 data
= (struct cselib_record_autoinc_data
*)arg
;
2822 data
->sets
[data
->n_sets
].dest
= dest
;
2825 data
->sets
[data
->n_sets
].src
= gen_rtx_PLUS (GET_MODE (src
), src
, srcoff
);
2827 data
->sets
[data
->n_sets
].src
= src
;
2834 /* Record the effects of any sets and autoincs in INSN. */
2836 cselib_record_sets (rtx_insn
*insn
)
2840 struct cselib_set sets
[MAX_SETS
];
2842 int n_sets_before_autoinc
;
2843 int n_strict_low_parts
= 0;
2844 struct cselib_record_autoinc_data data
;
2846 rtx body
= PATTERN (insn
);
2847 if (GET_CODE (body
) == COND_EXEC
)
2849 cond
= COND_EXEC_TEST (body
);
2850 body
= COND_EXEC_CODE (body
);
2853 /* Find all sets. */
2854 if (GET_CODE (body
) == SET
)
2856 sets
[0].src
= SET_SRC (body
);
2857 sets
[0].dest
= SET_DEST (body
);
2860 else if (GET_CODE (body
) == PARALLEL
)
2862 /* Look through the PARALLEL and record the values being
2863 set, if possible. Also handle any CLOBBERs. */
2864 for (i
= XVECLEN (body
, 0) - 1; i
>= 0; --i
)
2866 rtx x
= XVECEXP (body
, 0, i
);
2868 if (GET_CODE (x
) == SET
)
2870 sets
[n_sets
].src
= SET_SRC (x
);
2871 sets
[n_sets
].dest
= SET_DEST (x
);
2878 && MEM_P (sets
[0].src
)
2879 && !cselib_record_memory
2880 && MEM_READONLY_P (sets
[0].src
))
2882 rtx note
= find_reg_equal_equiv_note (insn
);
2884 if (note
&& CONSTANT_P (XEXP (note
, 0)))
2885 sets
[0].src
= XEXP (note
, 0);
2889 data
.n_sets
= n_sets_before_autoinc
= n_sets
;
2890 for_each_inc_dec (PATTERN (insn
), cselib_record_autoinc_cb
, &data
);
2891 n_sets
= data
.n_sets
;
2893 /* Look up the values that are read. Do this before invalidating the
2894 locations that are written. */
2895 for (i
= 0; i
< n_sets
; i
++)
2897 rtx dest
= sets
[i
].dest
;
2900 /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
2901 the low part after invalidating any knowledge about larger modes. */
2902 if (GET_CODE (sets
[i
].dest
) == STRICT_LOW_PART
)
2903 sets
[i
].dest
= dest
= XEXP (dest
, 0);
2905 /* We don't know how to record anything but REG or MEM. */
2907 || (MEM_P (dest
) && cselib_record_memory
))
2909 rtx src
= sets
[i
].src
;
2911 src
= gen_rtx_IF_THEN_ELSE (GET_MODE (dest
), cond
, src
, dest
);
2912 sets
[i
].src_elt
= cselib_lookup (src
, GET_MODE (dest
), 1, VOIDmode
);
2915 machine_mode address_mode
= get_address_mode (dest
);
2917 sets
[i
].dest_addr_elt
= cselib_lookup (XEXP (dest
, 0),
2922 sets
[i
].dest_addr_elt
= 0;
2925 /* Improve handling of STRICT_LOW_PART if the current value is known
2926 to be const0_rtx, then the low bits will be set to dest and higher
2927 bits will remain zero. Used in code like:
2929 {di:SI=0;clobber flags:CC;}
2930 flags:CCNO=cmp(bx:SI,0)
2931 strict_low_part(di:QI)=flags:CCNO<=0
2933 where we can note both that di:QI=flags:CCNO<=0 and
2934 also that because di:SI is known to be 0 and strict_low_part(di:QI)
2935 preserves the upper bits that di:SI=zero_extend(flags:CCNO<=0). */
2936 scalar_int_mode mode
;
2938 && cselib_record_sets_hook
2940 && HARD_REGISTER_P (dest
)
2942 && is_a
<scalar_int_mode
> (GET_MODE (dest
), &mode
)
2943 && n_sets
+ n_strict_low_parts
< MAX_SETS
)
2945 opt_scalar_int_mode wider_mode_iter
;
2946 FOR_EACH_WIDER_MODE (wider_mode_iter
, mode
)
2948 scalar_int_mode wider_mode
= wider_mode_iter
.require ();
2949 if (GET_MODE_PRECISION (wider_mode
) > BITS_PER_WORD
)
2952 rtx reg
= gen_lowpart (wider_mode
, dest
);
2956 cselib_val
*v
= cselib_lookup (reg
, wider_mode
, 0, VOIDmode
);
2960 struct elt_loc_list
*l
;
2961 for (l
= v
->locs
; l
; l
= l
->next
)
2962 if (l
->loc
== const0_rtx
)
2968 sets
[n_sets
+ n_strict_low_parts
].dest
= reg
;
2969 sets
[n_sets
+ n_strict_low_parts
].src
= dest
;
2970 sets
[n_sets
+ n_strict_low_parts
++].src_elt
= sets
[i
].src_elt
;
2976 if (cselib_record_sets_hook
)
2977 cselib_record_sets_hook (insn
, sets
, n_sets
);
2979 /* Invalidate all locations written by this insn. Note that the elts we
2980 looked up in the previous loop aren't affected, just some of their
2981 locations may go away. */
2982 note_pattern_stores (body
, cselib_invalidate_rtx_note_stores
, NULL
);
2984 for (i
= n_sets_before_autoinc
; i
< n_sets
; i
++)
2985 cselib_invalidate_rtx (sets
[i
].dest
);
2987 /* If this is an asm, look for duplicate sets. This can happen when the
2988 user uses the same value as an output multiple times. This is valid
2989 if the outputs are not actually used thereafter. Treat this case as
2990 if the value isn't actually set. We do this by smashing the destination
2991 to pc_rtx, so that we won't record the value later. */
2992 if (n_sets
>= 2 && asm_noperands (body
) >= 0)
2994 for (i
= 0; i
< n_sets
; i
++)
2996 rtx dest
= sets
[i
].dest
;
2997 if (REG_P (dest
) || MEM_P (dest
))
3000 for (j
= i
+ 1; j
< n_sets
; j
++)
3001 if (rtx_equal_p (dest
, sets
[j
].dest
))
3003 sets
[i
].dest
= pc_rtx
;
3004 sets
[j
].dest
= pc_rtx
;
3010 /* Now enter the equivalences in our tables. */
3011 for (i
= 0; i
< n_sets
; i
++)
3013 rtx dest
= sets
[i
].dest
;
3015 || (MEM_P (dest
) && cselib_record_memory
))
3016 cselib_record_set (dest
, sets
[i
].src_elt
, sets
[i
].dest_addr_elt
);
3019 /* And deal with STRICT_LOW_PART. */
3020 for (i
= 0; i
< n_strict_low_parts
; i
++)
3022 if (! PRESERVED_VALUE_P (sets
[n_sets
+ i
].src_elt
->val_rtx
))
3024 machine_mode dest_mode
= GET_MODE (sets
[n_sets
+ i
].dest
);
3026 = cselib_lookup (sets
[n_sets
+ i
].dest
, dest_mode
, 1, VOIDmode
);
3027 cselib_preserve_value (v
);
3028 rtx r
= gen_rtx_ZERO_EXTEND (dest_mode
,
3029 sets
[n_sets
+ i
].src_elt
->val_rtx
);
3030 cselib_add_permanent_equiv (v
, r
, insn
);
3034 /* Return true if INSN in the prologue initializes hard_frame_pointer_rtx. */
3037 fp_setter_insn (rtx_insn
*insn
)
3039 rtx expr
, pat
= NULL_RTX
;
3041 if (!RTX_FRAME_RELATED_P (insn
))
3044 expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
3046 pat
= XEXP (expr
, 0);
3047 if (!modified_in_p (hard_frame_pointer_rtx
, pat
? pat
: insn
))
3050 /* Don't return true for frame pointer restores in the epilogue. */
3051 if (find_reg_note (insn
, REG_CFA_RESTORE
, hard_frame_pointer_rtx
))
3056 /* V is one of the values in REG_VALUES (REGNO). Return true if it
3057 would be invalidated by CALLEE_ABI. */
3060 cselib_invalidated_by_call_p (const function_abi
&callee_abi
,
3061 unsigned int regno
, cselib_val
*v
)
3063 machine_mode mode
= GET_MODE (v
->val_rtx
);
3064 if (mode
== VOIDmode
)
3066 v
= REG_VALUES (regno
)->elt
;
3068 /* If we don't know what the mode of the constant value is, and we
3069 don't know what mode the register was set in, conservatively
3070 assume that the register is clobbered. The value's going to be
3071 essentially useless in this case anyway. */
3073 mode
= GET_MODE (v
->val_rtx
);
3075 return callee_abi
.clobbers_reg_p (mode
, regno
);
3078 /* Record the effects of INSN. */
3081 cselib_process_insn (rtx_insn
*insn
)
3086 cselib_current_insn
= insn
;
3088 /* Forget everything at a CODE_LABEL or a setjmp. */
3091 && find_reg_note (insn
, REG_SETJMP
, NULL
)))
3092 && !cselib_preserve_constants
)
3094 cselib_reset_table (next_uid
);
3095 cselib_current_insn
= NULL
;
3099 if (! INSN_P (insn
))
3101 cselib_current_insn
= NULL
;
3105 /* If this is a call instruction, forget anything stored in a
3106 call clobbered register, or, if this is not a const call, in
3110 function_abi callee_abi
= insn_callee_abi (insn
);
3111 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3113 elt_list
**l
= ®_VALUES (i
);
3116 cselib_val
*v
= (*l
)->elt
;
3117 if (v
&& cselib_invalidated_by_call_p (callee_abi
, i
, v
))
3118 cselib_invalidate_regno_val (i
, l
);
3124 /* Since it is not clear how cselib is going to be used, be
3125 conservative here and treat looping pure or const functions
3126 as if they were regular functions. */
3127 if (RTL_LOOPING_CONST_OR_PURE_CALL_P (insn
)
3128 || !(RTL_CONST_OR_PURE_CALL_P (insn
)))
3129 cselib_invalidate_mem (callmem
);
3131 /* For const/pure calls, invalidate any argument slots because
3132 they are owned by the callee. */
3133 for (x
= CALL_INSN_FUNCTION_USAGE (insn
); x
; x
= XEXP (x
, 1))
3134 if (GET_CODE (XEXP (x
, 0)) == USE
3135 && MEM_P (XEXP (XEXP (x
, 0), 0)))
3136 cselib_invalidate_mem (XEXP (XEXP (x
, 0), 0));
3139 cselib_record_sets (insn
);
3141 /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
3142 after we have processed the insn. */
3145 for (x
= CALL_INSN_FUNCTION_USAGE (insn
); x
; x
= XEXP (x
, 1))
3146 if (GET_CODE (XEXP (x
, 0)) == CLOBBER
)
3147 cselib_invalidate_rtx (XEXP (XEXP (x
, 0), 0));
3149 /* Flush everything on setjmp. */
3150 if (cselib_preserve_constants
3151 && find_reg_note (insn
, REG_SETJMP
, NULL
))
3153 cselib_preserve_only_values ();
3154 cselib_reset_table (next_uid
);
3158 /* On setter of the hard frame pointer if frame_pointer_needed,
3159 invalidate stack_pointer_rtx, so that sp and {,h}fp based
3160 VALUEs are distinct. */
3161 if (reload_completed
3162 && frame_pointer_needed
3163 && fp_setter_insn (insn
))
3164 cselib_invalidate_rtx (stack_pointer_rtx
);
3166 cselib_current_insn
= NULL
;
3168 if (n_useless_values
> MAX_USELESS_VALUES
3169 /* remove_useless_values is linear in the hash table size. Avoid
3170 quadratic behavior for very large hashtables with very few
3171 useless elements. */
3172 && ((unsigned int)n_useless_values
3173 > (cselib_hash_table
->elements () - n_debug_values
) / 4))
3174 remove_useless_values ();
3177 /* Initialize cselib for one pass. The caller must also call
3178 init_alias_analysis. */
3181 cselib_init (int record_what
)
3183 cselib_record_memory
= record_what
& CSELIB_RECORD_MEMORY
;
3184 cselib_preserve_constants
= record_what
& CSELIB_PRESERVE_CONSTANTS
;
3185 cselib_any_perm_equivs
= false;
3187 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything,
3188 see canon_true_dependence. This is only created once. */
3190 callmem
= gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
));
3192 cselib_nregs
= max_reg_num ();
3194 /* We preserve reg_values to allow expensive clearing of the whole thing.
3195 Reallocate it however if it happens to be too large. */
3196 if (!reg_values
|| reg_values_size
< cselib_nregs
3197 || (reg_values_size
> 10 && reg_values_size
> cselib_nregs
* 4))
3200 /* Some space for newly emit instructions so we don't end up
3201 reallocating in between passes. */
3202 reg_values_size
= cselib_nregs
+ (63 + cselib_nregs
) / 16;
3203 reg_values
= XCNEWVEC (struct elt_list
*, reg_values_size
);
3205 used_regs
= XNEWVEC (unsigned int, cselib_nregs
);
3207 /* FIXME: enable sanitization (PR87845) */
3209 = new hash_table
<cselib_hasher
> (31, /* ggc */ false,
3210 /* sanitize_eq_and_hash */ false);
3211 if (cselib_preserve_constants
)
3212 cselib_preserved_hash_table
3213 = new hash_table
<cselib_hasher
> (31, /* ggc */ false,
3214 /* sanitize_eq_and_hash */ false);
3218 /* Called when the current user is done with cselib. */
3221 cselib_finish (void)
3223 bool preserved
= cselib_preserve_constants
;
3224 cselib_discard_hook
= NULL
;
3225 cselib_preserve_constants
= false;
3226 cselib_any_perm_equivs
= false;
3227 cfa_base_preserved_val
= NULL
;
3228 cfa_base_preserved_regno
= INVALID_REGNUM
;
3229 elt_list_pool
.release ();
3230 elt_loc_list_pool
.release ();
3231 cselib_val_pool
.release ();
3232 value_pool
.release ();
3233 cselib_clear_table ();
3234 delete cselib_hash_table
;
3235 cselib_hash_table
= NULL
;
3237 delete cselib_preserved_hash_table
;
3238 cselib_preserved_hash_table
= NULL
;
3241 n_useless_values
= 0;
3242 n_useless_debug_values
= 0;
3247 /* Dump the cselib_val *X to FILE *OUT. */
3250 dump_cselib_val (cselib_val
**x
, FILE *out
)
3253 bool need_lf
= true;
3255 print_inline_rtx (out
, v
->val_rtx
, 0);
3259 struct elt_loc_list
*l
= v
->locs
;
3265 fputs (" locs:", out
);
3268 if (l
->setting_insn
)
3269 fprintf (out
, "\n from insn %i ",
3270 INSN_UID (l
->setting_insn
));
3272 fprintf (out
, "\n ");
3273 print_inline_rtx (out
, l
->loc
, 4);
3275 while ((l
= l
->next
));
3280 fputs (" no locs", out
);
3286 struct elt_list
*e
= v
->addr_list
;
3292 fputs (" addr list:", out
);
3296 print_inline_rtx (out
, e
->elt
->val_rtx
, 2);
3298 while ((e
= e
->next
));
3303 fputs (" no addrs", out
);
3307 if (v
->next_containing_mem
== &dummy_val
)
3308 fputs (" last mem\n", out
);
3309 else if (v
->next_containing_mem
)
3311 fputs (" next mem ", out
);
3312 print_inline_rtx (out
, v
->next_containing_mem
->val_rtx
, 2);
3321 /* Dump to OUT everything in the CSELIB table. */
3324 dump_cselib_table (FILE *out
)
3326 fprintf (out
, "cselib hash table:\n");
3327 cselib_hash_table
->traverse
<FILE *, dump_cselib_val
> (out
);
3328 fprintf (out
, "cselib preserved hash table:\n");
3329 cselib_preserved_hash_table
->traverse
<FILE *, dump_cselib_val
> (out
);
3330 if (first_containing_mem
!= &dummy_val
)
3332 fputs ("first mem ", out
);
3333 print_inline_rtx (out
, first_containing_mem
->val_rtx
, 2);
3336 fprintf (out
, "next uid %i\n", next_uid
);
3339 #include "gt-cselib.h"