diff options
-rw-r--r-- | lisc/isel.c | 15 | ||||
-rw-r--r-- | lisc/lisc.h | 1 | ||||
-rw-r--r-- | lisc/rega.c | 20 | ||||
-rw-r--r-- | lisc/util.c | 7 |
4 files changed, 24 insertions, 19 deletions
diff --git a/lisc/isel.c b/lisc/isel.c index 126baf7..17fc01e 100644 --- a/lisc/isel.c +++ b/lisc/isel.c @@ -622,7 +622,7 @@ void isel(Fn *fn) { Blk *b, **sb; - Ins *i, *i0; + Ins *i, *i0, *ip; Phi *p; uint a; int n, al, s; @@ -637,14 +637,13 @@ isel(Fn *fn) if (i->op != OPar && i->op != OParc) break; selpar(fn, b->ins, i); - i0 = i; - n = b->nins - (i-b->ins); - b->nins = n + (curi-insb); - i = alloc(b->nins * sizeof i[0]); - memcpy(i, insb, (curi-insb) * sizeof i[0]); - memcpy(&i[curi-insb], i0, n * sizeof i[0]); + n = b->nins - (i - b->ins) + (curi - insb); + i0 = alloc(n * sizeof(Ins)); + ip = icpy(ip = i0, insb, curi - insb); + ip = icpy(ip, i, &b->ins[b->nins] - i); + b->nins = n; free(b->ins); - b->ins = i; + b->ins = i0; /* lower function calls */ for (b=fn->start; b; b=b->link) { diff --git a/lisc/lisc.h b/lisc/lisc.h index 7ae7db9..7afce94 100644 --- a/lisc/lisc.h +++ b/lisc/lisc.h @@ -278,6 +278,7 @@ void emit(int, int, Ref, Ref, Ref); void emiti(Ins); int bcnt(Bits *); void vdup(void *, void *, size_t); +Ins *icpy(Ins *, Ins *, ulong); /* parse.c */ extern OpDesc opdesc[NOp]; diff --git a/lisc/rega.c b/lisc/rega.c index 2f335e6..cca3847 100644 --- a/lisc/rega.c +++ b/lisc/rega.c @@ -225,8 +225,8 @@ static Ins * dopm(Blk *b, Ins *i, RMap *m) { RMap m0; - int n, r, r1, t, nins; - Ins *i1, *ib, *ip, *ir; + int n, r, r1, t; + Ins *i0, *i1, *ip, *ir; ulong def; m0 = *m; @@ -263,16 +263,14 @@ dopm(Blk *b, Ins *i, RMap *m) #ifdef TEST_PMOV return 0; #endif - nins = curi-insb; - ib = alloc((b->nins + nins - (i1-i)) * sizeof(Ins)); - memcpy(ip = ib, b->ins, (i - b->ins) * sizeof(Ins)); - ip += i - b->ins; - memcpy(ir = ip, insb, nins * sizeof(Ins)); - ip += nins; - memcpy(ip, i1, (&b->ins[b->nins] - i1) * sizeof(Ins)); - b->nins += nins - (i1-i); + n = b->nins - (i1 - i) + (curi - insb); + i0 = alloc(n * sizeof(Ins)); + ip = icpy(ip = i0, b->ins, i - b->ins); + ip = icpy(ir = ip, insb, curi - insb); + ip = icpy(ip, i1, &b->ins[b->nins] - i1); + b->nins = n; free(b->ins); - b->ins = ib; + b->ins = i0; return ir; } diff --git a/lisc/util.c b/lisc/util.c index fe0e4b1..723a8db 100644 --- a/lisc/util.c +++ b/lisc/util.c @@ -72,3 +72,10 @@ vdup(void *pd, void *s, size_t sz) free(*(void **)pd); memcpy(*(void **)pd = alloc(sz), s, sz); } + +Ins * +icpy(Ins *d, Ins *s, ulong n) +{ + memcpy(d, s, n * sizeof(Ins)); + return d + n; +} |