Skip to content

Commit 38f8165

Browse files
rocallahanjix
authored andcommitted
Remove direct RTLIL access from gate_t
1 parent 222f457 commit 38f8165

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

passes/techmap/abc.cc

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ struct gate_t
104104
gate_type_t type;
105105
int in1, in2, in3, in4;
106106
bool is_port;
107-
RTLIL::SigBit bit;
107+
bool bit_is_wire;
108+
bool bit_is_1;
108109
RTLIL::State init;
110+
std::string bit_str;
109111
};
110112

111113
bool map_mux4;
@@ -156,6 +158,7 @@ struct AbcModuleState {
156158

157159
int map_autoidx = 0;
158160
std::vector<gate_t> signal_list;
161+
std::vector<RTLIL::SigBit> signal_bits;
159162
dict<RTLIL::SigBit, int> signal_map;
160163
FfInitVals &initvals;
161164
bool had_init = false;
@@ -204,10 +207,13 @@ int AbcModuleState::map_signal(const AbcSigMap &assign_map, RTLIL::SigBit bit, g
204207
gate.in3 = -1;
205208
gate.in4 = -1;
206209
gate.is_port = bit.wire != nullptr && val.is_port;
207-
gate.bit = bit;
210+
gate.bit_is_wire = bit.wire != nullptr;
211+
gate.bit_is_1 = bit == State::S1;
208212
gate.init = initvals(bit);
209-
signal_list.push_back(gate);
213+
gate.bit_str = std::string(log_signal(bit));
210214
signal_map[bit] = gate.id;
215+
signal_list.push_back(std::move(gate));
216+
signal_bits.push_back(bit);
211217
}
212218

213219
gate_t &gate = signal_list[signal_map[bit]];
@@ -463,17 +469,17 @@ std::string AbcModuleState::remap_name(RTLIL::IdString abc_name, RTLIL::Wire **o
463469

464470
if (sid < GetSize(signal_list))
465471
{
466-
auto sig = signal_list.at(sid);
467-
if (sig.bit.wire != nullptr)
472+
const auto &bit = signal_bits.at(sid);
473+
if (bit.wire != nullptr)
468474
{
469-
std::string s = stringf("$abc$%d$%s", map_autoidx, sig.bit.wire->name.c_str()+1);
470-
if (sig.bit.wire->width != 1)
471-
s += stringf("[%d]", sig.bit.offset);
475+
std::string s = stringf("$abc$%d$%s", map_autoidx, bit.wire->name.c_str()+1);
476+
if (bit.wire->width != 1)
477+
s += stringf("[%d]", bit.offset);
472478
if (isnew)
473479
s += "_new";
474480
s += postfix;
475481
if (orig_wire != nullptr)
476-
*orig_wire = sig.bit.wire;
482+
*orig_wire = bit.wire;
477483
return s;
478484
}
479485
}
@@ -501,7 +507,7 @@ void AbcModuleState::dump_loop_graph(FILE *f, int &nr, dict<int, pool<int>> &edg
501507
}
502508

503509
for (auto n : nodes)
504-
fprintf(f, " ys__n%d [label=\"%s\\nid=%d, count=%d\"%s];\n", n, log_signal(signal_list[n].bit),
510+
fprintf(f, " ys__n%d [label=\"%s\\nid=%d, count=%d\"%s];\n", n, signal_list[n].bit_str.c_str(),
505511
n, in_counts[n], workpool.count(n) ? ", shape=box" : "");
506512

507513
for (auto &e : edges)
@@ -562,7 +568,7 @@ void AbcModuleState::handle_loops(AbcSigMap &assign_map, RTLIL::Module *module)
562568
int id = *workpool.begin();
563569
workpool.erase(id);
564570

565-
// log("Removing non-loop node %d from graph: %s\n", id, log_signal(signal_list[id].bit));
571+
// log("Removing non-loop node %d from graph: %s\n", id, signal_list[id].bit_str);
566572

567573
for (int id2 : edges[id]) {
568574
log_assert(in_edges_count[id2] > 0);
@@ -582,8 +588,8 @@ void AbcModuleState::handle_loops(AbcSigMap &assign_map, RTLIL::Module *module)
582588

583589
for (auto &edge_it : edges) {
584590
int id2 = edge_it.first;
585-
RTLIL::Wire *w1 = signal_list[id1].bit.wire;
586-
RTLIL::Wire *w2 = signal_list[id2].bit.wire;
591+
RTLIL::Wire *w1 = signal_bits[id1].wire;
592+
RTLIL::Wire *w2 = signal_bits[id2].wire;
587593
if (w1 == nullptr)
588594
id1 = id2;
589595
else if (w2 == nullptr)
@@ -605,7 +611,7 @@ void AbcModuleState::handle_loops(AbcSigMap &assign_map, RTLIL::Module *module)
605611
continue;
606612
}
607613

608-
log_assert(signal_list[id1].bit.wire != nullptr);
614+
log_assert(signal_bits[id1].wire != nullptr);
609615

610616
std::stringstream sstr;
611617
sstr << "$abcloop$" << (autoidx++);
@@ -615,10 +621,10 @@ void AbcModuleState::handle_loops(AbcSigMap &assign_map, RTLIL::Module *module)
615621
for (int id2 : edges[id1]) {
616622
if (first_line)
617623
log("Breaking loop using new signal %s: %s -> %s\n", log_signal(RTLIL::SigSpec(wire)),
618-
log_signal(signal_list[id1].bit), log_signal(signal_list[id2].bit));
624+
signal_list[id1].bit_str, signal_list[id2].bit_str);
619625
else
620626
log(" %*s %s -> %s\n", int(strlen(log_signal(RTLIL::SigSpec(wire)))), "",
621-
log_signal(signal_list[id1].bit), log_signal(signal_list[id2].bit));
627+
signal_list[id1].bit_str, signal_list[id2].bit_str);
622628
first_line = false;
623629
}
624630

@@ -641,7 +647,7 @@ void AbcModuleState::handle_loops(AbcSigMap &assign_map, RTLIL::Module *module)
641647
}
642648
edges[id1].swap(edges[id3]);
643649

644-
connect(assign_map, module, RTLIL::SigSig(signal_list[id3].bit, signal_list[id1].bit));
650+
connect(assign_map, module, RTLIL::SigSig(signal_bits[id3], signal_bits[id1]));
645651
dump_loop_graph(dot_f, dot_nr, edges, workpool, in_edges_count);
646652
}
647653
}
@@ -1006,7 +1012,7 @@ void AbcModuleState::run_abc()
10061012
if (!si.is_port || si.type != G(NONE))
10071013
continue;
10081014
fprintf(f, " ys__n%d", si.id);
1009-
pi_map[count_input++] = log_signal(si.bit);
1015+
pi_map[count_input++] = si.bit_str;
10101016
}
10111017
if (count_input == 0)
10121018
fprintf(f, " dummy_input\n");
@@ -1018,17 +1024,17 @@ void AbcModuleState::run_abc()
10181024
if (!si.is_port || si.type == G(NONE))
10191025
continue;
10201026
fprintf(f, " ys__n%d", si.id);
1021-
po_map[count_output++] = log_signal(si.bit);
1027+
po_map[count_output++] = si.bit_str;
10221028
}
10231029
fprintf(f, "\n");
10241030

10251031
for (auto &si : signal_list)
1026-
fprintf(f, "# ys__n%-5d %s\n", si.id, log_signal(si.bit));
1032+
fprintf(f, "# ys__n%-5d %s\n", si.id, si.bit_str.c_str());
10271033

10281034
for (auto &si : signal_list) {
1029-
if (si.bit.wire == nullptr) {
1035+
if (!si.bit_is_wire) {
10301036
fprintf(f, ".names ys__n%d\n", si.id);
1031-
if (si.bit == RTLIL::State::S1)
1037+
if (si.bit_is_1)
10321038
fprintf(f, "1\n");
10331039
}
10341040
}
@@ -1503,12 +1509,12 @@ void AbcModuleState::extract(AbcSigMap &assign_map, RTLIL::Design *design, RTLIL
15031509
snprintf(buffer, 100, "\\ys__n%d", si.id);
15041510
RTLIL::SigSig conn;
15051511
if (si.type != G(NONE)) {
1506-
conn.first = si.bit;
1512+
conn.first = signal_bits[si.id];
15071513
conn.second = module->wire(remap_name(buffer));
15081514
out_wires++;
15091515
} else {
15101516
conn.first = module->wire(remap_name(buffer));
1511-
conn.second = si.bit;
1517+
conn.second = signal_bits[si.id];
15121518
in_wires++;
15131519
}
15141520
connect(assign_map, module, conn);

0 commit comments

Comments
 (0)