| 1 | 
         684 | 
         jeremybenn | 
         /* Common subexpression elimination for GNU compiler.
  | 
      
      
         | 2 | 
          | 
          | 
            Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
  | 
      
      
         | 3 | 
          | 
          | 
            1998, 1999, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
  | 
      
      
         | 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 | 
          | 
          | 
         /* Describe a value.  */
  | 
      
      
         | 23 | 
          | 
          | 
         typedef struct cselib_val_struct {
  | 
      
      
         | 24 | 
          | 
          | 
           /* The hash value.  */
  | 
      
      
         | 25 | 
          | 
          | 
           unsigned int hash;
  | 
      
      
         | 26 | 
          | 
          | 
          
  | 
      
      
         | 27 | 
          | 
          | 
           /* A unique id assigned to values.  */
  | 
      
      
         | 28 | 
          | 
          | 
           int uid;
  | 
      
      
         | 29 | 
          | 
          | 
          
  | 
      
      
         | 30 | 
          | 
          | 
           /* A VALUE rtx that points back to this structure.  */
  | 
      
      
         | 31 | 
          | 
          | 
           rtx val_rtx;
  | 
      
      
         | 32 | 
          | 
          | 
          
  | 
      
      
         | 33 | 
          | 
          | 
           /* All rtl expressions that hold this value at the current time during a
  | 
      
      
         | 34 | 
          | 
          | 
              scan.  */
  | 
      
      
         | 35 | 
          | 
          | 
           struct elt_loc_list *locs;
  | 
      
      
         | 36 | 
          | 
          | 
          
  | 
      
      
         | 37 | 
          | 
          | 
           /* If this value is used as an address, points to a list of values that
  | 
      
      
         | 38 | 
          | 
          | 
              use it as an address in a MEM.  */
  | 
      
      
         | 39 | 
          | 
          | 
           struct elt_list *addr_list;
  | 
      
      
         | 40 | 
          | 
          | 
          
  | 
      
      
         | 41 | 
          | 
          | 
           struct cselib_val_struct *next_containing_mem;
  | 
      
      
         | 42 | 
          | 
          | 
         } cselib_val;
  | 
      
      
         | 43 | 
          | 
          | 
          
  | 
      
      
         | 44 | 
          | 
          | 
         /* A list of rtl expressions that hold the same value.  */
  | 
      
      
         | 45 | 
          | 
          | 
         struct elt_loc_list {
  | 
      
      
         | 46 | 
          | 
          | 
           /* Next element in the list.  */
  | 
      
      
         | 47 | 
          | 
          | 
           struct elt_loc_list *next;
  | 
      
      
         | 48 | 
          | 
          | 
           /* An rtl expression that holds the value.  */
  | 
      
      
         | 49 | 
          | 
          | 
           rtx loc;
  | 
      
      
         | 50 | 
          | 
          | 
           /* The insn that made the equivalence.  */
  | 
      
      
         | 51 | 
          | 
          | 
           rtx setting_insn;
  | 
      
      
         | 52 | 
          | 
          | 
         };
  | 
      
      
         | 53 | 
          | 
          | 
          
  | 
      
      
         | 54 | 
          | 
          | 
         /* Describe a single set that is part of an insn.  */
  | 
      
      
         | 55 | 
          | 
          | 
         struct cselib_set
  | 
      
      
         | 56 | 
          | 
          | 
         {
  | 
      
      
         | 57 | 
          | 
          | 
           rtx src;
  | 
      
      
         | 58 | 
          | 
          | 
           rtx dest;
  | 
      
      
         | 59 | 
          | 
          | 
           cselib_val *src_elt;
  | 
      
      
         | 60 | 
          | 
          | 
           cselib_val *dest_addr_elt;
  | 
      
      
         | 61 | 
          | 
          | 
         };
  | 
      
      
         | 62 | 
          | 
          | 
          
  | 
      
      
         | 63 | 
          | 
          | 
         enum cselib_record_what
  | 
      
      
         | 64 | 
          | 
          | 
         {
  | 
      
      
         | 65 | 
          | 
          | 
           CSELIB_RECORD_MEMORY = 1,
  | 
      
      
         | 66 | 
          | 
          | 
           CSELIB_PRESERVE_CONSTANTS = 2
  | 
      
      
         | 67 | 
          | 
          | 
         };
  | 
      
      
         | 68 | 
          | 
          | 
          
  | 
      
      
         | 69 | 
          | 
          | 
         extern void (*cselib_discard_hook) (cselib_val *);
  | 
      
      
         | 70 | 
          | 
          | 
         extern void (*cselib_record_sets_hook) (rtx insn, struct cselib_set *sets,
  | 
      
      
         | 71 | 
          | 
          | 
                                                 int n_sets);
  | 
      
      
         | 72 | 
          | 
          | 
          
  | 
      
      
         | 73 | 
          | 
          | 
         extern cselib_val *cselib_lookup (rtx, enum machine_mode,
  | 
      
      
         | 74 | 
          | 
          | 
                                           int, enum machine_mode);
  | 
      
      
         | 75 | 
          | 
          | 
         extern cselib_val *cselib_lookup_from_insn (rtx, enum machine_mode,
  | 
      
      
         | 76 | 
          | 
          | 
                                                     int, enum machine_mode, rtx);
  | 
      
      
         | 77 | 
          | 
          | 
         extern void cselib_init (int);
  | 
      
      
         | 78 | 
          | 
          | 
         extern void cselib_clear_table (void);
  | 
      
      
         | 79 | 
          | 
          | 
         extern void cselib_finish (void);
  | 
      
      
         | 80 | 
          | 
          | 
         extern void cselib_process_insn (rtx);
  | 
      
      
         | 81 | 
          | 
          | 
         extern enum machine_mode cselib_reg_set_mode (const_rtx);
  | 
      
      
         | 82 | 
          | 
          | 
         extern int rtx_equal_for_cselib_p (rtx, rtx);
  | 
      
      
         | 83 | 
          | 
          | 
         extern int references_value_p (const_rtx, int);
  | 
      
      
         | 84 | 
          | 
          | 
         extern rtx cselib_expand_value_rtx (rtx, bitmap, int);
  | 
      
      
         | 85 | 
          | 
          | 
         typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *);
  | 
      
      
         | 86 | 
          | 
          | 
         extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int,
  | 
      
      
         | 87 | 
          | 
          | 
                                                cselib_expand_callback, void *);
  | 
      
      
         | 88 | 
          | 
          | 
         extern bool cselib_dummy_expand_value_rtx_cb (rtx, bitmap, int,
  | 
      
      
         | 89 | 
          | 
          | 
                                                       cselib_expand_callback, void *);
  | 
      
      
         | 90 | 
          | 
          | 
         extern rtx cselib_subst_to_values (rtx, enum machine_mode);
  | 
      
      
         | 91 | 
          | 
          | 
         extern rtx cselib_subst_to_values_from_insn (rtx, enum machine_mode, rtx);
  | 
      
      
         | 92 | 
          | 
          | 
         extern void cselib_invalidate_rtx (rtx);
  | 
      
      
         | 93 | 
          | 
          | 
          
  | 
      
      
         | 94 | 
          | 
          | 
         extern void cselib_reset_table (unsigned int);
  | 
      
      
         | 95 | 
          | 
          | 
         extern unsigned int cselib_get_next_uid (void);
  | 
      
      
         | 96 | 
          | 
          | 
         extern void cselib_preserve_value (cselib_val *);
  | 
      
      
         | 97 | 
          | 
          | 
         extern bool cselib_preserved_value_p (cselib_val *);
  | 
      
      
         | 98 | 
          | 
          | 
         extern void cselib_preserve_only_values (void);
  | 
      
      
         | 99 | 
          | 
          | 
         extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int);
  | 
      
      
         | 100 | 
          | 
          | 
         extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx);
  | 
      
      
         | 101 | 
          | 
          | 
          
  | 
      
      
         | 102 | 
          | 
          | 
         extern void dump_cselib_table (FILE *);
  | 
      
      
         | 103 | 
          | 
          | 
          
  | 
      
      
         | 104 | 
          | 
          | 
         /* Return the canonical value for VAL, following the equivalence chain
  | 
      
      
         | 105 | 
          | 
          | 
            towards the earliest (== lowest uid) equivalent value.  */
  | 
      
      
         | 106 | 
          | 
          | 
          
  | 
      
      
         | 107 | 
          | 
          | 
         static inline cselib_val *
  | 
      
      
         | 108 | 
          | 
          | 
         canonical_cselib_val (cselib_val *val)
  | 
      
      
         | 109 | 
          | 
          | 
         {
  | 
      
      
         | 110 | 
          | 
          | 
           cselib_val *canon;
  | 
      
      
         | 111 | 
          | 
          | 
          
  | 
      
      
         | 112 | 
          | 
          | 
           if (!val->locs || val->locs->next
  | 
      
      
         | 113 | 
          | 
          | 
               || !val->locs->loc || GET_CODE (val->locs->loc) != VALUE
  | 
      
      
         | 114 | 
          | 
          | 
               || val->uid < CSELIB_VAL_PTR (val->locs->loc)->uid)
  | 
      
      
         | 115 | 
          | 
          | 
             return val;
  | 
      
      
         | 116 | 
          | 
          | 
          
  | 
      
      
         | 117 | 
          | 
          | 
           canon = CSELIB_VAL_PTR (val->locs->loc);
  | 
      
      
         | 118 | 
          | 
          | 
           gcc_checking_assert (canonical_cselib_val (canon) == canon);
  | 
      
      
         | 119 | 
          | 
          | 
           return canon;
  | 
      
      
         | 120 | 
          | 
          | 
         }
  |