c3e418c075de481cd25b765a40c37f9144f10619
2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
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/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct OptPass
: public Pass
{
29 OptPass() : Pass("opt", "perform simple optimizations") { }
32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
34 log(" opt [options] [selection]\n");
36 log("This pass calls all the other opt_* passes in a useful order. This performs\n");
37 log("a series of trivial optimizations and cleanups. This pass executes the other\n");
38 log("passes in the following order:\n");
40 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-noclkinv] [-fine] [-full] [-keepdc]\n");
41 log(" opt_merge [-share_all] -nomux\n");
44 log(" opt_muxtree\n");
45 log(" opt_reduce [-fine] [-full]\n");
46 log(" opt_merge [-share_all]\n");
47 log(" opt_share (-full only)\n");
48 log(" opt_dff [-nodffe] [-nosdff] [-keepdc] [-sat] (except when called with -noff)\n");
49 log(" opt_clean [-purge]\n");
50 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-noclkinv] [-fine] [-full] [-keepdc]\n");
51 log(" while <changed design>\n");
53 log("When called with -fast the following script is used instead:\n");
56 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-noclkinv] [-fine] [-full] [-keepdc]\n");
57 log(" opt_merge [-share_all]\n");
58 log(" opt_dff [-nodffe] [-nosdff] [-keepdc] [-sat] (except when called with -noff)\n");
59 log(" opt_clean [-purge]\n");
60 log(" while <changed design in opt_dff>\n");
62 log("Note: Options in square brackets (such as [-keepdc]) are passed through to\n");
63 log("the opt_* commands when given to 'opt'.\n");
67 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
69 std::string opt_clean_args
;
70 std::string opt_expr_args
;
71 std::string opt_reduce_args
;
72 std::string opt_merge_args
;
73 std::string opt_dff_args
;
74 bool opt_share
= false;
75 bool fast_mode
= false;
76 bool noff_mode
= false;
78 log_header(design
, "Executing OPT pass (performing simple optimizations).\n");
82 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
83 if (args
[argidx
] == "-purge") {
84 opt_clean_args
+= " -purge";
87 if (args
[argidx
] == "-mux_undef") {
88 opt_expr_args
+= " -mux_undef";
91 if (args
[argidx
] == "-mux_bool") {
92 opt_expr_args
+= " -mux_bool";
95 if (args
[argidx
] == "-undriven") {
96 opt_expr_args
+= " -undriven";
99 if (args
[argidx
] == "-noclkinv") {
100 opt_expr_args
+= " -noclkinv";
103 if (args
[argidx
] == "-fine") {
104 opt_expr_args
+= " -fine";
105 opt_reduce_args
+= " -fine";
108 if (args
[argidx
] == "-full") {
109 opt_expr_args
+= " -full";
110 opt_reduce_args
+= " -full";
114 if (args
[argidx
] == "-keepdc") {
115 opt_expr_args
+= " -keepdc";
116 opt_dff_args
+= " -keepdc";
119 if (args
[argidx
] == "-nodffe") {
120 opt_dff_args
+= " -nodffe";
123 if (args
[argidx
] == "-nosdff") {
124 opt_dff_args
+= " -nosdff";
127 if (args
[argidx
] == "-sat") {
128 opt_dff_args
+= " -sat";
131 if (args
[argidx
] == "-share_all") {
132 opt_merge_args
+= " -share_all";
135 if (args
[argidx
] == "-fast") {
139 if (args
[argidx
] == "-noff") {
145 extra_args(args
, argidx
, design
);
150 Pass::call(design
, "opt_expr" + opt_expr_args
);
151 Pass::call(design
, "opt_merge" + opt_merge_args
);
152 design
->scratchpad_unset("opt.did_something");
154 Pass::call(design
, "opt_dff" + opt_dff_args
);
155 if (design
->scratchpad_get_bool("opt.did_something") == false)
157 Pass::call(design
, "opt_clean" + opt_clean_args
);
158 log_header(design
, "Rerunning OPT passes. (Removed registers in this run.)\n");
160 Pass::call(design
, "opt_clean" + opt_clean_args
);
164 Pass::call(design
, "opt_expr" + opt_expr_args
);
165 Pass::call(design
, "opt_merge -nomux" + opt_merge_args
);
167 design
->scratchpad_unset("opt.did_something");
168 Pass::call(design
, "opt_muxtree");
169 Pass::call(design
, "opt_reduce" + opt_reduce_args
);
170 Pass::call(design
, "opt_merge" + opt_merge_args
);
172 Pass::call(design
, "opt_share");
174 Pass::call(design
, "opt_dff" + opt_dff_args
);
175 Pass::call(design
, "opt_clean" + opt_clean_args
);
176 Pass::call(design
, "opt_expr" + opt_expr_args
);
177 if (design
->scratchpad_get_bool("opt.did_something") == false)
179 log_header(design
, "Rerunning OPT passes. (Maybe there is more to do..)\n");
187 log_header(design
, fast_mode
? "Finished fast OPT passes.\n" : "Finished OPT passes. (There is nothing left to do.)\n");
192 PRIVATE_NAMESPACE_END