+static iCode *
+packRegsForHLUse3 (iCode * lic, operand * op, eBBlock * ebp)
+{
+ int i, key;
+ symbol *sym;
+ iCode *ic, *dic;
+ bool isFirst = TRUE;
+
+#if 0
+ printf("Checking:\n");
+ piCode(lic, NULL);
+#endif
+
+ if ( OP_SYMBOL(op)->accuse)
+ {
+ return NULL;
+ }
+
+ if (OP_SYMBOL(op)->remat)
+ {
+ return NULL;
+ }
+
+ /* Only defined once */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL;
+
+ if (getSize (operandType (op)) != 2)
+ return NULL;
+
+ /* And this is the definition */
+ if (bitVectFirstBit (OP_DEFS (op)) != lic->key)
+ return NULL;
+
+ /* first check if any overlapping liverange has already been
+ assigned to DPTR */
+ if (OP_SYMBOL(op)->clashes)
+ {
+ for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ )
+ {
+ if (bitVectBitValue(OP_SYMBOL(op)->clashes,i))
+ {
+ sym = hTabItemWithKey(liveRanges,i);
+ if (sym->accuse == ACCUSE_SCRATCH)
+ {
+ return NULL;
+ }
+ }
+ }
+ }
+
+ /* Nothing else that clashes with this is using the scratch
+ register. Scan through all of the intermediate instructions and
+ see if any of them could nuke HL.
+ */
+ dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
+
+ for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
+ ic = hTabNextItem(iCodeSeqhTab,&key))
+ {
+#if 0
+ piCode(ic, NULL);
+ printf("(op: %u)\n", ic->op);
+#endif
+ if (isFirst)
+ {
+ isFirst = FALSE;
+ if (ic->op == ADDRESS_OF)
+ continue;
+ if (POINTER_GET (ic))
+ continue;
+ }
+
+ /* Handle the non left/right/result ones first */
+ if (ic->op == IFX)
+ continue;
+ if (ic->op == JUMPTABLE)
+ return NULL;
+
+ if (SKIP_IC2(ic))
+ continue;
+
+ if (ic->op == IPUSH && isOperandEqual (op, IC_LEFT (ic)))
+ continue;
+
+ if ((ic->op == '=' && !POINTER_SET(ic)) ||
+ ic->op == UNARYMINUS ||
+ ic->op == '+' ||
+ ic->op == '-' ||
+ 0)
+ continue;
+
+ if (POINTER_GET (ic) && isOperandEqual (op, IC_LEFT (ic)))
+ continue;
+
+ if (IS_VALOP (IC_RIGHT (ic)) &&
+ (ic->op == EQ_OP ||
+ 0))
+ {
+ continue;
+ }
+
+ /* By default give up */
+ return NULL;
+ }
+
+#if 0
+ printf("Succeeded!\n");
+#endif
+ OP_SYMBOL (op)->accuse = ACCUSE_SCRATCH;
+
+ return dic;
+}
+
+static iCode *
+packRegsForIYUse (iCode * lic, operand * op, eBBlock * ebp)
+{
+ int i, key;
+ symbol *sym;
+ iCode *ic, *dic;
+ bitVect *uses;
+
+#if 0
+ printf("Checking IY on %p lic key %u first def %u:\n", OP_SYMBOL(op), lic->key, bitVectFirstBit(OP_DEFS(op)));
+ piCode(lic, NULL);
+#endif
+
+ if ( OP_SYMBOL(op)->accuse)
+ {
+ return NULL;
+ }
+
+ if (OP_SYMBOL(op)->remat)
+ {
+ return NULL;
+ }
+
+ /* Only defined once */
+ if (bitVectnBitsOn (OP_DEFS (op)) > 1)
+ return NULL;
+
+ /* And this is the definition */
+ if (bitVectFirstBit (OP_DEFS (op)) != lic->key)
+ return NULL;
+
+ /* first check if any overlapping liverange has already been
+ assigned to DPTR */
+ if (OP_SYMBOL(op)->clashes)
+ {
+ for (i = 0 ; i < OP_SYMBOL(op)->clashes->size ; i++ )
+ {
+ if (bitVectBitValue(OP_SYMBOL(op)->clashes,i))
+ {
+ sym = hTabItemWithKey(liveRanges,i);
+ if (sym->accuse == ACCUSE_IY)
+ {
+ return NULL;
+ }
+ }
+ }
+ }
+
+ /* Only a few instructions can load into IY */
+ if (lic->op != '=')
+ {
+ return NULL;
+ }
+
+ /* Nothing else that clashes with this is using the scratch
+ register. Scan through all of the intermediate instructions and
+ see if any of them could nuke HL.
+ */
+ dic = ic = hTabFirstItemWK(iCodeSeqhTab,OP_SYMBOL(op)->liveFrom);
+ uses = OP_USES(op);
+
+ for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
+ ic = hTabNextItem(iCodeSeqhTab,&key))
+ {
+#if 0
+ piCode(ic, NULL);
+ printf("(op: %u uses %u)\n", ic->op, bitVectBitValue(uses, ic->key));
+#endif
+
+ if (ic->op == PCALL ||
+ ic->op == CALL ||
+ ic->op == JUMPTABLE
+ )
+ return NULL;
+
+ if (SKIP_IC2(ic))
+ continue;
+
+ /* Only certain rules will work against IY. Check if this iCode uses
+ this symbol. */
+ if (bitVectBitValue(uses, ic->key) != 0)
+ {
+ if (ic->op == IFX)
+ return NULL;
+
+ if (ic->op == '=' &&
+ isOperandEqual(IC_RESULT(ic), op))
+ continue;
+
+ if (ic->op == GET_VALUE_AT_ADDRESS &&
+ isOperandEqual(IC_LEFT(ic), op))
+ continue;
+
+ if (isOperandEqual(IC_RESULT(ic), IC_LEFT(ic)) == FALSE)
+ return NULL;
+
+ if (IC_RIGHT (ic) && IS_VALOP (IC_RIGHT (ic)))
+ {
+ if (ic->op == '+' ||
+ ic->op == '-')
+ {
+ /* Only works if the constant is small */
+ if (operandLitValue (IC_RIGHT (ic)) < 4)
+ continue;
+ }
+ }
+
+ return NULL;
+ }
+ else
+ {
+ if (ic->op == IFX)
+ continue;
+
+ /* This iCode doesn't use the sym. See if this iCode preserves IY.
+ */
+ if (IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
+ isOperandInDirSpace(IC_RESULT(ic)))
+ return NULL;
+
+ if (IC_RIGHT(ic) && IS_SYMOP(IC_RIGHT(ic)) &&
+ isOperandInFarSpace(IC_RIGHT(ic)))
+ return NULL;
+
+ if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
+ isOperandInFarSpace(IC_LEFT(ic)))
+ return NULL;
+
+ continue;
+ }
+
+ /* By default give up */
+ return NULL;
+ }
+
+#if 0
+ printf("Succeeded IY!\n");
+#endif
+ OP_SYMBOL (op)->accuse = ACCUSE_IY;
+
+ return dic;
+}
+
+/** Returns TRUE if this operation can use acc and if it preserves the value.
+ */