Fixed nested mem2reg
authorClifford Wolf <clifford@clifford.at>
Wed, 29 Jul 2015 14:37:08 +0000 (16:37 +0200)
committerClifford Wolf <clifford@clifford.at>
Wed, 29 Jul 2015 14:37:08 +0000 (16:37 +0200)
frontends/ast/ast.h
frontends/ast/simplify.cc

index 69bbc813dc13fe1ad1ce3ead3bdf7c1878cecf38..28959d5d9ba57a41346b110a179e85fd15578ed7 100644 (file)
@@ -215,7 +215,7 @@ namespace AST
                void replace_ids(const std::string &prefix, const std::map<std::string, std::string> &rules);
                void mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg_places,
                                dict<AstNode*, uint32_t> &mem2reg_flags, dict<AstNode*, uint32_t> &proc_flags, uint32_t &status_flags);
-               void mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block);
+               bool mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block);
                bool mem2reg_check(pool<AstNode*> &mem2reg_set);
                void meminfo(int &mem_width, int &mem_size, int &addr_bits);
 
index 5b09ad04d3c939a9237b1ec986f15973e188802d..efa65f30fc4d8ec1f746ad1b70793d7da238fe1e 100644 (file)
@@ -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<AstNode*> &mem2reg_set)
 }
 
 // actually replace memories with registers
-void AstNode::mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block)
+bool AstNode::mem2reg_as_needed_pass2(pool<AstNode*> &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<AstNode*> &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<AstNode*> &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