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"
|
|
|
|
|
|
|
|
#ifdef REGVARS
|
|
|
|
|
|
|
|
#ifndef NORCSID
|
1994-06-24 14:02:31 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-08 15:34:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include <cgg_cg.h>
|
|
|
|
#include "data.h"
|
|
|
|
#include "regvar.h"
|
|
|
|
#include <em_reg.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-12 16:25:18 +00:00
|
|
|
static struct regvar *rvlist;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
struct regvar *linkreg(long of, int sz, int tp, int sc) {
|
|
|
|
struct regvar *rvlp;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
|
|
|
|
rvlp->rv_next = rvlist;
|
|
|
|
rvlist=rvlp;
|
|
|
|
rvlp->rv_off = of;
|
|
|
|
rvlp->rv_size = sz;
|
|
|
|
rvlp->rv_type = tp;
|
|
|
|
rvlp->rv_score = sc;
|
|
|
|
rvlp->rv_reg = 0; /* no register assigned yet */
|
|
|
|
return(rvlp);
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void tryreg(struct regvar *rvlp, int typ) {
|
1985-01-08 15:34:54 +00:00
|
|
|
int score;
|
2017-11-13 17:44:17 +00:00
|
|
|
int i;
|
|
|
|
struct regassigned *ra;
|
1985-01-08 15:34:54 +00:00
|
|
|
struct regvar *save;
|
|
|
|
|
|
|
|
if (typ != reg_any && nregvar[typ]!=0) {
|
2017-10-14 16:40:04 +00:00
|
|
|
struct reginfo *ri = &machregs[rvnumbers[typ][0]];
|
|
|
|
int size, wrong;
|
|
|
|
|
|
|
|
size = ri->r_size;
|
|
|
|
wrong = (size!=rvlp->rv_size);
|
|
|
|
#ifdef REGLAP
|
|
|
|
/* reg_float may have one subregister */
|
|
|
|
if (wrong && ri->r_members[0]!=0) {
|
|
|
|
size = machregs[ri->r_members[0]].r_size;
|
|
|
|
wrong = (size!=rvlp->rv_size);
|
|
|
|
}
|
|
|
|
#endif /* REGLAP */
|
|
|
|
if (wrong)
|
1985-01-08 15:34:54 +00:00
|
|
|
score = -1;
|
|
|
|
else
|
|
|
|
score = regscore(rvlp->rv_off,
|
|
|
|
rvlp->rv_size,
|
|
|
|
rvlp->rv_type,
|
|
|
|
rvlp->rv_score,
|
|
|
|
typ); /* machine dependent */
|
|
|
|
ra = regassigned[typ];
|
|
|
|
if (score>ra[nregvar[typ]-1].ra_score) {
|
|
|
|
save = ra[nregvar[typ]-1].ra_rv;
|
|
|
|
for (i=nregvar[typ]-1;i>0 && ra[i-1].ra_score<score;i--)
|
|
|
|
ra[i] = ra[i-1];
|
|
|
|
ra[i].ra_rv = rvlp;
|
|
|
|
ra[i].ra_score = score;
|
|
|
|
if((rvlp=save)==0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nregvar[reg_any]==0)
|
|
|
|
return;
|
|
|
|
if (machregs[rvnumbers[reg_any][0]].r_size!=rvlp->rv_size)
|
|
|
|
score = -1;
|
|
|
|
else
|
|
|
|
score = regscore(rvlp->rv_off,
|
|
|
|
rvlp->rv_size,
|
|
|
|
rvlp->rv_type,
|
|
|
|
rvlp->rv_score,
|
|
|
|
reg_any); /* machine dependent */
|
|
|
|
ra = regassigned[reg_any];
|
|
|
|
if (score>ra[nregvar[reg_any]-1].ra_score) {
|
|
|
|
for (i=nregvar[reg_any]-1;i>0 && ra[i-1].ra_score<score;i--)
|
|
|
|
ra[i] = ra[i-1];
|
|
|
|
ra[i].ra_rv = rvlp;
|
|
|
|
ra[i].ra_score = score;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void fixregvars(int saveall) {
|
2017-10-15 17:15:03 +00:00
|
|
|
struct reginfo *rp, *rp2;
|
|
|
|
struct regvar *rv;
|
|
|
|
int i, regno, rvtyp;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
swtxt();
|
|
|
|
i_regsave(); /* machine dependent initialization */
|
|
|
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
|
|
|
for(i=0;i<nregvar[rvtyp];i++)
|
|
|
|
if (saveall) {
|
|
|
|
rp= &machregs[rvnumbers[rvtyp][i]];
|
2017-10-14 16:40:04 +00:00
|
|
|
#ifdef REGLAP
|
2017-10-15 17:15:03 +00:00
|
|
|
/*
|
|
|
|
* A reg_float may have two sizes. If so,
|
|
|
|
* only save the larger size.
|
|
|
|
*/
|
|
|
|
if ((regno = rp->r_members[0]) != 0 &&
|
|
|
|
machregs[regno].r_size > rp->r_size)
|
|
|
|
rp= &machregs[regno];
|
2017-10-14 16:40:04 +00:00
|
|
|
#endif
|
2017-10-15 17:15:03 +00:00
|
|
|
regsave(codestrings[rp->r_repr],
|
|
|
|
(long)-TEM_WSIZE,rp->r_size);
|
1985-01-08 15:34:54 +00:00
|
|
|
} else if(regassigned[rvtyp][i].ra_score>0) {
|
|
|
|
rv=regassigned[rvtyp][i].ra_rv;
|
2017-10-15 17:15:03 +00:00
|
|
|
rv->rv_reg = regno = rvnumbers[rvtyp][i];
|
1986-03-27 15:49:16 +00:00
|
|
|
rv->rv_type = rvtyp;
|
2017-10-14 16:40:04 +00:00
|
|
|
#ifdef REGLAP
|
2017-10-15 17:15:03 +00:00
|
|
|
/*
|
|
|
|
* Change regno to match rv->rv_size, but
|
|
|
|
* leave old regno in rv->rv_reg so that
|
|
|
|
* isregvar_size() can handle both sizes.
|
|
|
|
*/
|
|
|
|
if (machregs[regno].r_size != rv->rv_size) {
|
|
|
|
regno = machregs[regno].r_members[0];
|
|
|
|
assert(regno != 0);
|
|
|
|
assert(machregs[regno].r_size == rv->rv_size);
|
2017-10-14 16:40:04 +00:00
|
|
|
}
|
|
|
|
#endif
|
2017-10-15 17:15:03 +00:00
|
|
|
regsave(codestrings[machregs[regno].r_repr],
|
1985-01-08 15:34:54 +00:00
|
|
|
rv->rv_off,rv->rv_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_regsave();
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
int isregvar(long off) {
|
|
|
|
struct regvar *rvlp;
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
|
|
|
if(rvlp->rv_off == off)
|
|
|
|
return(rvlp->rv_reg);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2017-10-15 17:15:03 +00:00
|
|
|
#ifdef REGLAP
|
2017-11-13 17:44:17 +00:00
|
|
|
int isregvar_size(long off, int size) {
|
2017-10-15 17:15:03 +00:00
|
|
|
int regno = isregvar(off);
|
|
|
|
/*
|
|
|
|
* A reg_float may have two sizes. If this register has the
|
|
|
|
* wrong size, then use the overlapping register. A register
|
|
|
|
* may switch sizes in the middle of a procedure.
|
|
|
|
*/
|
|
|
|
if (regno > 0 && machregs[regno].r_size != size) {
|
|
|
|
if (machregs[regno].r_size != size) {
|
|
|
|
regno = machregs[regno].r_members[0];
|
|
|
|
assert(regno != 0);
|
|
|
|
assert(machregs[regno].r_size == size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return regno;
|
|
|
|
}
|
|
|
|
#endif /* REGLAP */
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
int isregtyp(long off) {
|
|
|
|
struct regvar *rvlp;
|
1986-03-27 15:49:16 +00:00
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
for (rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
|
|
|
|
if (rvlp->rv_off == off)
|
1986-03-27 15:49:16 +00:00
|
|
|
return(rvlp->rv_reg ? rvlp->rv_type+1 : 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
void unlinkregs(void) {
|
|
|
|
struct regvar *rvlp,*t;
|
|
|
|
struct regassigned *ra;
|
1985-01-08 15:34:54 +00:00
|
|
|
int rvtyp,i;
|
|
|
|
|
2017-11-13 17:44:17 +00:00
|
|
|
for (rvlp=rvlist;rvlp!=0;rvlp=t) {
|
1985-01-08 15:34:54 +00:00
|
|
|
t=rvlp->rv_next;
|
1988-06-28 14:41:02 +00:00
|
|
|
myfree((string)rvlp);
|
1985-01-08 15:34:54 +00:00
|
|
|
}
|
|
|
|
rvlist=0;
|
|
|
|
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
|
2017-11-13 17:44:17 +00:00
|
|
|
for (i=0;i<nregvar[rvtyp];i++) {
|
1985-01-08 15:34:54 +00:00
|
|
|
ra= ®assigned[rvtyp][i];
|
|
|
|
ra->ra_rv = 0;
|
|
|
|
ra->ra_score = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1991-12-17 15:05:43 +00:00
|
|
|
#endif /* REGVARS */
|
1985-01-08 15:34:54 +00:00
|
|
|
|
|
|
|
/* nothing after this */
|