1 /* $Id: ra_interv.c,v 1.5 1994/06/24 10:27:39 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 /* R E G I S T E R A L L O C A T I O N
8 * R A _ I N T E R V A L . C
13 #include "../share/types.h"
14 #include "../share/debug.h"
15 #include "../share/global.h"
16 #include "../share/alloc.h"
17 #include "../share/lset.h"
19 #include "ra_interv.h"
21 interv_p cons_interval(t_start,t_stop)
34 add_interval(t1,t2,list)
38 /* Add interval (t1,t2) to the list of intervals (which is
39 * an in-out parameter!). The list is sorted in 'chronological'
40 * order. We attempt to keep the list as small as possible, by
41 * putting adjacent intervals in one interval.
44 register interv_p x1, x2, *q;
50 for (x2 = *list; x2 != (interv_p) 0; x2 = x2->i_next) {
51 if (t2 < x2->i_start) break;
55 /* Now interval (t1,t2) should be inserted somewhere in between
58 if (x1 != (interv_p) 0 && t1 == x1->i_stop + 1) {
59 /* join x1 and (t1,t2) */
63 if (x2 != (interv_p) 0 && t2 + 1 == x2->i_start) {
64 /* join (t1,t2) and x2 */
69 /* no adjacents, allocate a new intervalfor (t1,t2) */
70 x = cons_interval(t1,t2);
75 /* x1, (t1,t2) and x2 can be put in one interval */
76 x1->i_stop = x2->i_stop;
77 x1->i_next = x2->i_next;
85 interv_p loop_lifetime(lp)
88 /* Determine the timespan of the loop, expressed as a list
96 for (bi = Lfirst(lp->LP_BLOCKS); bi != (Lindex) 0;
97 bi = Lnext(bi,lp->LP_BLOCKS)) {
98 b = (bblock_p) Lelem(bi);
99 add_interval(b->B_BEGIN,b->B_END,<);
105 interv_p proc_lifetime(p)
108 /* Determine the lifetime of an entire procedure */
112 for (b = p->p_start; b->b_next != (bblock_p) 0; b = b->b_next) ;
113 return cons_interval(0,b->B_END);
118 STATIC set_min_max(iv1,iv2)
121 /* Auxiliary routine of intersect */
123 interv_p i1 = *iv1, i2 = *iv2;
125 if (i1->i_start < i2->i_start) {
136 interv_p intersect(list1,list2)
137 interv_p list1,list2;
139 /* Intersect two lifetimes, each denoted by a list of intervals.
140 * We maintain two pointers, pmin and pmax, pointing to the
141 * next interval of each list. At any time, pmin points to the
142 * interval of which i_start is lowest; pmax points to the
143 * other interval (i.e. the next interval of the other list).
149 #define BUMP(p) p = p->i_next
150 #define EMIT(t1,t2) add_interval(t1,t2,<)
154 while (pmin != (interv_p) 0 && pmax != (interv_p) 0) {
155 set_min_max(&pmin,&pmax);
156 if (pmax->i_start > pmin->i_stop) {
157 /* e.g. (5,7) and (9,13) */
160 if (pmax->i_stop < pmin->i_stop) {
161 /* e.g. (5,12) and (7,10) */
162 EMIT(pmax->i_start,pmax->i_stop);
165 /* e.g. (5,8) and (7,12) */
166 EMIT(pmax->i_start,pmin->i_stop);
167 if (pmax->i_stop == pmin->i_stop) {
168 /* e.g. (5,12) and (7,12) */
180 bool not_disjoint(list1,list2)
181 interv_p list1,list2;
183 /* See if list1 and list2 do overlap somewhere */
189 while (pmin != (interv_p) 0 && pmax != (interv_p) 0) {
190 set_min_max(&pmin,&pmax);
191 if (pmax->i_start > pmin->i_stop) {
192 /* e.g. (5,7) and (9,13) */
195 return TRUE; /* not disjoint */
198 return FALSE; /* disjoint */
203 bool contains(t,timespan)
207 register interv_p iv;
209 for (iv = timespan; iv != (interv_p) 0; iv = iv->i_next) {
210 if (t <= iv->i_stop) return (t >= iv->i_start);
217 interv_p copy_timespan(list)
220 /* copy the time span */
222 interv_p x,y,head,*p;
227 for (x = list; x != (interv_p) 0; x = x->i_next) {
228 y = cons_interval(x->i_start,x->i_stop);