Commit 683f5d7b authored by Keith Randall's avatar Keith Randall

[dev.ssa] cmd/compile/internal/ssa: put new values for block rewrites in rewritten block

Don't put them in the control value's block.
That may be many blocks up the dominator tree.

Change-Id: Iab3ea36a890ffe0e355dadec7aeb676901c4f070
Reviewed-on: https://go-review.googlesource.com/13134Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent b8efee0d
...@@ -104,6 +104,7 @@ func genRules(arch arch) { ...@@ -104,6 +104,7 @@ func genRules(arch arch) {
fmt.Fprintln(w, "// generated with: cd gen; go run *.go") fmt.Fprintln(w, "// generated with: cd gen; go run *.go")
fmt.Fprintln(w, "package ssa") fmt.Fprintln(w, "package ssa")
fmt.Fprintf(w, "func rewriteValue%s(v *Value, config *Config) bool {\n", arch.name) fmt.Fprintf(w, "func rewriteValue%s(v *Value, config *Config) bool {\n", arch.name)
fmt.Fprintln(w, "b := v.Block")
// generate code for each rule // generate code for each rule
fmt.Fprintf(w, "switch v.Op {\n") fmt.Fprintf(w, "switch v.Op {\n")
...@@ -238,7 +239,7 @@ func genRules(arch arch) { ...@@ -238,7 +239,7 @@ func genRules(arch arch) {
// Modify predecessor lists for no-longer-reachable blocks // Modify predecessor lists for no-longer-reachable blocks
for succ := range m { for succ := range m {
fmt.Fprintf(w, "v.Block.Func.removePredecessor(b, %s)\n", succ) fmt.Fprintf(w, "b.Func.removePredecessor(b, %s)\n", succ)
} }
fmt.Fprintf(w, "b.Kind = %s\n", blockName(t[0], arch)) fmt.Fprintf(w, "b.Kind = %s\n", blockName(t[0], arch))
...@@ -397,7 +398,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool) str ...@@ -397,7 +398,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool) str
} else { } else {
v = fmt.Sprintf("v%d", *alloc) v = fmt.Sprintf("v%d", *alloc)
*alloc++ *alloc++
fmt.Fprintf(w, "%s := v.Block.NewValue0(v.Line, %s, TypeInvalid)\n", v, opName(s[0], arch)) fmt.Fprintf(w, "%s := b.NewValue0(v.Line, %s, TypeInvalid)\n", v, opName(s[0], arch))
} }
for _, a := range s[1:] { for _, a := range s[1:] {
if a[0] == '<' { if a[0] == '<' {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
package ssa package ssa
func rewriteValuegeneric(v *Value, config *Config) bool { func rewriteValuegeneric(v *Value, config *Config) bool {
b := v.Block
switch v.Op { switch v.Op {
case OpAdd64: case OpAdd64:
// match: (Add64 (Const64 [c]) (Const64 [d])) // match: (Add64 (Const64 [c]) (Const64 [d]))
...@@ -65,7 +66,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -65,7 +66,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpPtrIndex, TypeInvalid) v0 := b.NewValue0(v.Line, OpPtrIndex, TypeInvalid)
v0.Type = v.Type.PtrTo() v0.Type = v.Type.PtrTo()
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(idx) v0.AddArg(idx)
...@@ -162,14 +163,14 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -162,14 +163,14 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpAddr, TypeInvalid) v0 := b.NewValue0(v.Line, OpAddr, TypeInvalid)
v0.Type = config.Frontend().TypeBytePtr() v0.Type = config.Frontend().TypeBytePtr()
v0.Aux = config.fe.StringData(s.(string)) v0.Aux = config.fe.StringData(s.(string))
v1 := v.Block.NewValue0(v.Line, OpSB, TypeInvalid) v1 := b.NewValue0(v.Line, OpSB, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v0.AddArg(v1) v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v2 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v2.Type = config.Frontend().TypeUintptr() v2.Type = config.Frontend().TypeUintptr()
v2.AuxInt = int64(len(s.(string))) v2.AuxInt = int64(len(s.(string)))
v.AddArg(v2) v.AddArg(v2)
...@@ -291,12 +292,12 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -291,12 +292,12 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpLoad, TypeInvalid) v0 := b.NewValue0(v.Line, OpLoad, TypeInvalid)
v0.Type = config.Frontend().TypeUintptr() v0.Type = config.Frontend().TypeUintptr()
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(mem) v0.AddArg(mem)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v1 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AuxInt = 0 v1.AuxInt = 0
v.AddArg(v1) v.AddArg(v1)
...@@ -343,14 +344,14 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -343,14 +344,14 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpLoad, TypeInvalid) v0 := b.NewValue0(v.Line, OpLoad, TypeInvalid)
v0.Type = config.Frontend().TypeBytePtr() v0.Type = config.Frontend().TypeBytePtr()
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(mem) v0.AddArg(mem)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpLoad, TypeInvalid) v1 := b.NewValue0(v.Line, OpLoad, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v2 := v.Block.NewValue0(v.Line, OpOffPtr, TypeInvalid) v2 := b.NewValue0(v.Line, OpOffPtr, TypeInvalid)
v2.Type = config.Frontend().TypeBytePtr() v2.Type = config.Frontend().TypeBytePtr()
v2.AuxInt = config.PtrSize v2.AuxInt = config.PtrSize
v2.AddArg(ptr) v2.AddArg(ptr)
...@@ -521,12 +522,12 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -521,12 +522,12 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpLoad, TypeInvalid) v0 := b.NewValue0(v.Line, OpLoad, TypeInvalid)
v0.Type = config.Frontend().TypeUintptr() v0.Type = config.Frontend().TypeUintptr()
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(mem) v0.AddArg(mem)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v1 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AuxInt = 0 v1.AuxInt = 0
v.AddArg(v1) v.AddArg(v1)
...@@ -548,10 +549,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -548,10 +549,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(ptr) v.AddArg(ptr)
v0 := v.Block.NewValue0(v.Line, OpMulPtr, TypeInvalid) v0 := b.NewValue0(v.Line, OpMulPtr, TypeInvalid)
v0.Type = config.Frontend().TypeUintptr() v0.Type = config.Frontend().TypeUintptr()
v0.AddArg(idx) v0.AddArg(idx)
v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v1 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AuxInt = t.Elem().Size() v1.AuxInt = t.Elem().Size()
v0.AddArg(v1) v0.AddArg(v1)
...@@ -575,10 +576,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -575,10 +576,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid) v0 := b.NewValue0(v.Line, OpAddPtr, TypeInvalid)
v0.Type = ptr.Type v0.Type = ptr.Type
v0.AddArg(ptr) v0.AddArg(ptr)
v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v1 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AuxInt = config.PtrSize * 2 v1.AuxInt = config.PtrSize * 2
v0.AddArg(v1) v0.AddArg(v1)
...@@ -603,10 +604,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -603,10 +604,10 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid) v0 := b.NewValue0(v.Line, OpAddPtr, TypeInvalid)
v0.Type = ptr.Type v0.Type = ptr.Type
v0.AddArg(ptr) v0.AddArg(ptr)
v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid) v1 := b.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AuxInt = config.PtrSize v1.AuxInt = config.PtrSize
v0.AddArg(v1) v0.AddArg(v1)
...@@ -683,19 +684,19 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -683,19 +684,19 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpOffPtr, TypeInvalid) v0 := b.NewValue0(v.Line, OpOffPtr, TypeInvalid)
v0.Type = config.Frontend().TypeBytePtr() v0.Type = config.Frontend().TypeBytePtr()
v0.AuxInt = config.PtrSize v0.AuxInt = config.PtrSize
v0.AddArg(dst) v0.AddArg(dst)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpStringLen, TypeInvalid) v1 := b.NewValue0(v.Line, OpStringLen, TypeInvalid)
v1.Type = config.Frontend().TypeUintptr() v1.Type = config.Frontend().TypeUintptr()
v1.AddArg(str) v1.AddArg(str)
v.AddArg(v1) v.AddArg(v1)
v2 := v.Block.NewValue0(v.Line, OpStore, TypeInvalid) v2 := b.NewValue0(v.Line, OpStore, TypeInvalid)
v2.Type = TypeMem v2.Type = TypeMem
v2.AddArg(dst) v2.AddArg(dst)
v3 := v.Block.NewValue0(v.Line, OpStringPtr, TypeInvalid) v3 := b.NewValue0(v.Line, OpStringPtr, TypeInvalid)
v3.Type = config.Frontend().TypeBytePtr() v3.Type = config.Frontend().TypeBytePtr()
v3.AddArg(str) v3.AddArg(str)
v2.AddArg(v3) v2.AddArg(v3)
...@@ -759,7 +760,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -759,7 +760,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v0 := v.Block.NewValue0(v.Line, OpOffPtr, TypeInvalid) v0 := b.NewValue0(v.Line, OpOffPtr, TypeInvalid)
v0.Type = v.Type.PtrTo() v0.Type = v.Type.PtrTo()
v0.AuxInt = idx v0.AuxInt = idx
v0.AddArg(ptr) v0.AddArg(ptr)
...@@ -809,7 +810,7 @@ func rewriteBlockgeneric(b *Block) bool { ...@@ -809,7 +810,7 @@ func rewriteBlockgeneric(b *Block) bool {
if !(c.(bool)) { if !(c.(bool)) {
goto end9ff0273f9b1657f4afc287562ca889f0 goto end9ff0273f9b1657f4afc287562ca889f0
} }
v.Block.Func.removePredecessor(b, no) b.Func.removePredecessor(b, no)
b.Kind = BlockPlain b.Kind = BlockPlain
b.Control = nil b.Control = nil
b.Succs = b.Succs[:1] b.Succs = b.Succs[:1]
...@@ -833,7 +834,7 @@ func rewriteBlockgeneric(b *Block) bool { ...@@ -833,7 +834,7 @@ func rewriteBlockgeneric(b *Block) bool {
if !(!c.(bool)) { if !(!c.(bool)) {
goto endf401a4553c3c7c6bed64801da7bba076 goto endf401a4553c3c7c6bed64801da7bba076
} }
v.Block.Func.removePredecessor(b, yes) b.Func.removePredecessor(b, yes)
b.Kind = BlockPlain b.Kind = BlockPlain
b.Control = nil b.Control = nil
b.Succs = b.Succs[:1] b.Succs = b.Succs[:1]
......
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