diff options
author | Keith Randall <khr@golang.org> | 2020-07-17 12:12:59 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2020-08-27 22:35:45 +0000 |
commit | 8247da36621986a282c96b2abc236bbda2fdef41 (patch) | |
tree | 2d475415cda6cd9f8532bb6ad45664ac677a5099 /src/cmd/internal/obj/pass.go | |
parent | 5c2c6d3fbf4f0a1299b5e41463847d242eae19ca (diff) | |
download | go-git-8247da36621986a282c96b2abc236bbda2fdef41.tar.gz |
cmd/compile,cmd/asm: simplify recording of branch targets
We currently use two fields to store the targets of branches.
Some phases use p.To.Val, some use p.Pcond. Rewrite so that
every branch instruction uses p.To.Val.
p.From.Val is also used in rare instances.
Introduce a Pool link for use by arm/arm64, instead of
repurposing Pcond.
This is a cleanup CL in preparation for some stack frame CLs.
Change-Id: I9055bf0a1d986aff421e47951a1dedc301c846f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/243318
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj/pass.go')
-rw-r--r-- | src/cmd/internal/obj/pass.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/cmd/internal/obj/pass.go b/src/cmd/internal/obj/pass.go index 4f156d969b..09d520b4e9 100644 --- a/src/cmd/internal/obj/pass.go +++ b/src/cmd/internal/obj/pass.go @@ -36,8 +36,8 @@ package obj // 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 { - if q.As != AJMP || q.Pcond == nil { + for q := p; q != nil; q = q.To.Target() { + if q.As != AJMP || q.To.Target() == nil { return q } c++ @@ -132,8 +132,6 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) { continue } if p.To.Val != nil { - // TODO: Remove To.Val.(*Prog) in favor of p->pcond. - p.Pcond = p.To.Val.(*Prog) continue } @@ -158,8 +156,7 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) { p.To.Type = TYPE_NONE } - p.To.Val = q - p.Pcond = q + p.To.SetTarget(q) } if !ctxt.Flag_optimize { @@ -168,12 +165,12 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) { // Collapse series of jumps to jumps. for p := sym.Func.Text; p != nil; p = p.Link { - if p.Pcond == nil { + if p.To.Target() == nil { continue } - p.Pcond = brloop(p.Pcond) - if p.Pcond != nil && p.To.Type == TYPE_BRANCH { - p.To.Offset = p.Pcond.Pc + p.To.SetTarget(brloop(p.To.Target())) + if p.To.Target() != nil && p.To.Type == TYPE_BRANCH { + p.To.Offset = p.To.Target().Pc } } } |