@@ -396,11 +396,12 @@ export class Graph {
396396 let newRoot = root ;
397397 if ( root . attributes . includes ( "osr" ) ) {
398398 assert ( root . succs . length > 0 ) ;
399- osrBlocks . push ( root ) ;
400- newRoot = root . succs [ 0 ] ;
401399
402400 // Walk up the graph by repeatedly choosing the first non-OSR, non-
403401 // backedge predecessor.
402+
403+ const postOSR = root . succs [ 0 ] ;
404+ newRoot = postOSR ;
404405 for ( let j = 0 ; ; j ++ ) {
405406 if ( j >= 10_000_000 ) {
406407 throw new Error ( "likely infinite loop" ) ;
@@ -412,6 +413,14 @@ export class Graph {
412413 }
413414 newRoot = validPredecessors [ 0 ] ;
414415 }
416+
417+ // Did we actually end up at a new block? If so, track it, otherwise
418+ // just treat the OSR block as a normal root.
419+ if ( newRoot !== postOSR ) {
420+ osrBlocks . push ( root ) ;
421+ } else {
422+ newRoot = root ;
423+ }
415424 }
416425
417426 // Track and deduplicate
@@ -520,6 +529,7 @@ export class Graph {
520529 if ( ! to . srcNodes . includes ( from ) ) {
521530 to . srcNodes . push ( from ) ;
522531 }
532+ log . log ( "connected" , from . id , "to" , to . id ) ;
523533 }
524534
525535 let blocksByLayer : Block [ ] [ ] ;
@@ -591,6 +601,7 @@ export class Graph {
591601 layoutNodesByLayer [ layer ] . push ( newDummy ) ;
592602 dummiesByDest . set ( edge . dstBlock . id , newDummy ) ;
593603 dummy = newDummy ;
604+ log . log ( "Created dummy" , dummy . id , "on the way to block" , edge . dstBlock . id ) ;
594605 }
595606
596607 // Update the active edge with the latest dummy.
@@ -700,6 +711,7 @@ export class Graph {
700711 // we always generate dummy nodes at each level for active loops, but if a
701712 // loop doesn't branch back at the end, several dummy nodes will be left
702713 // orphaned.
714+ log . log ( "Pruning backedge dummies" ) ;
703715 {
704716 const orphanRoots : DummyNode [ ] = [ ] ;
705717 for ( const dummy of backedgeDummies ( layoutNodesByLayer ) ) {
@@ -728,6 +740,7 @@ export class Graph {
728740 }
729741
730742 // Mark leftmost and rightmost dummies.
743+ log . log ( "Marking leftmost and rightmost dummies" ) ;
731744 for ( const nodes of layoutNodesByLayer ) {
732745 for ( let i = 0 ; i < nodes . length ; i ++ ) {
733746 if ( nodes [ i ] . block === null ) {
@@ -746,6 +759,7 @@ export class Graph {
746759 }
747760
748761 // Ensure that our nodes are all ok
762+ log . log ( "Verifying integrity of all nodes" ) ;
749763 for ( const layer of layoutNodesByLayer ) {
750764 for ( const node of layer ) {
751765 if ( node . block ) {
0 commit comments