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.
23 #include "kernel/yosys.h"
29 static const dict
<RTLIL::IdString
, int>& default_gate_cost() {
30 static const dict
<RTLIL::IdString
, int> db
= {
51 static const dict
<RTLIL::IdString
, int>& cmos_gate_cost() {
52 static const dict
<RTLIL::IdString
, int> db
= {
73 dict
<RTLIL::IdString
, int> mod_cost_cache
;
74 const dict
<RTLIL::IdString
, int> *gate_cost
= nullptr;
75 Design
*design
= nullptr;
77 int get(RTLIL::IdString type
) const
79 if (gate_cost
&& gate_cost
->count(type
))
80 return gate_cost
->at(type
);
82 log_warning("Can't determine cost of %s cell.\n", log_id(type
));
86 int get(RTLIL::Cell
*cell
)
88 if (gate_cost
&& gate_cost
->count(cell
->type
))
89 return gate_cost
->at(cell
->type
);
91 if (design
&& design
->module(cell
->type
) && cell
->parameters
.empty())
93 RTLIL::Module
*mod
= design
->module(cell
->type
);
95 if (mod
->attributes
.count("\\cost"))
96 return mod
->attributes
.at("\\cost").as_int();
98 if (mod_cost_cache
.count(mod
->name
))
99 return mod_cost_cache
.at(mod
->name
);
102 for (auto c
: mod
->cells())
103 module_cost
+= get(c
);
105 mod_cost_cache
[mod
->name
] = module_cost
;
109 log_warning("Can't determine cost of %s cell (%d parameters).\n", log_id(cell
->type
), GetSize(cell
->parameters
));