Skip to content

Commit

Permalink
Merge pull request #5065 from WalterBright/go
Browse files Browse the repository at this point in the history
refactor: encapsulate some globals
  • Loading branch information
yebblies committed Sep 11, 2015
2 parents 8c19631 + 3eb77c2 commit 5d40a78
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 77 deletions.
28 changes: 14 additions & 14 deletions src/backend/gdag.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void builddags()
}
#endif
#if 0
dbg_printf("defkill "); vec_println(defkill,exptop);
dbg_printf("starkill "); vec_println(starkill,exptop);
dbg_printf("vptrkill "); vec_println(vptrkill,exptop);
dbg_printf("defkill "); vec_println(go.defkill,exptop);
dbg_printf("starkill "); vec_println(go.starkill,exptop);
dbg_printf("vptrkill "); vec_println(go.vptrkill,exptop);
#endif

#if 0
Expand Down Expand Up @@ -303,7 +303,7 @@ STATIC void aewalk(elem **pn,vec_t ae)
assert(t->Eoper == OPvar);
s = t->EV.sp.Vsym;
if (!(s->Sflags & SFLunambig))
vec_subass(ae,starkill);
vec_subass(ae,go.starkill);
foreach (i,exptop,ae) /* for each ae elem */
{ elem *e = expnod[i];

Expand All @@ -330,9 +330,9 @@ STATIC void aewalk(elem **pn,vec_t ae)
}
else /* else ambiguous definition */
{
vec_subass(ae,defkill);
vec_subass(ae,go.defkill);
if (OTcalldef(op))
vec_subass(ae,vptrkill);
vec_subass(ae,go.vptrkill);
}

// GEN the lvalue of an assignment operator
Expand All @@ -344,7 +344,7 @@ STATIC void aewalk(elem **pn,vec_t ae)
#if TARGET_SEGMENTED
if (op == OPvp_fp || op == OPcvp_fp)
/* Invalidate all other OPvp_fps */
vec_subass(ae,vptrkill);
vec_subass(ae,go.vptrkill);
#endif

/*dbg_printf("available: ("); WReqn(n); dbg_printf(")\n");
Expand Down Expand Up @@ -579,9 +579,9 @@ void boolopt()
#if 0
for (i = 0; i < exptop; i++)
dbg_printf("expnod[%d] = 0x%x\n",i,expnod[i]);
dbg_printf("defkill "); vec_println(defkill,exptop);
dbg_printf("starkill "); vec_println(starkill,exptop);
dbg_printf("vptrkill "); vec_println(vptrkill,exptop);
dbg_printf("defkill "); vec_println(go.defkill,exptop);
dbg_printf("starkill "); vec_println(go.starkill,exptop);
dbg_printf("vptrkill "); vec_println(go.vptrkill,exptop);
#endif

/* Do CSEs across extended basic blocks only. This is because */
Expand Down Expand Up @@ -788,7 +788,7 @@ STATIC void abewalk(elem *n,vec_t ae,vec_t aeval)
assert(t->Eoper == OPvar);
s = t->EV.sp.Vsym;
if (!(s->Sflags & SFLunambig))
vec_subass(ae,starkill);
vec_subass(ae,go.starkill);
foreach (i,exptop,ae) /* for each ae elem */
{ elem *e = expnod[i];

Expand All @@ -799,9 +799,9 @@ STATIC void abewalk(elem *n,vec_t ae,vec_t aeval)
}
else /* else ambiguous definition */
{
vec_subass(ae,defkill);
vec_subass(ae,go.defkill);
if (OTcalldef(op))
vec_subass(ae,vptrkill);
vec_subass(ae,go.vptrkill);
}
/* GEN the lvalue of an assignment operator */
if (op == OPeq && (i1 = t->Eexp) != 0 && (i2 = n->E2->Eexp) != 0)
Expand All @@ -821,7 +821,7 @@ STATIC void abewalk(elem *n,vec_t ae,vec_t aeval)
#if TARGET_SEGMENTED
if (op == OPvp_fp || op == OPcvp_fp)
/* Invalidate all other OPvp_fps */
vec_subass(ae,vptrkill);
vec_subass(ae,go.vptrkill);
#endif

/*dbg_printf("available: ("); WReqn(n); dbg_printf(")\n");
Expand Down
94 changes: 47 additions & 47 deletions src/backend/gflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,17 @@ STATIC void aecpgenkill()
}
assert(exptop == exptopsave);

defstarkill(); /* compute defkill and starkill */
defstarkill(); /* compute go.defkill and go.starkill */

#if 0
assert(vec_numbits(defkill) == exptop);
assert(vec_numbits(starkill) == exptop);
assert(vec_numbits(vptrkill) == exptop);
dbg_printf("defkill "); vec_println(defkill);
if (starkill)
{ dbg_printf("starkill "); vec_println(starkill);}
if (vptrkill)
{ dbg_printf("vptrkill "); vec_println(vptrkill); }
assert(vec_numbits(go.defkill) == exptop);
assert(vec_numbits(go.starkill) == exptop);
assert(vec_numbits(go.vptrkill) == exptop);
dbg_printf("defkill "); vec_println(go.defkill);
if (go.starkill)
{ dbg_printf("starkill "); vec_println(go.starkill);}
if (go.vptrkill)
{ dbg_printf("vptrkill "); vec_println(go.vptrkill); }
#endif

for (i = 0; i < dfotop; i++) /* for each block */
Expand Down Expand Up @@ -726,17 +726,17 @@ STATIC void defstarkill()
{ unsigned i,op;
elem *n;

vec_free(vptrkill);
vec_free(defkill);
vec_free(starkill); /* dump any existing ones */
defkill = vec_calloc(exptop);
vec_free(go.vptrkill);
vec_free(go.defkill);
vec_free(go.starkill); /* dump any existing ones */
go.defkill = vec_calloc(exptop);
if (flowxx != CP)
{ starkill = vec_calloc(exptop); /* and create new ones */
vptrkill = vec_calloc(exptop); /* and create new ones */
{ go.starkill = vec_calloc(exptop); /* and create new ones */
go.vptrkill = vec_calloc(exptop); /* and create new ones */
}
else /* CP */
{ starkill = NULL;
vptrkill = NULL;
{ go.starkill = NULL;
go.vptrkill = NULL;
}

if (flowxx == CP)
Expand All @@ -754,7 +754,7 @@ STATIC void defstarkill()
if (!(s1->Sflags & SFLunambig) ||
!(n->E2->EV.sp.Vsym->Sflags & SFLunambig))
{
vec_setbit(i,defkill);
vec_setbit(i,go.defkill);
}
}
}
Expand All @@ -767,7 +767,7 @@ STATIC void defstarkill()
{
case OPvar:
if (!(n->EV.sp.Vsym->Sflags & SFLunambig))
vec_setbit(i,defkill);
vec_setbit(i,go.defkill);
break;

case OPind: // if a 'starred' ref
Expand Down Expand Up @@ -808,34 +808,34 @@ void main()
case OPstrcmp:
case OPmemcmp:
case OPbt: // OPbt is like OPind
vec_setbit(i,defkill);
vec_setbit(i,starkill);
vec_setbit(i,go.defkill);
vec_setbit(i,go.starkill);
break;

#if TARGET_SEGMENTED
case OPvp_fp:
case OPcvp_fp:
vec_setbit(i,vptrkill);
vec_setbit(i,go.vptrkill);
goto Lunary;
#endif

default:
if (OTunary(op))
{
Lunary:
if (vec_testbit(n->E1->Eexp,defkill))
vec_setbit(i,defkill);
if (vec_testbit(n->E1->Eexp,starkill))
vec_setbit(i,starkill);
if (vec_testbit(n->E1->Eexp,go.defkill))
vec_setbit(i,go.defkill);
if (vec_testbit(n->E1->Eexp,go.starkill))
vec_setbit(i,go.starkill);
}
else if (OTbinary(op))
{
if (vec_testbit(n->E1->Eexp,defkill) ||
vec_testbit(n->E2->Eexp,defkill))
vec_setbit(i,defkill);
if (vec_testbit(n->E1->Eexp,starkill) ||
vec_testbit(n->E2->Eexp,starkill))
vec_setbit(i,starkill);
if (vec_testbit(n->E1->Eexp,go.defkill) ||
vec_testbit(n->E2->Eexp,go.defkill))
vec_setbit(i,go.defkill);
if (vec_testbit(n->E1->Eexp,go.starkill) ||
vec_testbit(n->E2->Eexp,go.starkill))
vec_setbit(i,go.starkill);
}
break;
}
Expand Down Expand Up @@ -993,7 +993,7 @@ STATIC void accumaecpx(elem *n)
case OPvp_fp:
case OPcvp_fp: // if vptr access
if ((flowxx == AE) && n->Eexp)
vec_orass(KILL,vptrkill); // kill all other vptr accesses
vec_orass(KILL,go.vptrkill); // kill all other vptr accesses
break;
#endif

Expand Down Expand Up @@ -1030,8 +1030,8 @@ STATIC void accumaecpx(elem *n)
if (!OTdef(op)) /* if not def elem */
return;
if (!Eunambig(n)) /* if ambiguous def elem */
{ vec_orass(KILL,defkill);
vec_subass(GEN,defkill);
{ vec_orass(KILL,go.defkill);
vec_subass(GEN,go.defkill);
}
else /* unambiguous def elem */
{ symbol *s;
Expand Down Expand Up @@ -1070,11 +1070,11 @@ STATIC void accumaecpx(elem *n)
else if (OTdef(op)) /* else if definition elem */
{
if (!Eunambig(n)) /* if ambiguous def elem */
{ vec_orass(KILL,defkill);
vec_subass(GEN,defkill);
{ vec_orass(KILL,go.defkill);
vec_subass(GEN,go.defkill);
if (OTcalldef(op))
{ vec_orass(KILL,vptrkill);
vec_subass(GEN,vptrkill);
{ vec_orass(KILL,go.vptrkill);
vec_subass(GEN,go.vptrkill);
}
}
else /* unambiguous def elem */
Expand All @@ -1083,8 +1083,8 @@ STATIC void accumaecpx(elem *n)
assert(t->Eoper == OPvar);
s = t->EV.sp.Vsym; /* idx of var being def'd */
if (!(s->Sflags & SFLunambig))
{ vec_orass(KILL,starkill); /* kill all 'starred' refs */
vec_subass(GEN,starkill);
{ vec_orass(KILL,go.starkill); /* kill all 'starred' refs */
vec_subass(GEN,go.starkill);
}
for (i = 1; i < exptop; i++) /* for each ae elem */
{ elem *e = expnod[i];
Expand Down Expand Up @@ -1453,8 +1453,8 @@ void flowvbe()
/* Bin =(Bout - Bkill) | Bgen */
/* Using Ullman's algorithm: */

/*dbg_printf("defkill = "); vec_println(defkill);
dbg_printf("starkill = "); vec_println(starkill);*/
/*dbg_printf("defkill = "); vec_println(go.defkill);
dbg_printf("starkill = "); vec_println(go.starkill);*/

for (i = 0; i < dfotop; i++)
{ block *b = dfo[i];
Expand Down Expand Up @@ -1653,25 +1653,25 @@ STATIC void accumvbe(vec_t GEN,vec_t KILL,elem *n)
#if TARGET_SEGMENTED
if (op == OPvp_fp || op == OPcvp_fp)
{
vec_orass(KILL,vptrkill); /* KILL all vptr accesses */
vec_orass(KILL,go.vptrkill); /* KILL all vptr accesses */
vec_subass(KILL,GEN); /* except for GENed stuff */
}
#endif
}
else if (OTdef(op)) /* if definition elem */
{
if (!Eunambig(n)) /* if ambiguous definition */
{ vec_orass(KILL,defkill);
{ vec_orass(KILL,go.defkill);
if (OTcalldef(op))
vec_orass(KILL,vptrkill);
vec_orass(KILL,go.vptrkill);
}
else /* unambiguous definition */
{ symbol *s;

assert(t->Eoper == OPvar);
s = t->EV.sp.Vsym; // ptr to var being def'd
if (!(s->Sflags & SFLunambig))
vec_orass(KILL,starkill);/* kill all 'starred' refs */
vec_orass(KILL,go.starkill);/* kill all 'starred' refs */
for (i = 1; i < exptop; i++) /* for each vbe elem */
{ elem *e = expnod[i];
unsigned eop = e->Eoper;
Expand Down
6 changes: 3 additions & 3 deletions src/backend/go.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ static char __file__[] = __FILE__; /* for tassert.h */

void go_term()
{
vec_free(defkill);
vec_free(starkill);
vec_free(vptrkill);
vec_free(go.defkill);
vec_free(go.starkill);
vec_free(go.vptrkill);
util_free(expnod);
util_free(expblk);
util_free(defnod);
Expand Down
18 changes: 12 additions & 6 deletions src/backend/go.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ extern unsigned deftop; /* # of entries in defnod[] */
extern elem **expnod; /* array of expression elems */
extern unsigned exptop; /* top of expnod[] */
extern block **expblk; /* parallel array of block pointers */
extern vec_t defkill; /* vector of AEs killed by an ambiguous */
/* definition */
extern vec_t starkill; /* vector of AEs killed by a definition */
/* of something that somebody could be */
/* pointing to */
extern vec_t vptrkill; /* vector of AEs killed by an access */

/* Global Optimizer variables
*/
struct Go
{
vec_t defkill; // vector of AEs killed by an ambiguous definition
vec_t starkill; // vector of AEs killed by a definition of something that somebody could be
// pointing to
vec_t vptrkill; // vector of AEs killed by an access
};

extern struct Go go;

/* gdag.c */
void builddags(void);
Expand Down
8 changes: 1 addition & 7 deletions src/backend/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,7 @@ unsigned
deftop = 0, /* # of entries in defnod[] */
exptop = 0; /* top of expnod[] */

vec_t defkill = NULL, /* vector of AEs killed by an ambiguous */
/* definition */
starkill = NULL, /* vector of AEs killed by a definition */
/* of something that somebody could be */
/* pointing to */
vptrkill = NULL; /* vector of AEs killed by an access */
/* to a vptr */
struct Go go;

/* From debug.c */
#if DEBUG
Expand Down

0 comments on commit 5d40a78

Please sign in to comment.