OSDN Git Service

libcpp/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libbanshee / engine / setst-var.c
1 /*
2  * Copyright (c) 2000-2001
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30
31 #include <stdio.h>
32 #include <assert.h>
33 #include <regions.h>
34 #include "setst-var.h"
35 #include "jcollection.h"
36 #include "ufind.h"
37 #include "bounds.h"
38
39 struct st_info
40 {
41   stamp st;
42   bounds lbs;
43   bounds sources;
44   bounds sinks;
45   jcoll tlb_cache;
46   const char *name;
47   bool seen;
48   int path_pos;
49   int src_sz;
50   int snk_sz;
51 };
52
53 typedef struct st_info *st_info;
54
55 DECLARE_UFIND(st_elt,st_info)
56
57 DEFINE_UFIND(st_elt,st_info)
58
59 DEFINE_LIST(setst_var_list,setst_var)
60
61 #define get_info(v) (st_elt_get_info((v)->elt))
62
63 struct setst_var /* extends gen_e */
64 {
65 #ifdef NONSPEC
66   sort_kind sort;
67 #endif
68   int type;
69   st_elt elt;
70 };
71
72 bool st_eq(setst_var v1, setst_var v2)
73 {
74   return (st_get_stamp(v1) == st_get_stamp(v2));
75 }
76
77 static setst_var make_var(region r, const char *name, stamp st)
78 {
79   setst_var result = ralloc(r,struct setst_var);
80   st_info info = ralloc(r, struct st_info);
81
82   info->st = st;
83   info->lbs = bounds_create(r);
84   info->sources = bounds_create(r);
85   info->sinks = bounds_create(r);
86   info->tlb_cache = NULL;
87   info->name = name ? rstrdup(r,name) : "fv";
88   info->seen = FALSE;
89   info->path_pos = 0;
90   info->src_sz = 0;
91   info->snk_sz = 0;
92
93   result->type = VAR_TYPE;
94   result->elt = new_st_elt(r,info);
95
96
97 #ifdef NONSPEC
98   result->sort = setst_sort;
99 #endif
100
101   return result;
102 }
103
104 setst_var st_fresh(region r, const char *name)
105 {
106   return make_var(r,name,stamp_fresh());
107 }
108
109 setst_var st_fresh_large(region r, const char *name)
110 {
111   return make_var(r,name,stamp_fresh_large());
112 }
113
114 setst_var st_fresh_small(region r, const char *name)
115 {
116   return make_var(r,name,stamp_fresh_small());
117 }
118
119 stamp st_get_stamp(setst_var v)
120 {
121   return get_info(v)->st;
122 }
123
124 const char *st_get_name(setst_var v)
125 {
126   return get_info(v)->name;
127 }
128
129 void st_unify(setst_var v,setst_var_list vars)
130 {
131   setst_var temp;
132   setst_var_list_scanner scan;
133
134   setst_var_list_scan(vars,&scan);
135
136   while (setst_var_list_next(&scan,&temp)) 
137     {
138       st_elt_union(v->elt,temp->elt);
139     }
140 }
141
142 setst_var_list st_get_lbs(setst_var v)
143 {
144   return (setst_var_list)bounds_exprs(get_info(v)->lbs);
145 }
146
147 gen_e_list st_get_sources(setst_var v)
148 {
149   return bounds_exprs(get_info(v)->sources);
150 }
151
152 gen_e_list st_get_sinks(setst_var v)
153 {
154   return bounds_exprs(get_info(v)->sinks);
155 }
156
157 bool st_add_lb(setst_var v, setst_var lb)
158 {
159   return bounds_add(get_info(v)->lbs,(gen_e)lb,st_get_stamp(lb));
160 }
161
162 bool st_add_source(setst_var v, gen_e source, stamp s)
163 {
164   return bounds_add(get_info(v)->sources,source,s);
165 }
166
167 bool st_add_sink(setst_var v, gen_e sink, stamp s)
168 {
169   return bounds_add(get_info(v)->sinks,sink,s);
170 }
171
172 jcoll st_get_tlb_cache(setst_var v)
173 {
174   return get_info(v)->tlb_cache;
175 }
176
177 void st_set_tlb_cache(setst_var v, jcoll j)
178 {
179   get_info(v)->tlb_cache = j;
180 }
181
182 void st_clear_tlb_cache(setst_var v)
183 {
184   get_info(v)->tlb_cache = NULL;
185 }
186
187 gen_e st_get_ub_proj(setst_var v, get_proj_fn_ptr get_proj)
188 {
189   return get_proj(st_get_sinks(v));
190 }
191 static setst_var neq_temp;
192 static bool neq (const setst_var v2)
193 {
194   return (!(st_get_stamp (neq_temp) == st_get_stamp (v2)));
195 }
196 void st_repair_bounds(setst_var v1)
197 {
198   setst_var_list lbs;
199   neq_temp = v1;
200   lbs = setst_var_list_filter2(st_get_lbs(v1),neq);  
201
202   bounds_set(get_info(v1)->lbs,(gen_e_list)lbs);
203 }
204
205 void st_set_path_pos(setst_var v, int pos)
206 {
207   get_info(v)->path_pos = pos;
208 }
209
210 int st_get_path_pos(setst_var v)
211 {
212   return get_info(v)->path_pos;
213 }
214
215 void st_set_seen(setst_var v, bool b)
216 {
217   get_info(v)->seen = b;
218 }
219
220 bool st_get_seen(setst_var v)
221 {
222   return get_info(v)->seen;
223 }
224
225 void st_set_src_sz(setst_var v, int size)
226 {
227   get_info(v)->src_sz = size;
228 }
229
230 int st_get_src_sz(setst_var v)
231 {
232   return get_info(v)->src_sz;
233 }
234
235 void st_set_snk_sz(setst_var v, int size)
236 {
237   get_info(v)->snk_sz = size;
238 }
239
240 int st_get_snk_sz(setst_var v)
241 {
242   return get_info(v)->snk_sz;
243 }
244
245
246
247
248
249