36 int found_matching_case_idx = -1;
37 for (
int i = 0; i < int(sw->
cases.size()) && found_matching_case_idx < 0; i++)
42 for (
int j = 0; j < int(cs->
compare.size()); j++) {
48 found_matching_case_idx = i;
53 if (cs->
compare.size() == 0 && found_matching_case_idx < 0) {
58 while (found_matching_case_idx >= 0 &&
int(sw->
cases.size()) > found_matching_case_idx+1) {
59 delete sw->
cases.back();
62 if (found_matching_case_idx == 0)
66 if (parent->
switches.front() == sw && sw->
cases.size() == 1 &&
70 for (
auto &action : sw->
cases[0]->actions)
71 parent->
actions.push_back(action);
72 for (
auto sw2 : sw->
cases[0]->switches)
74 sw->
cases[0]->switches.clear();
80 bool all_cases_are_empty =
true;
81 for (
auto cs : sw->
cases) {
82 if (cs->actions.size() != 0 || cs->switches.size() != 0)
83 all_cases_are_empty =
false;
87 if (all_cases_are_empty) {
89 for (
auto cs : sw->
cases)
101 for (
size_t i = 0; i < cs->
actions.size(); i++) {
102 if (cs->
actions[i].first.size() == 0) {
103 did_something =
true;
107 for (
size_t i = 0; i < cs->
switches.size(); i++) {
109 if (sw->
cases.size() == 0) {
111 did_something =
true;
114 }
else if (max_depth != 0)
126 for (
size_t i = 0; i < proc->
syncs.size(); i++) {
127 for (
size_t j = 0; j < proc->
syncs[i]->actions.size(); j++)
128 if (proc->
syncs[i]->actions[j].first.size() == 0)
129 proc->
syncs[i]->actions.erase(proc->
syncs[i]->actions.begin() + (j--));
130 if (proc->
syncs[i]->actions.size() == 0) {
131 delete proc->
syncs[i];
132 proc->
syncs.erase(proc->
syncs.begin() + (i--));
135 while (did_something) {
136 did_something =
false;
140 log(
"Found and cleaned up %d empty switch%s in `%s.%s'.\n", count, count == 1 ?
"" :
"es", mod->
name.
c_str(), proc->
name.
c_str());
141 total_count += count;
150 log(
" proc_clean [selection]\n");
152 log(
"This pass removes empty parts of processes and ultimately removes a process\n");
153 log(
"if it contains only empty structures.\n");
159 log_header(
"Executing PROC_CLEAN pass (remove empty switches from decision trees).\n");
163 for (
auto mod : design->
modules()) {
164 std::vector<RTLIL::IdString> delme;
167 for (
auto &proc_it : mod->processes) {
168 if (!design->
selected(mod, proc_it.second))
171 if (proc_it.second->syncs.size() == 0 && proc_it.second->root_case.switches.size() == 0 &&
172 proc_it.second->root_case.actions.size() == 0) {
173 log(
"Removing empty process `%s.%s'.\n",
log_id(mod), proc_it.second->name.c_str());
174 delme.push_back(proc_it.first);
177 for (
auto &
id : delme) {
178 delete mod->processes[
id];
179 mod->processes.erase(
id);
183 log(
"Cleaned up %d empty switch%s.\n", total_count, total_count == 1 ?
"" :
"es");
const char * c_str() const
bool selected(T1 *module) const
YOSYS_NAMESPACE_END USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN void proc_clean_switch(RTLIL::SwitchRule *sw, RTLIL::CaseRule *parent, bool &did_something, int &count, int max_depth)
void log_header(const char *format,...)
#define YOSYS_NAMESPACE_END
RTLIL_ATTRIBUTE_MEMBERS std::vector< RTLIL::CaseRule * > cases
std::vector< RTLIL::SigSpec > compare
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
YOSYS_NAMESPACE_END PRIVATE_NAMESPACE_BEGIN void proc_clean(RTLIL::Module *mod, RTLIL::Process *proc, int &total_count)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
ProcCleanPass ProcCleanPass
#define PRIVATE_NAMESPACE_BEGIN
YOSYS_NAMESPACE_BEGIN void proc_clean_case(RTLIL::CaseRule *cs, bool &did_something, int &count, int max_depth)
bool is_fully_const() const
#define PRIVATE_NAMESPACE_END
#define USING_YOSYS_NAMESPACE
RTLIL::ObjRange< RTLIL::Module * > modules()
#define YOSYS_NAMESPACE_BEGIN
void log(const char *format,...)
std::vector< RTLIL::SyncRule * > syncs
std::vector< RTLIL::SigSig > actions
std::string id(RTLIL::IdString internal_id, bool may_rename=true)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
std::vector< RTLIL::SwitchRule * > switches
const char * log_id(RTLIL::IdString str)
RTLIL_ATTRIBUTE_MEMBERS RTLIL::CaseRule root_case