From 4513ff1b85ee5cdb7fc5fb0cc49d2338de686eea Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 29 Jul 2015 16:37:08 +0200 Subject: [PATCH] Fixed nested mem2reg --- frontends/ast/ast.h | 2 +- frontends/ast/simplify.cc | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h index 69bbc813d..28959d5d9 100644 --- a/frontends/ast/ast.h +++ b/frontends/ast/ast.h @@ -215,7 +215,7 @@ namespace AST void replace_ids(const std::string &prefix, const std::map &rules); void mem2reg_as_needed_pass1(dict> &mem2reg_places, dict &mem2reg_flags, dict &proc_flags, uint32_t &status_flags); - void mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, AstNode *block); + bool mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, AstNode *block); bool mem2reg_check(pool &mem2reg_set); void meminfo(int &mem_width, int &mem_size, int &addr_bits); diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 5b09ad04d..efa65f30f 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -148,7 +148,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, } } - mem2reg_as_needed_pass2(mem2reg_set, this, NULL); + while (mem2reg_as_needed_pass2(mem2reg_set, this, NULL)) { } for (size_t i = 0; i < children.size(); i++) { if (mem2reg_set.count(children[i]) > 0) { @@ -2366,8 +2366,10 @@ bool AstNode::mem2reg_check(pool &mem2reg_set) } // actually replace memories with registers -void AstNode::mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, AstNode *block) +bool AstNode::mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, AstNode *block) { + bool did_something = false; + if (type == AST_BLOCK) block = this; @@ -2426,6 +2428,8 @@ void AstNode::mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, children[0]->id2ast = NULL; children[0]->str = id_data; type = AST_ASSIGN_EQ; + + did_something = true; } if (mem2reg_check(mem2reg_set)) @@ -2526,7 +2530,10 @@ void AstNode::mem2reg_as_needed_pass2(pool &mem2reg_set, AstNode *mod, auto children_list = children; for (size_t i = 0; i < children_list.size(); i++) - children_list[i]->mem2reg_as_needed_pass2(mem2reg_set, mod, block); + if (children_list[i]->mem2reg_as_needed_pass2(mem2reg_set, mod, block)) + did_something = true; + + return did_something; } // calulate memory dimensions -- 2.30.2