Added support for bit/part select to mem2reg rewriter
authorClifford Wolf <clifford@clifford.at>
Thu, 17 Jul 2014 11:49:32 +0000 (13:49 +0200)
committerClifford Wolf <clifford@clifford.at>
Thu, 17 Jul 2014 11:49:32 +0000 (13:49 +0200)
frontends/ast/simplify.cc
tests/simple/memory.v

index 320c80d72fe7e3feb9cb765b2490578e8f86a769..eee5a7b39901d80a1dbbe64cc63e247ed1a84709 100644 (file)
@@ -1974,6 +1974,8 @@ void AstNode::mem2reg_as_needed_pass2(std::set<AstNode*> &mem2reg_set, AstNode *
                                continue;
                        AstNode *cond_node = new AstNode(AST_COND, AstNode::mkconst_int(i, false, addr_bits), new AstNode(AST_BLOCK));
                        AstNode *assign_reg = new AstNode(type, new AstNode(AST_IDENTIFIER), new AstNode(AST_IDENTIFIER));
+                       if (children[0]->children.size() == 2)
+                               assign_reg->children[0]->children.push_back(children[0]->children[1]->clone());
                        assign_reg->children[0]->str = stringf("%s[%d]", children[0]->str.c_str(), i);
                        assign_reg->children[1]->str = id_data;
                        cond_node->children[1]->children.push_back(assign_reg);
@@ -1990,6 +1992,10 @@ void AstNode::mem2reg_as_needed_pass2(std::set<AstNode*> &mem2reg_set, AstNode *
 
        if (type == AST_IDENTIFIER && id2ast && mem2reg_set.count(id2ast) > 0)
        {
+               AstNode *bit_part_sel = NULL;
+               if (children.size() == 2)
+                       bit_part_sel = children[1]->clone();
+
                if (children[0]->children[0]->type == AST_CONSTANT)
                {
                        int id = children[0]->children[0]->integer;
@@ -2073,6 +2079,9 @@ void AstNode::mem2reg_as_needed_pass2(std::set<AstNode*> &mem2reg_set, AstNode *
                        id2ast = NULL;
                        str = id_data;
                }
+
+               if (bit_part_sel)
+                       children.push_back(bit_part_sel);
        }
 
        assert(id2ast == NULL || mem2reg_set.count(id2ast) == 0);
index aae3feace535466db019c16c6bceb5ef33fe3236..21271b5e22dd81161e1a9e49c3a32c06113b00d1 100644 (file)
@@ -134,3 +134,24 @@ always @(posedge clk) begin
 end
 
 endmodule
+
+// ----------------------------------------------------------
+
+module test06(input clk, input rst, input [2:0] idx, input [7:0] din, output [7:0] dout);
+    (* gentb_constant=0 *) wire rst;
+    reg [7:0] test [0:7];
+    integer i;
+    always @(posedge clk or posedge rst) begin
+        if (rst) begin
+            for (i=0; i<8; i=i+1)
+                test[i] <= 0;
+        end else begin
+            test[0][2] <= din[1];
+            test[0][5] <= test[0][2];
+            test[idx][3] <= din[idx];
+            test[idx][6] <= test[idx][2];
+            test[idx][idx] <= !test[idx][idx];
+        end
+    end
+    assign dout = test[idx];
+endmodule