schedule loop nesting computations earlier
This commit is contained in:
parent
d04ba5eae8
commit
3c3afdc896
4 changed files with 63 additions and 26 deletions
2
all.h
2
all.h
|
@ -553,6 +553,8 @@ void filldom(Fn *);
|
||||||
int sdom(Blk *, Blk *);
|
int sdom(Blk *, Blk *);
|
||||||
int dom(Blk *, Blk *);
|
int dom(Blk *, Blk *);
|
||||||
void fillfron(Fn *);
|
void fillfron(Fn *);
|
||||||
|
void loopiter(Fn *, void (*)(Blk *, Blk *));
|
||||||
|
void fillloop(Fn *);
|
||||||
|
|
||||||
/* mem.c */
|
/* mem.c */
|
||||||
void memopt(Fn *);
|
void memopt(Fn *);
|
||||||
|
|
47
cfg.c
47
cfg.c
|
@ -228,3 +228,50 @@ fillfron(Fn *fn)
|
||||||
addfron(a, b->s2);
|
addfron(a, b->s2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
loopmark(Blk *hd, Blk *b, void f(Blk *, Blk *))
|
||||||
|
{
|
||||||
|
uint p;
|
||||||
|
|
||||||
|
if (b->id < hd->id || b->visit == hd->id)
|
||||||
|
return;
|
||||||
|
b->visit = hd->id;
|
||||||
|
f(hd, b);
|
||||||
|
for (p=0; p<b->npred; ++p)
|
||||||
|
loopmark(hd, b->pred[p], f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
loopiter(Fn *fn, void f(Blk *, Blk *))
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
uint p;
|
||||||
|
Blk *b;
|
||||||
|
|
||||||
|
for (b=fn->start; b; b=b->link)
|
||||||
|
b->visit = -1;
|
||||||
|
for (n=0; n<fn->nblk; ++n) {
|
||||||
|
b = fn->rpo[n];
|
||||||
|
for (p=0; p<b->npred; ++p)
|
||||||
|
if (b->pred[p]->id >= n)
|
||||||
|
loopmark(b, b->pred[p], f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
multloop(Blk *hd, Blk *b)
|
||||||
|
{
|
||||||
|
(void)hd;
|
||||||
|
b->loop *= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fillloop(Fn *fn)
|
||||||
|
{
|
||||||
|
Blk *b;
|
||||||
|
|
||||||
|
for (b=fn->start; b; b=b->link)
|
||||||
|
b->loop = 1;
|
||||||
|
loopiter(fn, multloop);
|
||||||
|
}
|
||||||
|
|
1
main.c
1
main.c
|
@ -49,6 +49,7 @@ func(Fn *fn)
|
||||||
ssa(fn);
|
ssa(fn);
|
||||||
filluse(fn);
|
filluse(fn);
|
||||||
ssacheck(fn);
|
ssacheck(fn);
|
||||||
|
fillloop(fn);
|
||||||
fillalias(fn);
|
fillalias(fn);
|
||||||
loadopt(fn);
|
loadopt(fn);
|
||||||
filluse(fn);
|
filluse(fn);
|
||||||
|
|
39
spill.c
39
spill.c
|
@ -1,23 +1,16 @@
|
||||||
#include "all.h"
|
#include "all.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
loopmark(Blk *hd, Blk *b)
|
aggreg(Blk *hd, Blk *b)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
uint n;
|
|
||||||
|
|
||||||
if (b->id < hd->id || b->visit == hd->id)
|
|
||||||
return;
|
|
||||||
b->visit = hd->id;
|
|
||||||
b->loop *= 10;
|
|
||||||
/* aggregate looping information at
|
/* aggregate looping information at
|
||||||
* loop headers */
|
* loop headers */
|
||||||
bsunion(hd->gen, b->gen);
|
bsunion(hd->gen, b->gen);
|
||||||
for (k=0; k<2; k++)
|
for (k=0; k<2; k++)
|
||||||
if (b->nlive[k] > hd->nlive[k])
|
if (b->nlive[k] > hd->nlive[k])
|
||||||
hd->nlive[k] = b->nlive[k];
|
hd->nlive[k] = b->nlive[k];
|
||||||
for (n=0; n<b->npred; n++)
|
|
||||||
loopmark(hd, b->pred[n]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -46,32 +39,26 @@ tmpuse(Ref r, int use, int loop, Fn *fn)
|
||||||
void
|
void
|
||||||
fillcost(Fn *fn)
|
fillcost(Fn *fn)
|
||||||
{
|
{
|
||||||
int n, hd;
|
int n;
|
||||||
uint a;
|
uint a;
|
||||||
Blk *b;
|
Blk *b;
|
||||||
Ins *i;
|
Ins *i;
|
||||||
Tmp *t;
|
Tmp *t;
|
||||||
Phi *p;
|
Phi *p;
|
||||||
|
|
||||||
for (b=fn->start; b; b=b->link) {
|
loopiter(fn, aggreg);
|
||||||
b->loop = 1;
|
if (debug['S']) {
|
||||||
b->visit = -1;
|
|
||||||
}
|
|
||||||
if (debug['S'])
|
|
||||||
fprintf(stderr, "\n> Loop information:\n");
|
fprintf(stderr, "\n> Loop information:\n");
|
||||||
for (n=0; n<fn->nblk; n++) {
|
for (b=fn->start; b; b=b->link) {
|
||||||
b = fn->rpo[n];
|
for (a=0; a<b->npred; ++a)
|
||||||
hd = 0;
|
if (b->id <= b->pred[a]->id)
|
||||||
for (a=0; a<b->npred; a++)
|
break;
|
||||||
if (b->pred[a]->id >= n) {
|
if (a != b->npred) {
|
||||||
loopmark(b, b->pred[a]);
|
fprintf(stderr, "\t%-10s", b->name);
|
||||||
hd = 1;
|
fprintf(stderr, " (% 3d ", b->nlive[0]);
|
||||||
|
fprintf(stderr, "% 3d) ", b->nlive[1]);
|
||||||
|
dumpts(b->gen, fn->tmp, stderr);
|
||||||
}
|
}
|
||||||
if (hd && debug['S']) {
|
|
||||||
fprintf(stderr, "\t%-10s", b->name);
|
|
||||||
fprintf(stderr, " (% 3d ", b->nlive[0]);
|
|
||||||
fprintf(stderr, "% 3d) ", b->nlive[1]);
|
|
||||||
dumpts(b->gen, fn->tmp, stderr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (t=fn->tmp; t-fn->tmp < fn->ntmp; t++) {
|
for (t=fn->tmp; t-fn->tmp < fn->ntmp; t++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue