ack/mach/proto/cg/reg.c

180 lines
3.6 KiB
C
Raw Permalink 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 "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 "reg.h"
1984-05-18 21:27:39 +00:00
2019-05-10 17:11:54 +00:00
/* Froward local declarations */
static void awayreg(int);
1984-05-18 21:27:39 +00:00
2019-05-10 17:11:54 +00:00
void chrefcount(int regno, int amount, int tflag)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
2019-05-10 17:11:54 +00:00
register int i;
1984-05-18 21:27:39 +00:00
rp= &machregs[regno];
#if MAXMEMBERS!=0
if (rp->r_members[0]==0) {
#endif
rp->r_refcount += amount;
if (tflag)
rp->r_tcount += amount;
assert(rp->r_refcount >= 0);
#if MAXMEMBERS!=0
} else
for (i=0;i<MAXMEMBERS;i++)
if (rp->r_members[i]!=0)
chrefcount(rp->r_members[i],amount,tflag);
#endif
}
2019-05-10 17:11:54 +00:00
int getrefcount(int regno, int tflag)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
2019-05-10 17:11:54 +00:00
register int i,maxcount;
1984-05-18 21:27:39 +00:00
rp= &machregs[regno];
#if MAXMEMBERS!=0
if (rp->r_members[0]==0)
#endif
return(rp->r_refcount - (tflag ? rp->r_tcount : 0));
1984-05-18 21:27:39 +00:00
#if MAXMEMBERS!=0
else {
maxcount=0;
for (i=0;i<MAXMEMBERS;i++)
if (rp->r_members[i]!=0)
maxcount=max(maxcount,getrefcount(rp->r_members[i], tflag));
1984-05-18 21:27:39 +00:00
return(maxcount);
}
#endif
}
2019-05-10 17:11:54 +00:00
void erasereg(int regno)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
register int i;
rp = &machregs[regno];
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0;
1984-05-18 21:27:39 +00:00
#if MAXMEMBERS == 0
awayreg(regno);
1984-05-18 21:27:39 +00:00
#else
1987-03-05 17:40:48 +00:00
if (regno == 1) { /* condition codes */
} else
1984-05-18 21:27:39 +00:00
for (rp=machregs;rp<machregs+NREGS;rp++)
1987-02-20 17:33:06 +00:00
if (rp->r_clash[regno>>4]&(1<<(regno&017))) {
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0;
1990-04-25 14:23:05 +00:00
awayreg((int)(rp-machregs));
1987-02-20 17:33:06 +00:00
}
#endif
}
2019-05-10 17:11:54 +00:00
static void awayreg(int regno)
{
register struct reginfo *rp;
register tkdef_p tdp;
2019-05-10 17:11:54 +00:00
register int i;
/* Now erase recursively all registers containing
* something using this one
*/
for (rp=machregs;rp<machregs+NREGS;rp++) {
if (rp->r_contents.t_token == -1) {
if (rp->r_contents.t_att[0].ar == regno)
1990-04-25 14:23:05 +00:00
erasereg((int)(rp-machregs));
1987-01-08 14:09:14 +00:00
} else if (rp->r_contents.t_token > 0) {
tdp= & tokens[rp->r_contents.t_token];
1984-05-18 21:27:39 +00:00
for (i=0;i<TOKENSIZE;i++)
if (tdp->t_type[i] == EV_REG &&
rp->r_contents.t_att[i].ar == regno) {
1990-04-25 14:23:05 +00:00
erasereg((int)(rp-machregs));
break;
}
1984-05-18 21:27:39 +00:00
}
}
1984-05-18 21:27:39 +00:00
}
2019-05-10 17:11:54 +00:00
void cleanregs(void)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
2019-05-10 17:11:54 +00:00
register int i;
1984-05-18 21:27:39 +00:00
for (rp=machregs;rp<machregs+NREGS;rp++) {
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0;
}
}
#ifndef NDEBUG
2019-05-10 17:11:54 +00:00
void inctcount(int regno)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
2019-05-10 17:11:54 +00:00
register int i;
1984-05-18 21:27:39 +00:00
rp = &machregs[regno];
#if MAXMEMBERS!=0
if (rp->r_members[0] == 0) {
#endif
rp->r_tcount++;
#if MAXMEMBERS!=0
} else {
for (i=0;i<MAXMEMBERS;i++)
if (rp->r_members[i] != 0)
inctcount(rp->r_members[i]);
}
#endif
}
2019-05-10 17:11:54 +00:00
void chkregs(void)
{
1984-05-18 21:27:39 +00:00
register struct reginfo *rp;
register token_p tp;
register tkdef_p tdp;
int i;
for (rp=machregs;rp<machregs+NREGS;rp++) {
assert(rp->r_tcount==0);
}
for (tp=fakestack;tp<fakestack+stackheight;tp++) {
if (tp->t_token == -1)
inctcount(tp->t_att[0].ar);
else {
tdp = &tokens[tp->t_token];
for (i=0;i<TOKENSIZE;i++)
if (tdp->t_type[i]==EV_REG)
inctcount(tp->t_att[i].ar);
}
}
#ifdef REGVARS
#include <em_reg.h>
for(i=reg_any;i<=reg_float;i++) {
int j;
for(j=0;j<nregvar[i];j++)
inctcount(rvnumbers[i][j]);
}
#endif /* REGVARS */
1984-05-18 21:27:39 +00:00
for (rp=machregs;rp<machregs+NREGS;rp++) {
assert(rp->r_refcount==rp->r_tcount);
rp->r_tcount=0;
}
}
#endif