mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Add handling of init attributes in "opt_expr -undriven"
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
		
							parent
							
								
									754b1ee4b3
								
							
						
					
					
						commit
						9d117eba9d
					
				
					 2 changed files with 42 additions and 3 deletions
				
			
		| 
						 | 
					@ -39,6 +39,9 @@ void replace_undriven(RTLIL::Design *design, RTLIL::Module *module)
 | 
				
			||||||
	SigPool used_signals;
 | 
						SigPool used_signals;
 | 
				
			||||||
	SigPool all_signals;
 | 
						SigPool all_signals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dict<SigBit, pair<Wire*, State>> initbits;
 | 
				
			||||||
 | 
						pool<Wire*> revisit_initwires;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (auto cell : module->cells())
 | 
						for (auto cell : module->cells())
 | 
				
			||||||
	for (auto &conn : cell->connections()) {
 | 
						for (auto &conn : cell->connections()) {
 | 
				
			||||||
		if (!ct.cell_known(cell->type) || ct.cell_output(cell->type, conn.first))
 | 
							if (!ct.cell_known(cell->type) || ct.cell_output(cell->type, conn.first))
 | 
				
			||||||
| 
						 | 
					@ -48,6 +51,14 @@ void replace_undriven(RTLIL::Design *design, RTLIL::Module *module)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (auto wire : module->wires()) {
 | 
						for (auto wire : module->wires()) {
 | 
				
			||||||
 | 
							if (wire->attributes.count("\\init")) {
 | 
				
			||||||
 | 
								SigSpec sig = sigmap(wire);
 | 
				
			||||||
 | 
								Const initval = wire->attributes.at("\\init");
 | 
				
			||||||
 | 
								for (int i = 0; i < GetSize(initval) && i < GetSize(wire); i++) {
 | 
				
			||||||
 | 
									if (initval[i] == State::S0 || initval[i] == State::S1)
 | 
				
			||||||
 | 
										initbits[sig[i]] = make_pair(wire, initval[i]);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if (wire->port_input)
 | 
							if (wire->port_input)
 | 
				
			||||||
			driven_signals.add(sigmap(wire));
 | 
								driven_signals.add(sigmap(wire));
 | 
				
			||||||
		if (wire->port_output)
 | 
							if (wire->port_output)
 | 
				
			||||||
| 
						 | 
					@ -67,10 +78,38 @@ void replace_undriven(RTLIL::Design *design, RTLIL::Module *module)
 | 
				
			||||||
		if (sig.size() == 0)
 | 
							if (sig.size() == 0)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log_debug("Setting undriven signal in %s to undef: %s\n", RTLIL::id2cstr(module->name), log_signal(c));
 | 
							Const val(RTLIL::State::Sx, GetSize(sig));
 | 
				
			||||||
		module->connect(RTLIL::SigSig(c, RTLIL::SigSpec(RTLIL::State::Sx, c.width)));
 | 
							for (int i = 0; i < GetSize(sig); i++) {
 | 
				
			||||||
 | 
								SigBit bit = sigmap(sig[i]);
 | 
				
			||||||
 | 
								auto cursor = initbits.find(bit);
 | 
				
			||||||
 | 
								if (cursor != initbits.end()) {
 | 
				
			||||||
 | 
									revisit_initwires.insert(cursor->second.first);
 | 
				
			||||||
 | 
									val[i] = cursor->second.second;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							log_debug("Setting undriven signal in %s to constant: %s = %s\n", RTLIL::id2cstr(module->name), log_signal(sig), log_signal(val));
 | 
				
			||||||
 | 
							module->connect(sig, val);
 | 
				
			||||||
		did_something = true;
 | 
							did_something = true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!revisit_initwires.empty())
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							SigMap sm2(module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for (auto wire : revisit_initwires) {
 | 
				
			||||||
 | 
								SigSpec sig = sm2(wire);
 | 
				
			||||||
 | 
								Const initval = wire->attributes.at("\\init");
 | 
				
			||||||
 | 
								for (int i = 0; i < GetSize(initval) && i < GetSize(wire); i++) {
 | 
				
			||||||
 | 
									if (SigBit(initval[i]) == sig[i])
 | 
				
			||||||
 | 
										initval[i] = State::Sx;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (initval.is_fully_undef())
 | 
				
			||||||
 | 
									wire->attributes.erase("\\init");
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									wire->attributes["\\init"] = initval;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void replace_cell(SigMap &assign_map, RTLIL::Module *module, RTLIL::Cell *cell, std::string info, std::string out_port, RTLIL::SigSpec out_val)
 | 
					void replace_cell(SigMap &assign_map, RTLIL::Module *module, RTLIL::Cell *cell, std::string info, std::string out_port, RTLIL::SigSpec out_val)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -253,7 +253,7 @@ struct SynthEcp5Pass : public ScriptPass
 | 
				
			||||||
			if (!nodffe)
 | 
								if (!nodffe)
 | 
				
			||||||
				run("dff2dffe -direct-match $_DFF_* -direct-match $__DFFS_*");
 | 
									run("dff2dffe -direct-match $_DFF_* -direct-match $__DFFS_*");
 | 
				
			||||||
			run("techmap -D NO_LUT -map +/ecp5/cells_map.v");
 | 
								run("techmap -D NO_LUT -map +/ecp5/cells_map.v");
 | 
				
			||||||
			run("opt_expr -mux_undef");
 | 
								run("opt_expr -undriven -mux_undef");
 | 
				
			||||||
			run("simplemap");
 | 
								run("simplemap");
 | 
				
			||||||
			run("ecp5_ffinit");
 | 
								run("ecp5_ffinit");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue