-------------------------------------------------------------------------*/
#include "common.h"
+#include "newalloc.h"
int eBBNum = 0;
set *graphEdges = NULL ; /* list of edges in this flow graph */
-extern int labelKey ;
/*-----------------------------------------------------------------*/
/* printEntryLabel - prints entry label of a ebblock */
{
eBBlock *ebb;
- ALLOC(ebb,sizeof(eBBlock));
+ ebb = Safe_calloc(sizeof(eBBlock));
return ebb ;
}
{
edge *ep ;
- ALLOC(ep,sizeof(edge));
+ ep = Safe_calloc(sizeof(edge));
ep->from = from;
ep->to = to;
return ep;
}
+/*-----------------------------------------------------------------*/
+/* dumpLiveRanges - dump liverange information into a file */
+/*-----------------------------------------------------------------*/
+void dumpLiveRanges (char *ext,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
+ file = stdout;
+
+ for (sym = hTabFirstItem(liveRanges,&k); sym ;
+ sym = hTabNextItem(liveRanges,&k)) {
+
+ fprintf (file,"%s [k%d lr%d:%d so:%d]{ re%d rm%d}",
+ (sym->rname[0] ? sym->rname : sym->name),
+ sym->key,
+ sym->liveFrom,sym->liveTo,
+ sym->stack,
+ sym->isreqv,sym->remat
+ );
+
+ fprintf(file,"{"); printTypeChain(sym->type,file);
+ if (sym->usl.spillLoc) {
+ 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,"\n");
+ }
+
+ fclose(file);
+}
/*-----------------------------------------------------------------*/
/* dumpEbbsToFileExt - writeall the basic blocks to a file */
/*-----------------------------------------------------------------*/
FILE *of;
int i;
- /* create the file name */
- strcpy(buffer,srcFileName);
- strcat(buffer,ext);
-
- if (!(of = fopen(buffer,"a+"))) {
- werror(E_FILE_OPEN_ERR,buffer);
- exit(1);
- }
+ if (ext) {
+ /* create the file name */
+ strcpy(buffer,srcFileName);
+ strcat(buffer,ext);
+
+ if (!(of = fopen(buffer,"a+"))) {
+ werror(E_FILE_OPEN_ERR,buffer);
+ exit(1);
+ }
+ } else
+ of = stdout;
for (i=0; i < count ; i++ ) {
fprintf(of,"\n----------------------------------------------------------------\n");
/* if the last instruction is a goto */
/* we add it just before the goto */
- if ( ebp->ech->op == GOTO || ebp->ech->op == JUMPTABLE) {
+ if ( ebp->ech->op == GOTO || ebp->ech->op == JUMPTABLE
+ || ebp->ech->op == RETURN)
+ {
ic->lineno = ebp->ech->lineno;
ic->prev = ebp->ech->prev;
ebp->ech->prev = ic;
*count = 0 ;
/* allocate for the first entry */
- ALLOC(ebbs,sizeof(eBBlock **));
+
+ ebbs = Safe_calloc(sizeof(eBBlock **));
while (loop) {
/* put it in the array */
ebbs[(*count)++] = ebb ;
- /* allocate for the next one */
- if (!(ebbs = GC_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)))) {
- werror(E_OUT_OF_MEM,__FILE__,(*count + 1)*sizeof(eBBlock **));
- exit (1);
- }
-
+ /* allocate for the next one. Remember to clear the new */
+ /* pointer at the end, that was created by realloc. */
+
+ ebbs = Safe_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)) ;
+
+ ebbs[*count] = 0;
+
/* if this one ends in a goto or a conditional */
/* branch then check if the block it is going */
/* to already exists, if yes then this could */
}
(*count)++ ;
+
/* if we have stopped at the block , allocate for an extra one */
- if (!(ebbs = GC_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)))) {
- werror(E_OUT_OF_MEM,__FILE__,(*count + 1)*sizeof(eBBlock **));
- exit (1);
- }
+
+ ebbs = Safe_realloc(ebbs,(*count + 1)*sizeof(eBBlock **)) ;
+
+ ebbs[*count] = 0;
/* then move the block down one count */
pBlock = ebbs[j = i];