2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/register.h"
21 #include "kernel/celltypes.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 bool check_label(bool &active
, std::string run_from
, std::string run_to
, std::string label
)
30 if (label
== run_from
)
37 struct SynthXilinxPass
: public Pass
39 SynthXilinxPass() : Pass("synth_xilinx", "synthesis for Xilinx FPGAs") { }
41 void help() YS_OVERRIDE
43 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
45 log(" synth_xilinx [options]\n");
47 log("This command runs synthesis for Xilinx FPGAs. This command does not operate on\n");
48 log("partly selected designs. At the moment this command creates netlists that are\n");
49 log("compatible with 7-Series Xilinx devices.\n");
51 log(" -top <module>\n");
52 log(" use the specified module as top module\n");
54 log(" -edif <file>\n");
55 log(" write the design to the specified edif file. writing of an output file\n");
56 log(" is omitted if this parameter is not specified.\n");
58 log(" -blif <file>\n");
59 log(" write the design to the specified BLIF file. writing of an output file\n");
60 log(" is omitted if this parameter is not specified.\n");
63 log(" generate an output netlist (and BLIF file) suitable for VPR\n");
64 log(" (this feature is experimental and incomplete)\n");
67 log(" disable inference of block rams\n");
70 log(" disable inference of distributed rams\n");
73 log(" disable inference of shift registers\n");
75 log(" -run <from_label>:<to_label>\n");
76 log(" only run the commands between the labels (see below). an empty\n");
77 log(" from label is synonymous to 'begin', and empty to label is\n");
78 log(" synonymous to the end of the command list.\n");
81 log(" flatten design before synthesis\n");
84 log(" run 'abc' with -dff option\n");
87 log("The following commands are executed by this synthesis command:\n");
90 log(" read_verilog -lib +/xilinx/cells_sim.v\n");
91 log(" read_verilog -lib +/xilinx/cells_xtra.v\n");
92 log(" read_verilog -lib +/xilinx/brams_bb.v\n");
93 log(" hierarchy -check -top <top>\n");
95 log(" flatten: (only if -flatten)\n");
100 log(" synth -run coarse\n");
102 log(" bram: (only executed when '-nobram' is not given)\n");
103 log(" memory_bram -rules +/xilinx/brams.txt\n");
104 log(" techmap -map +/xilinx/brams_map.v\n");
106 log(" dram: (only executed when '-nodram' is not given)\n");
107 log(" memory_bram -rules +/xilinx/drams.txt\n");
108 log(" techmap -map +/xilinx/drams_map.v\n");
111 log(" opt -fast -full\n");
112 log(" memory_map\n");
115 log(" simplemap t:$dff t:$dffe (without '-nosrl' only)\n");
116 log(" pmux2shiftx (without '-nosrl' only)\n");
117 log(" opt_expr -mux_undef (without '-nosrl' only)\n");
118 log(" shregmap -tech xilinx -minlen 3 (without '-nosrl' only)\n");
119 log(" techmap -map +/xilinx/arith_map.v\n");
122 log(" map_cells:\n");
123 log(" techmap -map +/xilinx/cells_map.v\n");
128 log(" techmap -map +/techmap.v -D _NO_POS_SR -map +/xilinx/ff_map.v\n");
129 log(" abc -luts 2:2,3,6:5,10,20 [-dff]\n");
131 log(" shregmap -minlen 3 -init -params -enpol any_or_none (without '-nosrl' only)\n");
132 log(" techmap -map +/xilinx/lut_map.v -map +/xilinx/ff_map.v -map +/xilinx/cells_map.v");
133 log(" dffinit -ff FDRE Q INIT -ff FDCE Q INIT -ff FDPE Q INIT -ff FDSE Q INIT \\\n");
134 log(" -ff FDRE_1 Q INIT -ff FDCE_1 Q INIT -ff FDPE_1 Q INIT -ff FDSE_1 Q INIT\n");
137 log(" hierarchy -check\n");
139 log(" check -noinit\n");
141 log(" edif: (only if -edif)\n");
142 log(" write_edif <file-name>\n");
144 log(" blif: (only if -blif)\n");
145 log(" write_blif <file-name>\n");
148 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
150 std::string top_opt
= "-auto-top";
151 std::string edif_file
;
152 std::string blif_file
;
153 std::string run_from
, run_to
;
154 bool flatten
= false;
162 for (argidx
= 1; argidx
< args
.size(); argidx
++)
164 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
165 top_opt
= "-top " + args
[++argidx
];
168 if (args
[argidx
] == "-edif" && argidx
+1 < args
.size()) {
169 edif_file
= args
[++argidx
];
172 if (args
[argidx
] == "-blif" && argidx
+1 < args
.size()) {
173 blif_file
= args
[++argidx
];
176 if (args
[argidx
] == "-run" && argidx
+1 < args
.size()) {
177 size_t pos
= args
[argidx
+1].find(':');
178 if (pos
== std::string::npos
)
180 run_from
= args
[++argidx
].substr(0, pos
);
181 run_to
= args
[argidx
].substr(pos
+1);
184 if (args
[argidx
] == "-flatten") {
188 if (args
[argidx
] == "-retime") {
192 if (args
[argidx
] == "-vpr") {
196 if (args
[argidx
] == "-nobram") {
200 if (args
[argidx
] == "-nodram") {
204 if (args
[argidx
] == "-nosrl") {
210 extra_args(args
, argidx
, design
);
212 if (!design
->full_selection())
213 log_cmd_error("This command only operates on fully selected designs!\n");
215 bool active
= run_from
.empty();
217 log_header(design
, "Executing SYNTH_XILINX pass.\n");
220 if (check_label(active
, run_from
, run_to
, "begin"))
223 Pass::call(design
, "read_verilog -lib -D_EXPLICIT_CARRY +/xilinx/cells_sim.v");
225 Pass::call(design
, "read_verilog -lib +/xilinx/cells_sim.v");
228 Pass::call(design
, "read_verilog -lib +/xilinx/cells_xtra.v");
231 Pass::call(design
, "read_verilog -lib +/xilinx/brams_bb.v");
234 Pass::call(design
, stringf("hierarchy -check %s", top_opt
.c_str()));
237 if (flatten
&& check_label(active
, run_from
, run_to
, "flatten"))
239 Pass::call(design
, "proc");
240 Pass::call(design
, "flatten");
243 if (check_label(active
, run_from
, run_to
, "coarse"))
245 Pass::call(design
, "synth -run coarse");
248 if (check_label(active
, run_from
, run_to
, "bram"))
251 Pass::call(design
, "memory_bram -rules +/xilinx/brams.txt");
252 Pass::call(design
, "techmap -map +/xilinx/brams_map.v");
256 if (check_label(active
, run_from
, run_to
, "dram"))
259 Pass::call(design
, "memory_bram -rules +/xilinx/drams.txt");
260 Pass::call(design
, "techmap -map +/xilinx/drams_map.v");
264 if (check_label(active
, run_from
, run_to
, "fine"))
266 Pass::call(design
, "opt -fast");
267 Pass::call(design
, "memory_map");
268 Pass::call(design
, "dffsr2dff");
269 Pass::call(design
, "dff2dffe");
272 // shregmap operates on bit-level flops, not word-level,
273 // so break those down here
274 Pass::call(design
, "simplemap t:$dff t:$dffe");
275 // shregmap -tech xilinx can cope with $shiftx and $mux
276 // cells for identifiying variable-length shift registers,
277 // so attempt to convert $pmux-es to the former
278 Pass::call(design
, "pmux2shiftx");
279 // pmux2shiftx can leave behind a $pmux with a single entry
280 // -- need this to clean that up
281 Pass::call(design
, "opt_expr -mux_undef");
282 Pass::call(design
, "shregmap -tech xilinx -minlen 3");
286 Pass::call(design
, "techmap -map +/xilinx/arith_map.v -D _EXPLICIT_CARRY");
288 Pass::call(design
, "techmap -map +/xilinx/arith_map.v");
291 Pass::call(design
, "hierarchy -check");
292 Pass::call(design
, "opt -fast");
295 if (check_label(active
, run_from
, run_to
, "map_cells"))
297 Pass::call(design
, "techmap -map +/xilinx/cells_map.v");
298 Pass::call(design
, "clean");
301 if (check_label(active
, run_from
, run_to
, "map_luts"))
303 Pass::call(design
, "opt -full");
304 Pass::call(design
, "techmap -map +/techmap.v -D _NO_POS_SR -map +/xilinx/ff_map.v");
305 Pass::call(design
, "abc -luts 2:2,3,6:5,10,20" + string(retime
? " -dff" : ""));
306 Pass::call(design
, "clean");
308 Pass::call(design
, "shregmap -minlen 3 -init -params -enpol any_or_none");
309 Pass::call(design
, "techmap -map +/xilinx/lut_map.v -map +/xilinx/ff_map.v -map +/xilinx/cells_map.v");
310 Pass::call(design
, "dffinit -ff FDRE Q INIT -ff FDCE Q INIT -ff FDPE Q INIT -ff FDSE Q INIT "
311 "-ff FDRE_1 Q INIT -ff FDCE_1 Q INIT -ff FDPE_1 Q INIT -ff FDSE_1 Q INIT");
314 if (check_label(active
, run_from
, run_to
, "check"))
316 Pass::call(design
, "hierarchy -check");
317 Pass::call(design
, "stat");
318 Pass::call(design
, "check -noinit");
321 if (check_label(active
, run_from
, run_to
, "edif"))
323 if (!edif_file
.empty())
324 Pass::call(design
, stringf("write_edif -pvector bra %s", edif_file
.c_str()));
326 if (check_label(active
, run_from
, run_to
, "blif"))
328 if (!blif_file
.empty())
329 Pass::call(design
, stringf("write_blif %s", edif_file
.c_str()));
336 PRIVATE_NAMESPACE_END