1/* Common subexpression elimination for GNU compiler. 2 Copyright (C) 1987-2015 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License 17along with GCC; see the file COPYING3. If not see 18<http://www.gnu.org/licenses/>. */ 19 20#ifndef GCC_CSELIB_H 21#define GCC_CSELIB_H 22 23/* Describe a value. */ 24struct cselib_val { 25 /* The hash value. */ 26 unsigned int hash; 27 28 /* A unique id assigned to values. */ 29 int uid; 30 31 /* A VALUE rtx that points back to this structure. */ 32 rtx val_rtx; 33 34 /* All rtl expressions that hold this value at the current time during a 35 scan. */ 36 struct elt_loc_list *locs; 37 38 /* If this value is used as an address, points to a list of values that 39 use it as an address in a MEM. */ 40 struct elt_list *addr_list; 41 42 struct cselib_val *next_containing_mem; 43}; 44 45/* A list of rtl expressions that hold the same value. */ 46struct elt_loc_list { 47 /* Next element in the list. */ 48 struct elt_loc_list *next; 49 /* An rtl expression that holds the value. */ 50 rtx loc; 51 /* The insn that made the equivalence. */ 52 rtx_insn *setting_insn; 53}; 54 55/* Describe a single set that is part of an insn. */ 56struct cselib_set 57{ 58 rtx src; 59 rtx dest; 60 cselib_val *src_elt; 61 cselib_val *dest_addr_elt; 62}; 63 64enum cselib_record_what 65{ 66 CSELIB_RECORD_MEMORY = 1, 67 CSELIB_PRESERVE_CONSTANTS = 2 68}; 69 70extern void (*cselib_discard_hook) (cselib_val *); 71extern void (*cselib_record_sets_hook) (rtx_insn *insn, struct cselib_set *sets, 72 int n_sets); 73 74extern cselib_val *cselib_lookup (rtx, machine_mode, 75 int, machine_mode); 76extern cselib_val *cselib_lookup_from_insn (rtx, machine_mode, 77 int, machine_mode, rtx_insn *); 78extern void cselib_init (int); 79extern void cselib_clear_table (void); 80extern void cselib_finish (void); 81extern void cselib_process_insn (rtx_insn *); 82extern bool fp_setter_insn (rtx); 83extern machine_mode cselib_reg_set_mode (const_rtx); 84extern int rtx_equal_for_cselib_p (rtx, rtx); 85extern int references_value_p (const_rtx, int); 86extern rtx cselib_expand_value_rtx (rtx, bitmap, int); 87typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *); 88extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int, 89 cselib_expand_callback, void *); 90extern bool cselib_dummy_expand_value_rtx_cb (rtx, bitmap, int, 91 cselib_expand_callback, void *); 92extern rtx cselib_subst_to_values (rtx, machine_mode); 93extern rtx cselib_subst_to_values_from_insn (rtx, machine_mode, rtx_insn *); 94extern void cselib_invalidate_rtx (rtx); 95 96extern void cselib_reset_table (unsigned int); 97extern unsigned int cselib_get_next_uid (void); 98extern void cselib_preserve_value (cselib_val *); 99extern bool cselib_preserved_value_p (cselib_val *); 100extern void cselib_preserve_only_values (void); 101extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int); 102extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx_insn *); 103extern bool cselib_have_permanent_equivalences (void); 104extern void cselib_set_value_sp_based (cselib_val *); 105extern bool cselib_sp_based_value_p (cselib_val *); 106 107extern void dump_cselib_table (FILE *); 108 109/* Return the canonical value for VAL, following the equivalence chain 110 towards the earliest (== lowest uid) equivalent value. */ 111 112static inline cselib_val * 113canonical_cselib_val (cselib_val *val) 114{ 115 cselib_val *canon; 116 117 if (!val->locs || val->locs->next 118 || !val->locs->loc || GET_CODE (val->locs->loc) != VALUE 119 || val->uid < CSELIB_VAL_PTR (val->locs->loc)->uid) 120 return val; 121 122 canon = CSELIB_VAL_PTR (val->locs->loc); 123 gcc_checking_assert (canonical_cselib_val (canon) == canon); 124 return canon; 125} 126 127#endif /* GCC_CSELIB_H */ 128