Skip to content

Commit 9da4fe7

Browse files
committed
fix bus ioff inference
1 parent 2241a65 commit 9da4fe7

File tree

2 files changed

+91
-8
lines changed

2 files changed

+91
-8
lines changed

techlibs/quicklogic/ql_ioff.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,29 @@ struct QlIoffPass : public Pass {
3939
if (!(e_const && r_const && s_const))
4040
continue;
4141

42-
auto d_sig = modwalker.sigmap(cell->getPort(ID::D));
43-
if (d_sig.is_wire() && d_sig.as_wire()->port_input) {
42+
SigSpec d = cell->getPort(ID::D);
43+
if (GetSize(d) != 1) continue;
44+
SigBit d_sig = modwalker.sigmap(d[0]);
45+
if (d_sig.is_wire() && d_sig.wire->port_input) {
4446
log_debug("Cell %s is potentially eligible for promotion to input IOFF.\n", cell->name.c_str());
4547
// check that d_sig has no other consumers
46-
if (GetSize(d_sig) != 1) continue;
4748
pool<ModWalker::PortBit> portbits;
48-
modwalker.get_consumers(portbits, d_sig[0]);
49+
modwalker.get_consumers(portbits, d_sig);
4950
if (GetSize(portbits) > 1) {
5051
log_debug("not promoting: d_sig has other consumers\n");
5152
continue;
5253
}
5354
cells_to_replace.insert(cell);
5455
continue; // no need to check Q if we already put it on the list
5556
}
56-
auto q_sig = modwalker.sigmap(cell->getPort(ID::Q));
57-
if (q_sig.is_wire() && q_sig.as_wire()->port_output) {
57+
SigSpec q = cell->getPort(ID::Q);
58+
if (GetSize(q) != 1) continue;
59+
SigBit q_sig = modwalker.sigmap(q[0]);
60+
if (q_sig.is_wire() && q_sig.wire->port_output) {
5861
log_debug("Cell %s is potentially eligible for promotion to output IOFF.\n", cell->name.c_str());
5962
// check that q_sig has no other consumers
60-
if (GetSize(q_sig) != 1) continue;
6163
pool<ModWalker::PortBit> portbits;
62-
modwalker.get_consumers(portbits, q_sig[0]);
64+
modwalker.get_consumers(portbits, q_sig);
6365
if (GetSize(portbits) > 0) {
6466
log_debug("not promoting: q_sig has other consumers\n");
6567
continue;

tests/arch/quicklogic/qlf_k6n10f/ioff.ys

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ EOF
99
synth_quicklogic -family qlf_k6n10f -top top
1010
select -assert-count 1 t:dff
1111

12+
design -reset
13+
# test: acceptable for output IOFF promotion
14+
read_verilog <<EOF
15+
module top (input clk, input [3:0] a, output reg [3:0] o);
16+
always @(posedge clk) begin
17+
o <= ~a;
18+
end
19+
endmodule
20+
EOF
21+
synth_quicklogic -family qlf_k6n10f -top top
22+
select -assert-count 4 t:dff
23+
1224
design -reset
1325
# test: acceptable for input IOFF promotion
1426
read_verilog <<EOF
@@ -23,6 +35,20 @@ EOF
2335
synth_quicklogic -family qlf_k6n10f -top top
2436
select -assert-count 1 t:dff
2537

38+
design -reset
39+
# test: acceptable for input IOFF promotion
40+
read_verilog <<EOF
41+
module top (input clk, input [3:0] a, output [3:0] o);
42+
reg [3:0] r;
43+
always @(posedge clk) begin
44+
r <= a;
45+
end
46+
assign o = ~r;
47+
endmodule
48+
EOF
49+
synth_quicklogic -family qlf_k6n10f -top top
50+
select -assert-count 4 t:dff
51+
2652
design -reset
2753
# test: acceptable for either IOFF promotion
2854
read_verilog <<EOF
@@ -47,6 +73,18 @@ EOF
4773
synth_quicklogic -family qlf_k6n10f -top top
4874
select -assert-count 0 t:dff
4975

76+
design -reset
77+
# test: not acceptable for output IOFF promotion: output signal is used
78+
read_verilog <<EOF
79+
module top (input clk, input [3:0] a, output reg [3:0] o);
80+
always @(posedge clk) begin
81+
o <= ~a | o;
82+
end
83+
endmodule
84+
EOF
85+
synth_quicklogic -family qlf_k6n10f -top top
86+
select -assert-count 0 t:dff
87+
5088
design -reset
5189
# test: not acceptable for input IOFF promotion: input signal is used
5290
read_verilog <<EOF
@@ -62,6 +100,21 @@ EOF
62100
synth_quicklogic -family qlf_k6n10f -top top
63101
select -assert-count 0 t:dff
64102

103+
design -reset
104+
# test: not acceptable for input IOFF promotion: input signal is used
105+
read_verilog <<EOF
106+
module top (input clk, input [3:0] a, output [3:0] o, output [3:0] p);
107+
reg [3:0] r;
108+
always @(posedge clk) begin
109+
r <= a;
110+
end
111+
assign o = ~r;
112+
assign p = ~a;
113+
endmodule
114+
EOF
115+
synth_quicklogic -family qlf_k6n10f -top top
116+
select -assert-count 0 t:dff
117+
65118
design -reset
66119
# test: not acceptable for IOFF promotion: FF has reset
67120
read_verilog <<EOF
@@ -77,6 +130,21 @@ EOF
77130
synth_quicklogic -family qlf_k6n10f -top top
78131
select -assert-count 0 t:dff
79132

133+
design -reset
134+
# test: not acceptable for IOFF promotion: FF has reset
135+
read_verilog <<EOF
136+
module top (input clk, input rst, input [3:0] a, output reg [3:0] o);
137+
always @(posedge clk) begin
138+
if (rst)
139+
o <= 4'b0;
140+
else
141+
o <= a;
142+
end
143+
endmodule
144+
EOF
145+
synth_quicklogic -family qlf_k6n10f -top top
146+
select -assert-count 0 t:dff
147+
80148
design -reset
81149
# test: not acceptable for IOFF promotion: FF has enable
82150
read_verilog <<EOF
@@ -89,3 +157,16 @@ endmodule
89157
EOF
90158
synth_quicklogic -family qlf_k6n10f -top top
91159
select -assert-count 0 t:dff
160+
161+
design -reset
162+
# test: not acceptable for IOFF promotion: FF has enable
163+
read_verilog <<EOF
164+
module top (input clk, input en, input [3:0] a, output reg [3:0] o);
165+
always @(posedge clk) begin
166+
if (en)
167+
o <= a;
168+
end
169+
endmodule
170+
EOF
171+
synth_quicklogic -family qlf_k6n10f -top top
172+
select -assert-count 0 t:dff

0 commit comments

Comments
 (0)