1 /* List management for the GCC expander.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
24 #include "diagnostic-core.h"
28 static void free_list (rtx
*, rtx
*);
30 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
32 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
33 static GTY ((deletable
)) rtx unused_insn_list
;
35 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
36 static GTY ((deletable
)) rtx unused_expr_list
;
38 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
39 or DEPS_LIST nodes. This is to be used only on lists that consist
40 exclusively of nodes of one type only. This is only called by
41 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
43 free_list (rtx
*listp
, rtx
*unused_listp
)
48 link
= XEXP (prev_link
, 1);
50 gcc_assert (unused_listp
!= &unused_insn_list
51 || GET_CODE (prev_link
) == INSN_LIST
);
55 gcc_assert (unused_listp
!= &unused_insn_list
56 || GET_CODE (prev_link
) == INSN_LIST
);
59 link
= XEXP (link
, 1);
62 XEXP (prev_link
, 1) = *unused_listp
;
63 *unused_listp
= *listp
;
67 /* Find corresponding to ELEM node in the list pointed to by LISTP.
68 This node must exist in the list. Returns pointer to that node. */
70 find_list_elem (rtx elem
, rtx
*listp
)
72 while (XEXP (*listp
, 0) != elem
)
73 listp
= &XEXP (*listp
, 1);
77 /* Remove the node pointed to by LISTP from the list. */
79 remove_list_node (rtx
*listp
)
84 *listp
= XEXP (node
, 1);
88 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
91 remove_list_elem (rtx elem
, rtx
*listp
)
95 listp
= find_list_elem (elem
, listp
);
97 remove_list_node (listp
);
101 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
102 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
105 alloc_INSN_LIST (rtx val
, rtx next
)
109 if (unused_insn_list
)
111 r
= unused_insn_list
;
112 unused_insn_list
= XEXP (r
, 1);
115 PUT_REG_NOTE_KIND (r
, VOIDmode
);
117 gcc_assert (GET_CODE (r
) == INSN_LIST
);
120 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
125 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
126 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
129 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
133 if (unused_expr_list
)
135 r
= unused_expr_list
;
136 unused_expr_list
= XEXP (r
, 1);
139 PUT_REG_NOTE_KIND (r
, kind
);
142 r
= gen_rtx_EXPR_LIST ((enum machine_mode
) kind
, val
, next
);
147 /* This function will free up an entire list of EXPR_LIST nodes. */
149 free_EXPR_LIST_list (rtx
*listp
)
153 free_list (listp
, &unused_expr_list
);
156 /* This function will free up an entire list of INSN_LIST nodes. */
158 free_INSN_LIST_list (rtx
*listp
)
162 free_list (listp
, &unused_insn_list
);
165 /* Make a copy of the INSN_LIST list LINK and return it. */
167 copy_INSN_LIST (rtx link
)
170 rtx
*pqueue
= &new_queue
;
172 for (; link
; link
= XEXP (link
, 1))
174 rtx x
= XEXP (link
, 0);
175 rtx newlink
= alloc_INSN_LIST (x
, NULL
);
177 pqueue
= &XEXP (newlink
, 1);
183 /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */
185 concat_INSN_LIST (rtx copy
, rtx old
)
188 for (; copy
; copy
= XEXP (copy
, 1))
190 new_rtx
= alloc_INSN_LIST (XEXP (copy
, 0), new_rtx
);
191 PUT_REG_NOTE_KIND (new_rtx
, REG_NOTE_KIND (copy
));
196 /* This function will free up an individual EXPR_LIST node. */
198 free_EXPR_LIST_node (rtx ptr
)
200 XEXP (ptr
, 1) = unused_expr_list
;
201 unused_expr_list
= ptr
;
204 /* This function will free up an individual INSN_LIST node. */
206 free_INSN_LIST_node (rtx ptr
)
208 gcc_assert (GET_CODE (ptr
) == INSN_LIST
);
209 XEXP (ptr
, 1) = unused_insn_list
;
210 unused_insn_list
= ptr
;
213 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
216 remove_free_INSN_LIST_elem (rtx elem
, rtx
*listp
)
218 free_INSN_LIST_node (remove_list_elem (elem
, listp
));
221 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
223 remove_free_INSN_LIST_node (rtx
*listp
)
226 rtx elem
= XEXP (node
, 0);
228 remove_list_node (listp
);
229 free_INSN_LIST_node (node
);
234 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
236 remove_free_EXPR_LIST_node (rtx
*listp
)
239 rtx elem
= XEXP (node
, 0);
241 remove_list_node (listp
);
242 free_EXPR_LIST_node (node
);
247 #include "gt-lists.h"