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
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
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/>. */
24 #include "coretypes.h"
26 #include "diagnostic-core.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. */
46 free_list (rtx
*listp
, rtx
*unused_listp
)
51 link
= XEXP (prev_link
, 1);
53 gcc_assert (unused_listp
!= &unused_insn_list
54 || GET_CODE (prev_link
) == INSN_LIST
);
58 gcc_assert (unused_listp
!= &unused_insn_list
59 || GET_CODE (prev_link
) == INSN_LIST
);
62 link
= XEXP (link
, 1);
65 XEXP (prev_link
, 1) = *unused_listp
;
66 *unused_listp
= *listp
;
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. */
73 find_list_elem (rtx elem
, rtx
*listp
)
75 while (XEXP (*listp
, 0) != elem
)
76 listp
= &XEXP (*listp
, 1);
80 /* Remove the node pointed to by LISTP from the list. */
82 remove_list_node (rtx
*listp
)
87 *listp
= XEXP (node
, 1);
91 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
94 remove_list_elem (rtx elem
, rtx
*listp
)
98 listp
= find_list_elem (elem
, listp
);
100 remove_list_node (listp
);
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
108 alloc_INSN_LIST (rtx val
, rtx next
)
112 if (unused_insn_list
)
114 r
= unused_insn_list
;
115 unused_insn_list
= XEXP (r
, 1);
118 PUT_REG_NOTE_KIND (r
, VOIDmode
);
120 gcc_assert (GET_CODE (r
) == INSN_LIST
);
123 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
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
132 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
136 if (unused_expr_list
)
138 r
= unused_expr_list
;
139 unused_expr_list
= XEXP (r
, 1);
142 PUT_REG_NOTE_KIND (r
, kind
);
145 r
= gen_rtx_EXPR_LIST ((enum machine_mode
) kind
, val
, next
);
150 /* This function will free up an entire list of EXPR_LIST nodes. */
152 free_EXPR_LIST_list (rtx
*listp
)
156 free_list (listp
, &unused_expr_list
);
159 /* This function will free up an entire list of INSN_LIST nodes. */
161 free_INSN_LIST_list (rtx
*listp
)
165 free_list (listp
, &unused_insn_list
);
168 /* This function will free up an individual EXPR_LIST node. */
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. */
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
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
)
198 rtx elem
= XEXP (node
, 0);
200 remove_list_node (listp
);
201 free_INSN_LIST_node (node
);
206 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
208 remove_free_EXPR_LIST_node (rtx
*listp
)
211 rtx elem
= XEXP (node
, 0);
213 remove_list_node (listp
);
214 free_EXPR_LIST_node (node
);
219 #include "gt-lists.h"