mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	Add latch detection for use_case_method in part-select write, fixes #2040
Signed-off-by: Claire Wolf <claire@symbioticeda.com>
This commit is contained in:
		
							parent
							
								
									7112f187cd
								
							
						
					
					
						commit
						7ad0c49905
					
				
					 2 changed files with 58 additions and 0 deletions
				
			
		|  | @ -257,6 +257,7 @@ namespace AST | ||||||
| 		bool mem2reg_check(pool<AstNode*> &mem2reg_set); | 		bool mem2reg_check(pool<AstNode*> &mem2reg_set); | ||||||
| 		void mem2reg_remove(pool<AstNode*> &mem2reg_set, vector<AstNode*> &delnodes); | 		void mem2reg_remove(pool<AstNode*> &mem2reg_set, vector<AstNode*> &delnodes); | ||||||
| 		void meminfo(int &mem_width, int &mem_size, int &addr_bits); | 		void meminfo(int &mem_width, int &mem_size, int &addr_bits); | ||||||
|  | 		bool detect_latch(const std::string &var); | ||||||
| 
 | 
 | ||||||
| 		// additional functionality for evaluating constant functions
 | 		// additional functionality for evaluating constant functions
 | ||||||
| 		struct varinfo_t { RTLIL::Const val; int offset; bool is_signed; }; | 		struct varinfo_t { RTLIL::Const val; int offset; bool is_signed; }; | ||||||
|  |  | ||||||
|  | @ -2017,6 +2017,9 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, | ||||||
| 				use_case_method = true; | 				use_case_method = true; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		if (!use_case_method && current_always->detect_latch(children[0]->str)) | ||||||
|  | 			use_case_method = true; | ||||||
|  | 
 | ||||||
| 		if (use_case_method) | 		if (use_case_method) | ||||||
| 		{ | 		{ | ||||||
| 			// big case block
 | 			// big case block
 | ||||||
|  | @ -4085,6 +4088,60 @@ void AstNode::meminfo(int &mem_width, int &mem_size, int &addr_bits) | ||||||
| 		addr_bits++; | 		addr_bits++; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool AstNode::detect_latch(const std::string &var) | ||||||
|  | { | ||||||
|  | 	switch (type) | ||||||
|  | 	{ | ||||||
|  | 	case AST_ALWAYS: | ||||||
|  | 		for (auto &c : children) | ||||||
|  | 		{ | ||||||
|  | 			switch (c->type) | ||||||
|  | 			{ | ||||||
|  | 			case AST_POSEDGE: | ||||||
|  | 			case AST_NEGEDGE: | ||||||
|  | 				return false; | ||||||
|  | 			case AST_BLOCK: | ||||||
|  | 				if (!c->detect_latch(var)) | ||||||
|  | 					return false; | ||||||
|  | 				break; | ||||||
|  | 			default: | ||||||
|  | 				log_abort(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return true; | ||||||
|  | 	case AST_BLOCK: | ||||||
|  | 		for (auto &c : children) | ||||||
|  | 			if (!c->detect_latch(var)) | ||||||
|  | 				return false; | ||||||
|  | 		return true; | ||||||
|  | 	case AST_CASE: | ||||||
|  | 		{ | ||||||
|  | 			bool r = true; | ||||||
|  | 			for (auto &c : children) { | ||||||
|  | 				if (c->type == AST_COND) { | ||||||
|  | 					if (c->children.at(1)->detect_latch(var)) | ||||||
|  | 						return true; | ||||||
|  | 					r = false; | ||||||
|  | 				} | ||||||
|  | 				if (c->type == AST_DEFAULT) { | ||||||
|  | 					if (c->children.at(0)->detect_latch(var)) | ||||||
|  | 						return true; | ||||||
|  | 					r = false; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			return r; | ||||||
|  | 		} | ||||||
|  | 	case AST_ASSIGN_EQ: | ||||||
|  | 	case AST_ASSIGN_LE: | ||||||
|  | 		if (children.at(0)->type == AST_IDENTIFIER && | ||||||
|  | 				children.at(0)->children.empty() && children.at(0)->str == var) | ||||||
|  | 			return false; | ||||||
|  | 		return true; | ||||||
|  | 	default: | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool AstNode::has_const_only_constructs(bool &recommend_const_eval) | bool AstNode::has_const_only_constructs(bool &recommend_const_eval) | ||||||
| { | { | ||||||
| 	if (type == AST_FOR) | 	if (type == AST_FOR) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue