| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | ! Copyright (C) 2009 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-08-08 05:02:18 -04:00
										 |  |  | USING: assocs cpu.architecture compiler.cfg.registers | 
					
						
							| 
									
										
										
										
											2009-08-07 18:44:50 -04:00
										 |  |  | compiler.cfg.instructions deques dlists fry kernel locals namespaces | 
					
						
							|  |  |  | sequences hashtables ;
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | IN: compiler.cfg.parallel-copy | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | ! Revisiting Out-of-SSA Translation for Correctness, Code Quality, and Efficiency | 
					
						
							|  |  |  | ! http://hal.archives-ouvertes.fr/docs/00/34/99/25/PDF/OutSSA-RR.pdf, | 
					
						
							|  |  |  | ! Algorithm 1 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | <PRIVATE
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | SYMBOLS: temp locs preds to-do ready ;
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | : init-to-do ( bs -- )
 | 
					
						
							|  |  |  |     to-do get push-all-back ;
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | : init-ready ( bs -- )
 | 
					
						
							|  |  |  |     locs get '[ _ key? not ] filter ready get push-all-front ;
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | : init ( mapping temp -- )
 | 
					
						
							|  |  |  |     temp set
 | 
					
						
							|  |  |  |     <dlist> to-do set
 | 
					
						
							|  |  |  |     <dlist> ready set
 | 
					
						
							| 
									
										
										
										
											2009-07-28 09:47:35 -04:00
										 |  |  |     [ preds set ] | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  |     [ [ nip dup ] H{ } assoc-map-as locs set ] | 
					
						
							|  |  |  |     [ keys [ init-to-do ] [ init-ready ] bi ] tri ;
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | :: process-ready ( b quot -- )
 | 
					
						
							|  |  |  |     b preds get at :> a | 
					
						
							|  |  |  |     a locs get at :> c | 
					
						
							|  |  |  |     b c quot call
 | 
					
						
							|  |  |  |     b a locs get set-at
 | 
					
						
							|  |  |  |     a c = a preds get at and [ a ready get push-front ] when ; inline
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | :: process-to-do ( b quot -- )
 | 
					
						
							|  |  |  |     ! Note that we check if b = loc(b), not b = loc(pred(b)) as the | 
					
						
							|  |  |  |     ! paper suggests. Confirmed by one of the authors at | 
					
						
							|  |  |  |     ! http://www.reddit.com/comments/93253/some_lecture_notes_on_ssa_form/c0bco4f | 
					
						
							|  |  |  |     b locs get at b = [ | 
					
						
							|  |  |  |         temp get b quot call
 | 
					
						
							|  |  |  |         temp get b locs get set-at
 | 
					
						
							|  |  |  |         b ready get push-front | 
					
						
							|  |  |  |     ] when ; inline
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :: parallel-mapping ( mapping temp quot -- )
 | 
					
						
							| 
									
										
										
										
											2009-07-24 20:46:33 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-07-27 17:54:47 -04:00
										 |  |  |         mapping temp init | 
					
						
							|  |  |  |         to-do get [ | 
					
						
							|  |  |  |             ready get [ | 
					
						
							|  |  |  |                 quot process-ready | 
					
						
							|  |  |  |             ] slurp-deque | 
					
						
							|  |  |  |             quot process-to-do | 
					
						
							|  |  |  |         ] slurp-deque | 
					
						
							|  |  |  |     ] with-scope ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-08 05:02:18 -04:00
										 |  |  | : parallel-copy ( mapping -- )
 | 
					
						
							| 
									
										
										
										
											2011-11-11 22:48:38 -05:00
										 |  |  |     next-vreg [ any-rep ##copy, ] parallel-mapping ;
 |