Fixed nested mem2reg

This commit is contained in:
Clifford Wolf 2015-07-29 16:37:08 +02:00
parent 516e8828f2
commit 4513ff1b85
2 changed files with 11 additions and 4 deletions

View File

@ -215,7 +215,7 @@ namespace AST
void replace_ids(const std::string &prefix, const std::map<std::string, std::string> &rules); 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, 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); 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); bool mem2reg_check(pool<AstNode*> &mem2reg_set);
void meminfo(int &mem_width, int &mem_size, int &addr_bits); void meminfo(int &mem_width, int &mem_size, int &addr_bits);

View 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++) { for (size_t i = 0; i < children.size(); i++) {
if (mem2reg_set.count(children[i]) > 0) { if (mem2reg_set.count(children[i]) > 0) {
@ -2366,8 +2366,10 @@ bool AstNode::mem2reg_check(pool<AstNode*> &mem2reg_set)
} }
// actually replace memories with registers // 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) if (type == AST_BLOCK)
block = this; block = this;
@ -2426,6 +2428,8 @@ void AstNode::mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod,
children[0]->id2ast = NULL; children[0]->id2ast = NULL;
children[0]->str = id_data; children[0]->str = id_data;
type = AST_ASSIGN_EQ; type = AST_ASSIGN_EQ;
did_something = true;
} }
if (mem2reg_check(mem2reg_set)) 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; auto children_list = children;
for (size_t i = 0; i < children_list.size(); i++) 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 // calulate memory dimensions