Use mem2reg on memories that only have constant-index write ports
authorClifford Wolf <clifford@clifford.at>
Fri, 1 Mar 2019 21:35:09 +0000 (13:35 -0800)
committerClifford Wolf <clifford@clifford.at>
Fri, 1 Mar 2019 21:35:09 +0000 (13:35 -0800)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
frontends/ast/ast.h
frontends/ast/simplify.cc

index 08f91c9c3118afe16bd4652485c5a57557802f9f..89f7e6e4f9a3297fb8ef7eceab48ae8908654a8a 100644 (file)
@@ -214,6 +214,8 @@ namespace AST
                        MEM2REG_FL_SET_ASYNC = 0x00000800,
                        MEM2REG_FL_EQ2       = 0x00001000,
                        MEM2REG_FL_CMPLX_LHS = 0x00002000,
+                       MEM2REG_FL_CONST_LHS = 0x00004000,
+                       MEM2REG_FL_VAR_LHS   = 0x00008000,
 
                        /* proc flags */
                        MEM2REG_FL_EQ1       = 0x01000000,
index 46013544b6ae26e3bb5365652f2d5697728b75ec..589c683f812c2b09649dd5bb4f52813aee4bd643 100644 (file)
@@ -113,6 +113,9 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
                                if (memflags & AstNode::MEM2REG_FL_CMPLX_LHS)
                                        goto verbose_activate;
 
+                               if ((memflags & AstNode::MEM2REG_FL_CONST_LHS) && !(memflags & AstNode::MEM2REG_FL_VAR_LHS))
+                                       goto verbose_activate;
+
                                // log("Note: Not replacing memory %s with list of registers (flags=0x%08lx).\n", mem->str.c_str(), long(memflags));
                                continue;
 
@@ -2936,6 +2939,14 @@ void AstNode::mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg
                                proc_flags[mem] |= AstNode::MEM2REG_FL_EQ1;
                        }
 
+                       // remember if this is a constant index or not
+                       if (children[0]->children.size() && children[0]->children[0]->type == AST_RANGE && children[0]->children[0]->children.size()) {
+                               if (children[0]->children[0]->children[0]->type == AST_CONSTANT)
+                                       mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_CONST_LHS;
+                               else
+                                       mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_VAR_LHS;
+                       }
+
                        // remember where this is
                        if (flags & MEM2REG_FL_INIT) {
                                if (!(mem2reg_candidates[mem] & AstNode::MEM2REG_FL_SET_INIT))