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
|
|
|
|
|
2017-11-12 00:35:48 +00:00
|
|
|
#include <assert.h>
|
2013-05-07 23:48:48 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1985-01-08 15:34:54 +00:00
|
|
|
#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
|
|
|
|
*/
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void chrefcount(int regno, int amount, int tflag) {
|
|
|
|
struct reginfo *rp;
|
1988-03-31 11:17:47 +00:00
|
|
|
#if MAXMEMBERS != 0
|
2017-11-13 17:44:17 +00:00
|
|
|
int i, tmp;
|
1988-03-31 11:17:47 +00:00
|
|
|
#endif
|
1985-01-08 15:34:54 +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++)
|
1991-01-10 18:39:36 +00:00
|
|
|
if ((tmp = rp->r_members[i])!=0)
|
|
|
|
chrefcount(tmp,amount,tflag);
|
1985-01-08 15:34:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
int getrefcount(int regno, int tflag) {
|
|
|
|
struct reginfo *rp;
|
1988-03-31 11:17:47 +00:00
|
|
|
#if MAXMEMBERS != 0
|
2017-11-13 17:44:17 +00:00
|
|
|
int i,maxcount, tmp;
|
1988-03-31 11:17:47 +00:00
|
|
|
#endif
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
rp= &machregs[regno];
|
|
|
|
#if MAXMEMBERS!=0
|
|
|
|
if (rp->r_members[0]==0)
|
|
|
|
#endif
|
1988-07-15 11:12:13 +00:00
|
|
|
return(rp->r_refcount - (tflag ? rp->r_tcount : 0));
|
1985-01-08 15:34:54 +00:00
|
|
|
#if MAXMEMBERS!=0
|
|
|
|
else {
|
|
|
|
maxcount=0;
|
|
|
|
for (i=0;i<MAXMEMBERS;i++)
|
1991-01-10 18:39:36 +00:00
|
|
|
if ((tmp=rp->r_members[i])!=0) {
|
|
|
|
tmp = getrefcount(tmp, tflag);
|
|
|
|
if (tmp > maxcount) maxcount = tmp;
|
|
|
|
}
|
1985-01-08 15:34:54 +00:00
|
|
|
return(maxcount);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void erasereg(int regno) {
|
|
|
|
struct reginfo *rp = &machregs[regno];
|
|
|
|
int i;
|
|
|
|
byte *tdpb;
|
1987-01-08 14:10:02 +00:00
|
|
|
|
1988-03-31 10:14:48 +00:00
|
|
|
#if MAXMEMBERS==0
|
1987-01-08 14:10:02 +00:00
|
|
|
rp->r_contents.t_token = 0;
|
1991-01-10 18:39:36 +00:00
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
1987-01-08 14:10:02 +00:00
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
/* Now erase recursively all registers containing
|
|
|
|
* something using this one
|
|
|
|
*/
|
|
|
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
|
|
|
if (rp->r_contents.t_token == -1) {
|
1988-03-31 10:14:48 +00:00
|
|
|
if (rp->r_contents.t_att[0].ar == regno) {
|
|
|
|
/* erasereg(rp-machregs);
|
|
|
|
replaced by the following three
|
|
|
|
lines
|
|
|
|
*/
|
|
|
|
rp->r_contents.t_token = 0;
|
1991-01-10 18:39:36 +00:00
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
1988-03-31 10:14:48 +00:00
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
|
|
|
}
|
1987-01-08 14:10:02 +00:00
|
|
|
} else if (rp->r_contents.t_token > 0) {
|
1988-03-31 10:14:48 +00:00
|
|
|
tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
|
1985-01-08 15:34:54 +00:00
|
|
|
for (i=0;i<TOKENSIZE;i++)
|
1988-03-31 10:14:48 +00:00
|
|
|
if (*tdpb++ == EV_REG &&
|
1985-01-08 15:34:54 +00:00
|
|
|
rp->r_contents.t_att[i].ar == regno) {
|
1988-03-31 10:14:48 +00:00
|
|
|
/* erasereg(rp-machregs);
|
|
|
|
replaced by the following three
|
|
|
|
lines
|
|
|
|
*/
|
|
|
|
rp->r_contents.t_token = 0;
|
1991-01-10 18:39:36 +00:00
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
1988-03-31 10:14:48 +00:00
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
1985-01-08 15:34:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1991-01-10 18:39:36 +00:00
|
|
|
#else
|
|
|
|
extern short clashlist[];
|
2017-11-13 17:44:17 +00:00
|
|
|
short *sp = &clashlist[rp->r_iclash];
|
1991-01-10 18:39:36 +00:00
|
|
|
|
|
|
|
rp->r_contents.t_token = 0;
|
|
|
|
while (*sp) {
|
|
|
|
rp = &machregs[*sp];
|
|
|
|
rp->r_contents.t_token = 0;
|
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
|
|
|
regno = *sp++;
|
|
|
|
/* 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) {
|
|
|
|
/* erasereg(rp-machregs);
|
|
|
|
replaced by the following three
|
|
|
|
lines
|
|
|
|
*/
|
|
|
|
rp->r_contents.t_token = 0;
|
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
|
|
|
}
|
|
|
|
} else if (rp->r_contents.t_token > 0) {
|
|
|
|
tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
|
|
|
|
for (i=0;i<TOKENSIZE;i++)
|
|
|
|
if (*tdpb++ == EV_REG &&
|
|
|
|
rp->r_contents.t_att[i].ar == regno) {
|
|
|
|
/* erasereg(rp-machregs);
|
|
|
|
replaced by the following three
|
|
|
|
lines
|
|
|
|
*/
|
|
|
|
rp->r_contents.t_token = 0;
|
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1985-01-08 15:34:54 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void cleanregs(void) {
|
|
|
|
struct reginfo *rp;
|
|
|
|
int i;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
for (rp=machregs;rp<machregs+NREGS;rp++) {
|
|
|
|
rp->r_contents.t_token = 0;
|
1991-01-10 18:39:36 +00:00
|
|
|
for (i=TOKENSIZE-1;i>=0;i--)
|
1985-01-08 15:34:54 +00:00
|
|
|
rp->r_contents.t_att[i].aw = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2017-11-13 17:44:17 +00:00
|
|
|
static void inctcount(int regno) {
|
|
|
|
struct reginfo *rp;
|
|
|
|
int i;
|
1985-01-08 15:34:54 +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
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void chkregs(void) {
|
|
|
|
struct reginfo *rp;
|
|
|
|
token_p tp;
|
|
|
|
byte *tdpb;
|
1985-01-08 15:34:54 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (rp=machregs+1;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 {
|
1988-03-31 10:14:48 +00:00
|
|
|
tdpb = &(tokens[tp->t_token].t_type[0]);
|
1985-01-08 15:34:54 +00:00
|
|
|
for (i=0;i<TOKENSIZE;i++)
|
1988-03-31 10:14:48 +00:00
|
|
|
if (*tdpb++==EV_REG)
|
1985-01-08 15:34:54 +00:00
|
|
|
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]);
|
|
|
|
}
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* REGVARS */
|
1985-01-08 15:34:54 +00:00
|
|
|
for (rp=machregs+1;rp<machregs+NREGS;rp++) {
|
|
|
|
assert(rp->r_refcount==rp->r_tcount);
|
|
|
|
rp->r_tcount=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|