ack/mach/proto/cg/equiv.c

104 lines
1.8 KiB
C
Raw Normal View History

2019-05-10 17:11:54 +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".
*
* Author: Hans van Staveren
*/
1984-05-18 21:27:39 +00:00
#include "assert.h"
#include "equiv.h"
#include "param.h"
#include "tables.h"
#include "types.h"
#include <cg_pattern.h>
#include "data.h"
#include "result.h"
#include "extern.h"
2019-05-10 17:11:54 +00:00
#include "subr.h"
#include "salloc.h"
#include "reg.h"
1984-05-18 21:27:39 +00:00
int rar[MAXCREG];
rl_p* lar;
1984-05-18 21:27:39 +00:00
int maxindex;
int regclass[NREGS];
struct perm* perms;
1984-05-18 21:27:39 +00:00
2019-05-10 17:11:54 +00:00
static void permute(int index);
struct perm* tuples(rl_p* regls, int nregneeded)
{
int class = 0;
2019-05-10 17:11:54 +00:00
register int i, j;
1984-05-18 21:27:39 +00:00
/*
* First compute equivalence classes of registers.
*/
for (i = 0; i < NREGS; i++)
{
regclass[i] = class ++;
if (getrefcount(i, FALSE) == 0)
{
for (j = 0; j < i; j++)
{
if (eqregclass(i, j) && eqtoken(&machregs[i].r_contents,
&machregs[j].r_contents))
{
1984-05-18 21:27:39 +00:00
regclass[i] = regclass[j];
break;
}
}
}
}
/*
* Now create tuples through a recursive function
*/
maxindex = nregneeded;
lar = regls;
perms = 0;
permute(0);
return (perms);
1984-05-18 21:27:39 +00:00
}
2019-05-10 17:11:54 +00:00
static void permute(int index)
{
register struct perm* pp;
1984-05-18 21:27:39 +00:00
register rl_p rlp;
2019-05-10 17:11:54 +00:00
register int i, j;
1984-05-18 21:27:39 +00:00
if (index == maxindex)
{
for (pp = perms; pp != 0; pp = pp->p_next)
{
for (i = 0; i < maxindex; i++)
1984-05-18 21:27:39 +00:00
if (regclass[rar[i]] != regclass[pp->p_rar[i]])
goto diff;
for (i = 0; i < maxindex; i++)
for (j = 0; j < i; j++)
if (clash(rar[i], rar[j]) != clash(pp->p_rar[i], pp->p_rar[j]))
1984-05-18 21:27:39 +00:00
goto diff;
return;
diff:;
1984-05-18 21:27:39 +00:00
}
pp = (struct perm*)myalloc(sizeof(*pp));
1984-05-18 21:27:39 +00:00
pp->p_next = perms;
for (i = 0; i < maxindex; i++)
1984-05-18 21:27:39 +00:00
pp->p_rar[i] = rar[i];
perms = pp;
}
else
{
rlp = lar[index];
for (i = rlp->rl_n - 1; i >= 0; i--)
{
1984-05-18 21:27:39 +00:00
rar[index] = rlp->rl_list[i];
permute(index + 1);
1984-05-18 21:27:39 +00:00
}
}
}