il1_aux.c 3.6 KB

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