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 "setif-var.h"
41 bounds sameregion lbs
;
42 bounds sameregion ubs
;
49 typedef struct sv_info
*sv_info
;
51 DECLARE_UFIND(sv_elt
,sv_info
)
53 DEFINE_UFIND(sv_elt
,sv_info
)
55 DEFINE_LIST(setif_var_list
,setif_var
)
57 #define get_info(v) (sv_elt_get_info((v)->elt))
59 struct setif_var
/* extends gen_e */
68 bool sv_lt(setif_var v1
, setif_var v2
)
70 return ( sv_get_stamp(v1
) < sv_get_stamp(v2
) );
73 bool sv_eq(setif_var v1
, setif_var v2
)
75 return ( sv_get_stamp(v1
) == sv_get_stamp(v2
) );
78 static setif_var
make_var(region r
, const char *name
, stamp st
)
80 setif_var result
= ralloc(r
, struct setif_var
);
81 sv_info info
= ralloc(r
, struct sv_info
);
84 info
->lbs
= bounds_create(r
);
85 info
->ubs
= bounds_create(r
);
86 info
->tlb_cache
= NULL
;
87 info
->ub_projs
= new_gen_e_list(r
);
88 info
->name
= name
? rstrdup(r
,name
) : "fv";
89 info
->component
= new_uf_element(r
, NULL
);
91 result
->type
= VAR_TYPE
;
92 result
->elt
= new_sv_elt(r
,info
);
95 result
->sort
= setif_sort
;
101 setif_var
sv_fresh(region r
, const char *name
)
103 return make_var(r
,name
,stamp_fresh());
106 setif_var
sv_fresh_large(region r
, const char *name
)
108 return make_var(r
,name
,stamp_fresh_large());
111 setif_var
sv_fresh_small(region r
, const char *name
)
113 return make_var(r
,name
,stamp_fresh_small());
116 stamp
sv_get_stamp(setif_var v
)
118 return get_info(v
)->st
;
121 const char *sv_get_name(setif_var v
)
123 return get_info(v
)->name
;
127 static sv_info
combine(sv_info i1
, sv_info i2
)
134 void sv_unify(setif_var v
,setif_var_list vars
)
137 setif_var_list_scanner scan
;
139 setif_var_list_scan(vars
,&scan
);
141 while (setif_var_list_next(&scan
,&temp
))
143 sv_elt_unify(combine
,v
->elt
,temp
->elt
);
147 gen_e_list
sv_get_lbs(setif_var v
)
149 return bounds_exprs(get_info(v
)->lbs
);
152 gen_e_list
sv_get_ubs(setif_var v
)
154 return bounds_exprs(get_info(v
)->ubs
);
157 bool sv_add_ub(setif_var v
, gen_e e
, stamp s
)
159 return bounds_add(get_info(v
)->ubs
,e
,s
);
162 bool sv_add_lb(setif_var v
, gen_e e
, stamp s
)
164 return bounds_add(get_info(v
)->lbs
,e
,s
);
167 bool sv_is_ub(setif_var v
, stamp s
)
169 bool self_edge
= sv_get_stamp(v
) == s
,
170 in_bounds
= bounds_query(get_info(v
)->ubs
,s
);
172 return (self_edge
|| in_bounds
);
175 bool sv_is_lb(setif_var v
, stamp s
)
178 bool self_edge
= sv_get_stamp(v
) == s
,
179 in_bounds
= bounds_query(get_info(v
)->lbs
,s
);
181 return (self_edge
|| in_bounds
);
185 void sv_add_ub_proj(setif_var v
, gen_e e
)
187 gen_e_list_cons(e
,get_info(v
)->ub_projs
);
190 gen_e
sv_get_ub_proj(setif_var v
, get_proj_fn_ptr get_proj
)
192 return get_proj(get_info(v
)->ub_projs
);
195 gen_e_list
sv_get_ub_projs(setif_var v
)
197 return get_info(v
)->ub_projs
;
201 bool sv_union_component(setif_var v1
, setif_var v2
)
203 if (uf_eq(get_info(v1
)->component
,get_info(v2
)->component
))
208 uf_union(get_info(v1
)->component
,get_info(v2
)->component
);
213 void sv_set_tlb_cache(setif_var v
, jcoll j
)
215 get_info(v
)->tlb_cache
= j
;
218 jcoll
sv_get_tlb_cache(setif_var v
)
220 return get_info(v
)->tlb_cache
;
223 void sv_clear_tlb_cache(setif_var v
)
225 get_info(v
)->tlb_cache
= NULL
;