Skip to content

Commit d4071b6

Browse files
Merge pull request #5268 from YosysHQ/krys/cutpoint_inout
Track wire drivers in cutpoint
2 parents fcc3d71 + af7d1d3 commit d4071b6

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

passes/sat/cutpoint.cc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

tests/various/cutpoint_blackbox.ys

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,44 @@ design -load gold
7070
select -read cutpoint.gate.sel
7171
# nothing in gold but not gate
7272
select -assert-none % %n
73+
74+
# replacing the blackbox with a verific-style unknown module should work too
75+
# (note this specific example loses the values of SOME_PARAM which would
76+
# normally be retained by verific)
77+
design -load hier
78+
delete =bb
79+
read_rtlil << EOT
80+
attribute \blackbox 1
81+
module \bb
82+
parameter \SOME_PARAM 0
83+
wire inout 3 \o
84+
wire inout 2 \b
85+
wire inout 1 \a
86+
end
87+
EOT
88+
cutpoint -blackbox
89+
check -assert
90+
91+
# also concatenated signals, and signals between two inout ports
92+
design -load hier
93+
delete top =bb
94+
read_verilog << EOT
95+
module top(input [1:0] a, b, output [1:0] o);
96+
wire [1:0] c, d, e;
97+
bb #(.SOME_PARAM(1)) bb1 (.a ({a[0], e[1]}), .b (b), .o (c));
98+
bb #(.SOME_PARAM(2)) bb2 (.a ({c[1], a[0]}), .b (c), .o (d));
99+
wb wb1 (.a (a), .b (b), .o (e));
100+
some_mod some_inst (.a (c), .b (d), .c (e), .o (o));
101+
endmodule
102+
EOT
103+
read_rtlil << EOT
104+
attribute \blackbox 1
105+
module \bb
106+
parameter \SOME_PARAM 0
107+
wire inout 3 width 2 \o
108+
wire inout 2 width 2 \b
109+
wire inout 1 width 2 \a
110+
end
111+
EOT
112+
cutpoint -blackbox
113+
check -assert

0 commit comments

Comments
 (0)