+ if(total_registers_saved && pic16_pcode_verbose)
+ fprintf(stderr, " *** Saved %d registers ***\n", total_registers_saved);
+}
+
+static int insideLRBlock(pCode *pc)
+{
+ pCode *pc1;
+ int t1=-1, t2=-1;
+
+ pc1 = pc->prev;
+ while(pc1) {
+ if(isPCINFO(pc1) && (PCINF(pc1)->type == INF_LOCALREGS)) {
+ t1 = PCOLR (PCINF (pc1)->oper1)->type;
+ break;
+ }
+ pc1 = pc1->prev;
+ }
+
+ pc1 = pc->next;
+ while(pc1) {
+ if(isPCINFO(pc1) && (PCINF(pc1)->type == INF_LOCALREGS)) {
+ t2 = PCOLR (PCINF (pc1)->oper1)->type;
+ break;
+ }
+ pc1 = pc1->next;
+ }
+
+ if((t1 == LR_ENTRY_BEGIN && t2 == LR_ENTRY_END)
+ || (t1 == LR_EXIT_BEGIN && t2 == LR_EXIT_END))
+ return 1;
+
+ return 0;
+}
+
+
+static void RemoveRegFromLRBlock(regs *reg)
+{
+ if(elementsInSet(reg->reglives.usedpCodes) == 2) {
+ pCode *pc1;
+
+ /* only continue if there are just 2 uses of the register,
+ * in in the local *entry* block and one in the local *exit* block */
+
+ /* search for entry block */
+ pc1 = indexSet(reg->reglives.usedpCodes, 1);
+
+ if(insideLRBlock( pc1 )) {
+ fprintf(stderr, "usedpCodes[0] inside LR block\n");
+ deleteSetItem(&pc1->pb->tregisters, PCOR(PCI(pc1)->pcop)->r);
+ Remove1pcode(pc1, reg);
+ }
+
+ pc1 = indexSet(reg->reglives.usedpCodes, 0);
+ if(insideLRBlock( pc1 )) {
+ fprintf(stderr, "usedpCodes[1] inside LR block\n");
+ deleteSetItem(&pc1->pb->tregisters, PCOR(PCI(pc1)->pcop)->r);
+ Remove1pcode(pc1, reg);
+ }
+
+ /* remove r0x00 */
+ reg->isFree = 1;
+ reg->wasUsed = 0;
+ }