Skip to content

Commit 0f23dde

Browse files
authored
Merge pull request #2086 from sdamghan/yosys_odin_net_names
Node naming, including hierarchical history in Yosys+Odin-II
2 parents a887299 + 549e334 commit 0f23dde

File tree

11 files changed

+90
-34
lines changed

11 files changed

+90
-34
lines changed

ODIN_II/SRC/BLIFReader.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,7 @@ void BLIF::Reader::create_hard_block_nodes(hard_block_models* models) {
336336
t_model* hb_model = NULL;
337337
nnode_t* new_node = allocate_nnode(my_location);
338338

339-
// Name the node subcircuit_name~hard_block_number so that the name is unique.
340339
static long hard_block_number = 0;
341-
odin_sprintf(buffer, "%s~%ld", subcircuit_name, hard_block_number++);
342-
new_node->name = make_full_ref_name(buffer, NULL, NULL, NULL, -1);
343340

344341
// init the edge sensitivity of hard block
345342
if (configuration.coarsen)
@@ -357,21 +354,15 @@ void BLIF::Reader::create_hard_block_nodes(hard_block_models* models) {
357354
new_node->type = yosys_subckt_strmap[subcircuit_stripped_name];
358355

359356
if (new_node->type == NO_OP) {
360-
char new_name[READ_BLIF_BUFFER];
361-
vtr::free(new_node->name);
362357
/* in case of weird names, need to add memories manually */
363358
int sc_spot = -1;
364359
char* yosys_subckt_str = NULL;
365360
if ((yosys_subckt_str = retrieve_node_type_from_subckt_name(subcircuit_stripped_name)) != NULL) {
366361
/* specify node type */
367362
new_node->type = yosys_subckt_strmap[yosys_subckt_str];
368-
/* specify node name */
369-
odin_sprintf(new_name, "\\%s~%ld", yosys_subckt_str, hard_block_number - 1);
370363
} else if ((sc_spot = sc_lookup_string(hard_block_names, subcircuit_stripped_name)) != -1) {
371364
/* specify node type */
372365
new_node->type = HARD_IP;
373-
/* specify node name */
374-
odin_sprintf(new_name, "\\%s~%ld", subcircuit_stripped_name, hard_block_number - 1);
375366
/* Detect used hard block for the blif generation */
376367
hb_model = find_hard_block(subcircuit_stripped_name);
377368
if (hb_model) {
@@ -381,7 +372,6 @@ void BLIF::Reader::create_hard_block_nodes(hard_block_models* models) {
381372
error_message(PARSE_BLIF, unknown_location,
382373
"Unsupported subcircuit type (%s) in BLIF file.\n", subcircuit_name);
383374
}
384-
new_node->name = make_full_ref_name(new_name, NULL, NULL, NULL, -1);
385375

386376
// CLEAN UP
387377
vtr::free(yosys_subckt_str);
@@ -493,6 +483,31 @@ void BLIF::Reader::create_hard_block_nodes(hard_block_models* models) {
493483
output_nets_hash->add(name, new_net);
494484
}
495485

486+
if (!configuration.coarsen
487+
|| !configuration.decode_names
488+
|| new_node->type == SPRAM
489+
|| new_node->type == DPRAM) {
490+
// Name the node subcircuit_name~hard_block_number so that the name is unique.
491+
odin_sprintf(buffer, "%s~%ld", subcircuit_name, hard_block_number++);
492+
new_node->name = make_full_ref_name(buffer, NULL, NULL, NULL, -1);
493+
} else {
494+
// Find the basename of the output pin and name the node
495+
// with BASENAME^TYPE
496+
char* splitter = strrchr(new_node->output_pins[0]->net->name, '.');
497+
char* output_pin_fullname = new_node->output_pins[0]->net->name;
498+
499+
// there is only a top module, no instantiation of submodules
500+
if (splitter == NULL)
501+
splitter = strchr(output_pin_fullname, '^');
502+
503+
char basename[READ_BLIF_BUFFER];
504+
size_t basename_len = splitter - output_pin_fullname;
505+
506+
strncpy(basename, output_pin_fullname, basename_len);
507+
basename[basename_len] = '\0';
508+
new_node->name = node_name(new_node, basename);
509+
}
510+
496511
// Create a fake ast node.
497512
if (!configuration.coarsen || new_node->type == HARD_IP) {
498513
new_node->related_ast_node = create_node_w_type(HARD_BLOCK, my_location);

ODIN_II/SRC/include/config_t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct config_t {
1717
bool fflegalize; // Legalize DFFs by making them rising edge
1818
bool coarsen; // Specify if the input BLIF is coarse-grain
1919
bool show_yosys_log; // Print Yosys logs into the standard output stream
20+
bool decode_names; // Extracting hierarchical information from Yosys coarse-grained BLIF file for signal naming
2021

2122
bool output_ast_graphs; // switch that outputs ast graphs per node for use with GRaphViz tools
2223
bool output_netlist_graphs; // switch that outputs netlist graphs per node for use with GraphViz tools

ODIN_II/SRC/include/odin_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct global_args_t {
113113
argparse::ArgValue<bool> fflegalize; // makes flip-flops rising edge sensitive
114114
argparse::ArgValue<bool> coarsen; // tells Odin-II that the input blif is coarse-grain
115115
argparse::ArgValue<bool> show_yosys_log; // Show Yosys output logs into the standard output stream
116+
argparse::ArgValue<bool> decode_names; // Extracting hierarchical information from Yosys coarse-grained BLIF file for signal naming
116117

117118
argparse::ArgValue<std::string> adder_def; //DEPRECATED
118119

ODIN_II/SRC/odin_ii.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ void get_options(int argc, char** argv) {
533533
.help("TCL file")
534534
.metavar("TCL_FILE");
535535

536+
ext_elaborator_group.add_argument(global_args.decode_names, "--decode_names")
537+
.help("Enable extracting hierarchical information from Yosys coarse-grained BLIF file for signal naming")
538+
.default_value("false")
539+
.action(argparse::Action::STORE_TRUE)
540+
.metavar("DECODE_NAMES");
541+
536542
auto& other_grp = parser.add_argument_group("other options");
537543

538544
other_grp.add_argument(global_args.show_help, "-h")
@@ -752,6 +758,10 @@ void get_options(int argc, char** argv) {
752758
configuration.elaborator_type = elaborator_e::_YOSYS;
753759
}
754760

761+
if (global_args.decode_names.provenance() == argparse::Provenance::SPECIFIED) {
762+
configuration.decode_names = global_args.decode_names;
763+
}
764+
755765
if (global_args.write_netlist_as_dot.provenance() == argparse::Provenance::SPECIFIED) {
756766
configuration.output_netlist_graphs = global_args.write_netlist_as_dot;
757767
}
@@ -809,6 +819,7 @@ void set_default_config() {
809819
configuration.coarsen = false;
810820
configuration.fflegalize = false;
811821
configuration.show_yosys_log = false;
822+
configuration.decode_names = false;
812823
configuration.tcl_file = "";
813824
configuration.output_file_type = file_type_e::_BLIF;
814825
configuration.elaborator_type = elaborator_e::_ODIN;

doc/src/yosys+odin/user_guide.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Synthesis Arguments
2626
**`--elaborator`** **[odin (default), yosys]** **Specify the tool that should perform the HDL elaboration**
2727
**`--fflegalize`** **Converts latches' sensitivity to the rising edge as required by VPR**
2828
**`--show_yosys_log`** **Showing the Yosys elaboration logs in the console window**
29+
**`--decode_names`** **Enable extracting hierarchical information from Yosys coarse-grained BLIF file for signal naming \
30+
(the VTR flow scripts take advantage of this option by default)**
2931
======================= ============================== =================================================================================================
3032

3133

@@ -42,6 +44,15 @@ Passes a Verilog file to Yosys for performing elaboration.
4244
The BLIF elaboration and partial mapping phases will be executed on the generated netlist.
4345
However, all latches in the Yosys+Odin-II output file will be rising edge.
4446

47+
.. code-block:: bash
48+
49+
./odin_II --elaborator yosys -V <Path/to/Verilog/file> --decode_names
50+
51+
52+
Performs the design elaboration by Yosys parsers and generates a coarse-grained netlist in BLIF.
53+
Odin-II then extracts the hierarchical information of subcircuits to use for signal naming when reading the coarse-grained BLIF file.
54+
The BLIF elaboration and partial mapping phases will be executed on the generated netlist.
55+
4556
.. code-block:: bash
4657
4758
./odin_II -b <Path/to/BLIF/file> --coarsen --fflegalize

libs/EXTERNAL/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(${ODIN_USE_YOSYS} OR ${WITH_YOSYS})
2020
add_subdirectory(libyosys)
2121

2222
# In addition to libyosys in the build folder, we copy the libyosys directory
23-
# into a temporary folder in the VTR root, name Yosys, to have access to Yosys
23+
# into a temporary folder in the VTR root, named Yosys, to have access to Yosys
2424
# execs for using in VTR scripts (similar to VPR/vpr or ODIN_II/odin_II)
2525
add_custom_target(vtr-yosys ALL
2626
DEPENDS yosys

vtr_flow/scripts/python_libs/vtr/odin/odin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def init_config_file(
8787
config_file.write(odin_config_full_path)
8888

8989

90-
# pylint: disable=too-many-arguments, too-many-locals
90+
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches
9191
def run(
9292
architecture_file,
9393
circuit_file,
@@ -190,6 +190,11 @@ def run(
190190
cmd = [odin_exec]
191191
use_odin_simulation = False
192192

193+
# handling the Odin-II decode_name flag for Yosys coarse-grained BLIFs
194+
if not odin_args["encode_names"]:
195+
odin_args["decode_names"] = True
196+
del odin_args["encode_names"]
197+
193198
if "use_odin_simulation" in odin_args:
194199
use_odin_simulation = True
195200
del odin_args["use_odin_simulation"]
@@ -245,4 +250,4 @@ def run(
245250
)
246251

247252

248-
# pylint: enable=too-many-arguments, too-many-locals
253+
# pylint: enable=too-many-arguments, too-many-locals, too-many-branches

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ def vtr_command_argparser(prog=None):
360360
help="Make flip-flops rising edge for coarse-grain input BLIFs in the techmap"
361361
+ "(Odin-II synthesis flow generates rising edge FFs by default)",
362362
)
363+
odin.add_argument(
364+
"-encode_names",
365+
default=False,
366+
action="store_true",
367+
dest="encode_names",
368+
help="Enable Odin-II utilization of operation-type-encoded naming style for Yosys"
369+
+ " coarse-grained RTLIL nodes",
370+
)
363371
#
364372
# YOSYS arguments
365373
#
@@ -673,6 +681,7 @@ def process_odin_args(args):
673681
odin_args["adder_type"] = args.adder_type
674682
odin_args["top_module"] = args.top_module
675683
odin_args["elaborator"] = args.elaborator
684+
odin_args["encode_names"] = args.encode_names
676685

677686
if args.adder_cin_global:
678687
odin_args["adder_cin_global"] = True

vtr_flow/tasks/regression_tests/vtr_reg_basic/hdl_include_odin/config/config.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# Configuration file for running experiments #
33
# #
44
# This config file is testing the ability to specify include #
5-
# files that should pass to the VTR frontend with the top #
6-
# module of the benchmark (ch_intrinsic_top.v). This is done #
7-
# by specifying two Verilog header files that provide essential #
8-
# definitions, and memory_controller design that provides the #
9-
# design of an internal component for ch_intrinsic_top. If the #
10-
# include files are not properly included during compilation #
11-
# the benchmark is incomplete and the flow will error out. #
5+
# files that should be passed to the VTR Odin-II frontend with #
6+
# the top module of the benchmark (ch_intrinsic_modified.v). #
7+
# This is done by specifying two Verilog header files that #
8+
# provide essential definitions, and memory_controller design #
9+
# that provides the design of an internal component for #
10+
# "ch_intrinsic_modified.v". If the include files are not #
11+
# properly included during compilation the benchmark is #
12+
# incomplete and the flow will error out. #
1213
#################################################################
1314

1415
# Path to directory of circuits to use

vtr_flow/tasks/regression_tests/vtr_reg_basic/hdl_include_yosys/config/config.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# Configuration file for running experiments #
33
# #
44
# This config file is testing the ability to specify include #
5-
# files that should pass to the VTR frontend with the top #
6-
# module of the benchmark (ch_intrinsic_top.v). This is done #
7-
# by specifying two Verilog header files that provide essential #
8-
# definitions, and memory_controller design that provides the #
9-
# design of an internal component for ch_intrinsic_top. If the #
10-
# include files are not properly included during compilation #
11-
# the benchmark is incomplete and the flow will error out. #
5+
# files that should be passed to the VTR Yosys frontend with #
6+
# the top module of the benchmark (ch_intrinsic_modified.v). #
7+
# This is done by specifying two Verilog header files that #
8+
# provide essential definitions, and memory_controller design #
9+
# that provides the design of an internal component for #
10+
# "ch_intrinsic_modified.v". If the include files are not #
11+
# properly included during compilation the benchmark is #
12+
# incomplete and the flow will error out. #
1213
#################################################################
1314

1415
# Path to directory of circuits to use

vtr_flow/tasks/regression_tests/vtr_reg_basic/hdl_include_yosys_odin/config/config.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# Configuration file for running experiments #
33
# #
44
# This config file is testing the ability to specify include #
5-
# files that should pass to the VTR frontend with the top #
6-
# module of the benchmark (ch_intrinsic_top.v). This is done #
7-
# by specifying two Verilog header files that provide essential #
8-
# definitions, and memory_controller design that provides the #
9-
# design of an internal component for ch_intrinsic_top. If the #
10-
# include files are not properly included during compilation #
11-
# the benchmark is incomplete and the flow will error out. #
5+
# files that should be passed to the VTR Yosys+Odin-II frontend #
6+
# with the top module of the benchmark (ch_intrinsic_modified). #
7+
# This is done by specifying two Verilog header files that #
8+
# provide essential definitions, and memory_controller design #
9+
# that provides the design of an internal component for #
10+
# "ch_intrinsic_modified.v". If the include files are not #
11+
# properly included during compilation the benchmark is #
12+
# incomplete and the flow will error out. #
1213
#################################################################
1314

1415
# Path to directory of circuits to use

0 commit comments

Comments
 (0)