il1_cal.c 3.1 KB

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