il1_cal.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* $Id$ */
  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 _ C A L . C
  9. */
  10. #include <stdio.h>
  11. #include <em_spec.h>
  12. #include <em_mnem.h>
  13. #include "../share/types.h"
  14. #include "il.h"
  15. #include "il1_cal.h"
  16. #include "../share/debug.h"
  17. #include "../share/alloc.h"
  18. #include "../share/global.h"
  19. #include "../share/lset.h"
  20. #include "il1_aux.h"
  21. #include "../share/parser.h"
  22. STATIC actual_p acts, *app;
  23. #define INIT_ACTS() {acts = (actual_p) 0; app = &acts;}
  24. #define APPEND_ACTUAL(a) {*app = a; app = &a->ac_next;}
  25. STATIC make_actual(l1,l2,size)
  26. line_p l1,l2;
  27. offset size;
  28. {
  29. /* Allocate a struct for a new actual parameter
  30. * expression, the code of which extends from
  31. * l1 to l2.
  32. */
  33. actual_p a;
  34. a = newactual();
  35. a->ac_exp = copy_code(l1,l2);
  36. a->ac_size = size;
  37. APPEND_ACTUAL(a); /* append it to actual-list */
  38. }
  39. STATIC bool chck_asp(p,l)
  40. proc_p p;
  41. line_p l;
  42. {
  43. /* We require a call to a procedure p that has n formal
  44. * parameters to be followed by an 'asp n' instruction
  45. * (i.e. the caller should remove the actual parameters).
  46. */
  47. return (p->p_nrformals == 0 || (l != (line_p) 0 &&INSTR(l) == op_asp &&
  48. TYPE(l) == OPSHORT && SHORT(l) == p->p_nrformals));
  49. }
  50. STATIC inc_count(caller,callee)
  51. proc_p caller, callee;
  52. {
  53. /* Update the call-count information.
  54. * Record the fact that there is one more call
  55. * to 'callee', appearing in 'caller'.
  56. */
  57. calcnt_p cc;
  58. if (!SUITABLE(caller)) return;
  59. /* if the calling routine is never expanded in line
  60. * we do not need call-count information.
  61. */
  62. for (cc = cchead; cc != (calcnt_p) 0; cc = cc->cc_next) {
  63. if (cc->cc_proc == callee) {
  64. cc->cc_count++;
  65. /* #calls to callee from caller */
  66. return;
  67. }
  68. }
  69. /* This is the first call from caller to callee.
  70. * Allocate a new calcnt struct.
  71. */
  72. cc = newcalcnt();
  73. cc->cc_proc = callee;
  74. cc->cc_count = 1;
  75. cc->cc_next = cchead; /* insert it at front of list */
  76. cchead = cc;
  77. }
  78. anal_cal(p,call,b,cf)
  79. proc_p p;
  80. line_p call;
  81. bblock_p b;
  82. FILE *cf;
  83. {
  84. /* Analyze a call instruction. If the called
  85. * routine may be expanded in line, try to
  86. * recognize the actual parameter expressions of
  87. * the call and extend the call list.
  88. */
  89. call_p c;
  90. line_p lnp;
  91. proc_p callee;
  92. #ifdef VERBOSE
  93. Scals++;
  94. #endif
  95. calnr++;
  96. callee = PROC(call);
  97. if (SUITABLE(callee)) {
  98. /* The called procedure may be expanded */
  99. callee->P_NRCALLED++; /* #calls to callee from anywhere */
  100. INIT_ACTS();
  101. if (parse(PREV(call),callee->p_nrformals,&lnp,0,make_actual) &&
  102. chck_asp(callee,call->l_next)) {
  103. /* succeeded in recognizing the actuals */
  104. c = newcall();
  105. c->cl_caller = p;
  106. c->cl_id = calnr;
  107. c->cl_proc = callee;
  108. c->cl_looplevel = (byte) looplevel(b);
  109. if (c->cl_looplevel > 0 && IS_FIRM(b)) {
  110. c->cl_flags |= CLF_FIRM;
  111. }
  112. c->cl_actuals = acts;
  113. inc_count(p,callee);
  114. /* update call-count info */
  115. putcall(c,cf,(short) 0); /* write the call to the calfile */
  116. } else {
  117. #ifdef VERBOSE
  118. Sparsefails++;
  119. #endif
  120. rem_actuals(acts);
  121. }
  122. }
  123. }