Merge from vendor branch BIND:
[dragonfly.git] / contrib / gcc-3.4 / 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 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
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 "expr.h"
37 #include "toplev.h"
38 #include "output.h"
39 #include "ggc.h"
40 #include "hashtab.h"
41 #include "cselib.h"
42 #include "params.h"
43 #include "alloc-pool.h"
44
45 static int entry_and_rtx_equal_p (const void *, const void *);
46 static hashval_t get_value_hash (const void *);
47 static struct elt_list *new_elt_list (struct elt_list *, cselib_val *);
48 static struct elt_loc_list *new_elt_loc_list (struct elt_loc_list *, rtx);
49 static void unchain_one_value (cselib_val *);
50 static void unchain_one_elt_list (struct elt_list **);
51 static void unchain_one_elt_loc_list (struct elt_loc_list **);
52 static void clear_table (void);
53 static int discard_useless_locs (void **, void *);
54 static int discard_useless_values (void **, void *);
55 static void remove_useless_values (void);
56 static rtx wrap_constant (enum machine_mode, rtx);
57 static unsigned int hash_rtx (rtx, enum machine_mode, int);
58 static cselib_val *new_cselib_val (unsigned int, enum machine_mode);
59 static void add_mem_for_addr (cselib_val *, cselib_val *, rtx);
60 static cselib_val *cselib_lookup_mem (rtx, int);
61 static void cselib_invalidate_regno (unsigned int, enum machine_mode);
62 static void cselib_invalidate_mem (rtx);
63 static void cselib_record_set (rtx, cselib_val *, cselib_val *);
64 static void cselib_record_sets (rtx);
65
66 /* There are three ways in which cselib can look up an rtx:
67    - for a REG, the reg_values table (which is indexed by regno) is used
68    - for a MEM, we recursively look up its address and then follow the
69      addr_list of that value
70    - for everything else, we compute a hash value and go through the hash
71      table.  Since different rtx's can still have the same hash value,
72      this involves walking the table entries for a given value and comparing
73      the locations of the entries with the rtx we are looking up.  */
74
75 /* A table that enables us to look up elts by their value.  */
76 static GTY((param_is (cselib_val))) htab_t hash_table;
77
78 /* This is a global so we don't have to pass this through every function.
79    It is used in new_elt_loc_list to set SETTING_INSN.  */
80 static rtx cselib_current_insn;
81 static bool cselib_current_insn_in_libcall;
82
83 /* Every new unknown value gets a unique number.  */
84 static unsigned int next_unknown_value;
85
86 /* The number of registers we had when the varrays were last resized.  */
87 static unsigned int cselib_nregs;
88
89 /* Count values without known locations.  Whenever this grows too big, we
90    remove these useless values from the table.  */
91 static int n_useless_values;
92
93 /* Number of useless values before we remove them from the hash table.  */
94 #define MAX_USELESS_VALUES 32
95
96 /* This table maps from register number to values.  It does not
97    contain pointers to cselib_val structures, but rather elt_lists.
98    The purpose is to be able to refer to the same register in
99    different modes.  The first element of the list defines the mode in
100    which the register was set; if the mode is unknown or the value is
101    no longer valid in that mode, ELT will be NULL for the first
102    element.  */
103 static GTY(()) varray_type reg_values;
104 static GTY((deletable (""))) varray_type reg_values_old;
105 #define REG_VALUES(I) VARRAY_ELT_LIST (reg_values, (I))
106
107 /* The largest number of hard regs used by any entry added to the
108    REG_VALUES table.  Cleared on each clear_table() invocation.  */
109 static unsigned int max_value_regs;
110
111 /* Here the set of indices I with REG_VALUES(I) != 0 is saved.  This is used
112    in clear_table() for fast emptying.  */
113 static GTY(()) varray_type used_regs;
114 static GTY((deletable (""))) varray_type used_regs_old;
115
116 /* We pass this to cselib_invalidate_mem to invalidate all of
117    memory for a non-const call instruction.  */
118 static GTY(()) rtx callmem;
119
120 /* Set by discard_useless_locs if it deleted the last location of any
121    value.  */
122 static int values_became_useless;
123
124 /* Used as stop element of the containing_mem list so we can check
125    presence in the list by checking the next pointer.  */
126 static cselib_val dummy_val;
127
128 /* Used to list all values that contain memory reference.
129    May or may not contain the useless values - the list is compacted
130    each time memory is invalidated.  */
131 static cselib_val *first_containing_mem = &dummy_val;
132 static alloc_pool elt_loc_list_pool, elt_list_pool, cselib_val_pool, value_pool;
133 \f
134
135 /* Allocate a struct elt_list and fill in its two elements with the
136    arguments.  */
137
138 static inline struct elt_list *
139 new_elt_list (struct elt_list *next, cselib_val *elt)
140 {
141   struct elt_list *el;
142   el = pool_alloc (elt_list_pool);
143   el->next = next;
144   el->elt = elt;
145   return el;
146 }
147
148 /* Allocate a struct elt_loc_list and fill in its two elements with the
149    arguments.  */
150
151 static inline struct elt_loc_list *
152 new_elt_loc_list (struct elt_loc_list *next, rtx loc)
153 {
154   struct elt_loc_list *el;
155   el = pool_alloc (elt_loc_list_pool);
156   el->next = next;
157   el->loc = loc;
158   el->canon_loc = NULL;
159   el->setting_insn = cselib_current_insn;
160   el->in_libcall = cselib_current_insn_in_libcall;
161   return el;
162 }
163
164 /* The elt_list at *PL is no longer needed.  Unchain it and free its
165    storage.  */
166
167 static inline void
168 unchain_one_elt_list (struct elt_list **pl)
169 {
170   struct elt_list *l = *pl;
171
172   *pl = l->next;
173   pool_free (elt_list_pool, l);
174 }
175
176 /* Likewise for elt_loc_lists.  */
177
178 static void
179 unchain_one_elt_loc_list (struct elt_loc_list **pl)
180 {
181   struct elt_loc_list *l = *pl;
182
183   *pl = l->next;
184   pool_free (elt_loc_list_pool, l);
185 }
186
187 /* Likewise for cselib_vals.  This also frees the addr_list associated with
188    V.  */
189
190 static void
191 unchain_one_value (cselib_val *v)
192 {
193   while (v->addr_list)
194     unchain_one_elt_list (&v->addr_list);
195
196   pool_free (cselib_val_pool, v);
197 }
198
199 /* Remove all entries from the hash table.  Also used during
200    initialization.  If CLEAR_ALL isn't set, then only clear the entries
201    which are known to have been used.  */
202
203 static void
204 clear_table (void)
205 {
206   unsigned int i;
207
208   for (i = 0; i < VARRAY_ACTIVE_SIZE (used_regs); i++)
209     REG_VALUES (VARRAY_UINT (used_regs, i)) = 0;
210
211   max_value_regs = 0;
212
213   VARRAY_POP_ALL (used_regs);
214
215   htab_empty (hash_table);
216
217   n_useless_values = 0;
218
219   next_unknown_value = 0;
220
221   first_containing_mem = &dummy_val;
222 }
223
224 /* The equality test for our hash table.  The first argument ENTRY is a table
225    element (i.e. a cselib_val), while the second arg X is an rtx.  We know
226    that all callers of htab_find_slot_with_hash will wrap CONST_INTs into a
227    CONST of an appropriate mode.  */
228
229 static int
230 entry_and_rtx_equal_p (const void *entry, const void *x_arg)
231 {
232   struct elt_loc_list *l;
233   const cselib_val *v = (const cselib_val *) entry;
234   rtx x = (rtx) x_arg;
235   enum machine_mode mode = GET_MODE (x);
236
237   if (GET_CODE (x) == CONST_INT
238       || (mode == VOIDmode && GET_CODE (x) == CONST_DOUBLE))
239     abort ();
240   if (mode != GET_MODE (v->u.val_rtx))
241     return 0;
242
243   /* Unwrap X if necessary.  */
244   if (GET_CODE (x) == CONST
245       && (GET_CODE (XEXP (x, 0)) == CONST_INT
246           || GET_CODE (XEXP (x, 0)) == CONST_DOUBLE))
247     x = XEXP (x, 0);
248
249   /* We don't guarantee that distinct rtx's have different hash values,
250      so we need to do a comparison.  */
251   for (l = v->locs; l; l = l->next)
252     if (rtx_equal_for_cselib_p (l->loc, x))
253       return 1;
254
255   return 0;
256 }
257
258 /* The hash function for our hash table.  The value is always computed with
259    hash_rtx when adding an element; this function just extracts the hash
260    value from a cselib_val structure.  */
261
262 static hashval_t
263 get_value_hash (const void *entry)
264 {
265   const cselib_val *v = (const cselib_val *) entry;
266   return v->value;
267 }
268
269 /* Return true if X contains a VALUE rtx.  If ONLY_USELESS is set, we
270    only return true for values which point to a cselib_val whose value
271    element has been set to zero, which implies the cselib_val will be
272    removed.  */
273
274 int
275 references_value_p (rtx x, int only_useless)
276 {
277   enum rtx_code code = GET_CODE (x);
278   const char *fmt = GET_RTX_FORMAT (code);
279   int i, j;
280
281   if (GET_CODE (x) == VALUE
282       && (! only_useless || CSELIB_VAL_PTR (x)->locs == 0))
283     return 1;
284
285   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
286     {
287       if (fmt[i] == 'e' && references_value_p (XEXP (x, i), only_useless))
288         return 1;
289       else if (fmt[i] == 'E')
290         for (j = 0; j < XVECLEN (x, i); j++)
291           if (references_value_p (XVECEXP (x, i, j), only_useless))
292             return 1;
293     }
294
295   return 0;
296 }
297
298 /* For all locations found in X, delete locations that reference useless
299    values (i.e. values without any location).  Called through
300    htab_traverse.  */
301
302 static int
303 discard_useless_locs (void **x, void *info ATTRIBUTE_UNUSED)
304 {
305   cselib_val *v = (cselib_val *)*x;
306   struct elt_loc_list **p = &v->locs;
307   int had_locs = v->locs != 0;
308
309   while (*p)
310     {
311       if (references_value_p ((*p)->loc, 1))
312         unchain_one_elt_loc_list (p);
313       else
314         p = &(*p)->next;
315     }
316
317   if (had_locs && v->locs == 0)
318     {
319       n_useless_values++;
320       values_became_useless = 1;
321     }
322   return 1;
323 }
324
325 /* If X is a value with no locations, remove it from the hashtable.  */
326
327 static int
328 discard_useless_values (void **x, void *info ATTRIBUTE_UNUSED)
329 {
330   cselib_val *v = (cselib_val *)*x;
331
332   if (v->locs == 0)
333     {
334       CSELIB_VAL_PTR (v->u.val_rtx) = NULL;
335       htab_clear_slot (hash_table, x);
336       unchain_one_value (v);
337       n_useless_values--;
338     }
339
340   return 1;
341 }
342
343 /* Clean out useless values (i.e. those which no longer have locations
344    associated with them) from the hash table.  */
345
346 static void
347 remove_useless_values (void)
348 {
349   cselib_val **p, *v;
350   /* First pass: eliminate locations that reference the value.  That in
351      turn can make more values useless.  */
352   do
353     {
354       values_became_useless = 0;
355       htab_traverse (hash_table, discard_useless_locs, 0);
356     }
357   while (values_became_useless);
358
359   /* Second pass: actually remove the values.  */
360   p = &first_containing_mem;
361   for (v = *p; v != &dummy_val; v = v->next_containing_mem)
362     if (v->locs)
363       {
364         *p = v;
365         p = &(*p)->next_containing_mem;
366       }
367   *p = &dummy_val;
368
369   htab_traverse (hash_table, discard_useless_values, 0);
370
371   if (n_useless_values != 0)
372     abort ();
373 }
374
375 /* Return the mode in which a register was last set.  If X is not a
376    register, return its mode.  If the mode in which the register was
377    set is not known, or the value was already clobbered, return
378    VOIDmode.  */
379
380 enum machine_mode
381 cselib_reg_set_mode (rtx x)
382 {
383   if (GET_CODE (x) != REG)
384     return GET_MODE (x);
385
386   if (REG_VALUES (REGNO (x)) == NULL
387       || REG_VALUES (REGNO (x))->elt == NULL)
388     return VOIDmode;
389
390   return GET_MODE (REG_VALUES (REGNO (x))->elt->u.val_rtx);
391 }
392
393 /* Return nonzero if we can prove that X and Y contain the same value, taking
394    our gathered information into account.  */
395
396 int
397 rtx_equal_for_cselib_p (rtx x, rtx y)
398 {
399   enum rtx_code code;
400   const char *fmt;
401   int i;
402
403   if (GET_CODE (x) == REG || GET_CODE (x) == MEM)
404     {
405       cselib_val *e = cselib_lookup (x, GET_MODE (x), 0);
406
407       if (e)
408         x = e->u.val_rtx;
409     }
410
411   if (GET_CODE (y) == REG || GET_CODE (y) == MEM)
412     {
413       cselib_val *e = cselib_lookup (y, GET_MODE (y), 0);
414
415       if (e)
416         y = e->u.val_rtx;
417     }
418
419   if (x == y)
420     return 1;
421
422   if (GET_CODE (x) == VALUE && GET_CODE (y) == VALUE)
423     return CSELIB_VAL_PTR (x) == CSELIB_VAL_PTR (y);
424
425   if (GET_CODE (x) == VALUE)
426     {
427       cselib_val *e = CSELIB_VAL_PTR (x);
428       struct elt_loc_list *l;
429
430       for (l = e->locs; l; l = l->next)
431         {
432           rtx t = l->loc;
433
434           /* Avoid infinite recursion.  */
435           if (GET_CODE (t) == REG || GET_CODE (t) == MEM)
436             continue;
437           else if (rtx_equal_for_cselib_p (t, y))
438             return 1;
439         }
440
441       return 0;
442     }
443
444   if (GET_CODE (y) == VALUE)
445     {
446       cselib_val *e = CSELIB_VAL_PTR (y);
447       struct elt_loc_list *l;
448
449       for (l = e->locs; l; l = l->next)
450         {
451           rtx t = l->loc;
452
453           if (GET_CODE (t) == REG || GET_CODE (t) == MEM)
454             continue;
455           else if (rtx_equal_for_cselib_p (x, t))
456             return 1;
457         }
458
459       return 0;
460     }
461
462   if (GET_CODE (x) != GET_CODE (y) || GET_MODE (x) != GET_MODE (y))
463     return 0;
464
465   /* This won't be handled correctly by the code below.  */
466   if (GET_CODE (x) == LABEL_REF)
467     return XEXP (x, 0) == XEXP (y, 0);
468
469   code = GET_CODE (x);
470   fmt = GET_RTX_FORMAT (code);
471
472   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
473     {
474       int j;
475
476       switch (fmt[i])
477         {
478         case 'w':
479           if (XWINT (x, i) != XWINT (y, i))
480             return 0;
481           break;
482
483         case 'n':
484         case 'i':
485           if (XINT (x, i) != XINT (y, i))
486             return 0;
487           break;
488
489         case 'V':
490         case 'E':
491           /* Two vectors must have the same length.  */
492           if (XVECLEN (x, i) != XVECLEN (y, i))
493             return 0;
494
495           /* And the corresponding elements must match.  */
496           for (j = 0; j < XVECLEN (x, i); j++)
497             if (! rtx_equal_for_cselib_p (XVECEXP (x, i, j),
498                                           XVECEXP (y, i, j)))
499               return 0;
500           break;
501
502         case 'e':
503           if (! rtx_equal_for_cselib_p (XEXP (x, i), XEXP (y, i)))
504             return 0;
505           break;
506
507         case 'S':
508         case 's':
509           if (strcmp (XSTR (x, i), XSTR (y, i)))
510             return 0;
511           break;
512
513         case 'u':
514           /* These are just backpointers, so they don't matter.  */
515           break;
516
517         case '0':
518         case 't':
519           break;
520
521           /* It is believed that rtx's at this level will never
522              contain anything but integers and other rtx's,
523              except for within LABEL_REFs and SYMBOL_REFs.  */
524         default:
525           abort ();
526         }
527     }
528   return 1;
529 }
530
531 /* We need to pass down the mode of constants through the hash table
532    functions.  For that purpose, wrap them in a CONST of the appropriate
533    mode.  */
534 static rtx
535 wrap_constant (enum machine_mode mode, rtx x)
536 {
537   if (GET_CODE (x) != CONST_INT
538       && (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode))
539     return x;
540   if (mode == VOIDmode)
541     abort ();
542   return gen_rtx_CONST (mode, x);
543 }
544
545 /* Hash an rtx.  Return 0 if we couldn't hash the rtx.
546    For registers and memory locations, we look up their cselib_val structure
547    and return its VALUE element.
548    Possible reasons for return 0 are: the object is volatile, or we couldn't
549    find a register or memory location in the table and CREATE is zero.  If
550    CREATE is nonzero, table elts are created for regs and mem.
551    MODE is used in hashing for CONST_INTs only;
552    otherwise the mode of X is used.  */
553
554 static unsigned int
555 hash_rtx (rtx x, enum machine_mode mode, int create)
556 {
557   cselib_val *e;
558   int i, j;
559   enum rtx_code code;
560   const char *fmt;
561   unsigned int hash = 0;
562
563   code = GET_CODE (x);
564   hash += (unsigned) code + (unsigned) GET_MODE (x);
565
566   switch (code)
567     {
568     case MEM:
569     case REG:
570       e = cselib_lookup (x, GET_MODE (x), create);
571       if (! e)
572         return 0;
573
574       return e->value;
575
576     case CONST_INT:
577       hash += ((unsigned) CONST_INT << 7) + (unsigned) mode + INTVAL (x);
578       return hash ? hash : (unsigned int) CONST_INT;
579
580     case CONST_DOUBLE:
581       /* This is like the general case, except that it only counts
582          the integers representing the constant.  */
583       hash += (unsigned) code + (unsigned) GET_MODE (x);
584       if (GET_MODE (x) != VOIDmode)
585         hash += real_hash (CONST_DOUBLE_REAL_VALUE (x));
586       else
587         hash += ((unsigned) CONST_DOUBLE_LOW (x)
588                  + (unsigned) CONST_DOUBLE_HIGH (x));
589       return hash ? hash : (unsigned int) CONST_DOUBLE;
590
591     case CONST_VECTOR:
592       {
593         int units;
594         rtx elt;
595
596         units = CONST_VECTOR_NUNITS (x);
597
598         for (i = 0; i < units; ++i)
599           {
600             elt = CONST_VECTOR_ELT (x, i);
601             hash += hash_rtx (elt, GET_MODE (elt), 0);
602           }
603
604         return hash;
605       }
606
607       /* Assume there is only one rtx object for any given label.  */
608     case LABEL_REF:
609       hash
610         += ((unsigned) LABEL_REF << 7) + (unsigned long) XEXP (x, 0);
611       return hash ? hash : (unsigned int) LABEL_REF;
612
613     case SYMBOL_REF:
614       hash
615         += ((unsigned) SYMBOL_REF << 7) + (unsigned long) XSTR (x, 0);
616       return hash ? hash : (unsigned int) SYMBOL_REF;
617
618     case PRE_DEC:
619     case PRE_INC:
620     case POST_DEC:
621     case POST_INC:
622     case POST_MODIFY:
623     case PRE_MODIFY:
624     case PC:
625     case CC0:
626     case CALL:
627     case UNSPEC_VOLATILE:
628       return 0;
629
630     case ASM_OPERANDS:
631       if (MEM_VOLATILE_P (x))
632         return 0;
633
634       break;
635
636     default:
637       break;
638     }
639
640   i = GET_RTX_LENGTH (code) - 1;
641   fmt = GET_RTX_FORMAT (code);
642   for (; i >= 0; i--)
643     {
644       if (fmt[i] == 'e')
645         {
646           rtx tem = XEXP (x, i);
647           unsigned int tem_hash = hash_rtx (tem, 0, create);
648
649           if (tem_hash == 0)
650             return 0;
651
652           hash += tem_hash;
653         }
654       else if (fmt[i] == 'E')
655         for (j = 0; j < XVECLEN (x, i); j++)
656           {
657             unsigned int tem_hash = hash_rtx (XVECEXP (x, i, j), 0, create);
658
659             if (tem_hash == 0)
660               return 0;
661
662             hash += tem_hash;
663           }
664       else if (fmt[i] == 's')
665         {
666           const unsigned char *p = (const unsigned char *) XSTR (x, i);
667
668           if (p)
669             while (*p)
670               hash += *p++;
671         }
672       else if (fmt[i] == 'i')
673         hash += XINT (x, i);
674       else if (fmt[i] == '0' || fmt[i] == 't')
675         /* unused */;
676       else
677         abort ();
678     }
679
680   return hash ? hash : 1 + (unsigned int) GET_CODE (x);
681 }
682
683 /* Create a new value structure for VALUE and initialize it.  The mode of the
684    value is MODE.  */
685
686 static inline cselib_val *
687 new_cselib_val (unsigned int value, enum machine_mode mode)
688 {
689   cselib_val *e = pool_alloc (cselib_val_pool);
690
691 #ifdef ENABLE_CHECKING
692   if (value == 0)
693     abort ();
694 #endif
695
696   e->value = value;
697   /* We use custom method to allocate this RTL construct because it accounts
698      about 8% of overall memory usage.  */
699   e->u.val_rtx = pool_alloc (value_pool);
700   memset (e->u.val_rtx, 0, RTX_HDR_SIZE);
701   PUT_CODE (e->u.val_rtx, VALUE);
702   PUT_MODE (e->u.val_rtx, mode);
703   CSELIB_VAL_PTR (e->u.val_rtx) = e;
704   e->addr_list = 0;
705   e->locs = 0;
706   e->next_containing_mem = 0;
707   return e;
708 }
709
710 /* ADDR_ELT is a value that is used as address.  MEM_ELT is the value that
711    contains the data at this address.  X is a MEM that represents the
712    value.  Update the two value structures to represent this situation.  */
713
714 static void
715 add_mem_for_addr (cselib_val *addr_elt, cselib_val *mem_elt, rtx x)
716 {
717   struct elt_loc_list *l;
718
719   /* Avoid duplicates.  */
720   for (l = mem_elt->locs; l; l = l->next)
721     if (GET_CODE (l->loc) == MEM
722         && CSELIB_VAL_PTR (XEXP (l->loc, 0)) == addr_elt)
723       return;
724
725   addr_elt->addr_list = new_elt_list (addr_elt->addr_list, mem_elt);
726   mem_elt->locs
727     = new_elt_loc_list (mem_elt->locs,
728                         replace_equiv_address_nv (x, addr_elt->u.val_rtx));
729   if (mem_elt->next_containing_mem == NULL)
730     {
731       mem_elt->next_containing_mem = first_containing_mem;
732       first_containing_mem = mem_elt;
733     }
734 }
735
736 /* Subroutine of cselib_lookup.  Return a value for X, which is a MEM rtx.
737    If CREATE, make a new one if we haven't seen it before.  */
738
739 static cselib_val *
740 cselib_lookup_mem (rtx x, int create)
741 {
742   enum machine_mode mode = GET_MODE (x);
743   void **slot;
744   cselib_val *addr;
745   cselib_val *mem_elt;
746   struct elt_list *l;
747
748   if (MEM_VOLATILE_P (x) || mode == BLKmode
749       || (FLOAT_MODE_P (mode) && flag_float_store))
750     return 0;
751
752   /* Look up the value for the address.  */
753   addr = cselib_lookup (XEXP (x, 0), mode, create);
754   if (! addr)
755     return 0;
756
757   /* Find a value that describes a value of our mode at that address.  */
758   for (l = addr->addr_list; l; l = l->next)
759     if (GET_MODE (l->elt->u.val_rtx) == mode)
760       return l->elt;
761
762   if (! create)
763     return 0;
764
765   mem_elt = new_cselib_val (++next_unknown_value, mode);
766   add_mem_for_addr (addr, mem_elt, x);
767   slot = htab_find_slot_with_hash (hash_table, wrap_constant (mode, x),
768                                    mem_elt->value, INSERT);
769   *slot = mem_elt;
770   return mem_elt;
771 }
772
773 /* Walk rtx X and replace all occurrences of REG and MEM subexpressions
774    with VALUE expressions.  This way, it becomes independent of changes
775    to registers and memory.
776    X isn't actually modified; if modifications are needed, new rtl is
777    allocated.  However, the return value can share rtl with X.  */
778
779 rtx
780 cselib_subst_to_values (rtx x)
781 {
782   enum rtx_code code = GET_CODE (x);
783   const char *fmt = GET_RTX_FORMAT (code);
784   cselib_val *e;
785   struct elt_list *l;
786   rtx copy = x;
787   int i;
788
789   switch (code)
790     {
791     case REG:
792       l = REG_VALUES (REGNO (x));
793       if (l && l->elt == NULL)
794         l = l->next;
795       for (; l; l = l->next)
796         if (GET_MODE (l->elt->u.val_rtx) == GET_MODE (x))
797           return l->elt->u.val_rtx;
798
799       abort ();
800
801     case MEM:
802       e = cselib_lookup_mem (x, 0);
803       if (! e)
804         {
805           /* This happens for autoincrements.  Assign a value that doesn't
806              match any other.  */
807           e = new_cselib_val (++next_unknown_value, GET_MODE (x));
808         }
809       return e->u.val_rtx;
810
811     case CONST_DOUBLE:
812     case CONST_VECTOR:
813     case CONST_INT:
814       return x;
815
816     case POST_INC:
817     case PRE_INC:
818     case POST_DEC:
819     case PRE_DEC:
820     case POST_MODIFY:
821     case PRE_MODIFY:
822       e = new_cselib_val (++next_unknown_value, GET_MODE (x));
823       return e->u.val_rtx;
824
825     default:
826       break;
827     }
828
829   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
830     {
831       if (fmt[i] == 'e')
832         {
833           rtx t = cselib_subst_to_values (XEXP (x, i));
834
835           if (t != XEXP (x, i) && x == copy)
836             copy = shallow_copy_rtx (x);
837
838           XEXP (copy, i) = t;
839         }
840       else if (fmt[i] == 'E')
841         {
842           int j, k;
843
844           for (j = 0; j < XVECLEN (x, i); j++)
845             {
846               rtx t = cselib_subst_to_values (XVECEXP (x, i, j));
847
848               if (t != XVECEXP (x, i, j) && XVEC (x, i) == XVEC (copy, i))
849                 {
850                   if (x == copy)
851                     copy = shallow_copy_rtx (x);
852
853                   XVEC (copy, i) = rtvec_alloc (XVECLEN (x, i));
854                   for (k = 0; k < j; k++)
855                     XVECEXP (copy, i, k) = XVECEXP (x, i, k);
856                 }
857
858               XVECEXP (copy, i, j) = t;
859             }
860         }
861     }
862
863   return copy;
864 }
865
866 /* Look up the rtl expression X in our tables and return the value it has.
867    If CREATE is zero, we return NULL if we don't know the value.  Otherwise,
868    we create a new one if possible, using mode MODE if X doesn't have a mode
869    (i.e. because it's a constant).  */
870
871 cselib_val *
872 cselib_lookup (rtx x, enum machine_mode mode, int create)
873 {
874   void **slot;
875   cselib_val *e;
876   unsigned int hashval;
877
878   if (GET_MODE (x) != VOIDmode)
879     mode = GET_MODE (x);
880
881   if (GET_CODE (x) == VALUE)
882     return CSELIB_VAL_PTR (x);
883
884   if (GET_CODE (x) == REG)
885     {
886       struct elt_list *l;
887       unsigned int i = REGNO (x);
888
889       l = REG_VALUES (i);
890       if (l && l->elt == NULL)
891         l = l->next;
892       for (; l; l = l->next)
893         if (mode == GET_MODE (l->elt->u.val_rtx))
894           return l->elt;
895
896       if (! create)
897         return 0;
898
899       if (i < FIRST_PSEUDO_REGISTER)
900         {
901           unsigned int n = HARD_REGNO_NREGS (i, mode);
902
903           if (n > max_value_regs)
904             max_value_regs = n;
905         }
906
907       e = new_cselib_val (++next_unknown_value, GET_MODE (x));
908       e->locs = new_elt_loc_list (e->locs, x);
909       if (REG_VALUES (i) == 0)
910         {
911           /* Maintain the invariant that the first entry of
912              REG_VALUES, if present, must be the value used to set the
913              register, or NULL.  */
914           VARRAY_PUSH_UINT (used_regs, i);
915           REG_VALUES (i) = new_elt_list (REG_VALUES (i), NULL);
916         }
917       REG_VALUES (i)->next = new_elt_list (REG_VALUES (i)->next, e);
918       slot = htab_find_slot_with_hash (hash_table, x, e->value, INSERT);
919       *slot = e;
920       return e;
921     }
922
923   if (GET_CODE (x) == MEM)
924     return cselib_lookup_mem (x, create);
925
926   hashval = hash_rtx (x, mode, create);
927   /* Can't even create if hashing is not possible.  */
928   if (! hashval)
929     return 0;
930
931   slot = htab_find_slot_with_hash (hash_table, wrap_constant (mode, x),
932                                    hashval, create ? INSERT : NO_INSERT);
933   if (slot == 0)
934     return 0;
935
936   e = (cselib_val *) *slot;
937   if (e)
938     return e;
939
940   e = new_cselib_val (hashval, mode);
941
942   /* We have to fill the slot before calling cselib_subst_to_values:
943      the hash table is inconsistent until we do so, and
944      cselib_subst_to_values will need to do lookups.  */
945   *slot = (void *) e;
946   e->locs = new_elt_loc_list (e->locs, cselib_subst_to_values (x));
947   return e;
948 }
949
950 /* Invalidate any entries in reg_values that overlap REGNO.  This is called
951    if REGNO is changing.  MODE is the mode of the assignment to REGNO, which
952    is used to determine how many hard registers are being changed.  If MODE
953    is VOIDmode, then only REGNO is being changed; this is used when
954    invalidating call clobbered registers across a call.  */
955
956 static void
957 cselib_invalidate_regno (unsigned int regno, enum machine_mode mode)
958 {
959   unsigned int endregno;
960   unsigned int i;
961
962   /* If we see pseudos after reload, something is _wrong_.  */
963   if (reload_completed && regno >= FIRST_PSEUDO_REGISTER
964       && reg_renumber[regno] >= 0)
965     abort ();
966
967   /* Determine the range of registers that must be invalidated.  For
968      pseudos, only REGNO is affected.  For hard regs, we must take MODE
969      into account, and we must also invalidate lower register numbers
970      if they contain values that overlap REGNO.  */
971   if (regno < FIRST_PSEUDO_REGISTER)
972     {
973       if (mode == VOIDmode)
974         abort ();
975
976       if (regno < max_value_regs)
977         i = 0;
978       else
979         i = regno - max_value_regs;
980
981       endregno = regno + HARD_REGNO_NREGS (regno, mode);
982     }
983   else
984     {
985       i = regno;
986       endregno = regno + 1;
987     }
988
989   for (; i < endregno; i++)
990     {
991       struct elt_list **l = &REG_VALUES (i);
992
993       /* Go through all known values for this reg; if it overlaps the range
994          we're invalidating, remove the value.  */
995       while (*l)
996         {
997           cselib_val *v = (*l)->elt;
998           struct elt_loc_list **p;
999           unsigned int this_last = i;
1000
1001           if (i < FIRST_PSEUDO_REGISTER && v != NULL)
1002             this_last += HARD_REGNO_NREGS (i, GET_MODE (v->u.val_rtx)) - 1;
1003
1004           if (this_last < regno || v == NULL)
1005             {
1006               l = &(*l)->next;
1007               continue;
1008             }
1009
1010           /* We have an overlap.  */
1011           if (*l == REG_VALUES (i))
1012             {
1013               /* Maintain the invariant that the first entry of
1014                  REG_VALUES, if present, must be the value used to set
1015                  the register, or NULL.  This is also nice because
1016                  then we won't push the same regno onto user_regs
1017                  multiple times.  */
1018               (*l)->elt = NULL;
1019               l = &(*l)->next;
1020             }
1021           else
1022             unchain_one_elt_list (l);
1023
1024           /* Now, we clear the mapping from value to reg.  It must exist, so
1025              this code will crash intentionally if it doesn't.  */
1026           for (p = &v->locs; ; p = &(*p)->next)
1027             {
1028               rtx x = (*p)->loc;
1029
1030               if (GET_CODE (x) == REG && REGNO (x) == i)
1031                 {
1032                   unchain_one_elt_loc_list (p);
1033                   break;
1034                 }
1035             }
1036           if (v->locs == 0)
1037             n_useless_values++;
1038         }
1039     }
1040 }
1041 \f
1042 /* Return 1 if X has a value that can vary even between two
1043    executions of the program.  0 means X can be compared reliably
1044    against certain constants or near-constants.  */
1045
1046 static int
1047 cselib_rtx_varies_p (rtx x ATTRIBUTE_UNUSED, int from_alias ATTRIBUTE_UNUSED)
1048 {
1049   /* We actually don't need to verify very hard.  This is because
1050      if X has actually changed, we invalidate the memory anyway,
1051      so assume that all common memory addresses are
1052      invariant.  */
1053   return 0;
1054 }
1055
1056 /* Invalidate any locations in the table which are changed because of a
1057    store to MEM_RTX.  If this is called because of a non-const call
1058    instruction, MEM_RTX is (mem:BLK const0_rtx).  */
1059
1060 static void
1061 cselib_invalidate_mem (rtx mem_rtx)
1062 {
1063   cselib_val **vp, *v, *next;
1064   int num_mems = 0;
1065   rtx mem_addr;
1066
1067   mem_addr = canon_rtx (get_addr (XEXP (mem_rtx, 0)));
1068   mem_rtx = canon_rtx (mem_rtx);
1069
1070   vp = &first_containing_mem;
1071   for (v = *vp; v != &dummy_val; v = next)
1072     {
1073       bool has_mem = false;
1074       struct elt_loc_list **p = &v->locs;
1075       int had_locs = v->locs != 0;
1076
1077       while (*p)
1078         {
1079           rtx x = (*p)->loc;
1080           rtx canon_x = (*p)->canon_loc;
1081           cselib_val *addr;
1082           struct elt_list **mem_chain;
1083
1084           /* MEMs may occur in locations only at the top level; below
1085              that every MEM or REG is substituted by its VALUE.  */
1086           if (GET_CODE (x) != MEM)
1087             {
1088               p = &(*p)->next;
1089               continue;
1090             }
1091           if (!canon_x)
1092             canon_x = (*p)->canon_loc = canon_rtx (x);
1093           if (num_mems < PARAM_VALUE (PARAM_MAX_CSELIB_MEMORY_LOCATIONS)
1094               && ! canon_true_dependence (mem_rtx, GET_MODE (mem_rtx), mem_addr,
1095                                           x, cselib_rtx_varies_p))
1096             {
1097               has_mem = true;
1098               num_mems++;
1099               p = &(*p)->next;
1100               continue;
1101             }
1102
1103           /* This one overlaps.  */
1104           /* We must have a mapping from this MEM's address to the
1105              value (E).  Remove that, too.  */
1106           addr = cselib_lookup (XEXP (x, 0), VOIDmode, 0);
1107           mem_chain = &addr->addr_list;
1108           for (;;)
1109             {
1110               if ((*mem_chain)->elt == v)
1111                 {
1112                   unchain_one_elt_list (mem_chain);
1113                   break;
1114                 }
1115
1116               mem_chain = &(*mem_chain)->next;
1117             }
1118
1119           unchain_one_elt_loc_list (p);
1120         }
1121
1122       if (had_locs && v->locs == 0)
1123         n_useless_values++;
1124
1125       next = v->next_containing_mem;
1126       if (has_mem)
1127         {
1128           *vp = v;
1129           vp = &(*vp)->next_containing_mem;
1130         }
1131       else
1132         v->next_containing_mem = NULL;
1133     }
1134   *vp = &dummy_val;
1135 }
1136
1137 /* Invalidate DEST, which is being assigned to or clobbered.  */
1138
1139 void
1140 cselib_invalidate_rtx (rtx dest)
1141 {
1142   while (GET_CODE (dest) == STRICT_LOW_PART || GET_CODE (dest) == SIGN_EXTRACT
1143          || GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SUBREG)
1144     dest = XEXP (dest, 0);
1145
1146   if (GET_CODE (dest) == REG)
1147     cselib_invalidate_regno (REGNO (dest), GET_MODE (dest));
1148   else if (GET_CODE (dest) == MEM)
1149     cselib_invalidate_mem (dest);
1150
1151   /* Some machines don't define AUTO_INC_DEC, but they still use push
1152      instructions.  We need to catch that case here in order to
1153      invalidate the stack pointer correctly.  Note that invalidating
1154      the stack pointer is different from invalidating DEST.  */
1155   if (push_operand (dest, GET_MODE (dest)))
1156     cselib_invalidate_rtx (stack_pointer_rtx);
1157 }
1158
1159 /* A wrapper for cselib_invalidate_rtx to be called via note_stores.  */
1160
1161 static void
1162 cselib_invalidate_rtx_note_stores (rtx dest, rtx ignore ATTRIBUTE_UNUSED,
1163                                    void *data ATTRIBUTE_UNUSED)
1164 {
1165   cselib_invalidate_rtx (dest);
1166 }
1167
1168 /* Record the result of a SET instruction.  DEST is being set; the source
1169    contains the value described by SRC_ELT.  If DEST is a MEM, DEST_ADDR_ELT
1170    describes its address.  */
1171
1172 static void
1173 cselib_record_set (rtx dest, cselib_val *src_elt, cselib_val *dest_addr_elt)
1174 {
1175   int dreg = GET_CODE (dest) == REG ? (int) REGNO (dest) : -1;
1176
1177   if (src_elt == 0 || side_effects_p (dest))
1178     return;
1179
1180   if (dreg >= 0)
1181     {
1182       if (dreg < FIRST_PSEUDO_REGISTER)
1183         {
1184           unsigned int n = HARD_REGNO_NREGS (dreg, GET_MODE (dest));
1185
1186           if (n > max_value_regs)
1187             max_value_regs = n;
1188         }
1189
1190       if (REG_VALUES (dreg) == 0)
1191         {
1192           VARRAY_PUSH_UINT (used_regs, dreg);
1193           REG_VALUES (dreg) = new_elt_list (REG_VALUES (dreg), src_elt);
1194         }
1195       else
1196         {
1197           if (REG_VALUES (dreg)->elt == 0)
1198             REG_VALUES (dreg)->elt = src_elt;
1199           else
1200             /* The register should have been invalidated.  */
1201             abort ();
1202         }
1203
1204       if (src_elt->locs == 0)
1205         n_useless_values--;
1206       src_elt->locs = new_elt_loc_list (src_elt->locs, dest);
1207     }
1208   else if (GET_CODE (dest) == MEM && dest_addr_elt != 0)
1209     {
1210       if (src_elt->locs == 0)
1211         n_useless_values--;
1212       add_mem_for_addr (dest_addr_elt, src_elt, dest);
1213     }
1214 }
1215
1216 /* Describe a single set that is part of an insn.  */
1217 struct set
1218 {
1219   rtx src;
1220   rtx dest;
1221   cselib_val *src_elt;
1222   cselib_val *dest_addr_elt;
1223 };
1224
1225 /* There is no good way to determine how many elements there can be
1226    in a PARALLEL.  Since it's fairly cheap, use a really large number.  */
1227 #define MAX_SETS (FIRST_PSEUDO_REGISTER * 2)
1228
1229 /* Record the effects of any sets in INSN.  */
1230 static void
1231 cselib_record_sets (rtx insn)
1232 {
1233   int n_sets = 0;
1234   int i;
1235   struct set sets[MAX_SETS];
1236   rtx body = PATTERN (insn);
1237   rtx cond = 0;
1238
1239   body = PATTERN (insn);
1240   if (GET_CODE (body) == COND_EXEC)
1241     {
1242       cond = COND_EXEC_TEST (body);
1243       body = COND_EXEC_CODE (body);
1244     }
1245
1246   /* Find all sets.  */
1247   if (GET_CODE (body) == SET)
1248     {
1249       sets[0].src = SET_SRC (body);
1250       sets[0].dest = SET_DEST (body);
1251       n_sets = 1;
1252     }
1253   else if (GET_CODE (body) == PARALLEL)
1254     {
1255       /* Look through the PARALLEL and record the values being
1256          set, if possible.  Also handle any CLOBBERs.  */
1257       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
1258         {
1259           rtx x = XVECEXP (body, 0, i);
1260
1261           if (GET_CODE (x) == SET)
1262             {
1263               sets[n_sets].src = SET_SRC (x);
1264               sets[n_sets].dest = SET_DEST (x);
1265               n_sets++;
1266             }
1267         }
1268     }
1269
1270   /* Look up the values that are read.  Do this before invalidating the
1271      locations that are written.  */
1272   for (i = 0; i < n_sets; i++)
1273     {
1274       rtx dest = sets[i].dest;
1275
1276       /* A STRICT_LOW_PART can be ignored; we'll record the equivalence for
1277          the low part after invalidating any knowledge about larger modes.  */
1278       if (GET_CODE (sets[i].dest) == STRICT_LOW_PART)
1279         sets[i].dest = dest = XEXP (dest, 0);
1280
1281       /* We don't know how to record anything but REG or MEM.  */
1282       if (GET_CODE (dest) == REG || GET_CODE (dest) == MEM)
1283         {
1284           rtx src = sets[i].src;
1285           if (cond)
1286             src = gen_rtx_IF_THEN_ELSE (GET_MODE (src), cond, src, dest);
1287           sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1);
1288           if (GET_CODE (dest) == MEM)
1289             sets[i].dest_addr_elt = cselib_lookup (XEXP (dest, 0), Pmode, 1);
1290           else
1291             sets[i].dest_addr_elt = 0;
1292         }
1293     }
1294
1295   /* Invalidate all locations written by this insn.  Note that the elts we
1296      looked up in the previous loop aren't affected, just some of their
1297      locations may go away.  */
1298   note_stores (body, cselib_invalidate_rtx_note_stores, NULL);
1299
1300   /* If this is an asm, look for duplicate sets.  This can happen when the
1301      user uses the same value as an output multiple times.  This is valid
1302      if the outputs are not actually used thereafter.  Treat this case as
1303      if the value isn't actually set.  We do this by smashing the destination
1304      to pc_rtx, so that we won't record the value later.  */
1305   if (n_sets >= 2 && asm_noperands (body) >= 0)
1306     {
1307       for (i = 0; i < n_sets; i++)
1308         {
1309           rtx dest = sets[i].dest;
1310           if (GET_CODE (dest) == REG || GET_CODE (dest) == MEM)
1311             {
1312               int j;
1313               for (j = i + 1; j < n_sets; j++)
1314                 if (rtx_equal_p (dest, sets[j].dest))
1315                   {
1316                     sets[i].dest = pc_rtx;
1317                     sets[j].dest = pc_rtx;
1318                   }
1319             }
1320         }
1321     }
1322
1323   /* Now enter the equivalences in our tables.  */
1324   for (i = 0; i < n_sets; i++)
1325     {
1326       rtx dest = sets[i].dest;
1327       if (GET_CODE (dest) == REG || GET_CODE (dest) == MEM)
1328         cselib_record_set (dest, sets[i].src_elt, sets[i].dest_addr_elt);
1329     }
1330 }
1331
1332 /* Record the effects of INSN.  */
1333
1334 void
1335 cselib_process_insn (rtx insn)
1336 {
1337   int i;
1338   rtx x;
1339
1340   if (find_reg_note (insn, REG_LIBCALL, NULL))
1341     cselib_current_insn_in_libcall = true;
1342   cselib_current_insn = insn;
1343
1344   /* Forget everything at a CODE_LABEL, a volatile asm, or a setjmp.  */
1345   if (GET_CODE (insn) == CODE_LABEL
1346       || (GET_CODE (insn) == CALL_INSN
1347           && find_reg_note (insn, REG_SETJMP, NULL))
1348       || (GET_CODE (insn) == INSN
1349           && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
1350           && MEM_VOLATILE_P (PATTERN (insn))))
1351     {
1352       if (find_reg_note (insn, REG_RETVAL, NULL))
1353         cselib_current_insn_in_libcall = false;
1354       clear_table ();
1355       return;
1356     }
1357
1358   if (! INSN_P (insn))
1359     {
1360       if (find_reg_note (insn, REG_RETVAL, NULL))
1361         cselib_current_insn_in_libcall = false;
1362       cselib_current_insn = 0;
1363       return;
1364     }
1365
1366   /* If this is a call instruction, forget anything stored in a
1367      call clobbered register, or, if this is not a const call, in
1368      memory.  */
1369   if (GET_CODE (insn) == CALL_INSN)
1370     {
1371       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1372         if (call_used_regs[i])
1373           cselib_invalidate_regno (i, reg_raw_mode[i]);
1374
1375       if (! CONST_OR_PURE_CALL_P (insn))
1376         cselib_invalidate_mem (callmem);
1377     }
1378
1379   cselib_record_sets (insn);
1380
1381 #ifdef AUTO_INC_DEC
1382   /* Clobber any registers which appear in REG_INC notes.  We
1383      could keep track of the changes to their values, but it is
1384      unlikely to help.  */
1385   for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
1386     if (REG_NOTE_KIND (x) == REG_INC)
1387       cselib_invalidate_rtx (XEXP (x, 0));
1388 #endif
1389
1390   /* Look for any CLOBBERs in CALL_INSN_FUNCTION_USAGE, but only
1391      after we have processed the insn.  */
1392   if (GET_CODE (insn) == CALL_INSN)
1393     for (x = CALL_INSN_FUNCTION_USAGE (insn); x; x = XEXP (x, 1))
1394       if (GET_CODE (XEXP (x, 0)) == CLOBBER)
1395         cselib_invalidate_rtx (XEXP (XEXP (x, 0), 0));
1396
1397   if (find_reg_note (insn, REG_RETVAL, NULL))
1398     cselib_current_insn_in_libcall = false;
1399   cselib_current_insn = 0;
1400
1401   if (n_useless_values > MAX_USELESS_VALUES)
1402     remove_useless_values ();
1403 }
1404
1405 /* Make sure our varrays are big enough.  Not called from any cselib routines;
1406    it must be called by the user if it allocated new registers.  */
1407
1408 void
1409 cselib_update_varray_sizes (void)
1410 {
1411   unsigned int nregs = max_reg_num ();
1412
1413   if (nregs == cselib_nregs)
1414     return;
1415
1416   cselib_nregs = nregs;
1417   VARRAY_GROW (reg_values, nregs);
1418   VARRAY_GROW (used_regs, nregs);
1419 }
1420
1421 /* Initialize cselib for one pass.  The caller must also call
1422    init_alias_analysis.  */
1423
1424 void
1425 cselib_init (void)
1426 {
1427   elt_list_pool = create_alloc_pool ("elt_list", 
1428                                      sizeof (struct elt_list), 10);
1429   elt_loc_list_pool = create_alloc_pool ("elt_loc_list", 
1430                                          sizeof (struct elt_loc_list), 10);
1431   cselib_val_pool = create_alloc_pool ("cselib_val_list", 
1432                                        sizeof (cselib_val), 10);
1433   value_pool = create_alloc_pool ("value", 
1434                                   RTX_SIZE (VALUE), 10);
1435   /* This is only created once.  */
1436   if (! callmem)
1437     callmem = gen_rtx_MEM (BLKmode, const0_rtx);
1438
1439   cselib_nregs = max_reg_num ();
1440   if (reg_values_old != NULL && VARRAY_SIZE (reg_values_old) >= cselib_nregs)
1441     {
1442       reg_values = reg_values_old;
1443       used_regs = used_regs_old;
1444     }
1445   else
1446     {
1447       VARRAY_ELT_LIST_INIT (reg_values, cselib_nregs, "reg_values");
1448       VARRAY_UINT_INIT (used_regs, cselib_nregs, "used_regs");
1449     }
1450   hash_table = htab_create_ggc (31, get_value_hash, entry_and_rtx_equal_p,
1451                                 NULL);
1452   cselib_current_insn_in_libcall = false;
1453 }
1454
1455 /* Called when the current user is done with cselib.  */
1456
1457 void
1458 cselib_finish (void)
1459 {
1460   free_alloc_pool (elt_list_pool);
1461   free_alloc_pool (elt_loc_list_pool);
1462   free_alloc_pool (cselib_val_pool);
1463   free_alloc_pool (value_pool);
1464   clear_table ();
1465   reg_values_old = reg_values;
1466   reg_values = 0;
1467   used_regs_old = used_regs;
1468   used_regs = 0;
1469   hash_table = 0;
1470   n_useless_values = 0;
1471   next_unknown_value = 0;
1472 }
1473
1474 #include "gt-cselib.h"