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") { }
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_rmdff [-keepdc]\n");
48 log(" opt_clean [-purge]\n");
49 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-clkinv] [-fine] [-full] [-keepdc]\n");
50 log(" while <changed design>\n");
52 log("When called with -fast the following script is used instead:\n");
55 log(" opt_expr [-mux_undef] [-mux_bool] [-undriven] [-clkinv] [-fine] [-full] [-keepdc]\n");
56 log(" opt_merge [-share_all]\n");
57 log(" opt_rmdff [-keepdc]\n");
58 log(" opt_clean [-purge]\n");
59 log(" while <changed design in opt_rmdff>\n");
61 log("Note: Options in square brackets (such as [-keepdc]) are passed through to\n");
62 log("the opt_* commands when given to 'opt'.\n");
66 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
)
68 std::string opt_clean_args
;
69 std::string opt_expr_args
;
70 std::string opt_reduce_args
;
71 std::string opt_merge_args
;
72 std::string opt_rmdff_args
;
73 bool fast_mode
= false;
75 log_header(design
, "Executing OPT pass (performing simple optimizations).\n");
79 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
80 if (args
[argidx
] == "-purge") {
81 opt_clean_args
+= " -purge";
84 if (args
[argidx
] == "-mux_undef") {
85 opt_expr_args
+= " -mux_undef";
88 if (args
[argidx
] == "-mux_bool") {
89 opt_expr_args
+= " -mux_bool";
92 if (args
[argidx
] == "-undriven") {
93 opt_expr_args
+= " -undriven";
96 if (args
[argidx
] == "-clkinv") {
97 opt_expr_args
+= " -clkinv";
100 if (args
[argidx
] == "-fine") {
101 opt_expr_args
+= " -fine";
102 opt_reduce_args
+= " -fine";
105 if (args
[argidx
] == "-full") {
106 opt_expr_args
+= " -full";
107 opt_reduce_args
+= " -full";
110 if (args
[argidx
] == "-keepdc") {
111 opt_expr_args
+= " -keepdc";
112 opt_rmdff_args
+= " -keepdc";
115 if (args
[argidx
] == "-share_all") {
116 opt_merge_args
+= " -share_all";
119 if (args
[argidx
] == "-fast") {
125 extra_args(args
, argidx
, design
);
130 Pass::call(design
, "opt_expr" + opt_expr_args
);
131 Pass::call(design
, "opt_merge" + opt_merge_args
);
132 design
->scratchpad_unset("opt.did_something");
133 Pass::call(design
, "opt_rmdff" + opt_rmdff_args
);
134 if (design
->scratchpad_get_bool("opt.did_something") == false)
136 Pass::call(design
, "opt_clean" + opt_clean_args
);
137 log_header(design
, "Rerunning OPT passes. (Removed registers in this run.)\n");
139 Pass::call(design
, "opt_clean" + opt_clean_args
);
143 Pass::call(design
, "opt_expr" + opt_expr_args
);
144 Pass::call(design
, "opt_merge -nomux" + opt_merge_args
);
146 design
->scratchpad_unset("opt.did_something");
147 Pass::call(design
, "opt_muxtree");
148 Pass::call(design
, "opt_reduce" + opt_reduce_args
);
149 Pass::call(design
, "opt_merge" + opt_merge_args
);
150 Pass::call(design
, "opt_rmdff" + opt_rmdff_args
);
151 Pass::call(design
, "opt_clean" + opt_clean_args
);
152 Pass::call(design
, "opt_expr" + opt_expr_args
);
153 if (design
->scratchpad_get_bool("opt.did_something") == false)
155 log_header(design
, "Rerunning OPT passes. (Maybe there is more to do..)\n");
163 log_header(design
, fast_mode
? "Finished fast OPT passes.\n" : "Finished OPT passes. (There is nothing left to do.)\n");
168 PRIVATE_NAMESPACE_END