equiv.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Id$";
  3. #endif
  4. #include "assert.h"
  5. #include "equiv.h"
  6. #include "param.h"
  7. #include "tables.h"
  8. #include "types.h"
  9. #include <cg_pattern.h>
  10. #include "data.h"
  11. #include "result.h"
  12. #include "extern.h"
  13. /*
  14. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  15. * See the copyright notice in the ACK home directory, in the file "Copyright".
  16. *
  17. * Author: Hans van Staveren
  18. */
  19. extern string myalloc();
  20. int rar[MAXCREG];
  21. rl_p *lar;
  22. int maxindex;
  23. int regclass[NREGS];
  24. struct perm *perms;
  25. struct perm *
  26. tuples(regls,nregneeded) rl_p *regls; {
  27. int class=0;
  28. register i,j;
  29. /*
  30. * First compute equivalence classes of registers.
  31. */
  32. for (i=0;i<NREGS;i++) {
  33. regclass[i] = class++;
  34. if (getrefcount(i, FALSE) == 0) {
  35. for (j=0;j<i;j++) {
  36. if (eqregclass(i,j) &&
  37. eqtoken(&machregs[i].r_contents,
  38. &machregs[j].r_contents)) {
  39. regclass[i] = regclass[j];
  40. break;
  41. }
  42. }
  43. }
  44. }
  45. /*
  46. * Now create tuples through a recursive function
  47. */
  48. maxindex = nregneeded;
  49. lar = regls;
  50. perms = 0;
  51. permute(0);
  52. return(perms);
  53. }
  54. permute(index) {
  55. register struct perm *pp;
  56. register rl_p rlp;
  57. register i,j;
  58. if (index == maxindex) {
  59. for (pp=perms; pp != 0; pp=pp->p_next) {
  60. for (i=0; i<maxindex; i++)
  61. if (regclass[rar[i]] != regclass[pp->p_rar[i]])
  62. goto diff;
  63. for (i=0; i<maxindex; i++)
  64. for (j=0; j<i; j++)
  65. if (clash(rar[i],rar[j]) !=
  66. clash(pp->p_rar[i],pp->p_rar[j]))
  67. goto diff;
  68. return;
  69. diff: ;
  70. }
  71. pp = (struct perm *) myalloc(sizeof ( *pp ));
  72. pp->p_next = perms;
  73. for (i=0; i<maxindex; i++)
  74. pp->p_rar[i] = rar[i];
  75. perms = pp;
  76. } else {
  77. rlp=lar[index];
  78. for (i=rlp->rl_n-1; i>=0; i--) {
  79. rar[index] = rlp->rl_list[i];
  80. permute(index+1);
  81. }
  82. }
  83. }