il1_formal.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 _ F O R M A L . C
  9. */
  10. #include "../share/types.h"
  11. #include "il.h"
  12. #include "../share/debug.h"
  13. #include "../share/alloc.h"
  14. #include "../share/global.h"
  15. #include "../share/lset.h"
  16. #include "il1_aux.h"
  17. #include "il1_formal.h"
  18. #define NOT_USED(f) (!(f->f_flags & USEMASK))
  19. #define USED_ONCE(f) f->f_flags |= FF_ONCEUSED
  20. #define USED_OFTEN(f) f->f_flags |= FF_OFTENUSED
  21. #define BADFORMAL(f) f->f_flags |= FF_BAD
  22. #define OUTSIDE_LOOP(b) (Lnrelems(b->b_loops) == 0)
  23. #define IS_FORMAL(x) (x >= 0)
  24. formal_p find_formal(p,type,off)
  25. proc_p p;
  26. int type;
  27. offset off;
  28. {
  29. /* Find a formal parameter of p
  30. * If the formal overlaps with an existing formal
  31. * or has an unknown type (i.e. its address is used)
  32. * 0 is returned.
  33. */
  34. formal_p f,prev,nf;
  35. if (type == UNKNOWN) return (formal_p) 0;
  36. prev = (formal_p) 0;
  37. for (f = p->P_FORMALS; f != (formal_p) 0; f = f->f_next) {
  38. if (f->f_offset >= off) break;
  39. prev = f;
  40. }
  41. if (f != (formal_p) 0 && f->f_offset == off) {
  42. return (same_size(f->f_type,type) ? f : (formal_p) 0);
  43. }
  44. if (f != (formal_p) 0 && par_overlap(off,type,f->f_offset,f->f_type)) {
  45. return (formal_p) 0;
  46. }
  47. if (prev != (formal_p) 0 && par_overlap(prev->f_offset,prev->f_type,
  48. off,type)) {
  49. return (formal_p) 0;
  50. }
  51. nf = newformal();
  52. nf->f_type = type;
  53. nf->f_offset = off;
  54. if (prev == (formal_p) 0) {
  55. p->P_FORMALS = nf;
  56. } else {
  57. prev->f_next = nf;
  58. }
  59. nf->f_next = f;
  60. return nf;
  61. }
  62. STATIC no_inl_pars(p)
  63. proc_p p;
  64. {
  65. /* p may not have any in line parameters */
  66. p->p_flags2 |= PF_NO_INLPARS;
  67. remov_formals(p);
  68. }
  69. STATIC inc_use(f,b)
  70. formal_p f;
  71. bblock_p b;
  72. {
  73. /* Increment the use count of formal f.
  74. * The counter has only three states: not used,
  75. * used once, used more than once.
  76. * We count the number of times the formal
  77. * is used dynamically (rather than statically),
  78. * so if it is used in a loop, the counter
  79. * is always set to more than once.
  80. */
  81. if (NOT_USED(f) && OUTSIDE_LOOP(b)) {
  82. USED_ONCE(f);
  83. } else {
  84. USED_OFTEN(f);
  85. }
  86. }
  87. formal(p,b,off,type,usage)
  88. proc_p p;
  89. bblock_p b;
  90. offset off;
  91. int type,
  92. usage;
  93. {
  94. /* Analyze a reference to a parameter of p
  95. * (occurring within basic block b).
  96. * The parameter has offset off. If this
  97. * offset is less than 0, it is not a
  98. * parameter, but a local.
  99. * The type can be SINGLE (1 word), DOUBLE
  100. * (2 words), POINTER or UNKNOWN.
  101. */
  102. formal_p f;
  103. if (!IS_FORMAL(off) || !SUITABLE(p) || !INLINE_PARS(p)) return;
  104. /* We are not interested in formal parameters of
  105. * proccedures that will never be expanded in line,
  106. * or whose parameters will not be expanded in line.
  107. */
  108. f = find_formal(p,type,off);
  109. /* Find the formal; if not found, create one;
  110. * if inconsistent with previous formals (e.g.
  111. * overlapping formals) then return 0;
  112. * also fills in its type.
  113. */
  114. if (f == (formal_p) 0) {
  115. no_inl_pars(p);
  116. /* parameters of p may not be expanded in line */
  117. } else {
  118. if (usage == CHANGE) {
  119. /* don't expand f in line */
  120. BADFORMAL(f);
  121. } else {
  122. inc_use(f,b); /* increment use count */
  123. }
  124. }
  125. }