diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-06 22:51:51 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-10-06 22:51:51 -0400 |
commit | 72fc4559786dac5154ba344755758ba7a096be1b (patch) | |
tree | 424e25f3f99dbc2d00f4f6082ef10f0849917bf0 | |
parent | 99ad19546d983957d4bdb5596fc323a260d73fa6 (diff) | |
download | roux-72fc4559786dac5154ba344755758ba7a096be1b.tar.gz |
add pool memory management
-rw-r--r-- | lisc/isel.c | 5 | ||||
-rw-r--r-- | lisc/lisc.h | 4 | ||||
-rw-r--r-- | lisc/main.c | 2 | ||||
-rw-r--r-- | lisc/rega.c | 9 | ||||
-rw-r--r-- | lisc/spill.c | 2 | ||||
-rw-r--r-- | lisc/ssa.c | 11 | ||||
-rw-r--r-- | lisc/util.c | 54 |
7 files changed, 54 insertions, 33 deletions
diff --git a/lisc/isel.c b/lisc/isel.c index 49b8f28..fd2d760 100644 --- a/lisc/isel.c +++ b/lisc/isel.c @@ -516,8 +516,6 @@ selcall(Fn *fn, Ins *i0, Ins *i1) assert(stk == 8); emit(OXPush, 1, R, CON_Z, R); } - - free(ac); } static void @@ -580,8 +578,6 @@ selpar(Fn *fn, Ins *i0, Ins *i1) *curi++ = (Ins){OStorel, 0, R, {r1, r}}; } } - - free(ac); } /* instruction selection @@ -611,7 +607,6 @@ isel(Fn *fn) ip = icpy(ip = i0, insb, curi - insb); ip = icpy(ip, i, &b->ins[b->nins] - i); b->nins = n; - free(b->ins); b->ins = i0; /* lower function calls */ diff --git a/lisc/lisc.h b/lisc/lisc.h index 453d2ca..d4c08ce 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -272,8 +272,10 @@ void dumpts(Bits *, Tmp *, FILE *); extern Typ typ[NTyp]; extern Ins insb[NIns], *curi; void diag(char *); +void *ealloc(size_t); void *alloc(size_t); -Blk *balloc(); +void freeall(void); +Blk *balloc(void); void emit(int, int, Ref, Ref, Ref); void emiti(Ins); int bcnt(Bits *); diff --git a/lisc/main.c b/lisc/main.c index 9ac0286..c8edeb5 100644 --- a/lisc/main.c +++ b/lisc/main.c @@ -61,6 +61,7 @@ main(int ac, char *av[]) } fn = parse(inf); + fclose(inf); if (debug['P']) { fprintf(stderr, "\n> After parsing:\n"); printfn(fn, stderr); @@ -85,6 +86,7 @@ main(int ac, char *av[]) emitfn(fn, stdout); else fprintf(stderr, "\n"); + freeall(); exit(0); Usage: diff --git a/lisc/rega.c b/lisc/rega.c index 630298c..e1dbac0 100644 --- a/lisc/rega.c +++ b/lisc/rega.c @@ -198,7 +198,6 @@ pmgen() w = 0; pmrec(status, i, &w); } - free(status); } static void @@ -269,7 +268,6 @@ dopm(Blk *b, Ins *i, RMap *m) ip = icpy(ir = ip, insb, curi - insb); ip = icpy(ip, i1, &b->ins[b->nins] - i1); b->nins = n; - free(b->ins); b->ins = i0; return ir; } @@ -441,15 +439,10 @@ rega(Fn *fn) } } for (b=fn->start; b; b=b->link) - while ((p=b->phi)) { + while ((p=b->phi)) b->phi = p->link; - free(p); - } fn->reg = regu; - free(end); - free(beg); - if (debug['R']) { fprintf(stderr, "\n> After register allocation:\n"); printfn(fn, stderr); diff --git a/lisc/spill.c b/lisc/spill.c index aae214d..6b696d3 100644 --- a/lisc/spill.c +++ b/lisc/spill.c @@ -188,7 +188,7 @@ limit(Bits *b, int k, Bits *fst) return 0; if (nt > maxt) { free(tarr); - tarr = alloc(nt * sizeof tarr[0]); + tarr = ealloc(nt * sizeof tarr[0]); maxt = nt; } i = 0; diff --git a/lisc/ssa.c b/lisc/ssa.c index e60edc0..46a6023 100644 --- a/lisc/ssa.c +++ b/lisc/ssa.c @@ -24,7 +24,6 @@ fillpreds(Fn *f) for (b=f->start; b; b=b->link) { b->npred = 0; - free(b->pred); b->pred = 0; } for (b=f->start; b; b=b->link) { @@ -74,7 +73,6 @@ fillrpo(Fn *f) b->id = -1; n = 1 + rporec(f->start, f->nblk-1); f->nblk -= n; - free(f->rpo); f->rpo = alloc(f->nblk * sizeof f->rpo[0]); for (p=&f->start; *p;) { b = *p; @@ -197,7 +195,6 @@ topdef(Blk *b, Fn *f, int w) void ssafix(Fn *f, int t) { - char s[NString]; uint n; int t0, t1, w; Ref rt; @@ -252,10 +249,6 @@ ssafix(Fn *f, int t) b->jmp.arg = topdef(b, f, w); } /* add new temporaries */ - for (t1=f->ntmp; t1<t0; t1++) { - snprintf(s, NString, "%s%d", f->tmp[t].name, t0-t1); - newtmp(s, f); - } - free(top); - free(bot); + for (t1=f->ntmp; t1<t0; t1++) + newtmp(f->tmp[t].name, f); } diff --git a/lisc/util.c b/lisc/util.c index 399c144..6f01e9e 100644 --- a/lisc/util.c +++ b/lisc/util.c @@ -13,14 +13,20 @@ struct Vec { } align[]; }; + enum { - VMin = 2, + VMin = 32, VMag = 0xcabba9e, + NPtr = 256, }; Typ typ[NTyp]; Ins insb[NIns], *curi; +static void *ptr[NPtr]; +static void **pool = ptr; +static int nptr = 1; + void diag(char *s) { @@ -30,18 +36,50 @@ diag(char *s) } void * -alloc(size_t n) +ealloc(size_t n) { void *p; - if (n == 0) - return 0; p = calloc(1, n); if (!p) - abort(); + diag("ealloc: out of memory"); return p; } +void * +alloc(size_t n) +{ + void **pp; + + if (n == 0) + return 0; + if (nptr >= NPtr) { + pp = ealloc(NPtr * sizeof(void *)); + pp[0] = pool; + pool = pp; + nptr = 1; + } + return pool[nptr++] = ealloc(n); +} + +void +freeall() +{ + void **pp; + + for (;;) { + for (pp = &pool[1]; pp < &pool[NPtr]; pp++) + free(*pp); + pp = pool[0]; + if (!pp) + break; + free(pool); + pool = pp; + nptr = NPtr; + } + nptr = 1; +} + Blk * balloc() { @@ -87,7 +125,6 @@ bcnt(Bits *b) void idup(Ins **pd, Ins *s, ulong n) { - free(*pd); *pd = alloc(n * sizeof(Ins)); memcpy(*pd, s, n * sizeof(Ins)); } @@ -105,10 +142,10 @@ valloc(ulong len, size_t esz) ulong cap; Vec *v; - v = alloc(len * esz + sizeof(Vec)); - v->mag = VMag; for (cap=VMin; cap<len; cap*=2) ; + v = alloc(cap * esz + sizeof(Vec)); + v->mag = VMag; v->cap = cap; v->esz = esz; return v + 1; @@ -126,7 +163,6 @@ vgrow(void *vp, ulong len) return; v1 = valloc(len, v->esz); memcpy(v1, v+1, v->cap * v->esz); - free(v); *(Vec **)vp = v1; } |