Line data Source code
1 : /* List management for the GCC expander.
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 : #include "config.h"
21 : #include "system.h"
22 : #include "coretypes.h"
23 : #include "tm.h"
24 : #include "rtl.h"
25 :
26 : /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
27 :
28 : /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
29 : static GTY ((deletable)) rtx unused_insn_list;
30 :
31 : /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
32 : static GTY ((deletable)) rtx unused_expr_list;
33 :
34 : /* This function will free an entire list of either EXPR_LIST, INSN_LIST
35 : or DEPS_LIST nodes. This is to be used only on lists that consist
36 : exclusively of nodes of one type only. This is only called by
37 : free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
38 : template <typename T>
39 : static void
40 880055222 : free_list (T **listp, rtx *unused_listp)
41 : {
42 : rtx link, prev_link;
43 :
44 880055222 : prev_link = *listp;
45 880055222 : link = XEXP (prev_link, 1);
46 :
47 880055222 : gcc_assert (unused_listp != &unused_insn_list
48 : || GET_CODE (prev_link) == INSN_LIST);
49 :
50 1082133728 : while (link)
51 : {
52 202078506 : gcc_assert (unused_listp != &unused_insn_list
53 : || GET_CODE (prev_link) == INSN_LIST);
54 :
55 202078506 : prev_link = link;
56 202078506 : link = XEXP (link, 1);
57 : }
58 :
59 880055222 : XEXP (prev_link, 1) = *unused_listp;
60 880055222 : *unused_listp = *listp;
61 880055222 : *listp = 0;
62 880055222 : }
63 :
64 : /* Find corresponding to ELEM node in the list pointed to by LISTP.
65 : This node must exist in the list. Returns pointer to that node. */
66 : static rtx *
67 139374 : find_list_elem (rtx elem, rtx *listp)
68 : {
69 206399 : while (XEXP (*listp, 0) != elem)
70 67025 : listp = &XEXP (*listp, 1);
71 139374 : return listp;
72 : }
73 :
74 : /* Remove the node pointed to by LISTP from the list. */
75 : static void
76 139374 : remove_list_node (rtx *listp)
77 : {
78 139374 : rtx node;
79 :
80 139374 : node = *listp;
81 139374 : *listp = XEXP (node, 1);
82 139374 : XEXP (node, 1) = 0;
83 0 : }
84 :
85 : /* Removes corresponding to ELEM node from the list pointed to by LISTP.
86 : Returns that node. */
87 : rtx
88 139374 : remove_list_elem (rtx elem, rtx *listp)
89 : {
90 139374 : rtx node;
91 :
92 139374 : listp = find_list_elem (elem, listp);
93 139374 : node = *listp;
94 139374 : remove_list_node (listp);
95 139374 : return node;
96 : }
97 :
98 : /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
99 : node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
100 : is made. */
101 : rtx_insn_list *
102 1061094004 : alloc_INSN_LIST (rtx val, rtx next)
103 : {
104 1061094004 : rtx_insn_list *r;
105 :
106 1061094004 : if (unused_insn_list)
107 : {
108 1007441977 : r = as_a <rtx_insn_list *> (unused_insn_list);
109 1007441977 : unused_insn_list = r->next ();
110 1007441977 : XEXP (r, 0) = val;
111 1007441977 : XEXP (r, 1) = next;
112 1007441977 : PUT_REG_NOTE_KIND (r, VOIDmode);
113 :
114 1007441977 : gcc_assert (GET_CODE (r) == INSN_LIST);
115 : }
116 : else
117 53652027 : r = gen_rtx_INSN_LIST (VOIDmode, val, next);
118 :
119 1061094004 : return r;
120 : }
121 :
122 : /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
123 : node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
124 : is made. */
125 : rtx_expr_list *
126 833718469 : alloc_EXPR_LIST (int kind, rtx val, rtx next)
127 : {
128 833718469 : rtx_expr_list *r;
129 :
130 833718469 : if (unused_expr_list)
131 : {
132 642133037 : r = as_a <rtx_expr_list *> (unused_expr_list);
133 642133037 : unused_expr_list = XEXP (r, 1);
134 642133037 : XEXP (r, 0) = val;
135 642133037 : XEXP (r, 1) = next;
136 642133037 : PUT_REG_NOTE_KIND (r, kind);
137 : }
138 : else
139 191585432 : r = gen_rtx_EXPR_LIST ((machine_mode) kind, val, next);
140 :
141 833718469 : return r;
142 : }
143 :
144 : /* This function will free up an entire list of EXPR_LIST nodes. */
145 : void
146 62508205 : free_EXPR_LIST_list (rtx_expr_list **listp)
147 : {
148 62508205 : if (*listp == 0)
149 : return;
150 15011250 : free_list (listp, &unused_expr_list);
151 : }
152 :
153 : /* This function will free up an entire list of INSN_LIST nodes. */
154 : void
155 1924605876 : free_INSN_LIST_list (rtx_insn_list **listp)
156 : {
157 1924605876 : if (*listp == 0)
158 : return;
159 865043972 : free_list (listp, &unused_insn_list);
160 : }
161 :
162 : /* Make a copy of the INSN_LIST list LINK and return it. */
163 : rtx_insn_list *
164 2312 : copy_INSN_LIST (rtx_insn_list *link)
165 : {
166 2312 : rtx new_queue;
167 2312 : rtx *pqueue = &new_queue;
168 :
169 4631 : for (; link; link = link->next ())
170 : {
171 2319 : rtx_insn *x = link->insn ();
172 2319 : rtx_insn_list *newlink = alloc_INSN_LIST (x, NULL);
173 2319 : *pqueue = newlink;
174 2319 : pqueue = &XEXP (newlink, 1);
175 : }
176 2312 : *pqueue = NULL;
177 2312 : return safe_as_a <rtx_insn_list *> (new_queue);
178 : }
179 :
180 : /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */
181 : rtx_insn_list *
182 85598 : concat_INSN_LIST (rtx_insn_list *copy, rtx_insn_list *old)
183 : {
184 85598 : rtx_insn_list *new_rtx = old;
185 128187 : for (; copy ; copy = copy->next ())
186 : {
187 42589 : new_rtx = alloc_INSN_LIST (copy->insn (), new_rtx);
188 42589 : PUT_REG_NOTE_KIND (new_rtx, REG_NOTE_KIND (copy));
189 : }
190 85598 : return new_rtx;
191 : }
192 :
193 : /* This function will free up an individual EXPR_LIST node. */
194 : void
195 603135545 : free_EXPR_LIST_node (rtx ptr)
196 : {
197 603135545 : XEXP (ptr, 1) = unused_expr_list;
198 603135545 : unused_expr_list = ptr;
199 603135545 : }
200 :
201 : /* This function will free up an individual INSN_LIST node. */
202 : void
203 153319 : free_INSN_LIST_node (rtx ptr)
204 : {
205 153319 : gcc_assert (GET_CODE (ptr) == INSN_LIST);
206 153319 : XEXP (ptr, 1) = unused_insn_list;
207 153319 : unused_insn_list = ptr;
208 153319 : }
209 :
210 : /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
211 : by LISTP. */
212 : void
213 139374 : remove_free_INSN_LIST_elem (rtx_insn *elem, rtx_insn_list **listp)
214 : {
215 139374 : rtx list = *listp;
216 139374 : free_INSN_LIST_node (remove_list_elem (elem, &list));
217 139374 : *listp = safe_as_a <rtx_insn_list *> (list);
218 139374 : }
219 :
220 : /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
221 : rtx_insn *
222 13940 : remove_free_INSN_LIST_node (rtx_insn_list **listp)
223 : {
224 13940 : rtx_insn_list *node = *listp;
225 13940 : rtx_insn *elem = node->insn ();
226 :
227 13940 : *listp = node->next ();
228 13940 : free_INSN_LIST_node (node);
229 :
230 13940 : return elem;
231 : }
232 :
233 : /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
234 : rtx
235 660 : remove_free_EXPR_LIST_node (rtx_expr_list **listp)
236 : {
237 660 : rtx_expr_list *node = *listp;
238 660 : rtx elem = XEXP (node, 0);
239 :
240 660 : *listp = node->next ();
241 660 : free_EXPR_LIST_node (node);
242 :
243 660 : return elem;
244 : }
245 :
246 : #include "gt-lists.h"
|