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