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/yosys.h"
23 PRIVATE_NAMESPACE_BEGIN
25 struct UniquifyPass
: public Pass
{
26 UniquifyPass() : Pass("uniquify", "create unique copies of modules") { }
27 void help() YS_OVERRIDE
29 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
31 log(" uniquify [selection]\n");
33 log("By default, a module that is instantiated by several other modules is only\n");
34 log("kept once in the design. This preserves the original modularity of the design\n");
35 log("and reduces the overall size of the design in memory. But it prevents certain\n");
36 log("optimizations and other operations on the design. This pass creates unique\n");
37 log("modules for all selected cells. The created modules are marked with the\n");
38 log("'unique' attribute.\n");
40 log("This commands only operates on modules that by themself have the 'unique'\n");
41 log("attribute set (the 'top' module is unique implicitly).\n");
44 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
46 log_header(design
, "Executing UNIQUIFY pass (creating unique copies of modules).\n");
49 for (argidx
= 1; argidx
< args
.size(); argidx
++)
51 // if (args[argidx] == "-check") {
56 extra_args(args
, argidx
, design
);
58 bool did_something
= true;
63 did_something
= false;
65 for (auto module
: design
->selected_modules())
67 if (!module
->get_bool_attribute(ID::unique
) && !module
->get_bool_attribute(ID::top
))
70 for (auto cell
: module
->selected_cells())
72 Module
*tmod
= design
->module(cell
->type
);
73 IdString newname
= module
->name
.str() + "." + log_id(cell
->name
);
78 if (tmod
->get_blackbox_attribute())
81 if (tmod
->get_bool_attribute(ID::unique
) && newname
== tmod
->name
)
84 log("Creating module %s from %s.\n", log_id(newname
), log_id(tmod
));
86 auto smod
= tmod
->clone();
89 smod
->set_bool_attribute(ID::unique
);
90 if (smod
->attributes
.count(ID::hdlname
) == 0)
91 smod
->attributes
[ID::hdlname
] = string(log_id(tmod
->name
));
100 log("Created %d unique modules.\n", count
);
104 PRIVATE_NAMESPACE_END