Commit e360f7c4 authored by Keith Randall's avatar Keith Randall

cmd/compile: keep JMPs around with -N

When -N, make sure we don't drop every instruction from
a block, even ones which would otherwise be empty.
Helps keep line numbers around for debugging, particularly
for break and continue statements (which often compile
down to nothing).

Fixes #14379

Change-Id: I33722c4f0dcd502f146fa48af262ba3a477c959a
Reviewed-on: https://go-review.googlesource.com/19854
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMinux Ma <minux@golang.org>
parent c4cb365e
......@@ -236,6 +236,7 @@ func Main() {
}
Ctxt.Flag_shared = int32(flag_shared)
Ctxt.Flag_dynlink = flag_dynlink
Ctxt.Flag_optimize = Debug['N'] == 0
Ctxt.Debugasm = int32(Debug['S'])
Ctxt.Debugvlog = int32(Debug['v'])
......
......@@ -138,15 +138,16 @@ func fixjmp(firstp *obj.Prog) {
fmt.Printf("%v\n", p)
}
if p.As != obj.ACALL && p.To.Type == obj.TYPE_BRANCH && p.To.Val.(*obj.Prog) != nil && p.To.Val.(*obj.Prog).As == obj.AJMP {
p.To.Val = chasejmp(p.To.Val.(*obj.Prog), &jmploop)
if Debug['R'] != 0 && Debug['v'] != 0 {
fmt.Printf("->%v\n", p)
if Debug['N'] == 0 {
p.To.Val = chasejmp(p.To.Val.(*obj.Prog), &jmploop)
if Debug['R'] != 0 && Debug['v'] != 0 {
fmt.Printf("->%v\n", p)
}
}
}
p.Opt = dead
}
if Debug['R'] != 0 && Debug['v'] != 0 {
fmt.Printf("\n")
}
......@@ -186,7 +187,7 @@ func fixjmp(firstp *obj.Prog) {
// pass 4: elide JMP to next instruction.
// only safe if there are no jumps to JMPs anymore.
if jmploop == 0 {
if jmploop == 0 && Debug['N'] == 0 {
var last *obj.Prog
for p := firstp; p != nil; p = p.Link {
if p.As == obj.AJMP && p.To.Type == obj.TYPE_BRANCH && p.To.Val == p.Link {
......
......@@ -572,6 +572,7 @@ type Link struct {
Debugpcln int32
Flag_shared int32
Flag_dynlink bool
Flag_optimize bool
Bso *Biobuf
Pathname string
Windows int32
......
......@@ -295,7 +295,9 @@ func Flushplist(ctxt *Link) {
for s := text; s != nil; s = s.Next {
mkfwd(s)
linkpatch(ctxt, s)
ctxt.Arch.Follow(ctxt, s)
if ctxt.Flag_optimize {
ctxt.Arch.Follow(ctxt, s)
}
ctxt.Arch.Preprocess(ctxt, s)
ctxt.Arch.Assemble(ctxt, s)
fieldtrack(ctxt, s)
......
......@@ -202,13 +202,15 @@ func linkpatch(ctxt *Link, sym *LSym) {
p.Pcond = q
}
for p := sym.Text; p != nil; p = p.Link {
p.Mark = 0 /* initialization for follow */
if p.Pcond != nil {
p.Pcond = brloop(ctxt, p.Pcond)
if ctxt.Flag_optimize {
for p := sym.Text; p != nil; p = p.Link {
p.Mark = 0 /* initialization for follow */
if p.Pcond != nil {
if p.To.Type == TYPE_BRANCH {
p.To.Offset = p.Pcond.Pc
p.Pcond = brloop(ctxt, p.Pcond)
if p.Pcond != nil {
if p.To.Type == TYPE_BRANCH {
p.To.Offset = p.Pcond.Pc
}
}
}
}
......
......@@ -110,6 +110,7 @@ func Linknew(arch *LinkArch) *Link {
ctxt.Goarm = Getgoarm()
}
ctxt.Flag_optimize = true
return ctxt
}
......
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