- symbol *sym =NULL;
- int key =0;
- int pass;
-
- if (getenv("DISABLE_FILL_GAPS")) return;
-
- /* look for livernages that was spilt by the allocator */
- for (sym = hTabFirstItem(liveRanges,&key) ; sym ;
- sym = hTabNextItem(liveRanges,&key)) {
-
- int i;
- int pdone = 0;
-
- if (!sym->spillA || !sym->clashes || sym->remat) continue ;
-
- /* find the liveRanges this one clashes with, that are
- still assigned to registers & mark the registers as used*/
- for ( i = 0 ; i < sym->clashes->size ; i ++) {
- int k;
- symbol *clr;
-
- if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
- bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
- continue ;
-
- clr = hTabItemWithKey(liveRanges,i);
- assert(clr);
-
- /* mark these registers as used */
- for (k = 0 ; k < clr->nRegs ; k++ )
- useReg(clr->regs[k]);
- }
-
- if (willCauseSpill(sym->nRegs,sym->regType)) {
- /* NOPE :( clear all registers & and continue */
- freeAllRegs();
- continue ;
- }
-
- D(printf("Atemping fillGaps on %s: [",sym->name));
- /* THERE IS HOPE !!!! */
- for (i=0; i < sym->nRegs ; i++ ) {
- if (sym->regType == REG_PTR)
- sym->regs[i] = getRegPtrNoSpil ();
- else
- sym->regs[i] = getRegGprNoSpil ();
- D(printf("%s ", sym->regs[i]->name));
- }
- D(printf("]\n"));
-
- /* For all its definitions check if the registers
- allocated needs positioning NOTE: we can position
- only ONCE if more than One positioning required
- then give up.
- We may need to perform the checks twice; once to
- position the registers as needed, the second to
- verify any register repositioning is still
- compatible.
- */
- sym->isspilt = 0;
- for (pass=0; pass<2; pass++) {
- D(printf(" checking definitions\n"));
- for (i = 0 ; i < sym->defs->size ; i++ ) {
- if (bitVectBitValue(sym->defs,i)) {
- iCode *ic;
- if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
- D(printf(" ic->seq = %d\n", ic->seq));
- if (SKIP_IC(ic)) continue;
- assert(isSymbolEqual(sym,OP_SYMBOL(IC_RESULT(ic)))); /* just making sure */
- /* if left is assigned to registers */
- if (IS_SYMOP(IC_LEFT(ic)))
- {
- D(printf(" left = "));
- D(printOperand(IC_LEFT(ic),NULL));
- }
- if (IS_SYMOP(IC_LEFT(ic)) &&
- bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_LEFT(ic))->key)) {
- pdone += (positionRegs(sym,OP_SYMBOL(IC_LEFT(ic)))>0);
- }
- if (IS_SYMOP(IC_RIGHT(ic)))
- {
- D(printf(" right = "));
- D(printOperand(IC_RIGHT(ic),NULL));
- }
- if (IS_SYMOP(IC_RIGHT(ic)) &&
- bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RIGHT(ic))->key)) {
- pdone += (positionRegs(sym,OP_SYMBOL(IC_RIGHT(ic)))>0);
- }
- D(printf(" pdone = %d\n", pdone));
- if (pdone > 1) break;
- }
- }
- D(printf(" checking uses\n"));
- for (i = 0 ; i < sym->uses->size ; i++ ) {
- if (bitVectBitValue(sym->uses,i)) {
- iCode *ic;
- if (!(ic = hTabItemWithKey(iCodehTab,i))) continue ;
- D(printf(" ic->seq = %d\n", ic->seq));
- if (SKIP_IC(ic)) continue;
- if (POINTER_SET(ic) || POINTER_GET(ic)) continue ;
-
- /* if result is assigned to registers */
- if (IS_SYMOP(IC_RESULT(ic)))
- {
- D(printf(" result = "));
- D(printOperand(IC_RESULT(ic),NULL));
- }
- if (IS_SYMOP(IC_RESULT(ic)) &&
- bitVectBitValue(_G.totRegAssigned,OP_SYMBOL(IC_RESULT(ic))->key)) {
- pdone += (positionRegs(sym,OP_SYMBOL(IC_RESULT(ic)))>0);
- }
- D(printf(" pdone = %d\n", pdone));
- if (pdone > 1) break;
- }
- }
- if (pdone == 0) break; /* second pass only if regs repositioned */
- if (pdone > 1) break;
- }
- D(printf(" sym->regs = ["));
- for (i=0; i < sym->nRegs ; i++ )
+ symbol *sym =NULL;
+ int key =0;
+ int pass;
+ iCode *ic = NULL;
+
+ if (getenv("DISABLE_FILL_GAPS"))
+ return;
+
+ /* look for liveranges that were spilt by the allocator */
+ for (sym = hTabFirstItem(liveRanges, &key) ; sym ;
+ sym = hTabNextItem(liveRanges, &key))
+ {
+ int i;
+ int pdone = 0;
+
+ if (!sym->spillA || !sym->clashes || sym->remat)
+ continue;
+
+ /* if spilt in direct space the original rname is lost */
+ if (sym->usl.spillLoc && (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype))))
+ continue;
+
+ /* find the liveRanges this one clashes with, that are
+ still assigned to registers & mark the registers as used*/
+ for ( i = 0 ; i < sym->clashes->size ; i ++)
+ {
+ int k;
+ symbol *clr;
+
+ if (bitVectBitValue(sym->clashes,i) == 0 || /* those that clash with this */
+ bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
+ continue ;
+
+ clr = hTabItemWithKey(liveRanges, i);
+ assert(clr);
+
+ /* mark these registers as used */
+ for (k = 0 ; k < clr->nRegs ; k++ )
+ useReg(clr->regs[k]);
+ }
+
+ if (willCauseSpill(sym->nRegs, sym->regType))
+ {
+ /* NOPE :( clear all registers & and continue */
+ freeAllRegs();
+ continue ;
+ }
+
+ ic = NULL;
+ for (i = 0 ; i < sym->defs->size ; i++ )
+ {
+ if (bitVectBitValue(sym->defs, i))
+ {
+ if (!(ic = hTabItemWithKey(iCodehTab, i)))
+ continue;
+ if (ic->op == CAST)
+ break;
+ }
+ }
+
+ D(printf("Attempting fillGaps on %s: [", sym->name));
+ /* THERE IS HOPE !!!! */
+ for (i=0; i < sym->nRegs ; i++ )
+ {
+ if (sym->regType == REG_PTR)
+ sym->regs[i] = getRegPtrNoSpil ();
+ else if (sym->regType == REG_BIT)
+ sym->regs[i] = getRegBitNoSpil ();
+ else
+ {
+ sym->regs[i] = NULL;
+ if (ic && ic->op == CAST && IS_SYMOP (IC_RIGHT (ic)))
+ {
+ symbol * right = OP_SYMBOL (IC_RIGHT (ic));
+
+ if (right->regs[i])
+ sym->regs[i] = allocThisReg (right->regs[i]);
+ }
+ if (!sym->regs[i])
+ sym->regs[i] = getRegGprNoSpil ();
+ }