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"
30 static void free_list (rtx
*, rtx
*);
32 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
34 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
35 static GTY ((deletable
)) rtx unused_insn_list
;
37 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
38 static GTY ((deletable
)) rtx unused_expr_list
;
40 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
41 or DEPS_LIST nodes. This is to be used only on lists that consist
42 exclusively of nodes of one type only. This is only called by
43 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
45 free_list (rtx
*listp
, rtx
*unused_listp
)
50 link
= XEXP (prev_link
, 1);
52 gcc_assert (unused_listp
!= &unused_insn_list
53 || GET_CODE (prev_link
) == INSN_LIST
);
57 gcc_assert (unused_listp
!= &unused_insn_list
58 || GET_CODE (prev_link
) == INSN_LIST
);
61 link
= XEXP (link
, 1);
64 XEXP (prev_link
, 1) = *unused_listp
;
65 *unused_listp
= *listp
;
69 /* Find corresponding to ELEM node in the list pointed to by LISTP.
70 This node must exist in the list. Returns pointer to that node. */
72 find_list_elem (rtx elem
, rtx
*listp
)
74 while (XEXP (*listp
, 0) != elem
)
75 listp
= &XEXP (*listp
, 1);
79 /* Remove the node pointed to by LISTP from the list. */
81 remove_list_node (rtx
*listp
)
86 *listp
= XEXP (node
, 1);
90 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
93 remove_list_elem (rtx elem
, rtx
*listp
)
97 listp
= find_list_elem (elem
, listp
);
99 remove_list_node (listp
);
103 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
104 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
107 alloc_INSN_LIST (rtx val
, rtx next
)
111 if (unused_insn_list
)
113 r
= unused_insn_list
;
114 unused_insn_list
= XEXP (r
, 1);
117 PUT_REG_NOTE_KIND (r
, VOIDmode
);
119 gcc_assert (GET_CODE (r
) == INSN_LIST
);
122 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
127 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
128 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
131 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
135 if (unused_expr_list
)
137 r
= unused_expr_list
;
138 unused_expr_list
= XEXP (r
, 1);
141 PUT_REG_NOTE_KIND (r
, kind
);
144 r
= gen_rtx_EXPR_LIST ((enum machine_mode
) kind
, val
, next
);
149 /* This function will free up an entire list of EXPR_LIST nodes. */
151 free_EXPR_LIST_list (rtx
*listp
)
155 free_list (listp
, &unused_expr_list
);
158 /* This function will free up an entire list of INSN_LIST nodes. */
160 free_INSN_LIST_list (rtx
*listp
)
164 free_list (listp
, &unused_insn_list
);
167 /* This function will free up an individual EXPR_LIST node. */
169 free_EXPR_LIST_node (rtx ptr
)
171 XEXP (ptr
, 1) = unused_expr_list
;
172 unused_expr_list
= ptr
;
175 /* This function will free up an individual INSN_LIST node. */
177 free_INSN_LIST_node (rtx ptr
)
179 gcc_assert (GET_CODE (ptr
) == INSN_LIST
);
180 XEXP (ptr
, 1) = unused_insn_list
;
181 unused_insn_list
= ptr
;
184 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
187 remove_free_INSN_LIST_elem (rtx elem
, rtx
*listp
)
189 free_INSN_LIST_node (remove_list_elem (elem
, listp
));
192 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
194 remove_free_INSN_LIST_node (rtx
*listp
)
197 rtx elem
= XEXP (node
, 0);
199 remove_list_node (listp
);
200 free_INSN_LIST_node (node
);
205 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
207 remove_free_EXPR_LIST_node (rtx
*listp
)
210 rtx elem
= XEXP (node
, 0);
212 remove_list_node (listp
);
213 free_EXPR_LIST_node (node
);
218 #include "gt-lists.h"