blob: 067784e4b1938ef8fd96796522b46a2c15012110 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "lisc.h"
static void
addpred(Blk *bp, Blk *bc)
{
int i;
if (!bc->preds) {
bc->preds = alloc(bc->npreds * sizeof(Blk*));
for (i=0; i<bc->npreds; i++)
bc->preds[i] = 0;
}
for (i=0; bc->preds[i]; i++)
;
bc->preds[i] = bp;
}
void
fillpreds(Fn *f)
{
Blk *b;
for (b=f->start; b; b=b->link) {
b->npreds = 0;
free(b->preds);
b->preds = 0;
}
for (b=f->start; b; b=b->link) {
if (b->s1)
b->s1->npreds++;
if (b->s2)
b->s2->npreds++;
}
for (b=f->start; b; b=b->link) {
if (b->s1)
addpred(b, b->s1);
if (b->s2)
addpred(b, b->s2);
}
}
static int
rporec(Blk *b, int x)
{
if (b->rpo >= 0)
return x;
if (b->s1)
x = rporec(b->s1, x);
if (b->s2)
x = rporec(b->s2, x);
b->rpo = x;
return x - 1;
}
void
fillrpo(Fn *f)
{
int n;
Blk *b, **p;
for (b=f->start; b; b=b->link)
b->rpo = -1;
n = rporec(f->start, f->nblk-1);
free(f->rpo);
f->rpo = alloc(n * sizeof(Blk*));
for (p=&f->start; *p;) {
b = *p;
if (b->rpo == -1) {
*p = b->link;
/* todo, free block */
} else {
b->rpo -= n;
f->rpo[b->rpo] = b;
p=&(*p)->link;
}
}
}
void
ssafix(Fn *f, Ref v)
{
(void)f;
(void)v;
return;
}
|