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/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct OptPass
: public Pass
{
29 OptPass() : Pass("opt", "perform simple optimizations") { }
30 void help() YS_OVERRIDE
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] [-clkinv] [-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_rmdff [-keepdc] [-sat]\n");
49 log(" opt_clean [-purge]\n");
50 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-clkinv] [-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] [-clkinv] [-fine] [-full] [-keepdc]\n");
57 log(" opt_merge [-share_all]\n");
58 log(" opt_rmdff [-keepdc] [-sat]\n");
59 log(" opt_clean [-purge]\n");
60 log(" while <changed design in opt_rmdff>\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
) YS_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_rmdff_args
;
74 bool opt_share
= false;
75 bool fast_mode
= false;
77 log_header(design
, "Executing OPT pass (performing simple optimizations).\n");
81 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
82 if (args
[argidx
] == "-purge") {
83 opt_clean_args
+= " -purge";
86 if (args
[argidx
] == "-mux_undef") {
87 opt_expr_args
+= " -mux_undef";
90 if (args
[argidx
] == "-mux_bool") {
91 opt_expr_args
+= " -mux_bool";
94 if (args
[argidx
] == "-undriven") {
95 opt_expr_args
+= " -undriven";
98 if (args
[argidx
] == "-clkinv") {
99 opt_expr_args
+= " -clkinv";
102 if (args
[argidx
] == "-fine") {
103 opt_expr_args
+= " -fine";
104 opt_reduce_args
+= " -fine";
107 if (args
[argidx
] == "-full") {
108 opt_expr_args
+= " -full";
109 opt_reduce_args
+= " -full";
113 if (args
[argidx
] == "-keepdc") {
114 opt_expr_args
+= " -keepdc";
115 opt_rmdff_args
+= " -keepdc";
118 if (args
[argidx
] == "-sat") {
119 opt_rmdff_args
+= " -sat";
122 if (args
[argidx
] == "-share_all") {
123 opt_merge_args
+= " -share_all";
126 if (args
[argidx
] == "-fast") {
132 extra_args(args
, argidx
, design
);
137 Pass::call(design
, "opt_expr" + opt_expr_args
);
138 Pass::call(design
, "opt_merge" + opt_merge_args
);
139 design
->scratchpad_unset("opt.did_something");
140 Pass::call(design
, "opt_rmdff" + opt_rmdff_args
);
141 if (design
->scratchpad_get_bool("opt.did_something") == false)
143 Pass::call(design
, "opt_clean" + opt_clean_args
);
144 log_header(design
, "Rerunning OPT passes. (Removed registers in this run.)\n");
146 Pass::call(design
, "opt_clean" + opt_clean_args
);
150 Pass::call(design
, "opt_expr" + opt_expr_args
);
151 Pass::call(design
, "opt_merge -nomux" + opt_merge_args
);
153 design
->scratchpad_unset("opt.did_something");
154 Pass::call(design
, "opt_muxtree");
155 Pass::call(design
, "opt_reduce" + opt_reduce_args
);
156 Pass::call(design
, "opt_merge" + opt_merge_args
);
158 Pass::call(design
, "opt_share");
159 Pass::call(design
, "opt_rmdff" + opt_rmdff_args
);
160 Pass::call(design
, "opt_clean" + opt_clean_args
);
161 Pass::call(design
, "opt_expr" + opt_expr_args
);
162 if (design
->scratchpad_get_bool("opt.did_something") == false)
164 log_header(design
, "Rerunning OPT passes. (Maybe there is more to do..)\n");
172 log_header(design
, fast_mode
? "Finished fast OPT passes.\n" : "Finished OPT passes. (There is nothing left to do.)\n");
177 PRIVATE_NAMESPACE_END