Re-use (vgrow) b->ins vector in backend xxx_abi() fn's.

Removes last re-allocation of b->ins.
This commit is contained in:
Roland Paterson-Jones 2024-10-23 09:15:30 +02:00 committed by Quentin Carbonneaux
parent 434cf5fdc4
commit 0ce9966c23
4 changed files with 28 additions and 25 deletions

View File

@ -656,9 +656,9 @@ void
amd64_sysv_abi(Fn *fn)
{
Blk *b;
Ins *i, *i0, *ip;
Ins *i, *i0;
RAlloc *ral;
int n, fa;
int n0, n1, ioff, fa;
for (b=fn->start; b; b=b->link)
b->visit = 0;
@ -668,12 +668,13 @@ amd64_sysv_abi(Fn *fn)
if (!ispar(i->op))
break;
fa = selpar(fn, b->ins, i);
n = b->nins - (i - b->ins) + (&insb[NIns] - curi);
i0 = vnew(n, sizeof(Ins), PFn);
ip = icpy(ip = i0, curi, &insb[NIns] - curi);
ip = icpy(ip, i, &b->ins[b->nins] - i);
b->nins = n;
b->ins = i0;
n0 = &insb[NIns] - curi;
ioff = i - b->ins;
n1 = b->nins - ioff;
vgrow(&b->ins, n0+n1);
icpy(b->ins+n0, b->ins+ioff, n1);
icpy(b->ins, curi, n0);
b->nins = n0+n1;
/* lower calls, returns, and vararg instructions */
ral = 0;

View File

@ -729,9 +729,9 @@ void
arm64_abi(Fn *fn)
{
Blk *b;
Ins *i, *i0, *ip;
Ins *i, *i0;
Insl *il;
int n;
int n0, n1, ioff;
Params p;
for (b=fn->start; b; b=b->link)
@ -742,12 +742,13 @@ arm64_abi(Fn *fn)
if (!ispar(i->op))
break;
p = selpar(fn, b->ins, i);
n = b->nins - (i - b->ins) + (&insb[NIns] - curi);
i0 = vnew(n, sizeof(Ins), PFn);
ip = icpy(ip = i0, curi, &insb[NIns] - curi);
ip = icpy(ip, i, &b->ins[b->nins] - i);
b->nins = n;
b->ins = i0;
n0 = &insb[NIns] - curi;
ioff = i - b->ins;
n1 = b->nins - ioff;
vgrow(&b->ins, n0+n1);
icpy(b->ins+n0, b->ins+ioff, n1);
icpy(b->ins, curi, n0);
b->nins = n0+n1;
/* lower calls, returns, and vararg instructions */
il = 0;

View File

@ -587,9 +587,9 @@ void
rv64_abi(Fn *fn)
{
Blk *b;
Ins *i, *i0, *ip;
Ins *i, *i0;
Insl *il;
int n;
int n0, n1, ioff;
Params p;
for (b=fn->start; b; b=b->link)
@ -600,12 +600,13 @@ rv64_abi(Fn *fn)
if (!ispar(i->op))
break;
p = selpar(fn, b->ins, i);
n = b->nins - (i - b->ins) + (&insb[NIns] - curi);
i0 = vnew(n, sizeof(Ins), PFn);
ip = icpy(ip = i0, curi, &insb[NIns] - curi);
ip = icpy(ip, i, &b->ins[b->nins] - i);
b->nins = n;
b->ins = i0;
n0 = &insb[NIns] - curi;
ioff = i - b->ins;
n1 = b->nins - ioff;
vgrow(&b->ins, n0+n1);
icpy(b->ins+n0, b->ins+ioff, n1);
icpy(b->ins, curi, n0);
b->nins = n0+n1;
/* lower calls, returns, and vararg instructions */
il = 0;

2
util.c
View File

@ -268,7 +268,7 @@ Ins *
icpy(Ins *d, Ins *s, ulong n)
{
if (n)
memcpy(d, s, n * sizeof(Ins));
memmove(d, s, n * sizeof(Ins));
return d + n;
}