Skip to content

Commit

Permalink
Merge pull request #5069 from WalterBright/go4
Browse files Browse the repository at this point in the history
refactor: encapsulate some globals 4
  • Loading branch information
yebblies committed Sep 13, 2015
2 parents 2736fb4 + bb628a1 commit 8d5d4c3
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 83 deletions.
36 changes: 18 additions & 18 deletions src/backend/blockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ void blockopt(int iter)
count = 0;
do
{
//printf("changes = %d, count = %d, dfotop = %d\n",changes,count,dfotop);
//printf("changes = %d, count = %d, dfotop = %d\n",go.changes,count,dfotop);
#if MARS
util_progress();
#else
if (controlc_saw)
util_exit(EXIT_BREAK);
#endif
changes = 0;
go.changes = 0;
bropt(); // branch optimization
brrear(); // branch rearrangement
blident(); // combine identical blocks
Expand All @@ -608,7 +608,7 @@ void blockopt(int iter)
assert(count < iterationLimit);
count++;
} while (mergeblks()); /* merge together blocks */
} while (changes);
} while (go.changes);
#ifdef DEBUG
if (debugw)
for (b = startblock; b; b = b->Bnext)
Expand Down Expand Up @@ -867,7 +867,7 @@ void brcombine()
}
}
if (anychanges)
{ changes++;
{ go.changes++;
continue;
}
} while (0);
Expand Down Expand Up @@ -907,7 +907,7 @@ STATIC void bropt()
n->Ety = tym;
b->Bsucc = list_reverse(b->Bsucc);
cmes("CHANGE: if (!e)\n");
changes++;
go.changes++;
}

/* Take care of IF (constant) */
Expand All @@ -928,7 +928,7 @@ STATIC void bropt()
/* delete elem if it has no side effects */
b->Belem = doptelem(b->Belem,GOALnone | GOALagain);
cmes("CHANGE: if (const)\n");
changes++;
go.changes++;
}

/* Look for both destinations being the same */
Expand All @@ -939,7 +939,7 @@ STATIC void bropt()
list_subtract(&(b->Bsucc),db);
list_subtract(&(db->Bpred),b);
cmes("CHANGE: if (e) goto L1; else goto L1;\n");
changes++;
go.changes++;
}
}
else if (b->BC == BCswitch)
Expand Down Expand Up @@ -985,7 +985,7 @@ STATIC void bropt()
b->BC = BCgoto;
b->Belem = doptelem(b->Belem,GOALnone | GOALagain);
cmes("CHANGE: switch (const)\n");
changes++;
go.changes++;
}
}
}
Expand Down Expand Up @@ -1176,7 +1176,7 @@ STATIC void elimblks()
b->Bnext = bf;
bf = b; /* prepend to deferred list to free */
cmes2("CHANGE: block %p deleted\n",b);
changes++;
go.changes++;
}
else
pb = &((*pb)->Bnext);
Expand Down Expand Up @@ -1338,7 +1338,7 @@ STATIC void blident()
/* successors match */
/* elems match */
if (b->BC == bn->BC &&
//(!OPTIMIZER || !(mfoptim & MFtime) || !b->Bsucc) &&
//(!OPTIMIZER || !(go.mfoptim & MFtime) || !b->Bsucc) &&
(!OPTIMIZER || !(b->Bflags & BFLnomerg) || !b->Bsucc) &&
list_equal(b->Bsucc,bn->Bsucc) &&
#if SCPP || NTEXCEPTIONS
Expand Down Expand Up @@ -1456,7 +1456,7 @@ STATIC void blident()
dbg_printf("block B%d (%p) removed, it was same as B%d (%p)\n",
bn->Bdfoidx,bn,b->Bdfoidx,b);
#endif
changes++;
go.changes++;
break;
}
}
Expand All @@ -1470,7 +1470,7 @@ STATIC void blident()

STATIC void blreturn()
{
if (!(mfoptim & MFtime)) /* if optimized for space */
if (!(go.mfoptim & MFtime)) /* if optimized for space */
{
int retcount; /* number of return counts */
block *b;
Expand Down Expand Up @@ -1590,7 +1590,7 @@ STATIC void bltailmerge()
{
cmes("bltailmerge()\n");
assert(!PARSER && OPTIMIZER);
if (!(mfoptim & MFtime)) /* if optimized for space */
if (!(go.mfoptim & MFtime)) /* if optimized for space */
{
block *b;
block *bn;
Expand Down Expand Up @@ -1693,7 +1693,7 @@ STATIC void bltailmerge()
list_append(&b->Bsucc,bnew);
list_append(&bn->Bsucc,bnew);

changes++;
go.changes++;

/* Find all the expressions we can merge */
do
Expand Down Expand Up @@ -1786,7 +1786,7 @@ STATIC void brmin()
b->Bnext = bs;
#endif
cmes3("Moving block %p to appear after %p\n",bs,b);
changes++;
go.changes++;
break;

L2: ;
Expand Down Expand Up @@ -1928,7 +1928,7 @@ STATIC void brtailrecursion()
startblock = bs;

cmes("tail recursion\n");
changes++;
go.changes++;
return;
}
}
Expand Down Expand Up @@ -2057,7 +2057,7 @@ STATIC void emptyloops()
dbg_printf(" eliminated loop\n");
}
#endif
changes++;
go.changes++;
}
#else
// Find einc and erel
Expand Down Expand Up @@ -2094,7 +2094,7 @@ STATIC void emptyloops()
dbg_printf(" eliminated loop\n");
}
#endif
changes++;
go.changes++;
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions src/backend/el.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ elem *el_convfloat(elem *e)
else if (loadconst(e, 0))
return e;

changes++;
go.changes++;
tym_t ty = e->Ety;
int sz = tysize(ty);
assert(sz <= sizeof(buffer));
Expand Down Expand Up @@ -1977,7 +1977,7 @@ elem *el_convxmm(elem *e)
return e;
#endif

changes++;
go.changes++;
tym_t ty = e->Ety;
int sz = tysize(ty);
assert(sz <= sizeof(buffer));
Expand Down Expand Up @@ -2154,7 +2154,7 @@ elem *el_convert(elem *e)
break;

case OPstring:
changes++;
go.changes++;
e = el_convstring(e);
break;

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gdag.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ STATIC void abeboolres(elem *n,vec_t ae,vec_t aeval)
n->EV.Vlong = vec_testbit(i,aeval) != 0;
n->Eoper = OPconst;
n->Ety = TYint;
changes++;
go.changes++;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/glocal.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ STATIC void local_exp(elem *e,int goal)
)
{ // Change (x += a),(x += b) to
// (x + a),(x += a + b)
changes++;
go.changes++;
e->E2 = el_bin(opeqtoop(op),e->E2->Ety,em->E2,e->E2);
em->Eoper = opeqtoop(op);
em->E2 = el_copytree(em->E2);
Expand Down Expand Up @@ -349,7 +349,7 @@ STATIC void local_exp(elem *e,int goal)
dbg_printf(";\n");
}
#endif
changes++;
go.changes++;
em->Ety = e->Ety;
el_copy(e,em);
em->E1 = em->E2 = NULL;
Expand Down
34 changes: 16 additions & 18 deletions src/backend/gloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ static char __file__[] = __FILE__; /* for tassert.h */

/*#define vec_copy(t,f) (dbg_printf("line %d\n",__LINE__),vec_copy((t),(f)))*/

extern mftype mfoptim;

struct Iv;

/*********************************
Expand Down Expand Up @@ -579,7 +577,7 @@ STATIC int looprotate(loop *l)
//if (debugc) { dbg_printf("looprotate: "); l->print(); }
#endif

if ((mfoptim & MFtime) && head->BC != BCswitch && head->BC != BCasm)
if ((go.mfoptim & MFtime) && head->BC != BCswitch && head->BC != BCasm)
{ // Duplicate the header past the tail (but doing
// switches would be too expensive in terms of code
// generated).
Expand Down Expand Up @@ -632,7 +630,7 @@ STATIC int looprotate(loop *l)
list_append(&(head2->Bsucc),list_block(bl));
list_append(&(list_block(bl)->Bpred),head2);
}
changes++;
go.changes++;
return TRUE;
}
else if (startblock != head
Expand Down Expand Up @@ -665,7 +663,7 @@ STATIC int looprotate(loop *l)
head->Bnext = tail->Bnext;
tail->Bnext = head;
cmes2( "Rotated loop %p\n", l);
changes++;
go.changes++;
}
Lret:
return FALSE;
Expand Down Expand Up @@ -892,7 +890,7 @@ void loopopt()
//list_free(&l->Llis,FPNULL);
cmes2("...Loop %p done...\n",l);

if (mfoptim & MFliv)
if (go.mfoptim & MFliv)
{ loopiv(l); /* induction variables */
if (addblk) /* if we added a block */
{ compdfo();
Expand Down Expand Up @@ -1575,7 +1573,7 @@ STATIC void movelis(elem *n,block *b,loop *l,int *pdomexit)
el_copy(n->E2,list_elem(nl)->E1);
cmes("LI assignment rvalue was replaced\n");
doflow = TRUE;
changes++;
go.changes++;
break;
}
}
Expand All @@ -1588,7 +1586,7 @@ STATIC void movelis(elem *n,block *b,loop *l,int *pdomexit)
dbg_printf(";\n");
}
#endif
changes++;
go.changes++;
doflow = TRUE; // redo flow analysis
ne = el_calloc();
el_copy(ne,n); // create assignment elem
Expand Down Expand Up @@ -1755,7 +1753,7 @@ STATIC void movelis(elem *n,block *b,loop *l,int *pdomexit)
dbg_printf("\n");
}
#endif
changes++;
go.changes++;
doflow = TRUE; // redo flow analysis
goto Lret;
}
Expand All @@ -1771,7 +1769,7 @@ STATIC void movelis(elem *n,block *b,loop *l,int *pdomexit)
if (tyaggregate(n->Ety))
goto Lret;

changes++;
go.changes++;
doflow = TRUE; // redo flow analysis

t = el_alloctmp(n->Ety); /* allocate temporary t */
Expand Down Expand Up @@ -2600,7 +2598,7 @@ STATIC void intronvars(loop *l)
el_free(*fl->FLpelem);
*fl->FLpelem = T; /* replace elem n with ref to T */
doflow = TRUE; /* redo flow analysis */
changes++;
go.changes++;
} /* for */
} /* for */
}
Expand Down Expand Up @@ -2748,7 +2746,7 @@ STATIC bool funcprev(Iv *biv,famlist *fl)
fls->FLtemp->Sflags |= SFLnotbasiciv;

fl->FLtemp = FLELIM; /* mark iv as being gone */
changes++;
go.changes++;
doflow = TRUE;
return TRUE; /* it was replaced */
}
Expand Down Expand Up @@ -2964,7 +2962,7 @@ STATIC void elimbasivs(loop *l)
}
#endif

changes++;
go.changes++;
doflow = TRUE; /* redo flow analysis */

/* if X is live on entry to any successor S outside loop */
Expand Down Expand Up @@ -3043,7 +3041,7 @@ STATIC void elimbasivs(loop *l)
ne,b->Belem);
else
b->Belem = ne;
changes++;
go.changes++;
doflow = TRUE; /* redo flow analysis */
} /* for each successor */
} /* foreach exit block */
Expand Down Expand Up @@ -3074,7 +3072,7 @@ STATIC void elimbasivs(loop *l)
/* placeholder in the tree) */
*(biv->IVincr) = el_selecte2(*(biv->IVincr));

changes++;
go.changes++;
doflow = TRUE; /* redo flow analysis */
L1: ;
}
Expand Down Expand Up @@ -3135,7 +3133,7 @@ STATIC void elimopeqs(loop *l)
// placeholder in the tree)
*(biv->IVincr) = el_selecte2(*(biv->IVincr));

changes++;
go.changes++;
doflow = TRUE; // redo flow analysis
L1: ;
}
Expand Down Expand Up @@ -3436,7 +3434,7 @@ STATIC void elimspecwalk(elem **pn)
n->E2->Ety = n->Ety;
n->Eoper = OPcomma;

changes++;
go.changes++;
doflow = TRUE;

elimspecwalk(&n->E1);
Expand Down Expand Up @@ -3478,7 +3476,7 @@ STATIC void elimspecwalk(elem **pn)
/* increment node is now guaranteed to have no goal */
e1->Nflags |= NFLnogoal;
n->Eoper = OPcomma;
//changes++;
//go.changes++;
doflow = TRUE;

elimspecwalk(&n->E1);
Expand Down

0 comments on commit 8d5d4c3

Please sign in to comment.