summaryrefslogtreecommitdiff
path: root/libbanshee/engine/setst-var.c
blob: ba4c59eb5de20af2347327909a753c4e17f0e704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Copyright (c) 2000-2001
 *      The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include <stdio.h>
#include <assert.h>
#include <regions.h>
#include "setst-var.h"
#include "jcollection.h"
#include "ufind.h"
#include "bounds.h"

struct st_info
{
  stamp st;
  bounds lbs;
  bounds sources;
  bounds sinks;
  jcoll tlb_cache;
  const char *name;
  bool seen;
  int path_pos;
  int src_sz;
  int snk_sz;
};

typedef struct st_info *st_info;

DECLARE_UFIND(st_elt,st_info)

DEFINE_UFIND(st_elt,st_info)

DEFINE_LIST(setst_var_list,setst_var)

#define get_info(v) (st_elt_get_info((v)->elt))

struct setst_var /* extends gen_e */
{
#ifdef NONSPEC
  sort_kind sort;
#endif
  int type;
  st_elt elt;
};

bool st_eq(setst_var v1, setst_var v2)
{
  return (st_get_stamp(v1) == st_get_stamp(v2));
}

static setst_var make_var(region r, const char *name, stamp st)
{
  setst_var result = ralloc(r,struct setst_var);
  st_info info = ralloc(r, struct st_info);

  info->st = st;
  info->lbs = bounds_create(r);
  info->sources = bounds_create(r);
  info->sinks = bounds_create(r);
  info->tlb_cache = NULL;
  info->name = name ? rstrdup(r,name) : "fv";
  info->seen = FALSE;
  info->path_pos = 0;
  info->src_sz = 0;
  info->snk_sz = 0;

  result->type = VAR_TYPE;
  result->elt = new_st_elt(r,info);


#ifdef NONSPEC
  result->sort = setst_sort;
#endif

  return result;
}

setst_var st_fresh(region r, const char *name)
{
  return make_var(r,name,stamp_fresh());
}

setst_var st_fresh_large(region r, const char *name)
{
  return make_var(r,name,stamp_fresh_large());
}

setst_var st_fresh_small(region r, const char *name)
{
  return make_var(r,name,stamp_fresh_small());
}

stamp st_get_stamp(setst_var v)
{
  return get_info(v)->st;
}

const char *st_get_name(setst_var v)
{
  return get_info(v)->name;
}

void st_unify(setst_var v,setst_var_list vars)
{
  setst_var temp;
  setst_var_list_scanner scan;

  setst_var_list_scan(vars,&scan);

  while (setst_var_list_next(&scan,&temp)) 
    {
      st_elt_union(v->elt,temp->elt);
    }
}

setst_var_list st_get_lbs(setst_var v)
{
  return (setst_var_list)bounds_exprs(get_info(v)->lbs);
}

gen_e_list st_get_sources(setst_var v)
{
  return bounds_exprs(get_info(v)->sources);
}

gen_e_list st_get_sinks(setst_var v)
{
  return bounds_exprs(get_info(v)->sinks);
}

bool st_add_lb(setst_var v, setst_var lb)
{
  return bounds_add(get_info(v)->lbs,(gen_e)lb,st_get_stamp(lb));
}

bool st_add_source(setst_var v, gen_e source, stamp s)
{
  return bounds_add(get_info(v)->sources,source,s);
}

bool st_add_sink(setst_var v, gen_e sink, stamp s)
{
  return bounds_add(get_info(v)->sinks,sink,s);
}

jcoll st_get_tlb_cache(setst_var v)
{
  return get_info(v)->tlb_cache;
}

void st_set_tlb_cache(setst_var v, jcoll j)
{
  get_info(v)->tlb_cache = j;
}

void st_clear_tlb_cache(setst_var v)
{
  get_info(v)->tlb_cache = NULL;
}

gen_e st_get_ub_proj(setst_var v, get_proj_fn_ptr get_proj)
{
  return get_proj(st_get_sinks(v));
}
static setst_var neq_temp;
static bool neq (const setst_var v2)
{
  return (!(st_get_stamp (neq_temp) == st_get_stamp (v2)));
}
void st_repair_bounds(setst_var v1)
{
  setst_var_list lbs;
  neq_temp = v1;
  lbs = setst_var_list_filter2(st_get_lbs(v1),neq);  

  bounds_set(get_info(v1)->lbs,(gen_e_list)lbs);
}

void st_set_path_pos(setst_var v, int pos)
{
  get_info(v)->path_pos = pos;
}

int st_get_path_pos(setst_var v)
{
  return get_info(v)->path_pos;
}

void st_set_seen(setst_var v, bool b)
{
  get_info(v)->seen = b;
}

bool st_get_seen(setst_var v)
{
  return get_info(v)->seen;
}

void st_set_src_sz(setst_var v, int size)
{
  get_info(v)->src_sz = size;
}

int st_get_src_sz(setst_var v)
{
  return get_info(v)->src_sz;
}

void st_set_snk_sz(setst_var v, int size)
{
  get_info(v)->snk_sz = size;
}

int st_get_snk_sz(setst_var v)
{
  return get_info(v)->snk_sz;
}