yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
proc_clean.cc File Reference
#include "kernel/register.h"
#include "kernel/log.h"
#include <stdlib.h>
#include <stdio.h>
+ Include dependency graph for proc_clean.cc:

Go to the source code of this file.

Data Structures

struct  ProcCleanPass
 

Functions

YOSYS_NAMESPACE_BEGIN void proc_clean_case (RTLIL::CaseRule *cs, bool &did_something, int &count, int max_depth)
 
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)
 
YOSYS_NAMESPACE_END
PRIVATE_NAMESPACE_BEGIN void 
proc_clean (RTLIL::Module *mod, RTLIL::Process *proc, int &total_count)
 

Variables

ProcCleanPass ProcCleanPass
 

Function Documentation

YOSYS_NAMESPACE_END PRIVATE_NAMESPACE_BEGIN void proc_clean ( RTLIL::Module mod,
RTLIL::Process proc,
int &  total_count 
)

Definition at line 122 of file proc_clean.cc.

123 {
124  int count = 0;
125  bool did_something = true;
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--));
133  }
134  }
135  while (did_something) {
136  did_something = false;
137  proc_clean_case(&proc->root_case, did_something, count, -1);
138  }
139  if (count > 0)
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;
142 }
const char * c_str() const
Definition: rtlil.h:178
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
Definition: opt_const.cc:32
YOSYS_NAMESPACE_BEGIN void proc_clean_case(RTLIL::CaseRule *cs, bool &did_something, int &count, int max_depth)
Definition: proc_clean.cc:99
RTLIL::IdString name
Definition: rtlil.h:599
RTLIL::IdString name
Definition: rtlil.h:1154
void log(const char *format,...)
Definition: log.cc:180
std::vector< RTLIL::SyncRule * > syncs
Definition: rtlil.h:1157
RTLIL_ATTRIBUTE_MEMBERS RTLIL::CaseRule root_case
Definition: rtlil.h:1156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

YOSYS_NAMESPACE_BEGIN void proc_clean_case ( RTLIL::CaseRule cs,
bool &  did_something,
int &  count,
int  max_depth 
)

Definition at line 99 of file proc_clean.cc.

100 {
101  for (size_t i = 0; i < cs->actions.size(); i++) {
102  if (cs->actions[i].first.size() == 0) {
103  did_something = true;
104  cs->actions.erase(cs->actions.begin() + (i--));
105  }
106  }
107  for (size_t i = 0; i < cs->switches.size(); i++) {
108  RTLIL::SwitchRule *sw = cs->switches[i];
109  if (sw->cases.size() == 0) {
110  cs->switches.erase(cs->switches.begin() + (i--));
111  did_something = true;
112  delete sw;
113  count++;
114  } else if (max_depth != 0)
115  proc_clean_switch(sw, cs, did_something, count, max_depth-1);
116  }
117 }
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)
Definition: proc_clean.cc:32
RTLIL_ATTRIBUTE_MEMBERS std::vector< RTLIL::CaseRule * > cases
Definition: rtlil.h:1134
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
Definition: opt_const.cc:32
std::vector< RTLIL::SigSig > actions
Definition: rtlil.h:1120
std::vector< RTLIL::SwitchRule * > switches
Definition: rtlil.h:1121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)

Definition at line 32 of file proc_clean.cc.

33 {
34  if (sw->signal.size() > 0 && sw->signal.is_fully_const())
35  {
36  int found_matching_case_idx = -1;
37  for (int i = 0; i < int(sw->cases.size()) && found_matching_case_idx < 0; i++)
38  {
39  RTLIL::CaseRule *cs = sw->cases[i];
40  if (cs->compare.size() == 0)
41  break;
42  for (int j = 0; j < int(cs->compare.size()); j++) {
43  RTLIL::SigSpec &val = cs->compare[j];
44  if (!val.is_fully_const())
45  continue;
46  if (val == sw->signal) {
47  cs->compare.clear();
48  found_matching_case_idx = i;
49  break;
50  } else
51  cs->compare.erase(cs->compare.begin()+(j--));
52  }
53  if (cs->compare.size() == 0 && found_matching_case_idx < 0) {
54  sw->cases.erase(sw->cases.begin()+(i--));
55  delete cs;
56  }
57  }
58  while (found_matching_case_idx >= 0 && int(sw->cases.size()) > found_matching_case_idx+1) {
59  delete sw->cases.back();
60  sw->cases.pop_back();
61  }
62  if (found_matching_case_idx == 0)
63  sw->signal = RTLIL::SigSpec();
64  }
65 
66  if (parent->switches.front() == sw && sw->cases.size() == 1 &&
67  (sw->signal.size() == 0 || sw->cases[0]->compare.empty()))
68  {
69  did_something = true;
70  for (auto &action : sw->cases[0]->actions)
71  parent->actions.push_back(action);
72  for (auto sw2 : sw->cases[0]->switches)
73  parent->switches.push_back(sw2);
74  sw->cases[0]->switches.clear();
75  delete sw->cases[0];
76  sw->cases.clear();
77  }
78  else
79  {
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;
84  if (max_depth != 0)
85  proc_clean_case(cs, did_something, count, max_depth-1);
86  }
87  if (all_cases_are_empty) {
88  did_something = true;
89  for (auto cs : sw->cases)
90  delete cs;
91  sw->cases.clear();
92  }
93  }
94 }
RTLIL_ATTRIBUTE_MEMBERS std::vector< RTLIL::CaseRule * > cases
Definition: rtlil.h:1134
int size() const
Definition: rtlil.h:1019
std::vector< RTLIL::SigSpec > compare
Definition: rtlil.h:1119
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
Definition: opt_const.cc:32
RTLIL::SigSpec signal
Definition: rtlil.h:1132
YOSYS_NAMESPACE_BEGIN void proc_clean_case(RTLIL::CaseRule *cs, bool &did_something, int &count, int max_depth)
Definition: proc_clean.cc:99
bool is_fully_const() const
Definition: rtlil.cc:2763
std::vector< RTLIL::SigSig > actions
Definition: rtlil.h:1120
std::vector< RTLIL::SwitchRule * > switches
Definition: rtlil.h:1121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation