]>
Commit | Line | Data |
---|---|---|
5e6908ea | 1 | /* List management for the GCC expander. |
8d9254fc | 2 | Copyright (C) 1987-2020 Free Software Foundation, Inc. |
5a4f6418 | 3 | |
1322177d | 4 | This file is part of GCC. |
5a4f6418 | 5 | |
1322177d LB |
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 | |
9dcd6f09 | 8 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 9 | version. |
5a4f6418 | 10 | |
1322177d LB |
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. | |
5a4f6418 AM |
15 | |
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
5a4f6418 AM |
19 | |
20 | #include "config.h" | |
21 | #include "system.h" | |
4977bab6 ZW |
22 | #include "coretypes.h" |
23 | #include "tm.h" | |
5a4f6418 AM |
24 | #include "rtl.h" |
25 | ||
3d7aafde | 26 | static void free_list (rtx *, rtx *); |
ca3075bd | 27 | |
5a4f6418 AM |
28 | /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */ |
29 | ||
30 | /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */ | |
1431042e | 31 | static GTY ((deletable)) rtx unused_insn_list; |
5a4f6418 AM |
32 | |
33 | /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */ | |
1431042e | 34 | static GTY ((deletable)) rtx unused_expr_list; |
5a4f6418 | 35 | |
ddbd5439 MK |
36 | /* This function will free an entire list of either EXPR_LIST, INSN_LIST |
37 | or DEPS_LIST nodes. This is to be used only on lists that consist | |
38 | exclusively of nodes of one type only. This is only called by | |
39 | free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */ | |
5a4f6418 | 40 | static void |
3d7aafde | 41 | free_list (rtx *listp, rtx *unused_listp) |
5a4f6418 | 42 | { |
b3694847 | 43 | rtx link, prev_link; |
5a4f6418 AM |
44 | |
45 | prev_link = *listp; | |
46 | link = XEXP (prev_link, 1); | |
47 | ||
b198261f MK |
48 | gcc_assert (unused_listp != &unused_insn_list |
49 | || GET_CODE (prev_link) == INSN_LIST); | |
b8698a0f | 50 | |
5a4f6418 AM |
51 | while (link) |
52 | { | |
b198261f MK |
53 | gcc_assert (unused_listp != &unused_insn_list |
54 | || GET_CODE (prev_link) == INSN_LIST); | |
b8698a0f | 55 | |
5a4f6418 AM |
56 | prev_link = link; |
57 | link = XEXP (link, 1); | |
58 | } | |
59 | ||
60 | XEXP (prev_link, 1) = *unused_listp; | |
61 | *unused_listp = *listp; | |
62 | *listp = 0; | |
63 | } | |
64 | ||
ddbd5439 MK |
65 | /* Find corresponding to ELEM node in the list pointed to by LISTP. |
66 | This node must exist in the list. Returns pointer to that node. */ | |
67 | static rtx * | |
68 | find_list_elem (rtx elem, rtx *listp) | |
69 | { | |
70 | while (XEXP (*listp, 0) != elem) | |
71 | listp = &XEXP (*listp, 1); | |
72 | return listp; | |
73 | } | |
74 | ||
75 | /* Remove the node pointed to by LISTP from the list. */ | |
76 | static void | |
77 | remove_list_node (rtx *listp) | |
78 | { | |
79 | rtx node; | |
80 | ||
81 | node = *listp; | |
82 | *listp = XEXP (node, 1); | |
83 | XEXP (node, 1) = 0; | |
84 | } | |
85 | ||
86 | /* Removes corresponding to ELEM node from the list pointed to by LISTP. | |
87 | Returns that node. */ | |
63f54b1a | 88 | rtx |
ddbd5439 MK |
89 | remove_list_elem (rtx elem, rtx *listp) |
90 | { | |
91 | rtx node; | |
92 | ||
93 | listp = find_list_elem (elem, listp); | |
94 | node = *listp; | |
95 | remove_list_node (listp); | |
96 | return node; | |
97 | } | |
98 | ||
5a4f6418 | 99 | /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached |
e11e816e | 100 | node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST |
5a4f6418 | 101 | is made. */ |
3dc99c19 | 102 | rtx_insn_list * |
3d7aafde | 103 | alloc_INSN_LIST (rtx val, rtx next) |
5a4f6418 | 104 | { |
3dc99c19 | 105 | rtx_insn_list *r; |
5a4f6418 AM |
106 | |
107 | if (unused_insn_list) | |
108 | { | |
3dc99c19 DM |
109 | r = as_a <rtx_insn_list *> (unused_insn_list); |
110 | unused_insn_list = r->next (); | |
5a4f6418 AM |
111 | XEXP (r, 0) = val; |
112 | XEXP (r, 1) = next; | |
113 | PUT_REG_NOTE_KIND (r, VOIDmode); | |
ddbd5439 MK |
114 | |
115 | gcc_assert (GET_CODE (r) == INSN_LIST); | |
5a4f6418 AM |
116 | } |
117 | else | |
118 | r = gen_rtx_INSN_LIST (VOIDmode, val, next); | |
119 | ||
120 | return r; | |
121 | } | |
122 | ||
123 | /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached | |
e11e816e | 124 | node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST |
5a4f6418 | 125 | is made. */ |
2f33ff0a | 126 | rtx_expr_list * |
3d7aafde | 127 | alloc_EXPR_LIST (int kind, rtx val, rtx next) |
5a4f6418 | 128 | { |
2f33ff0a | 129 | rtx_expr_list *r; |
5a4f6418 AM |
130 | |
131 | if (unused_expr_list) | |
132 | { | |
2f33ff0a | 133 | r = as_a <rtx_expr_list *> (unused_expr_list); |
5a4f6418 AM |
134 | unused_expr_list = XEXP (r, 1); |
135 | XEXP (r, 0) = val; | |
136 | XEXP (r, 1) = next; | |
137 | PUT_REG_NOTE_KIND (r, kind); | |
138 | } | |
139 | else | |
ef4bddc2 | 140 | r = gen_rtx_EXPR_LIST ((machine_mode) kind, val, next); |
5a4f6418 AM |
141 | |
142 | return r; | |
143 | } | |
144 | ||
5a4f6418 | 145 | /* This function will free up an entire list of EXPR_LIST nodes. */ |
e11e816e | 146 | void |
2f33ff0a | 147 | free_EXPR_LIST_list (rtx_expr_list **listp) |
5a4f6418 AM |
148 | { |
149 | if (*listp == 0) | |
150 | return; | |
2f33ff0a | 151 | free_list ((rtx *)listp, &unused_expr_list); |
5a4f6418 AM |
152 | } |
153 | ||
154 | /* This function will free up an entire list of INSN_LIST nodes. */ | |
e11e816e | 155 | void |
3dc99c19 | 156 | free_INSN_LIST_list (rtx_insn_list **listp) |
5a4f6418 AM |
157 | { |
158 | if (*listp == 0) | |
159 | return; | |
3dc99c19 | 160 | free_list ((rtx *)listp, &unused_insn_list); |
5a4f6418 AM |
161 | } |
162 | ||
e2724e63 | 163 | /* Make a copy of the INSN_LIST list LINK and return it. */ |
3dc99c19 DM |
164 | rtx_insn_list * |
165 | copy_INSN_LIST (rtx_insn_list *link) | |
e2724e63 | 166 | { |
3dc99c19 DM |
167 | rtx_insn_list *new_queue; |
168 | rtx_insn_list **pqueue = &new_queue; | |
e2724e63 | 169 | |
3dc99c19 | 170 | for (; link; link = link->next ()) |
e2724e63 | 171 | { |
3dc99c19 DM |
172 | rtx_insn *x = link->insn (); |
173 | rtx_insn_list *newlink = alloc_INSN_LIST (x, NULL); | |
e2724e63 | 174 | *pqueue = newlink; |
3dc99c19 | 175 | pqueue = (rtx_insn_list **)&XEXP (newlink, 1); |
e2724e63 | 176 | } |
3dc99c19 | 177 | *pqueue = NULL; |
e2724e63 BS |
178 | return new_queue; |
179 | } | |
180 | ||
181 | /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */ | |
3dc99c19 DM |
182 | rtx_insn_list * |
183 | concat_INSN_LIST (rtx_insn_list *copy, rtx_insn_list *old) | |
e2724e63 | 184 | { |
3dc99c19 DM |
185 | rtx_insn_list *new_rtx = old; |
186 | for (; copy ; copy = copy->next ()) | |
e2724e63 | 187 | { |
3dc99c19 | 188 | new_rtx = alloc_INSN_LIST (copy->insn (), new_rtx); |
e2724e63 BS |
189 | PUT_REG_NOTE_KIND (new_rtx, REG_NOTE_KIND (copy)); |
190 | } | |
191 | return new_rtx; | |
192 | } | |
193 | ||
5a4f6418 | 194 | /* This function will free up an individual EXPR_LIST node. */ |
e11e816e | 195 | void |
3d7aafde | 196 | free_EXPR_LIST_node (rtx ptr) |
5a4f6418 AM |
197 | { |
198 | XEXP (ptr, 1) = unused_expr_list; | |
199 | unused_expr_list = ptr; | |
200 | } | |
201 | ||
202 | /* This function will free up an individual INSN_LIST node. */ | |
e11e816e | 203 | void |
3d7aafde | 204 | free_INSN_LIST_node (rtx ptr) |
5a4f6418 | 205 | { |
ddbd5439 | 206 | gcc_assert (GET_CODE (ptr) == INSN_LIST); |
5a4f6418 AM |
207 | XEXP (ptr, 1) = unused_insn_list; |
208 | unused_insn_list = ptr; | |
209 | } | |
e2500fed | 210 | |
63f54b1a MK |
211 | /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to |
212 | by LISTP. */ | |
213 | void | |
3dc99c19 | 214 | remove_free_INSN_LIST_elem (rtx_insn *elem, rtx_insn_list **listp) |
63f54b1a | 215 | { |
3dc99c19 | 216 | free_INSN_LIST_node (remove_list_elem (elem, (rtx *)listp)); |
63f54b1a MK |
217 | } |
218 | ||
e855c69d | 219 | /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */ |
3dc99c19 DM |
220 | rtx_insn * |
221 | remove_free_INSN_LIST_node (rtx_insn_list **listp) | |
e855c69d | 222 | { |
3dc99c19 DM |
223 | rtx_insn_list *node = *listp; |
224 | rtx_insn *elem = node->insn (); | |
e855c69d | 225 | |
3dc99c19 | 226 | remove_list_node ((rtx *)listp); |
e855c69d AB |
227 | free_INSN_LIST_node (node); |
228 | ||
229 | return elem; | |
230 | } | |
231 | ||
232 | /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */ | |
233 | rtx | |
2f33ff0a | 234 | remove_free_EXPR_LIST_node (rtx_expr_list **listp) |
e855c69d | 235 | { |
2f33ff0a | 236 | rtx_expr_list *node = *listp; |
e855c69d AB |
237 | rtx elem = XEXP (node, 0); |
238 | ||
2f33ff0a | 239 | remove_list_node ((rtx *)listp); |
e855c69d AB |
240 | free_EXPR_LIST_node (node); |
241 | ||
242 | return elem; | |
243 | } | |
244 | ||
e2500fed | 245 | #include "gt-lists.h" |