Commit 2f2cd557 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: 's avatarCherry Zhang <cherryyz@google.com>
parent 4c8023bf
......@@ -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 {
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 {
p.To.Offset = p.Pcond.Pc
}
}
}
if !ctxt.Flag_optimize {
return
}
// Collapse series of jumps to jumps.
for p := sym.Text; p != nil; p = p.Link {
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
}
}
}
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