Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
havlak5
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Feb 3, 2017
1 parent 245d899 commit 2d41d6d
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions havlak/havlak.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ func appendUnique(a []int, x int) []int {
return append(a, x)
}


var cache struct {
size int
nonBackPreds [][]int
backPreds [][]int
number []int
header []int
types []int
last []int
nodes []*UnionFindNode
}

// FindLoops
//
// Find loops and build loop forest using Havlak's algorithm, which
Expand All @@ -273,19 +285,35 @@ func FindLoops(cfgraph *CFG, lsgraph *LSG) {
}

size := cfgraph.NumNodes()

if cache.size < size {
cache.size = size
cache.nonBackPreds = make([][]int, size)
cache.backPreds = make([][]int, size)
cache.number = make([]int, size)
cache.header = make([]int, size)
cache.types = make([]int, size)
cache.last = make([]int, size)
cache.nodes = make([]*UnionFindNode, size)
for i := range cache.nodes {
cache.nodes[i] = new(UnionFindNode)
}
}

nonBackPreds := make([][]int, size)
backPreds := make([][]int, size)

number := make([]int, size)
header := make([]int, size, size)
types := make([]int, size, size)
last := make([]int, size, size)
nodes := make([]*UnionFindNode, size, size)

for i := 0; i < size; i++ {
nodes[i] = new(UnionFindNode)
nonBackPreds := cache.nonBackPreds[:size]
for i := range nonBackPreds {
nonBackPreds[i] = nonBackPreds[i][:0]
}
backPreds := cache.backPreds[:size]
for i := range nonBackPreds {
backPreds[i] = backPreds[i][:0]
}
number := cache.number[:size]
header := cache.header[:size]
types := cache.types[:size]
last := cache.last[:size]
nodes := cache.nodes[:size]


// Step a:
// - initialize all nodes as unvisited.
Expand Down

0 comments on commit 2d41d6d

Please sign in to comment.