1 /* List management for the GCC expander.
2 Copyright (C) 1987-2015 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"
27 static void free_list (rtx
*, rtx
*);
29 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
31 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
32 static GTY ((deletable
)) rtx unused_insn_list
;
34 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
35 static GTY ((deletable
)) rtx unused_expr_list
;
37 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
38 or DEPS_LIST nodes. This is to be used only on lists that consist
39 exclusively of nodes of one type only. This is only called by
40 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
42 free_list (rtx
*listp
, rtx
*unused_listp
)
47 link
= XEXP (prev_link
, 1);
49 gcc_assert (unused_listp
!= &unused_insn_list
50 || GET_CODE (prev_link
) == INSN_LIST
);
54 gcc_assert (unused_listp
!= &unused_insn_list
55 || GET_CODE (prev_link
) == INSN_LIST
);
58 link
= XEXP (link
, 1);
61 XEXP (prev_link
, 1) = *unused_listp
;
62 *unused_listp
= *listp
;
66 /* Find corresponding to ELEM node in the list pointed to by LISTP.
67 This node must exist in the list. Returns pointer to that node. */
69 find_list_elem (rtx elem
, rtx
*listp
)
71 while (XEXP (*listp
, 0) != elem
)
72 listp
= &XEXP (*listp
, 1);
76 /* Remove the node pointed to by LISTP from the list. */
78 remove_list_node (rtx
*listp
)
83 *listp
= XEXP (node
, 1);
87 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
90 remove_list_elem (rtx elem
, rtx
*listp
)
94 listp
= find_list_elem (elem
, listp
);
96 remove_list_node (listp
);
100 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
101 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
104 alloc_INSN_LIST (rtx val
, rtx next
)
108 if (unused_insn_list
)
110 r
= as_a
<rtx_insn_list
*> (unused_insn_list
);
111 unused_insn_list
= r
->next ();
114 PUT_REG_NOTE_KIND (r
, VOIDmode
);
116 gcc_assert (GET_CODE (r
) == INSN_LIST
);
119 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
124 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
125 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
128 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
132 if (unused_expr_list
)
134 r
= as_a
<rtx_expr_list
*> (unused_expr_list
);
135 unused_expr_list
= XEXP (r
, 1);
138 PUT_REG_NOTE_KIND (r
, kind
);
141 r
= gen_rtx_EXPR_LIST ((machine_mode
) kind
, val
, next
);
146 /* This function will free up an entire list of EXPR_LIST nodes. */
148 free_EXPR_LIST_list (rtx_expr_list
**listp
)
152 free_list ((rtx
*)listp
, &unused_expr_list
);
155 /* This function will free up an entire list of INSN_LIST nodes. */
157 free_INSN_LIST_list (rtx_insn_list
**listp
)
161 free_list ((rtx
*)listp
, &unused_insn_list
);
164 /* Make a copy of the INSN_LIST list LINK and return it. */
166 copy_INSN_LIST (rtx_insn_list
*link
)
168 rtx_insn_list
*new_queue
;
169 rtx_insn_list
**pqueue
= &new_queue
;
171 for (; link
; link
= link
->next ())
173 rtx_insn
*x
= link
->insn ();
174 rtx_insn_list
*newlink
= alloc_INSN_LIST (x
, NULL
);
176 pqueue
= (rtx_insn_list
**)&XEXP (newlink
, 1);
182 /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */
184 concat_INSN_LIST (rtx_insn_list
*copy
, rtx_insn_list
*old
)
186 rtx_insn_list
*new_rtx
= old
;
187 for (; copy
; copy
= copy
->next ())
189 new_rtx
= alloc_INSN_LIST (copy
->insn (), new_rtx
);
190 PUT_REG_NOTE_KIND (new_rtx
, REG_NOTE_KIND (copy
));
195 /* This function will free up an individual EXPR_LIST node. */
197 free_EXPR_LIST_node (rtx ptr
)
199 XEXP (ptr
, 1) = unused_expr_list
;
200 unused_expr_list
= ptr
;
203 /* This function will free up an individual INSN_LIST node. */
205 free_INSN_LIST_node (rtx ptr
)
207 gcc_assert (GET_CODE (ptr
) == INSN_LIST
);
208 XEXP (ptr
, 1) = unused_insn_list
;
209 unused_insn_list
= ptr
;
212 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
215 remove_free_INSN_LIST_elem (rtx_insn
*elem
, rtx_insn_list
**listp
)
217 free_INSN_LIST_node (remove_list_elem (elem
, (rtx
*)listp
));
220 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
222 remove_free_INSN_LIST_node (rtx_insn_list
**listp
)
224 rtx_insn_list
*node
= *listp
;
225 rtx_insn
*elem
= node
->insn ();
227 remove_list_node ((rtx
*)listp
);
228 free_INSN_LIST_node (node
);
233 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
235 remove_free_EXPR_LIST_node (rtx_expr_list
**listp
)
237 rtx_expr_list
*node
= *listp
;
238 rtx elem
= XEXP (node
, 0);
240 remove_list_node ((rtx
*)listp
);
241 free_EXPR_LIST_node (node
);
246 #include "gt-lists.h"