Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / cselib.c
blob05029fa286ce04984ba10c11f667967278529d12
1 /* Common subexpression elimination library for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
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 3, or (at your option) any later
11 version.
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.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "flags.h"
32 #include "insn-config.h"
33 #include "recog.h"
34 #include "function.h"
35 #include "emit-rtl.h"
36 #include "diagnostic-core.h"
37 #include "toplev.h"
38 #include "output.h"
39 #include "ggc.h"
40 #include "hashtab.h"
41 #include "tree-pass.h"
42 #include "cselib.h"
43 #include "params.h"
44 #include "alloc-pool.h"
45 #include "target.h"
46 #include "bitmap.h"
48 static bool cselib_record_memory;
49 static bool cselib_preserve_constants;
50 static int entry_and_rtx_equal_p (const void *, const void *);
51 static hashval_t get_value_hash (const void *);
52 static struct elt_list *new_elt_list (struct elt_list *, cselib_val *);
53 static struct elt_loc_list *new_elt_loc_list (struct elt_loc_list *, rtx);
54 static void unchain_one_value (cselib_val *);
55 static void unchain_one_elt_list (struct elt_list **);
56 static void unchain_one_elt_loc_list (struct elt_loc_list **);
57 static int discard_useless_locs (void **, void *);
58 static int discard_useless_values (void **, void *);
59 static void remove_useless_values (void);
60 static unsigned int cselib_hash_rtx (rtx, int);
61 static cselib_val *new_cselib_val (unsigned int, enum machine_mode, rtx);
62 static void add_mem_for_addr (cselib_val *, cselib_val *, rtx);
63 static cselib_val *cselib_lookup_mem (rtx, int);
64 static void cselib_invalidate_regno (unsigned int, enum machine_mode);
65 static void cselib_invalidate_mem (rtx);
66 static void cselib_record_set (rtx, cselib_val *, cselib_val *);
67 static void cselib_record_sets (rtx);
69 struct expand_value_data
71 bitmap regs_active;
72 cselib_expand_callback callback;
73 void *callback_arg;
74 bool dummy;
77 static rtx cselib_expand_value_rtx_1 (rtx, struct expand_value_data *, int);
79 /* There are three ways in which cselib can look up an rtx:
80 - for a REG, the reg_values table (which is indexed by regno) is used
81 - for a MEM, we recursively look up its address and then follow the
82 addr_list of that value
83 - for everything else, we compute a hash value and go through the hash
84 table. Since different rtx's can still have the same hash value,
85 this involves walking the table entries for a given value and comparing
86 the locations of the entries with the rtx we are looking up. */
88 /* A table that enables us to look up elts by their value. */
89 static htab_t cselib_hash_table;
91 /* This is a global so we don't have to pass this through every function.
92 It is used in new_elt_loc_list to set SETTING_INSN. */
93 static rtx cselib_current_insn;
95 /* The unique id that the next create value will take. */
96 static unsigned int next_uid;
98 /* The number of registers we had when the varrays were last resized. */
99 static unsigned int cselib_nregs;
101 /* Count values without known locations, or with only locations that
102 wouldn't have been known except for debug insns. Whenever this
103 grows too big, we remove these useless values from the table.
105 Counting values with only debug values is a bit tricky. We don't
106 want to increment n_useless_values when we create a value for a
107 debug insn, for this would get n_useless_values out of sync, but we
108 want increment it if all locs in the list that were ever referenced
109 in nondebug insns are removed from the list.
111 In the general case, once we do that, we'd have to stop accepting
112 nondebug expressions in the loc list, to avoid having two values
113 equivalent that, without debug insns, would have been made into
114 separate values. However, because debug insns never introduce
115 equivalences themselves (no assignments), the only means for
116 growing loc lists is through nondebug assignments. If the locs
117 also happen to be referenced in debug insns, it will work just fine.
119 A consequence of this is that there's at most one debug-only loc in
120 each loc list. If we keep it in the first entry, testing whether
121 we have a debug-only loc list takes O(1).
123 Furthermore, since any additional entry in a loc list containing a
124 debug loc would have to come from an assignment (nondebug) that
125 references both the initial debug loc and the newly-equivalent loc,
126 the initial debug loc would be promoted to a nondebug loc, and the
127 loc list would not contain debug locs any more.
129 So the only case we have to be careful with in order to keep
130 n_useless_values in sync between debug and nondebug compilations is
131 to avoid incrementing n_useless_values when removing the single loc
132 from a value that turns out to not appear outside debug values. We
133 increment n_useless_debug_values instead, and leave such values
134 alone until, for other reasons, we garbage-collect useless
135 values. */
136 static int n_useless_values;
137 static int n_useless_debug_values;
139 /* Count values whose locs have been taken exclusively from debug
140 insns for the entire life of the value. */
141 static int n_debug_values;
143 /* Number of useless values before we remove them from the hash table. */
144 #define MAX_USELESS_VALUES 32
146 /* This table maps from register number to values. It does not
147 contain pointers to cselib_val structures, but rather elt_lists.
148 The purpose is to be able to refer to the same register in
149 different modes. The first element of the list defines the mode in
150 which the register was set; if the mode is unknown or the value is
151 no longer valid in that mode, ELT will be NULL for the first
152 element. */
153 static struct elt_list **reg_values;
154 static unsigned int reg_values_size;
155 #define REG_VALUES(i) reg_values[i]
157 /* The largest number of hard regs used by any entry added to the
158 REG_VALUES table. Cleared on each cselib_clear_table() invocation. */
159 static unsigned int max_value_regs;
161 /* Here the set of indices I with REG_VALUES(I) != 0 is saved. This is used
162 in cselib_clear_table() for fast emptying. */
163 static unsigned int *used_regs;
164 static unsigned int n_used_regs;
166 /* We pass this to cselib_invalidate_mem to invalidate all of
167 memory for a non-const call instruction. */
168 static GTY(()) rtx callmem;
170 /* Set by discard_useless_locs if it deleted the last location of any
171 value. */
172 static int values_became_useless;
174 /* Used as stop element of the containing_mem list so we can check
175 presence in the list by checking the next pointer. */
176 static cselib_val dummy_val;
178 /* If non-NULL, value of the eliminated arg_pointer_rtx or frame_pointer_rtx
179 that is constant through the whole function and should never be
180 eliminated. */
181 static cselib_val *cfa_base_preserved_val;
182 static unsigned int cfa_base_preserved_regno;
184 /* Used to list all values that contain memory reference.
185 May or may not contain the useless values - the list is compacted
186 each time memory is invalidated. */
187 static cselib_val *first_containing_mem = &dummy_val;
188 static alloc_pool elt_loc_list_pool, elt_list_pool, cselib_val_pool, value_pool;
190 /* If nonnull, cselib will call this function before freeing useless
191 VALUEs. A VALUE is deemed useless if its "locs" field is null. */
192 void (*cselib_discard_hook) (cselib_val *);
194 /* If nonnull, cselib will call this function before recording sets or
195 even clobbering outputs of INSN. All the recorded sets will be
196 represented in the array sets[n_sets]. new_val_min can be used to
197 tell whether values present in sets are introduced by this
198 instruction. */
199 void (*cselib_record_sets_hook) (rtx insn, struct cselib_set *sets,
200 int n_sets);
202 #define PRESERVED_VALUE_P(RTX) \
203 (RTL_FLAG_CHECK1("PRESERVED_VALUE_P", (RTX), VALUE)->unchanging)
207 /* Allocate a struct elt_list and fill in its two elements with the
208 arguments. */
210 static inline struct elt_list *
211 new_elt_list (struct elt_list *next, cselib_val *elt)
213 struct elt_list *el;
214 el = (struct elt_list *) pool_alloc (elt_list_pool);
215 el->next = next;
216 el->elt = elt;
217 return el;
220 /* Allocate a struct elt_loc_list and fill in its two elements with the
221 arguments. */
223 static inline struct elt_loc_list *
224 new_elt_loc_list (struct elt_loc_list *next, rtx loc)
226 struct elt_loc_list *el;
227 el = (struct elt_loc_list *) pool_alloc (elt_loc_list_pool);
228 el->next = next;
229 el->loc = loc;
230 el->setting_insn = cselib_current_insn;
231 gcc_assert (!next || !next->setting_insn
232 || !DEBUG_INSN_P (next->setting_insn));
234 /* If we're creating the first loc in a debug insn context, we've
235 just created a debug value. Count it. */
236 if (!next && cselib_current_insn && DEBUG_INSN_P (cselib_current_insn))
237 n_debug_values++;
239 return el;
242 /* Promote loc L to a nondebug cselib_current_insn if L is marked as
243 originating from a debug insn, maintaining the debug values
244 count. */
246 static inline void
247 promote_debug_loc (struct elt_loc_list *l)
249 if (l->setting_insn && DEBUG_INSN_P (l->setting_insn)
250 && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
252 n_debug_values--;
253 l->setting_insn = cselib_current_insn;
254 gcc_assert (!l->next);
258 /* The elt_list at *PL is no longer needed. Unchain it and free its
259 storage. */
261 static inline void
262 unchain_one_elt_list (struct elt_list **pl)
264 struct elt_list *l = *pl;
266 *pl = l->next;
267 pool_free (elt_list_pool, l);
270 /* Likewise for elt_loc_lists. */
272 static void
273 unchain_one_elt_loc_list (struct elt_loc_list **pl)
275 struct elt_loc_list *l = *pl;
277 *pl = l->next;
278 pool_free (elt_loc_list_pool, l);
281 /* Likewise for cselib_vals. This also frees the addr_list associated with
282 V. */
284 static void
285 unchain_one_value (cselib_val *v)
287 while (v->addr_list)
288 unchain_one_elt_list (&v->addr_list);
290 pool_free (cselib_val_pool, v);
293 /* Remove all entries from the hash table. Also used during
294 initialization. */
296 void
297 cselib_clear_table (void)
299 cselib_reset_table (1);
302 /* Remove from hash table all VALUEs except constants. */
304 static int
305 preserve_only_constants (void **x, void *info ATTRIBUTE_UNUSED)
307 cselib_val *v = (cselib_val *)*x;
309 if (v->locs != NULL
310 && v->locs->next == NULL)
312 if (CONSTANT_P (v->locs->loc)
313 && (GET_CODE (v->locs->loc) != CONST
314 || !references_value_p (v->locs->loc, 0)))
315 return 1;
316 if (cfa_base_preserved_val)
318 if (v == cfa_base_preserved_val)
319 return 1;
320 if (GET_CODE (v->locs->loc) == PLUS
321 && CONST_INT_P (XEXP (v->locs->loc, 1))
322 && XEXP (v->locs->loc, 0) == cfa_base_preserved_val->val_rtx)
323 return 1;
327 htab_clear_slot (cselib_hash_table, x);
328 return 1;
331 /* Remove all entries from the hash table, arranging for the next
332 value to be numbered NUM. */
334 void
335 cselib_reset_table (unsigned int num)
337 unsigned int i;
339 max_value_regs = 0;
341 if (cfa_base_preserved_val)
343 unsigned int regno = cfa_base_preserved_regno;
344 unsigned int new_used_regs = 0;
345 for (i = 0; i < n_used_regs; i++)
346 if (used_regs[i] == regno)
348 new_used_regs = 1;
349 continue;
351 else
352 REG_VALUES (used_regs[i]) = 0;
353 gcc_assert (new_used_regs == 1);
354 n_used_regs = new_used_regs;
355 used_regs[0] = regno;
356 max_value_regs
357 = hard_regno_nregs[regno][GET_MODE (cfa_base_preserved_val->locs->loc)];
359 else
361 for (i = 0; i < n_used_regs; i++)
362 REG_VALUES (used_regs[i]) = 0;
363 n_used_regs = 0;
366 if (cselib_preserve_constants)
367 htab_traverse (cselib_hash_table, preserve_only_constants, NULL);
368 else
369 htab_empty (cselib_hash_table);
371 n_useless_values = 0;
372 n_useless_debug_values = 0;
373 n_debug_values = 0;
375 next_uid = num;
377 first_containing_mem = &dummy_val;
380 /* Return the number of the next value that will be generated. */
382 unsigned int
383 cselib_get_next_uid (void)
385 return next_uid;
388 /* The equality test for our hash table. The first argument ENTRY is a table
389 element (i.e. a cselib_val), while the second arg X is an rtx. We know
390 that all callers of htab_find_slot_with_hash will wrap CONST_INTs into a
391 CONST of an appropriate mode. */
393 static int
394 entry_and_rtx_equal_p (const void *entry, const void *x_arg)
396 struct elt_loc_list *l;
397 const cselib_val *const v = (const cselib_val *) entry;
398 rtx x = CONST_CAST_RTX ((const_rtx)x_arg);
399 enum machine_mode mode = GET_MODE (x);
401 gcc_assert (!CONST_INT_P (x) && GET_CODE (x) != CONST_FIXED
402 && (mode != VOIDmode || GET_CODE (x) != CONST_DOUBLE));
404 if (mode != GET_MODE (v->val_rtx))
405 return 0;
407 /* Unwrap X if necessary. */
408 if (GET_CODE (x) == CONST
409 && (CONST_INT_P (XEXP (x, 0))
410 || GET_CODE (XEXP (x, 0)) == CONST_FIXED
411 || GET_CODE (XEXP (x, 0)) == CONST_DOUBLE))
412 x = XEXP (x, 0);
414 /* We don't guarantee that distinct rtx's have different hash values,
415 so we need to do a comparison. */
416 for (l = v->locs; l; l = l->next)
417 if (rtx_equal_for_cselib_p (l->loc, x))
419 promote_debug_loc (l);
420 return 1;
423 return 0;
426 /* The hash function for our hash table. The value is always computed with
427 cselib_hash_rtx when adding an element; this function just extracts the
428 hash value from a cselib_val structure. */
430 static hashval_t
431 get_value_hash (const void *entry)
433 const cselib_val *const v = (const cselib_val *) entry;
434 return v->hash;
437 /* Return true if X contains a VALUE rtx. If ONLY_USELESS is set, we
438 only return true for values which point to a cselib_val whose value
439 element has been set to zero, which implies the cselib_val will be
440 removed. */
443 references_value_p (const_rtx x, int only_useless)
445 const enum rtx_code code = GET_CODE (x);
446 const char *fmt = GET_RTX_FORMAT (code);
447 int i, j;
449 if (GET_CODE (x) == VALUE
450 && (! only_useless || CSELIB_VAL_PTR (x)->locs == 0))
451 return 1;
453 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
455 if (fmt[i] == 'e' && references_value_p (XEXP (x, i), only_useless))
456 return 1;
457 else if (fmt[i] == 'E')
458 for (j = 0; j < XVECLEN (x, i); j++)
459 if (references_value_p (XVECEXP (x, i, j), only_useless))
460 return 1;
463 return 0;
466 /* For all locations found in X, delete locations that reference useless
467 values (i.e. values without any location). Called through
468 htab_traverse. */
470 static int
471 discard_useless_locs (void **x, void *info ATTRIBUTE_UNUSED)
473 cselib_val *v = (cselib_val *)*x;
474 struct elt_loc_list **p = &v->locs;
475 bool had_locs = v->locs != NULL;
476 rtx setting_insn = v->locs ? v->locs->setting_insn : NULL;
478 while (*p)
480 if (references_value_p ((*p)->loc, 1))
481 unchain_one_elt_loc_list (p);
482 else
483 p = &(*p)->next;
486 if (had_locs && v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
488 if (setting_insn && DEBUG_INSN_P (setting_insn))
489 n_useless_debug_values++;
490 else
491 n_useless_values++;
492 values_became_useless = 1;
494 return 1;
497 /* If X is a value with no locations, remove it from the hashtable. */
499 static int
500 discard_useless_values (void **x, void *info ATTRIBUTE_UNUSED)
502 cselib_val *v = (cselib_val *)*x;
504 if (v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
506 if (cselib_discard_hook)
507 cselib_discard_hook (v);
509 CSELIB_VAL_PTR (v->val_rtx) = NULL;
510 htab_clear_slot (cselib_hash_table, x);
511 unchain_one_value (v);
512 n_useless_values--;
515 return 1;
518 /* Clean out useless values (i.e. those which no longer have locations
519 associated with them) from the hash table. */
521 static void
522 remove_useless_values (void)
524 cselib_val **p, *v;
526 /* First pass: eliminate locations that reference the value. That in
527 turn can make more values useless. */
530 values_became_useless = 0;
531 htab_traverse (cselib_hash_table, discard_useless_locs, 0);
533 while (values_became_useless);
535 /* Second pass: actually remove the values. */
537 p = &first_containing_mem;
538 for (v = *p; v != &dummy_val; v = v->next_containing_mem)
539 if (v->locs)
541 *p = v;
542 p = &(*p)->next_containing_mem;
544 *p = &dummy_val;
546 n_useless_values += n_useless_debug_values;
547 n_debug_values -= n_useless_debug_values;
548 n_useless_debug_values = 0;
550 htab_traverse (cselib_hash_table, discard_useless_values, 0);
552 gcc_assert (!n_useless_values);
555 /* Arrange for a value to not be removed from the hash table even if
556 it becomes useless. */
558 void
559 cselib_preserve_value (cselib_val *v)
561 PRESERVED_VALUE_P (v->val_rtx) = 1;
564 /* Test whether a value is preserved. */
566 bool
567 cselib_preserved_value_p (cselib_val *v)
569 return PRESERVED_VALUE_P (v->val_rtx);
572 /* Arrange for a REG value to be assumed constant through the whole function,
573 never invalidated and preserved across cselib_reset_table calls. */
575 void
576 cselib_preserve_cfa_base_value (cselib_val *v, unsigned int regno)
578 if (cselib_preserve_constants
579 && v->locs
580 && REG_P (v->locs->loc))
582 cfa_base_preserved_val = v;
583 cfa_base_preserved_regno = regno;
587 /* Clean all non-constant expressions in the hash table, but retain
588 their values. */
590 void
591 cselib_preserve_only_values (void)
593 int i;
595 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
596 cselib_invalidate_regno (i, reg_raw_mode[i]);
598 cselib_invalidate_mem (callmem);
600 remove_useless_values ();
602 gcc_assert (first_containing_mem == &dummy_val);
605 /* Return the mode in which a register was last set. If X is not a
606 register, return its mode. If the mode in which the register was
607 set is not known, or the value was already clobbered, return
608 VOIDmode. */
610 enum machine_mode
611 cselib_reg_set_mode (const_rtx x)
613 if (!REG_P (x))
614 return GET_MODE (x);
616 if (REG_VALUES (REGNO (x)) == NULL
617 || REG_VALUES (REGNO (x))->elt == NULL)
618 return VOIDmode;
620 return GET_MODE (REG_VALUES (REGNO (x))->elt->val_rtx);
623 /* Return nonzero if we can prove that X and Y contain the same value, taking
624 our gathered information into account. */
627 rtx_equal_for_cselib_p (rtx x, rtx y)
629 enum rtx_code code;
630 const char *fmt;
631 int i;
633 if (REG_P (x) || MEM_P (x))
635 cselib_val *e = cselib_lookup (x, GET_MODE (x), 0);
637 if (e)
638 x = e->val_rtx;
641 if (REG_P (y) || MEM_P (y))
643 cselib_val *e = cselib_lookup (y, GET_MODE (y), 0);
645 if (e)
646 y = e->val_rtx;
649 if (x == y)
650 return 1;
652 if (GET_CODE (x) == VALUE && GET_CODE (y) == VALUE)
653 return CSELIB_VAL_PTR (x) == CSELIB_VAL_PTR (y);
655 if (GET_CODE (x) == VALUE)
657 cselib_val *e = CSELIB_VAL_PTR (x);
658 struct elt_loc_list *l;
660 for (l = e->locs; l; l = l->next)
662 rtx t = l->loc;
664 /* Avoid infinite recursion. */
665 if (REG_P (t) || MEM_P (t))
666 continue;
667 else if (rtx_equal_for_cselib_p (t, y))
668 return 1;
671 return 0;
674 if (GET_CODE (y) == VALUE)
676 cselib_val *e = CSELIB_VAL_PTR (y);
677 struct elt_loc_list *l;
679 for (l = e->locs; l; l = l->next)
681 rtx t = l->loc;
683 if (REG_P (t) || MEM_P (t))
684 continue;
685 else if (rtx_equal_for_cselib_p (x, t))
686 return 1;
689 return 0;
692 if (GET_CODE (x) != GET_CODE (y) || GET_MODE (x) != GET_MODE (y))
693 return 0;
695 /* These won't be handled correctly by the code below. */
696 switch (GET_CODE (x))
698 case CONST_DOUBLE:
699 case CONST_FIXED:
700 case DEBUG_EXPR:
701 return 0;
703 case DEBUG_IMPLICIT_PTR:
704 return DEBUG_IMPLICIT_PTR_DECL (x)
705 == DEBUG_IMPLICIT_PTR_DECL (y);
707 case LABEL_REF:
708 return XEXP (x, 0) == XEXP (y, 0);
710 default:
711 break;
714 code = GET_CODE (x);
715 fmt = GET_RTX_FORMAT (code);
717 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
719 int j;
721 switch (fmt[i])
723 case 'w':
724 if (XWINT (x, i) != XWINT (y, i))
725 return 0;
726 break;
728 case 'n':
729 case 'i':
730 if (XINT (x, i) != XINT (y, i))
731 return 0;
732 break;
734 case 'V':
735 case 'E':
736 /* Two vectors must have the same length. */
737 if (XVECLEN (x, i) != XVECLEN (y, i))
738 return 0;
740 /* And the corresponding elements must match. */
741 for (j = 0; j < XVECLEN (x, i); j++)
742 if (! rtx_equal_for_cselib_p (XVECEXP (x, i, j),
743 XVECEXP (y, i, j)))
744 return 0;
745 break;
747 case 'e':
748 if (i == 1
749 && targetm.commutative_p (x, UNKNOWN)
750 && rtx_equal_for_cselib_p (XEXP (x, 1), XEXP (y, 0))
751 && rtx_equal_for_cselib_p (XEXP (x, 0), XEXP (y, 1)))
752 return 1;
753 if (! rtx_equal_for_cselib_p (XEXP (x, i), XEXP (y, i)))
754 return 0;
755 break;
757 case 'S':
758 case 's':
759 if (strcmp (XSTR (x, i), XSTR (y, i)))
760 return 0;
761 break;
763 case 'u':
764 /* These are just backpointers, so they don't matter. */
765 break;
767 case '0':
768 case 't':
769 break;
771 /* It is believed that rtx's at this level will never
772 contain anything but integers and other rtx's,
773 except for within LABEL_REFs and SYMBOL_REFs. */
774 default:
775 gcc_unreachable ();
778 return 1;
781 /* We need to pass down the mode of constants through the hash table
782 functions. For that purpose, wrap them in a CONST of the appropriate
783 mode. */
784 static rtx
785 wrap_constant (enum machine_mode mode, rtx x)
787 if (!CONST_INT_P (x) && GET_CODE (x) != CONST_FIXED
788 && (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode))
789 return x;
790 gcc_assert (mode != VOIDmode);
791 return gen_rtx_CONST (mode, x);
794 /* Hash an rtx. Return 0 if we couldn't hash the rtx.
795 For registers and memory locations, we look up their cselib_val structure
796 and return its VALUE element.
797 Possible reasons for return 0 are: the object is volatile, or we couldn't
798 find a register or memory location in the table and CREATE is zero. If
799 CREATE is nonzero, table elts are created for regs and mem.
800 N.B. this hash function returns the same hash value for RTXes that
801 differ only in the order of operands, thus it is suitable for comparisons
802 that take commutativity into account.
803 If we wanted to also support associative rules, we'd have to use a different
804 strategy to avoid returning spurious 0, e.g. return ~(~0U >> 1) .
805 We used to have a MODE argument for hashing for CONST_INTs, but that
806 didn't make sense, since it caused spurious hash differences between
807 (set (reg:SI 1) (const_int))
808 (plus:SI (reg:SI 2) (reg:SI 1))
810 (plus:SI (reg:SI 2) (const_int))
811 If the mode is important in any context, it must be checked specifically
812 in a comparison anyway, since relying on hash differences is unsafe. */
814 static unsigned int
815 cselib_hash_rtx (rtx x, int create)
817 cselib_val *e;
818 int i, j;
819 enum rtx_code code;
820 const char *fmt;
821 unsigned int hash = 0;
823 code = GET_CODE (x);
824 hash += (unsigned) code + (unsigned) GET_MODE (x);
826 switch (code)
828 case MEM:
829 case REG:
830 e = cselib_lookup (x, GET_MODE (x), create);
831 if (! e)
832 return 0;
834 return e->hash;
836 case DEBUG_EXPR:
837 hash += ((unsigned) DEBUG_EXPR << 7)
838 + DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x));
839 return hash ? hash : (unsigned int) DEBUG_EXPR;
841 case DEBUG_IMPLICIT_PTR:
842 hash += ((unsigned) DEBUG_IMPLICIT_PTR << 7)
843 + DECL_UID (DEBUG_IMPLICIT_PTR_DECL (x));
844 return hash ? hash : (unsigned int) DEBUG_IMPLICIT_PTR;
846 case CONST_INT:
847 hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
848 return hash ? hash : (unsigned int) CONST_INT;
850 case CONST_DOUBLE:
851 /* This is like the general case, except that it only counts
852 the integers representing the constant. */
853 hash += (unsigned) code + (unsigned) GET_MODE (x);
854 if (GET_MODE (x) != VOIDmode)
855 hash += real_hash (CONST_DOUBLE_REAL_VALUE (x));
856 else
857 hash += ((unsigned) CONST_DOUBLE_LOW (x)
858 + (unsigned) CONST_DOUBLE_HIGH (x));
859 return hash ? hash : (unsigned int) CONST_DOUBLE;
861 case CONST_FIXED:
862 hash += (unsigned int) code + (unsigned int) GET_MODE (x);
863 hash += fixed_hash (CONST_FIXED_VALUE (x));
864 return hash ? hash : (unsigned int) CONST_FIXED;
866 case CONST_VECTOR:
868 int units;
869 rtx elt;
871 units = CONST_VECTOR_NUNITS (x);
873 for (i = 0; i < units; ++i)
875 elt = CONST_VECTOR_ELT (x, i);
876 hash += cselib_hash_rtx (elt, 0);
879 return hash;
882 /* Assume there is only one rtx object for any given label. */
883 case LABEL_REF:
884 /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
885 differences and differences between each stage's debugging dumps. */
886 hash += (((unsigned int) LABEL_REF << 7)
887 + CODE_LABEL_NUMBER (XEXP (x, 0)));
888 return hash ? hash : (unsigned int) LABEL_REF;
890 case SYMBOL_REF:
892 /* Don't hash on the symbol's address to avoid bootstrap differences.
893 Different hash values may cause expressions to be recorded in
894 different orders and thus different registers to be used in the
895 final assembler. This also avoids differences in the dump files
896 between various stages. */
897 unsigned int h = 0;
898 const unsigned char *p = (const unsigned char *) XSTR (x, 0);
900 while (*p)
901 h += (h << 7) + *p++; /* ??? revisit */
903 hash += ((unsigned int) SYMBOL_REF << 7) + h;
904 return hash ? hash : (unsigned int) SYMBOL_REF;
907 case PRE_DEC:
908 case PRE_INC:
909 case POST_DEC:
910 case POST_INC:
911 case POST_MODIFY:
912 case PRE_MODIFY:
913 case PC:
914 case CC0:
915 case CALL:
916 case UNSPEC_VOLATILE:
917 return 0;
919 case ASM_OPERANDS:
920 if (MEM_VOLATILE_P (x))
921 return 0;
923 break;
925 default:
926 break;
929 i = GET_RTX_LENGTH (code) - 1;
930 fmt = GET_RTX_FORMAT (code);
931 for (; i >= 0; i--)
933 switch (fmt[i])
935 case 'e':
937 rtx tem = XEXP (x, i);
938 unsigned int tem_hash = cselib_hash_rtx (tem, create);
940 if (tem_hash == 0)
941 return 0;
943 hash += tem_hash;
945 break;
946 case 'E':
947 for (j = 0; j < XVECLEN (x, i); j++)
949 unsigned int tem_hash
950 = cselib_hash_rtx (XVECEXP (x, i, j), create);
952 if (tem_hash == 0)
953 return 0;
955 hash += tem_hash;
957 break;
959 case 's':
961 const unsigned char *p = (const unsigned char *) XSTR (x, i);
963 if (p)
964 while (*p)
965 hash += *p++;
966 break;
969 case 'i':
970 hash += XINT (x, i);
971 break;
973 case '0':
974 case 't':
975 /* unused */
976 break;
978 default:
979 gcc_unreachable ();
983 return hash ? hash : 1 + (unsigned int) GET_CODE (x);
986 /* Create a new value structure for VALUE and initialize it. The mode of the
987 value is MODE. */
989 static inline cselib_val *
990 new_cselib_val (unsigned int hash, enum machine_mode mode, rtx x)
992 cselib_val *e = (cselib_val *) pool_alloc (cselib_val_pool);
994 gcc_assert (hash);
995 gcc_assert (next_uid);
997 e->hash = hash;
998 e->uid = next_uid++;
999 /* We use an alloc pool to allocate this RTL construct because it
1000 accounts for about 8% of the overall memory usage. We know
1001 precisely when we can have VALUE RTXen (when cselib is active)
1002 so we don't need to put them in garbage collected memory.
1003 ??? Why should a VALUE be an RTX in the first place? */
1004 e->val_rtx = (rtx) pool_alloc (value_pool);
1005 memset (e->val_rtx, 0, RTX_HDR_SIZE);
1006 PUT_CODE (e->val_rtx, VALUE);
1007 PUT_MODE (e->val_rtx, mode);
1008 CSELIB_VAL_PTR (e->val_rtx) = e;
1009 e->addr_list = 0;
1010 e->locs = 0;
1011 e->next_containing_mem = 0;
1013 if (dump_file && (dump_flags & TDF_DETAILS))
1015 fprintf (dump_file, "cselib value %u:%u ", e->uid, hash);
1016 if (flag_dump_noaddr || flag_dump_unnumbered)
1017 fputs ("# ", dump_file);
1018 else
1019 fprintf (dump_file, "%p ", (void*)e);
1020 print_rtl_single (dump_file, x);
1021 fputc ('\n', dump_file);
1024 return e;
1027 /* ADDR_ELT is a value that is used as address. MEM_ELT is the value that
1028 contains the data at this address. X is a MEM that represents the
1029 value. Update the two value structures to represent this situation. */
1031 static void
1032 add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
1034 struct elt_loc_list *l;
1036 /* Avoid duplicates. */
1037 for (l = mem_elt->locs; l; l = l->next)
1038 if (MEM_P (l->loc)
1039 && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt)
1041 promote_debug_loc (l);
1042 return;
1045 addr_elt->addr_list = new_elt_list (addr_elt->addr_list, mem_elt);
1046 mem_elt->locs
1047 = new_elt_loc_list (mem_elt->locs,
1048 replace_equiv_address_nv (x, addr_elt->val_rtx));
1049 if (mem_elt->next_containing_mem == NULL)
1051 mem_elt->next_containing_mem = first_containing_mem;
1052 first_containing_mem = mem_elt;
1056 /* Subroutine of cselib_lookup. Return a value for X, which is a MEM rtx.
1057 If CREATE, make a new one if we haven't seen it before. */
1059 static cselib_val *
1060 cselib_lookup_mem (rtx x, int create)
1062 enum machine_mode mode = GET_MODE (x);
1063 void **slot;
1064 cselib_val *addr;
1065 cselib_val *mem_elt;
1066 struct elt_list *l;
1068 if (MEM_VOLATILE_P (x) || mode == BLKmode
1069 || !cselib_record_memory
1070 || (FLOAT_MODE_P (mode) && flag_float_store))
1071 return 0;
1073 /* Look up the value for the address. */
1074 addr = cselib_lookup (XEXP (x, 0), mode, create);
1075 if (! addr)
1076 return 0;
1078 /* Find a value that describes a value of our mode at that address. */
1079 for (l = addr->addr_list; l; l = l->next)
1080 if (GET_MODE (l->elt->val_rtx) == mode)
1082 promote_debug_loc (l->elt->locs);
1083 return l->elt;
1086 if (! create)
1087 return 0;
1089 mem_elt = new_cselib_val (next_uid, mode, x);
1090 add_mem_for_addr (addr, mem_elt, x);
1091 slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
1092 mem_elt->hash, INSERT);
1093 *slot = mem_elt;
1094 return mem_elt;
1097 /* Search thru the possible substitutions in P. We prefer a non reg
1098 substitution because this allows us to expand the tree further. If
1099 we find, just a reg, take the lowest regno. There may be several
1100 non-reg results, we just take the first one because they will all
1101 expand to the same place. */
1103 static rtx
1104 expand_loc (struct elt_loc_list *p, struct expand_value_data *evd,
1105 int max_depth)
1107 rtx reg_result = NULL;
1108 unsigned int regno = UINT_MAX;
1109 struct elt_loc_list *p_in = p;
1111 for (; p; p = p -> next)
1113 /* Avoid infinite recursion trying to expand a reg into a
1114 the same reg. */
1115 if ((REG_P (p->loc))
1116 && (REGNO (p->loc) < regno)
1117 && !bitmap_bit_p (evd->regs_active, REGNO (p->loc)))
1119 reg_result = p->loc;
1120 regno = REGNO (p->loc);
1122 /* Avoid infinite recursion and do not try to expand the
1123 value. */
1124 else if (GET_CODE (p->loc) == VALUE
1125 && CSELIB_VAL_PTR (p->loc)->locs == p_in)
1126 continue;
1127 else if (!REG_P (p->loc))
1129 rtx result, note;
1130 if (dump_file && (dump_flags & TDF_DETAILS))
1132 print_inline_rtx (dump_file, p->loc, 0);
1133 fprintf (dump_file, "\n");
1135 if (GET_CODE (p->loc) == LO_SUM
1136 && GET_CODE (XEXP (p->loc, 1)) == SYMBOL_REF
1137 && p->setting_insn
1138 && (note = find_reg_note (p->setting_insn, REG_EQUAL, NULL_RTX))
1139 && XEXP (note, 0) == XEXP (p->loc, 1))
1140 return XEXP (p->loc, 1);
1141 result = cselib_expand_value_rtx_1 (p->loc, evd, max_depth - 1);
1142 if (result)
1143 return result;
1148 if (regno != UINT_MAX)
1150 rtx result;
1151 if (dump_file && (dump_flags & TDF_DETAILS))
1152 fprintf (dump_file, "r%d\n", regno);
1154 result = cselib_expand_value_rtx_1 (reg_result, evd, max_depth - 1);
1155 if (result)
1156 return result;
1159 if (dump_file && (dump_flags & TDF_DETAILS))
1161 if (reg_result)
1163 print_inline_rtx (dump_file, reg_result, 0);
1164 fprintf (dump_file, "\n");
1166 else
1167 fprintf (dump_file, "NULL\n");
1169 return reg_result;
1173 /* Forward substitute and expand an expression out to its roots.
1174 This is the opposite of common subexpression. Because local value
1175 numbering is such a weak optimization, the expanded expression is
1176 pretty much unique (not from a pointer equals point of view but
1177 from a tree shape point of view.
1179 This function returns NULL if the expansion fails. The expansion
1180 will fail if there is no value number for one of the operands or if
1181 one of the operands has been overwritten between the current insn
1182 and the beginning of the basic block. For instance x has no
1183 expansion in:
1185 r1 <- r1 + 3
1186 x <- r1 + 8
1188 REGS_ACTIVE is a scratch bitmap that should be clear when passing in.
1189 It is clear on return. */
1192 cselib_expand_value_rtx (rtx orig, bitmap regs_active, int max_depth)
1194 struct expand_value_data evd;
1196 evd.regs_active = regs_active;
1197 evd.callback = NULL;
1198 evd.callback_arg = NULL;
1199 evd.dummy = false;
1201 return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
1204 /* Same as cselib_expand_value_rtx, but using a callback to try to
1205 resolve some expressions. The CB function should return ORIG if it
1206 can't or does not want to deal with a certain RTX. Any other
1207 return value, including NULL, will be used as the expansion for
1208 VALUE, without any further changes. */
1211 cselib_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
1212 cselib_expand_callback cb, void *data)
1214 struct expand_value_data evd;
1216 evd.regs_active = regs_active;
1217 evd.callback = cb;
1218 evd.callback_arg = data;
1219 evd.dummy = false;
1221 return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
1224 /* Similar to cselib_expand_value_rtx_cb, but no rtxs are actually copied
1225 or simplified. Useful to find out whether cselib_expand_value_rtx_cb
1226 would return NULL or non-NULL, without allocating new rtx. */
1228 bool
1229 cselib_dummy_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
1230 cselib_expand_callback cb, void *data)
1232 struct expand_value_data evd;
1234 evd.regs_active = regs_active;
1235 evd.callback = cb;
1236 evd.callback_arg = data;
1237 evd.dummy = true;
1239 return cselib_expand_value_rtx_1 (orig, &evd, max_depth) != NULL;
1242 /* Internal implementation of cselib_expand_value_rtx and
1243 cselib_expand_value_rtx_cb. */
1245 static rtx
1246 cselib_expand_value_rtx_1 (rtx orig, struct expand_value_data *evd,
1247 int max_depth)
1249 rtx copy, scopy;
1250 int i, j;
1251 RTX_CODE code;
1252 const char *format_ptr;
1253 enum machine_mode mode;
1255 code = GET_CODE (orig);
1257 /* For the context of dse, if we end up expand into a huge tree, we
1258 will not have a useful address, so we might as well just give up
1259 quickly. */
1260 if (max_depth <= 0)
1261 return NULL;
1263 switch (code)
1265 case REG:
1267 struct elt_list *l = REG_VALUES (REGNO (orig));
1269 if (l && l->elt == NULL)
1270 l = l->next;
1271 for (; l; l = l->next)
1272 if (GET_MODE (l->elt->val_rtx) == GET_MODE (orig))
1274 rtx result;
1275 int regno = REGNO (orig);
1277 /* The only thing that we are not willing to do (this
1278 is requirement of dse and if others potential uses
1279 need this function we should add a parm to control
1280 it) is that we will not substitute the
1281 STACK_POINTER_REGNUM, FRAME_POINTER or the
1282 HARD_FRAME_POINTER.
1284 These expansions confuses the code that notices that
1285 stores into the frame go dead at the end of the
1286 function and that the frame is not effected by calls
1287 to subroutines. If you allow the
1288 STACK_POINTER_REGNUM substitution, then dse will
1289 think that parameter pushing also goes dead which is
1290 wrong. If you allow the FRAME_POINTER or the
1291 HARD_FRAME_POINTER then you lose the opportunity to
1292 make the frame assumptions. */
1293 if (regno == STACK_POINTER_REGNUM
1294 || regno == FRAME_POINTER_REGNUM
1295 || regno == HARD_FRAME_POINTER_REGNUM)
1296 return orig;
1298 bitmap_set_bit (evd->regs_active, regno);
1300 if (dump_file && (dump_flags & TDF_DETAILS))
1301 fprintf (dump_file, "expanding: r%d into: ", regno);
1303 result = expand_loc (l->elt->locs, evd, max_depth);
1304 bitmap_clear_bit (evd->regs_active, regno);
1306 if (result)
1307 return result;
1308 else
1309 return orig;
1313 case CONST_INT:
1314 case CONST_DOUBLE:
1315 case CONST_VECTOR:
1316 case SYMBOL_REF:
1317 case CODE_LABEL:
1318 case PC:
1319 case CC0:
1320 case SCRATCH:
1321 /* SCRATCH must be shared because they represent distinct values. */
1322 return orig;
1323 case CLOBBER:
1324 if (REG_P (XEXP (orig, 0)) && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))))
1325 return orig;
1326 break;
1328 case CONST:
1329 if (shared_const_p (orig))
1330 return orig;
1331 break;
1333 case SUBREG:
1335 rtx subreg;
1337 if (evd->callback)
1339 subreg = evd->callback (orig, evd->regs_active, max_depth,
1340 evd->callback_arg);
1341 if (subreg != orig)
1342 return subreg;
1345 subreg = cselib_expand_value_rtx_1 (SUBREG_REG (orig), evd,
1346 max_depth - 1);
1347 if (!subreg)
1348 return NULL;
1349 scopy = simplify_gen_subreg (GET_MODE (orig), subreg,
1350 GET_MODE (SUBREG_REG (orig)),
1351 SUBREG_BYTE (orig));
1352 if (scopy == NULL
1353 || (GET_CODE (scopy) == SUBREG
1354 && !REG_P (SUBREG_REG (scopy))
1355 && !MEM_P (SUBREG_REG (scopy))))
1356 return NULL;
1358 return scopy;
1361 case VALUE:
1363 rtx result;
1365 if (dump_file && (dump_flags & TDF_DETAILS))
1367 fputs ("\nexpanding ", dump_file);
1368 print_rtl_single (dump_file, orig);
1369 fputs (" into...", dump_file);
1372 if (evd->callback)
1374 result = evd->callback (orig, evd->regs_active, max_depth,
1375 evd->callback_arg);
1377 if (result != orig)
1378 return result;
1381 result = expand_loc (CSELIB_VAL_PTR (orig)->locs, evd, max_depth);
1382 return result;
1385 case DEBUG_EXPR:
1386 if (evd->callback)
1387 return evd->callback (orig, evd->regs_active, max_depth,
1388 evd->callback_arg);
1389 return orig;
1391 default:
1392 break;
1395 /* Copy the various flags, fields, and other information. We assume
1396 that all fields need copying, and then clear the fields that should
1397 not be copied. That is the sensible default behavior, and forces
1398 us to explicitly document why we are *not* copying a flag. */
1399 if (evd->dummy)
1400 copy = NULL;
1401 else
1402 copy = shallow_copy_rtx (orig);
1404 format_ptr = GET_RTX_FORMAT (code);
1406 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1407 switch (*format_ptr++)
1409 case 'e':
1410 if (XEXP (orig, i) != NULL)
1412 rtx result = cselib_expand_value_rtx_1 (XEXP (orig, i), evd,
1413 max_depth - 1);
1414 if (!result)
1415 return NULL;
1416 if (copy)
1417 XEXP (copy, i) = result;
1419 break;
1421 case 'E':
1422 case 'V':
1423 if (XVEC (orig, i) != NULL)
1425 if (copy)
1426 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
1427 for (j = 0; j < XVECLEN (orig, i); j++)
1429 rtx result = cselib_expand_value_rtx_1 (XVECEXP (orig, i, j),
1430 evd, max_depth - 1);
1431 if (!result)
1432 return NULL;
1433 if (copy)
1434 XVECEXP (copy, i, j) = result;
1437 break;
1439 case 't':
1440 case 'w':
1441 case 'i':
1442 case 's':
1443 case 'S':
1444 case 'T':
1445 case 'u':
1446 case 'B':
1447 case '0':
1448 /* These are left unchanged. */
1449 break;
1451 default:
1452 gcc_unreachable ();
1455 if (evd->dummy)
1456 return orig;
1458 mode = GET_MODE (copy);
1459 /* If an operand has been simplified into CONST_INT, which doesn't
1460 have a mode and the mode isn't derivable from whole rtx's mode,
1461 try simplify_*_operation first with mode from original's operand
1462 and as a fallback wrap CONST_INT into gen_rtx_CONST. */
1463 scopy = copy;
1464 switch (GET_RTX_CLASS (code))
1466 case RTX_UNARY:
1467 if (CONST_INT_P (XEXP (copy, 0))
1468 && GET_MODE (XEXP (orig, 0)) != VOIDmode)
1470 scopy = simplify_unary_operation (code, mode, XEXP (copy, 0),
1471 GET_MODE (XEXP (orig, 0)));
1472 if (scopy)
1473 return scopy;
1475 break;
1476 case RTX_COMM_ARITH:
1477 case RTX_BIN_ARITH:
1478 /* These expressions can derive operand modes from the whole rtx's mode. */
1479 break;
1480 case RTX_TERNARY:
1481 case RTX_BITFIELD_OPS:
1482 if (CONST_INT_P (XEXP (copy, 0))
1483 && GET_MODE (XEXP (orig, 0)) != VOIDmode)
1485 scopy = simplify_ternary_operation (code, mode,
1486 GET_MODE (XEXP (orig, 0)),
1487 XEXP (copy, 0), XEXP (copy, 1),
1488 XEXP (copy, 2));
1489 if (scopy)
1490 return scopy;
1492 break;
1493 case RTX_COMPARE:
1494 case RTX_COMM_COMPARE:
1495 if (CONST_INT_P (XEXP (copy, 0))
1496 && GET_MODE (XEXP (copy, 1)) == VOIDmode
1497 && (GET_MODE (XEXP (orig, 0)) != VOIDmode
1498 || GET_MODE (XEXP (orig, 1)) != VOIDmode))
1500 scopy = simplify_relational_operation (code, mode,
1501 (GET_MODE (XEXP (orig, 0))
1502 != VOIDmode)
1503 ? GET_MODE (XEXP (orig, 0))
1504 : GET_MODE (XEXP (orig, 1)),
1505 XEXP (copy, 0),
1506 XEXP (copy, 1));
1507 if (scopy)
1508 return scopy;
1510 break;
1511 default:
1512 break;
1514 scopy = simplify_rtx (copy);
1515 if (scopy)
1516 return scopy;
1517 return copy;
1520 /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
1521 with VALUE expressions. This way, it becomes independent of changes
1522 to registers and memory.
1523 X isn't actually modified; if modifications are needed, new rtl is
1524 allocated. However, the return value can share rtl with X. */
1527 cselib_subst_to_values (rtx x)
1529 enum rtx_code code = GET_CODE (x);
1530 const char *fmt = GET_RTX_FORMAT (code);
1531 cselib_val *e;
1532 struct elt_list *l;
1533 rtx copy = x;
1534 int i;
1536 switch (code)
1538 case REG:
1539 l = REG_VALUES (REGNO (x));
1540 if (l && l->elt == NULL)
1541 l = l->next;
1542 for (; l; l = l->next)
1543 if (GET_MODE (l->elt->val_rtx) == GET_MODE (x))
1544 return l->elt->val_rtx;
1546 gcc_unreachable ();
1548 case MEM:
1549 e = cselib_lookup_mem (x, 0);
1550 if (! e)
1552 /* This happens for autoincrements. Assign a value that doesn't
1553 match any other. */
1554 e = new_cselib_val (next_uid, GET_MODE (x), x);
1556 return e->val_rtx;
1558 case CONST_DOUBLE:
1559 case CONST_VECTOR:
1560 case CONST_INT:
1561 case CONST_FIXED:
1562 return x;
1564 case POST_INC:
1565 case PRE_INC:
1566 case POST_DEC:
1567 case PRE_DEC:
1568 case POST_MODIFY:
1569 case PRE_MODIFY:
1570 e = new_cselib_val (next_uid, GET_MODE (x), x);
1571 return e->val_rtx;
1573 default:
1574 break;
1577 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1579 if (fmt[i] == 'e')
1581 rtx t = cselib_subst_to_values (XEXP (x, i));
1583 if (t != XEXP (x, i))
1585 if (x == copy)
1586 copy = shallow_copy_rtx (x);
1587 XEXP (copy, i) = t;
1590 else if (fmt[i] == 'E')
1592 int j;
1594 for (j = 0; j < XVECLEN (x, i); j++)
1596 rtx t = cselib_subst_to_values (XVECEXP (x, i, j));
1598 if (t != XVECEXP (x, i, j))
1600 if (XVEC (x, i) == XVEC (copy, i))
1602 if (x == copy)
1603 copy = shallow_copy_rtx (x);
1604 XVEC (copy, i) = shallow_copy_rtvec (XVEC (x, i));
1606 XVECEXP (copy, i, j) = t;
1612 return copy;
1615 /* Look up the rtl expression X in our tables and return the value it has.
1616 If CREATE is zero, we return NULL if we don't know the value. Otherwise,
1617 we create a new one if possible, using mode MODE if X doesn't have a mode
1618 (i.e. because it's a constant). */
1620 static cselib_val *
1621 cselib_lookup_1 (rtx x, enum machine_mode mode, int create)
1623 void **slot;
1624 cselib_val *e;
1625 unsigned int hashval;
1627 if (GET_MODE (x) != VOIDmode)
1628 mode = GET_MODE (x);
1630 if (GET_CODE (x) == VALUE)
1631 return CSELIB_VAL_PTR (x);
1633 if (REG_P (x))
1635 struct elt_list *l;
1636 unsigned int i = REGNO (x);
1638 l = REG_VALUES (i);
1639 if (l && l->elt == NULL)
1640 l = l->next;
1641 for (; l; l = l->next)
1642 if (mode == GET_MODE (l->elt->val_rtx))
1644 promote_debug_loc (l->elt->locs);
1645 return l->elt;
1648 if (! create)
1649 return 0;
1651 if (i < FIRST_PSEUDO_REGISTER)
1653 unsigned int n = hard_regno_nregs[i][mode];
1655 if (n > max_value_regs)
1656 max_value_regs = n;
1659 e = new_cselib_val (next_uid, GET_MODE (x), x);
1660 e->locs = new_elt_loc_list (e->locs, x);
1661 if (REG_VALUES (i) == 0)
1663 /* Maintain the invariant that the first entry of
1664 REG_VALUES, if present, must be the value used to set the
1665 register, or NULL. */
1666 used_regs[n_used_regs++] = i;
1667 REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
1669 REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
1670 slot = htab_find_slot_with_hash (cselib_hash_table, x, e->hash, INSERT);
1671 *slot = e;
1672 return e;
1675 if (MEM_P (x))
1676 return cselib_lookup_mem (x, create);
1678 hashval = cselib_hash_rtx (x, create);
1679 /* Can't even create if hashing is not possible. */
1680 if (! hashval)
1681 return 0;
1683 slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
1684 hashval, create ? INSERT : NO_INSERT);
1685 if (slot == 0)
1686 return 0;
1688 e = (cselib_val *) *slot;
1689 if (e)
1690 return e;
1692 e = new_cselib_val (hashval, mode, x);
1694 /* We have to fill the slot before calling cselib_subst_to_values:
1695 the hash table is inconsistent until we do so, and
1696 cselib_subst_to_values will need to do lookups. */
1697 *slot = (void *) e;
1698 e->locs = new_elt_loc_list (e->locs, cselib_subst_to_values (x));
1699 return e;
1702 /* Wrapper for cselib_lookup, that indicates X is in INSN. */
1704 cselib_val *
1705 cselib_lookup_from_insn (rtx x, enum machine_mode mode,
1706 int create, rtx insn)
1708 cselib_val *ret;
1710 gcc_assert (!cselib_current_insn);
1711 cselib_current_insn = insn;
1713 ret = cselib_lookup (x, mode, create);
1715 cselib_current_insn = NULL;
1717 return ret;
1720 /* Wrapper for cselib_lookup_1, that logs the lookup result and
1721 maintains invariants related with debug insns. */
1723 cselib_val *
1724 cselib_lookup (rtx x, enum machine_mode mode, int create)
1726 cselib_val *ret = cselib_lookup_1 (x, mode, create);
1728 /* ??? Should we return NULL if we're not to create an entry, the
1729 found loc is a debug loc and cselib_current_insn is not DEBUG?
1730 If so, we should also avoid converting val to non-DEBUG; probably
1731 easiest setting cselib_current_insn to NULL before the call
1732 above. */
1734 if (dump_file && (dump_flags & TDF_DETAILS))
1736 fputs ("cselib lookup ", dump_file);
1737 print_inline_rtx (dump_file, x, 2);
1738 fprintf (dump_file, " => %u:%u\n",
1739 ret ? ret->uid : 0,
1740 ret ? ret->hash : 0);
1743 return ret;
1746 /* Invalidate any entries in reg_values that overlap REGNO. This is called
1747 if REGNO is changing. MODE is the mode of the assignment to REGNO, which
1748 is used to determine how many hard registers are being changed. If MODE
1749 is VOIDmode, then only REGNO is being changed; this is used when
1750 invalidating call clobbered registers across a call. */
1752 static void
1753 cselib_invalidate_regno (unsigned int regno, enum machine_mode mode)
1755 unsigned int endregno;
1756 unsigned int i;
1758 /* If we see pseudos after reload, something is _wrong_. */
1759 gcc_assert (!reload_completed || regno < FIRST_PSEUDO_REGISTER
1760 || reg_renumber[regno] < 0);
1762 /* Determine the range of registers that must be invalidated. For
1763 pseudos, only REGNO is affected. For hard regs, we must take MODE
1764 into account, and we must also invalidate lower register numbers
1765 if they contain values that overlap REGNO. */
1766 if (regno < FIRST_PSEUDO_REGISTER)
1768 gcc_assert (mode != VOIDmode);
1770 if (regno < max_value_regs)
1771 i = 0;
1772 else
1773 i = regno - max_value_regs;
1775 endregno = end_hard_regno (mode, regno);
1777 else
1779 i = regno;
1780 endregno = regno + 1;
1783 for (; i < endregno; i++)
1785 struct elt_list **l = &REG_VALUES (i);
1787 /* Go through all known values for this reg; if it overlaps the range
1788 we're invalidating, remove the value. */
1789 while (*l)
1791 cselib_val *v = (*l)->elt;
1792 bool had_locs;
1793 rtx setting_insn;
1794 struct elt_loc_list **p;
1795 unsigned int this_last = i;
1797 if (i < FIRST_PSEUDO_REGISTER && v != NULL)
1798 this_last = end_hard_regno (GET_MODE (v->val_rtx), i) - 1;
1800 if (this_last < regno || v == NULL
1801 || (v == cfa_base_preserved_val
1802 && i == cfa_base_preserved_regno))
1804 l = &(*l)->next;
1805 continue;
1808 /* We have an overlap. */
1809 if (*l == REG_VALUES (i))
1811 /* Maintain the invariant that the first entry of
1812 REG_VALUES, if present, must be the value used to set
1813 the register, or NULL. This is also nice because
1814 then we won't push the same regno onto user_regs
1815 multiple times. */
1816 (*l)->elt = NULL;
1817 l = &(*l)->next;
1819 else
1820 unchain_one_elt_list (l);
1822 had_locs = v->locs != NULL;
1823 setting_insn = v->locs ? v->locs->setting_insn : NULL;
1825 /* Now, we clear the mapping from value to reg. It must exist, so
1826 this code will crash intentionally if it doesn't. */
1827 for (p = &v->locs; ; p = &(*p)->next)
1829 rtx x = (*p)->loc;
1831 if (REG_P (x) && REGNO (x) == i)
1833 unchain_one_elt_loc_list (p);
1834 break;
1838 if (had_locs && v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
1840 if (setting_insn && DEBUG_INSN_P (setting_insn))
1841 n_useless_debug_values++;
1842 else
1843 n_useless_values++;
1849 /* Return 1 if X has a value that can vary even between two
1850 executions of the program. 0 means X can be compared reliably
1851 against certain constants or near-constants. */
1853 static bool
1854 cselib_rtx_varies_p (const_rtx x ATTRIBUTE_UNUSED, bool from_alias ATTRIBUTE_UNUSED)
1856 /* We actually don't need to verify very hard. This is because
1857 if X has actually changed, we invalidate the memory anyway,
1858 so assume that all common memory addresses are
1859 invariant. */
1860 return 0;
1863 /* Invalidate any locations in the table which are changed because of a
1864 store to MEM_RTX. If this is called because of a non-const call
1865 instruction, MEM_RTX is (mem:BLK const0_rtx). */
1867 static void
1868 cselib_invalidate_mem (rtx mem_rtx)
1870 cselib_val **vp, *v, *next;
1871 int num_mems = 0;
1872 rtx mem_addr;
1874 mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0)));
1875 mem_rtx = canon_rtx (mem_rtx);
1877 vp = &first_containing_mem;
1878 for (v = *vp; v != &dummy_val; v = next)
1880 bool has_mem = false;
1881 struct elt_loc_list **p = &v->locs;
1882 bool had_locs = v->locs != NULL;
1883 rtx setting_insn = v->locs ? v->locs->setting_insn : NULL;
1885 while (*p)
1887 rtx x = (*p)->loc;
1888 cselib_val *addr;
1889 struct elt_list **mem_chain;
1891 /* MEMs may occur in locations only at the top level; below
1892 that every MEM or REG is substituted by its VALUE. */
1893 if (!MEM_P (x))
1895 p = &(*p)->next;
1896 continue;
1898 if (num_mems < PARAM_VALUE (PARAM_MAX_CSELIB_MEMORY_LOCATIONS)
1899 && ! canon_true_dependence (mem_rtx, GET_MODE (mem_rtx), mem_addr,
1900 x, NULL_RTX, cselib_rtx_varies_p))
1902 has_mem = true;
1903 num_mems++;
1904 p = &(*p)->next;
1905 continue;
1908 /* This one overlaps. */
1909 /* We must have a mapping from this MEM's address to the
1910 value (E). Remove that, too. */
1911 addr = cselib_lookup (XEXP (x, 0), VOIDmode, 0);
1912 mem_chain = &addr->addr_list;
1913 for (;;)
1915 if ((*mem_chain)->elt == v)
1917 unchain_one_elt_list (mem_chain);
1918 break;
1921 mem_chain = &(*mem_chain)->next;
1924 unchain_one_elt_loc_list (p);
1927 if (had_locs && v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
1929 if (setting_insn && DEBUG_INSN_P (setting_insn))
1930 n_useless_debug_values++;
1931 else
1932 n_useless_values++;
1935 next = v->next_containing_mem;
1936 if (has_mem)
1938 *vp = v;
1939 vp = &(*vp)->next_containing_mem;
1941 else
1942 v->next_containing_mem = NULL;
1944 *vp = &dummy_val;
1947 /* Invalidate DEST, which is being assigned to or clobbered. */
1949 void
1950 cselib_invalidate_rtx (rtx dest)
1952 while (GET_CODE (dest) == SUBREG
1953 || GET_CODE (dest) == ZERO_EXTRACT
1954 || GET_CODE (dest) == STRICT_LOW_PART)
1955 dest = XEXP (dest, 0);
1957 if (REG_P (dest))
1958 cselib_invalidate_regno (REGNO (dest), GET_MODE (dest));
1959 else if (MEM_P (dest))
1960 cselib_invalidate_mem (dest);
1962 /* Some machines don't define AUTO_INC_DEC, but they still use push
1963 instructions. We need to catch that case here in order to
1964 invalidate the stack pointer correctly. Note that invalidating
1965 the stack pointer is different from invalidating DEST. */
1966 if (push_operand (dest, GET_MODE (dest)))
1967 cselib_invalidate_rtx (stack_pointer_rtx);
1970 /* A wrapper for cselib_invalidate_rtx to be called via note_stores. */
1972 static void
1973 cselib_invalidate_rtx_note_stores (rtx dest, const_rtx ignore ATTRIBUTE_UNUSED,
1974 void *data ATTRIBUTE_UNUSED)
1976 cselib_invalidate_rtx (dest);
1979 /* Record the result of a SET instruction. DEST is being set; the source
1980 contains the value described by SRC_ELT. If DEST is a MEM, DEST_ADDR_ELT
1981 describes its address. */
1983 static void
1984 cselib_record_set (rtx dest, cselib_val *src_elt, cselib_val *dest_addr_elt)
1986 int dreg = REG_P (dest) ? (int) REGNO (dest) : -1;
1988 if (src_elt == 0 || side_effects_p (dest))
1989 return;
1991 if (dreg >= 0)
1993 if (dreg < FIRST_PSEUDO_REGISTER)
1995 unsigned int n = hard_regno_nregs[dreg][GET_MODE (dest)];
1997 if (n > max_value_regs)
1998 max_value_regs = n;
2001 if (REG_VALUES (dreg) == 0)
2003 used_regs[n_used_regs++] = dreg;
2004 REG_VALUES (dreg) = new_elt_list (REG_VALUES (dreg), src_elt);
2006 else
2008 /* The register should have been invalidated. */
2009 gcc_assert (REG_VALUES (dreg)->elt == 0);
2010 REG_VALUES (dreg)->elt = src_elt;
2013 if (src_elt->locs == 0 && !PRESERVED_VALUE_P (src_elt->val_rtx))
2014 n_useless_values--;
2015 src_elt->locs = new_elt_loc_list (src_elt->locs, dest);
2017 else if (MEM_P (dest) && dest_addr_elt != 0
2018 && cselib_record_memory)
2020 if (src_elt->locs == 0 && !PRESERVED_VALUE_P (src_elt->val_rtx))
2021 n_useless_values--;
2022 add_mem_for_addr (dest_addr_elt, src_elt, dest);
2026 /* There is no good way to determine how many elements there can be
2027 in a PARALLEL. Since it's fairly cheap, use a really large number. */
2028 #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
2030 /* Record the effects of any sets in INSN. */
2031 static void
2032 cselib_record_sets (rtx insn)
2034 int n_sets = 0;
2035 int i;
2036 struct cselib_set sets[MAX_SETS];
2037 rtx body = PATTERN (insn);
2038 rtx cond = 0;
2040 body = PATTERN (insn);
2041 if (GET_CODE (body) == COND_EXEC)
2043 cond = COND_EXEC_TEST (body);
2044 body = COND_EXEC_CODE (body);
2047 /* Find all sets. */
2048 if (GET_CODE (body) == SET)
2050 sets[0].src = SET_SRC (body);
2051 sets[0].dest = SET_DEST (body);
2052 n_sets = 1;
2054 else if (GET_CODE (body) == PARALLEL)
2056 /* Look through the PARALLEL and record the values being
2057 set, if possible. Also handle any CLOBBERs. */
2058 for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
2060 rtx x = XVECEXP (body, 0, i);
2062 if (GET_CODE (x) == SET)
2064 sets[n_sets].src = SET_SRC (x);
2065 sets[n_sets].dest = SET_DEST (x);
2066 n_sets++;
2071 if (n_sets == 1
2072 && MEM_P (sets[0].src)
2073 && !cselib_record_memory
2074 && MEM_READONLY_P (sets[0].src))
2076 rtx note = find_reg_equal_equiv_note (insn);
2078 if (note && CONSTANT_P (XEXP (note, 0)))
2079 sets[0].src = XEXP (note, 0);
2082 /* Look up the values that are read. Do this before invalidating the
2083 locations that are written. */
2084 for (i = 0; i < n_sets; i++)
2086 rtx dest = sets[i].dest;
2088 /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
2089 the low part after invalidating any knowledge about larger modes. */
2090 if (GET_CODE (sets[i].dest) == STRICT_LOW_PART)
2091 sets[i].dest = dest = XEXP (dest, 0);
2093 /* We don't know how to record anything but REG or MEM. */
2094 if (REG_P (dest)
2095 || (MEM_P (dest) && cselib_record_memory))
2097 rtx src = sets[i].src;
2098 if (cond)
2099 src = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), cond, src, dest);
2100 sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1);
2101 if (MEM_P (dest))
2103 enum machine_mode address_mode
2104 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (dest));
2106 sets[i].dest_addr_elt = cselib_lookup (XEXP (dest, 0),
2107 address_mode, 1);
2109 else
2110 sets[i].dest_addr_elt = 0;
2114 if (cselib_record_sets_hook)
2115 cselib_record_sets_hook (insn, sets, n_sets);
2117 /* Invalidate all locations written by this insn. Note that the elts we
2118 looked up in the previous loop aren't affected, just some of their
2119 locations may go away. */
2120 note_stores (body, cselib_invalidate_rtx_note_stores, NULL);
2122 /* If this is an asm, look for duplicate sets. This can happen when the
2123 user uses the same value as an output multiple times. This is valid
2124 if the outputs are not actually used thereafter. Treat this case as
2125 if the value isn't actually set. We do this by smashing the destination
2126 to pc_rtx, so that we won't record the value later. */
2127 if (n_sets >= 2 && asm_noperands (body) >= 0)
2129 for (i = 0; i < n_sets; i++)
2131 rtx dest = sets[i].dest;
2132 if (REG_P (dest) || MEM_P (dest))
2134 int j;
2135 for (j = i + 1; j < n_sets; j++)
2136 if (rtx_equal_p (dest, sets[j].dest))
2138 sets[i].dest = pc_rtx;
2139 sets[j].dest = pc_rtx;
2145 /* Now enter the equivalences in our tables. */
2146 for (i = 0; i < n_sets; i++)
2148 rtx dest = sets[i].dest;
2149 if (REG_P (dest)
2150 || (MEM_P (dest) && cselib_record_memory))
2151 cselib_record_set (dest, sets[i].src_elt, sets[i].dest_addr_elt);
2155 /* Record the effects of INSN. */
2157 void
2158 cselib_process_insn (rtx insn)
2160 int i;
2161 rtx x;
2163 cselib_current_insn = insn;
2165 /* Forget everything at a CODE_LABEL, a volatile asm, or a setjmp. */
2166 if (LABEL_P (insn)
2167 || (CALL_P (insn)
2168 && find_reg_note (insn, REG_SETJMP, NULL))
2169 || (NONJUMP_INSN_P (insn)
2170 && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
2171 && MEM_VOLATILE_P (PATTERN (insn))))
2173 cselib_reset_table (next_uid);
2174 cselib_current_insn = NULL_RTX;
2175 return;
2178 if (! INSN_P (insn))
2180 cselib_current_insn = NULL_RTX;
2181 return;
2184 /* If this is a call instruction, forget anything stored in a
2185 call clobbered register, or, if this is not a const call, in
2186 memory. */
2187 if (CALL_P (insn))
2189 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2190 if (call_used_regs[i]
2191 || (REG_VALUES (i) && REG_VALUES (i)->elt
2192 && HARD_REGNO_CALL_PART_CLOBBERED (i,
2193 GET_MODE (REG_VALUES (i)->elt->val_rtx))))
2194 cselib_invalidate_regno (i, reg_raw_mode[i]);
2196 /* Since it is not clear how cselib is going to be used, be
2197 conservative here and treat looping pure or const functions
2198 as if they were regular functions. */
2199 if (RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)
2200 || !(RTL_CONST_OR_PURE_CALL_P (insn)))
2201 cselib_invalidate_mem (callmem);
2204 cselib_record_sets (insn);
2206 #ifdef AUTO_INC_DEC
2207 /* Clobber any registers which appear in REG_INC notes. We
2208 could keep track of the changes to their values, but it is
2209 unlikely to help. */
2210 for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
2211 if (REG_NOTE_KIND (x) == REG_INC)
2212 cselib_invalidate_rtx (XEXP (x, 0));
2213 #endif
2215 /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
2216 after we have processed the insn. */
2217 if (CALL_P (insn))
2218 for (x = CALL_INSN_FUNCTION_USAGE (insn); x; x = XEXP (x, 1))
2219 if (GET_CODE (XEXP (x, 0)) == CLOBBER)
2220 cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0));
2222 cselib_current_insn = NULL_RTX;
2224 if (n_useless_values > MAX_USELESS_VALUES
2225 /* remove_useless_values is linear in the hash table size. Avoid
2226 quadratic behavior for very large hashtables with very few
2227 useless elements. */
2228 && ((unsigned int)n_useless_values
2229 > (cselib_hash_table->n_elements
2230 - cselib_hash_table->n_deleted
2231 - n_debug_values) / 4))
2232 remove_useless_values ();
2235 /* Initialize cselib for one pass. The caller must also call
2236 init_alias_analysis. */
2238 void
2239 cselib_init (int record_what)
2241 elt_list_pool = create_alloc_pool ("elt_list",
2242 sizeof (struct elt_list), 10);
2243 elt_loc_list_pool = create_alloc_pool ("elt_loc_list",
2244 sizeof (struct elt_loc_list), 10);
2245 cselib_val_pool = create_alloc_pool ("cselib_val_list",
2246 sizeof (cselib_val), 10);
2247 value_pool = create_alloc_pool ("value", RTX_CODE_SIZE (VALUE), 100);
2248 cselib_record_memory = record_what & CSELIB_RECORD_MEMORY;
2249 cselib_preserve_constants = record_what & CSELIB_PRESERVE_CONSTANTS;
2251 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything,
2252 see canon_true_dependence. This is only created once. */
2253 if (! callmem)
2254 callmem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
2256 cselib_nregs = max_reg_num ();
2258 /* We preserve reg_values to allow expensive clearing of the whole thing.
2259 Reallocate it however if it happens to be too large. */
2260 if (!reg_values || reg_values_size < cselib_nregs
2261 || (reg_values_size > 10 && reg_values_size > cselib_nregs * 4))
2263 if (reg_values)
2264 free (reg_values);
2265 /* Some space for newly emit instructions so we don't end up
2266 reallocating in between passes. */
2267 reg_values_size = cselib_nregs + (63 + cselib_nregs) / 16;
2268 reg_values = XCNEWVEC (struct elt_list *, reg_values_size);
2270 used_regs = XNEWVEC (unsigned int, cselib_nregs);
2271 n_used_regs = 0;
2272 cselib_hash_table = htab_create (31, get_value_hash,
2273 entry_and_rtx_equal_p, NULL);
2274 next_uid = 1;
2277 /* Called when the current user is done with cselib. */
2279 void
2280 cselib_finish (void)
2282 cselib_discard_hook = NULL;
2283 cselib_preserve_constants = false;
2284 cfa_base_preserved_val = NULL;
2285 cfa_base_preserved_regno = INVALID_REGNUM;
2286 free_alloc_pool (elt_list_pool);
2287 free_alloc_pool (elt_loc_list_pool);
2288 free_alloc_pool (cselib_val_pool);
2289 free_alloc_pool (value_pool);
2290 cselib_clear_table ();
2291 htab_delete (cselib_hash_table);
2292 free (used_regs);
2293 used_regs = 0;
2294 cselib_hash_table = 0;
2295 n_useless_values = 0;
2296 n_useless_debug_values = 0;
2297 n_debug_values = 0;
2298 next_uid = 0;
2301 /* Dump the cselib_val *X to FILE *info. */
2303 static int
2304 dump_cselib_val (void **x, void *info)
2306 cselib_val *v = (cselib_val *)*x;
2307 FILE *out = (FILE *)info;
2308 bool need_lf = true;
2310 print_inline_rtx (out, v->val_rtx, 0);
2312 if (v->locs)
2314 struct elt_loc_list *l = v->locs;
2315 if (need_lf)
2317 fputc ('\n', out);
2318 need_lf = false;
2320 fputs (" locs:", out);
2323 fprintf (out, "\n from insn %i ",
2324 INSN_UID (l->setting_insn));
2325 print_inline_rtx (out, l->loc, 4);
2327 while ((l = l->next));
2328 fputc ('\n', out);
2330 else
2332 fputs (" no locs", out);
2333 need_lf = true;
2336 if (v->addr_list)
2338 struct elt_list *e = v->addr_list;
2339 if (need_lf)
2341 fputc ('\n', out);
2342 need_lf = false;
2344 fputs (" addr list:", out);
2347 fputs ("\n ", out);
2348 print_inline_rtx (out, e->elt->val_rtx, 2);
2350 while ((e = e->next));
2351 fputc ('\n', out);
2353 else
2355 fputs (" no addrs", out);
2356 need_lf = true;
2359 if (v->next_containing_mem == &dummy_val)
2360 fputs (" last mem\n", out);
2361 else if (v->next_containing_mem)
2363 fputs (" next mem ", out);
2364 print_inline_rtx (out, v->next_containing_mem->val_rtx, 2);
2365 fputc ('\n', out);
2367 else if (need_lf)
2368 fputc ('\n', out);
2370 return 1;
2373 /* Dump to OUT everything in the CSELIB table. */
2375 void
2376 dump_cselib_table (FILE *out)
2378 fprintf (out, "cselib hash table:\n");
2379 htab_traverse (cselib_hash_table, dump_cselib_val, out);
2380 if (first_containing_mem != &dummy_val)
2382 fputs ("first mem ", out);
2383 print_inline_rtx (out, first_containing_mem->val_rtx, 2);
2384 fputc ('\n', out);
2386 fprintf (out, "next uid %i\n", next_uid);
2389 #include "gt-cselib.h"