genFarPointerGet, genCodePointerGet, genGenPointerGet, genUnpackBits),
* src/mcs51/ralloc.c (packRegisters): optimze pointer get values used as
conditionals
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3449
4a8a32a2-be11-0410-ad9d-
d568d2c75423
+2004-08-24 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+ * src/mcs51/gen.c (genPointerGet, genNearPointerGet, genPagedPointerGet,
+ genFarPointerGet, genCodePointerGet, genGenPointerGet, genUnpackBits),
+ * src/mcs51/ralloc.c (packRegisters): optimze pointer get values used as
+ conditionals
+
2004-08-22 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
* src/mcs51/peeph.def: peepholes 248.i-m for xdata bitfields
2004-08-22 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
* src/mcs51/peeph.def: peepholes 248.i-m for xdata bitfields
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
static void
/* genUnpackBits - generates code for unpacking bits */
/*-----------------------------------------------------------------*/
static void
-genUnpackBits (operand * result, char *rname, int ptype)
+genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx)
{
int offset = 0; /* result byte offset */
int rsize; /* result size */
{
int offset = 0; /* result byte offset */
int rsize; /* result size */
sym_link *etype; /* bitfield type information */
int blen; /* bitfield length */
int bstr; /* bitfield starting bit within byte */
sym_link *etype; /* bitfield type information */
int blen; /* bitfield length */
int bstr; /* bitfield starting bit within byte */
D(emitcode ("; genUnpackBits",""));
D(emitcode ("; genUnpackBits",""));
blen = SPEC_BLEN (etype);
bstr = SPEC_BSTR (etype);
blen = SPEC_BLEN (etype);
bstr = SPEC_BSTR (etype);
+ if (ifx && blen <= 8)
+ {
+ emitPtrByteGet (rname, ptype, FALSE);
+ if (blen == 1)
+ {
+ SNPRINTF (buffer, sizeof(buffer),
+ "acc.%d", bstr);
+ genIfxJump (ifx, buffer, NULL, NULL, NULL);
+ }
+ else
+ {
+ if (blen < 8)
+ emitcode ("anl", "a,#0x%02x",
+ (((unsigned char) -1) >> (8 - blen)) << bstr);
+ genIfxJump (ifx, "a", NULL, NULL, NULL);
+ }
+ return;
+ }
+ wassert (!ifx);
+
/* If the bitfield length is less than a byte */
if (blen < 8)
{
/* If the bitfield length is less than a byte */
if (blen < 8)
{
genNearPointerGet (operand * left,
operand * result,
iCode * ic,
genNearPointerGet (operand * left,
operand * result,
iCode * ic,
+ iCode * pi,
+ iCode * ifx)
{
asmop *aop = NULL;
regs *preg = NULL;
{
asmop *aop = NULL;
regs *preg = NULL;
/* if bitfield then unpack the bits */
if (IS_BITFIELD (retype))
/* if bitfield then unpack the bits */
if (IS_BITFIELD (retype))
- genUnpackBits (result, rname, POINTER);
+ genUnpackBits (result, rname, POINTER, ifx);
else
{
/* we have can just get the values */
else
{
/* we have can just get the values */
- if (IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
+ if (ifx || IS_AOP_PREG (result) || AOP_TYPE (result) == AOP_STK)
{
emitcode ("mov", "a,@%s", rname);
{
emitcode ("mov", "a,@%s", rname);
- aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE));
emitcode ("dec", "%s", rname);
}
}
emitcode ("dec", "%s", rname);
}
}
+
+ if (ifx && !ifx->generated)
+ {
+ genIfxJump (ifx, "a", left, NULL, result);
+ }
/* done */
freeAsmop (result, NULL, ic, RESULTONSTACK (ic) ? FALSE : TRUE);
/* done */
freeAsmop (result, NULL, ic, RESULTONSTACK (ic) ? FALSE : TRUE);
genPagedPointerGet (operand * left,
operand * result,
iCode * ic,
genPagedPointerGet (operand * left,
operand * result,
iCode * ic,
+ iCode *pi,
+ iCode *ifx)
{
asmop *aop = NULL;
regs *preg = NULL;
{
asmop *aop = NULL;
regs *preg = NULL;
/* if bitfield then unpack the bits */
if (IS_BITFIELD (retype))
/* if bitfield then unpack the bits */
if (IS_BITFIELD (retype))
- genUnpackBits (result, rname, PPOINTER);
+ genUnpackBits (result, rname, PPOINTER, ifx);
else
{
/* we have can just get the values */
else
{
/* we have can just get the values */
{
emitcode ("movx", "a,@%s", rname);
{
emitcode ("movx", "a,@%s", rname);
- aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE));
+ if (ifx && !ifx->generated)
+ {
+ genIfxJump (ifx, "a", left, NULL, result);
+ }
+
/* done */
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
/* done */
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
/*-----------------------------------------------------------------*/
static void
genFarPointerGet (operand * left,
/*-----------------------------------------------------------------*/
static void
genFarPointerGet (operand * left,
- operand * result, iCode * ic, iCode * pi)
+ operand * result, iCode * ic, iCode * pi, iCode * ifx)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
/* if bit then unpack */
if (IS_BITFIELD (retype))
/* if bit then unpack */
if (IS_BITFIELD (retype))
- genUnpackBits (result, "dptr", FPOINTER);
+ genUnpackBits (result, "dptr", FPOINTER, ifx);
else
{
size = AOP_SIZE (result);
else
{
size = AOP_SIZE (result);
while (size--)
{
emitcode ("movx", "a,@dptr");
while (size--)
{
emitcode ("movx", "a,@dptr");
- aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
if (size || pi)
emitcode ("inc", "dptr");
}
if (size || pi)
emitcode ("inc", "dptr");
}
+
+ }
+
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR)
+ {
+ aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
+ aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
+ pi->generated = 1;
+ }
+
+ if (ifx && !ifx->generated)
+ {
+ genIfxJump (ifx, "a", left, NULL, result);
- if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
- aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
- aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
- pi->generated = 1;
- }
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
static void
genCodePointerGet (operand * left,
/*-----------------------------------------------------------------*/
static void
genCodePointerGet (operand * left,
- operand * result, iCode * ic, iCode *pi)
+ operand * result, iCode * ic, iCode *pi, iCode *ifx)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
/* if bit then unpack */
if (IS_BITFIELD (retype))
/* if bit then unpack */
if (IS_BITFIELD (retype))
- genUnpackBits (result, "dptr", CPOINTER);
+ genUnpackBits (result, "dptr", CPOINTER, ifx);
else
{
size = AOP_SIZE (result);
else
{
size = AOP_SIZE (result);
{
emitcode ("clr", "a");
emitcode ("movc", "a,@a+dptr");
{
emitcode ("clr", "a");
emitcode ("movc", "a,@a+dptr");
- aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
emitcode ("inc", "dptr");
}
else
{
emitcode ("mov", "a,#0x%02x", offset);
emitcode ("movc", "a,@a+dptr");
emitcode ("inc", "dptr");
}
else
{
emitcode ("mov", "a,#0x%02x", offset);
emitcode ("movc", "a,@a+dptr");
- aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
- if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
- aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
- aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
- pi->generated = 1;
- }
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR)
+ {
+ aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
+ aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
+ pi->generated = 1;
+ }
+
+ if (ifx && !ifx->generated)
+ {
+ genIfxJump (ifx, "a", left, NULL, result);
+ }
+
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
static void
genGenPointerGet (operand * left,
/*-----------------------------------------------------------------*/
static void
genGenPointerGet (operand * left,
- operand * result, iCode * ic, iCode *pi)
+ operand * result, iCode * ic, iCode *pi, iCode *ifx)
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
{
int size, offset;
sym_link *retype = getSpec (operandType (result));
/* if bit then unpack */
if (IS_BITFIELD (retype))
/* if bit then unpack */
if (IS_BITFIELD (retype))
- genUnpackBits (result, "dptr", GPOINTER);
+ genUnpackBits (result, "dptr", GPOINTER, ifx);
else
{
size = AOP_SIZE (result);
else
{
size = AOP_SIZE (result);
while (size--)
{
emitcode ("lcall", "__gptrget");
while (size--)
{
emitcode ("lcall", "__gptrget");
- aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
+ if (!ifx)
+ aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE));
if (size || pi)
emitcode ("inc", "dptr");
}
}
if (size || pi)
emitcode ("inc", "dptr");
}
}
- if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) {
- aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
- aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
- pi->generated = 1;
- }
+ if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR)
+ {
+ aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE));
+ aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE));
+ pi->generated = 1;
+ }
+
+ if (ifx && !ifx->generated)
+ {
+ genIfxJump (ifx, "a", left, NULL, result);
+ }
+
+
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void
/* genPointerGet - generate code for pointer get */
/*-----------------------------------------------------------------*/
static void
-genPointerGet (iCode * ic, iCode *pi)
+genPointerGet (iCode * ic, iCode *pi, iCode *ifx)
{
operand *left, *result;
sym_link *type, *etype;
{
operand *left, *result;
sym_link *type, *etype;
left = IC_LEFT (ic);
result = IC_RESULT (ic);
left = IC_LEFT (ic);
result = IC_RESULT (ic);
+
+ if (getSize (operandType (result))>1)
+ ifx = NULL;
/* depending on the type of pointer we need to
move it to the correct pointer register */
/* depending on the type of pointer we need to
move it to the correct pointer register */
case POINTER:
case IPOINTER:
case POINTER:
case IPOINTER:
- genNearPointerGet (left, result, ic, pi);
+ genNearPointerGet (left, result, ic, pi, ifx);
- genPagedPointerGet (left, result, ic, pi);
+ genPagedPointerGet (left, result, ic, pi, ifx);
- genFarPointerGet (left, result, ic, pi);
+ genFarPointerGet (left, result, ic, pi, ifx);
- genCodePointerGet (left, result, ic, pi);
+ genCodePointerGet (left, result, ic, pi, ifx);
- genGenPointerGet (left, result, ic, pi);
+ genGenPointerGet (left, result, ic, pi, ifx);
break;
case GET_VALUE_AT_ADDRESS:
break;
case GET_VALUE_AT_ADDRESS:
- genPointerGet (ic, hasInc(IC_LEFT(ic),ic,getSize(operandType(IC_RESULT(ic)))));
+ genPointerGet (ic,
+ hasInc (IC_LEFT (ic), ic,
+ getSize (operandType (IC_RESULT (ic)))),
+ ifxForOp (IC_RESULT (ic), ic) );
this is the only usage then
mark the itemp as a conditional */
if ((IS_CONDITIONAL (ic) ||
this is the only usage then
mark the itemp as a conditional */
if ((IS_CONDITIONAL (ic) ||
- (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
+ (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic)) ||
+ (POINTER_GET (ic) && getSize (operandType (IC_RESULT (ic))) <=1)) &&
ic->next && ic->next->op == IFX &&
bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
ic->next && ic->next->op == IFX &&
bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
continue;
}
OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
continue;
}
+
+ /* if the condition of an if instruction
+ is defined in the previous GET_POINTER instruction and
+ this is the only usage then
+ mark the itemp as accumulator use */
+ if ((POINTER_GET (ic) && getSize (operandType (IC_RESULT (ic))) <=1) &&
+ ic->next && ic->next->op == IFX &&
+ bitVectnBitsOn (OP_USES(IC_RESULT(ic)))==1 &&
+ isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
+ OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
+ {
+ OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
+ continue;
+ }
/* reduce for support function calls */
if (ic->supportRtn || ic->op == '+' || ic->op == '-')
/* reduce for support function calls */
if (ic->supportRtn || ic->op == '+' || ic->op == '-')