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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 static void free_list (rtx
*, rtx
*);
31 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
33 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
34 static GTY ((deletable
)) rtx unused_insn_list
;
36 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
37 static GTY ((deletable
)) rtx unused_expr_list
;
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. */
44 free_list (rtx
*listp
, rtx
*unused_listp
)
49 link
= XEXP (prev_link
, 1);
51 gcc_assert (unused_listp
!= &unused_insn_list
52 || GET_CODE (prev_link
) == INSN_LIST
);
56 gcc_assert (unused_listp
!= &unused_insn_list
57 || GET_CODE (prev_link
) == INSN_LIST
);
60 link
= XEXP (link
, 1);
63 XEXP (prev_link
, 1) = *unused_listp
;
64 *unused_listp
= *listp
;
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. */
71 find_list_elem (rtx elem
, rtx
*listp
)
73 while (XEXP (*listp
, 0) != elem
)
74 listp
= &XEXP (*listp
, 1);
78 /* Remove the node pointed to by LISTP from the list. */
80 remove_list_node (rtx
*listp
)
85 *listp
= XEXP (node
, 1);
89 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
92 remove_list_elem (rtx elem
, rtx
*listp
)
96 listp
= find_list_elem (elem
, listp
);
98 remove_list_node (listp
);
102 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
103 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
106 alloc_INSN_LIST (rtx val
, rtx next
)
110 if (unused_insn_list
)
112 r
= unused_insn_list
;
113 unused_insn_list
= XEXP (r
, 1);
116 PUT_REG_NOTE_KIND (r
, VOIDmode
);
118 gcc_assert (GET_CODE (r
) == INSN_LIST
);
121 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
126 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
127 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
130 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
134 if (unused_expr_list
)
136 r
= unused_expr_list
;
137 unused_expr_list
= XEXP (r
, 1);
140 PUT_REG_NOTE_KIND (r
, kind
);
143 r
= gen_rtx_EXPR_LIST (kind
, val
, next
);
148 /* This function will free up an entire list of EXPR_LIST nodes. */
150 free_EXPR_LIST_list (rtx
*listp
)
154 free_list (listp
, &unused_expr_list
);
157 /* This function will free up an entire list of INSN_LIST nodes. */
159 free_INSN_LIST_list (rtx
*listp
)
163 free_list (listp
, &unused_insn_list
);
166 /* This function will free up an individual EXPR_LIST node. */
168 free_EXPR_LIST_node (rtx ptr
)
170 XEXP (ptr
, 1) = unused_expr_list
;
171 unused_expr_list
= ptr
;
174 /* This function will free up an individual INSN_LIST node. */
176 free_INSN_LIST_node (rtx ptr
)
178 gcc_assert (GET_CODE (ptr
) == INSN_LIST
);
179 XEXP (ptr
, 1) = unused_insn_list
;
180 unused_insn_list
= ptr
;
183 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
186 remove_free_INSN_LIST_elem (rtx elem
, rtx
*listp
)
188 free_INSN_LIST_node (remove_list_elem (elem
, listp
));
191 #include "gt-lists.h"