for (size_t i = 0; i < cfg.nbbfall; ++i) {
const cfg_bb_t &b = cfg.bblocks[i];
for (const tcmd_t *p = b.cmd; p; p = p->next) {
- const tagver_t r = p->rhs;
+ const tagver_t r = p->rhs, h = p->pred;
if (tcmd_t::iscopy(r)) {
used[r] = true;
}
+ if (h != TAGVER_ZERO) {
+ used[h] = true;
+ }
used[p->lhs] = true;
}
}
cfg_t::live_through_bblock(p->next, buf2);
// exclude RHS
- if (tcmd_t::iscopy(r)) {
- buf2[r] = false;
- }
+ if (tcmd_t::iscopy(r)) buf2[r] = false;
// exclude tags assigned to the same RHS
for (const tcmd_t *q = cmd; q; q = q->next) {
- if (q->rhs == r) {
- buf2[q->lhs] = false;
- }
+ if (q->rhs == r) buf2[q->lhs] = false;
}
const size_t l = static_cast<size_t>(p->lhs);
live_through_bblock(cmd->next, live);
- const tagver_t l = cmd->lhs, r = cmd->rhs;
- if (live[l] && tcmd_t::iscopy(r)) {
- live[r] = true;
+ const tagver_t l = cmd->lhs, r = cmd->rhs, p = cmd->pred;
+ if (live[l]) {
+ // first reset, than set: LHS might be equal to history
+ live[l] = false;
+ if (tcmd_t::iscopy(r)) {
+ live[r] = true;
+ }
+ if (p != TAGVER_ZERO) {
+ live[p] = true;
+ }
}
- live[l] = false;
}
void cfg_t::liveness_analysis(const cfg_t &cfg, bool *live)
cfg_bb_t *b = cfg.bblocks, *be = b + cfg.nbbfall;
for (; b < be; ++b) {
for (tcmd_t *p, **pp = &b->cmd; (p = *pp);) {
- tagver_t &l = p->lhs, &r = p->rhs;
+ tagver_t &l = p->lhs, &r = p->rhs, &h = p->pred;
l = ver2new[l];
if (tcmd_t::iscopy(r)) {
r = ver2new[r];
}
+ if (h != TAGVER_ZERO) {
+ h = ver2new[h];
+ }
if (l == r) {
*pp = p->next;
} else {
for (const tcmd_t *p = b->cmd; p; p = p->next) {
x = p->lhs;
y = p->rhs;
- if (!tcmd_t::iscopy(y)) continue;
+ if (!tcmd_t::iscopy(y)) y = p->pred;
+ if (y == TAGVER_ZERO || y == x) continue;
rx = repr[x];
ry = repr[y];