1
0
mirror of https://github.com/golang/go synced 2024-11-24 08:50:14 -07:00

cmd/internal/obj: clean up brloop

Add docs.
Reduce indentation.

Passes toolstash-check -all.

Change-Id: I968d1af25989886ae9945052e05e211a107dde9c
Reviewed-on: https://go-review.googlesource.com/38443
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Josh Bleecher Snyder 2017-03-21 22:06:39 -07:00
parent 4c8023bfed
commit 2f2cd557a6

View File

@ -32,21 +32,21 @@ package obj
// Code and data passes.
func brloop(ctxt *Link, p *Prog) *Prog {
var q *Prog
// brloop returns the ultimate destination of the series of unconditional jumps beginning at p.
// In the case of an infinite loop, brloop returns nil.
func brloop(p *Prog) *Prog {
c := 0
for q = p; q != nil; q = q.Pcond {
for q := p; q != nil; q = q.Pcond {
if q.As != AJMP || q.Pcond == nil {
break
return q
}
c++
if c >= 5000 {
// infinite loop
return nil
}
}
return q
panic("unreachable")
}
// checkaddr checks that a has an expected encoding, especially TYPE_CONST vs TYPE_ADDR.
@ -169,16 +169,18 @@ func linkpatch(ctxt *Link, sym *LSym) {
p.Pcond = q
}
if ctxt.Flag_optimize {
if !ctxt.Flag_optimize {
return
}
// Collapse series of jumps to jumps.
for p := sym.Text; p != nil; p = p.Link {
if p.Pcond != nil {
p.Pcond = brloop(ctxt, p.Pcond)
if p.Pcond != nil {
if p.To.Type == TYPE_BRANCH {
if p.Pcond == nil {
continue
}
p.Pcond = brloop(p.Pcond)
if p.Pcond != nil && p.To.Type == TYPE_BRANCH {
p.To.Offset = p.Pcond.Pc
}
}
}
}
}
}