yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fsm_detect.cc File Reference
#include "kernel/log.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/consteval.h"
#include "kernel/celltypes.h"
#include "fsmdata.h"
+ Include dependency graph for fsm_detect.cc:

Go to the source code of this file.

Data Structures

struct  FsmDetectPass
 

Typedefs

typedef std::pair< RTLIL::Cell
*, RTLIL::IdString
sig2driver_entry_t
 

Functions

static bool check_state_mux_tree (RTLIL::SigSpec old_sig, RTLIL::SigSpec sig, SigPool &recursion_monitor)
 
static bool check_state_users (RTLIL::SigSpec sig)
 
static void detect_fsm (RTLIL::Wire *wire)
 

Variables

USING_YOSYS_NAMESPACE static
PRIVATE_NAMESPACE_BEGIN
RTLIL::Module
module
 
static SigMap assign_map
 
static SigSet< sig2driver_entry_tsig2driver
 
static SigSet< sig2driver_entry_tsig2user
 
static std::set< RTLIL::Cell * > muxtree_cells
 
static SigPool sig_at_port
 
FsmDetectPass FsmDetectPass
 

Typedef Documentation

Definition at line 32 of file fsm_detect.cc.

Function Documentation

static bool check_state_mux_tree ( RTLIL::SigSpec  old_sig,
RTLIL::SigSpec  sig,
SigPool recursion_monitor 
)
static

Definition at line 37 of file fsm_detect.cc.

38 {
40  return false;
41 
42  if (sig.is_fully_const() || old_sig == sig)
43  return true;
44 
45  if (recursion_monitor.check_any(sig)) {
46  log_warning("logic loop in mux tree at signal %s in module %s.\n",
48  return false;
49  }
50 
51  recursion_monitor.add(sig);
52 
53  std::set<sig2driver_entry_t> cellport_list;
54  sig2driver.find(sig, cellport_list);
55  for (auto &cellport : cellport_list) {
56  if ((cellport.first->type != "$mux" && cellport.first->type != "$pmux") || cellport.second != "\\Y")
57  return false;
58  RTLIL::SigSpec sig_a = assign_map(cellport.first->getPort("\\A"));
59  RTLIL::SigSpec sig_b = assign_map(cellport.first->getPort("\\B"));
60  if (!check_state_mux_tree(old_sig, sig_a, recursion_monitor))
61  return false;
62  for (int i = 0; i < sig_b.size(); i += sig_a.size())
63  if (!check_state_mux_tree(old_sig, sig_b.extract(i, sig_a.size()), recursion_monitor))
64  return false;
65  muxtree_cells.insert(cellport.first);
66  }
67 
68  recursion_monitor.del(sig);
69 
70  return true;
71 }
void log_warning(const char *format,...)
Definition: log.cc:196
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
static SigPool sig_at_port
Definition: fsm_detect.cc:35
int size() const
Definition: rtlil.h:1019
bool check_any(RTLIL::SigSpec sig)
Definition: sigtools.h:100
static SigMap assign_map
Definition: fsm_detect.cc:31
bool is_fully_const() const
Definition: rtlil.cc:2763
RTLIL::IdString name
Definition: rtlil.h:599
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267
void add(RTLIL::SigSpec sig)
Definition: sigtools.h:41
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
static SigSet< sig2driver_entry_t > sig2driver
Definition: fsm_detect.cc:33
static std::set< RTLIL::Cell * > muxtree_cells
Definition: fsm_detect.cc:34
void del(RTLIL::SigSpec sig)
Definition: sigtools.h:54
static bool check_state_mux_tree(RTLIL::SigSpec old_sig, RTLIL::SigSpec sig, SigPool &recursion_monitor)
Definition: fsm_detect.cc:37
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN RTLIL::Module * module
Definition: fsm_detect.cc:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool check_state_users ( RTLIL::SigSpec  sig)
static

Definition at line 73 of file fsm_detect.cc.

74 {
76  return false;
77 
78  std::set<sig2driver_entry_t> cellport_list;
79  sig2user.find(sig, cellport_list);
80  for (auto &cellport : cellport_list) {
81  RTLIL::Cell *cell = cellport.first;
82  if (muxtree_cells.count(cell) > 0)
83  continue;
84  if (cellport.second != "\\A" && cellport.second != "\\B")
85  return false;
86  if (!cell->hasPort("\\A") || !cell->hasPort("\\B") || !cell->hasPort("\\Y"))
87  return false;
88  for (auto &port_it : cell->connections())
89  if (port_it.first != "\\A" && port_it.first != "\\B" && port_it.first != "\\Y")
90  return false;
91  if (assign_map(cell->getPort("\\A")) == sig && cell->getPort("\\B").is_fully_const())
92  continue;
93  if (assign_map(cell->getPort("\\B")) == sig && cell->getPort("\\A").is_fully_const())
94  continue;
95  return false;
96  }
97 
98  return true;
99 }
static SigPool sig_at_port
Definition: fsm_detect.cc:35
bool check_any(RTLIL::SigSpec sig)
Definition: sigtools.h:100
static SigMap assign_map
Definition: fsm_detect.cc:31
RTLIL_ATTRIBUTE_MEMBERS bool hasPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1766
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
bool is_fully_const() const
Definition: rtlil.cc:2763
static SigSet< sig2driver_entry_t > sig2user
Definition: fsm_detect.cc:33
static std::set< RTLIL::Cell * > muxtree_cells
Definition: fsm_detect.cc:34
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void detect_fsm ( RTLIL::Wire wire)
static

Definition at line 101 of file fsm_detect.cc.

102 {
103  if (wire->attributes.count("\\fsm_encoding") > 0 || wire->width <= 1)
104  return;
106  return;
107 
108  std::set<sig2driver_entry_t> cellport_list;
109  sig2driver.find(RTLIL::SigSpec(wire), cellport_list);
110  for (auto &cellport : cellport_list) {
111  if ((cellport.first->type != "$dff" && cellport.first->type != "$adff") || cellport.second != "\\Q")
112  continue;
113  muxtree_cells.clear();
114  SigPool recursion_monitor;
115  RTLIL::SigSpec sig_q = assign_map(cellport.first->getPort("\\Q"));
116  RTLIL::SigSpec sig_d = assign_map(cellport.first->getPort("\\D"));
117  if (sig_q == RTLIL::SigSpec(wire) && check_state_mux_tree(sig_q, sig_d, recursion_monitor) && check_state_users(sig_q)) {
118  log("Found FSM state register %s in module %s.\n", wire->name.c_str(), module->name.c_str());
119  wire->attributes["\\fsm_encoding"] = RTLIL::Const("auto");
120  return;
121  }
122  }
123 }
const char * c_str() const
Definition: rtlil.h:178
int width
Definition: rtlil.h:826
static SigPool sig_at_port
Definition: fsm_detect.cc:35
static bool check_state_users(RTLIL::SigSpec sig)
Definition: fsm_detect.cc:73
bool check_any(RTLIL::SigSpec sig)
Definition: sigtools.h:100
static SigMap assign_map
Definition: fsm_detect.cc:31
RTLIL::IdString name
Definition: rtlil.h:599
RTLIL::IdString name
Definition: rtlil.h:825
void log(const char *format,...)
Definition: log.cc:180
static SigSet< sig2driver_entry_t > sig2driver
Definition: fsm_detect.cc:33
static std::set< RTLIL::Cell * > muxtree_cells
Definition: fsm_detect.cc:34
static bool check_state_mux_tree(RTLIL::SigSpec old_sig, RTLIL::SigSpec sig, SigPool &recursion_monitor)
Definition: fsm_detect.cc:37
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN RTLIL::Module * module
Definition: fsm_detect.cc:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

SigMap assign_map
static

Definition at line 31 of file fsm_detect.cc.

Definition at line 30 of file fsm_detect.cc.

std::set<RTLIL::Cell*> muxtree_cells
static

Definition at line 34 of file fsm_detect.cc.

SigSet<sig2driver_entry_t> sig2driver
static

Definition at line 33 of file fsm_detect.cc.

SigSet<sig2driver_entry_t> sig2user
static

Definition at line 33 of file fsm_detect.cc.

SigPool sig_at_port
static

Definition at line 35 of file fsm_detect.cc.