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
38 DECLARE_UFIND(contour_elt
,contour
)
40 struct flow_var
/* extends gen_e */
45 int type
; /* alias or var */
48 bounds sameregion ubs
;
49 bounds sameregion lbs
;
54 DEFINE_UFIND(contour_elt
,contour
)
55 DEFINE_LIST(flow_var_list
, flow_var
)
57 #define get_contour(x) (contour_elt_get_info((x)->elt))
59 static flow_var
make_var(region r
, const char *name
, stamp st
)
61 flow_var result
= ralloc(r
,struct flow_var
);
63 result
->type
= VAR_TYPE
;
66 result
->ubs
= bounds_create(r
);
67 result
->lbs
= bounds_create(r
);
68 result
->elt
= new_contour_elt(r
,NULL
);
72 result
->sort
= flow_sort
;
78 flow_var
fv_fresh(region r
, const char *name
)
80 return make_var(r
,name
,stamp_fresh());
83 flow_var
fv_fresh_large(region r
, const char *name
)
85 return make_var(r
,name
,stamp_fresh_large());
88 flow_var
fv_fresh_small(region r
, const char *name
)
90 return make_var(r
,name
,stamp_fresh_small());
93 const char * fv_get_name(flow_var v
)
98 gen_e_list
fv_get_lbs(flow_var v
)
100 return bounds_exprs(v
->lbs
);
103 gen_e_list
fv_get_ubs(flow_var v
)
105 return bounds_exprs(v
->ubs
);
108 bool fv_add_ub(flow_var v
, gen_e e
, stamp st
)
110 return bounds_add(v
->ubs
,e
,st
);
113 bool fv_add_lb(flow_var v
, gen_e e
, stamp st
)
115 return bounds_add(v
->lbs
,e
,st
);
118 bool fv_is_ub(flow_var v
, stamp st
)
120 bool self_edge
= v
->st
== st
,
121 in_bounds
= bounds_query(v
->ubs
,st
);
123 return (self_edge
|| in_bounds
);
126 bool fv_is_lb(flow_var v
, stamp st
)
128 bool self_edge
= v
->st
== st
,
129 in_bounds
= bounds_query(v
->lbs
,st
);
131 return (self_edge
|| in_bounds
);
134 void fv_set_alias(flow_var v
, gen_e e
)
136 assert(v
->type
== VAR_TYPE
);
138 v
->type
= ALIAS_TYPE
;
142 gen_e
fv_get_alias(flow_var v
)
147 bool fv_has_contour(flow_var v
)
149 return (get_contour(v
) != NULL
);
152 void fv_set_contour(flow_var v
, contour c
)
154 contour_elt_update(v
->elt
,c
);
157 static contour
combine_contour(contour c1
, contour c2
)
166 fail("Attempt to unify two distinct contours\n");
171 void fv_unify_contour(flow_var v1
, flow_var v2
)
173 contour_elt_unify(combine_contour
,v1
->elt
,v2
->elt
);
177 gen_e
fv_instantiate_contour(flow_var v
) deletes
179 contour c
= get_contour(v
);
180 return c
->instantiate(c
->fresh
,c
->get_stamp
,c
->shape
);