]> granicus.if.org Git - re2c/commitdiff
Fixed tag optimizations to respect tags with history.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 5 Apr 2017 20:56:44 +0000 (21:56 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 6 Apr 2017 07:29:24 +0000 (08:29 +0100)
re2c/src/dfa/cfg/compact.cc
re2c/src/dfa/cfg/interfere.cc
re2c/src/dfa/cfg/liveanal.cc
re2c/src/dfa/cfg/rename.cc
re2c/src/dfa/cfg/varalloc.cc

index fcd068209d9ec6c3eb93ab46561fc3b40c3594df..fe7ce413945a5f02c738cb8aa3dc1ad945d3f090 100644 (file)
@@ -19,10 +19,13 @@ tagver_t cfg_t::compact(const cfg_t &cfg, tagver_t *ver2new)
        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;
                }
        }
index a83961f16e23c7ceb790245addac378bb3a92d27..aedf65760ace7face8e45ff70dd1c016de4d00d7 100644 (file)
@@ -38,15 +38,11 @@ void interfere(const tcmd_t *cmd, const bool *live, bool *interf,
                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);
index efe65d9ef84a65e53f7a65ba0a280b47cd0b26b7..f03b37836d3b7d36214c0b3d4d74d43d06438a7a 100644 (file)
@@ -29,11 +29,17 @@ void cfg_t::live_through_bblock(const tcmd_t *cmd, bool *live)
 
        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)
index 56c475a8362b50ae40640ae1739a56eba251d403..25cb52503c3c963c839127bc9a9a2fa45a015a00 100644 (file)
@@ -12,12 +12,15 @@ void cfg_t::renaming(cfg_t &cfg, const tagver_t *ver2new, tagver_t maxver)
        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 {
index f92249bad99a8335129e1401c44762d2cefb703c..a50027c82a6204595a1688b80a450344e090f5ed 100644 (file)
@@ -35,7 +35,8 @@ tagver_t cfg_t::variable_allocation(const cfg_t &cfg, const bool *interf,
                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];