OSDN Git Service

* lists.c: Include ggc.h.
[pf3gnuchains/gcc-fork.git] / gcc / lists.c
1 /* List management for the GNU C-Compiler expander.
2    Copyright (C) 1987, 88, 92-97, 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "toplev.h"
24 #include "rtl.h"
25 #include "ggc.h"
26
27 /* Functions for maintaining cache-able lists of EXPR_LIST and INSN_LISTs.  */
28
29 /* An INSN_LIST containing all INSN_LISTs allocated but currently unused.  */
30 static rtx unused_insn_list;
31
32 /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused.  */
33 static rtx unused_expr_list;
34
35
36 /* This function will free an entire list of either EXPR_LIST or INSN_LIST
37    nodes. This is to be used only only lists that consist exclusively of
38    nodes of one type only.  This is only called by free_EXPR_LIST_list
39    and free_INSN_LIST_list.  */
40 static void
41 free_list (listp, unused_listp)
42      rtx *listp, *unused_listp;
43 {
44   register rtx link, prev_link;
45
46   prev_link = *listp;
47   link = XEXP (prev_link, 1);
48
49   while (link)
50     {
51       prev_link = link;
52       link = XEXP (link, 1);
53     }
54
55   XEXP (prev_link, 1) = *unused_listp;
56   *unused_listp = *listp;
57   *listp = 0;
58 }
59
60 /* This call is used in place of a gen_rtx_INSN_LIST. If there is a cached
61    node available, we'll use it, otherwise a call to gen_rtx_INSN_LIST 
62    is made.  */
63 rtx
64 alloc_INSN_LIST (val, next)
65      rtx val, next;
66 {
67   rtx r;
68
69   if (unused_insn_list)
70     {
71       r = unused_insn_list;
72       unused_insn_list = XEXP (r, 1);
73       XEXP (r, 0) = val;
74       XEXP (r, 1) = next;
75       PUT_REG_NOTE_KIND (r, VOIDmode);
76     }
77   else
78     r = gen_rtx_INSN_LIST (VOIDmode, val, next);
79
80   return r;
81 }
82
83 /* This call is used in place of a gen_rtx_EXPR_LIST. If there is a cached
84    node available, we'll use it, otherwise a call to gen_rtx_EXPR_LIST 
85    is made.  */
86 rtx
87 alloc_EXPR_LIST (kind, val, next)
88      int kind;
89      rtx val, next;
90 {
91   rtx r;
92
93   if (unused_expr_list)
94     {
95       r = unused_expr_list;
96       unused_expr_list = XEXP (r, 1);
97       XEXP (r, 0) = val;
98       XEXP (r, 1) = next;
99       PUT_REG_NOTE_KIND (r, kind);
100     }
101   else
102     r = gen_rtx_EXPR_LIST (kind, val, next);
103
104   return r;
105 }
106
107 /* This function will initialize the EXPR_LIST and INSN_LIST caches.  */
108
109 static void
110 zap_lists (dummy)
111      void *dummy ATTRIBUTE_UNUSED;
112 {
113   unused_expr_list = NULL;
114   unused_insn_list = NULL;
115 }
116
117 void 
118 init_EXPR_INSN_LIST_cache ()
119 {
120   static int initialized;
121   if (!initialized)
122     {
123       initialized = 1;
124       ggc_add_root (&unused_expr_list, 1, 1, zap_lists);
125     }
126     
127   unused_expr_list = NULL;
128   unused_insn_list = NULL;
129 }
130
131 /* This function will free up an entire list of EXPR_LIST nodes.  */
132 void 
133 free_EXPR_LIST_list (listp)
134      rtx *listp;
135 {
136   if (*listp == 0)
137     return;
138   free_list (listp, &unused_expr_list);
139 }
140
141 /* This function will free up an entire list of INSN_LIST nodes.  */
142 void 
143 free_INSN_LIST_list (listp)
144      rtx *listp;
145 {
146   if (*listp == 0)
147     return;
148   free_list (listp, &unused_insn_list);
149 }
150
151 /* This function will free up an individual EXPR_LIST node.  */
152 void 
153 free_EXPR_LIST_node (ptr)
154      rtx ptr;
155 {
156   XEXP (ptr, 1) = unused_expr_list;
157   unused_expr_list = ptr;
158 }
159
160 /* This function will free up an individual INSN_LIST node.  */
161 void 
162 free_INSN_LIST_node (ptr)
163      rtx ptr;
164 {
165   XEXP (ptr, 1) = unused_insn_list;
166   unused_insn_list = ptr;
167 }