il1_aux.c 3.7 KB

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