Add -select option to aigmap

This commit is contained in:
Eddie Hung 2019-09-27 17:44:01 -07:00
parent 11cb5fab00
commit fe722b737c
1 changed files with 40 additions and 6 deletions

View File

@ -27,6 +27,7 @@ struct AigmapPass : public Pass {
AigmapPass() : Pass("aigmap", "map logic to and-inverter-graph circuit") { } AigmapPass() : Pass("aigmap", "map logic to and-inverter-graph circuit") { }
void help() YS_OVERRIDE void help() YS_OVERRIDE
{ {
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n"); log("\n");
log(" aigmap [options] [selection]\n"); log(" aigmap [options] [selection]\n");
log("\n"); log("\n");
@ -36,10 +37,15 @@ struct AigmapPass : public Pass {
log(" -nand\n"); log(" -nand\n");
log(" Enable creation of $_NAND_ cells\n"); log(" Enable creation of $_NAND_ cells\n");
log("\n"); log("\n");
log(" -select\n");
log(" Overwrite replaced cells in the current selection with new $_AND_,\n");
log(" $_NOT_, and $_NAND_, cells\n");
log("\n");
} }
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
{ {
bool nand_mode = false; bool nand_mode = false, select_mode = false;
log_header(design, "Executing AIGMAP pass (map logic to AIG).\n"); log_header(design, "Executing AIGMAP pass (map logic to AIG).\n");
@ -50,6 +56,10 @@ struct AigmapPass : public Pass {
nand_mode = true; nand_mode = true;
continue; continue;
} }
if (args[argidx] == "-select") {
select_mode = true;
continue;
}
break; break;
} }
extra_args(args, argidx, design); extra_args(args, argidx, design);
@ -62,6 +72,7 @@ struct AigmapPass : public Pass {
dict<IdString, int> stat_not_replaced; dict<IdString, int> stat_not_replaced;
int orig_num_cells = GetSize(module->cells()); int orig_num_cells = GetSize(module->cells());
pool<IdString> new_sel;
for (auto cell : module->selected_cells()) for (auto cell : module->selected_cells())
{ {
Aig aig(cell); Aig aig(cell);
@ -75,6 +86,8 @@ struct AigmapPass : public Pass {
if (aig.name.empty()) { if (aig.name.empty()) {
not_replaced_count++; not_replaced_count++;
stat_not_replaced[cell->type]++; stat_not_replaced[cell->type]++;
if (select_mode)
new_sel.insert(cell->name);
continue; continue;
} }
@ -95,19 +108,33 @@ struct AigmapPass : public Pass {
SigBit A = sigs.at(node.left_parent); SigBit A = sigs.at(node.left_parent);
SigBit B = sigs.at(node.right_parent); SigBit B = sigs.at(node.right_parent);
if (nand_mode && node.inverter) { if (nand_mode && node.inverter) {
bit = module->NandGate(NEW_ID, A, B); bit = module->addWire(NEW_ID);
auto gate = module->addNandGate(NEW_ID, A, B, bit);
if (select_mode)
new_sel.insert(gate->name);
goto skip_inverter; goto skip_inverter;
} else { } else {
pair<int, int> key(node.left_parent, node.right_parent); pair<int, int> key(node.left_parent, node.right_parent);
if (and_cache.count(key)) if (and_cache.count(key))
bit = and_cache.at(key); bit = and_cache.at(key);
else else {
bit = module->AndGate(NEW_ID, A, B); bit = module->addWire(NEW_ID);
auto gate = module->addAndGate(NEW_ID, A, B, bit);
if (select_mode)
new_sel.insert(gate->name);
}
} }
} }
if (node.inverter) if (node.inverter) {
bit = module->NotGate(NEW_ID, bit); SigBit new_bit = module->addWire(NEW_ID);
auto gate = module->addNotGate(NEW_ID, bit, new_bit);
bit = new_bit;
if (select_mode)
new_sel.insert(gate->name);
}
skip_inverter: skip_inverter:
for (auto &op : node.outports) for (auto &op : node.outports)
@ -142,6 +169,13 @@ struct AigmapPass : public Pass {
for (auto cell : replaced_cells) for (auto cell : replaced_cells)
module->remove(cell); module->remove(cell);
if (select_mode) {
log_assert(!design->selection_stack.empty());
RTLIL::Selection& sel = design->selection_stack.back();
sel.selected_members[module->name] = std::move(new_sel);
}
} }
} }
} AigmapPass; } AigmapPass;