always define DYNAMIC_CHAIN_ADDRESS
[official-gcc.git] / gcc / lists.c
blob1e1fd32794897afe2d8463777afcd3985f4efe8e
1 /* List management for the GCC expander.
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 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "diagnostic-core.h"
25 #include "rtl.h"
27 static void free_list (rtx *, rtx *);
29 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
31 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
32 static GTY ((deletable)) rtx unused_insn_list;
34 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
35 static GTY ((deletable)) rtx unused_expr_list;
37 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
38 or DEPS_LIST nodes. This is to be used only on lists that consist
39 exclusively of nodes of one type only. This is only called by
40 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
41 static void
42 free_list (rtx *listp, rtx *unused_listp)
44 rtx link, prev_link;
46 prev_link = *listp;
47 link = XEXP (prev_link, 1);
49 gcc_assert (unused_listp != &unused_insn_list
50 || GET_CODE (prev_link) == INSN_LIST);
52 while (link)
54 gcc_assert (unused_listp != &unused_insn_list
55 || GET_CODE (prev_link) == INSN_LIST);
57 prev_link = link;
58 link = XEXP (link, 1);
61 XEXP (prev_link, 1) = *unused_listp;
62 *unused_listp = *listp;
63 *listp = 0;
66 /* Find corresponding to ELEM node in the list pointed to by LISTP.
67 This node must exist in the list. Returns pointer to that node. */
68 static rtx *
69 find_list_elem (rtx elem, rtx *listp)
71 while (XEXP (*listp, 0) != elem)
72 listp = &XEXP (*listp, 1);
73 return listp;
76 /* Remove the node pointed to by LISTP from the list. */
77 static void
78 remove_list_node (rtx *listp)
80 rtx node;
82 node = *listp;
83 *listp = XEXP (node, 1);
84 XEXP (node, 1) = 0;
87 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
88 Returns that node. */
89 rtx
90 remove_list_elem (rtx elem, rtx *listp)
92 rtx node;
94 listp = find_list_elem (elem, listp);
95 node = *listp;
96 remove_list_node (listp);
97 return node;
100 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
101 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
102 is made. */
103 rtx_insn_list *
104 alloc_INSN_LIST (rtx val, rtx next)
106 rtx_insn_list *r;
108 if (unused_insn_list)
110 r = as_a <rtx_insn_list *> (unused_insn_list);
111 unused_insn_list = r->next ();
112 XEXP (r, 0) = val;
113 XEXP (r, 1) = next;
114 PUT_REG_NOTE_KIND (r, VOIDmode);
116 gcc_assert (GET_CODE (r) == INSN_LIST);
118 else
119 r = gen_rtx_INSN_LIST (VOIDmode, val, next);
121 return r;
124 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
125 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
126 is made. */
127 rtx_expr_list *
128 alloc_EXPR_LIST (int kind, rtx val, rtx next)
130 rtx_expr_list *r;
132 if (unused_expr_list)
134 r = as_a <rtx_expr_list *> (unused_expr_list);
135 unused_expr_list = XEXP (r, 1);
136 XEXP (r, 0) = val;
137 XEXP (r, 1) = next;
138 PUT_REG_NOTE_KIND (r, kind);
140 else
141 r = gen_rtx_EXPR_LIST ((machine_mode) kind, val, next);
143 return r;
146 /* This function will free up an entire list of EXPR_LIST nodes. */
147 void
148 free_EXPR_LIST_list (rtx_expr_list **listp)
150 if (*listp == 0)
151 return;
152 free_list ((rtx *)listp, &unused_expr_list);
155 /* This function will free up an entire list of INSN_LIST nodes. */
156 void
157 free_INSN_LIST_list (rtx_insn_list **listp)
159 if (*listp == 0)
160 return;
161 free_list ((rtx *)listp, &unused_insn_list);
164 /* Make a copy of the INSN_LIST list LINK and return it. */
165 rtx_insn_list *
166 copy_INSN_LIST (rtx_insn_list *link)
168 rtx_insn_list *new_queue;
169 rtx_insn_list **pqueue = &new_queue;
171 for (; link; link = link->next ())
173 rtx_insn *x = link->insn ();
174 rtx_insn_list *newlink = alloc_INSN_LIST (x, NULL);
175 *pqueue = newlink;
176 pqueue = (rtx_insn_list **)&XEXP (newlink, 1);
178 *pqueue = NULL;
179 return new_queue;
182 /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */
183 rtx_insn_list *
184 concat_INSN_LIST (rtx_insn_list *copy, rtx_insn_list *old)
186 rtx_insn_list *new_rtx = old;
187 for (; copy ; copy = copy->next ())
189 new_rtx = alloc_INSN_LIST (copy->insn (), new_rtx);
190 PUT_REG_NOTE_KIND (new_rtx, REG_NOTE_KIND (copy));
192 return new_rtx;
195 /* This function will free up an individual EXPR_LIST node. */
196 void
197 free_EXPR_LIST_node (rtx ptr)
199 XEXP (ptr, 1) = unused_expr_list;
200 unused_expr_list = ptr;
203 /* This function will free up an individual INSN_LIST node. */
204 void
205 free_INSN_LIST_node (rtx ptr)
207 gcc_assert (GET_CODE (ptr) == INSN_LIST);
208 XEXP (ptr, 1) = unused_insn_list;
209 unused_insn_list = ptr;
212 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
213 by LISTP. */
214 void
215 remove_free_INSN_LIST_elem (rtx_insn *elem, rtx_insn_list **listp)
217 free_INSN_LIST_node (remove_list_elem (elem, (rtx *)listp));
220 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
221 rtx_insn *
222 remove_free_INSN_LIST_node (rtx_insn_list **listp)
224 rtx_insn_list *node = *listp;
225 rtx_insn *elem = node->insn ();
227 remove_list_node ((rtx *)listp);
228 free_INSN_LIST_node (node);
230 return elem;
233 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
235 remove_free_EXPR_LIST_node (rtx_expr_list **listp)
237 rtx_expr_list *node = *listp;
238 rtx elem = XEXP (node, 0);
240 remove_list_node ((rtx *)listp);
241 free_EXPR_LIST_node (node);
243 return elem;
246 #include "gt-lists.h"