github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/ssa/basic_block_sort_old.go (about)

     1  //go:build !go1.21
     2  
     3  // TODO: delete after the floor Go version is 1.21
     4  
     5  package ssa
     6  
     7  import "sort"
     8  
     9  func sortBlocks(blocks []*basicBlock) {
    10  	sort.SliceStable(blocks, func(i, j int) bool {
    11  		iBlk, jBlk := blocks[i], blocks[j]
    12  		if jBlk.ReturnBlock() {
    13  			return true
    14  		}
    15  		if iBlk.ReturnBlock() {
    16  			return false
    17  		}
    18  		iRoot, jRoot := iBlk.rootInstr, jBlk.rootInstr
    19  		if iRoot == nil || jRoot == nil { // For testing.
    20  			return true
    21  		}
    22  		return iBlk.rootInstr.id < jBlk.rootInstr.id
    23  	})
    24  }