@@ -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);
@@ -291,7 +290,7 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
291
290
return ;
292
291
}
293
292
294
- int gate_id = map_signal (ff.sig_q , type, map_signal (ff.sig_d ));
293
+ int gate_id = map_signal (assign_map, ff.sig_q , type, map_signal (assign_map, ff.sig_d ));
295
294
if (keepff) {
296
295
SigBit bit = ff.sig_q ;
297
296
if (assign_map (bit).wire != nullptr ) {
@@ -301,6 +300,8 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
301
300
bit.wire ->attributes [ID::keep] = 1 ;
302
301
}
303
302
303
+ map_signal (assign_map, ff.sig_q , type, map_signal (assign_map, ff.sig_d ));
304
+
304
305
ff.remove ();
305
306
return ;
306
307
}
@@ -313,7 +314,7 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
313
314
assign_map.apply (sig_a);
314
315
assign_map.apply (sig_y);
315
316
316
- map_signal (sig_y, cell->type == ID ($_BUF_) ? G (BUF) : G (NOT), map_signal (sig_a));
317
+ map_signal (assign_map, sig_y, cell->type == ID ($_BUF_) ? G (BUF) : G (NOT), map_signal (assign_map, sig_a));
317
318
318
319
module ->remove (cell);
319
320
return ;
@@ -329,25 +330,25 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
329
330
assign_map.apply (sig_b);
330
331
assign_map.apply (sig_y);
331
332
332
- int mapped_a = map_signal (sig_a);
333
- int mapped_b = map_signal (sig_b);
333
+ int mapped_a = map_signal (assign_map, sig_a);
334
+ int mapped_b = map_signal (assign_map, sig_b);
334
335
335
336
if (cell->type == ID ($_AND_))
336
- map_signal (sig_y, G (AND), mapped_a, mapped_b);
337
+ map_signal (assign_map, sig_y, G (AND), mapped_a, mapped_b);
337
338
else if (cell->type == ID ($_NAND_))
338
- map_signal (sig_y, G (NAND), mapped_a, mapped_b);
339
+ map_signal (assign_map, sig_y, G (NAND), mapped_a, mapped_b);
339
340
else if (cell->type == ID ($_OR_))
340
- map_signal (sig_y, G (OR), mapped_a, mapped_b);
341
+ map_signal (assign_map, sig_y, G (OR), mapped_a, mapped_b);
341
342
else if (cell->type == ID ($_NOR_))
342
- map_signal (sig_y, G (NOR), mapped_a, mapped_b);
343
+ map_signal (assign_map, sig_y, G (NOR), mapped_a, mapped_b);
343
344
else if (cell->type == ID ($_XOR_))
344
- map_signal (sig_y, G (XOR), mapped_a, mapped_b);
345
+ map_signal (assign_map, sig_y, G (XOR), mapped_a, mapped_b);
345
346
else if (cell->type == ID ($_XNOR_))
346
- map_signal (sig_y, G (XNOR), mapped_a, mapped_b);
347
+ map_signal (assign_map, sig_y, G (XNOR), mapped_a, mapped_b);
347
348
else if (cell->type == ID ($_ANDNOT_))
348
- map_signal (sig_y, G (ANDNOT), mapped_a, mapped_b);
349
+ map_signal (assign_map, sig_y, G (ANDNOT), mapped_a, mapped_b);
349
350
else if (cell->type == ID ($_ORNOT_))
350
- map_signal (sig_y, G (ORNOT), mapped_a, mapped_b);
351
+ map_signal (assign_map, sig_y, G (ORNOT), mapped_a, mapped_b);
351
352
else
352
353
log_abort ();
353
354
@@ -367,11 +368,11 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
367
368
assign_map.apply (sig_s);
368
369
assign_map.apply (sig_y);
369
370
370
- int mapped_a = map_signal (sig_a);
371
- int mapped_b = map_signal (sig_b);
372
- int mapped_s = map_signal (sig_s);
371
+ int mapped_a = map_signal (assign_map, sig_a);
372
+ int mapped_b = map_signal (assign_map, sig_b);
373
+ int mapped_s = map_signal (assign_map, sig_s);
373
374
374
- map_signal (sig_y, cell->type == ID ($_MUX_) ? G (MUX) : G (NMUX), mapped_a, mapped_b, mapped_s);
375
+ map_signal (assign_map, sig_y, cell->type == ID ($_MUX_) ? G (MUX) : G (NMUX), mapped_a, mapped_b, mapped_s);
375
376
376
377
module ->remove (cell);
377
378
return ;
@@ -389,11 +390,11 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
389
390
assign_map.apply (sig_c);
390
391
assign_map.apply (sig_y);
391
392
392
- int mapped_a = map_signal (sig_a);
393
- int mapped_b = map_signal (sig_b);
394
- int mapped_c = map_signal (sig_c);
393
+ int mapped_a = map_signal (assign_map, sig_a);
394
+ int mapped_b = map_signal (assign_map, sig_b);
395
+ int mapped_c = map_signal (assign_map, sig_c);
395
396
396
- map_signal (sig_y, cell->type == ID ($_AOI3_) ? G (AOI3) : G (OAI3), mapped_a, mapped_b, mapped_c);
397
+ map_signal (assign_map, sig_y, cell->type == ID ($_AOI3_) ? G (AOI3) : G (OAI3), mapped_a, mapped_b, mapped_c);
397
398
398
399
module ->remove (cell);
399
400
return ;
@@ -413,12 +414,12 @@ void AbcModuleState::extract_cell(RTLIL::Module *module, RTLIL::Cell *cell, bool
413
414
assign_map.apply (sig_d);
414
415
assign_map.apply (sig_y);
415
416
416
- int mapped_a = map_signal (sig_a);
417
- int mapped_b = map_signal (sig_b);
418
- int mapped_c = map_signal (sig_c);
419
- int mapped_d = map_signal (sig_d);
417
+ int mapped_a = map_signal (assign_map, sig_a);
418
+ int mapped_b = map_signal (assign_map, sig_b);
419
+ int mapped_c = map_signal (assign_map, sig_c);
420
+ int mapped_d = map_signal (assign_map, sig_d);
420
421
421
- map_signal (sig_y, cell->type == ID ($_AOI4_) ? G (AOI4) : G (OAI4), mapped_a, mapped_b, mapped_c, mapped_d);
422
+ map_signal (assign_map, sig_y, cell->type == ID ($_AOI4_) ? G (AOI4) : G (OAI4), mapped_a, mapped_b, mapped_c, mapped_d);
422
423
423
424
module ->remove (cell);
424
425
return ;
@@ -493,7 +494,13 @@ void AbcModuleState::dump_loop_graph(FILE *f, int &nr, dict<int, pool<int>> &edg
493
494
fprintf (f, " }\n " );
494
495
}
495
496
496
- void AbcModuleState::handle_loops (RTLIL::Module *module )
497
+ void connect (SigMap &assign_map, RTLIL::Module *module , const RTLIL::SigSig &conn)
498
+ {
499
+ module ->connect (conn);
500
+ assign_map.add (conn.first , conn.second );
501
+ }
502
+
503
+ void AbcModuleState::handle_loops (SigMap &assign_map, RTLIL::Module *module )
497
504
{
498
505
// http://en.wikipedia.org/wiki/Topological_sorting
499
506
// (Kahn, Arthur B. (1962), "Topological sorting of large networks")
@@ -598,7 +605,7 @@ void AbcModuleState::handle_loops(RTLIL::Module *module)
598
605
first_line = false ;
599
606
}
600
607
601
- int id3 = map_signal (RTLIL::SigSpec (wire));
608
+ int id3 = map_signal (assign_map, RTLIL::SigSpec (wire));
602
609
signal_list[id1].is_port = true ;
603
610
signal_list[id3].is_port = true ;
604
611
log_assert (id3 == int (in_edges_count.size ()));
@@ -617,7 +624,7 @@ void AbcModuleState::handle_loops(RTLIL::Module *module)
617
624
}
618
625
edges[id1].swap (edges[id3]);
619
626
620
- module -> connect (RTLIL::SigSig (signal_list[id3].bit , signal_list[id1].bit ));
627
+ connect (assign_map, module , RTLIL::SigSig (signal_list[id3].bit , signal_list[id1].bit ));
621
628
dump_loop_graph (dot_f, dot_nr, edges, workpool, in_edges_count);
622
629
}
623
630
}
@@ -753,7 +760,7 @@ struct abc_output_filter
753
760
}
754
761
};
755
762
756
- void AbcModuleState::abc_module (RTLIL::Design *design, RTLIL::Module *module , const std::vector<RTLIL::Cell*> &cells,
763
+ void AbcModuleState::abc_module (RTLIL::Design *design, RTLIL::Module *module , SigMap &assign_map, const std::vector<RTLIL::Cell*> &cells,
757
764
bool dff_mode, std::string clk_str)
758
765
{
759
766
initvals.set (&assign_map, module );
@@ -939,33 +946,33 @@ void AbcModuleState::abc_module(RTLIL::Design *design, RTLIL::Module *module, co
939
946
940
947
had_init = false ;
941
948
for (auto c : cells)
942
- extract_cell (module , c, config.keepff );
949
+ extract_cell (assign_map, module , c, config.keepff );
943
950
944
951
if (undef_bits_lost)
945
952
log (" Replacing %d occurrences of constant undef bits with constant zero bits\n " , undef_bits_lost);
946
953
947
954
for (auto wire : module ->wires ()) {
948
955
if (wire->port_id > 0 || wire->get_bool_attribute (ID::keep))
949
- mark_port (wire);
956
+ mark_port (assign_map, wire);
950
957
}
951
958
952
959
for (auto cell : module ->cells ())
953
960
for (auto &port_it : cell->connections ())
954
- mark_port (port_it.second );
961
+ mark_port (assign_map, port_it.second );
955
962
956
963
if (clk_sig.size () != 0 )
957
- mark_port (clk_sig);
964
+ mark_port (assign_map, clk_sig);
958
965
959
966
if (en_sig.size () != 0 )
960
- mark_port (en_sig);
967
+ mark_port (assign_map, en_sig);
961
968
962
969
if (arst_sig.size () != 0 )
963
- mark_port (arst_sig);
970
+ mark_port (assign_map, arst_sig);
964
971
965
972
if (srst_sig.size () != 0 )
966
- mark_port (srst_sig);
973
+ mark_port (assign_map, srst_sig);
967
974
968
- handle_loops (module );
975
+ handle_loops (assign_map, module );
969
976
970
977
buffer = stringf (" %s/input.blif" , tempdir_name.c_str ());
971
978
f = fopen (buffer.c_str (), " wt" );
@@ -1208,7 +1215,7 @@ void AbcModuleState::abc_module(RTLIL::Design *design, RTLIL::Module *module, co
1208
1215
log (" Don't call ABC as there is nothing to map.\n " );
1209
1216
}
1210
1217
1211
- void AbcModuleState::extract (RTLIL::Design *design, RTLIL::Module *module )
1218
+ void AbcModuleState::extract (SigMap &assign_map, RTLIL::Design *design, RTLIL::Module *module )
1212
1219
{
1213
1220
if (!did_run_abc) {
1214
1221
return ;
@@ -1253,7 +1260,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1253
1260
RTLIL::IdString name_y = remap_name (c->getPort (ID::Y).as_wire ()->name );
1254
1261
conn.first = module ->wire (name_y);
1255
1262
conn.second = RTLIL::SigSpec (c->type == ID (ZERO) ? 0 : 1 , 1 );
1256
- module -> connect (conn);
1263
+ connect (assign_map, module , conn);
1257
1264
continue ;
1258
1265
}
1259
1266
if (c->type == ID (BUF)) {
@@ -1262,7 +1269,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1262
1269
RTLIL::IdString name_a = remap_name (c->getPort (ID::A).as_wire ()->name );
1263
1270
conn.first = module ->wire (name_y);
1264
1271
conn.second = module ->wire (name_a);
1265
- module -> connect (conn);
1272
+ connect (assign_map, module , conn);
1266
1273
continue ;
1267
1274
}
1268
1275
if (c->type == ID (NOT)) {
@@ -1394,7 +1401,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1394
1401
RTLIL::SigSig conn;
1395
1402
conn.first = module ->wire (remap_name (c->connections ().begin ()->second .as_wire ()->name ));
1396
1403
conn.second = RTLIL::SigSpec (c->type == ID (_const0_) ? 0 : 1 , 1 );
1397
- module -> connect (conn);
1404
+ connect (assign_map, module , conn);
1398
1405
continue ;
1399
1406
}
1400
1407
@@ -1439,7 +1446,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1439
1446
if (c->type == ID ($lut) && GetSize (c->getPort (ID::A)) == 1 && c->getParam (ID::LUT).as_int () == 2 ) {
1440
1447
SigSpec my_a = module ->wire (remap_name (c->getPort (ID::A).as_wire ()->name ));
1441
1448
SigSpec my_y = module ->wire (remap_name (c->getPort (ID::Y).as_wire ()->name ));
1442
- module -> connect (my_y, my_a);
1449
+ connect (assign_map, module , RTLIL::SigSig ( my_a, my_y) );
1443
1450
continue ;
1444
1451
}
1445
1452
@@ -1464,7 +1471,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1464
1471
conn.first = module ->wire (remap_name (conn.first .as_wire ()->name ));
1465
1472
if (!conn.second .is_fully_const ())
1466
1473
conn.second = module ->wire (remap_name (conn.second .as_wire ()->name ));
1467
- module -> connect (conn);
1474
+ connect (assign_map, module , conn);
1468
1475
}
1469
1476
1470
1477
cell_stats.sort ();
@@ -1485,7 +1492,7 @@ void AbcModuleState::extract(RTLIL::Design *design, RTLIL::Module *module)
1485
1492
conn.second = si.bit ;
1486
1493
in_wires++;
1487
1494
}
1488
- module -> connect (conn);
1495
+ connect (assign_map, module , conn);
1489
1496
}
1490
1497
log (" ABC RESULTS: internal signals: %8d\n " , int (signal_list.size ()) - in_wires - out_wires);
1491
1498
log (" ABC RESULTS: input signals: %8d\n " , in_wires);
@@ -2079,16 +2086,18 @@ struct AbcPass : public Pass {
2079
2086
2080
2087
for (auto mod : design->selected_modules ())
2081
2088
{
2089
+ SigMap assign_map;
2090
+ assign_map.set (mod);
2091
+
2082
2092
if (mod->processes .size () > 0 ) {
2083
2093
log (" Skipping module %s as it contains processes.\n " , log_id (mod));
2084
2094
continue ;
2085
2095
}
2086
2096
2087
2097
if (!dff_mode || !clk_str.empty ()) {
2088
2098
AbcModuleState state (config);
2089
- state.assign_map .set (mod);
2090
- state.abc_module (design, mod, mod->selected_cells (), dff_mode, clk_str);
2091
- state.extract (design, mod);
2099
+ state.abc_module (design, mod, assign_map, mod->selected_cells (), dff_mode, clk_str);
2100
+ state.extract (assign_map, design, mod);
2092
2101
state.finish ();
2093
2102
continue ;
2094
2103
}
@@ -2109,8 +2118,6 @@ struct AbcPass : public Pass {
2109
2118
dict<RTLIL::Cell*, pool<RTLIL::SigBit>> cell_to_bit, cell_to_bit_up, cell_to_bit_down;
2110
2119
dict<RTLIL::SigBit, pool<RTLIL::Cell*>> bit_to_cell, bit_to_cell_up, bit_to_cell_down;
2111
2120
2112
- SigMap assign_map;
2113
- assign_map.set (mod);
2114
2121
FfInitVals initvals;
2115
2122
initvals.set (&assign_map, mod);
2116
2123
for (auto cell : all_cells)
@@ -2247,7 +2254,6 @@ struct AbcPass : public Pass {
2247
2254
2248
2255
for (auto &it : assigned_cells) {
2249
2256
AbcModuleState state (config);
2250
- state.assign_map .set (mod);
2251
2257
state.clk_polarity = std::get<0 >(it.first );
2252
2258
state.clk_sig = assign_map (std::get<1 >(it.first ));
2253
2259
state.en_polarity = std::get<2 >(it.first );
@@ -2256,8 +2262,8 @@ struct AbcPass : public Pass {
2256
2262
state.arst_sig = assign_map (std::get<5 >(it.first ));
2257
2263
state.srst_polarity = std::get<6 >(it.first );
2258
2264
state.srst_sig = assign_map (std::get<7 >(it.first ));
2259
- state.abc_module (design, mod, it.second , !state.clk_sig .empty (), " $" );
2260
- state.extract (design, mod);
2265
+ state.abc_module (design, mod, assign_map, it.second , !state.clk_sig .empty (), " $" );
2266
+ state.extract (assign_map, design, mod);
2261
2267
state.finish ();
2262
2268
}
2263
2269
}
0 commit comments