explicit cfg_t(dfa_t &a);
~cfg_t();
+ static tagver_t compact(const cfg_t &cfg, tagver_t *ver2new);
static void liveness_analysis(const cfg_t &cfg, bool *live);
static void dead_code_elimination(cfg_t &cfg, const bool *live);
static void interference(const cfg_t &cfg, const bool *live, bool *interf);
--- /dev/null
+#include "src/ir/dfa/cfg/cfg.h"
+
+namespace re2c
+{
+
+tagver_t cfg_t::compact(const cfg_t &cfg, tagver_t *ver2new)
+{
+ const size_t
+ nver = static_cast<size_t>(cfg.dfa.maxtagver) + 1,
+ ntag = cfg.dfa.vartags.size();
+ const tagver_t *fins = cfg.dfa.finvers;
+ bool *used = new bool[nver];
+
+ std::fill(used, used + nver, false);
+ for (size_t t = 0; t < ntag; ++t) {
+ used[fins[t]] = true;
+ }
+ for (size_t i = 0; i < cfg.nbbfall; ++i) {
+ const cfg_bb_t &b = cfg.bblocks[i];
+
+ for (const tagsave_t *p = b.cmd->save; p; p = p->next) {
+ used[p->ver] = true;
+ }
+
+ for (const tagcopy_t *p = b.cmd->copy; p; p = p->next) {
+ used[p->lhs] = used[p->rhs] = true;
+ }
+ }
+
+ tagver_t maxver = 0;
+ for (size_t v = 0; v < nver; ++v) {
+ if (used[v]) {
+ ver2new[v] = ++maxver;
+ }
+ }
+
+ return maxver;
+}
+
+} // namespace re2c
+
void optimize_tags(dfa_t &dfa)
{
- if (dfa.maxtagver > 0) {
+ tagver_t maxver = dfa.maxtagver;
+ if (maxver > 0) {
cfg_t cfg(dfa);
- const size_t nver = static_cast<size_t>(dfa.maxtagver) + 1;
+ size_t nver = static_cast<size_t>(maxver) + 1;
+ tagver_t *ver2new = new tagver_t[nver];
+
+ maxver = cfg_t::compact(cfg, ver2new);
+ cfg_t::renaming(cfg, ver2new, maxver);
+
+ nver = static_cast<size_t>(maxver) + 1;
bool *live = new bool[cfg.nbbfin * nver];
bool *interf = new bool[nver * nver];
- tagver_t *ver2new = new tagver_t[nver];
static const uint32_t NPASS = 2;
for (uint32_t n = 0; n < NPASS; ++n) {
cfg_t::liveness_analysis(cfg, live);
cfg_t::dead_code_elimination(cfg, live);
cfg_t::interference(cfg, live, interf);
- const tagver_t maxver = cfg_t::variable_allocation(cfg, interf, ver2new);
+ maxver = cfg_t::variable_allocation(cfg, interf, ver2new);
cfg_t::renaming(cfg, ver2new, maxver);
cfg_t::normalization(cfg);
}