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:
parent
4c8023bfed
commit
2f2cd557a6
@ -32,21 +32,21 @@ package obj
|
|||||||
|
|
||||||
// Code and data passes.
|
// Code and data passes.
|
||||||
|
|
||||||
func brloop(ctxt *Link, p *Prog) *Prog {
|
// brloop returns the ultimate destination of the series of unconditional jumps beginning at p.
|
||||||
var q *Prog
|
// In the case of an infinite loop, brloop returns nil.
|
||||||
|
func brloop(p *Prog) *Prog {
|
||||||
c := 0
|
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 {
|
if q.As != AJMP || q.Pcond == nil {
|
||||||
break
|
return q
|
||||||
}
|
}
|
||||||
c++
|
c++
|
||||||
if c >= 5000 {
|
if c >= 5000 {
|
||||||
|
// infinite loop
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
panic("unreachable")
|
||||||
return q
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkaddr checks that a has an expected encoding, especially TYPE_CONST vs TYPE_ADDR.
|
// 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
|
p.Pcond = q
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt.Flag_optimize {
|
if !ctxt.Flag_optimize {
|
||||||
for p := sym.Text; p != nil; p = p.Link {
|
return
|
||||||
if p.Pcond != nil {
|
}
|
||||||
p.Pcond = brloop(ctxt, p.Pcond)
|
|
||||||
if p.Pcond != nil {
|
// Collapse series of jumps to jumps.
|
||||||
if p.To.Type == TYPE_BRANCH {
|
for p := sym.Text; p != nil; p = p.Link {
|
||||||
p.To.Offset = p.Pcond.Pc
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user