OSDN Git Service

5bf6023d8760bb82e02529b96d8154ecc18b2f78
[pf3gnuchains/gcc-fork.git] / gcc / lists.c
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.
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>.  */
21
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"
30
31 static void free_list (rtx *, rtx *);
32
33 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs.  */
34
35 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused.  */
36 static GTY ((deletable)) rtx unused_insn_list;
37
38 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused.  */
39 static GTY ((deletable)) rtx unused_expr_list;
40
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)
47 {
48   rtx link, prev_link;
49
50   prev_link = *listp;
51   link = XEXP (prev_link, 1);
52
53   gcc_assert (unused_listp != &unused_insn_list
54               || GET_CODE (prev_link) == INSN_LIST);
55
56   while (link)
57     {
58       gcc_assert (unused_listp != &unused_insn_list
59                   || GET_CODE (prev_link) == INSN_LIST);
60
61       prev_link = link;
62       link = XEXP (link, 1);
63     }
64
65   XEXP (prev_link, 1) = *unused_listp;
66   *unused_listp = *listp;
67   *listp = 0;
68 }
69
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)
74 {
75   while (XEXP (*listp, 0) != elem)
76     listp = &XEXP (*listp, 1);
77   return listp;
78 }
79
80 /* Remove the node pointed to by LISTP from the list.  */
81 static void
82 remove_list_node (rtx *listp)
83 {
84   rtx node;
85
86   node = *listp;
87   *listp = XEXP (node, 1);
88   XEXP (node, 1) = 0;
89 }
90
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)
95 {
96   rtx node;
97
98   listp = find_list_elem (elem, listp);
99   node = *listp;
100   remove_list_node (listp);
101   return node;
102 }
103
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.  */
107 rtx
108 alloc_INSN_LIST (rtx val, rtx next)
109 {
110   rtx r;
111
112   if (unused_insn_list)
113     {
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);
119
120       gcc_assert (GET_CODE (r) == INSN_LIST);
121     }
122   else
123     r = gen_rtx_INSN_LIST (VOIDmode, val, next);
124
125   return r;
126 }
127
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.  */
131 rtx
132 alloc_EXPR_LIST (int kind, rtx val, rtx next)
133 {
134   rtx r;
135
136   if (unused_expr_list)
137     {
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);
143     }
144   else
145     r = gen_rtx_EXPR_LIST ((enum machine_mode) kind, val, next);
146
147   return r;
148 }
149
150 /* This function will free up an entire list of EXPR_LIST nodes.  */
151 void
152 free_EXPR_LIST_list (rtx *listp)
153 {
154   if (*listp == 0)
155     return;
156   free_list (listp, &unused_expr_list);
157 }
158
159 /* This function will free up an entire list of INSN_LIST nodes.  */
160 void
161 free_INSN_LIST_list (rtx *listp)
162 {
163   if (*listp == 0)
164     return;
165   free_list (listp, &unused_insn_list);
166 }
167
168 /* This function will free up an individual EXPR_LIST node.  */
169 void
170 free_EXPR_LIST_node (rtx ptr)
171 {
172   XEXP (ptr, 1) = unused_expr_list;
173   unused_expr_list = ptr;
174 }
175
176 /* This function will free up an individual INSN_LIST node.  */
177 void
178 free_INSN_LIST_node (rtx ptr)
179 {
180   gcc_assert (GET_CODE (ptr) == INSN_LIST);
181   XEXP (ptr, 1) = unused_insn_list;
182   unused_insn_list = ptr;
183 }
184
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)
189 {
190   free_INSN_LIST_node (remove_list_elem (elem, listp));
191 }
192
193 /* Remove and free the first node in the INSN_LIST pointed to by LISTP.  */
194 rtx
195 remove_free_INSN_LIST_node (rtx *listp)
196 {
197   rtx node = *listp;
198   rtx elem = XEXP (node, 0);
199
200   remove_list_node (listp);
201   free_INSN_LIST_node (node);
202
203   return elem;
204 }
205
206 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP.  */
207 rtx
208 remove_free_EXPR_LIST_node (rtx *listp)
209 {
210   rtx node = *listp;
211   rtx elem = XEXP (node, 0);
212
213   remove_list_node (listp);
214   free_EXPR_LIST_node (node);
215
216   return elem;
217 }
218
219 #include "gt-lists.h"