sr_aux.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /* S T R E N G T H R E D U C T I O N
  7. *
  8. * S R _ A U X . C
  9. *
  10. */
  11. #include <em_mnem.h>
  12. #include <em_pseu.h>
  13. #include "../share/types.h"
  14. #include "sr.h"
  15. #include "../share/debug.h"
  16. #include "../share/global.h"
  17. #include "../share/lset.h"
  18. #include "../share/aux.h"
  19. #include "sr_aux.h"
  20. #include "sr_xform.h"
  21. #define INSIDE_LOOP(b,lp) Lis_elem(b,lp->LP_BLOCKS)
  22. bool is_loopconst(lnp,vars)
  23. line_p lnp;
  24. lset vars;
  25. {
  26. Lindex i;
  27. assert(TYPE(lnp) == OPSHORT || TYPE(lnp) == OPOFFSET);
  28. if (!is_regvar(off_set(lnp))) return FALSE;
  29. for (i = Lfirst(vars); i != (Lindex) 0; i = Lnext(i,vars)) {
  30. if (same_local(Lelem(i),lnp)) {
  31. return FALSE; /* variable was changed */
  32. }
  33. }
  34. return TRUE;
  35. }
  36. bool is_caddress(lnp,vars)
  37. line_p lnp;
  38. lset vars; /* variables changed in loop */
  39. {
  40. /* See if lnp is a single instruction (i.e. without arguments)
  41. * that pushes a loop-invariant entity of size pointer-size (ps)
  42. * on the stack.
  43. */
  44. if (lnp == (line_p) 0) return FALSE;
  45. switch(INSTR(lnp)) {
  46. case op_lae:
  47. case op_lal:
  48. return TRUE;
  49. case op_lol:
  50. return ps == ws && is_loopconst(lnp,vars);
  51. case op_ldl:
  52. return ps == 2*ws && is_loopconst(lnp,vars);
  53. default:
  54. return FALSE;
  55. }
  56. /* NOTREACHED */
  57. }
  58. STATIC arg_p find_arg(n,list)
  59. int n;
  60. arg_p list;
  61. {
  62. /* Find the n-th element of the list */
  63. while (--n) {
  64. if (list == (arg_p) 0) break;
  65. list = list->a_next;
  66. }
  67. return list;
  68. }
  69. int elemsize(lnp)
  70. line_p lnp;
  71. {
  72. /* lnp is an instruction that loads the address of an array
  73. * descriptor. Find the size of the elements of the array.
  74. * If this size cannot be determined (e.g. the descriptor may
  75. * not be in a rom) then return UNKNOWN_SIZE.
  76. */
  77. dblock_p d;
  78. arg_p v;
  79. assert (lnp != (line_p) 0);
  80. if (INSTR(lnp) == op_lae) {
  81. d = OBJ(lnp)->o_dblock; /* datablock */
  82. if (d->d_pseudo == DROM &&
  83. (v = find_arg(3,d->d_values)) != (arg_p) 0 &&
  84. v->a_type == ARGOFF) {
  85. return (int) v->a_a.a_offset;
  86. }
  87. }
  88. return UNKNOWN_SIZE;
  89. }
  90. concatenate(list1,list2)
  91. line_p list1,list2;
  92. {
  93. /* Append list2 to the end of list1. list1 may not be empty. */
  94. register line_p l;
  95. assert(list1 != (line_p) 0);
  96. for (l =list1; l->l_next != (line_p) 0; l = l->l_next);
  97. l->l_next = list2;
  98. }