OSDN Git Service

Remove extra pathname.
[pf3gnuchains/gcc-fork.git] / gcc / cselib.c
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
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26
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 "real.h"
33 #include "insn-config.h"
34 #include "recog.h"
35 #include "function.h"
36 #include "emit-rtl.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
47 static bool cselib_record_memory;
48 static int entry_and_rtx_equal_p (const void *, const void *);
49 static hashval_t get_value_hash (const void *);
50 static struct elt_list *new_elt_list (struct elt_list *, cselib_val *);
51 static struct elt_loc_list *new_elt_loc_list (struct elt_loc_list *, rtx);
52 static void unchain_one_value (cselib_val *);
53 static void unchain_one_elt_list (struct elt_list **);
54 static void unchain_one_elt_loc_list (struct elt_loc_list **);
55 static int discard_useless_locs (void **, void *);
56 static int discard_useless_values (void **, void *);
57 static void remove_useless_values (void);
58 static unsigned int cselib_hash_rtx (rtx, int);
59 static cselib_val *new_cselib_val (unsigned int, enum machine_mode, rtx);
60 static void add_mem_for_addr (cselib_val *, cselib_val *, rtx);
61 static cselib_val *cselib_lookup_mem (rtx, int);
62 static void cselib_invalidate_regno (unsigned int, enum machine_mode);
63 static void cselib_invalidate_mem (rtx);
64 static void cselib_record_set (rtx, cselib_val *, cselib_val *);
65 static void cselib_record_sets (rtx);
66
67 struct expand_value_data
68 {
69   bitmap regs_active;
70   cselib_expand_callback callback;
71   void *callback_arg;
72 };
73
74 static rtx cselib_expand_value_rtx_1 (rtx, struct expand_value_data *, int);
75
76 /* There are three ways in which cselib can look up an rtx:
77    - for a REG, the reg_values table (which is indexed by regno) is used
78    - for a MEM, we recursively look up its address and then follow the
79      addr_list of that value
80    - for everything else, we compute a hash value and go through the hash
81      table.  Since different rtx's can still have the same hash value,
82      this involves walking the table entries for a given value and comparing
83      the locations of the entries with the rtx we are looking up.  */
84
85 /* A table that enables us to look up elts by their value.  */
86 static htab_t cselib_hash_table;
87
88 /* This is a global so we don't have to pass this through every function.
89    It is used in new_elt_loc_list to set SETTING_INSN.  */
90 static rtx cselib_current_insn;
91
92 /* Every new unknown value gets a unique number.  */
93 static unsigned int next_unknown_value;
94
95 /* The number of registers we had when the varrays were last resized.  */
96 static unsigned int cselib_nregs;
97
98 /* Count values without known locations.  Whenever this grows too big, we
99    remove these useless values from the table.  */
100 static int n_useless_values;
101
102 /* Number of useless values before we remove them from the hash table.  */
103 #define MAX_USELESS_VALUES 32
104
105 /* This table maps from register number to values.  It does not
106    contain pointers to cselib_val structures, but rather elt_lists.
107    The purpose is to be able to refer to the same register in
108    different modes.  The first element of the list defines the mode in
109    which the register was set; if the mode is unknown or the value is
110    no longer valid in that mode, ELT will be NULL for the first
111    element.  */
112 static struct elt_list **reg_values;
113 static unsigned int reg_values_size;
114 #define REG_VALUES(i) reg_values[i]
115
116 /* The largest number of hard regs used by any entry added to the
117    REG_VALUES table.  Cleared on each cselib_clear_table() invocation.  */
118 static unsigned int max_value_regs;
119
120 /* Here the set of indices I with REG_VALUES(I) != 0 is saved.  This is used
121    in cselib_clear_table() for fast emptying.  */
122 static unsigned int *used_regs;
123 static unsigned int n_used_regs;
124
125 /* We pass this to cselib_invalidate_mem to invalidate all of
126    memory for a non-const call instruction.  */
127 static GTY(()) rtx callmem;
128
129 /* Set by discard_useless_locs if it deleted the last location of any
130    value.  */
131 static int values_became_useless;
132
133 /* Used as stop element of the containing_mem list so we can check
134    presence in the list by checking the next pointer.  */
135 static cselib_val dummy_val;
136
137 /* Used to list all values that contain memory reference.
138    May or may not contain the useless values - the list is compacted
139    each time memory is invalidated.  */
140 static cselib_val *first_containing_mem = &dummy_val;
141 static alloc_pool elt_loc_list_pool, elt_list_pool, cselib_val_pool, value_pool;
142
143 /* If nonnull, cselib will call this function before freeing useless
144    VALUEs.  A VALUE is deemed useless if its "locs" field is null.  */
145 void (*cselib_discard_hook) (cselib_val *);
146
147 /* If nonnull, cselib will call this function before recording sets or
148    even clobbering outputs of INSN.  All the recorded sets will be
149    represented in the array sets[n_sets].  new_val_min can be used to
150    tell whether values present in sets are introduced by this
151    instruction.  */
152 void (*cselib_record_sets_hook) (rtx insn, struct cselib_set *sets,
153                                  int n_sets);
154
155 #define PRESERVED_VALUE_P(RTX) \
156   (RTL_FLAG_CHECK1("PRESERVED_VALUE_P", (RTX), VALUE)->unchanging)
157 #define LONG_TERM_PRESERVED_VALUE_P(RTX) \
158   (RTL_FLAG_CHECK1("LONG_TERM_PRESERVED_VALUE_P", (RTX), VALUE)->in_struct)
159
160 \f
161
162 /* Allocate a struct elt_list and fill in its two elements with the
163    arguments.  */
164
165 static inline struct elt_list *
166 new_elt_list (struct elt_list *next, cselib_val *elt)
167 {
168   struct elt_list *el;
169   el = (struct elt_list *) pool_alloc (elt_list_pool);
170   el->next = next;
171   el->elt = elt;
172   return el;
173 }
174
175 /* Allocate a struct elt_loc_list and fill in its two elements with the
176    arguments.  */
177
178 static inline struct elt_loc_list *
179 new_elt_loc_list (struct elt_loc_list *next, rtx loc)
180 {
181   struct elt_loc_list *el;
182   el = (struct elt_loc_list *) pool_alloc (elt_loc_list_pool);
183   el->next = next;
184   el->loc = loc;
185   el->setting_insn = cselib_current_insn;
186   return el;
187 }
188
189 /* The elt_list at *PL is no longer needed.  Unchain it and free its
190    storage.  */
191
192 static inline void
193 unchain_one_elt_list (struct elt_list **pl)
194 {
195   struct elt_list *l = *pl;
196
197   *pl = l->next;
198   pool_free (elt_list_pool, l);
199 }
200
201 /* Likewise for elt_loc_lists.  */
202
203 static void
204 unchain_one_elt_loc_list (struct elt_loc_list **pl)
205 {
206   struct elt_loc_list *l = *pl;
207
208   *pl = l->next;
209   pool_free (elt_loc_list_pool, l);
210 }
211
212 /* Likewise for cselib_vals.  This also frees the addr_list associated with
213    V.  */
214
215 static void
216 unchain_one_value (cselib_val *v)
217 {
218   while (v->addr_list)
219     unchain_one_elt_list (&v->addr_list);
220
221   pool_free (cselib_val_pool, v);
222 }
223
224 /* Remove all entries from the hash table.  Also used during
225    initialization.  */
226
227 void
228 cselib_clear_table (void)
229 {
230   cselib_reset_table_with_next_value (0);
231 }
232
233 /* Remove all entries from the hash table, arranging for the next
234    value to be numbered NUM.  */
235
236 void
237 cselib_reset_table_with_next_value (unsigned int num)
238 {
239   unsigned int i;
240
241   for (i = 0; i < n_used_regs; i++)
242     REG_VALUES (used_regs[i]) = 0;
243
244   max_value_regs = 0;
245
246   n_used_regs = 0;
247
248   /* ??? Preserve constants?  */
249   htab_empty (cselib_hash_table);
250
251   n_useless_values = 0;
252
253   next_unknown_value = num;
254
255   first_containing_mem = &dummy_val;
256 }
257
258 /* Return the number of the next value that will be generated.  */
259
260 unsigned int
261 cselib_get_next_unknown_value (void)
262 {
263   return next_unknown_value;
264 }
265
266 /* The equality test for our hash table.  The first argument ENTRY is a table
267    element (i.e. a cselib_val), while the second arg X is an rtx.  We know
268    that all callers of htab_find_slot_with_hash will wrap CONST_INTs into a
269    CONST of an appropriate mode.  */
270
271 static int
272 entry_and_rtx_equal_p (const void *entry, const void *x_arg)
273 {
274   struct elt_loc_list *l;
275   const cselib_val *const v = (const cselib_val *) entry;
276   rtx x = CONST_CAST_RTX ((const_rtx)x_arg);
277   enum machine_mode mode = GET_MODE (x);
278
279   gcc_assert (!CONST_INT_P (x) && GET_CODE (x) != CONST_FIXED
280               && (mode != VOIDmode || GET_CODE (x) != CONST_DOUBLE));
281   
282   if (mode != GET_MODE (v->val_rtx))
283     return 0;
284
285   /* Unwrap X if necessary.  */
286   if (GET_CODE (x) == CONST
287       && (CONST_INT_P (XEXP (x, 0))
288           || GET_CODE (XEXP (x, 0)) == CONST_FIXED
289           || GET_CODE (XEXP (x, 0)) == CONST_DOUBLE))
290     x = XEXP (x, 0);
291
292   /* We don't guarantee that distinct rtx's have different hash values,
293      so we need to do a comparison.  */
294   for (l = v->locs; l; l = l->next)
295     if (rtx_equal_for_cselib_p (l->loc, x))
296       return 1;
297
298   return 0;
299 }
300
301 /* The hash function for our hash table.  The value is always computed with
302    cselib_hash_rtx when adding an element; this function just extracts the
303    hash value from a cselib_val structure.  */
304
305 static hashval_t
306 get_value_hash (const void *entry)
307 {
308   const cselib_val *const v = (const cselib_val *) entry;
309   return v->value;
310 }
311
312 /* Return true if X contains a VALUE rtx.  If ONLY_USELESS is set, we
313    only return true for values which point to a cselib_val whose value
314    element has been set to zero, which implies the cselib_val will be
315    removed.  */
316
317 int
318 references_value_p (const_rtx x, int only_useless)
319 {
320   const enum rtx_code code = GET_CODE (x);
321   const char *fmt = GET_RTX_FORMAT (code);
322   int i, j;
323
324   if (GET_CODE (x) == VALUE
325       && (! only_useless || CSELIB_VAL_PTR (x)->locs == 0))
326     return 1;
327
328   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
329     {
330       if (fmt[i] == 'e' && references_value_p (XEXP (x, i), only_useless))
331         return 1;
332       else if (fmt[i] == 'E')
333         for (j = 0; j < XVECLEN (x, i); j++)
334           if (references_value_p (XVECEXP (x, i, j), only_useless))
335             return 1;
336     }
337
338   return 0;
339 }
340
341 /* For all locations found in X, delete locations that reference useless
342    values (i.e. values without any location).  Called through
343    htab_traverse.  */
344
345 static int
346 discard_useless_locs (void **x, void *info ATTRIBUTE_UNUSED)
347 {
348   cselib_val *v = (cselib_val *)*x;
349   struct elt_loc_list **p = &v->locs;
350   int had_locs = v->locs != 0;
351
352   while (*p)
353     {
354       if (references_value_p ((*p)->loc, 1))
355         unchain_one_elt_loc_list (p);
356       else
357         p = &(*p)->next;
358     }
359
360   if (had_locs && v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
361     {
362       n_useless_values++;
363       values_became_useless = 1;
364     }
365   return 1;
366 }
367
368 /* If X is a value with no locations, remove it from the hashtable.  */
369
370 static int
371 discard_useless_values (void **x, void *info ATTRIBUTE_UNUSED)
372 {
373   cselib_val *v = (cselib_val *)*x;
374
375   if (v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
376     {
377       if (cselib_discard_hook)
378         cselib_discard_hook (v);
379
380       CSELIB_VAL_PTR (v->val_rtx) = NULL;
381       htab_clear_slot (cselib_hash_table, x);
382       unchain_one_value (v);
383       n_useless_values--;
384     }
385
386   return 1;
387 }
388
389 /* Clean out useless values (i.e. those which no longer have locations
390    associated with them) from the hash table.  */
391
392 static void
393 remove_useless_values (void)
394 {
395   cselib_val **p, *v;
396   /* First pass: eliminate locations that reference the value.  That in
397      turn can make more values useless.  */
398   do
399     {
400       values_became_useless = 0;
401       htab_traverse (cselib_hash_table, discard_useless_locs, 0);
402     }
403   while (values_became_useless);
404
405   /* Second pass: actually remove the values.  */
406
407   p = &first_containing_mem;
408   for (v = *p; v != &dummy_val; v = v->next_containing_mem)
409     if (v->locs)
410       {
411         *p = v;
412         p = &(*p)->next_containing_mem;
413       }
414   *p = &dummy_val;
415
416   htab_traverse (cselib_hash_table, discard_useless_values, 0);
417
418   gcc_assert (!n_useless_values);
419 }
420
421 /* Arrange for a value to not be removed from the hash table even if
422    it becomes useless.  */
423
424 void
425 cselib_preserve_value (cselib_val *v)
426 {
427   PRESERVED_VALUE_P (v->val_rtx) = 1;
428 }
429
430 /* Test whether a value is preserved.  */
431
432 bool
433 cselib_preserved_value_p (cselib_val *v)
434 {
435   return PRESERVED_VALUE_P (v->val_rtx);
436 }
437
438 /* Mark preserved values as preserved for the long term.  */
439
440 static int
441 cselib_preserve_definitely (void **slot, void *info ATTRIBUTE_UNUSED)
442 {
443   cselib_val *v = (cselib_val *)*slot;
444
445   if (PRESERVED_VALUE_P (v->val_rtx)
446       && !LONG_TERM_PRESERVED_VALUE_P (v->val_rtx))
447     LONG_TERM_PRESERVED_VALUE_P (v->val_rtx) = true;
448
449   return 1;
450 }
451
452 /* Clear the preserve marks for values not preserved for the long
453    term.  */
454
455 static int
456 cselib_clear_preserve (void **slot, void *info ATTRIBUTE_UNUSED)
457 {
458   cselib_val *v = (cselib_val *)*slot;
459
460   if (PRESERVED_VALUE_P (v->val_rtx)
461       && !LONG_TERM_PRESERVED_VALUE_P (v->val_rtx))
462     {
463       PRESERVED_VALUE_P (v->val_rtx) = false;
464       if (!v->locs)
465         n_useless_values++;
466     }
467
468   return 1;
469 }
470
471 /* Clean all non-constant expressions in the hash table, but retain
472    their values.  */
473
474 void
475 cselib_preserve_only_values (bool retain)
476 {
477   int i;
478
479   htab_traverse (cselib_hash_table,
480                  retain ? cselib_preserve_definitely : cselib_clear_preserve,
481                  NULL);
482
483   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
484     cselib_invalidate_regno (i, reg_raw_mode[i]);
485
486   cselib_invalidate_mem (callmem);
487
488   remove_useless_values ();
489
490   gcc_assert (first_containing_mem == &dummy_val);
491 }
492
493 /* Return the mode in which a register was last set.  If X is not a
494    register, return its mode.  If the mode in which the register was
495    set is not known, or the value was already clobbered, return
496    VOIDmode.  */
497
498 enum machine_mode
499 cselib_reg_set_mode (const_rtx x)
500 {
501   if (!REG_P (x))
502     return GET_MODE (x);
503
504   if (REG_VALUES (REGNO (x)) == NULL
505       || REG_VALUES (REGNO (x))->elt == NULL)
506     return VOIDmode;
507
508   return GET_MODE (REG_VALUES (REGNO (x))->elt->val_rtx);
509 }
510
511 /* Return nonzero if we can prove that X and Y contain the same value, taking
512    our gathered information into account.  */
513
514 int
515 rtx_equal_for_cselib_p (rtx x, rtx y)
516 {
517   enum rtx_code code;
518   const char *fmt;
519   int i;
520
521   if (REG_P (x) || MEM_P (x))
522     {
523       cselib_val *e = cselib_lookup (x, GET_MODE (x), 0);
524
525       if (e)
526         x = e->val_rtx;
527     }
528
529   if (REG_P (y) || MEM_P (y))
530     {
531       cselib_val *e = cselib_lookup (y, GET_MODE (y), 0);
532
533       if (e)
534         y = e->val_rtx;
535     }
536
537   if (x == y)
538     return 1;
539
540   if (GET_CODE (x) == VALUE && GET_CODE (y) == VALUE)
541     return CSELIB_VAL_PTR (x) == CSELIB_VAL_PTR (y);
542
543   if (GET_CODE (x) == VALUE)
544     {
545       cselib_val *e = CSELIB_VAL_PTR (x);
546       struct elt_loc_list *l;
547
548       for (l = e->locs; l; l = l->next)
549         {
550           rtx t = l->loc;
551
552           /* Avoid infinite recursion.  */
553           if (REG_P (t) || MEM_P (t))
554             continue;
555           else if (rtx_equal_for_cselib_p (t, y))
556             return 1;
557         }
558
559       return 0;
560     }
561
562   if (GET_CODE (y) == VALUE)
563     {
564       cselib_val *e = CSELIB_VAL_PTR (y);
565       struct elt_loc_list *l;
566
567       for (l = e->locs; l; l = l->next)
568         {
569           rtx t = l->loc;
570
571           if (REG_P (t) || MEM_P (t))
572             continue;
573           else if (rtx_equal_for_cselib_p (x, t))
574             return 1;
575         }
576
577       return 0;
578     }
579
580   if (GET_CODE (x) != GET_CODE (y) || GET_MODE (x) != GET_MODE (y))
581     return 0;
582
583   /* These won't be handled correctly by the code below.  */
584   switch (GET_CODE (x))
585     {
586     case CONST_DOUBLE:
587     case CONST_FIXED:
588     case DEBUG_EXPR:
589       return 0;
590
591     case LABEL_REF:
592       return XEXP (x, 0) == XEXP (y, 0);
593
594     default:
595       break;
596     }
597
598   code = GET_CODE (x);
599   fmt = GET_RTX_FORMAT (code);
600
601   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
602     {
603       int j;
604
605       switch (fmt[i])
606         {
607         case 'w':
608           if (XWINT (x, i) != XWINT (y, i))
609             return 0;
610           break;
611
612         case 'n':
613         case 'i':
614           if (XINT (x, i) != XINT (y, i))
615             return 0;
616           break;
617
618         case 'V':
619         case 'E':
620           /* Two vectors must have the same length.  */
621           if (XVECLEN (x, i) != XVECLEN (y, i))
622             return 0;
623
624           /* And the corresponding elements must match.  */
625           for (j = 0; j < XVECLEN (x, i); j++)
626             if (! rtx_equal_for_cselib_p (XVECEXP (x, i, j),
627                                           XVECEXP (y, i, j)))
628               return 0;
629           break;
630
631         case 'e':
632           if (i == 1
633               && targetm.commutative_p (x, UNKNOWN)
634               && rtx_equal_for_cselib_p (XEXP (x, 1), XEXP (y, 0))
635               && rtx_equal_for_cselib_p (XEXP (x, 0), XEXP (y, 1)))
636             return 1;
637           if (! rtx_equal_for_cselib_p (XEXP (x, i), XEXP (y, i)))
638             return 0;
639           break;
640
641         case 'S':
642         case 's':
643           if (strcmp (XSTR (x, i), XSTR (y, i)))
644             return 0;
645           break;
646
647         case 'u':
648           /* These are just backpointers, so they don't matter.  */
649           break;
650
651         case '0':
652         case 't':
653           break;
654
655           /* It is believed that rtx's at this level will never
656              contain anything but integers and other rtx's,
657              except for within LABEL_REFs and SYMBOL_REFs.  */
658         default:
659           gcc_unreachable ();
660         }
661     }
662   return 1;
663 }
664
665 /* Hash an rtx.  Return 0 if we couldn't hash the rtx.
666    For registers and memory locations, we look up their cselib_val structure
667    and return its VALUE element.
668    Possible reasons for return 0 are: the object is volatile, or we couldn't
669    find a register or memory location in the table and CREATE is zero.  If
670    CREATE is nonzero, table elts are created for regs and mem.
671    N.B. this hash function returns the same hash value for RTXes that
672    differ only in the order of operands, thus it is suitable for comparisons
673    that take commutativity into account.
674    If we wanted to also support associative rules, we'd have to use a different
675    strategy to avoid returning spurious 0, e.g. return ~(~0U >> 1) .
676    We used to have a MODE argument for hashing for CONST_INTs, but that
677    didn't make sense, since it caused spurious hash differences between
678     (set (reg:SI 1) (const_int))
679     (plus:SI (reg:SI 2) (reg:SI 1))
680    and
681     (plus:SI (reg:SI 2) (const_int))
682    If the mode is important in any context, it must be checked specifically
683    in a comparison anyway, since relying on hash differences is unsafe.  */
684
685 static unsigned int
686 cselib_hash_rtx (rtx x, int create)
687 {
688   cselib_val *e;
689   int i, j;
690   enum rtx_code code;
691   const char *fmt;
692   unsigned int hash = 0;
693
694   code = GET_CODE (x);
695   hash += (unsigned) code + (unsigned) GET_MODE (x);
696
697   switch (code)
698     {
699     case MEM:
700     case REG:
701       e = cselib_lookup (x, GET_MODE (x), create);
702       if (! e)
703         return 0;
704
705       return e->value;
706
707     case DEBUG_EXPR:
708       hash += ((unsigned) DEBUG_EXPR << 7)
709               + DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x));
710       return hash ? hash : (unsigned int) DEBUG_EXPR;
711
712     case CONST_INT:
713       hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
714       return hash ? hash : (unsigned int) CONST_INT;
715
716     case CONST_DOUBLE:
717       /* This is like the general case, except that it only counts
718          the integers representing the constant.  */
719       hash += (unsigned) code + (unsigned) GET_MODE (x);
720       if (GET_MODE (x) != VOIDmode)
721         hash += real_hash (CONST_DOUBLE_REAL_VALUE (x));
722       else
723         hash += ((unsigned) CONST_DOUBLE_LOW (x)
724                  + (unsigned) CONST_DOUBLE_HIGH (x));
725       return hash ? hash : (unsigned int) CONST_DOUBLE;
726
727     case CONST_FIXED:
728       hash += (unsigned int) code + (unsigned int) GET_MODE (x);
729       hash += fixed_hash (CONST_FIXED_VALUE (x));
730       return hash ? hash : (unsigned int) CONST_FIXED;
731
732     case CONST_VECTOR:
733       {
734         int units;
735         rtx elt;
736
737         units = CONST_VECTOR_NUNITS (x);
738
739         for (i = 0; i < units; ++i)
740           {
741             elt = CONST_VECTOR_ELT (x, i);
742             hash += cselib_hash_rtx (elt, 0);
743           }
744
745         return hash;
746       }
747
748       /* Assume there is only one rtx object for any given label.  */
749     case LABEL_REF:
750       /* We don't hash on the address of the CODE_LABEL to avoid bootstrap
751          differences and differences between each stage's debugging dumps.  */
752       hash += (((unsigned int) LABEL_REF << 7)
753                + CODE_LABEL_NUMBER (XEXP (x, 0)));
754       return hash ? hash : (unsigned int) LABEL_REF;
755
756     case SYMBOL_REF:
757       {
758         /* Don't hash on the symbol's address to avoid bootstrap differences.
759            Different hash values may cause expressions to be recorded in
760            different orders and thus different registers to be used in the
761            final assembler.  This also avoids differences in the dump files
762            between various stages.  */
763         unsigned int h = 0;
764         const unsigned char *p = (const unsigned char *) XSTR (x, 0);
765
766         while (*p)
767           h += (h << 7) + *p++; /* ??? revisit */
768
769         hash += ((unsigned int) SYMBOL_REF << 7) + h;
770         return hash ? hash : (unsigned int) SYMBOL_REF;
771       }
772
773     case PRE_DEC:
774     case PRE_INC:
775     case POST_DEC:
776     case POST_INC:
777     case POST_MODIFY:
778     case PRE_MODIFY:
779     case PC:
780     case CC0:
781     case CALL:
782     case UNSPEC_VOLATILE:
783       return 0;
784
785     case ASM_OPERANDS:
786       if (MEM_VOLATILE_P (x))
787         return 0;
788
789       break;
790
791     default:
792       break;
793     }
794
795   i = GET_RTX_LENGTH (code) - 1;
796   fmt = GET_RTX_FORMAT (code);
797   for (; i >= 0; i--)
798     {
799       switch (fmt[i])
800         {
801         case 'e':
802           {
803             rtx tem = XEXP (x, i);
804             unsigned int tem_hash = cselib_hash_rtx (tem, create);
805             
806             if (tem_hash == 0)
807               return 0;
808             
809             hash += tem_hash;
810           }
811           break;
812         case 'E':
813           for (j = 0; j < XVECLEN (x, i); j++)
814             {
815               unsigned int tem_hash
816                 = cselib_hash_rtx (XVECEXP (x, i, j), create);
817               
818               if (tem_hash == 0)
819                 return 0;
820               
821               hash += tem_hash;
822             }
823           break;
824
825         case 's':
826           {
827             const unsigned char *p = (const unsigned char *) XSTR (x, i);
828             
829             if (p)
830               while (*p)
831                 hash += *p++;
832             break;
833           }
834           
835         case 'i':
836           hash += XINT (x, i);
837           break;
838
839         case '0':
840         case 't':
841           /* unused */
842           break;
843           
844         default:
845           gcc_unreachable ();
846         }
847     }
848
849   return hash ? hash : 1 + (unsigned int) GET_CODE (x);
850 }
851
852 /* Create a new value structure for VALUE and initialize it.  The mode of the
853    value is MODE.  */
854
855 static inline cselib_val *
856 new_cselib_val (unsigned int value, enum machine_mode mode, rtx x)
857 {
858   cselib_val *e = (cselib_val *) pool_alloc (cselib_val_pool);
859
860   gcc_assert (value);
861
862   e->value = value;
863   /* We use an alloc pool to allocate this RTL construct because it
864      accounts for about 8% of the overall memory usage.  We know
865      precisely when we can have VALUE RTXen (when cselib is active)
866      so we don't need to put them in garbage collected memory.
867      ??? Why should a VALUE be an RTX in the first place?  */
868   e->val_rtx = (rtx) pool_alloc (value_pool);
869   memset (e->val_rtx, 0, RTX_HDR_SIZE);
870   PUT_CODE (e->val_rtx, VALUE);
871   PUT_MODE (e->val_rtx, mode);
872   CSELIB_VAL_PTR (e->val_rtx) = e;
873   e->addr_list = 0;
874   e->locs = 0;
875   e->next_containing_mem = 0;
876
877   if (dump_file && (dump_flags & TDF_DETAILS))
878     {
879       fprintf (dump_file, "cselib value %u ", value);
880       if (flag_dump_noaddr || flag_dump_unnumbered)
881         fputs ("# ", dump_file);
882       else
883         fprintf (dump_file, "%p ", (void*)e);
884       print_rtl_single (dump_file, x);
885       fputc ('\n', dump_file);
886     }
887
888   return e;
889 }
890
891 /* ADDR_ELT is a value that is used as address.  MEM_ELT is the value that
892    contains the data at this address.  X is a MEM that represents the
893    value.  Update the two value structures to represent this situation.  */
894
895 static void
896 add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
897 {
898   struct elt_loc_list *l;
899
900   /* Avoid duplicates.  */
901   for (l = mem_elt->locs; l; l = l->next)
902     if (MEM_P (l->loc)
903         && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt)
904       return;
905
906   addr_elt->addr_list = new_elt_list (addr_elt->addr_list, mem_elt);
907   mem_elt->locs
908     = new_elt_loc_list (mem_elt->locs,
909                         replace_equiv_address_nv (x, addr_elt->val_rtx));
910   if (mem_elt->next_containing_mem == NULL)
911     {
912       mem_elt->next_containing_mem = first_containing_mem;
913       first_containing_mem = mem_elt;
914     }
915 }
916
917 /* Subroutine of cselib_lookup.  Return a value for X, which is a MEM rtx.
918    If CREATE, make a new one if we haven't seen it before.  */
919
920 static cselib_val *
921 cselib_lookup_mem (rtx x, int create)
922 {
923   enum machine_mode mode = GET_MODE (x);
924   void **slot;
925   cselib_val *addr;
926   cselib_val *mem_elt;
927   struct elt_list *l;
928
929   if (MEM_VOLATILE_P (x) || mode == BLKmode
930       || !cselib_record_memory
931       || (FLOAT_MODE_P (mode) && flag_float_store))
932     return 0;
933
934   /* Look up the value for the address.  */
935   addr = cselib_lookup (XEXP (x, 0), mode, create);
936   if (! addr)
937     return 0;
938
939   /* Find a value that describes a value of our mode at that address.  */
940   for (l = addr->addr_list; l; l = l->next)
941     if (GET_MODE (l->elt->val_rtx) == mode)
942       return l->elt;
943
944   if (! create)
945     return 0;
946
947   mem_elt = new_cselib_val (++next_unknown_value, mode, x);
948   add_mem_for_addr (addr, mem_elt, x);
949   slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
950                                    mem_elt->value, INSERT);
951   *slot = mem_elt;
952   return mem_elt;
953 }
954
955 /* Search thru the possible substitutions in P.  We prefer a non reg
956    substitution because this allows us to expand the tree further.  If
957    we find, just a reg, take the lowest regno.  There may be several
958    non-reg results, we just take the first one because they will all
959    expand to the same place.  */
960
961 static rtx 
962 expand_loc (struct elt_loc_list *p, struct expand_value_data *evd,
963             int max_depth)
964 {
965   rtx reg_result = NULL;
966   unsigned int regno = UINT_MAX;
967   struct elt_loc_list *p_in = p;
968
969   for (; p; p = p -> next)
970     {
971       /* Avoid infinite recursion trying to expand a reg into a
972          the same reg.  */
973       if ((REG_P (p->loc)) 
974           && (REGNO (p->loc) < regno) 
975           && !bitmap_bit_p (evd->regs_active, REGNO (p->loc)))
976         {
977           reg_result = p->loc;
978           regno = REGNO (p->loc);
979         }
980       /* Avoid infinite recursion and do not try to expand the
981          value.  */
982       else if (GET_CODE (p->loc) == VALUE 
983                && CSELIB_VAL_PTR (p->loc)->locs == p_in)
984         continue;
985       else if (!REG_P (p->loc))
986         {
987           rtx result, note;
988           if (dump_file && (dump_flags & TDF_DETAILS))
989             {
990               print_inline_rtx (dump_file, p->loc, 0);
991               fprintf (dump_file, "\n");
992             }
993           if (GET_CODE (p->loc) == LO_SUM
994               && GET_CODE (XEXP (p->loc, 1)) == SYMBOL_REF
995               && p->setting_insn
996               && (note = find_reg_note (p->setting_insn, REG_EQUAL, NULL_RTX))
997               && XEXP (note, 0) == XEXP (p->loc, 1))
998             return XEXP (p->loc, 1);
999           result = cselib_expand_value_rtx_1 (p->loc, evd, max_depth - 1);
1000           if (result)
1001             return result;
1002         }
1003         
1004     }
1005   
1006   if (regno != UINT_MAX)
1007     {
1008       rtx result;
1009       if (dump_file && (dump_flags & TDF_DETAILS))
1010         fprintf (dump_file, "r%d\n", regno);
1011
1012       result = cselib_expand_value_rtx_1 (reg_result, evd, max_depth - 1);
1013       if (result)
1014         return result;
1015     }
1016
1017   if (dump_file && (dump_flags & TDF_DETAILS))
1018     {
1019       if (reg_result)
1020         {
1021           print_inline_rtx (dump_file, reg_result, 0);
1022           fprintf (dump_file, "\n");
1023         }
1024       else 
1025         fprintf (dump_file, "NULL\n");
1026     }
1027   return reg_result;
1028 }
1029
1030
1031 /* Forward substitute and expand an expression out to its roots.
1032    This is the opposite of common subexpression.  Because local value
1033    numbering is such a weak optimization, the expanded expression is
1034    pretty much unique (not from a pointer equals point of view but
1035    from a tree shape point of view.  
1036
1037    This function returns NULL if the expansion fails.  The expansion
1038    will fail if there is no value number for one of the operands or if
1039    one of the operands has been overwritten between the current insn
1040    and the beginning of the basic block.  For instance x has no
1041    expansion in:
1042
1043    r1 <- r1 + 3
1044    x <- r1 + 8
1045
1046    REGS_ACTIVE is a scratch bitmap that should be clear when passing in.
1047    It is clear on return.  */
1048
1049 rtx
1050 cselib_expand_value_rtx (rtx orig, bitmap regs_active, int max_depth)
1051 {
1052   struct expand_value_data evd;
1053
1054   evd.regs_active = regs_active;
1055   evd.callback = NULL;
1056   evd.callback_arg = NULL;
1057
1058   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
1059 }
1060
1061 /* Same as cselib_expand_value_rtx, but using a callback to try to
1062    resolve some expressions.  The CB function should return ORIG if it
1063    can't or does not want to deal with a certain RTX.  Any other
1064    return value, including NULL, will be used as the expansion for
1065    VALUE, without any further changes.  */
1066
1067 rtx
1068 cselib_expand_value_rtx_cb (rtx orig, bitmap regs_active, int max_depth,
1069                             cselib_expand_callback cb, void *data)
1070 {
1071   struct expand_value_data evd;
1072
1073   evd.regs_active = regs_active;
1074   evd.callback = cb;
1075   evd.callback_arg = data;
1076
1077   return cselib_expand_value_rtx_1 (orig, &evd, max_depth);
1078 }
1079
1080 /* Internal implementation of cselib_expand_value_rtx and
1081    cselib_expand_value_rtx_cb.  */
1082
1083 static rtx
1084 cselib_expand_value_rtx_1 (rtx orig, struct expand_value_data *evd,
1085                            int max_depth)
1086 {
1087   rtx copy, scopy;
1088   int i, j;
1089   RTX_CODE code;
1090   const char *format_ptr;
1091   enum machine_mode mode;
1092
1093   code = GET_CODE (orig);
1094
1095   /* For the context of dse, if we end up expand into a huge tree, we
1096      will not have a useful address, so we might as well just give up
1097      quickly.  */
1098   if (max_depth <= 0)
1099     return NULL;
1100
1101   switch (code)
1102     {
1103     case REG:
1104       {
1105         struct elt_list *l = REG_VALUES (REGNO (orig));
1106
1107         if (l && l->elt == NULL)
1108           l = l->next;
1109         for (; l; l = l->next)
1110           if (GET_MODE (l->elt->val_rtx) == GET_MODE (orig))
1111             {
1112               rtx result;
1113               int regno = REGNO (orig);
1114               
1115               /* The only thing that we are not willing to do (this
1116                  is requirement of dse and if others potential uses
1117                  need this function we should add a parm to control
1118                  it) is that we will not substitute the
1119                  STACK_POINTER_REGNUM, FRAME_POINTER or the
1120                  HARD_FRAME_POINTER.
1121
1122                  These expansions confuses the code that notices that
1123                  stores into the frame go dead at the end of the
1124                  function and that the frame is not effected by calls
1125                  to subroutines.  If you allow the
1126                  STACK_POINTER_REGNUM substitution, then dse will
1127                  think that parameter pushing also goes dead which is
1128                  wrong.  If you allow the FRAME_POINTER or the
1129                  HARD_FRAME_POINTER then you lose the opportunity to
1130                  make the frame assumptions.  */
1131               if (regno == STACK_POINTER_REGNUM
1132                   || regno == FRAME_POINTER_REGNUM
1133                   || regno == HARD_FRAME_POINTER_REGNUM)
1134                 return orig;
1135
1136               bitmap_set_bit (evd->regs_active, regno);
1137
1138               if (dump_file && (dump_flags & TDF_DETAILS))
1139                 fprintf (dump_file, "expanding: r%d into: ", regno);
1140
1141               result = expand_loc (l->elt->locs, evd, max_depth);
1142               bitmap_clear_bit (evd->regs_active, regno);
1143
1144               if (result)
1145                 return result;
1146               else 
1147                 return orig;
1148             }
1149       }
1150       
1151     case CONST_INT:
1152     case CONST_DOUBLE:
1153     case CONST_VECTOR:
1154     case SYMBOL_REF:
1155     case CODE_LABEL:
1156     case PC:
1157     case CC0:
1158     case SCRATCH:
1159       /* SCRATCH must be shared because they represent distinct values.  */
1160       return orig;
1161     case CLOBBER:
1162       if (REG_P (XEXP (orig, 0)) && HARD_REGISTER_NUM_P (REGNO (XEXP (orig, 0))))
1163         return orig;
1164       break;
1165
1166     case CONST:
1167       if (shared_const_p (orig))
1168         return orig;
1169       break;
1170
1171     case SUBREG:
1172       {
1173         rtx subreg;
1174
1175         if (evd->callback)
1176           {
1177             subreg = evd->callback (orig, evd->regs_active, max_depth,
1178                                     evd->callback_arg);
1179             if (subreg != orig)
1180               return subreg;
1181           }
1182
1183         subreg = cselib_expand_value_rtx_1 (SUBREG_REG (orig), evd,
1184                                             max_depth - 1);
1185         if (!subreg)
1186           return NULL;
1187         scopy = simplify_gen_subreg (GET_MODE (orig), subreg,
1188                                      GET_MODE (SUBREG_REG (orig)),
1189                                      SUBREG_BYTE (orig));
1190         if (scopy == NULL
1191             || (GET_CODE (scopy) == SUBREG
1192                 && !REG_P (SUBREG_REG (scopy))
1193                 && !MEM_P (SUBREG_REG (scopy))))
1194           return NULL;
1195
1196         return scopy;
1197       }
1198
1199     case VALUE:
1200       {
1201         rtx result;
1202
1203         if (dump_file && (dump_flags & TDF_DETAILS))
1204           {
1205             fputs ("\nexpanding ", dump_file);
1206             print_rtl_single (dump_file, orig);
1207             fputs (" into...", dump_file);
1208           }
1209
1210         if (evd->callback)
1211           {
1212             result = evd->callback (orig, evd->regs_active, max_depth,
1213                                     evd->callback_arg);
1214
1215             if (result != orig)
1216               return result;
1217           }
1218
1219         result = expand_loc (CSELIB_VAL_PTR (orig)->locs, evd, max_depth);
1220         return result;
1221       }
1222
1223     case DEBUG_EXPR:
1224       if (evd->callback)
1225         return evd->callback (orig, evd->regs_active, max_depth,
1226                               evd->callback_arg);
1227       return orig;
1228
1229     default:
1230       break;
1231     }
1232
1233   /* Copy the various flags, fields, and other information.  We assume
1234      that all fields need copying, and then clear the fields that should
1235      not be copied.  That is the sensible default behavior, and forces
1236      us to explicitly document why we are *not* copying a flag.  */
1237   copy = shallow_copy_rtx (orig);
1238
1239   format_ptr = GET_RTX_FORMAT (code);
1240
1241   for (i = 0; i < GET_RTX_LENGTH (code); i++)
1242     switch (*format_ptr++)
1243       {
1244       case 'e':
1245         if (XEXP (orig, i) != NULL)
1246           {
1247             rtx result = cselib_expand_value_rtx_1 (XEXP (orig, i), evd,
1248                                                     max_depth - 1);
1249             if (!result)
1250               return NULL;
1251             XEXP (copy, i) = result;
1252           }
1253         break;
1254
1255       case 'E':
1256       case 'V':
1257         if (XVEC (orig, i) != NULL)
1258           {
1259             XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
1260             for (j = 0; j < XVECLEN (copy, i); j++)
1261               {
1262                 rtx result = cselib_expand_value_rtx_1 (XVECEXP (orig, i, j),
1263                                                         evd, max_depth - 1);
1264                 if (!result)
1265                   return NULL;
1266                 XVECEXP (copy, i, j) = result;
1267               }
1268           }
1269         break;
1270
1271       case 't':
1272       case 'w':
1273       case 'i':
1274       case 's':
1275       case 'S':
1276       case 'T':
1277       case 'u':
1278       case 'B':
1279       case '0':
1280         /* These are left unchanged.  */
1281         break;
1282
1283       default:
1284         gcc_unreachable ();
1285       }
1286
1287   mode = GET_MODE (copy);
1288   /* If an operand has been simplified into CONST_INT, which doesn't
1289      have a mode and the mode isn't derivable from whole rtx's mode,
1290      try simplify_*_operation first with mode from original's operand
1291      and as a fallback wrap CONST_INT into gen_rtx_CONST.  */
1292   scopy = copy;
1293   switch (GET_RTX_CLASS (code))
1294     {
1295     case RTX_UNARY:
1296       if (CONST_INT_P (XEXP (copy, 0))
1297           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
1298         {
1299           scopy = simplify_unary_operation (code, mode, XEXP (copy, 0),
1300                                             GET_MODE (XEXP (orig, 0)));
1301           if (scopy)
1302             return scopy;
1303         }
1304       break;
1305     case RTX_COMM_ARITH:
1306     case RTX_BIN_ARITH:
1307       /* These expressions can derive operand modes from the whole rtx's mode.  */
1308       break;
1309     case RTX_TERNARY:
1310     case RTX_BITFIELD_OPS:
1311       if (CONST_INT_P (XEXP (copy, 0))
1312           && GET_MODE (XEXP (orig, 0)) != VOIDmode)
1313         {
1314           scopy = simplify_ternary_operation (code, mode,
1315                                               GET_MODE (XEXP (orig, 0)),
1316                                               XEXP (copy, 0), XEXP (copy, 1),
1317                                               XEXP (copy, 2));
1318           if (scopy)
1319             return scopy;
1320         }
1321       break;
1322     case RTX_COMPARE:
1323     case RTX_COMM_COMPARE:
1324       if (CONST_INT_P (XEXP (copy, 0))
1325           && GET_MODE (XEXP (copy, 1)) == VOIDmode
1326           && (GET_MODE (XEXP (orig, 0)) != VOIDmode
1327               || GET_MODE (XEXP (orig, 1)) != VOIDmode))
1328         {
1329           scopy = simplify_relational_operation (code, mode,
1330                                                  (GET_MODE (XEXP (orig, 0))
1331                                                   != VOIDmode)
1332                                                  ? GET_MODE (XEXP (orig, 0))
1333                                                  : GET_MODE (XEXP (orig, 1)),
1334                                                  XEXP (copy, 0),
1335                                                  XEXP (copy, 1));
1336           if (scopy)
1337             return scopy;
1338         }
1339       break;
1340     default:
1341       break;
1342     }
1343   if (scopy == NULL_RTX)
1344     {
1345       XEXP (copy, 0)
1346         = gen_rtx_CONST (GET_MODE (XEXP (orig, 0)), XEXP (copy, 0));
1347       if (dump_file && (dump_flags & TDF_DETAILS))
1348         fprintf (dump_file, "  wrapping const_int result in const to preserve mode %s\n",
1349                  GET_MODE_NAME (GET_MODE (XEXP (copy, 0))));
1350     }
1351   scopy = simplify_rtx (copy);
1352   if (scopy)
1353     {
1354       if (GET_MODE (copy) != GET_MODE (scopy))
1355         scopy = wrap_constant (GET_MODE (copy), scopy);
1356       return scopy;
1357     }
1358   return copy;
1359 }
1360
1361 /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
1362    with VALUE expressions.  This way, it becomes independent of changes
1363    to registers and memory.
1364    X isn't actually modified; if modifications are needed, new rtl is
1365    allocated.  However, the return value can share rtl with X.  */
1366
1367 rtx
1368 cselib_subst_to_values (rtx x)
1369 {
1370   enum rtx_code code = GET_CODE (x);
1371   const char *fmt = GET_RTX_FORMAT (code);
1372   cselib_val *e;
1373   struct elt_list *l;
1374   rtx copy = x;
1375   int i;
1376
1377   switch (code)
1378     {
1379     case REG:
1380       l = REG_VALUES (REGNO (x));
1381       if (l && l->elt == NULL)
1382         l = l->next;
1383       for (; l; l = l->next)
1384         if (GET_MODE (l->elt->val_rtx) == GET_MODE (x))
1385           return l->elt->val_rtx;
1386
1387       gcc_unreachable ();
1388
1389     case MEM:
1390       e = cselib_lookup_mem (x, 0);
1391       if (! e)
1392         {
1393           /* This happens for autoincrements.  Assign a value that doesn't
1394              match any other.  */
1395           e = new_cselib_val (++next_unknown_value, GET_MODE (x), x);
1396         }
1397       return e->val_rtx;
1398
1399     case CONST_DOUBLE:
1400     case CONST_VECTOR:
1401     case CONST_INT:
1402     case CONST_FIXED:
1403       return x;
1404
1405     case POST_INC:
1406     case PRE_INC:
1407     case POST_DEC:
1408     case PRE_DEC:
1409     case POST_MODIFY:
1410     case PRE_MODIFY:
1411       e = new_cselib_val (++next_unknown_value, GET_MODE (x), x);
1412       return e->val_rtx;
1413
1414     default:
1415       break;
1416     }
1417
1418   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1419     {
1420       if (fmt[i] == 'e')
1421         {
1422           rtx t = cselib_subst_to_values (XEXP (x, i));
1423
1424           if (t != XEXP (x, i) && x == copy)
1425             copy = shallow_copy_rtx (x);
1426
1427           XEXP (copy, i) = t;
1428         }
1429       else if (fmt[i] == 'E')
1430         {
1431           int j, k;
1432
1433           for (j = 0; j < XVECLEN (x, i); j++)
1434             {
1435               rtx t = cselib_subst_to_values (XVECEXP (x, i, j));
1436
1437               if (t != XVECEXP (x, i, j) && XVEC (x, i) == XVEC (copy, i))
1438                 {
1439                   if (x == copy)
1440                     copy = shallow_copy_rtx (x);
1441
1442                   XVEC (copy, i) = rtvec_alloc (XVECLEN (x, i));
1443                   for (k = 0; k < j; k++)
1444                     XVECEXP (copy, i, k) = XVECEXP (x, i, k);
1445                 }
1446
1447               XVECEXP (copy, i, j) = t;
1448             }
1449         }
1450     }
1451
1452   return copy;
1453 }
1454
1455 /* Log a lookup of X to the cselib table along with the result RET.  */
1456
1457 static cselib_val *
1458 cselib_log_lookup (rtx x, cselib_val *ret)
1459 {
1460   if (dump_file && (dump_flags & TDF_DETAILS))
1461     {
1462       fputs ("cselib lookup ", dump_file);
1463       print_inline_rtx (dump_file, x, 2);
1464       fprintf (dump_file, " => %u\n", ret ? ret->value : 0);
1465     }
1466
1467   return ret;
1468 }
1469
1470 /* Look up the rtl expression X in our tables and return the value it has.
1471    If CREATE is zero, we return NULL if we don't know the value.  Otherwise,
1472    we create a new one if possible, using mode MODE if X doesn't have a mode
1473    (i.e. because it's a constant).  */
1474
1475 cselib_val *
1476 cselib_lookup (rtx x, enum machine_mode mode, int create)
1477 {
1478   void **slot;
1479   cselib_val *e;
1480   unsigned int hashval;
1481
1482   if (GET_MODE (x) != VOIDmode)
1483     mode = GET_MODE (x);
1484
1485   if (GET_CODE (x) == VALUE)
1486     return CSELIB_VAL_PTR (x);
1487
1488   if (REG_P (x))
1489     {
1490       struct elt_list *l;
1491       unsigned int i = REGNO (x);
1492
1493       l = REG_VALUES (i);
1494       if (l && l->elt == NULL)
1495         l = l->next;
1496       for (; l; l = l->next)
1497         if (mode == GET_MODE (l->elt->val_rtx))
1498           return cselib_log_lookup (x, l->elt);
1499
1500       if (! create)
1501         return cselib_log_lookup (x, 0);
1502
1503       if (i < FIRST_PSEUDO_REGISTER)
1504         {
1505           unsigned int n = hard_regno_nregs[i][mode];
1506
1507           if (n > max_value_regs)
1508             max_value_regs = n;
1509         }
1510
1511       e = new_cselib_val (++next_unknown_value, GET_MODE (x), x);
1512       e->locs = new_elt_loc_list (e->locs, x);
1513       if (REG_VALUES (i) == 0)
1514         {
1515           /* Maintain the invariant that the first entry of
1516              REG_VALUES, if present, must be the value used to set the
1517              register, or NULL.  */
1518           used_regs[n_used_regs++] = i;
1519           REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
1520         }
1521       REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
1522       slot = htab_find_slot_with_hash (cselib_hash_table, x, e->value, INSERT);
1523       *slot = e;
1524       return cselib_log_lookup (x, e);
1525     }
1526
1527   if (MEM_P (x))
1528     return cselib_log_lookup (x, cselib_lookup_mem (x, create));
1529
1530   hashval = cselib_hash_rtx (x, create);
1531   /* Can't even create if hashing is not possible.  */
1532   if (! hashval)
1533     return cselib_log_lookup (x, 0);
1534
1535   slot = htab_find_slot_with_hash (cselib_hash_table, wrap_constant (mode, x),
1536                                    hashval, create ? INSERT : NO_INSERT);
1537   if (slot == 0)
1538     return cselib_log_lookup (x, 0);
1539
1540   e = (cselib_val *) *slot;
1541   if (e)
1542     return cselib_log_lookup (x, e);
1543
1544   e = new_cselib_val (hashval, mode, x);
1545
1546   /* We have to fill the slot before calling cselib_subst_to_values:
1547      the hash table is inconsistent until we do so, and
1548      cselib_subst_to_values will need to do lookups.  */
1549   *slot = (void *) e;
1550   e->locs = new_elt_loc_list (e->locs, cselib_subst_to_values (x));
1551   return cselib_log_lookup (x, e);
1552 }
1553
1554 /* Invalidate any entries in reg_values that overlap REGNO.  This is called
1555    if REGNO is changing.  MODE is the mode of the assignment to REGNO, which
1556    is used to determine how many hard registers are being changed.  If MODE
1557    is VOIDmode, then only REGNO is being changed; this is used when
1558    invalidating call clobbered registers across a call.  */
1559
1560 static void
1561 cselib_invalidate_regno (unsigned int regno, enum machine_mode mode)
1562 {
1563   unsigned int endregno;
1564   unsigned int i;
1565
1566   /* If we see pseudos after reload, something is _wrong_.  */
1567   gcc_assert (!reload_completed || regno < FIRST_PSEUDO_REGISTER
1568               || reg_renumber[regno] < 0);
1569
1570   /* Determine the range of registers that must be invalidated.  For
1571      pseudos, only REGNO is affected.  For hard regs, we must take MODE
1572      into account, and we must also invalidate lower register numbers
1573      if they contain values that overlap REGNO.  */
1574   if (regno < FIRST_PSEUDO_REGISTER)
1575     {
1576       gcc_assert (mode != VOIDmode);
1577
1578       if (regno < max_value_regs)
1579         i = 0;
1580       else
1581         i = regno - max_value_regs;
1582
1583       endregno = end_hard_regno (mode, regno);
1584     }
1585   else
1586     {
1587       i = regno;
1588       endregno = regno + 1;
1589     }
1590
1591   for (; i < endregno; i++)
1592     {
1593       struct elt_list **l = &REG_VALUES (i);
1594
1595       /* Go through all known values for this reg; if it overlaps the range
1596          we're invalidating, remove the value.  */
1597       while (*l)
1598         {
1599           cselib_val *v = (*l)->elt;
1600           struct elt_loc_list **p;
1601           unsigned int this_last = i;
1602
1603           if (i < FIRST_PSEUDO_REGISTER && v != NULL)
1604             this_last = end_hard_regno (GET_MODE (v->val_rtx), i) - 1;
1605
1606           if (this_last < regno || v == NULL)
1607             {
1608               l = &(*l)->next;
1609               continue;
1610             }
1611
1612           /* We have an overlap.  */
1613           if (*l == REG_VALUES (i))
1614             {
1615               /* Maintain the invariant that the first entry of
1616                  REG_VALUES, if present, must be the value used to set
1617                  the register, or NULL.  This is also nice because
1618                  then we won't push the same regno onto user_regs
1619                  multiple times.  */
1620               (*l)->elt = NULL;
1621               l = &(*l)->next;
1622             }
1623           else
1624             unchain_one_elt_list (l);
1625
1626           /* Now, we clear the mapping from value to reg.  It must exist, so
1627              this code will crash intentionally if it doesn't.  */
1628           for (p = &v->locs; ; p = &(*p)->next)
1629             {
1630               rtx x = (*p)->loc;
1631
1632               if (REG_P (x) && REGNO (x) == i)
1633                 {
1634                   unchain_one_elt_loc_list (p);
1635                   break;
1636                 }
1637             }
1638           if (v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
1639             n_useless_values++;
1640         }
1641     }
1642 }
1643 \f
1644 /* Return 1 if X has a value that can vary even between two
1645    executions of the program.  0 means X can be compared reliably
1646    against certain constants or near-constants.  */
1647
1648 static bool
1649 cselib_rtx_varies_p (const_rtx x ATTRIBUTE_UNUSED, bool from_alias ATTRIBUTE_UNUSED)
1650 {
1651   /* We actually don't need to verify very hard.  This is because
1652      if X has actually changed, we invalidate the memory anyway,
1653      so assume that all common memory addresses are
1654      invariant.  */
1655   return 0;
1656 }
1657
1658 /* Invalidate any locations in the table which are changed because of a
1659    store to MEM_RTX.  If this is called because of a non-const call
1660    instruction, MEM_RTX is (mem:BLK const0_rtx).  */
1661
1662 static void
1663 cselib_invalidate_mem (rtx mem_rtx)
1664 {
1665   cselib_val **vp, *v, *next;
1666   int num_mems = 0;
1667   rtx mem_addr;
1668
1669   mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0)));
1670   mem_rtx = canon_rtx (mem_rtx);
1671
1672   vp = &first_containing_mem;
1673   for (v = *vp; v != &dummy_val; v = next)
1674     {
1675       bool has_mem = false;
1676       struct elt_loc_list **p = &v->locs;
1677       int had_locs = v->locs != 0;
1678
1679       while (*p)
1680         {
1681           rtx x = (*p)->loc;
1682           cselib_val *addr;
1683           struct elt_list **mem_chain;
1684
1685           /* MEMs may occur in locations only at the top level; below
1686              that every MEM or REG is substituted by its VALUE.  */
1687           if (!MEM_P (x))
1688             {
1689               p = &(*p)->next;
1690               continue;
1691             }
1692           if (num_mems < PARAM_VALUE (PARAM_MAX_CSELIB_MEMORY_LOCATIONS)
1693               && ! canon_true_dependence (mem_rtx, GET_MODE (mem_rtx), mem_addr,
1694                                           x, NULL_RTX, cselib_rtx_varies_p))
1695             {
1696               has_mem = true;
1697               num_mems++;
1698               p = &(*p)->next;
1699               continue;
1700             }
1701
1702           /* This one overlaps.  */
1703           /* We must have a mapping from this MEM's address to the
1704              value (E).  Remove that, too.  */
1705           addr = cselib_lookup (XEXP (x, 0), VOIDmode, 0);
1706           mem_chain = &addr->addr_list;
1707           for (;;)
1708             {
1709               if ((*mem_chain)->elt == v)
1710                 {
1711                   unchain_one_elt_list (mem_chain);
1712                   break;
1713                 }
1714
1715               mem_chain = &(*mem_chain)->next;
1716             }
1717
1718           unchain_one_elt_loc_list (p);
1719         }
1720
1721       if (had_locs && v->locs == 0 && !PRESERVED_VALUE_P (v->val_rtx))
1722         n_useless_values++;
1723
1724       next = v->next_containing_mem;
1725       if (has_mem)
1726         {
1727           *vp = v;
1728           vp = &(*vp)->next_containing_mem;
1729         }
1730       else
1731         v->next_containing_mem = NULL;
1732     }
1733   *vp = &dummy_val;
1734 }
1735
1736 /* Invalidate DEST, which is being assigned to or clobbered.  */
1737
1738 void
1739 cselib_invalidate_rtx (rtx dest)
1740 {
1741   while (GET_CODE (dest) == SUBREG
1742          || GET_CODE (dest) == ZERO_EXTRACT
1743          || GET_CODE (dest) == STRICT_LOW_PART)
1744     dest = XEXP (dest, 0);
1745
1746   if (REG_P (dest))
1747     cselib_invalidate_regno (REGNO (dest), GET_MODE (dest));
1748   else if (MEM_P (dest))
1749     cselib_invalidate_mem (dest);
1750
1751   /* Some machines don't define AUTO_INC_DEC, but they still use push
1752      instructions.  We need to catch that case here in order to
1753      invalidate the stack pointer correctly.  Note that invalidating
1754      the stack pointer is different from invalidating DEST.  */
1755   if (push_operand (dest, GET_MODE (dest)))
1756     cselib_invalidate_rtx (stack_pointer_rtx);
1757 }
1758
1759 /* A wrapper for cselib_invalidate_rtx to be called via note_stores.  */
1760
1761 static void
1762 cselib_invalidate_rtx_note_stores (rtx dest, const_rtx ignore ATTRIBUTE_UNUSED,
1763                                    void *data ATTRIBUTE_UNUSED)
1764 {
1765   cselib_invalidate_rtx (dest);
1766 }
1767
1768 /* Record the result of a SET instruction.  DEST is being set; the source
1769    contains the value described by SRC_ELT.  If DEST is a MEM, DEST_ADDR_ELT
1770    describes its address.  */
1771
1772 static void
1773 cselib_record_set (rtx dest, cselib_val *src_elt, cselib_val *dest_addr_elt)
1774 {
1775   int dreg = REG_P (dest) ? (int) REGNO (dest) : -1;
1776
1777   if (src_elt == 0 || side_effects_p (dest))
1778     return;
1779
1780   if (dreg >= 0)
1781     {
1782       if (dreg < FIRST_PSEUDO_REGISTER)
1783         {
1784           unsigned int n = hard_regno_nregs[dreg][GET_MODE (dest)];
1785
1786           if (n > max_value_regs)
1787             max_value_regs = n;
1788         }
1789
1790       if (REG_VALUES (dreg) == 0)
1791         {
1792           used_regs[n_used_regs++] = dreg;
1793           REG_VALUES (dreg) = new_elt_list (REG_VALUES (dreg), src_elt);
1794         }
1795       else
1796         {
1797           /* The register should have been invalidated.  */
1798           gcc_assert (REG_VALUES (dreg)->elt == 0);
1799           REG_VALUES (dreg)->elt = src_elt;
1800         }
1801
1802       if (src_elt->locs == 0 && !PRESERVED_VALUE_P (src_elt->val_rtx))
1803         n_useless_values--;
1804       src_elt->locs = new_elt_loc_list (src_elt->locs, dest);
1805     }
1806   else if (MEM_P (dest) && dest_addr_elt != 0
1807            && cselib_record_memory)
1808     {
1809       if (src_elt->locs == 0 && !PRESERVED_VALUE_P (src_elt->val_rtx))
1810         n_useless_values--;
1811       add_mem_for_addr (dest_addr_elt, src_elt, dest);
1812     }
1813 }
1814
1815 /* There is no good way to determine how many elements there can be
1816    in a PARALLEL.  Since it's fairly cheap, use a really large number.  */
1817 #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
1818
1819 /* Record the effects of any sets in INSN.  */
1820 static void
1821 cselib_record_sets (rtx insn)
1822 {
1823   int n_sets = 0;
1824   int i;
1825   struct cselib_set sets[MAX_SETS];
1826   rtx body = PATTERN (insn);
1827   rtx cond = 0;
1828
1829   body = PATTERN (insn);
1830   if (GET_CODE (body) == COND_EXEC)
1831     {
1832       cond = COND_EXEC_TEST (body);
1833       body = COND_EXEC_CODE (body);
1834     }
1835
1836   /* Find all sets.  */
1837   if (GET_CODE (body) == SET)
1838     {
1839       sets[0].src = SET_SRC (body);
1840       sets[0].dest = SET_DEST (body);
1841       n_sets = 1;
1842     }
1843   else if (GET_CODE (body) == PARALLEL)
1844     {
1845       /* Look through the PARALLEL and record the values being
1846          set, if possible.  Also handle any CLOBBERs.  */
1847       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
1848         {
1849           rtx x = XVECEXP (body, 0, i);
1850
1851           if (GET_CODE (x) == SET)
1852             {
1853               sets[n_sets].src = SET_SRC (x);
1854               sets[n_sets].dest = SET_DEST (x);
1855               n_sets++;
1856             }
1857         }
1858     }
1859
1860   if (n_sets == 1
1861       && MEM_P (sets[0].src)
1862       && !cselib_record_memory
1863       && MEM_READONLY_P (sets[0].src))
1864     {
1865       rtx note = find_reg_equal_equiv_note (insn);
1866
1867       if (note && CONSTANT_P (XEXP (note, 0)))
1868         sets[0].src = XEXP (note, 0);
1869     }
1870
1871   /* Look up the values that are read.  Do this before invalidating the
1872      locations that are written.  */
1873   for (i = 0; i < n_sets; i++)
1874     {
1875       rtx dest = sets[i].dest;
1876
1877       /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
1878          the low part after invalidating any knowledge about larger modes.  */
1879       if (GET_CODE (sets[i].dest) == STRICT_LOW_PART)
1880         sets[i].dest = dest = XEXP (dest, 0);
1881
1882       /* We don't know how to record anything but REG or MEM.  */
1883       if (REG_P (dest)
1884           || (MEM_P (dest) && cselib_record_memory))
1885         {
1886           rtx src = sets[i].src;
1887           if (cond)
1888             src = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), cond, src, dest);
1889           sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1);
1890           if (MEM_P (dest))
1891             sets[i].dest_addr_elt = cselib_lookup (XEXP (dest, 0), Pmode, 1);
1892           else
1893             sets[i].dest_addr_elt = 0;
1894         }
1895     }
1896
1897   if (cselib_record_sets_hook)
1898     cselib_record_sets_hook (insn, sets, n_sets);
1899
1900   /* Invalidate all locations written by this insn.  Note that the elts we
1901      looked up in the previous loop aren't affected, just some of their
1902      locations may go away.  */
1903   note_stores (body, cselib_invalidate_rtx_note_stores, NULL);
1904
1905   /* If this is an asm, look for duplicate sets.  This can happen when the
1906      user uses the same value as an output multiple times.  This is valid
1907      if the outputs are not actually used thereafter.  Treat this case as
1908      if the value isn't actually set.  We do this by smashing the destination
1909      to pc_rtx, so that we won't record the value later.  */
1910   if (n_sets >= 2 && asm_noperands (body) >= 0)
1911     {
1912       for (i = 0; i < n_sets; i++)
1913         {
1914           rtx dest = sets[i].dest;
1915           if (REG_P (dest) || MEM_P (dest))
1916             {
1917               int j;
1918               for (j = i + 1; j < n_sets; j++)
1919                 if (rtx_equal_p (dest, sets[j].dest))
1920                   {
1921                     sets[i].dest = pc_rtx;
1922                     sets[j].dest = pc_rtx;
1923                   }
1924             }
1925         }
1926     }
1927
1928   /* Now enter the equivalences in our tables.  */
1929   for (i = 0; i < n_sets; i++)
1930     {
1931       rtx dest = sets[i].dest;
1932       if (REG_P (dest)
1933           || (MEM_P (dest) && cselib_record_memory))
1934         cselib_record_set (dest, sets[i].src_elt, sets[i].dest_addr_elt);
1935     }
1936 }
1937
1938 /* Record the effects of INSN.  */
1939
1940 void
1941 cselib_process_insn (rtx insn)
1942 {
1943   int i;
1944   rtx x;
1945
1946   cselib_current_insn = insn;
1947
1948   /* Forget everything at a CODE_LABEL, a volatile asm, or a setjmp.  */
1949   if (LABEL_P (insn)
1950       || (CALL_P (insn)
1951           && find_reg_note (insn, REG_SETJMP, NULL))
1952       || (NONJUMP_INSN_P (insn)
1953           && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
1954           && MEM_VOLATILE_P (PATTERN (insn))))
1955     {
1956       cselib_reset_table_with_next_value (next_unknown_value);
1957       return;
1958     }
1959
1960   if (! INSN_P (insn))
1961     {
1962       cselib_current_insn = 0;
1963       return;
1964     }
1965
1966   /* If this is a call instruction, forget anything stored in a
1967      call clobbered register, or, if this is not a const call, in
1968      memory.  */
1969   if (CALL_P (insn))
1970     {
1971       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1972         if (call_used_regs[i]
1973             || (REG_VALUES (i) && REG_VALUES (i)->elt
1974                 && HARD_REGNO_CALL_PART_CLOBBERED (i, 
1975                       GET_MODE (REG_VALUES (i)->elt->val_rtx))))
1976           cselib_invalidate_regno (i, reg_raw_mode[i]);
1977
1978       /* Since it is not clear how cselib is going to be used, be
1979          conservative here and treat looping pure or const functions
1980          as if they were regular functions.  */
1981       if (RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)
1982           || !(RTL_CONST_OR_PURE_CALL_P (insn)))
1983         cselib_invalidate_mem (callmem);
1984     }
1985
1986   cselib_record_sets (insn);
1987
1988 #ifdef AUTO_INC_DEC
1989   /* Clobber any registers which appear in REG_INC notes.  We
1990      could keep track of the changes to their values, but it is
1991      unlikely to help.  */
1992   for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
1993     if (REG_NOTE_KIND (x) == REG_INC)
1994       cselib_invalidate_rtx (XEXP (x, 0));
1995 #endif
1996
1997   /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
1998      after we have processed the insn.  */
1999   if (CALL_P (insn))
2000     for (x = CALL_INSN_FUNCTION_USAGE (insn); x; x = XEXP (x, 1))
2001       if (GET_CODE (XEXP (x, 0)) == CLOBBER)
2002         cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0));
2003
2004   cselib_current_insn = 0;
2005
2006   if (n_useless_values > MAX_USELESS_VALUES
2007       /* remove_useless_values is linear in the hash table size.  Avoid
2008          quadratic behavior for very large hashtables with very few
2009          useless elements.  */
2010       && (unsigned int)n_useless_values > cselib_hash_table->n_elements / 4)
2011     remove_useless_values ();
2012 }
2013
2014 /* Initialize cselib for one pass.  The caller must also call
2015    init_alias_analysis.  */
2016
2017 void
2018 cselib_init (bool record_memory)
2019 {
2020   elt_list_pool = create_alloc_pool ("elt_list", 
2021                                      sizeof (struct elt_list), 10);
2022   elt_loc_list_pool = create_alloc_pool ("elt_loc_list", 
2023                                          sizeof (struct elt_loc_list), 10);
2024   cselib_val_pool = create_alloc_pool ("cselib_val_list", 
2025                                        sizeof (cselib_val), 10);
2026   value_pool = create_alloc_pool ("value", RTX_CODE_SIZE (VALUE), 100);
2027   cselib_record_memory = record_memory;
2028
2029   /* (mem:BLK (scratch)) is a special mechanism to conflict with everything,
2030      see canon_true_dependence.  This is only created once.  */
2031   if (! callmem)
2032     callmem = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
2033
2034   cselib_nregs = max_reg_num ();
2035
2036   /* We preserve reg_values to allow expensive clearing of the whole thing.
2037      Reallocate it however if it happens to be too large.  */
2038   if (!reg_values || reg_values_size < cselib_nregs
2039       || (reg_values_size > 10 && reg_values_size > cselib_nregs * 4))
2040     {
2041       if (reg_values)
2042         free (reg_values);
2043       /* Some space for newly emit instructions so we don't end up
2044          reallocating in between passes.  */
2045       reg_values_size = cselib_nregs + (63 + cselib_nregs) / 16;
2046       reg_values = XCNEWVEC (struct elt_list *, reg_values_size);
2047     }
2048   used_regs = XNEWVEC (unsigned int, cselib_nregs);
2049   n_used_regs = 0;
2050   cselib_hash_table = htab_create (31, get_value_hash,
2051                                    entry_and_rtx_equal_p, NULL);
2052 }
2053
2054 /* Called when the current user is done with cselib.  */
2055
2056 void
2057 cselib_finish (void)
2058 {
2059   cselib_discard_hook = NULL;
2060   free_alloc_pool (elt_list_pool);
2061   free_alloc_pool (elt_loc_list_pool);
2062   free_alloc_pool (cselib_val_pool);
2063   free_alloc_pool (value_pool);
2064   cselib_clear_table ();
2065   htab_delete (cselib_hash_table);
2066   free (used_regs);
2067   used_regs = 0;
2068   cselib_hash_table = 0;
2069   n_useless_values = 0;
2070   next_unknown_value = 0;
2071 }
2072
2073 /* Dump the cselib_val *X to FILE *info.  */
2074
2075 static int
2076 dump_cselib_val (void **x, void *info)
2077 {
2078   cselib_val *v = (cselib_val *)*x;
2079   FILE *out = (FILE *)info;
2080   bool need_lf = true;
2081
2082   print_inline_rtx (out, v->val_rtx, 0);
2083
2084   if (v->locs)
2085     {
2086       struct elt_loc_list *l = v->locs;
2087       if (need_lf)
2088         {
2089           fputc ('\n', out);
2090           need_lf = false;
2091         }
2092       fputs (" locs:", out);
2093       do
2094         {
2095           fprintf (out, "\n  from insn %i ",
2096                    INSN_UID (l->setting_insn));
2097           print_inline_rtx (out, l->loc, 4);
2098         }
2099       while ((l = l->next));
2100       fputc ('\n', out);
2101     }
2102   else
2103     {
2104       fputs (" no locs", out);
2105       need_lf = true;
2106     }
2107
2108   if (v->addr_list)
2109     {
2110       struct elt_list *e = v->addr_list;
2111       if (need_lf)
2112         {
2113           fputc ('\n', out);
2114           need_lf = false;
2115         }
2116       fputs (" addr list:", out);
2117       do
2118         {
2119           fputs ("\n  ", out);
2120           print_inline_rtx (out, e->elt->val_rtx, 2);
2121         }
2122       while ((e = e->next));
2123       fputc ('\n', out);
2124     }
2125   else
2126     {
2127       fputs (" no addrs", out);
2128       need_lf = true;
2129     }
2130
2131   if (v->next_containing_mem == &dummy_val)
2132     fputs (" last mem\n", out);
2133   else if (v->next_containing_mem)
2134     {
2135       fputs (" next mem ", out);
2136       print_inline_rtx (out, v->next_containing_mem->val_rtx, 2);
2137       fputc ('\n', out);
2138     }
2139   else if (need_lf)
2140     fputc ('\n', out);
2141
2142   return 1;
2143 }
2144
2145 /* Dump to OUT everything in the CSELIB table.  */
2146
2147 void
2148 dump_cselib_table (FILE *out)
2149 {
2150   fprintf (out, "cselib hash table:\n");
2151   htab_traverse (cselib_hash_table, dump_cselib_val, out);
2152   if (first_containing_mem != &dummy_val)
2153     {
2154       fputs ("first mem ", out);
2155       print_inline_rtx (out, first_containing_mem->val_rtx, 2);
2156       fputc ('\n', out);
2157     }
2158   fprintf (out, "last unknown value %i\n", next_unknown_value);
2159 }
2160
2161 #include "gt-cselib.h"