Pristine Ack-5.5
[Ack-5.5.git] / util / ego / il / il1_aux.c
1 /* $Id: il1_aux.c,v 1.7 1994/06/24 10:25:24 ceriel Exp $ */
2 /*
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".
5  */
6 /*  I N L I N E   S U B S T I T U T I O N
7  *
8  *  I L 1 _ A U X . C
9  */
10
11 #include <em_spec.h>
12 #include "../share/types.h"
13 #include "il.h"
14 #include "../share/debug.h"
15 #include "../share/alloc.h"
16 #include "../share/global.h"
17 #include "../share/lset.h"
18 #include "il_aux.h"
19 #include "il1_aux.h"
20
21 #define USE_INDIR(p)    (p->p_use->u_flags & UF_INDIR)
22
23 #define IS_INSTR(c)     (c >= sp_fmnem && c <= sp_lmnem)
24
25
26 bool same_size(t1,t2)
27         int t1, t2;
28 {
29         /* See if the two types have the same size */
30
31         return tsize(t1) == tsize(t2);
32 }
33
34
35
36 STATIC bool is_reg(off,s)
37         offset off;
38         int    s;
39 {
40         /* See if there is a register message
41          * for the local or parameter at offset off
42          * and size s.
43          */
44
45         Lindex i;
46         arg_p arg;
47
48         for (i = Lfirst(mesregs); i != (Lindex) 0; i = Lnext(i,mesregs)) {
49                 arg = ((line_p) Lelem(i))->l_a.la_arg->a_next;
50                 if (arg->a_a.a_offset == off &&
51                     arg->a_next->a_a.a_offset == s) {
52                         return TRUE;
53                 }
54         }
55         return FALSE;
56 }
57
58
59 rem_actuals(acts)
60         actual_p acts;
61 {
62         /* remove the actual-list */
63
64         actual_p a,next;
65
66         for (a = acts; a != (actual_p) 0; a = next) {
67                 next = a->ac_next;
68                 /* REMOVE CODE OF a->ac_exp HERE */
69                 oldactual(a);
70         }
71 }
72
73
74
75 remov_formals(p)
76         proc_p p;
77 {
78         /* Remove the list of formals of p */
79
80         formal_p f, next;
81
82         for (f = p->P_FORMALS; f != (formal_p) 0; f = next) {
83                 next = f->f_next;
84                 oldformal(f);
85         }
86         p->P_FORMALS = (formal_p) 0;
87 }
88
89
90
91 rem_indir_acc(p)
92         proc_p p;
93 {
94         /* Formals that may be accessed indirectly
95          * cannot be expanded in line, so they are
96          * removed from the formals list.
97          */
98
99         formal_p prev, f, next;
100
101         if (!USE_INDIR(p) && !CHANGE_INDIR(p)) return;
102         /* Any formal for which we don't have
103          * a register message is now doomed.
104          */
105         prev = (formal_p) 0;
106         for (f = p->P_FORMALS; f != (formal_p) 0; f = next) {
107                 next = f->f_next;
108                 if (!is_reg(f->f_offset,tsize(f->f_type))) {
109                         if (prev == (formal_p) 0) {
110                                 p->P_FORMALS = next;
111                         } else {
112                                 prev->f_next = next;
113                         }
114                         oldformal(f);
115                 }
116         }
117 }
118
119
120
121 bool par_overlap(off1,t1,off2,t2)
122         offset off1,off2;
123         int    t1,t2;
124 {
125         /* See if the parameter at offset off1 and type t1
126          * overlaps the paramete at offset off2 and type t2.
127          */
128
129         if (off1 > off2) {
130                 return off2 + tsize(t2) > off1;
131         } else {
132                 if (off2 > off1) {
133                         return off1 + tsize(t1) > off2;
134                 } else {
135                         return TRUE;
136                 }
137         }
138 }
139
140
141
142 short looplevel(b)
143         bblock_p b;
144 {
145         /* determine the loop nesting level of basic block b;
146          * this is the highest nesting level of all blocks
147          * that b is part of.
148          * Note that the level of a loop is 0 for outer loops,
149          * so a block inside a loop with nesting level N has
150          * looplevel N+1.
151          */
152
153         Lindex i;
154         short max = 0;
155
156         for (i = Lfirst(b->b_loops); i != (Lindex)0; i = Lnext(i,b->b_loops)) {
157                 if (((loop_p) Lelem(i))->lp_level >= max) {
158                         max = ((loop_p) Lelem(i))->lp_level + 1;
159                 }
160         }
161         return max;
162 }
163
164
165
166 int proclength(p)
167         proc_p p;
168 {
169         /* count the number of EM instructions of p */
170
171         register int cnt;
172         register bblock_p b;
173         register line_p l;
174
175         cnt = 0;
176         for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
177                 for (l = b->b_start; l != (line_p) 0; l = l->l_next) {
178                         if (IS_INSTR(INSTR(l))) {
179                                 /* skip pseudo instructions */
180                                 cnt++;
181                         }
182                 }
183         }
184         return cnt;
185 }
186
187
188
189
190
191 line_p copy_code(l1,l2)
192         line_p l1,l2;
193 {
194         /* copy the code between l1 and l2 */
195
196         line_p head, tail, l, lnp;
197
198         head = (line_p) 0;
199         for (lnp = l1; ; lnp = lnp->l_next) {
200                 l = duplicate(lnp);
201                 if (head == (line_p) 0) {
202                         head = tail = l;
203                         PREV(l) = (line_p) 0;
204                 } else {
205                         tail->l_next = l;
206                         PREV(l) = tail;
207                         tail = l;
208                 }
209                 if (lnp == l2) break;
210         }
211         return head;
212 }