Line data Source code
1 : /* Common subexpression elimination for GNU compiler.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
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.
10 :
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.
15 :
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/>. */
19 :
20 : #ifndef GCC_CSELIB_H
21 : #define GCC_CSELIB_H
22 :
23 : /* Describe a value. */
24 : struct cselib_val
25 : {
26 : /* A mask equivalent of HASH's bitfield width. */
27 : static const unsigned int HASH_MASK = 0x3fffffff;
28 :
29 : /* The hash value. */
30 : unsigned int hash : 30;
31 :
32 : /* True if this value is entered in cselib_preserved_hash_table. */
33 : unsigned int in_preserved_table_p : 1;
34 :
35 : /* True if every value referenced by every element of LOCS is known
36 : to be a preserved value. */
37 : unsigned int all_locs_preserved_p : 1;
38 :
39 : /* A unique id assigned to values. */
40 : int uid;
41 :
42 : /* A VALUE rtx that points back to this structure. */
43 : rtx val_rtx;
44 :
45 : /* All rtl expressions that hold this value at the current time during a
46 : scan. */
47 : struct elt_loc_list *locs;
48 :
49 : /* If this value is used as an address, points to a list of values that
50 : use it as an address in a MEM. */
51 : struct elt_list *addr_list;
52 :
53 : struct cselib_val *next_containing_mem;
54 : };
55 :
56 : /* A list of rtl expressions that hold the same value. */
57 : struct elt_loc_list {
58 : /* Next element in the list. */
59 : struct elt_loc_list *next;
60 : /* An rtl expression that holds the value. */
61 : rtx loc;
62 : /* The insn that made the equivalence. */
63 : rtx_insn *setting_insn;
64 : };
65 :
66 : /* Describe a single set that is part of an insn. */
67 : struct cselib_set
68 : {
69 : rtx src;
70 : rtx dest;
71 : cselib_val *src_elt;
72 : cselib_val *dest_addr_elt;
73 : };
74 :
75 : enum cselib_record_what
76 : {
77 : CSELIB_RECORD_MEMORY = 1,
78 : CSELIB_PRESERVE_CONSTANTS = 2
79 : };
80 :
81 : extern void (*cselib_discard_hook) (cselib_val *);
82 : extern void (*cselib_record_sets_hook) (rtx_insn *insn, struct cselib_set *sets,
83 : int n_sets);
84 :
85 : extern cselib_val *cselib_lookup (rtx, machine_mode,
86 : int, machine_mode);
87 : extern cselib_val *cselib_lookup_from_insn (rtx, machine_mode,
88 : int, machine_mode, rtx_insn *);
89 : extern void cselib_init (int);
90 : extern void cselib_clear_table (void);
91 : extern void cselib_finish (void);
92 : extern void cselib_process_insn (rtx_insn *);
93 : extern bool fp_setter_insn (rtx_insn *);
94 : extern machine_mode cselib_reg_set_mode (const_rtx);
95 : extern bool rtx_equal_for_cselib_1 (rtx, rtx, machine_mode, int);
96 : extern bool cselib_redundant_set_p (rtx);
97 : extern bool references_value_p (const_rtx);
98 : extern rtx cselib_expand_value_rtx (rtx, bitmap, int);
99 : typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *);
100 : extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int,
101 : cselib_expand_callback, void *);
102 : extern bool cselib_dummy_expand_value_rtx_cb (rtx, bitmap, int,
103 : cselib_expand_callback, void *);
104 : extern rtx cselib_subst_to_values (rtx, machine_mode);
105 : extern rtx cselib_subst_to_values_from_insn (rtx, machine_mode, rtx_insn *);
106 : extern void cselib_invalidate_rtx (rtx);
107 :
108 : extern void cselib_reset_table (unsigned int);
109 : extern unsigned int cselib_get_next_uid (void);
110 : extern void cselib_preserve_value (cselib_val *);
111 : extern bool cselib_preserved_value_p (cselib_val *);
112 : extern void cselib_preserve_only_values (void);
113 : extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int);
114 : extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx_insn *);
115 : extern bool cselib_have_permanent_equivalences (void);
116 : extern void cselib_set_value_sp_based (cselib_val *);
117 : extern bool cselib_sp_based_value_p (cselib_val *);
118 : extern void cselib_record_sp_cfa_base_equiv (HOST_WIDE_INT, rtx_insn *);
119 : extern bool cselib_sp_derived_value_p (cselib_val *);
120 :
121 : extern void dump_cselib_table (FILE *);
122 :
123 : /* Return the canonical value for VAL, following the equivalence chain
124 : towards the earliest (== lowest uid) equivalent value. */
125 :
126 : inline cselib_val *
127 2500772160 : canonical_cselib_val (cselib_val *val)
128 : {
129 2500772160 : cselib_val *canon;
130 :
131 2500772160 : if (!val->locs || val->locs->next
132 835744372 : || !val->locs->loc || GET_CODE (val->locs->loc) != VALUE
133 19939580 : || val->uid < CSELIB_VAL_PTR (val->locs->loc)->uid)
134 : return val;
135 :
136 19917454 : canon = CSELIB_VAL_PTR (val->locs->loc);
137 19917454 : gcc_checking_assert (canonical_cselib_val (canon) == canon);
138 : return canon;
139 : }
140 :
141 : /* Return true if we can prove that X and Y contain the same value, taking
142 : our gathered information into account. */
143 :
144 : inline bool
145 54570617 : rtx_equal_for_cselib_p (rtx x, rtx y)
146 : {
147 54570617 : if (x == y)
148 : return true;
149 :
150 54554927 : return rtx_equal_for_cselib_1 (x, y, VOIDmode, 0);
151 : }
152 :
153 : #endif /* GCC_CSELIB_H */
|