X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCBBlock.c;h=5c757bca4bce7e7d2a12474e18ddbd224c87515e;hb=0cf06f41693869fcc73d996a435dc39641c3185a;hp=1fb1097b0fc36dcee7d174a48761303519bfbff8;hpb=573903c17677d00eaa7e5fbfbde9a22d41e2aeea;p=fw%2Fsdcc diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 1fb1097b..5c757bca 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -24,11 +24,27 @@ -------------------------------------------------------------------------*/ #include "common.h" -#include "newalloc.h" int eBBNum = 0; set *graphEdges = NULL; /* list of edges in this flow graph */ +struct _dumpFiles dumpFiles[] = { + {DUMP_RAW0, ".dumpraw0", NULL}, + {DUMP_RAW1, ".dumpraw1", NULL}, + {DUMP_CSE, ".dumpcse", NULL}, + {DUMP_DFLOW, ".dumpdflow", NULL}, + {DUMP_GCSE, ".dumpgcse", NULL}, + {DUMP_DEADCODE, ".dumpdeadcode", NULL}, + {DUMP_LOOP, ".dumploop", NULL}, + {DUMP_LOOPG, ".dumploopg", NULL}, + {DUMP_LOOPD, ".dumploopd", NULL}, + {DUMP_RANGE, ".dumprange", NULL}, + {DUMP_PACK, ".dumppack", NULL}, + {DUMP_RASSGN, ".dumprassgn", NULL}, + {DUMP_LRANGE, ".dumplrange", NULL}, + {0, NULL, NULL} +}; + /*-----------------------------------------------------------------*/ /* printEntryLabel - prints entry label of a ebblock */ /*-----------------------------------------------------------------*/ @@ -48,7 +64,7 @@ neweBBlock () { eBBlock *ebb; - ebb = Safe_calloc (1, sizeof (eBBlock)); + ebb = Safe_alloc (sizeof (eBBlock)); return ebb; } @@ -60,38 +76,73 @@ newEdge (eBBlock * from, eBBlock * to) { edge *ep; - ep = Safe_calloc (1, sizeof (edge)); + ep = Safe_alloc (sizeof (edge)); ep->from = from; ep->to = to; return ep; } +/*-----------------------------------------------------------------*/ +/* createDumpFile - create the dump file */ +/*-----------------------------------------------------------------*/ +FILE *createDumpFile (int id) { + struct _dumpFiles *dumpFilesPtr=dumpFiles; + + while (dumpFilesPtr->id) { + if (dumpFilesPtr->id==id) + break; + dumpFilesPtr++; + } + + if (!dumpFilesPtr->id) { + fprintf (stdout, "internal error: createDumpFile: unknown dump file.\n"); + exit (1); + } + + if (!dumpFilesPtr->filePtr) { + // not used before, create it + strncpyz (scratchFileName, dstFileName, PATH_MAX); + strncatz (scratchFileName, dumpFilesPtr->ext, PATH_MAX); + if (!(dumpFilesPtr->filePtr = fopen (scratchFileName, "w"))) { + werror (E_FILE_OPEN_ERR, scratchFileName); + exit (1); + } + } + return dumpFilesPtr->filePtr; +} + +/*-----------------------------------------------------------------*/ +/* closeDumpFiles - close possible opened dumpfiles */ +/*-----------------------------------------------------------------*/ +void closeDumpFiles() { + struct _dumpFiles *dumpFilesPtr; + + for (dumpFilesPtr=dumpFiles; dumpFilesPtr->id; dumpFilesPtr++) { + if (dumpFilesPtr->filePtr) { + fclose (dumpFilesPtr->filePtr); + } + } +} + /*-----------------------------------------------------------------*/ /* dumpLiveRanges - dump liverange information into a file */ /*-----------------------------------------------------------------*/ void -dumpLiveRanges (char *ext, hTab * liveRanges) +dumpLiveRanges (int id, hTab * liveRanges) { FILE *file; symbol *sym; int k; - if (ext) - { - /* create the file name */ - strcpy (buffer, srcFileName); - strcat (buffer, ext); - - if (!(file = fopen (buffer, "a+"))) - { - werror (E_FILE_OPEN_ERR, buffer); - exit (1); - } - } - else + if (id) { + file=createDumpFile(id); + } else { file = stdout; - + } + + if (currFunc) + fprintf(file,"------------- Func %s -------------\n",currFunc->name); for (sym = hTabFirstItem (liveRanges, &k); sym; sym = hTabNextItem (liveRanges, &k)) { @@ -110,79 +161,103 @@ dumpLiveRanges (char *ext, hTab * liveRanges) { fprintf (file, "}{ sir@ %s", sym->usl.spillLoc->rname); } - fprintf (file, "}"); - - /* if assigned to registers */ - if (sym->nRegs) - { - if (sym->isspilt) - { - if (!sym->remat) - if (sym->usl.spillLoc) - fprintf (file, "[%s]", (sym->usl.spillLoc->rname[0] ? - sym->usl.spillLoc->rname : - sym->usl.spillLoc->name)); - else - fprintf (file, "[err]"); - else - fprintf (file, "[remat]"); - } - else - { - int i; - fprintf (file, "["); - for (i = 0; i < sym->nRegs; i++) - fprintf (file, "%s ", port->getRegName (sym->regs[i])); - fprintf (file, "]"); - } - } + fprintf (file, "} clashes with "); + bitVectDebugOn(sym->clashes,file); fprintf (file, "\n"); } - fclose (file); + fflush(file); } + /*-----------------------------------------------------------------*/ /* dumpEbbsToFileExt - writeall the basic blocks to a file */ /*-----------------------------------------------------------------*/ void -dumpEbbsToFileExt (char *ext, eBBlock ** ebbs, int count) +dumpEbbsToFileExt (int id, eBBlock ** ebbs, int count) { FILE *of; int i; + eBBlock *bb; + set *cseSet; - if (ext) - { - /* create the file name */ - strcpy (buffer, srcFileName); - strcat (buffer, ext); - - if (!(of = fopen (buffer, "w"))) - { - werror (E_FILE_OPEN_ERR, buffer); - exit (1); - } - } - else + if (id) { + of=createDumpFile(id); + } else { of = stdout; + } for (i = 0; i < count; i++) { fprintf (of, "\n----------------------------------------------------------------\n"); - fprintf (of, "Basic Block %s : loop Depth = %d noPath = %d , lastinLoop = %d\n", + fprintf (of, "Basic Block %s (df:%d bb:%d lvl:%d): loopDepth=%d%s%s%s\n", ebbs[i]->entryLabel->name, + ebbs[i]->dfnum, ebbs[i]->bbnum, ebbs[i]->entryLabel->level, ebbs[i]->depth, - ebbs[i]->noPath, - ebbs[i]->isLastInLoop); + ebbs[i]->noPath ? " noPath" : "", + ebbs[i]->partOfLoop ? " partOfLoop" : "", + ebbs[i]->isLastInLoop ? " isLastInLoop" : ""); + + // a --nolabelopt makes this more readable + fprintf (of, "\nsuccessors: "); + for (bb=setFirstItem(ebbs[i]->succList); + bb; + bb=setNextItem(ebbs[i]->succList)) { + fprintf (of, "%s ", bb->entryLabel->name); + } + fprintf (of, "\npredecessors: "); + for (bb=setFirstItem(ebbs[i]->predList); + bb; + bb=setNextItem(ebbs[i]->predList)) { + fprintf (of, "%s ", bb->entryLabel->name); + } + { + int d; + fprintf (of, "\ndominators: "); + for (d=0; ddomVect->size; d++) { + if (bitVectBitValue(ebbs[i]->domVect, d)) { + fprintf (of, "%s ", ebbs[d]->entryLabel->name); + } + } + } + fprintf (of, "\n"); + fprintf (of, "\ndefines bitVector :"); bitVectDebugOn (ebbs[i]->defSet, of); fprintf (of, "\nlocal defines bitVector :"); bitVectDebugOn (ebbs[i]->ldefs, of); fprintf (of, "\npointers Set bitvector :"); bitVectDebugOn (ebbs[i]->ptrsSet, of); + if (ebbs[i]->isLastInLoop) { + fprintf (of, "\nInductions Set bitvector :"); + bitVectDebugOn (ebbs[i]->linds, of); + } + + fprintf (of, "\ninExprs:"); + for (cseSet = ebbs[i]->inExprs; cseSet; cseSet=cseSet->next) { + cseDef *item=cseSet->item; + fprintf (of, " %s(%d)",OP_SYMBOL(item->sym)->name,item->diCode->key); + if (item->fromGlobal) + fprintf (of, "g"); + } + fprintf (of, "\noutExprs:"); + for (cseSet = ebbs[i]->outExprs; cseSet; cseSet=cseSet->next) { + cseDef *item=cseSet->item; + fprintf (of, " %s(%d)",OP_SYMBOL(item->sym)->name,item->diCode->key); + if (item->fromGlobal) + fprintf (of, "g"); + } + fprintf (of, "\nkilledExprs:"); + for (cseSet = ebbs[i]->killedExprs; cseSet; cseSet=cseSet->next) { + cseDef *item=cseSet->item; + fprintf (of, " %s(%d)",OP_SYMBOL(item->sym)->name,item->diCode->key); + if (item->fromGlobal) + fprintf (of, "g"); + } + fprintf (of, "\n----------------------------------------------------------------\n"); printiCChain (ebbs[i]->sch, of); } - fclose (of); + fflush(of); } /*-----------------------------------------------------------------*/ @@ -192,17 +267,17 @@ eBBlock * iCode2eBBlock (iCode * ic) { iCode *loop; - eBBlock *ebb = neweBBlock (); /* a llocate an entry */ + eBBlock *ebb = neweBBlock (); /* allocate an entry */ /* put the first one unconditionally */ ebb->sch = ic; /* if this is a label then */ if (ic->op == LABEL) - ebb->entryLabel = ic->argLabel.label; + ebb->entryLabel = ic->label; else { - sprintf (buffer, "_eBBlock%d", eBBNum++); + SNPRINTF (buffer, sizeof(buffer), "_eBBlock%d", eBBNum++); ebb->entryLabel = newSymbol (buffer, 1); ebb->entryLabel->key = labelKey++; } @@ -215,6 +290,14 @@ iCode2eBBlock (iCode * ic) ebb->ech = ebb->sch; return ebb; } + + /* if this is a function call */ + if (ic->op == CALL || ic->op == PCALL) + { + ebb->hasFcall = 1; + if (currFunc) + FUNC_HASFCALL(currFunc->type) = 1; + } if ((ic->next && ic->next->op == LABEL) || !ic->next) @@ -235,7 +318,7 @@ iCode2eBBlock (iCode * ic) { ebb->hasFcall = 1; if (currFunc) - currFunc->hasFcall = 1; + FUNC_HASFCALL(currFunc->type) = 1; } /* if the next one is a label */ @@ -395,6 +478,7 @@ addiCodeToeBBlock (eBBlock * ebp, iCode * ic, iCode * ip) void remiCodeFromeBBlock (eBBlock * ebb, iCode * ic) { + wassert (ic->seq>=ebb->fSeq && ic->seq<=ebb->lSeq); if (ic->prev) ic->prev->next = ic->next; else @@ -419,7 +503,7 @@ iCodeBreakDown (iCode * ic, int *count) /* allocate for the first entry */ - ebbs = Safe_calloc (1, sizeof (eBBlock **)); + ebbs = Safe_alloc (sizeof (eBBlock **)); while (loop) { @@ -538,7 +622,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) { bitVectUnSetBit (OP_USES (IC_COND (ic)), ic->key); IC_COND (ic) = operandFromOperand (dest); - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key); continue; } @@ -547,7 +631,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); IC_RIGHT (ic) = operandFromOperand (dest); IC_RIGHT (ic)->isaddr = 0; - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key); } if (isOperandEqual (IC_LEFT (ic), src)) @@ -563,7 +647,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) IC_LEFT (ic) = operandFromOperand (dest); IC_LEFT (ic)->isaddr = 0; } - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key); } /* special case for pointer sets */ @@ -573,7 +657,7 @@ replaceSymBySym (set * sset, operand * src, operand * dest) bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key); IC_RESULT (ic) = operandFromOperand (dest); IC_RESULT (ic)->isaddr = 1; - OP_USES (dest) = bitVectSetBit (OP_USES (dest), ic->key); + OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key); } } } @@ -633,13 +717,32 @@ iCodeFromeBBlock (eBBlock ** ebbs, int count) (ebbs[i]->entryLabel != entryLabel && ebbs[i]->entryLabel != returnLabel)) { - werror (W_CODE_UNREACH, ebbs[i]->sch->filename, ebbs[i]->sch->lineno); - continue; + iCode *ic = NULL; + bool foundNonlabel = 0; + ic=ebbs[i]->sch; + do + { + if (ic->op != LABEL) + { + foundNonlabel = 1; + break; + } + if (ic==ebbs[i]->ech) + break; + ic = ic->next; + } + while (ic); + if (foundNonlabel && ic) + { + werrorfl (ic->filename, ic->lineno, W_CODE_UNREACH); + continue; + } } lic->next = ebbs[i]->sch; lic->next->prev = lic; lic = ebbs[i]->ech; + } return ric;