2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / gcc / lists.c
blob5bf6023d8760bb82e02529b96d8154ecc18b2f78
1 /* List management for the GCC expander.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "diagnostic-core.h"
27 #include "toplev.h"
28 #include "rtl.h"
29 #include "ggc.h"
31 static void free_list (rtx *, rtx *);
33 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
35 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
36 static GTY ((deletable)) rtx unused_insn_list;
38 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
39 static GTY ((deletable)) rtx unused_expr_list;
41 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
42 or DEPS_LIST nodes. This is to be used only on lists that consist
43 exclusively of nodes of one type only. This is only called by
44 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
45 static void
46 free_list (rtx *listp, rtx *unused_listp)
48 rtx link, prev_link;
50 prev_link = *listp;
51 link = XEXP (prev_link, 1);
53 gcc_assert (unused_listp != &unused_insn_list
54 || GET_CODE (prev_link) == INSN_LIST);
56 while (link)
58 gcc_assert (unused_listp != &unused_insn_list
59 || GET_CODE (prev_link) == INSN_LIST);
61 prev_link = link;
62 link = XEXP (link, 1);
65 XEXP (prev_link, 1) = *unused_listp;
66 *unused_listp = *listp;
67 *listp = 0;
70 /* Find corresponding to ELEM node in the list pointed to by LISTP.
71 This node must exist in the list. Returns pointer to that node. */
72 static rtx *
73 find_list_elem (rtx elem, rtx *listp)
75 while (XEXP (*listp, 0) != elem)
76 listp = &XEXP (*listp, 1);
77 return listp;
80 /* Remove the node pointed to by LISTP from the list. */
81 static void
82 remove_list_node (rtx *listp)
84 rtx node;
86 node = *listp;
87 *listp = XEXP (node, 1);
88 XEXP (node, 1) = 0;
91 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
92 Returns that node. */
93 rtx
94 remove_list_elem (rtx elem, rtx *listp)
96 rtx node;
98 listp = find_list_elem (elem, listp);
99 node = *listp;
100 remove_list_node (listp);
101 return node;
104 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
105 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
106 is made. */
108 alloc_INSN_LIST (rtx val, rtx next)
110 rtx r;
112 if (unused_insn_list)
114 r = unused_insn_list;
115 unused_insn_list = XEXP (r, 1);
116 XEXP (r, 0) = val;
117 XEXP (r, 1) = next;
118 PUT_REG_NOTE_KIND (r, VOIDmode);
120 gcc_assert (GET_CODE (r) == INSN_LIST);
122 else
123 r = gen_rtx_INSN_LIST (VOIDmode, val, next);
125 return r;
128 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
129 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
130 is made. */
132 alloc_EXPR_LIST (int kind, rtx val, rtx next)
134 rtx r;
136 if (unused_expr_list)
138 r = unused_expr_list;
139 unused_expr_list = XEXP (r, 1);
140 XEXP (r, 0) = val;
141 XEXP (r, 1) = next;
142 PUT_REG_NOTE_KIND (r, kind);
144 else
145 r = gen_rtx_EXPR_LIST ((enum machine_mode) kind, val, next);
147 return r;
150 /* This function will free up an entire list of EXPR_LIST nodes. */
151 void
152 free_EXPR_LIST_list (rtx *listp)
154 if (*listp == 0)
155 return;
156 free_list (listp, &unused_expr_list);
159 /* This function will free up an entire list of INSN_LIST nodes. */
160 void
161 free_INSN_LIST_list (rtx *listp)
163 if (*listp == 0)
164 return;
165 free_list (listp, &unused_insn_list);
168 /* This function will free up an individual EXPR_LIST node. */
169 void
170 free_EXPR_LIST_node (rtx ptr)
172 XEXP (ptr, 1) = unused_expr_list;
173 unused_expr_list = ptr;
176 /* This function will free up an individual INSN_LIST node. */
177 void
178 free_INSN_LIST_node (rtx ptr)
180 gcc_assert (GET_CODE (ptr) == INSN_LIST);
181 XEXP (ptr, 1) = unused_insn_list;
182 unused_insn_list = ptr;
185 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
186 by LISTP. */
187 void
188 remove_free_INSN_LIST_elem (rtx elem, rtx *listp)
190 free_INSN_LIST_node (remove_list_elem (elem, listp));
193 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
195 remove_free_INSN_LIST_node (rtx *listp)
197 rtx node = *listp;
198 rtx elem = XEXP (node, 0);
200 remove_list_node (listp);
201 free_INSN_LIST_node (node);
203 return elem;
206 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
208 remove_free_EXPR_LIST_node (rtx *listp)
210 rtx node = *listp;
211 rtx elem = XEXP (node, 0);
213 remove_list_node (listp);
214 free_EXPR_LIST_node (node);
216 return elem;
219 #include "gt-lists.h"