]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/lists.c
re PR target/37170 (gcc.dg/weak/weak-1.c)
[thirdparty/gcc.git] / gcc / lists.c
CommitLineData
5e6908ea 1/* List management for the GCC expander.
d050d723 2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
9dcd6f09 3 1999, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5a4f6418 4
1322177d 5This file is part of GCC.
5a4f6418 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
5a4f6418 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
5a4f6418
AM
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
5a4f6418
AM
20
21#include "config.h"
22#include "system.h"
4977bab6
ZW
23#include "coretypes.h"
24#include "tm.h"
5a4f6418
AM
25#include "toplev.h"
26#include "rtl.h"
7cf3d8b4 27#include "ggc.h"
5a4f6418 28
3d7aafde 29static void free_list (rtx *, rtx *);
ca3075bd 30
5a4f6418
AM
31/* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
32
33/* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
1431042e 34static GTY ((deletable)) rtx unused_insn_list;
5a4f6418
AM
35
36/* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
1431042e 37static GTY ((deletable)) rtx unused_expr_list;
5a4f6418 38
ddbd5439
MK
39/* This function will free an entire list of either EXPR_LIST, INSN_LIST
40 or DEPS_LIST nodes. This is to be used only on lists that consist
41 exclusively of nodes of one type only. This is only called by
42 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
5a4f6418 43static void
3d7aafde 44free_list (rtx *listp, rtx *unused_listp)
5a4f6418 45{
b3694847 46 rtx link, prev_link;
5a4f6418
AM
47
48 prev_link = *listp;
49 link = XEXP (prev_link, 1);
50
b198261f
MK
51 gcc_assert (unused_listp != &unused_insn_list
52 || GET_CODE (prev_link) == INSN_LIST);
ddbd5439 53
5a4f6418
AM
54 while (link)
55 {
b198261f
MK
56 gcc_assert (unused_listp != &unused_insn_list
57 || GET_CODE (prev_link) == INSN_LIST);
ddbd5439 58
5a4f6418
AM
59 prev_link = link;
60 link = XEXP (link, 1);
61 }
62
63 XEXP (prev_link, 1) = *unused_listp;
64 *unused_listp = *listp;
65 *listp = 0;
66}
67
ddbd5439
MK
68/* Find corresponding to ELEM node in the list pointed to by LISTP.
69 This node must exist in the list. Returns pointer to that node. */
70static rtx *
71find_list_elem (rtx elem, rtx *listp)
72{
73 while (XEXP (*listp, 0) != elem)
74 listp = &XEXP (*listp, 1);
75 return listp;
76}
77
78/* Remove the node pointed to by LISTP from the list. */
79static void
80remove_list_node (rtx *listp)
81{
82 rtx node;
83
84 node = *listp;
85 *listp = XEXP (node, 1);
86 XEXP (node, 1) = 0;
87}
88
89/* Removes corresponding to ELEM node from the list pointed to by LISTP.
90 Returns that node. */
63f54b1a 91rtx
ddbd5439
MK
92remove_list_elem (rtx elem, rtx *listp)
93{
94 rtx node;
95
96 listp = find_list_elem (elem, listp);
97 node = *listp;
98 remove_list_node (listp);
99 return node;
100}
101
5a4f6418 102/* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
e11e816e 103 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
5a4f6418
AM
104 is made. */
105rtx
3d7aafde 106alloc_INSN_LIST (rtx val, rtx next)
5a4f6418
AM
107{
108 rtx r;
109
110 if (unused_insn_list)
111 {
112 r = unused_insn_list;
113 unused_insn_list = XEXP (r, 1);
114 XEXP (r, 0) = val;
115 XEXP (r, 1) = next;
116 PUT_REG_NOTE_KIND (r, VOIDmode);
ddbd5439
MK
117
118 gcc_assert (GET_CODE (r) == INSN_LIST);
5a4f6418
AM
119 }
120 else
121 r = gen_rtx_INSN_LIST (VOIDmode, val, next);
122
123 return r;
124}
125
126/* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
e11e816e 127 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
5a4f6418
AM
128 is made. */
129rtx
3d7aafde 130alloc_EXPR_LIST (int kind, rtx val, rtx next)
5a4f6418
AM
131{
132 rtx r;
133
134 if (unused_expr_list)
135 {
136 r = unused_expr_list;
137 unused_expr_list = XEXP (r, 1);
138 XEXP (r, 0) = val;
139 XEXP (r, 1) = next;
140 PUT_REG_NOTE_KIND (r, kind);
141 }
142 else
143 r = gen_rtx_EXPR_LIST (kind, val, next);
144
145 return r;
146}
147
5a4f6418 148/* This function will free up an entire list of EXPR_LIST nodes. */
e11e816e 149void
3d7aafde 150free_EXPR_LIST_list (rtx *listp)
5a4f6418
AM
151{
152 if (*listp == 0)
153 return;
154 free_list (listp, &unused_expr_list);
155}
156
157/* This function will free up an entire list of INSN_LIST nodes. */
e11e816e 158void
3d7aafde 159free_INSN_LIST_list (rtx *listp)
5a4f6418
AM
160{
161 if (*listp == 0)
162 return;
163 free_list (listp, &unused_insn_list);
164}
165
166/* This function will free up an individual EXPR_LIST node. */
e11e816e 167void
3d7aafde 168free_EXPR_LIST_node (rtx ptr)
5a4f6418
AM
169{
170 XEXP (ptr, 1) = unused_expr_list;
171 unused_expr_list = ptr;
172}
173
174/* This function will free up an individual INSN_LIST node. */
e11e816e 175void
3d7aafde 176free_INSN_LIST_node (rtx ptr)
5a4f6418 177{
ddbd5439 178 gcc_assert (GET_CODE (ptr) == INSN_LIST);
5a4f6418
AM
179 XEXP (ptr, 1) = unused_insn_list;
180 unused_insn_list = ptr;
181}
e2500fed 182
63f54b1a
MK
183/* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
184 by LISTP. */
185void
186remove_free_INSN_LIST_elem (rtx elem, rtx *listp)
187{
188 free_INSN_LIST_node (remove_list_elem (elem, listp));
189}
190
e855c69d
AB
191/* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
192rtx
193remove_free_INSN_LIST_node (rtx *listp)
194{
195 rtx node = *listp;
196 rtx elem = XEXP (node, 0);
197
198 remove_list_node (listp);
199 free_INSN_LIST_node (node);
200
201 return elem;
202}
203
204/* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
205rtx
206remove_free_EXPR_LIST_node (rtx *listp)
207{
208 rtx node = *listp;
209 rtx elem = XEXP (node, 0);
210
211 remove_list_node (listp);
212 free_EXPR_LIST_node (node);
213
214 return elem;
215}
216
e2500fed 217#include "gt-lists.h"