1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:10:21 -07:00

[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/19197
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Alexandru Moșoi 2016-02-04 17:21:57 +01:00 committed by Keith Randall
parent 93a0b0f315
commit 2df4b9c265
5 changed files with 949 additions and 3768 deletions

View File

@ -122,10 +122,7 @@ func decomposeStringPhi(v *Value) {
ptr.AddArg(a.Block.NewValue1(v.Line, OpStringPtr, ptrType, a))
len.AddArg(a.Block.NewValue1(v.Line, OpStringLen, lenType, a))
}
v.Op = OpStringMake
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.reset(OpStringMake)
v.AddArg(ptr)
v.AddArg(len)
}
@ -143,10 +140,7 @@ func decomposeSlicePhi(v *Value) {
len.AddArg(a.Block.NewValue1(v.Line, OpSliceLen, lenType, a))
cap.AddArg(a.Block.NewValue1(v.Line, OpSliceCap, lenType, a))
}
v.Op = OpSliceMake
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.reset(OpSliceMake)
v.AddArg(ptr)
v.AddArg(len)
v.AddArg(cap)
@ -170,10 +164,7 @@ func decomposeComplexPhi(v *Value) {
real.AddArg(a.Block.NewValue1(v.Line, OpComplexReal, partType, a))
imag.AddArg(a.Block.NewValue1(v.Line, OpComplexImag, partType, a))
}
v.Op = OpComplexMake
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.reset(OpComplexMake)
v.AddArg(real)
v.AddArg(imag)
}
@ -187,10 +178,7 @@ func decomposeInterfacePhi(v *Value) {
itab.AddArg(a.Block.NewValue1(v.Line, OpITab, ptrType, a))
data.AddArg(a.Block.NewValue1(v.Line, OpIData, ptrType, a))
}
v.Op = OpIMake
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.reset(OpIMake)
v.AddArg(itab)
v.AddArg(data)
}
@ -206,10 +194,7 @@ func decomposeStructPhi(v *Value) {
fields[i].AddArg(a.Block.NewValue1I(v.Line, OpStructSelect, t.FieldType(i), i, a))
}
}
v.Op = StructMakeOp(n)
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.reset(StructMakeOp(n))
v.AddArgs(fields[:n]...)
// Recursively decompose phis for each field.

View File

@ -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
// (and particularly not a phi node).
// Introduce a copy.
fmt.Fprintf(w, "v.Op = 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.reset(OpCopy)\n")
fmt.Fprintf(w, "v.Type = %s.Type\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
var v string
if top && loc == "b" {
v = "v"
fmt.Fprintf(w, "v.reset(%s)\n", opName(s[0], arch))
if typeOverride {
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 {
if opType == "" {
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
fmt.Fprintf(w, "%s := %s.NewValue0(v.Line, %s, %s)\n", v, loc, opName(s[0], arch), opType)
if top {
// Rewrite original into a copy
fmt.Fprintf(w, "v.Op = 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.reset(OpCopy)\n")
fmt.Fprintf(w, "v.AddArg(%s)\n", v)
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -170,6 +170,13 @@ func (v *Value) resetArgs() {
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.
func (v *Value) copyInto(b *Block) *Value {
c := b.NewValue0(v.Line, v.Op, v.Type)