compiler.cfg.dominance: add pre order and max pre order numbers; use them to implement dominates? check
							parent
							
								
									5bbd89f170
								
							
						
					
					
						commit
						2137c9cc79
					
				| 
						 | 
				
			
			@ -6,7 +6,8 @@ compiler.cfg.predecessors ;
 | 
			
		|||
: test-dominance ( -- )
 | 
			
		||||
    cfg new 0 get >>entry
 | 
			
		||||
    compute-predecessors
 | 
			
		||||
    compute-dominance ;
 | 
			
		||||
    dup compute-dominance
 | 
			
		||||
    compute-dfs ;
 | 
			
		||||
 | 
			
		||||
! Example with no back edges
 | 
			
		||||
V{ } 0 test-bb
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +39,12 @@ V{ } 5 test-bb
 | 
			
		|||
[ { } ] [ 0 get dom-frontier ] unit-test
 | 
			
		||||
[ { } ] [ 4 get dom-frontier ] unit-test
 | 
			
		||||
 | 
			
		||||
[ t ] [ 0 get 3 get dominates? ] unit-test
 | 
			
		||||
[ f ] [ 3 get 4 get dominates? ] unit-test
 | 
			
		||||
[ f ] [ 1 get 4 get dominates? ] unit-test
 | 
			
		||||
[ t ] [ 4 get 5 get dominates? ] unit-test
 | 
			
		||||
[ f ] [ 1 get 5 get dominates? ] unit-test
 | 
			
		||||
 | 
			
		||||
! Example from the paper
 | 
			
		||||
V{ } 0 test-bb
 | 
			
		||||
V{ } 1 test-bb
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,3 +113,29 @@ PRIVATE>
 | 
			
		|||
        work-list get [ iterated-dom-frontier-step ] slurp-deque
 | 
			
		||||
        visited get keys
 | 
			
		||||
    ] with-scope ;
 | 
			
		||||
 | 
			
		||||
<PRIVATE
 | 
			
		||||
 | 
			
		||||
SYMBOLS: preorder maxpreorder ;
 | 
			
		||||
 | 
			
		||||
: pre-of ( bb -- n ) [ preorder get at ] [ -1/0. ] if* ;
 | 
			
		||||
 | 
			
		||||
: maxpre-of ( bb -- n ) [ maxpreorder get at ] [ 1/0. ] if* ;
 | 
			
		||||
 | 
			
		||||
: (compute-dfs) ( n bb -- n )
 | 
			
		||||
    [ 1 + ] dip
 | 
			
		||||
    [ dupd preorder get set-at ]
 | 
			
		||||
    [ dom-children [ (compute-dfs) ] each ]
 | 
			
		||||
    [ dupd maxpreorder get set-at ]
 | 
			
		||||
    tri ;
 | 
			
		||||
 | 
			
		||||
PRIVATE>
 | 
			
		||||
 | 
			
		||||
: compute-dfs ( cfg -- )
 | 
			
		||||
    H{ } clone preorder set
 | 
			
		||||
    H{ } clone maxpreorder set
 | 
			
		||||
    [ 0 ] dip entry>> (compute-dfs) drop ;
 | 
			
		||||
 | 
			
		||||
: dominates? ( bb1 bb2 -- ? )
 | 
			
		||||
    ! Requires DFS to be computed
 | 
			
		||||
    swap [ pre-of ] [ [ pre-of ] [ maxpre-of ] bi ] bi* between? ;
 | 
			
		||||
		Loading…
	
		Reference in New Issue