1 /* $Id: aux.c,v 1.6 1994/06/24 10:29:26 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".
8 * A U X I L I A R Y R O U T I N E S
25 switch(lnp->l_optype) {
27 return (offset) SHORT(lnp);
48 error("too few parameters");
49 if (ap->a_type != ARGOFF)
50 error("offset expected");
51 return(ap->a_a.a_offset);
55 offset tmplocal(p,size)
59 /* Allocate a new local variable in the stack frame of p */
61 p->p_localbytes += size;
62 return -(p->p_localbytes);
71 /* Allocate a line struct of type OPSHORT or OPOFFSET,
72 * whichever one fits best.
77 if ((short) off == off) {
79 lnp = newline(OPSHORT);
80 SHORT(lnp) = (short) off;
82 lnp = newline(OPOFFSET);
90 line_p reg_mes(tmp,size,typ,score)
95 /* Generate a register message */
100 #define NEXTARG(a,val) a->a_next = newarg(ARGOFF); a = a->a_next; \
101 a->a_a.a_offset = val
104 a = ARG(l) = newarg(ARGOFF);
105 a->a_a.a_offset = ms_reg;
117 /* See if b1 dominates b2. Note that a block always
123 for (b = b2; b != (bblock_p) 0; b = b->b_idom) {
124 /* See if b1 is a (not necessarily proper) ancestor
125 * of b2 in the immediate dominator tree.
127 if (b == b1) return TRUE;
133 bblock_p common_dom(a,b)
136 /* find a basic block that dominates a as well as b;
137 * note that a basic block also dominates itself.
140 assert (a != (bblock_p) 0);
141 assert (b != (bblock_p) 0);
148 return common_dom(a->b_idom,b->b_idom);
153 #define R time_space_ratio
155 short add_timespace(time,space)
158 /* Add together a time and space, using the time_space_ratio
159 * parameter that may be set by the user, indicating the need
160 * to optimize for time, space or something in between.
163 return (R * time + (100 - R) * space) / 100;
172 if (b->b_start == l) {
173 b->b_start = l->l_next;
175 PREV(l)->l_next = l->l_next;
177 if (l->l_next != (line_p) 0) {
178 PREV(l->l_next) = PREV(l);
189 /* Put l1 after l2 */
192 l1->l_next = l2->l_next;
194 if (l1->l_next != (line_p) 0) {
195 PREV(l1->l_next) = l1;
204 /* Determine the last line of a list */
206 register line_p l = b->b_start;
208 if (l == (line_p) 0) return (line_p) 0;
209 while (l->l_next != (line_p) 0) l = l->l_next;
216 line_p find_mesreg(off)
219 /* Find the register message for the local with the given offset */
224 for (li = Lfirst(mesregs); li != (Lindex) 0; li = Lnext(li,mesregs)) {
225 l = (line_p) Lelem(li);
226 if (aoff(ARG(l),1) == off) return l;
235 return find_mesreg(off) != (line_p) 0;
240 offset regv_arg(off,n)
244 /* fetch the n'th argument of the register message of the
245 * local variable at offset off;
248 line_p x = find_mesreg(off);
249 assert (x != (line_p) 0);
250 return aoff(ARG(x),n);