mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	write_xaiger: only instantiate each whitebox cell type once
This commit is contained in:
		
							parent
							
								
									e58c3f8351
								
							
						
					
					
						commit
						a75e08c709
					
				
					 1 changed files with 27 additions and 19 deletions
				
			
		| 
						 | 
					@ -605,15 +605,25 @@ struct XAigerWriter
 | 
				
			||||||
			RTLIL::Module *holes_module = module->design->addModule("$__holes__");
 | 
								RTLIL::Module *holes_module = module->design->addModule("$__holes__");
 | 
				
			||||||
			log_assert(holes_module);
 | 
								log_assert(holes_module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								dict<IdString, Cell*> cell_cache;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			int port_id = 1;
 | 
								int port_id = 1;
 | 
				
			||||||
			int box_count = 0;
 | 
								int box_count = 0;
 | 
				
			||||||
			for (auto cell : box_list) {
 | 
								for (auto cell : box_list) {
 | 
				
			||||||
				RTLIL::Module* box_module = module->design->module(cell->type);
 | 
									RTLIL::Module* box_module = module->design->module(cell->type);
 | 
				
			||||||
 | 
									log_assert(box_module);
 | 
				
			||||||
 | 
									IdString derived_name = box_module->derive(module->design, cell->parameters);
 | 
				
			||||||
 | 
									box_module = module->design->module(derived_name);
 | 
				
			||||||
 | 
									if (box_module->has_processes())
 | 
				
			||||||
 | 
										log_error("ABC9 box '%s' contains processes!\n", box_module->name.c_str());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				int box_inputs = 0, box_outputs = 0;
 | 
									int box_inputs = 0, box_outputs = 0;
 | 
				
			||||||
				Cell *holes_cell = nullptr;
 | 
									auto r = cell_cache.insert(std::make_pair(derived_name, nullptr));
 | 
				
			||||||
				if (box_module->get_bool_attribute("\\whitebox")) {
 | 
									Cell *holes_cell = r.first->second;
 | 
				
			||||||
 | 
									if (r.second && !holes_cell && box_module->get_bool_attribute("\\whitebox")) {
 | 
				
			||||||
					holes_cell = holes_module->addCell(cell->name, cell->type);
 | 
										holes_cell = holes_module->addCell(cell->name, cell->type);
 | 
				
			||||||
					holes_cell->parameters = cell->parameters;
 | 
										holes_cell->parameters = cell->parameters;
 | 
				
			||||||
 | 
										r.first->second = holes_cell;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// NB: Assume box_module->ports are sorted alphabetically
 | 
									// NB: Assume box_module->ports are sorted alphabetically
 | 
				
			||||||
| 
						 | 
					@ -622,8 +632,8 @@ struct XAigerWriter
 | 
				
			||||||
					RTLIL::Wire *w = box_module->wire(port_name);
 | 
										RTLIL::Wire *w = box_module->wire(port_name);
 | 
				
			||||||
					log_assert(w);
 | 
										log_assert(w);
 | 
				
			||||||
					RTLIL::Wire *holes_wire;
 | 
										RTLIL::Wire *holes_wire;
 | 
				
			||||||
					RTLIL::SigSpec port_wire;
 | 
										RTLIL::SigSpec port_sig;
 | 
				
			||||||
					if (w->port_input) {
 | 
										if (w->port_input)
 | 
				
			||||||
						for (int i = 0; i < GetSize(w); i++) {
 | 
											for (int i = 0; i < GetSize(w); i++) {
 | 
				
			||||||
							box_inputs++;
 | 
												box_inputs++;
 | 
				
			||||||
							holes_wire = holes_module->wire(stringf("\\i%d", box_inputs));
 | 
												holes_wire = holes_module->wire(stringf("\\i%d", box_inputs));
 | 
				
			||||||
| 
						 | 
					@ -634,28 +644,29 @@ struct XAigerWriter
 | 
				
			||||||
								holes_module->ports.push_back(holes_wire->name);
 | 
													holes_module->ports.push_back(holes_wire->name);
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							if (holes_cell)
 | 
												if (holes_cell)
 | 
				
			||||||
								port_wire.append(holes_wire);
 | 
													port_sig.append(holes_wire);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						if (!port_wire.empty())
 | 
					 | 
				
			||||||
							holes_cell->setPort(w->name, port_wire);
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if (w->port_output) {
 | 
										if (w->port_output) {
 | 
				
			||||||
						box_outputs += GetSize(w);
 | 
											box_outputs += GetSize(w);
 | 
				
			||||||
						for (int i = 0; i < GetSize(w); i++) {
 | 
											for (int i = 0; i < GetSize(w); i++) {
 | 
				
			||||||
							if (GetSize(w) == 1)
 | 
												if (GetSize(w) == 1)
 | 
				
			||||||
								holes_wire = holes_module->addWire(stringf("%s.%s", cell->name.c_str(), w->name.c_str()));
 | 
													holes_wire = holes_module->addWire(stringf("%s.%s", cell->name.c_str(), log_id(w->name)));
 | 
				
			||||||
							else
 | 
												else
 | 
				
			||||||
								holes_wire = holes_module->addWire(stringf("%s.%s[%d]", cell->name.c_str(), w->name.c_str(), i));
 | 
													holes_wire = holes_module->addWire(stringf("%s.%s[%d]", cell->name.c_str(), log_id(w->name), i));
 | 
				
			||||||
							holes_wire->port_output = true;
 | 
												holes_wire->port_output = true;
 | 
				
			||||||
							holes_wire->port_id = port_id++;
 | 
												holes_wire->port_id = port_id++;
 | 
				
			||||||
							holes_module->ports.push_back(holes_wire->name);
 | 
												holes_module->ports.push_back(holes_wire->name);
 | 
				
			||||||
							if (holes_cell)
 | 
												if (holes_cell)
 | 
				
			||||||
								port_wire.append(holes_wire);
 | 
													port_sig.append(holes_wire);
 | 
				
			||||||
							else
 | 
												else
 | 
				
			||||||
								holes_module->connect(holes_wire, State::S0);
 | 
													holes_module->connect(holes_wire, State::S0);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						if (!port_wire.empty())
 | 
										}
 | 
				
			||||||
							holes_cell->setPort(w->name, port_wire);
 | 
										if (!port_sig.empty()) {
 | 
				
			||||||
 | 
											if (r.second)
 | 
				
			||||||
 | 
												holes_cell->setPort(w->name, port_sig);
 | 
				
			||||||
 | 
											else
 | 
				
			||||||
 | 
												holes_module->connect(holes_cell->getPort(w->name), port_sig);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -685,14 +696,11 @@ struct XAigerWriter
 | 
				
			||||||
				RTLIL::Selection& sel = holes_module->design->selection_stack.back();
 | 
									RTLIL::Selection& sel = holes_module->design->selection_stack.back();
 | 
				
			||||||
				sel.select(holes_module);
 | 
									sel.select(holes_module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// TODO: Should not need to opt_merge if we only instantiate
 | 
					 | 
				
			||||||
				//       each box type once...
 | 
					 | 
				
			||||||
				Pass::call(holes_module->design, "opt_merge -share_all");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				Pass::call(holes_module->design, "flatten -wb");
 | 
									Pass::call(holes_module->design, "flatten -wb");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// TODO: Should techmap/aigmap/check all lib_whitebox-es just once,
 | 
									// Cannot techmap/aigmap/check all lib_whitebox-es outside of write_xaiger
 | 
				
			||||||
				//       instead of per write_xaiger call
 | 
									//   since boxes may contain parameters in which case `flatten` would have
 | 
				
			||||||
 | 
									//   created a new $paramod ...
 | 
				
			||||||
				Pass::call(holes_module->design, "techmap");
 | 
									Pass::call(holes_module->design, "techmap");
 | 
				
			||||||
				Pass::call(holes_module->design, "aigmap");
 | 
									Pass::call(holes_module->design, "aigmap");
 | 
				
			||||||
				for (auto cell : holes_module->cells())
 | 
									for (auto cell : holes_module->cells())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue