mirror of https://github.com/YosysHQ/yosys.git
dict/pool changes in ast
This commit is contained in:
parent
397ae5b697
commit
90bc71dd90
|
@ -180,6 +180,10 @@ bool AstNode::get_bool_attribute(RTLIL::IdString id)
|
|||
// (the optional child arguments make it easier to create AST trees)
|
||||
AstNode::AstNode(AstNodeType type, AstNode *child1, AstNode *child2)
|
||||
{
|
||||
static unsigned int hashidx_count = 123456789;
|
||||
hashidx_count = mkhash_xorshift(hashidx_count);
|
||||
hashidx_ = hashidx_count;
|
||||
|
||||
this->type = type;
|
||||
filename = current_filename;
|
||||
linenum = get_line_num();
|
||||
|
|
|
@ -142,6 +142,10 @@ namespace AST
|
|||
// The AST is built using instances of this struct
|
||||
struct AstNode
|
||||
{
|
||||
// for dict<> and pool<>
|
||||
unsigned int hashidx_;
|
||||
unsigned int hash() const { return hashidx_; }
|
||||
|
||||
// this nodes type
|
||||
AstNodeType type;
|
||||
|
||||
|
@ -207,10 +211,10 @@ namespace AST
|
|||
AstNode *readmem(bool is_readmemh, std::string mem_filename, AstNode *memory, int start_addr, int finish_addr);
|
||||
void expand_genblock(std::string index_var, std::string prefix, std::map<std::string, std::string> &name_map);
|
||||
void replace_ids(const std::string &prefix, const std::map<std::string, std::string> &rules);
|
||||
void mem2reg_as_needed_pass1(std::map<AstNode*, std::set<std::string>> &mem2reg_places,
|
||||
std::map<AstNode*, uint32_t> &mem2reg_flags, std::map<AstNode*, uint32_t> &proc_flags, uint32_t &status_flags);
|
||||
void mem2reg_as_needed_pass2(std::set<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block);
|
||||
bool mem2reg_check(std::set<AstNode*> &mem2reg_set);
|
||||
void mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg_places,
|
||||
dict<AstNode*, uint32_t> &mem2reg_flags, dict<AstNode*, uint32_t> &proc_flags, uint32_t &status_flags);
|
||||
void mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block);
|
||||
bool mem2reg_check(pool<AstNode*> &mem2reg_set);
|
||||
void meminfo(int &mem_width, int &mem_size, int &addr_bits);
|
||||
|
||||
// additional functionality for evaluating constant functions
|
||||
|
|
|
@ -67,12 +67,12 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
|
||||
if (!flag_nomem2reg && !get_bool_attribute("\\nomem2reg"))
|
||||
{
|
||||
std::map<AstNode*, std::set<std::string>> mem2reg_places;
|
||||
std::map<AstNode*, uint32_t> mem2reg_candidates, dummy_proc_flags;
|
||||
dict<AstNode*, pool<std::string>> mem2reg_places;
|
||||
dict<AstNode*, uint32_t> mem2reg_candidates, dummy_proc_flags;
|
||||
uint32_t flags = flag_mem2reg ? AstNode::MEM2REG_FL_ALL : 0;
|
||||
mem2reg_as_needed_pass1(mem2reg_places, mem2reg_candidates, dummy_proc_flags, flags);
|
||||
|
||||
std::set<AstNode*> mem2reg_set;
|
||||
pool<AstNode*> mem2reg_set;
|
||||
for (auto &it : mem2reg_candidates)
|
||||
{
|
||||
AstNode *mem = it.first;
|
||||
|
@ -2184,8 +2184,8 @@ void AstNode::replace_ids(const std::string &prefix, const std::map<std::string,
|
|||
}
|
||||
|
||||
// helper function for mem2reg_as_needed_pass1
|
||||
static void mark_memories_assign_lhs_complex(std::map<AstNode*, std::set<std::string>> &mem2reg_places,
|
||||
std::map<AstNode*, uint32_t> &mem2reg_candidates, AstNode *that)
|
||||
static void mark_memories_assign_lhs_complex(dict<AstNode*, pool<std::string>> &mem2reg_places,
|
||||
dict<AstNode*, uint32_t> &mem2reg_candidates, AstNode *that)
|
||||
{
|
||||
for (auto &child : that->children)
|
||||
mark_memories_assign_lhs_complex(mem2reg_places, mem2reg_candidates, child);
|
||||
|
@ -2199,8 +2199,8 @@ static void mark_memories_assign_lhs_complex(std::map<AstNode*, std::set<std::st
|
|||
}
|
||||
|
||||
// find memories that should be replaced by registers
|
||||
void AstNode::mem2reg_as_needed_pass1(std::map<AstNode*, std::set<std::string>> &mem2reg_places,
|
||||
std::map<AstNode*, uint32_t> &mem2reg_candidates, std::map<AstNode*, uint32_t> &proc_flags, uint32_t &flags)
|
||||
void AstNode::mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg_places,
|
||||
dict<AstNode*, uint32_t> &mem2reg_candidates, dict<AstNode*, uint32_t> &proc_flags, uint32_t &flags)
|
||||
{
|
||||
uint32_t children_flags = 0;
|
||||
int ignore_children_counter = 0;
|
||||
|
@ -2262,7 +2262,7 @@ void AstNode::mem2reg_as_needed_pass1(std::map<AstNode*, std::set<std::string>>
|
|||
if (type == AST_MODULE && get_bool_attribute("\\mem2reg"))
|
||||
children_flags |= AstNode::MEM2REG_FL_ALL;
|
||||
|
||||
std::map<AstNode*, uint32_t> *proc_flags_p = NULL;
|
||||
dict<AstNode*, uint32_t> *proc_flags_p = NULL;
|
||||
|
||||
if (type == AST_ALWAYS) {
|
||||
int count_edge_events = 0;
|
||||
|
@ -2271,12 +2271,12 @@ void AstNode::mem2reg_as_needed_pass1(std::map<AstNode*, std::set<std::string>>
|
|||
count_edge_events++;
|
||||
if (count_edge_events != 1)
|
||||
children_flags |= AstNode::MEM2REG_FL_ASYNC;
|
||||
proc_flags_p = new std::map<AstNode*, uint32_t>;
|
||||
proc_flags_p = new dict<AstNode*, uint32_t>;
|
||||
}
|
||||
|
||||
if (type == AST_INITIAL) {
|
||||
children_flags |= AstNode::MEM2REG_FL_INIT;
|
||||
proc_flags_p = new std::map<AstNode*, uint32_t>;
|
||||
proc_flags_p = new dict<AstNode*, uint32_t>;
|
||||
}
|
||||
|
||||
uint32_t backup_flags = flags;
|
||||
|
@ -2300,7 +2300,7 @@ void AstNode::mem2reg_as_needed_pass1(std::map<AstNode*, std::set<std::string>>
|
|||
}
|
||||
}
|
||||
|
||||
bool AstNode::mem2reg_check(std::set<AstNode*> &mem2reg_set)
|
||||
bool AstNode::mem2reg_check(pool<AstNode*> &mem2reg_set)
|
||||
{
|
||||
if (type != AST_IDENTIFIER || !id2ast || !mem2reg_set.count(id2ast))
|
||||
return false;
|
||||
|
@ -2312,7 +2312,7 @@ bool AstNode::mem2reg_check(std::set<AstNode*> &mem2reg_set)
|
|||
}
|
||||
|
||||
// actually replace memories with registers
|
||||
void AstNode::mem2reg_as_needed_pass2(std::set<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block)
|
||||
void AstNode::mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block)
|
||||
{
|
||||
if (type == AST_BLOCK)
|
||||
block = this;
|
||||
|
|
|
@ -159,6 +159,10 @@ namespace RTLIL {
|
|||
struct Monitor;
|
||||
}
|
||||
|
||||
namespace AST {
|
||||
struct AstNode;
|
||||
}
|
||||
|
||||
using RTLIL::IdString;
|
||||
using RTLIL::Const;
|
||||
using RTLIL::SigBit;
|
||||
|
@ -174,12 +178,14 @@ namespace hashlib {
|
|||
template<> struct hash_ops<RTLIL::Module*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<RTLIL::Design*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<RTLIL::Monitor*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<AST::AstNode*> : hash_obj_ops {};
|
||||
|
||||
template<> struct hash_ops<const RTLIL::Wire*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const RTLIL::Cell*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const RTLIL::Module*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const RTLIL::Design*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const RTLIL::Monitor*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const AST::AstNode*> : hash_obj_ops {};
|
||||
}
|
||||
|
||||
void memhasher_on();
|
||||
|
|
Loading…
Reference in New Issue