mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	Merge pull request #2338 from zachjs/const-branch-finish
Propagate const_fold through generate blocks and branches
This commit is contained in:
		
						commit
						4aa0dc4dc7
					
				
					 2 changed files with 43 additions and 4 deletions
				
			
		| 
						 | 
					@ -1807,7 +1807,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (type == AST_GENFOR) {
 | 
								if (type == AST_GENFOR) {
 | 
				
			||||||
				for (size_t i = 0; i < buf->children.size(); i++) {
 | 
									for (size_t i = 0; i < buf->children.size(); i++) {
 | 
				
			||||||
					buf->children[i]->simplify(false, false, false, stage, -1, false, false);
 | 
										buf->children[i]->simplify(const_fold, false, false, stage, -1, false, false);
 | 
				
			||||||
					current_ast_mod->children.push_back(buf->children[i]);
 | 
										current_ast_mod->children.push_back(buf->children[i]);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
| 
						 | 
					@ -1883,7 +1883,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (size_t i = 0; i < children.size(); i++) {
 | 
							for (size_t i = 0; i < children.size(); i++) {
 | 
				
			||||||
			children[i]->simplify(false, false, false, stage, -1, false, false);
 | 
								children[i]->simplify(const_fold, false, false, stage, -1, false, false);
 | 
				
			||||||
			current_ast_mod->children.push_back(children[i]);
 | 
								current_ast_mod->children.push_back(children[i]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1920,7 +1920,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (size_t i = 0; i < buf->children.size(); i++) {
 | 
								for (size_t i = 0; i < buf->children.size(); i++) {
 | 
				
			||||||
				buf->children[i]->simplify(false, false, false, stage, -1, false, false);
 | 
									buf->children[i]->simplify(const_fold, false, false, stage, -1, false, false);
 | 
				
			||||||
				current_ast_mod->children.push_back(buf->children[i]);
 | 
									current_ast_mod->children.push_back(buf->children[i]);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1999,7 +1999,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (size_t i = 0; i < buf->children.size(); i++) {
 | 
								for (size_t i = 0; i < buf->children.size(); i++) {
 | 
				
			||||||
				buf->children[i]->simplify(false, false, false, stage, -1, false, false);
 | 
									buf->children[i]->simplify(const_fold, false, false, stage, -1, false, false);
 | 
				
			||||||
				current_ast_mod->children.push_back(buf->children[i]);
 | 
									current_ast_mod->children.push_back(buf->children[i]);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										39
									
								
								tests/simple/const_branch_finish.v
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								tests/simple/const_branch_finish.v
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					`define CONSTANT_CHECK \
 | 
				
			||||||
 | 
						if (WIDTH === 'bx) begin \
 | 
				
			||||||
 | 
							$display("FAIL"); \
 | 
				
			||||||
 | 
							$finish; \
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module top;
 | 
				
			||||||
 | 
						parameter WIDTH = 32;
 | 
				
			||||||
 | 
						integer j;
 | 
				
			||||||
 | 
						initial begin
 | 
				
			||||||
 | 
							`CONSTANT_CHECK
 | 
				
			||||||
 | 
							if (WIDTH == 32) begin : procedural_conditional_block
 | 
				
			||||||
 | 
								`CONSTANT_CHECK
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
							case (WIDTH)
 | 
				
			||||||
 | 
								32: `CONSTANT_CHECK
 | 
				
			||||||
 | 
								default: ;
 | 
				
			||||||
 | 
							endcase
 | 
				
			||||||
 | 
							for (j = 0; j < 2; j = j + 1) begin : procedural_loop_block
 | 
				
			||||||
 | 
								`CONSTANT_CHECK
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						generate
 | 
				
			||||||
 | 
							begin : unconditional_block
 | 
				
			||||||
 | 
								initial `CONSTANT_CHECK
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
							if (WIDTH == 32) begin : conditional_block
 | 
				
			||||||
 | 
								initial `CONSTANT_CHECK
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
							case (WIDTH)
 | 
				
			||||||
 | 
								32: initial `CONSTANT_CHECK
 | 
				
			||||||
 | 
								default: ;
 | 
				
			||||||
 | 
							endcase
 | 
				
			||||||
 | 
							genvar i;
 | 
				
			||||||
 | 
							for (i = 0; i < 2; i = i + 1) begin : loop_block
 | 
				
			||||||
 | 
								initial `CONSTANT_CHECK
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
						endgenerate
 | 
				
			||||||
 | 
					endmodule
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue