1 /* $Id: il_aux.c,v 1.7 1994/06/24 10:26:07 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".
7 /* I N L I N E S U B S T I T U T I O N
16 #include "../share/types.h"
18 #include "../share/debug.h"
19 #include "../share/get.h"
20 #include "../share/put.h"
21 #include "../share/alloc.h"
22 #include "../share/global.h"
23 #include "../share/lset.h"
24 #include "../share/map.h"
31 /* Determine the size of a variable of the
36 case SINGLE: return ws;
37 case DOUBLE: return 2*ws;
38 case POINTER: return ps;
39 default: assert(FALSE);
49 /* Make a duplicate of an EM instruction.
50 * Pseudos may not be passed as argument.
55 l = newline(TYPE(lnp));
56 l->l_instr = INSTR(lnp);
61 SHORT(l) = SHORT(lnp);
64 OFFSET(l) = OFFSET(lnp);
67 INSTRLAB(l) = INSTRLAB(lnp);
76 assert(FALSE); /* cannot copy pseudo */
87 /* copy the expression */
89 line_p head, tail, l, lnp;
92 for (lnp = l1; lnp != (line_p) 0; lnp = lnp->l_next) {
94 if (head == (line_p) 0) {
115 for (act = c->cl_actuals; act != (actual_p) 0; act = nexta) {
116 nexta = act->ac_next;
117 for (l = act->ac_exp; l != (line_p) 0; l = nextl) {
125 for (; nc != (call_p) 0; nc = nextc) {
126 /* Take care of nested calls */
136 STATIC short remlines(l)
143 for (lnp = l; lnp != (line_p) 0; lnp = next) {
164 for (b = p->p_start; b != (bblock_p) 0; b = next) {
166 remlines(b->b_start);
167 Ldeleteset(b->b_loops);
168 Ldeleteset(b->b_succ);
169 Ldeleteset(b->b_pred);
172 for (pi = Lfirst(p->p_loops); pi != (Lindex) 0;
173 pi = Lnext(pi,p->p_loops)) {
176 Ldeleteset(p->p_loops);
177 oldmap(lmap,llength);
178 oldmap(lbmap,llength);
179 oldmap(bmap,blength);
180 oldmap(lpmap,lplength);
187 for (cc = head; cc != (calcnt_p) 0; cc = next) {
194 /* Extra I/O routines */
199 /* read a call from the call-file */
208 n = getshort(); /* void nesting level */
209 if (feof(curinp)) return (call_p) 0;
210 c->cl_caller = pmap[getshort()];
211 c->cl_id = getshort();
212 c->cl_proc = pmap[getshort()];
213 c->cl_looplevel = getbyte();
214 c->cl_flags = getbyte();
215 c->cl_ratio = getshort();
216 app = &c->cl_actuals;
221 act->ac_size = getoff();
222 act->ac_inl = getbyte();
223 act->ac_exp = getlines(cf,m,&voided);
233 line_p get_text(lf,p_out)
237 /* Read the EM text of one unit
238 * If it is a procedure, set p_out to
239 * the proc. just read. Else set p_out
243 line_p dumhead, l, lprev;
244 loop_p *oldlpmap = lpmap;
245 line_p *oldlmap = lmap;
246 short oldllength = llength;
247 short oldlastlabid = lastlabid;
251 dumhead = newline(OPNO);
252 /* The list of instructions is preceeded by a dummy
253 * line, to simplify list manipulation
255 dumhead->l_instr = op_nop; /* just for fun */
258 l = read_line(p_out);
259 if (feof(curinp)) return (line_p) 0;
262 if (INSTR(l) == ps_end) break;
263 if (INSTR(l) == ps_mes) {
268 /* The tables that map labels to instructions
269 * and labels to basic blocks are not used.
271 if (*p_out != (proc_p) 0) {
272 oldmap(lmap,llength);
273 oldmap(lbmap,llength);
277 llength = oldllength;
278 lastlabid = oldlastlabid;
284 calcnt_p getcc(ccf,p)
288 /* Get call-count info of procedure p */
290 calcnt_p head,cc,*ccp;
293 fseek(ccf,p->p_extend->px_il.p_ccaddr,0);
297 for (i = getshort(); i != (short) 0; i--) {
298 cc = *ccp = newcalcnt();
299 cc->cc_proc = pmap[getshort()];
300 cc->cc_count = getshort();
307 /* The following routines are only used by the Inline Substitution phase */
310 STATIC putactuals(alist,cfile)
314 /* output a list of actual parameters */
321 for (a = alist; a != (actual_p) 0; a = a->ac_next) count++;
322 outshort(count); /* number of actuals */
323 for (a = alist; a != (actual_p) 0; a = next) {
326 for (l = a->ac_exp; l != (line_p) 0; l= l->l_next) count++;
327 outshort(count); /* length of actual */
330 count = putlines(a->ac_exp,cfile);
337 putcall(c,cfile,level)
348 outshort(level); /* nesting level */
349 outshort(c->cl_caller->p_id); /* calling proc */
351 outshort(c->cl_proc->p_id); /* called proc */
352 outbyte(c->cl_looplevel);
353 outbyte(c->cl_flags);
354 outshort(c->cl_ratio);
355 putactuals(c->cl_actuals,cfile);
358 for (; nc != (call_p) 0; nc = nextc) {
359 /* take care of nested calls */
361 putcall(nc,cfile,level+1);
369 /* Write call-count information to file ccf.
370 * Return the disk address of the info written.
380 for (cc = head; cc != (calcnt_p) 0;cc = cc->cc_next) cnt++;
382 for (cc = head; cc != (calcnt_p) 0; cc = cc->cc_next) {
383 outproc(cc->cc_proc);
384 outshort(cc->cc_count);