33e1507bcd573565a878b23a13b591e535e954bd
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 "opt_status.h"
21 #include "kernel/register.h"
22 #include "kernel/log.h"
26 bool OPT_DID_SOMETHING
;
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");
41 log(" opt_share -nomux\n");
44 log(" opt_muxtree\n");
45 log(" opt_reduce [-fine]\n");
48 log(" opt_clean [-purge]\n");
49 log(" opt_const [-mux_undef] [-mux_bool] [-undriven] [-fine] [-keepdc]\n");
50 log(" while <changed design>\n");
52 log("Note: Options in square brackets (such as [-keepdc]) are passed through to\n");
53 log("the opt_* commands when given to 'opt'.\n");
56 virtual void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
)
58 std::string opt_clean_args
;
59 std::string opt_const_args
;
60 std::string opt_reduce_args
;
62 log_header("Executing OPT pass (performing simple optimizations).\n");
66 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
67 if (args
[argidx
] == "-purge") {
68 opt_clean_args
+= " -purge";
71 if (args
[argidx
] == "-mux_undef") {
72 opt_const_args
+= " -mux_undef";
75 if (args
[argidx
] == "-mux_bool") {
76 opt_const_args
+= " -mux_bool";
79 if (args
[argidx
] == "-undriven") {
80 opt_const_args
+= " -undriven";
83 if (args
[argidx
] == "-fine") {
84 opt_const_args
+= " -fine";
85 opt_reduce_args
+= " -fine";
88 if (args
[argidx
] == "-keepdc") {
89 opt_const_args
+= " -keepdc";
94 extra_args(args
, argidx
, design
);
96 log_header("Optimizing in-memory representation of design.\n");
99 Pass::call(design
, "opt_const");
100 Pass::call(design
, "opt_share -nomux");
102 OPT_DID_SOMETHING
= false;
103 Pass::call(design
, "opt_muxtree");
104 Pass::call(design
, "opt_reduce" + opt_reduce_args
);
105 Pass::call(design
, "opt_share");
106 Pass::call(design
, "opt_rmdff");
107 Pass::call(design
, "opt_clean" + opt_clean_args
);
108 Pass::call(design
, "opt_const" + opt_const_args
);
109 if (OPT_DID_SOMETHING
== false)
111 log_header("Rerunning OPT passes. (Maybe there is more to do..)\n");
114 log_header("Optimizing in-memory representation of design.\n");
117 log_header("Finished OPT passes. (There is nothing left to do.)\n");