ack/mach/proto/ncg/equiv.c

98 lines
1.9 KiB
C
Raw Normal View History

1985-01-08 15:34:54 +00:00
#ifndef NORCSID
1994-06-24 14:02:31 +00:00
static char rcsid[] = "$Id$";
1985-01-08 15:34:54 +00:00
#endif
#include "assert.h"
#include "equiv.h"
#include "param.h"
#include "tables.h"
#include "types.h"
#include <cgg_cg.h>
#include "data.h"
#include "result.h"
#include "extern.h"
/*
1987-03-10 01:26:51 +00:00
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
1985-01-08 15:34:54 +00:00
*
* Author: Hans van Staveren
*/
extern string myalloc();
int rar[MAXCREG];
rl_p *lar;
int maxindex;
int regclass[NREGS];
struct perm *perms;
struct perm *
tuples(regls,nregneeded) rl_p *regls; {
int class=0;
register i,j;
1991-01-11 10:54:03 +00:00
register struct reginfo *rp;
1985-01-08 15:34:54 +00:00
/*
* First compute equivalence classes of registers.
*/
1991-01-11 10:54:03 +00:00
for (i=NREGS, rp = &machregs[NREGS-1];--i>=0;rp--) {
1985-01-08 15:34:54 +00:00
regclass[i] = class++;
if (getrefcount(i, FALSE) == 0) {
for (j=NREGS;--j>i;) {
1985-01-08 15:34:54 +00:00
if (eqregclass(i,j) &&
1991-01-11 10:54:03 +00:00
eqtoken(&rp->r_contents,
1985-01-08 15:34:54 +00:00
&machregs[j].r_contents)) {
regclass[i] = regclass[j];
break;
}
}
}
}
/*
* Now create tuples through a recursive function
*/
maxindex = nregneeded;
lar = regls;
perms = 0;
permute(0);
return(perms);
}
permute(index) {
register struct perm *pp;
register rl_p rlp;
register i,j;
if (index == maxindex) {
for (pp=perms; pp != 0; pp=pp->p_next) {
for (i=0; i<maxindex; i++)
if (regclass[rar[i]] != regclass[pp->p_rar[i]])
goto diff;
1991-01-11 10:54:03 +00:00
for (i=0; i<maxindex; i++) {
int rari = rar[i], p_rari = pp->p_rar[i];
1985-01-08 15:34:54 +00:00
for (j=0; j<i; j++)
1991-01-11 10:54:03 +00:00
if (clash(rari,rar[j]) !=
clash(p_rari,pp->p_rar[j]))
1985-01-08 15:34:54 +00:00
goto diff;
1991-01-11 10:54:03 +00:00
}
1985-01-08 15:34:54 +00:00
return;
diff: ;
}
pp = (struct perm *) myalloc(sizeof ( *pp ));
pp->p_next = perms;
for (i=0; i<maxindex; i++)
pp->p_rar[i] = rar[i];
perms = pp;
} else {
rlp=lar[index];
for (i=rlp->rl_n; i>0; i--) {
rar[index] = rlp->rl_list[rlp->rl_n-i];
1985-01-08 15:34:54 +00:00
permute(index+1);
}
}
}