]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify postorder
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 17 May 2019 18:48:37 +0000 (11:48 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 29 Aug 2019 19:54:46 +0000 (19:54 +0000)
Use a bool instead of markKind;
it doesn't save space, but the semantics are more obvious.
Move type markKind closer to its only remaining use.

Change-Id: I9945a7baaeb764295a2709f83120ce3a82fa3beb
Reviewed-on: https://go-review.googlesource.com/c/go/+/177880
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/dom.go
src/cmd/compile/internal/ssa/loopreschedchecks.go

index 3d186fc56263518e2b93ec0d167a382ced20d12f..f31e7df72432c7eaafb6e6d8f1eb98415ab31e34 100644 (file)
@@ -4,16 +4,6 @@
 
 package ssa
 
-// mark values
-type markKind uint8
-
-const (
-       notFound    markKind = 0 // block has not been discovered yet
-       notExplored markKind = 1 // discovered and in queue, outedges not processed yet
-       explored    markKind = 2 // discovered and in queue, outedges processed
-       done        markKind = 3 // all done, in output ordering
-)
-
 // This file contains code to compute the dominator tree
 // of a control-flow graph.
 
@@ -31,7 +21,7 @@ type blockAndIndex struct {
 // postorderWithNumbering provides a DFS postordering.
 // This seems to make loop-finding more robust.
 func postorderWithNumbering(f *Func, ponums []int32) []*Block {
-       mark := make([]markKind, f.NumBlocks())
+       seen := make([]bool, f.NumBlocks())
 
        // result ordering
        order := make([]*Block, 0, len(f.Blocks))
@@ -41,26 +31,25 @@ func postorderWithNumbering(f *Func, ponums []int32) []*Block {
        // enough to cover almost every postorderWithNumbering call.
        s := make([]blockAndIndex, 0, 32)
        s = append(s, blockAndIndex{b: f.Entry})
-       mark[f.Entry.ID] = explored
+       seen[f.Entry.ID] = true
        for len(s) > 0 {
                tos := len(s) - 1
                x := s[tos]
                b := x.b
-               i := x.index
-               if i < len(b.Succs) {
+               if i := x.index; i < len(b.Succs) {
                        s[tos].index++
                        bb := b.Succs[i].Block()
-                       if mark[bb.ID] == notFound {
-                               mark[bb.ID] = explored
+                       if !seen[bb.ID] {
+                               seen[bb.ID] = true
                                s = append(s, blockAndIndex{b: bb})
                        }
-               } else {
-                       s = s[:tos]
-                       if len(ponums) > 0 {
-                               ponums[b.ID] = int32(len(order))
-                       }
-                       order = append(order, b)
+                       continue
+               }
+               s = s[:tos]
+               if ponums != nil {
+                       ponums[b.ID] = int32(len(order))
                }
+               order = append(order, b)
        }
        return order
 }
index 30ba1e9d660c944d8f176f8141445b8c913cded7..1932f9d23a7c06643fa212f3f7418f7b955d280e 100644 (file)
@@ -452,6 +452,16 @@ func findLastMems(f *Func) []*Value {
        return lastMems
 }
 
+// mark values
+type markKind uint8
+
+const (
+       notFound    markKind = iota // block has not been discovered yet
+       notExplored                 // discovered and in queue, outedges not processed yet
+       explored                    // discovered and in queue, outedges processed
+       done                        // all done, in output ordering
+)
+
 type backedgesState struct {
        b *Block
        i int