2 * Copyright (c) 2000-2001
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
34 #include "setst-var.h"
35 #include "jcollection.h"
53 typedef struct st_info
*st_info
;
55 DECLARE_UFIND(st_elt
,st_info
)
57 DEFINE_UFIND(st_elt
,st_info
)
59 DEFINE_LIST(setst_var_list
,setst_var
)
61 #define get_info(v) (st_elt_get_info((v)->elt))
63 struct setst_var
/* extends gen_e */
72 bool st_eq(setst_var v1
, setst_var v2
)
74 return (st_get_stamp(v1
) == st_get_stamp(v2
));
77 static setst_var
make_var(region r
, const char *name
, stamp st
)
79 setst_var result
= ralloc(r
,struct setst_var
);
80 st_info info
= ralloc(r
, struct st_info
);
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";
93 result
->type
= VAR_TYPE
;
94 result
->elt
= new_st_elt(r
,info
);
98 result
->sort
= setst_sort
;
104 setst_var
st_fresh(region r
, const char *name
)
106 return make_var(r
,name
,stamp_fresh());
109 setst_var
st_fresh_large(region r
, const char *name
)
111 return make_var(r
,name
,stamp_fresh_large());
114 setst_var
st_fresh_small(region r
, const char *name
)
116 return make_var(r
,name
,stamp_fresh_small());
119 stamp
st_get_stamp(setst_var v
)
121 return get_info(v
)->st
;
124 const char *st_get_name(setst_var v
)
126 return get_info(v
)->name
;
129 void st_unify(setst_var v
,setst_var_list vars
)
132 setst_var_list_scanner scan
;
134 setst_var_list_scan(vars
,&scan
);
136 while (setst_var_list_next(&scan
,&temp
))
138 st_elt_union(v
->elt
,temp
->elt
);
142 setst_var_list
st_get_lbs(setst_var v
)
144 return (setst_var_list
)bounds_exprs(get_info(v
)->lbs
);
147 gen_e_list
st_get_sources(setst_var v
)
149 return bounds_exprs(get_info(v
)->sources
);
152 gen_e_list
st_get_sinks(setst_var v
)
154 return bounds_exprs(get_info(v
)->sinks
);
157 bool st_add_lb(setst_var v
, setst_var lb
)
159 return bounds_add(get_info(v
)->lbs
,(gen_e
)lb
,st_get_stamp(lb
));
162 bool st_add_source(setst_var v
, gen_e source
, stamp s
)
164 return bounds_add(get_info(v
)->sources
,source
,s
);
167 bool st_add_sink(setst_var v
, gen_e sink
, stamp s
)
169 return bounds_add(get_info(v
)->sinks
,sink
,s
);
172 jcoll
st_get_tlb_cache(setst_var v
)
174 return get_info(v
)->tlb_cache
;
177 void st_set_tlb_cache(setst_var v
, jcoll j
)
179 get_info(v
)->tlb_cache
= j
;
182 void st_clear_tlb_cache(setst_var v
)
184 get_info(v
)->tlb_cache
= NULL
;
187 gen_e
st_get_ub_proj(setst_var v
, get_proj_fn_ptr get_proj
)
189 return get_proj(st_get_sinks(v
));
191 static setst_var neq_temp
;
192 static bool neq (const setst_var v2
)
194 return (!(st_get_stamp (neq_temp
) == st_get_stamp (v2
)));
196 void st_repair_bounds(setst_var v1
)
200 lbs
= setst_var_list_filter2(st_get_lbs(v1
),neq
);
202 bounds_set(get_info(v1
)->lbs
,(gen_e_list
)lbs
);
205 void st_set_path_pos(setst_var v
, int pos
)
207 get_info(v
)->path_pos
= pos
;
210 int st_get_path_pos(setst_var v
)
212 return get_info(v
)->path_pos
;
215 void st_set_seen(setst_var v
, bool b
)
217 get_info(v
)->seen
= b
;
220 bool st_get_seen(setst_var v
)
222 return get_info(v
)->seen
;
225 void st_set_src_sz(setst_var v
, int size
)
227 get_info(v
)->src_sz
= size
;
230 int st_get_src_sz(setst_var v
)
232 return get_info(v
)->src_sz
;
235 void st_set_snk_sz(setst_var v
, int size
)
237 get_info(v
)->snk_sz
= size
;
240 int st_get_snk_sz(setst_var v
)
242 return get_info(v
)->snk_sz
;