]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make node.Likely a flag
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 25 Apr 2017 15:46:00 +0000 (08:46 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 26 Apr 2017 00:02:24 +0000 (00:02 +0000)
node.Likely may once have held -1/0/+1,
but it is now only 0/1.

With improved SSA heuristics,
it may someday go away entirely.

Change-Id: I6451d17fd7fb47e67fea4d39df302b6db00ea57b
Reviewed-on: https://go-review.googlesource.com/41760
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/syntax.go

index 7dee46a17c521793b27093802de11c2b4852b5b8..bbdf19d1109d79c20438f63f102c7f24884b9b0a 100644 (file)
@@ -91,7 +91,7 @@ func fninit(n []*Node) {
        // (3)
        a := nod(OIF, nil, nil)
        a.Left = nod(OGT, gatevar, nodintconst(1))
-       a.Likely = 1
+       a.SetLikely(true)
        r = append(r, a)
        // (3a)
        a.Nbody.Set1(nod(ORETURN, nil, nil))
@@ -101,7 +101,7 @@ func fninit(n []*Node) {
        b.Left = nod(OEQ, gatevar, nodintconst(1))
        // this actually isn't likely, but code layout is better
        // like this: no JMP needed after the call.
-       b.Likely = 1
+       b.SetLikely(true)
        r = append(r, b)
        // (4a)
        b.Nbody.Set1(nod(OCALL, syslook("throwinit"), nil))
index fe2756d25b339a46c6fa7a40287b42c81f3a464b..0d16ba715ceb06678ebeaf2a6463a2a8e935c894 100644 (file)
@@ -733,11 +733,15 @@ func (s *state) stmt(n *Node) {
                bThen := s.f.NewBlock(ssa.BlockPlain)
                bEnd := s.f.NewBlock(ssa.BlockPlain)
                var bElse *ssa.Block
+               var likely int8
+               if n.Likely() {
+                       likely = 1
+               }
                if n.Rlist.Len() != 0 {
                        bElse = s.f.NewBlock(ssa.BlockPlain)
-                       s.condBranch(n.Left, bThen, bElse, n.Likely)
+                       s.condBranch(n.Left, bThen, bElse, likely)
                } else {
-                       s.condBranch(n.Left, bThen, bEnd, n.Likely)
+                       s.condBranch(n.Left, bThen, bEnd, likely)
                }
 
                s.startBlock(bThen)
index 5c3432cad171728a6abe304eb04bb4e5ad7b75ef..bcc8df0af69a065bbd3aca7a73628e2fdfece183 100644 (file)
@@ -62,7 +62,6 @@ type Node struct {
        Walkdef   uint8       // tracks state during typecheckdef; 2 == loop detected
        Typecheck uint8       // tracks state during typechecking; 2 == loop detected
        Initorder uint8
-       Likely    int8 // likeliness of if statement
        hasVal    int8 // +1 for Val, -1 for Opt, 0 for not yet set
 }
 
@@ -93,6 +92,7 @@ const (
        nodeAddable  // addressable
        nodeUsed     // for variable/label declared and not used error
        nodeHasCall  // expression contains a function call
+       nodeLikely   // if statement condition likely
 )
 
 func (n *Node) HasBreak() bool              { return n.flags&nodeHasBreak != 0 }
@@ -112,6 +112,7 @@ func (n *Node) Bounded() bool               { return n.flags&nodeBounded != 0 }
 func (n *Node) Addable() bool               { return n.flags&nodeAddable != 0 }
 func (n *Node) Used() bool                  { return n.flags&nodeUsed != 0 }
 func (n *Node) HasCall() bool               { return n.flags&nodeHasCall != 0 }
+func (n *Node) Likely() bool                { return n.flags&nodeLikely != 0 }
 
 func (n *Node) SetHasBreak(b bool)              { n.flags.set(nodeHasBreak, b) }
 func (n *Node) SetIsClosureVar(b bool)          { n.flags.set(nodeIsClosureVar, b) }
@@ -130,6 +131,7 @@ func (n *Node) SetBounded(b bool)               { n.flags.set(nodeBounded, b) }
 func (n *Node) SetAddable(b bool)               { n.flags.set(nodeAddable, b) }
 func (n *Node) SetUsed(b bool)                  { n.flags.set(nodeUsed, b) }
 func (n *Node) SetHasCall(b bool)               { n.flags.set(nodeHasCall, b) }
+func (n *Node) SetLikely(b bool)                { n.flags.set(nodeLikely, b) }
 
 // Val returns the Val for the node.
 func (n *Node) Val() Val {