Improvements in equiv_struct
authorClifford Wolf <clifford@clifford.at>
Sat, 24 Oct 2015 21:04:17 +0000 (23:04 +0200)
committerClifford Wolf <clifford@clifford.at>
Sat, 24 Oct 2015 21:04:17 +0000 (23:04 +0200)
passes/equiv/equiv_struct.cc

index c509e25565c30de0ad6079ebdc07093421394cf3..d231913c2a48a1a12ec86c96a84f7424d9e87261 100644 (file)
@@ -116,9 +116,15 @@ struct EquivStructWorker
        {
                log("  Starting new iteration.\n");
 
+               pool<SigBit> equiv_inputs;
+
                for (auto cell : module->selected_cells())
                        if (cell->type == "$equiv") {
-                               equiv_bits.add(sigmap(cell->getPort("\\A")), sigmap(cell->getPort("\\B")));
+                               SigBit sig_a = sigmap(cell->getPort("\\A").as_bit());
+                               SigBit sig_b = sigmap(cell->getPort("\\B").as_bit());
+                               equiv_bits.add(sig_b, sig_a);
+                               equiv_inputs.insert(sig_a);
+                               equiv_inputs.insert(sig_b);
                                cells_by_type[cell->type].insert(cell->name);
                        } else
                        if (module->design->selected(module, cell)) {
@@ -126,6 +132,21 @@ struct EquivStructWorker
                                        cells_by_type[cell->type].insert(cell->name);
                        }
 
+               for (auto cell_name : cells_by_type["$equiv"]) {
+                       Cell *cell = module->cell(cell_name);
+                       SigBit sig_a = sigmap(cell->getPort("\\A").as_bit());
+                       SigBit sig_b = sigmap(cell->getPort("\\B").as_bit());
+                       SigBit sig_y = sigmap(cell->getPort("\\Y").as_bit());
+                       if (sig_a == sig_b && equiv_inputs.count(sig_y)) {
+                               log("    Purging redundant $equiv cell %s.\n", log_id(cell));
+                               module->remove(cell);
+                               merge_count++;
+                       }
+               }
+
+               if (merge_count > 0)
+                       return;
+
                for (auto &it : cells_by_type)
                {
                        if (it.second.size() <= 1)