Debian Codegraph @

internal/engine/wazevo/ssa/basic_block_sort.go

raw
1 package ssa
2
3 import (
4 "slices"
5 )
6
7 func sortBlocks(blocks []*basicBlock) {
8 slices.SortFunc(blocks, func(i, j *basicBlock) int {
9 jIsReturn := j.ReturnBlock()
10 iIsReturn := i.ReturnBlock()
11 if iIsReturn && jIsReturn {
12 return 0
13 }
14 if jIsReturn {
15 return 1
16 }
17 if iIsReturn {
18 return -1
19 }
20 iRoot, jRoot := i.rootInstr, j.rootInstr
21 if iRoot == nil && jRoot == nil { // For testing.
22 return 0
23 }
24 if jRoot == nil {
25 return 1
26 }
27 if iRoot == nil {
28 return -1
29 }
30 return i.rootInstr.id - j.rootInstr.id
31 })
32 }