4 liveon(BSet
*v
, Blk
*b
, Blk
*s
)
10 for (p
=s
->phi
; p
; p
=p
->link
)
11 if (rtype(p
->to
) == RTmp
)
13 for (p
=s
->phi
; p
; p
=p
->link
)
14 for (a
=0; a
<p
->narg
; a
++)
16 if (rtype(p
->arg
[a
]) == RTmp
) {
17 bsset(v
, p
->arg
[a
].val
);
18 bsset(b
->gen
, p
->arg
[a
].val
);
23 bset(Ref r
, Blk
*b
, int *nlv
, Tmp
*tmp
)
29 if (!bshas(b
->in
, r
.val
)) {
30 nlv
[KBASE(tmp
[r
.val
].cls
)]++;
36 * requires rpo computation
43 int k
, t
, m
[2], n
, chg
, nlv
[2];
49 for (b
=f
->start
; b
; b
=b
->link
) {
50 bsinit(b
->in
, f
->ntmp
);
51 bsinit(b
->out
, f
->ntmp
);
52 bsinit(b
->gen
, f
->ntmp
);
56 for (n
=f
->nblk
-1; n
>=0; n
--) {
68 chg
|= !bsequal(b
->out
, u
);
70 memset(nlv
, 0, sizeof nlv
);
71 b
->out
->t
[0] |= T
.rglob
;
72 bscopy(b
->in
, b
->out
);
73 for (t
=0; bsiter(b
->in
, &t
); t
++)
74 nlv
[KBASE(f
->tmp
[t
].cls
)]++;
75 if (rtype(b
->jmp
.arg
) == RCall
) {
76 assert((int)bscount(b
->in
) == T
.nrglob
&&
77 b
->in
->t
[0] == T
.rglob
);
78 b
->in
->t
[0] |= T
.retregs(b
->jmp
.arg
, nlv
);
80 bset(b
->jmp
.arg
, b
, nlv
, f
->tmp
);
83 for (i
=&b
->ins
[b
->nins
]; i
!=b
->ins
;) {
84 if ((--i
)->op
== Ocall
&& rtype(i
->arg
[1]) == RCall
) {
85 b
->in
->t
[0] &= ~T
.retregs(i
->arg
[1], m
);
88 /* caller-save registers are used
89 * by the callee, in that sense,
90 * right in the middle of the call,
92 nlv
[k
] += T
.nrsave
[k
];
93 if (nlv
[k
] > b
->nlive
[k
])
96 b
->in
->t
[0] |= T
.argregs(i
->arg
[1], m
);
98 nlv
[k
] -= T
.nrsave
[k
];
102 if (!req(i
->to
, R
)) {
103 assert(rtype(i
->to
) == RTmp
);
106 nlv
[KBASE(f
->tmp
[t
].cls
)]--;
111 switch (rtype(i
->arg
[k
])) {
113 ma
= &f
->mem
[i
->arg
[k
].val
];
114 bset(ma
->base
, b
, nlv
, f
->tmp
);
115 bset(ma
->index
, b
, nlv
, f
->tmp
);
118 bset(i
->arg
[k
], b
, nlv
, f
->tmp
);
122 if (nlv
[k
] > b
->nlive
[k
])
123 b
->nlive
[k
] = nlv
[k
];
132 fprintf(stderr
, "\n> Liveness analysis:\n");
133 for (b
=f
->start
; b
; b
=b
->link
) {
134 fprintf(stderr
, "\t%-10sin: ", b
->name
);
135 dumpts(b
->in
, f
->tmp
, stderr
);
136 fprintf(stderr
, "\t out: ");
137 dumpts(b
->out
, f
->tmp
, stderr
);
138 fprintf(stderr
, "\t gen: ");
139 dumpts(b
->gen
, f
->tmp
, stderr
);
140 fprintf(stderr
, "\t live: ");
141 fprintf(stderr
, "%d %d\n", b
->nlive
[0], b
->nlive
[1]);