il1_aux.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 _ A U X . C
  9. */
  10. #include <em_spec.h>
  11. #include "../share/types.h"
  12. #include "il.h"
  13. #include "../share/debug.h"
  14. #include "../share/alloc.h"
  15. #include "../share/global.h"
  16. #include "../share/lset.h"
  17. #include "il_aux.h"
  18. #include "il1_aux.h"
  19. #define USE_INDIR(p) (p->p_use->u_flags & UF_INDIR)
  20. #define IS_INSTR(c) (c >= sp_fmnem && c <= sp_lmnem)
  21. bool same_size(t1,t2)
  22. int t1, t2;
  23. {
  24. /* See if the two types have the same size */
  25. return tsize(t1) == tsize(t2);
  26. }
  27. STATIC bool is_reg(off,s)
  28. offset off;
  29. int s;
  30. {
  31. /* See if there is a register message
  32. * for the local or parameter at offset off
  33. * and size s.
  34. */
  35. Lindex i;
  36. arg_p arg;
  37. for (i = Lfirst(mesregs); i != (Lindex) 0; i = Lnext(i,mesregs)) {
  38. arg = ((line_p) Lelem(i))->l_a.la_arg->a_next;
  39. if (arg->a_a.a_offset == off &&
  40. arg->a_next->a_a.a_offset == s) {
  41. return TRUE;
  42. }
  43. }
  44. return FALSE;
  45. }
  46. rem_actuals(acts)
  47. actual_p acts;
  48. {
  49. /* remove the actual-list */
  50. actual_p a,next;
  51. for (a = acts; a != (actual_p) 0; a = next) {
  52. next = a->ac_next;
  53. /* REMOVE CODE OF a->ac_exp HERE */
  54. oldactual(a);
  55. }
  56. }
  57. remov_formals(p)
  58. proc_p p;
  59. {
  60. /* Remove the list of formals of p */
  61. formal_p f, next;
  62. for (f = p->P_FORMALS; f != (formal_p) 0; f = next) {
  63. next = f->f_next;
  64. oldformal(f);
  65. }
  66. p->P_FORMALS = (formal_p) 0;
  67. }
  68. rem_indir_acc(p)
  69. proc_p p;
  70. {
  71. /* Formals that may be accessed indirectly
  72. * cannot be expanded in line, so they are
  73. * removed from the formals list.
  74. */
  75. formal_p prev, f, next;
  76. if (!USE_INDIR(p) && !CHANGE_INDIR(p)) return;
  77. /* Any formal for which we don't have
  78. * a register message is now doomed.
  79. */
  80. prev = (formal_p) 0;
  81. for (f = p->P_FORMALS; f != (formal_p) 0; f = next) {
  82. next = f->f_next;
  83. if (!is_reg(f->f_offset,tsize(f->f_type))) {
  84. if (prev == (formal_p) 0) {
  85. p->P_FORMALS = next;
  86. } else {
  87. prev->f_next = next;
  88. }
  89. oldformal(f);
  90. }
  91. }
  92. }
  93. bool par_overlap(off1,t1,off2,t2)
  94. offset off1,off2;
  95. int t1,t2;
  96. {
  97. /* See if the parameter at offset off1 and type t1
  98. * overlaps the paramete at offset off2 and type t2.
  99. */
  100. if (off1 > off2) {
  101. return off2 + tsize(t2) > off1;
  102. } else {
  103. if (off2 > off1) {
  104. return off1 + tsize(t1) > off2;
  105. } else {
  106. return TRUE;
  107. }
  108. }
  109. }
  110. short looplevel(b)
  111. bblock_p b;
  112. {
  113. /* determine the loop nesting level of basic block b;
  114. * this is the highest nesting level of all blocks
  115. * that b is part of.
  116. * Note that the level of a loop is 0 for outer loops,
  117. * so a block inside a loop with nesting level N has
  118. * looplevel N+1.
  119. */
  120. Lindex i;
  121. short max = 0;
  122. for (i = Lfirst(b->b_loops); i != (Lindex)0; i = Lnext(i,b->b_loops)) {
  123. if (((loop_p) Lelem(i))->lp_level >= max) {
  124. max = ((loop_p) Lelem(i))->lp_level + 1;
  125. }
  126. }
  127. return max;
  128. }
  129. int proclength(p)
  130. proc_p p;
  131. {
  132. /* count the number of EM instructions of p */
  133. register int cnt;
  134. register bblock_p b;
  135. register line_p l;
  136. cnt = 0;
  137. for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
  138. for (l = b->b_start; l != (line_p) 0; l = l->l_next) {
  139. if (IS_INSTR(INSTR(l))) {
  140. /* skip pseudo instructions */
  141. cnt++;
  142. }
  143. }
  144. }
  145. return cnt;
  146. }
  147. line_p copy_code(l1,l2)
  148. line_p l1,l2;
  149. {
  150. /* copy the code between l1 and l2 */
  151. line_p head, tail, l, lnp;
  152. head = (line_p) 0;
  153. for (lnp = l1; ; lnp = lnp->l_next) {
  154. l = duplicate(lnp);
  155. if (head == (line_p) 0) {
  156. head = tail = l;
  157. PREV(l) = (line_p) 0;
  158. } else {
  159. tail->l_next = l;
  160. PREV(l) = tail;
  161. tail = l;
  162. }
  163. if (lnp == l2) break;
  164. }
  165. return head;
  166. }