Commit 2df4b9c2 authored by Alexandru Moșoi's avatar Alexandru Moșoi Committed by Keith Randall

[dev.ssa] cmd/compile/internal/ssa/gen: move variable reset code into a function

Shaves about 3 lines per generated rule.

Change-Id: I94adc94ab79f90ac5fd033f896ece3b1eddf0f3d
Reviewed-on: https://go-review.googlesource.com/19197Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 93a0b0f3
...@@ -122,10 +122,7 @@ func decomposeStringPhi(v *Value) { ...@@ -122,10 +122,7 @@ func decomposeStringPhi(v *Value) {
ptr.AddArg(a.Block.NewValue1(v.Line, OpStringPtr, ptrType, a)) ptr.AddArg(a.Block.NewValue1(v.Line, OpStringPtr, ptrType, a))
len.AddArg(a.Block.NewValue1(v.Line, OpStringLen, lenType, a)) len.AddArg(a.Block.NewValue1(v.Line, OpStringLen, lenType, a))
} }
v.Op = OpStringMake v.reset(OpStringMake)
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(ptr) v.AddArg(ptr)
v.AddArg(len) v.AddArg(len)
} }
...@@ -143,10 +140,7 @@ func decomposeSlicePhi(v *Value) { ...@@ -143,10 +140,7 @@ func decomposeSlicePhi(v *Value) {
len.AddArg(a.Block.NewValue1(v.Line, OpSliceLen, lenType, a)) len.AddArg(a.Block.NewValue1(v.Line, OpSliceLen, lenType, a))
cap.AddArg(a.Block.NewValue1(v.Line, OpSliceCap, lenType, a)) cap.AddArg(a.Block.NewValue1(v.Line, OpSliceCap, lenType, a))
} }
v.Op = OpSliceMake v.reset(OpSliceMake)
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(ptr) v.AddArg(ptr)
v.AddArg(len) v.AddArg(len)
v.AddArg(cap) v.AddArg(cap)
...@@ -170,10 +164,7 @@ func decomposeComplexPhi(v *Value) { ...@@ -170,10 +164,7 @@ func decomposeComplexPhi(v *Value) {
real.AddArg(a.Block.NewValue1(v.Line, OpComplexReal, partType, a)) real.AddArg(a.Block.NewValue1(v.Line, OpComplexReal, partType, a))
imag.AddArg(a.Block.NewValue1(v.Line, OpComplexImag, partType, a)) imag.AddArg(a.Block.NewValue1(v.Line, OpComplexImag, partType, a))
} }
v.Op = OpComplexMake v.reset(OpComplexMake)
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(real) v.AddArg(real)
v.AddArg(imag) v.AddArg(imag)
} }
...@@ -187,10 +178,7 @@ func decomposeInterfacePhi(v *Value) { ...@@ -187,10 +178,7 @@ func decomposeInterfacePhi(v *Value) {
itab.AddArg(a.Block.NewValue1(v.Line, OpITab, ptrType, a)) itab.AddArg(a.Block.NewValue1(v.Line, OpITab, ptrType, a))
data.AddArg(a.Block.NewValue1(v.Line, OpIData, ptrType, a)) data.AddArg(a.Block.NewValue1(v.Line, OpIData, ptrType, a))
} }
v.Op = OpIMake v.reset(OpIMake)
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(itab) v.AddArg(itab)
v.AddArg(data) v.AddArg(data)
} }
...@@ -206,10 +194,7 @@ func decomposeStructPhi(v *Value) { ...@@ -206,10 +194,7 @@ func decomposeStructPhi(v *Value) {
fields[i].AddArg(a.Block.NewValue1I(v.Line, OpStructSelect, t.FieldType(i), i, a)) fields[i].AddArg(a.Block.NewValue1I(v.Line, OpStructSelect, t.FieldType(i), i, a))
} }
} }
v.Op = StructMakeOp(n) v.reset(StructMakeOp(n))
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArgs(fields[:n]...) v.AddArgs(fields[:n]...)
// Recursively decompose phis for each field. // Recursively decompose phis for each field.
......
...@@ -435,10 +435,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc ...@@ -435,10 +435,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc
// It in not safe in general to move a variable between blocks // It in not safe in general to move a variable between blocks
// (and particularly not a phi node). // (and particularly not a phi node).
// Introduce a copy. // Introduce a copy.
fmt.Fprintf(w, "v.Op = OpCopy\n") fmt.Fprintf(w, "v.reset(OpCopy)\n")
fmt.Fprintf(w, "v.AuxInt = 0\n")
fmt.Fprintf(w, "v.Aux = nil\n")
fmt.Fprintf(w, "v.resetArgs()\n")
fmt.Fprintf(w, "v.Type = %s.Type\n", result) fmt.Fprintf(w, "v.Type = %s.Type\n", result)
fmt.Fprintf(w, "v.AddArg(%s)\n", result) fmt.Fprintf(w, "v.AddArg(%s)\n", result)
} }
...@@ -478,13 +475,10 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc ...@@ -478,13 +475,10 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc
var v string var v string
if top && loc == "b" { if top && loc == "b" {
v = "v" v = "v"
fmt.Fprintf(w, "v.reset(%s)\n", opName(s[0], arch))
if typeOverride { if typeOverride {
fmt.Fprintf(w, "v.Type = %s\n", opType) fmt.Fprintf(w, "v.Type = %s\n", opType)
} }
fmt.Fprintf(w, "v.Op = %s\n", opName(s[0], arch))
fmt.Fprintf(w, "v.AuxInt = 0\n")
fmt.Fprintf(w, "v.Aux = nil\n")
fmt.Fprintf(w, "v.resetArgs()\n")
} else { } else {
if opType == "" { if opType == "" {
log.Fatalf("sub-expression %s (op=%s) must have a type", result, s[0]) log.Fatalf("sub-expression %s (op=%s) must have a type", result, s[0])
...@@ -494,10 +488,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc ...@@ -494,10 +488,7 @@ func genResult0(w io.Writer, arch arch, result string, alloc *int, top bool, loc
fmt.Fprintf(w, "%s := %s.NewValue0(v.Line, %s, %s)\n", v, loc, opName(s[0], arch), opType) fmt.Fprintf(w, "%s := %s.NewValue0(v.Line, %s, %s)\n", v, loc, opName(s[0], arch), opType)
if top { if top {
// Rewrite original into a copy // Rewrite original into a copy
fmt.Fprintf(w, "v.Op = OpCopy\n") fmt.Fprintf(w, "v.reset(OpCopy)\n")
fmt.Fprintf(w, "v.AuxInt = 0\n")
fmt.Fprintf(w, "v.Aux = nil\n")
fmt.Fprintf(w, "v.resetArgs()\n")
fmt.Fprintf(w, "v.AddArg(%s)\n", v) fmt.Fprintf(w, "v.AddArg(%s)\n", v)
} }
} }
......
...@@ -170,6 +170,13 @@ func (v *Value) resetArgs() { ...@@ -170,6 +170,13 @@ func (v *Value) resetArgs() {
v.Args = v.argstorage[:0] v.Args = v.argstorage[:0]
} }
func (v *Value) reset(op Op) {
v.Op = op
v.resetArgs()
v.AuxInt = 0
v.Aux = nil
}
// copyInto makes a new value identical to v and adds it to the end of b. // copyInto makes a new value identical to v and adds it to the end of b.
func (v *Value) copyInto(b *Block) *Value { func (v *Value) copyInto(b *Block) *Value {
c := b.NewValue0(v.Line, v.Op, v.Type) c := b.NewValue0(v.Line, v.Op, v.Type)
......
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