| 
									
										
										
										
											2010-04-24 02:38:43 -04:00
										 |  |  | ! Copyright (C) 2008, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2008-10-19 02:10:21 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2014-12-13 19:10:21 -05:00
										 |  |  | USING: accessors arrays assocs compiler.cfg compiler.cfg.def-use | 
					
						
							|  |  |  | compiler.cfg.instructions compiler.cfg.rpo | 
					
						
							|  |  |  | compiler.cfg.utilities kernel locals namespaces sequences | 
					
						
							|  |  |  | sequences.deep ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.alien | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.comparisons | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.expressions | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.folding | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.graph | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.math | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.misc | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.rewrite | 
					
						
							|  |  |  | USE: compiler.cfg.value-numbering.slots | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-19 02:10:21 -04:00
										 |  |  | IN: compiler.cfg.value-numbering | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 06:30:30 -04:00
										 |  |  | GENERIC: process-instruction ( insn -- insn' )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-24 06:06:16 -04:00
										 |  |  | : redundant-instruction ( insn vn -- insn' )
 | 
					
						
							| 
									
										
										
										
											2010-04-24 06:15:41 -04:00
										 |  |  |     [ dst>> ] dip [ swap set-vn ] [ <copy> ] 2bi ;
 | 
					
						
							| 
									
										
										
										
											2010-04-24 06:06:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | :: useful-instruction ( insn expr -- insn' )
 | 
					
						
							| 
									
										
										
										
											2010-04-24 06:15:41 -04:00
										 |  |  |     insn dst>> :> vn | 
					
						
							|  |  |  |     vn vn vregs>vns get set-at
 | 
					
						
							| 
									
										
										
										
											2010-04-24 06:06:16 -04:00
										 |  |  |     vn expr exprs>vns get set-at
 | 
					
						
							|  |  |  |     insn vn vns>insns get set-at
 | 
					
						
							|  |  |  |     insn ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : check-redundancy ( insn -- insn' )
 | 
					
						
							|  |  |  |     dup >expr dup exprs>vns get at
 | 
					
						
							|  |  |  |     [ redundant-instruction ] [ useful-instruction ] ?if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 06:30:30 -04:00
										 |  |  | M: insn process-instruction | 
					
						
							| 
									
										
										
										
											2010-07-13 07:40:14 -04:00
										 |  |  |     dup rewrite [ process-instruction ] [ ] ?if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: foldable-insn process-instruction | 
					
						
							| 
									
										
										
										
											2009-07-24 06:30:30 -04:00
										 |  |  |     dup rewrite | 
					
						
							| 
									
										
										
										
											2009-09-02 07:22:37 -04:00
										 |  |  |     [ process-instruction ] | 
					
						
							| 
									
										
										
										
											2010-07-13 07:40:14 -04:00
										 |  |  |     [ dup defs-vregs length 1 = [ check-redundancy ] when ] ?if ;
 | 
					
						
							| 
									
										
										
										
											2010-04-24 02:38:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: ##copy process-instruction | 
					
						
							|  |  |  |     dup [ src>> vreg>vn ] [ dst>> ] bi set-vn ;
 | 
					
						
							| 
									
										
										
										
											2009-07-10 00:14:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-27 01:06:19 -04:00
										 |  |  | M: array process-instruction | 
					
						
							|  |  |  |     [ process-instruction ] map ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 20:56:56 -04:00
										 |  |  | : value-numbering-step ( insns -- insns' )
 | 
					
						
							| 
									
										
										
										
											2009-07-22 04:08:28 -04:00
										 |  |  |     init-value-graph | 
					
						
							| 
									
										
										
										
											2009-08-27 01:06:19 -04:00
										 |  |  |     [ process-instruction ] map flatten ;
 | 
					
						
							| 
									
										
										
										
											2009-05-26 20:31:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-07 21:36:52 -05:00
										 |  |  | : value-numbering ( cfg -- )
 | 
					
						
							| 
									
										
										
										
											2014-12-10 10:14:08 -05:00
										 |  |  |     [ [ value-numbering-step ] simple-optimization ] | 
					
						
							|  |  |  |     [ cfg-changed ] | 
					
						
							|  |  |  |     [ predecessors-changed ] tri ;
 |