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];
|
2018-06-02 19:31:18 +00:00
|
|
|
rl_p* lar;
|
1984-05-18 21:27:39 +00:00
|
|
|
int maxindex;
|
|
|
|
int regclass[NREGS];
|
2018-06-02 19:31:18 +00:00
|
|
|
struct perm* perms;
|
1984-05-18 21:27:39 +00:00
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
static void permute(int index);
|
2018-06-02 19:31:18 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-06-02 19:31:18 +00:00
|
|
|
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);
|
2018-06-02 19:31:18 +00:00
|
|
|
return (perms);
|
1984-05-18 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:11:54 +00:00
|
|
|
static void permute(int index)
|
2018-06-02 19:31:18 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2018-06-02 19:31:18 +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;
|
2018-06-02 19:31:18 +00:00
|
|
|
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;
|
2018-06-02 19:31:18 +00:00
|
|
|
diff:;
|
1984-05-18 21:27:39 +00:00
|
|
|
}
|
2018-06-02 19:31:18 +00:00
|
|
|
pp = (struct perm*)myalloc(sizeof(*pp));
|
1984-05-18 21:27:39 +00:00
|
|
|
pp->p_next = perms;
|
2018-06-02 19:31:18 +00:00
|
|
|
for (i = 0; i < maxindex; i++)
|
1984-05-18 21:27:39 +00:00
|
|
|
pp->p_rar[i] = rar[i];
|
|
|
|
perms = pp;
|
2018-06-02 19:31:18 +00:00
|
|
|
}
|
|
|
|
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];
|
2018-06-02 19:31:18 +00:00
|
|
|
permute(index + 1);
|
1984-05-18 21:27:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|