il1_cal.c 3.1 KB

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