1 /* List management for the GCC expander.
2 Copyright (C) 1987-2024 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"
26 static void free_list (rtx
*, rtx
*);
28 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs. */
30 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused. */
31 static GTY ((deletable
)) rtx unused_insn_list
;
33 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused. */
34 static GTY ((deletable
)) rtx unused_expr_list
;
36 /* This function will free an entire list of either EXPR_LIST, INSN_LIST
37 or DEPS_LIST nodes. This is to be used only on lists that consist
38 exclusively of nodes of one type only. This is only called by
39 free_EXPR_LIST_list, free_INSN_LIST_list and free_DEPS_LIST_list. */
41 free_list (rtx
*listp
, rtx
*unused_listp
)
46 link
= XEXP (prev_link
, 1);
48 gcc_assert (unused_listp
!= &unused_insn_list
49 || GET_CODE (prev_link
) == INSN_LIST
);
53 gcc_assert (unused_listp
!= &unused_insn_list
54 || GET_CODE (prev_link
) == INSN_LIST
);
57 link
= XEXP (link
, 1);
60 XEXP (prev_link
, 1) = *unused_listp
;
61 *unused_listp
= *listp
;
65 /* Find corresponding to ELEM node in the list pointed to by LISTP.
66 This node must exist in the list. Returns pointer to that node. */
68 find_list_elem (rtx elem
, rtx
*listp
)
70 while (XEXP (*listp
, 0) != elem
)
71 listp
= &XEXP (*listp
, 1);
75 /* Remove the node pointed to by LISTP from the list. */
77 remove_list_node (rtx
*listp
)
82 *listp
= XEXP (node
, 1);
86 /* Removes corresponding to ELEM node from the list pointed to by LISTP.
89 remove_list_elem (rtx elem
, rtx
*listp
)
93 listp
= find_list_elem (elem
, listp
);
95 remove_list_node (listp
);
99 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
100 node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST
103 alloc_INSN_LIST (rtx val
, rtx next
)
107 if (unused_insn_list
)
109 r
= as_a
<rtx_insn_list
*> (unused_insn_list
);
110 unused_insn_list
= r
->next ();
113 PUT_REG_NOTE_KIND (r
, VOIDmode
);
115 gcc_assert (GET_CODE (r
) == INSN_LIST
);
118 r
= gen_rtx_INSN_LIST (VOIDmode
, val
, next
);
123 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
124 node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST
127 alloc_EXPR_LIST (int kind
, rtx val
, rtx next
)
131 if (unused_expr_list
)
133 r
= as_a
<rtx_expr_list
*> (unused_expr_list
);
134 unused_expr_list
= XEXP (r
, 1);
137 PUT_REG_NOTE_KIND (r
, kind
);
140 r
= gen_rtx_EXPR_LIST ((machine_mode
) kind
, val
, next
);
145 /* This function will free up an entire list of EXPR_LIST nodes. */
147 free_EXPR_LIST_list (rtx_expr_list
**listp
)
151 free_list ((rtx
*)listp
, &unused_expr_list
);
154 /* This function will free up an entire list of INSN_LIST nodes. */
156 free_INSN_LIST_list (rtx_insn_list
**listp
)
160 free_list ((rtx
*)listp
, &unused_insn_list
);
163 /* Make a copy of the INSN_LIST list LINK and return it. */
165 copy_INSN_LIST (rtx_insn_list
*link
)
167 rtx_insn_list
*new_queue
;
168 rtx_insn_list
**pqueue
= &new_queue
;
170 for (; link
; link
= link
->next ())
172 rtx_insn
*x
= link
->insn ();
173 rtx_insn_list
*newlink
= alloc_INSN_LIST (x
, NULL
);
175 pqueue
= (rtx_insn_list
**)&XEXP (newlink
, 1);
181 /* Duplicate the INSN_LIST elements of COPY and prepend them to OLD. */
183 concat_INSN_LIST (rtx_insn_list
*copy
, rtx_insn_list
*old
)
185 rtx_insn_list
*new_rtx
= old
;
186 for (; copy
; copy
= copy
->next ())
188 new_rtx
= alloc_INSN_LIST (copy
->insn (), new_rtx
);
189 PUT_REG_NOTE_KIND (new_rtx
, REG_NOTE_KIND (copy
));
194 /* This function will free up an individual EXPR_LIST node. */
196 free_EXPR_LIST_node (rtx ptr
)
198 XEXP (ptr
, 1) = unused_expr_list
;
199 unused_expr_list
= ptr
;
202 /* This function will free up an individual INSN_LIST node. */
204 free_INSN_LIST_node (rtx ptr
)
206 gcc_assert (GET_CODE (ptr
) == INSN_LIST
);
207 XEXP (ptr
, 1) = unused_insn_list
;
208 unused_insn_list
= ptr
;
211 /* Remove and free corresponding to ELEM node in the INSN_LIST pointed to
214 remove_free_INSN_LIST_elem (rtx_insn
*elem
, rtx_insn_list
**listp
)
216 free_INSN_LIST_node (remove_list_elem (elem
, (rtx
*)listp
));
219 /* Remove and free the first node in the INSN_LIST pointed to by LISTP. */
221 remove_free_INSN_LIST_node (rtx_insn_list
**listp
)
223 rtx_insn_list
*node
= *listp
;
224 rtx_insn
*elem
= node
->insn ();
226 remove_list_node ((rtx
*)listp
);
227 free_INSN_LIST_node (node
);
232 /* Remove and free the first node in the EXPR_LIST pointed to by LISTP. */
234 remove_free_EXPR_LIST_node (rtx_expr_list
**listp
)
236 rtx_expr_list
*node
= *listp
;
237 rtx elem
= XEXP (node
, 0);
239 remove_list_node ((rtx
*)listp
);
240 free_EXPR_LIST_node (node
);
245 #include "gt-lists.h"