1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:04:48 -07:00

cmd/compile: move all usage of delayTransform out of helpers.go

So next CL will make delayTransform to become irgen's method, because
the delay transform logic also depends on irgen.topFuncIsGeneric field.

For #48609

Change-Id: I660ed19856bd06c3b6f4279a9184db96175dea2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/351854
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Cuong Manh Le 2021-09-24 23:02:08 +07:00
parent f6b5ffb5e1
commit c94543b85f
2 changed files with 33 additions and 26 deletions

View File

@ -167,7 +167,12 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
index := g.expr(expr.Index) index := g.expr(expr.Index)
if index.Op() != ir.OTYPE { if index.Op() != ir.OTYPE {
// This is just a normal index expression // This is just a normal index expression
return Index(pos, g.typ(typ), g.expr(expr.X), index) n := Index(pos, g.typ(typ), g.expr(expr.X), index)
if !delayTransform() {
// transformIndex will modify n.Type() for OINDEXMAP.
transformIndex(n)
}
return n
} }
// This is generic function instantiation with a single type // This is generic function instantiation with a single type
targs = []ir.Node{index} targs = []ir.Node{index}
@ -200,7 +205,11 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
return g.selectorExpr(pos, typ, expr) return g.selectorExpr(pos, typ, expr)
case *syntax.SliceExpr: case *syntax.SliceExpr:
return Slice(pos, g.typ(typ), g.expr(expr.X), g.expr(expr.Index[0]), g.expr(expr.Index[1]), g.expr(expr.Index[2])) n := Slice(pos, g.typ(typ), g.expr(expr.X), g.expr(expr.Index[0]), g.expr(expr.Index[1]), g.expr(expr.Index[2]))
if !delayTransform() {
transformSlice(n)
}
return n
case *syntax.Operation: case *syntax.Operation:
if expr.Y == nil { if expr.Y == nil {
@ -208,9 +217,21 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
} }
switch op := g.op(expr.Op, binOps[:]); op { switch op := g.op(expr.Op, binOps[:]); op {
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE: case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
return Compare(pos, g.typ(typ), op, g.expr(expr.X), g.expr(expr.Y)) n := Compare(pos, g.typ(typ), op, g.expr(expr.X), g.expr(expr.Y))
if !delayTransform() {
transformCompare(n)
}
return n
case ir.OANDAND, ir.OOROR:
x := g.expr(expr.X)
y := g.expr(expr.Y)
return typed(x.Type(), ir.NewLogicalExpr(pos, op, x, y))
default: default:
return Binary(pos, op, g.typ(typ), g.expr(expr.X), g.expr(expr.Y)) n := Binary(pos, op, g.typ(typ), g.expr(expr.X), g.expr(expr.Y))
if op == ir.OADD && !delayTransform() {
return transformAdd(n)
}
return n
} }
default: default:

View File

@ -89,20 +89,16 @@ func Assert(pos src.XPos, x ir.Node, typ *types.Type) ir.Node {
return typed(typ, ir.NewTypeAssertExpr(pos, x, nil)) return typed(typ, ir.NewTypeAssertExpr(pos, x, nil))
} }
func Binary(pos src.XPos, op ir.Op, typ *types.Type, x, y ir.Node) ir.Node { func Binary(pos src.XPos, op ir.Op, typ *types.Type, x, y ir.Node) *ir.BinaryExpr {
switch op { switch op {
case ir.OANDAND, ir.OOROR:
return typed(x.Type(), ir.NewLogicalExpr(pos, op, x, y))
case ir.OADD: case ir.OADD:
n := ir.NewBinaryExpr(pos, op, x, y) n := ir.NewBinaryExpr(pos, op, x, y)
typed(typ, n) typed(typ, n)
r := ir.Node(n) return n
if !delayTransform() {
r = transformAdd(n)
}
return r
default: default:
return typed(x.Type(), ir.NewBinaryExpr(pos, op, x, y)) n := ir.NewBinaryExpr(pos, op, x, y)
typed(x.Type(), n)
return n
} }
} }
@ -195,12 +191,9 @@ func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool)
return n return n
} }
func Compare(pos src.XPos, typ *types.Type, op ir.Op, x, y ir.Node) ir.Node { func Compare(pos src.XPos, typ *types.Type, op ir.Op, x, y ir.Node) *ir.BinaryExpr {
n := ir.NewBinaryExpr(pos, op, x, y) n := ir.NewBinaryExpr(pos, op, x, y)
typed(typ, n) typed(typ, n)
if !delayTransform() {
transformCompare(n)
}
return n return n
} }
@ -270,26 +263,19 @@ func method(typ *types.Type, index int) *types.Field {
return types.ReceiverBaseType(typ).Methods().Index(index) return types.ReceiverBaseType(typ).Methods().Index(index)
} }
func Index(pos src.XPos, typ *types.Type, x, index ir.Node) ir.Node { func Index(pos src.XPos, typ *types.Type, x, index ir.Node) *ir.IndexExpr {
n := ir.NewIndexExpr(pos, x, index) n := ir.NewIndexExpr(pos, x, index)
typed(typ, n) typed(typ, n)
if !delayTransform() {
// transformIndex will modify n.Type() for OINDEXMAP.
transformIndex(n)
}
return n return n
} }
func Slice(pos src.XPos, typ *types.Type, x, low, high, max ir.Node) ir.Node { func Slice(pos src.XPos, typ *types.Type, x, low, high, max ir.Node) *ir.SliceExpr {
op := ir.OSLICE op := ir.OSLICE
if max != nil { if max != nil {
op = ir.OSLICE3 op = ir.OSLICE3
} }
n := ir.NewSliceExpr(pos, op, x, low, high, max) n := ir.NewSliceExpr(pos, op, x, low, high, max)
typed(typ, n) typed(typ, n)
if !delayTransform() {
transformSlice(n)
}
return n return n
} }