@@ -142,7 +142,6 @@ struct AbcModuleState {
142
142
const AbcConfig &config;
143
143
144
144
int map_autoidx = 0 ;
145
- SigMap assign_map;
146
145
std::vector<gate_t > signal_list;
147
146
dict<RTLIL::SigBit, int > signal_map;
148
147
FfInitVals initvals;
@@ -162,19 +161,19 @@ struct AbcModuleState {
162
161
163
162
AbcModuleState (const AbcConfig &config) : config(config) {}
164
163
165
- int map_signal (RTLIL::SigBit bit, gate_type_t gate_type = G(NONE), int in1 = -1, int in2 = -1, int in3 = -1, int in4 = -1);
166
- void mark_port (RTLIL::SigSpec sig);
167
- void extract_cell (RTLIL::Module *module , RTLIL::Cell *cell, bool keepff);
164
+ int map_signal (const SigMap &assign_map, RTLIL::SigBit bit, gate_type_t gate_type = G(NONE), int in1 = -1, int in2 = -1, int in3 = -1, int in4 = -1);
165
+ void mark_port (const SigMap &assign_map, RTLIL::SigSpec sig);
166
+ void extract_cell (const SigMap &assign_map, RTLIL::Module *module , RTLIL::Cell *cell, bool keepff);
168
167
std::string remap_name (RTLIL::IdString abc_name, RTLIL::Wire **orig_wire = nullptr );
169
168
void dump_loop_graph (FILE *f, int &nr, dict<int , pool<int >> &edges, pool<int > &workpool, std::vector<int > &in_counts);
170
- void handle_loops (RTLIL::Module *module );
171
- void abc_module (RTLIL::Design *design, RTLIL::Module *module , const std::vector<RTLIL::Cell*> &cells,
169
+ void handle_loops (SigMap &assign_map, RTLIL::Module *module );
170
+ void abc_module (RTLIL::Design *design, RTLIL::Module *module , SigMap &assign_map, const std::vector<RTLIL::Cell*> &cells,
172
171
bool dff_mode, std::string clk_str);
173
- void extract (RTLIL::Design *design, RTLIL::Module *module );
172
+ void extract (SigMap &assign_map, RTLIL::Design *design, RTLIL::Module *module );
174
173
void finish ();
175
174
};
176
175
177
- int AbcModuleState::map_signal (RTLIL::SigBit bit, gate_type_t gate_type, int in1, int in2, int in3, int in4)
176
+ int AbcModuleState::map_signal (const SigMap &assign_map, RTLIL::SigBit bit, gate_type_t gate_type, int in1, int in2, int in3, int in4)
178
177
{
179
178
assign_map.apply (bit);
180
179
@@ -212,14 +211,14 @@ int AbcModuleState::map_signal(RTLIL::SigBit bit, gate_type_t gate_type, int in1
212
211
return gate.id ;
213
212
}
214
213
215
- void AbcModuleState::mark_port (RTLIL::SigSpec sig)
214
+ void AbcModuleState::mark_port (const SigMap &assign_map, RTLIL::SigSpec sig)
216
215
{
217
216
for (auto &bit : assign_map (sig))
218
217
if (bit.wire != nullptr && signal_map.count (bit) > 0 )
219
218
signal_list[signal_map[bit]].is_port = true ;
220
219
}
221
220
222
- void AbcModuleState::extract_cell (RTLIL::Module *module , RTLIL::Cell *cell, bool keepff)
221
+ void AbcModuleState::extract_cell (const SigMap &assign_map, RTLIL::Module *module , RTLIL::Cell *cell, bool keepff)
223
222
{
224
223
if (RTLIL::builtin_ff_cell_types ().count (cell->type )) {
225
224
FfData ff (&initvals, cell);
@@ -296,7 +295,7 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
296
295
if (c.wire != nullptr )
297
296
c.wire ->attributes [ID::keep] = 1 ;
298
297
299
- map_signal (ff.sig_q , type, map_signal (ff.sig_d ));
298
+ map_signal (assign_map, ff.sig_q , type, map_signal (assign_map, ff.sig_d ));
300
299
301
300
ff.remove ();
302
301
return ;
@@ -310,7 +309,7 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
310
309
assign_map.apply (sig_a);
311
310
assign_map.apply (sig_y);
312
311
313
- map_signal (sig_y, cell->type == ID ($_BUF_) ? G (BUF) : G (NOT), map_signal (sig_a));
312
+ map_signal (assign_map, sig_y, cell->type == ID ($_BUF_) ? G (BUF) : G (NOT), map_signal (assign_map, sig_a));
314
313
315
314
module ->remove (cell);
316
315
return ;
@@ -326,25 +325,25 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
326
325
assign_map.apply (sig_b);
327
326
assign_map.apply (sig_y);
328
327
329
- int mapped_a = map_signal (sig_a);
330
- int mapped_b = map_signal (sig_b);
328
+ int mapped_a = map_signal (assign_map, sig_a);
329
+ int mapped_b = map_signal (assign_map, sig_b);
331
330
332
331
if (cell->type == ID ($_AND_))
333
- map_signal (sig_y, G (AND), mapped_a, mapped_b);
332
+ map_signal (assign_map, sig_y, G (AND), mapped_a, mapped_b);
334
333
else if (cell->type == ID ($_NAND_))
335
- map_signal (sig_y, G (NAND), mapped_a, mapped_b);
334
+ map_signal (assign_map, sig_y, G (NAND), mapped_a, mapped_b);
336
335
else if (cell->type == ID ($_OR_))
337
- map_signal (sig_y, G (OR), mapped_a, mapped_b);
336
+ map_signal (assign_map, sig_y, G (OR), mapped_a, mapped_b);
338
337
else if (cell->type == ID ($_NOR_))
339
- map_signal (sig_y, G (NOR), mapped_a, mapped_b);
338
+ map_signal (assign_map, sig_y, G (NOR), mapped_a, mapped_b);
340
339
else if (cell->type == ID ($_XOR_))
341
- map_signal (sig_y, G (XOR), mapped_a, mapped_b);
340
+ map_signal (assign_map, sig_y, G (XOR), mapped_a, mapped_b);
342
341
else if (cell->type == ID ($_XNOR_))
343
- map_signal (sig_y, G (XNOR), mapped_a, mapped_b);
342
+ map_signal (assign_map, sig_y, G (XNOR), mapped_a, mapped_b);
344
343
else if (cell->type == ID ($_ANDNOT_))
345
- map_signal (sig_y, G (ANDNOT), mapped_a, mapped_b);
344
+ map_signal (assign_map, sig_y, G (ANDNOT), mapped_a, mapped_b);
346
345
else if (cell->type == ID ($_ORNOT_))
347
- map_signal (sig_y, G (ORNOT), mapped_a, mapped_b);
346
+ map_signal (assign_map, sig_y, G (ORNOT), mapped_a, mapped_b);
348
347
else
349
348
log_abort ();
350
349
@@ -364,11 +363,11 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
364
363
assign_map.apply (sig_s);
365
364
assign_map.apply (sig_y);
366
365
367
- int mapped_a = map_signal (sig_a);
368
- int mapped_b = map_signal (sig_b);
369
- int mapped_s = map_signal (sig_s);
366
+ int mapped_a = map_signal (assign_map, sig_a);
367
+ int mapped_b = map_signal (assign_map, sig_b);
368
+ int mapped_s = map_signal (assign_map, sig_s);
370
369
371
- map_signal (sig_y, cell->type == ID ($_MUX_) ? G (MUX) : G (NMUX), mapped_a, mapped_b, mapped_s);
370
+ map_signal (assign_map, sig_y, cell->type == ID ($_MUX_) ? G (MUX) : G (NMUX), mapped_a, mapped_b, mapped_s);
372
371
373
372
module ->remove (cell);
374
373
return ;
@@ -386,11 +385,11 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
386
385
assign_map.apply (sig_c);
387
386
assign_map.apply (sig_y);
388
387
389
- int mapped_a = map_signal (sig_a);
390
- int mapped_b = map_signal (sig_b);
391
- int mapped_c = map_signal (sig_c);
388
+ int mapped_a = map_signal (assign_map, sig_a);
389
+ int mapped_b = map_signal (assign_map, sig_b);
390
+ int mapped_c = map_signal (assign_map, sig_c);
392
391
393
- map_signal (sig_y, cell->type == ID ($_AOI3_) ? G (AOI3) : G (OAI3), mapped_a, mapped_b, mapped_c);
392
+ map_signal (assign_map, sig_y, cell->type == ID ($_AOI3_) ? G (AOI3) : G (OAI3), mapped_a, mapped_b, mapped_c);
394
393
395
394
module ->remove (cell);
396
395
return ;
@@ -410,12 +409,12 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
410
409
assign_map.apply (sig_d);
411
410
assign_map.apply (sig_y);
412
411
413
- int mapped_a = map_signal (sig_a);
414
- int mapped_b = map_signal (sig_b);
415
- int mapped_c = map_signal (sig_c);
416
- int mapped_d = map_signal (sig_d);
412
+ int mapped_a = map_signal (assign_map, sig_a);
413
+ int mapped_b = map_signal (assign_map, sig_b);
414
+ int mapped_c = map_signal (assign_map, sig_c);
415
+ int mapped_d = map_signal (assign_map, sig_d);
417
416
418
- map_signal (sig_y, cell->type == ID ($_AOI4_) ? G (AOI4) : G (OAI4), mapped_a, mapped_b, mapped_c, mapped_d);
417
+ map_signal (assign_map, sig_y, cell->type == ID ($_AOI4_) ? G (AOI4) : G (OAI4), mapped_a, mapped_b, mapped_c, mapped_d);
419
418
420
419
module ->remove (cell);
421
420
return ;
@@ -490,7 +489,13 @@ void AbcModuleState::dump_loop_graph(FILE *f, int &nr, dict<int, pool<int>> &edg
490
489
fprintf (f, " }\n " );
491
490
}
492
491
493
- void AbcModuleState::handle_loops (RTLIL::Module *module )
492
+ void connect (SigMap &assign_map, RTLIL::Module *module , const RTLIL::SigSig &conn)
493
+ {
494
+ module ->connect (conn);
495
+ assign_map.add (conn.first , conn.second );
496
+ }
497
+
498
+ void AbcModuleState::handle_loops (SigMap &assign_map, RTLIL::Module *module )
494
499
{
495
500
// http://en.wikipedia.org/wiki/Topological_sorting
496
501
// (Kahn, Arthur B. (1962), "Topological sorting of large networks")
@@ -595,7 +600,7 @@ void AbcModuleState::handle_loops(RTLIL::Module *module)
595
600
first_line = false ;
596
601
}
597
602
598
- int id3 = map_signal (RTLIL::SigSpec (wire));
603
+ int id3 = map_signal (assign_map, RTLIL::SigSpec (wire));
599
604
signal_list[id1].is_port = true ;
600
605
signal_list[id3].is_port = true ;
601
606
log_assert (id3 == int (in_edges_count.size ()));
@@ -614,7 +619,7 @@ void AbcModuleState::handle_loops(RTLIL::Module *module)
614
619
}
615
620
edges[id1].swap (edges[id3]);
616
621
617
- module -> connect (RTLIL::SigSig (signal_list[id3].bit , signal_list[id1].bit ));
622
+ connect (assign_map, module , RTLIL::SigSig (signal_list[id3].bit , signal_list[id1].bit ));
618
623
dump_loop_graph (dot_f, dot_nr, edges, workpool, in_edges_count);
619
624
}
620
625
}
@@ -750,7 +755,7 @@ struct abc_output_filter
750
755
}
751
756
};
752
757
753
- void AbcModuleState::abc_module (RTLIL::Design *design, RTLIL::Module *module , const std::vector<RTLIL::Cell*> &cells,
758
+ void AbcModuleState::abc_module (RTLIL::Design *design, RTLIL::Module *module , SigMap &assign_map, const std::vector<RTLIL::Cell*> &cells,
754
759
bool dff_mode, std::string clk_str)
755
760
{
756
761
initvals.set (&assign_map, module );
@@ -936,33 +941,33 @@ void AbcModuleState::abc_module(RTLIL::Design *design, RTLIL::Module *module, co
936
941
937
942
had_init = false ;
938
943
for (auto c : cells)
939
- extract_cell (module , c, config.keepff );
944
+ extract_cell (assign_map, module , c, config.keepff );
940
945
941
946
if (undef_bits_lost)
942
947
log (" Replacing %d occurrences of constant undef bits with constant zero bits\n " , undef_bits_lost);
943
948
944
949
for (auto wire : module ->wires ()) {
945
950
if (wire->port_id > 0 || wire->get_bool_attribute (ID::keep))
946
- mark_port (wire);
951
+ mark_port (assign_map, wire);
947
952
}
948
953
949
954
for (auto cell : module ->cells ())
950
955
for (auto &port_it : cell->connections ())
951
- mark_port (port_it.second );
956
+ mark_port (assign_map, port_it.second );
952
957
953
958
if (clk_sig.size () != 0 )
954
- mark_port (clk_sig);
959
+ mark_port (assign_map, clk_sig);
955
960
956
961
if (en_sig.size () != 0 )
957
- mark_port (en_sig);
962
+ mark_port (assign_map, en_sig);
958
963
959
964
if (arst_sig.size () != 0 )
960
- mark_port (arst_sig);
965
+ mark_port (assign_map, arst_sig);
961
966
962
967
if (srst_sig.size () != 0 )
963
- mark_port (srst_sig);
968
+ mark_port (assign_map, srst_sig);
964
969
965
- handle_loops (module );
970
+ handle_loops (assign_map, module );
966
971
967
972
buffer = stringf (" %s/input.blif" , tempdir_name.c_str ());
968
973
f = fopen (buffer.c_str (), " wt" );
@@ -1205,7 +1210,7 @@ void AbcModuleState::abc_module(RTLIL::Design *design, RTLIL::Module *module, co
1205
1210
log (" Don't call ABC as there is nothing to map.\n " );
1206
1211
}
1207
1212
1208
- void AbcModuleState::extract (RTLIL::Design *design, RTLIL::Module *module )
1213
+ void AbcModuleState::extract (SigMap &assign_map, RTLIL::Design *design, RTLIL::Module *module )
1209
1214
{
1210
1215
if (!did_run_abc) {
1211
1216
return ;
@@ -1250,7 +1255,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1250
1255
RTLIL::IdString name_y = remap_name (c->getPort (ID::Y).as_wire ()->name );
1251
1256
conn.first = module ->wire (name_y);
1252
1257
conn.second = RTLIL::SigSpec (c->type == ID (ZERO) ? 0 : 1 , 1 );
1253
- module -> connect (conn);
1258
+ connect (assign_map, module , conn);
1254
1259
continue ;
1255
1260
}
1256
1261
if (c->type == ID (BUF)) {
@@ -1259,7 +1264,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1259
1264
RTLIL::IdString name_a = remap_name (c->getPort (ID::A).as_wire ()->name );
1260
1265
conn.first = module ->wire (name_y);
1261
1266
conn.second = module ->wire (name_a);
1262
- module -> connect (conn);
1267
+ connect (assign_map, module , conn);
1263
1268
continue ;
1264
1269
}
1265
1270
if (c->type == ID (NOT)) {
@@ -1391,7 +1396,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1391
1396
RTLIL::SigSig conn;
1392
1397
conn.first = module ->wire (remap_name (c->connections ().begin ()->second .as_wire ()->name ));
1393
1398
conn.second = RTLIL::SigSpec (c->type == ID (_const0_) ? 0 : 1 , 1 );
1394
- module -> connect (conn);
1399
+ connect (assign_map, module , conn);
1395
1400
continue ;
1396
1401
}
1397
1402
@@ -1436,7 +1441,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1436
1441
if (c->type == ID ($lut) && GetSize (c->getPort (ID::A)) == 1 && c->getParam (ID::LUT).as_int () == 2 ) {
1437
1442
SigSpec my_a = module ->wire (remap_name (c->getPort (ID::A).as_wire ()->name ));
1438
1443
SigSpec my_y = module ->wire (remap_name (c->getPort (ID::Y).as_wire ()->name ));
1439
- module -> connect (my_y, my_a);
1444
+ connect (assign_map, module , RTLIL::SigSig ( my_a, my_y) );
1440
1445
continue ;
1441
1446
}
1442
1447
@@ -1461,7 +1466,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1461
1466
conn.first = module ->wire (remap_name (conn.first .as_wire ()->name ));
1462
1467
if (!conn.second .is_fully_const ())
1463
1468
conn.second = module ->wire (remap_name (conn.second .as_wire ()->name ));
1464
- module -> connect (conn);
1469
+ connect (assign_map, module , conn);
1465
1470
}
1466
1471
1467
1472
cell_stats.sort ();
@@ -1482,7 +1487,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1482
1487
conn.second = si.bit ;
1483
1488
in_wires++;
1484
1489
}
1485
- module -> connect (conn);
1490
+ connect (assign_map, module , conn);
1486
1491
}
1487
1492
log (" ABC RESULTS: internal signals: %8d\n " , int (signal_list.size ()) - in_wires - out_wires);
1488
1493
log (" ABC RESULTS: input signals: %8d\n " , in_wires);
@@ -2076,16 +2081,18 @@ struct AbcPass : public Pass {
2076
2081
2077
2082
for (auto mod : design->selected_modules ())
2078
2083
{
2084
+ SigMap assign_map;
2085
+ assign_map.set (mod);
2086
+
2079
2087
if (mod->processes .size () > 0 ) {
2080
2088
log (" Skipping module %s as it contains processes.\n " , log_id (mod));
2081
2089
continue ;
2082
2090
}
2083
2091
2084
2092
if (!dff_mode || !clk_str.empty ()) {
2085
2093
AbcModuleState state (config);
2086
- state.assign_map .set (mod);
2087
- state.abc_module (design, mod, mod->selected_cells (), dff_mode, clk_str);
2088
- state.extract (design, mod);
2094
+ state.abc_module (design, mod, assign_map, mod->selected_cells (), dff_mode, clk_str);
2095
+ state.extract (assign_map, design, mod);
2089
2096
state.finish ();
2090
2097
continue ;
2091
2098
}
@@ -2106,8 +2113,6 @@ struct AbcPass : public Pass {
2106
2113
dict<RTLIL::Cell*, pool<RTLIL::SigBit>> cell_to_bit, cell_to_bit_up, cell_to_bit_down;
2107
2114
dict<RTLIL::SigBit, pool<RTLIL::Cell*>> bit_to_cell, bit_to_cell_up, bit_to_cell_down;
2108
2115
2109
- SigMap assign_map;
2110
- assign_map.set (mod);
2111
2116
FfInitVals initvals;
2112
2117
initvals.set (&assign_map, mod);
2113
2118
for (auto cell : all_cells)
@@ -2244,7 +2249,6 @@ struct AbcPass : public Pass {
2244
2249
2245
2250
for (auto &it : assigned_cells) {
2246
2251
AbcModuleState state (config);
2247
- state.assign_map .set (mod);
2248
2252
state.clk_polarity = std::get<0 >(it.first );
2249
2253
state.clk_sig = assign_map (std::get<1 >(it.first ));
2250
2254
state.en_polarity = std::get<2 >(it.first );
@@ -2253,8 +2257,8 @@ struct AbcPass : public Pass {
2253
2257
state.arst_sig = assign_map (std::get<5 >(it.first ));
2254
2258
state.srst_polarity = std::get<6 >(it.first );
2255
2259
state.srst_sig = assign_map (std::get<7 >(it.first ));
2256
- state.abc_module (design, mod, it.second , !state.clk_sig .empty (), " $" );
2257
- state.extract (design, mod);
2260
+ state.abc_module (design, mod, assign_map, it.second , !state.clk_sig .empty (), " $" );
2261
+ state.extract (assign_map, design, mod);
2258
2262
state.finish ();
2259
2263
}
2260
2264
}
0 commit comments