sr_aux.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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(line_p lnp, lset vars)
  23. {
  24. Lindex i;
  25. assert(TYPE(lnp) == OPSHORT || TYPE(lnp) == OPOFFSET);
  26. if (!is_regvar(off_set(lnp))) return FALSE;
  27. for (i = Lfirst(vars); i != (Lindex) 0; i = Lnext(i,vars)) {
  28. if (same_local(Lelem(i),lnp)) {
  29. return FALSE; /* variable was changed */
  30. }
  31. }
  32. return TRUE;
  33. }
  34. bool is_caddress(line_p lnp, lset vars)
  35. {
  36. /* See if lnp is a single instruction (i.e. without arguments)
  37. * that pushes a loop-invariant entity of size pointer-size (ps)
  38. * on the stack.
  39. */
  40. if (lnp == (line_p) 0) return FALSE;
  41. switch(INSTR(lnp)) {
  42. case op_lae:
  43. case op_lal:
  44. return TRUE;
  45. case op_lol:
  46. return ps == ws && is_loopconst(lnp,vars);
  47. case op_ldl:
  48. return ps == 2*ws && is_loopconst(lnp,vars);
  49. default:
  50. return FALSE;
  51. }
  52. /* NOTREACHED */
  53. return FALSE;
  54. }
  55. static arg_p find_arg(int n, arg_p list)
  56. {
  57. /* Find the n-th element of the list */
  58. while (--n) {
  59. if (list == (arg_p) 0) break;
  60. list = list->a_next;
  61. }
  62. return list;
  63. }
  64. int elemsize(line_p lnp)
  65. {
  66. /* lnp is an instruction that loads the address of an array
  67. * descriptor. Find the size of the elements of the array.
  68. * If this size cannot be determined (e.g. the descriptor may
  69. * not be in a rom) then return UNKNOWN_SIZE.
  70. */
  71. dblock_p d;
  72. arg_p v;
  73. assert (lnp != (line_p) 0);
  74. if (INSTR(lnp) == op_lae) {
  75. d = OBJ(lnp)->o_dblock; /* datablock */
  76. if (d->d_pseudo == DROM &&
  77. (v = find_arg(3,d->d_values)) != (arg_p) 0 &&
  78. v->a_type == ARGOFF) {
  79. return (int) v->a_a.a_offset;
  80. }
  81. }
  82. return UNKNOWN_SIZE;
  83. }
  84. void concatenate(line_p list1, line_p list2)
  85. {
  86. /* Append list2 to the end of list1. list1 may not be empty. */
  87. line_p l;
  88. assert(list1 != (line_p) 0);
  89. for (l =list1; l->l_next != (line_p) 0; l = l->l_next);
  90. l->l_next = list2;
  91. }