Commit 7f0757b3 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: make node.Likely a flag

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 6049b174
...@@ -91,7 +91,7 @@ func fninit(n []*Node) { ...@@ -91,7 +91,7 @@ func fninit(n []*Node) {
// (3) // (3)
a := nod(OIF, nil, nil) a := nod(OIF, nil, nil)
a.Left = nod(OGT, gatevar, nodintconst(1)) a.Left = nod(OGT, gatevar, nodintconst(1))
a.Likely = 1 a.SetLikely(true)
r = append(r, a) r = append(r, a)
// (3a) // (3a)
a.Nbody.Set1(nod(ORETURN, nil, nil)) a.Nbody.Set1(nod(ORETURN, nil, nil))
...@@ -101,7 +101,7 @@ func fninit(n []*Node) { ...@@ -101,7 +101,7 @@ func fninit(n []*Node) {
b.Left = nod(OEQ, gatevar, nodintconst(1)) b.Left = nod(OEQ, gatevar, nodintconst(1))
// this actually isn't likely, but code layout is better // this actually isn't likely, but code layout is better
// like this: no JMP needed after the call. // like this: no JMP needed after the call.
b.Likely = 1 b.SetLikely(true)
r = append(r, b) r = append(r, b)
// (4a) // (4a)
b.Nbody.Set1(nod(OCALL, syslook("throwinit"), nil)) b.Nbody.Set1(nod(OCALL, syslook("throwinit"), nil))
......
...@@ -733,11 +733,15 @@ func (s *state) stmt(n *Node) { ...@@ -733,11 +733,15 @@ func (s *state) stmt(n *Node) {
bThen := s.f.NewBlock(ssa.BlockPlain) bThen := s.f.NewBlock(ssa.BlockPlain)
bEnd := s.f.NewBlock(ssa.BlockPlain) bEnd := s.f.NewBlock(ssa.BlockPlain)
var bElse *ssa.Block var bElse *ssa.Block
var likely int8
if n.Likely() {
likely = 1
}
if n.Rlist.Len() != 0 { if n.Rlist.Len() != 0 {
bElse = s.f.NewBlock(ssa.BlockPlain) bElse = s.f.NewBlock(ssa.BlockPlain)
s.condBranch(n.Left, bThen, bElse, n.Likely) s.condBranch(n.Left, bThen, bElse, likely)
} else { } else {
s.condBranch(n.Left, bThen, bEnd, n.Likely) s.condBranch(n.Left, bThen, bEnd, likely)
} }
s.startBlock(bThen) s.startBlock(bThen)
......
...@@ -62,7 +62,6 @@ type Node struct { ...@@ -62,7 +62,6 @@ type Node struct {
Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected
Typecheck uint8 // tracks state during typechecking; 2 == loop detected Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Initorder uint8 Initorder uint8
Likely int8 // likeliness of if statement
hasVal int8 // +1 for Val, -1 for Opt, 0 for not yet set hasVal int8 // +1 for Val, -1 for Opt, 0 for not yet set
} }
...@@ -93,6 +92,7 @@ const ( ...@@ -93,6 +92,7 @@ const (
nodeAddable // addressable nodeAddable // addressable
nodeUsed // for variable/label declared and not used error nodeUsed // for variable/label declared and not used error
nodeHasCall // expression contains a function call nodeHasCall // expression contains a function call
nodeLikely // if statement condition likely
) )
func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 } func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 }
...@@ -112,6 +112,7 @@ func (n *Node) Bounded() bool { return n.flags&nodeBounded != 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) Addable() bool { return n.flags&nodeAddable != 0 }
func (n *Node) Used() bool { return n.flags&nodeUsed != 0 } func (n *Node) Used() bool { return n.flags&nodeUsed != 0 }
func (n *Node) HasCall() bool { return n.flags&nodeHasCall != 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) SetHasBreak(b bool) { n.flags.set(nodeHasBreak, b) }
func (n *Node) SetIsClosureVar(b bool) { n.flags.set(nodeIsClosureVar, 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) } ...@@ -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) SetAddable(b bool) { n.flags.set(nodeAddable, b) }
func (n *Node) SetUsed(b bool) { n.flags.set(nodeUsed, 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) 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. // Val returns the Val for the node.
func (n *Node) Val() Val { func (n *Node) Val() Val {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment