gcc/
[official-gcc.git] / gcc / cselib.h
blobcdd06ad952a96ba964084e20d97761de4e14a32c
1 /* Common subexpression elimination for GNU compiler.
2 Copyright (C) 1987-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_CSELIB_H
21 #define GCC_CSELIB_H
23 /* Describe a value. */
24 struct cselib_val
26 /* The hash value. */
27 unsigned int hash;
29 /* A unique id assigned to values. */
30 int uid;
32 /* A VALUE rtx that points back to this structure. */
33 rtx val_rtx;
35 /* All rtl expressions that hold this value at the current time during a
36 scan. */
37 struct elt_loc_list *locs;
39 /* If this value is used as an address, points to a list of values that
40 use it as an address in a MEM. */
41 struct elt_list *addr_list;
43 struct cselib_val *next_containing_mem;
45 /* Pool allocation new operator. */
46 inline void *operator new (size_t)
48 return pool.allocate ();
51 /* Delete operator utilizing pool allocation. */
52 inline void operator delete (void *ptr)
54 pool.remove ((cselib_val *) ptr);
57 /* Memory allocation pool. */
58 static pool_allocator<cselib_val> pool;
61 /* A list of rtl expressions that hold the same value. */
62 struct elt_loc_list {
63 /* Next element in the list. */
64 struct elt_loc_list *next;
65 /* An rtl expression that holds the value. */
66 rtx loc;
67 /* The insn that made the equivalence. */
68 rtx_insn *setting_insn;
70 /* Pool allocation new operator. */
71 inline void *operator new (size_t)
73 return pool.allocate ();
76 /* Delete operator utilizing pool allocation. */
77 inline void operator delete (void *ptr)
79 pool.remove ((elt_loc_list *) ptr);
82 /* Memory allocation pool. */
83 static pool_allocator<elt_loc_list> pool;
86 /* Describe a single set that is part of an insn. */
87 struct cselib_set
89 rtx src;
90 rtx dest;
91 cselib_val *src_elt;
92 cselib_val *dest_addr_elt;
95 enum cselib_record_what
97 CSELIB_RECORD_MEMORY = 1,
98 CSELIB_PRESERVE_CONSTANTS = 2
101 extern void (*cselib_discard_hook) (cselib_val *);
102 extern void (*cselib_record_sets_hook) (rtx_insn *insn, struct cselib_set *sets,
103 int n_sets);
105 extern cselib_val *cselib_lookup (rtx, machine_mode,
106 int, machine_mode);
107 extern cselib_val *cselib_lookup_from_insn (rtx, machine_mode,
108 int, machine_mode, rtx_insn *);
109 extern void cselib_init (int);
110 extern void cselib_clear_table (void);
111 extern void cselib_finish (void);
112 extern void cselib_process_insn (rtx_insn *);
113 extern bool fp_setter_insn (rtx_insn *);
114 extern machine_mode cselib_reg_set_mode (const_rtx);
115 extern int rtx_equal_for_cselib_p (rtx, rtx);
116 extern int references_value_p (const_rtx, int);
117 extern rtx cselib_expand_value_rtx (rtx, bitmap, int);
118 typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *);
119 extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int,
120 cselib_expand_callback, void *);
121 extern bool cselib_dummy_expand_value_rtx_cb (rtx, bitmap, int,
122 cselib_expand_callback, void *);
123 extern rtx cselib_subst_to_values (rtx, machine_mode);
124 extern rtx cselib_subst_to_values_from_insn (rtx, machine_mode, rtx_insn *);
125 extern void cselib_invalidate_rtx (rtx);
127 extern void cselib_reset_table (unsigned int);
128 extern unsigned int cselib_get_next_uid (void);
129 extern void cselib_preserve_value (cselib_val *);
130 extern bool cselib_preserved_value_p (cselib_val *);
131 extern void cselib_preserve_only_values (void);
132 extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int);
133 extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx_insn *);
134 extern bool cselib_have_permanent_equivalences (void);
135 extern void cselib_set_value_sp_based (cselib_val *);
136 extern bool cselib_sp_based_value_p (cselib_val *);
138 extern void dump_cselib_table (FILE *);
140 /* Return the canonical value for VAL, following the equivalence chain
141 towards the earliest (== lowest uid) equivalent value. */
143 static inline cselib_val *
144 canonical_cselib_val (cselib_val *val)
146 cselib_val *canon;
148 if (!val->locs || val->locs->next
149 || !val->locs->loc || GET_CODE (val->locs->loc) != VALUE
150 || val->uid < CSELIB_VAL_PTR (val->locs->loc)->uid)
151 return val;
153 canon = CSELIB_VAL_PTR (val->locs->loc);
154 gcc_checking_assert (canonical_cselib_val (canon) == canon);
155 return canon;
158 #endif /* GCC_CSELIB_H */