Commit 190b5c9a authored by Kai Backman's avatar Kai Backman

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
parent 94439982
...@@ -26,6 +26,7 @@ struct Addr ...@@ -26,6 +26,7 @@ struct Addr
Sym* sym; Sym* sym;
int width; int width;
uchar type; uchar type;
char reg;
uchar index; uchar index;
uchar etype; uchar etype;
uchar scale; /* doubles as width in DATA op */ uchar scale; /* doubles as width in DATA op */
...@@ -40,12 +41,18 @@ struct Prog ...@@ -40,12 +41,18 @@ struct Prog
Addr from; // src address Addr from; // src address
Addr to; // dst address Addr to; // dst address
Prog* link; // next instruction in this func 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 Biobuf* bout;
EXTERN int32 dynloc; EXTERN int32 dynloc;
EXTERN uchar reg[D_NONE]; EXTERN uchar reg[REGALLOC_FMAX];
EXTERN int32 pcloc; // instruction counter EXTERN int32 pcloc; // instruction counter
EXTERN Strlit emptystring; EXTERN Strlit emptystring;
extern char* anames[]; extern char* anames[];
...@@ -57,6 +64,7 @@ EXTERN Node* deferproc; ...@@ -57,6 +64,7 @@ EXTERN Node* deferproc;
EXTERN Node* deferreturn; EXTERN Node* deferreturn;
EXTERN Node* throwindex; EXTERN Node* throwindex;
EXTERN Node* throwreturn; EXTERN Node* throwreturn;
EXTERN int maxstksize;
/* /*
* gen.c * gen.c
...@@ -115,6 +123,8 @@ void ginit(void); ...@@ -115,6 +123,8 @@ void ginit(void);
void gclean(void); void gclean(void);
void regalloc(Node*, Type*, Node*); void regalloc(Node*, Type*, Node*);
void regfree(Node*); void regfree(Node*);
void tempalloc(Node*, Type*);
void tempfree(Node*);
Node* nodarg(Type*, int); Node* nodarg(Type*, int);
void nodreg(Node*, Type*, int); void nodreg(Node*, Type*, int);
void nodindreg(Node*, Type*, int); void nodindreg(Node*, Type*, int);
......
...@@ -65,10 +65,8 @@ compile(Node *fn) ...@@ -65,10 +65,8 @@ compile(Node *fn)
ptxt = gins(ATEXT, curfn->nname, &nod1); ptxt = gins(ATEXT, curfn->nname, &nod1);
afunclit(&ptxt->from); afunclit(&ptxt->from);
ginit();
gen(curfn->enter); gen(curfn->enter);
gen(curfn->nbody); gen(curfn->nbody);
gclean();
checklabels(); checklabels();
if(curfn->type->outtuple != 0) if(curfn->type->outtuple != 0)
...@@ -85,10 +83,14 @@ compile(Node *fn) ...@@ -85,10 +83,14 @@ compile(Node *fn)
*/ */
// fill in argument size // fill in argument size
ptxt->to.type = D_CONST2;
ptxt->to.offset2 = rnd(curfn->type->argwid, maxround); ptxt->to.offset2 = rnd(curfn->type->argwid, maxround);
// fill in final stack size // 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']) if(debug['f'])
frame(0); frame(0);
...@@ -359,42 +361,6 @@ cgen_asop(Node *n) ...@@ -359,42 +361,6 @@ cgen_asop(Node *n)
if(!isint[nr->type->etype]) if(!isint[nr->type->etype])
goto hard; 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) { switch(n->etype) {
case OADD: case OADD:
case OSUB: case OSUB:
......
...@@ -64,6 +64,8 @@ zhist(Biobuf *b, int line, vlong offset) ...@@ -64,6 +64,8 @@ zhist(Biobuf *b, int line, vlong offset)
Addr a; Addr a;
Bputc(b, AHISTORY); Bputc(b, AHISTORY);
Bputc(b, 0);
Bputc(b, 0);
Bputc(b, line); Bputc(b, line);
Bputc(b, line>>8); Bputc(b, line>>8);
Bputc(b, line>>16); Bputc(b, line>>16);
...@@ -82,19 +84,26 @@ zaddr(Biobuf *b, Addr *a, int s) ...@@ -82,19 +84,26 @@ zaddr(Biobuf *b, Addr *a, int s)
{ {
int32 l; int32 l;
Ieee e; Ieee e;
int i;
char *n;
// Bputc(b, a->type); switch(a->type) {
// TODO(kaib): Re-introduce registers once we figure out what they are used case D_STATIC:
// for. case D_EXTERN:
// Bputc(b, a->reg); case D_AUTO:
// Bputc(b, s); case D_PARAM:
// TODO(kaib): ditto for Addr.name Bputc(b, D_OREG);
// Bputc(b, a->name); 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) { switch(a->type) {
default: default:
print("unknown type %d in zaddr\n", a->type); print("unknown type %d in zaddr\n", a->type);
...@@ -107,10 +116,18 @@ zaddr(Biobuf *b, Addr *a, int s) ...@@ -107,10 +116,18 @@ zaddr(Biobuf *b, Addr *a, int s)
case D_PARAM: case D_PARAM:
break; 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_OREG:
case D_CONST: case D_CONST:
case D_BRANCH: case D_BRANCH:
case D_SHIFT: case D_SHIFT:
case D_STATIC:
case D_AUTO:
l = a->offset; l = a->offset;
Bputc(b, l); Bputc(b, l);
Bputc(b, l>>8); Bputc(b, l>>8);
...@@ -118,27 +135,27 @@ zaddr(Biobuf *b, Addr *a, int s) ...@@ -118,27 +135,27 @@ zaddr(Biobuf *b, Addr *a, int s)
Bputc(b, l>>24); Bputc(b, l>>24);
break; break;
// case D_SCONST: case D_SCONST:
// n = a->sval; n = a->sval;
// for(i=0; i<NSNAME; i++) { for(i=0; i<NSNAME; i++) {
// Bputc(b, b, *n); Bputc(b, *n);
// n++; n++;
// } }
// break; break;
// case D_FCONST: case D_FCONST:
// ieeedtod(&e, a->dval); ieeedtod(&e, a->dval);
// l = e.l; l = e.l;
// Bputc(b, l); Bputc(b, l);
// Bputc(b, l>>8); Bputc(b, l>>8);
// Bputc(b, l>>16); Bputc(b, l>>16);
// Bputc(b, l>>24); Bputc(b, l>>24);
// l = e.h; l = e.h;
// Bputc(b, l); Bputc(b, l);
// Bputc(b, l>>8); Bputc(b, l>>8);
// Bputc(b, l>>16); Bputc(b, l>>16);
// Bputc(b, l>>24); Bputc(b, l>>24);
// break; break;
} }
} }
...@@ -228,6 +245,8 @@ dumpfuncs(void) ...@@ -228,6 +245,8 @@ dumpfuncs(void)
break; break;
} }
Bputc(bout, p->as); Bputc(bout, p->as);
Bputc(bout, p->scond);
Bputc(bout, p->reg);
Bputc(bout, p->lineno); Bputc(bout, p->lineno);
Bputc(bout, p->lineno>>8); Bputc(bout, p->lineno>>8);
Bputc(bout, p->lineno>>16); Bputc(bout, p->lineno>>16);
......
This diff is collapsed.
...@@ -122,13 +122,14 @@ Dconv(Fmt *fp) ...@@ -122,13 +122,14 @@ Dconv(Fmt *fp)
break; break;
case D_CONST: case D_CONST:
if(fp->flags & FmtLong) { if(a->reg != NREG)
d1 = a->offset & 0xffffffffLL; sprint(str, "$%N(R%d)", a, a->reg);
d2 = (a->offset>>32) & 0xffffffffLL; else
snprint(str, sizeof(str), "$%lud-%lud", (ulong)d1, (ulong)d2); sprint(str, "$%N", a);
break; break;
}
snprint(str, sizeof(str), "$%d", a->offset); case D_CONST2:
sprint(str, "$%d-%d", a->offset, a->offset2);
break; break;
case D_FCONST: case D_FCONST:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment