mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-08-09 16:25:01 +00:00
Refactor elimination of *current* op in optimiser
The code to handle this was duplicated in two places; this pulls it out to a common chunk of code triggered by negative values of freeops. This isn't a big win here, but it sets us up to re-use this code in later commits.
This commit is contained in:
@@ -913,7 +913,7 @@ void release_seq(t_opseq *seq)
|
|||||||
*/
|
*/
|
||||||
int crunch_seq(t_opseq **seq)
|
int crunch_seq(t_opseq **seq)
|
||||||
{
|
{
|
||||||
t_opseq *opnext, *opnextnext;
|
t_opseq *opnext, *opnextnext, *opprev = 0;
|
||||||
t_opseq *op = *seq;
|
t_opseq *op = *seq;
|
||||||
int crunched = 0;
|
int crunched = 0;
|
||||||
int freeops = 0;
|
int freeops = 0;
|
||||||
@@ -977,15 +977,7 @@ int crunch_seq(t_opseq **seq)
|
|||||||
break;
|
break;
|
||||||
case BRFALSE_CODE:
|
case BRFALSE_CODE:
|
||||||
if (op->val)
|
if (op->val)
|
||||||
{
|
freeops = -2; // Remove constant and never taken branch
|
||||||
opnextnext = opnext->nextop; // Remove never taken branch
|
|
||||||
if (op == *seq)
|
|
||||||
*seq = opnextnext;
|
|
||||||
opnext->nextop = NULL;
|
|
||||||
release_seq(op);
|
|
||||||
opnext = opnextnext;
|
|
||||||
crunched = 1;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
op->code = BRNCH_CODE; // Always taken branch
|
op->code = BRNCH_CODE; // Always taken branch
|
||||||
@@ -995,15 +987,7 @@ int crunch_seq(t_opseq **seq)
|
|||||||
break;
|
break;
|
||||||
case BRTRUE_CODE:
|
case BRTRUE_CODE:
|
||||||
if (!op->val)
|
if (!op->val)
|
||||||
{
|
freeops = -2; // Remove constant never taken branch
|
||||||
opnextnext = opnext->nextop; // Remove never taken branch
|
|
||||||
if (op == *seq)
|
|
||||||
*seq = opnextnext;
|
|
||||||
opnext->nextop = NULL;
|
|
||||||
release_seq(op);
|
|
||||||
opnext = opnextnext;
|
|
||||||
crunched = 1;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
op->code = BRNCH_CODE; // Always taken branch
|
op->code = BRNCH_CODE; // Always taken branch
|
||||||
@@ -1206,8 +1190,32 @@ int crunch_seq(t_opseq **seq)
|
|||||||
break; // LOGIC_NOT_CODE
|
break; // LOGIC_NOT_CODE
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Free up crunched ops
|
// Free up crunched ops. If freeops is positive we free up that many ops
|
||||||
//
|
// *after* op; if it's negative, we free up abs(freeops) ops *starting
|
||||||
|
// with* op.
|
||||||
|
if (freeops < 0)
|
||||||
|
{
|
||||||
|
freeops = -freeops;
|
||||||
|
// If op is at the start of the sequence, we treat this as a special
|
||||||
|
// case.
|
||||||
|
if (op == *seq)
|
||||||
|
{
|
||||||
|
for (; freeops > 0; --freeops)
|
||||||
|
{
|
||||||
|
opnext = op->nextop;
|
||||||
|
release_op(op);
|
||||||
|
op = *seq = opnext;
|
||||||
|
}
|
||||||
|
crunched = 1;
|
||||||
|
}
|
||||||
|
// Otherwise we just move op back to point to the previous op and
|
||||||
|
// let the following loop remove the required number of ops.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
op = opprev;
|
||||||
|
opnext = op->nextop;
|
||||||
|
}
|
||||||
|
}
|
||||||
while (freeops)
|
while (freeops)
|
||||||
{
|
{
|
||||||
op->nextop = opnext->nextop;
|
op->nextop = opnext->nextop;
|
||||||
@@ -1217,6 +1225,7 @@ int crunch_seq(t_opseq **seq)
|
|||||||
crunched = 1;
|
crunched = 1;
|
||||||
freeops--;
|
freeops--;
|
||||||
}
|
}
|
||||||
|
opprev = op;
|
||||||
op = opnext;
|
op = opnext;
|
||||||
}
|
}
|
||||||
return (crunched);
|
return (crunched);
|
||||||
|
Reference in New Issue
Block a user