fixes to 5g object file generation. arm specific regalloc.

R=rsc
APPROVED=rsc
DELTA=976  (164 added, 237 deleted, 575 changed)
OCL=30705
CL=30743
This commit is contained in:
Kai Backman 2009-06-25 11:01:17 -07:00
parent 94439982b6
commit 190b5c9ad2
5 changed files with 699 additions and 772 deletions

View File

@ -26,6 +26,7 @@ struct Addr
Sym* sym;
int width;
uchar type;
char reg;
uchar index;
uchar etype;
uchar scale; /* doubles as width in DATA op */
@ -40,12 +41,18 @@ struct Prog
Addr from; // src address
Addr to; // dst address
Prog* link; // next instruction in this func
void* reg; // pointer to containing Reg struct
char reg;
uchar scond;
};
#define REGALLOC_R0 0
#define REGALLOC_RMAX REGEXT
#define REGALLOC_F0 (REGALLOC_RMAX+1)
#define REGALLOC_FMAX (REGALLOC_F0 + FREGEXT)
EXTERN Biobuf* bout;
EXTERN int32 dynloc;
EXTERN uchar reg[D_NONE];
EXTERN uchar reg[REGALLOC_FMAX];
EXTERN int32 pcloc; // instruction counter
EXTERN Strlit emptystring;
extern char* anames[];
@ -57,6 +64,7 @@ EXTERN Node* deferproc;
EXTERN Node* deferreturn;
EXTERN Node* throwindex;
EXTERN Node* throwreturn;
EXTERN int maxstksize;
/*
* gen.c
@ -115,6 +123,8 @@ void ginit(void);
void gclean(void);
void regalloc(Node*, Type*, Node*);
void regfree(Node*);
void tempalloc(Node*, Type*);
void tempfree(Node*);
Node* nodarg(Type*, int);
void nodreg(Node*, Type*, int);
void nodindreg(Node*, Type*, int);

View File

@ -65,10 +65,8 @@ compile(Node *fn)
ptxt = gins(ATEXT, curfn->nname, &nod1);
afunclit(&ptxt->from);
ginit();
gen(curfn->enter);
gen(curfn->nbody);
gclean();
checklabels();
if(curfn->type->outtuple != 0)
@ -85,10 +83,14 @@ compile(Node *fn)
*/
// fill in argument size
ptxt->to.type = D_CONST2;
ptxt->to.offset2 = rnd(curfn->type->argwid, maxround);
// fill in final stack size
ptxt->to.offset = rnd(stksize+maxarg, maxround);
if(stksize > maxstksize)
maxstksize = stksize;
ptxt->to.offset = rnd(maxstksize+maxarg, maxround);
maxstksize = 0;
if(debug['f'])
frame(0);
@ -359,42 +361,6 @@ cgen_asop(Node *n)
if(!isint[nr->type->etype])
goto hard;
switch(n->etype) {
case OADD:
if(smallintconst(nr))
if(mpgetfix(nr->val.u.xval) == 1) {
a = optoas(OINC, nl->type);
if(nl->addable) {
gins(a, N, nl);
goto ret;
}
if(sudoaddable(a, nl, &addr)) {
p1 = gins(a, N, N);
p1->to = addr;
sudoclean();
goto ret;
}
}
break;
case OSUB:
if(smallintconst(nr))
if(mpgetfix(nr->val.u.xval) == 1) {
a = optoas(ODEC, nl->type);
if(nl->addable) {
gins(a, N, nl);
goto ret;
}
if(sudoaddable(a, nl, &addr)) {
p1 = gins(a, N, N);
p1->to = addr;
sudoclean();
goto ret;
}
}
break;
}
switch(n->etype) {
case OADD:
case OSUB:

View File

@ -64,6 +64,8 @@ zhist(Biobuf *b, int line, vlong offset)
Addr a;
Bputc(b, AHISTORY);
Bputc(b, 0);
Bputc(b, 0);
Bputc(b, line);
Bputc(b, line>>8);
Bputc(b, line>>16);
@ -82,19 +84,26 @@ zaddr(Biobuf *b, Addr *a, int s)
{
int32 l;
Ieee e;
int i;
char *n;
// Bputc(b, a->type);
// TODO(kaib): Re-introduce registers once we figure out what they are used
// for.
// Bputc(b, a->reg);
// Bputc(b, s);
// TODO(kaib): ditto for Addr.name
// Bputc(b, a->name);
switch(a->type) {
case D_STATIC:
case D_EXTERN:
case D_AUTO:
case D_PARAM:
Bputc(b, D_OREG);
Bputc(b, a->reg);
Bputc(b, s);
Bputc(b, a->type);
break;
default:
Bputc(b, a->type);
Bputc(b, a->reg);
Bputc(b, s);
Bputc(b, D_NONE);
}
Bputc(b, 1);
Bputc(b, 0);
Bputc(b, 0);
Bputc(b, 0);
switch(a->type) {
default:
print("unknown type %d in zaddr\n", a->type);
@ -107,10 +116,18 @@ zaddr(Biobuf *b, Addr *a, int s)
case D_PARAM:
break;
case D_CONST2:
l = a->offset2;
Bputc(b, l);
Bputc(b, l>>8);
Bputc(b, l>>16);
Bputc(b, l>>24); // fall through
case D_OREG:
case D_CONST:
case D_BRANCH:
case D_SHIFT:
case D_STATIC:
case D_AUTO:
l = a->offset;
Bputc(b, l);
Bputc(b, l>>8);
@ -118,27 +135,27 @@ zaddr(Biobuf *b, Addr *a, int s)
Bputc(b, l>>24);
break;
// case D_SCONST:
// n = a->sval;
// for(i=0; i<NSNAME; i++) {
// Bputc(b, b, *n);
// n++;
// }
// break;
case D_SCONST:
n = a->sval;
for(i=0; i<NSNAME; i++) {
Bputc(b, *n);
n++;
}
break;
// case D_FCONST:
// ieeedtod(&e, a->dval);
// l = e.l;
// Bputc(b, l);
// Bputc(b, l>>8);
// Bputc(b, l>>16);
// Bputc(b, l>>24);
// l = e.h;
// Bputc(b, l);
// Bputc(b, l>>8);
// Bputc(b, l>>16);
// Bputc(b, l>>24);
// break;
case D_FCONST:
ieeedtod(&e, a->dval);
l = e.l;
Bputc(b, l);
Bputc(b, l>>8);
Bputc(b, l>>16);
Bputc(b, l>>24);
l = e.h;
Bputc(b, l);
Bputc(b, l>>8);
Bputc(b, l>>16);
Bputc(b, l>>24);
break;
}
}
@ -228,6 +245,8 @@ dumpfuncs(void)
break;
}
Bputc(bout, p->as);
Bputc(bout, p->scond);
Bputc(bout, p->reg);
Bputc(bout, p->lineno);
Bputc(bout, p->lineno>>8);
Bputc(bout, p->lineno>>16);

File diff suppressed because it is too large Load Diff

View File

@ -122,13 +122,14 @@ Dconv(Fmt *fp)
break;
case D_CONST:
if(fp->flags & FmtLong) {
d1 = a->offset & 0xffffffffLL;
d2 = (a->offset>>32) & 0xffffffffLL;
snprint(str, sizeof(str), "$%lud-%lud", (ulong)d1, (ulong)d2);
break;
}
snprint(str, sizeof(str), "$%d", a->offset);
if(a->reg != NREG)
sprint(str, "$%N(R%d)", a, a->reg);
else
sprint(str, "$%N", a);
break;
case D_CONST2:
sprint(str, "$%d-%d", a->offset, a->offset2);
break;
case D_FCONST: