123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /* $Id$ */
- /*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
- /* I N L I N E S U B S T I T U T I O N
- *
- * I L 1 _ C A L . C
- */
- #include <stdio.h>
- #include <em_spec.h>
- #include <em_mnem.h>
- #include "../share/types.h"
- #include "il.h"
- #include "il1_cal.h"
- #include "../share/debug.h"
- #include "../share/alloc.h"
- #include "../share/global.h"
- #include "../share/lset.h"
- #include "il1_aux.h"
- #include "../share/parser.h"
- STATIC actual_p acts, *app;
- #define INIT_ACTS() {acts = (actual_p) 0; app = &acts;}
- #define APPEND_ACTUAL(a) {*app = a; app = &a->ac_next;}
- STATIC make_actual(l1,l2,size)
- line_p l1,l2;
- offset size;
- {
- /* Allocate a struct for a new actual parameter
- * expression, the code of which extends from
- * l1 to l2.
- */
- actual_p a;
- a = newactual();
- a->ac_exp = copy_code(l1,l2);
- a->ac_size = size;
- APPEND_ACTUAL(a); /* append it to actual-list */
- }
- STATIC bool chck_asp(p,l)
- proc_p p;
- line_p l;
- {
- /* We require a call to a procedure p that has n formal
- * parameters to be followed by an 'asp n' instruction
- * (i.e. the caller should remove the actual parameters).
- */
- return (p->p_nrformals == 0 || (l != (line_p) 0 &&INSTR(l) == op_asp &&
- TYPE(l) == OPSHORT && SHORT(l) == p->p_nrformals));
- }
- STATIC inc_count(caller,callee)
- proc_p caller, callee;
- {
- /* Update the call-count information.
- * Record the fact that there is one more call
- * to 'callee', appearing in 'caller'.
- */
- calcnt_p cc;
- if (!SUITABLE(caller)) return;
- /* if the calling routine is never expanded in line
- * we do not need call-count information.
- */
- for (cc = cchead; cc != (calcnt_p) 0; cc = cc->cc_next) {
- if (cc->cc_proc == callee) {
- cc->cc_count++;
- /* #calls to callee from caller */
- return;
- }
- }
- /* This is the first call from caller to callee.
- * Allocate a new calcnt struct.
- */
- cc = newcalcnt();
- cc->cc_proc = callee;
- cc->cc_count = 1;
- cc->cc_next = cchead; /* insert it at front of list */
- cchead = cc;
- }
- anal_cal(p,call,b,cf)
- proc_p p;
- line_p call;
- bblock_p b;
- FILE *cf;
- {
- /* Analyze a call instruction. If the called
- * routine may be expanded in line, try to
- * recognize the actual parameter expressions of
- * the call and extend the call list.
- */
- call_p c;
- line_p lnp;
- proc_p callee;
- #ifdef VERBOSE
- Scals++;
- #endif
- calnr++;
- callee = PROC(call);
- if (SUITABLE(callee)) {
- /* The called procedure may be expanded */
- callee->P_NRCALLED++; /* #calls to callee from anywhere */
- INIT_ACTS();
- if (parse(PREV(call),callee->p_nrformals,&lnp,0,make_actual) &&
- chck_asp(callee,call->l_next)) {
- /* succeeded in recognizing the actuals */
- c = newcall();
- c->cl_caller = p;
- c->cl_id = calnr;
- c->cl_proc = callee;
- c->cl_looplevel = (byte) looplevel(b);
- if (c->cl_looplevel > 0 && IS_FIRM(b)) {
- c->cl_flags |= CLF_FIRM;
- }
- c->cl_actuals = acts;
- inc_count(p,callee);
- /* update call-count info */
- putcall(c,cf,(short) 0); /* write the call to the calfile */
- } else {
- #ifdef VERBOSE
- Sparsefails++;
- #endif
- rem_actuals(acts);
- }
- }
- }
|