ack/mach/proto/ncg/regvar.c
George Koehler 7e9348169c Add reglap to ncg. Add 4-byte reg_float to PowerPC ncg.
The new feature "reglap" allows two sizes of floating-point register
variables (reg_float), if each register overlaps a single register of
the other size.  PowerPC ncg uses reglap to define 4-byte instances
of f14 to f31 that overlap the 8-byte instances.

When ncgg sees the definition of fs14("f14")=f14, it removes the
8-byte f14 from its rvnumbers array, and adds the 4-byte fs14 in its
place.  Later, when ncg puts a variable in fs14, if it is an 8-byte
variable, then ncg switches to the 8-byte f14.  The code has
/* reglap */ comments in util/ncgg or #ifdef REGLAP in mach/proto/ncg

reglap became necessary because my commit a20b87c caused PowerPC ego
to allocate reg_float in both 4-byte and 8-byte sizes.
2017-10-14 12:40:04 -04:00

184 lines
4 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include "assert.h"
#include "param.h"
#include "tables.h"
#ifdef REGVARS
#ifndef NORCSID
static char rcsid[] = "$Id$";
#endif
#include "types.h"
#include <cgg_cg.h>
#include "data.h"
#include "regvar.h"
#include <em_reg.h>
#include "result.h"
#include "extern.h"
/*
* (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
*/
extern string myalloc();
struct regvar *rvlist;
struct regvar *
linkreg(of,sz,tp,sc) long of; {
register struct regvar *rvlp;
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);
}
void
tryreg(rvlp,typ) register struct regvar *rvlp; {
int score;
register i;
register struct regassigned *ra;
struct regvar *save;
if (typ != reg_any && nregvar[typ]!=0) {
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)
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;
}
}
fixregvars(saveall) {
register struct regvar *rv;
register rvtyp,i;
swtxt();
i_regsave(); /* machine dependent initialization */
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
for(i=0;i<nregvar[rvtyp];i++)
if (saveall) {
struct reginfo *rp;
rp= &machregs[rvnumbers[rvtyp][i]];
regsave(codestrings[rp->r_repr],
(long)-TEM_WSIZE,rp->r_size);
#ifdef REGLAP
/* reg_float may have one subregister */
if (rp->r_members[0]!=0) {
rp= &machregs[rp->r_members[0]];
regsave(codestrings[rp->r_repr],
(long)-TEM_WSIZE,rp->r_size);
}
#endif
} else if(regassigned[rvtyp][i].ra_score>0) {
rv=regassigned[rvtyp][i].ra_rv;
rv->rv_reg=rvnumbers[rvtyp][i];
rv->rv_type = rvtyp;
#ifdef REGLAP
/* reg_float may have alternate size */
if (machregs[rv->rv_reg].r_size != rv->rv_size) {
rv->rv_reg = machregs[rv->rv_reg].r_members[0];
assert(rv->rv_reg != 0);
assert(machregs[rv->rv_reg].r_size ==
rv->rv_size);
}
#endif
regsave(codestrings[machregs[rv->rv_reg].r_repr],
rv->rv_off,rv->rv_size);
}
}
f_regsave();
}
isregvar(off) long off; {
register struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off)
return(rvlp->rv_reg);
return(-1);
}
isregtyp(off) long off; {
register struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off)
return(rvlp->rv_reg ? rvlp->rv_type+1 : 0);
return(-1);
}
unlinkregs() {
register struct regvar *rvlp,*t;
register struct regassigned *ra;
int rvtyp,i;
for(rvlp=rvlist;rvlp!=0;rvlp=t) {
t=rvlp->rv_next;
myfree((string)rvlp);
}
rvlist=0;
for (rvtyp=reg_any;rvtyp<=reg_float;rvtyp++) {
for(i=0;i<nregvar[rvtyp];i++) {
ra= &regassigned[rvtyp][i];
ra->ra_rv = 0;
ra->ra_score = 0;
}
}
}
#endif /* REGVARS */
/* nothing after this */