@@ -109,13 +109,43 @@ struct CutpointPass : public Pass {
109109 SigMap sigmap (module );
110110 pool<SigBit> cutpoint_bits;
111111
112+ pool<SigBit> wire_drivers;
113+ for (auto cell : module ->cells ())
114+ for (auto &conn : cell->connections ())
115+ if (cell->output (conn.first ) && !cell->input (conn.first ))
116+ for (auto bit : sigmap (conn.second ))
117+ if (bit.wire )
118+ wire_drivers.insert (bit);
119+
120+ for (auto wire : module ->wires ())
121+ if (wire->port_input )
122+ for (auto bit : sigmap (wire))
123+ wire_drivers.insert (bit);
124+
112125 for (auto cell : module ->selected_cells ()) {
113126 if (cell->type == ID ($anyseq))
114127 continue ;
115128 log (" Removing cell %s.%s, making all cell outputs cutpoints.\n " , log_id (module ), log_id (cell));
116129 for (auto &conn : cell->connections ()) {
117- if (cell->output (conn.first ))
118- module ->connect (conn.second , flag_undef ? Const (State::Sx, GetSize (conn.second )) : module ->Anyseq (NEW_ID, GetSize (conn.second )));
130+ if (cell->output (conn.first )) {
131+ bool do_cut = true ;
132+ if (cell->input (conn.first ))
133+ for (auto bit : sigmap (conn.second ))
134+ if (wire_drivers.count (bit)) {
135+ log_debug (" Treating inout port '%s' as input.\n " , id2cstr (conn.first ));
136+ do_cut = false ;
137+ break ;
138+ }
139+
140+ if (do_cut) {
141+ module ->connect (conn.second , flag_undef ? Const (State::Sx, GetSize (conn.second )) : module ->Anyseq (NEW_ID, GetSize (conn.second )));
142+ if (cell->input (conn.first )) {
143+ log_debug (" Treating inout port '%s' as output.\n " , id2cstr (conn.first ));
144+ for (auto bit : sigmap (conn.second ))
145+ wire_drivers.insert (bit);
146+ }
147+ }
148+ }
119149 }
120150
121151 RTLIL::Cell *scopeinfo = nullptr ;
0 commit comments