From 53827ba49eb6afae541579c96c6f6b3df3605694 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Tue, 3 Oct 2023 10:33:48 +0000 Subject: [PATCH] cmd/compile,runtime: remove runtime.mulUintptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For #48798 Change-Id: I3e928d3921cfd5a7bf35b23d0ae6442aa6d2d482 GitHub-Last-Rev: b101a8a54f2cc9ea917f879a545f30c702508743 GitHub-Pull-Request: golang/go#63349 Reviewed-on: https://go-review.googlesource.com/c/go/+/532355 TryBot-Result: Gopher Robot Commit-Queue: Keith Randall Reviewed-by: Keith Randall Run-TryBot: Martin Möhrmann Reviewed-by: Keith Randall Auto-Submit: Keith Randall Reviewed-by: Martin Möhrmann --- src/cmd/compile/internal/ssagen/ssa.go | 1 - .../internal/typecheck/_builtin/runtime.go | 2 - src/cmd/compile/internal/typecheck/builtin.go | 204 +++++++++--------- src/cmd/compile/internal/walk/builtin.go | 20 +- src/runtime/slice.go | 6 - 5 files changed, 118 insertions(+), 115 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index a9d80552cb..845421ca54 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -4117,7 +4117,6 @@ func InitTables() { return s.newValue2(ssa.OpMul64uover, types.NewTuple(types.Types[types.TUINT], types.Types[types.TUINT]), args[0], args[1]) }, sys.AMD64, sys.I386, sys.Loong64, sys.MIPS64, sys.RISCV64, sys.ARM64) - alias("runtime", "mulUintptr", "runtime/internal/math", "MulUintptr", all...) add("runtime", "KeepAlive", func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value { data := s.newValue1(ssa.OpIData, s.f.Config.Types.BytePtr, args[0]) diff --git a/src/cmd/compile/internal/typecheck/_builtin/runtime.go b/src/cmd/compile/internal/typecheck/_builtin/runtime.go index 6bace1e6bb..c758d7f4b7 100644 --- a/src/cmd/compile/internal/typecheck/_builtin/runtime.go +++ b/src/cmd/compile/internal/typecheck/_builtin/runtime.go @@ -189,8 +189,6 @@ func unsafestringcheckptr(ptr unsafe.Pointer, len int64) func panicunsafestringlen() func panicunsafestringnilptr() -func mulUintptr(x, y uintptr) (uintptr, bool) - func memmove(to *any, frm *any, length uintptr) func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) func memclrHasPointers(ptr unsafe.Pointer, n uintptr) diff --git a/src/cmd/compile/internal/typecheck/builtin.go b/src/cmd/compile/internal/typecheck/builtin.go index cbf1a42752..2caa9a6484 100644 --- a/src/cmd/compile/internal/typecheck/builtin.go +++ b/src/cmd/compile/internal/typecheck/builtin.go @@ -156,87 +156,86 @@ var runtimeDecls = [...]struct { {"unsafestringcheckptr", funcTag, 120}, {"panicunsafestringlen", funcTag, 9}, {"panicunsafestringnilptr", funcTag, 9}, - {"mulUintptr", funcTag, 121}, - {"memmove", funcTag, 122}, - {"memclrNoHeapPointers", funcTag, 123}, - {"memclrHasPointers", funcTag, 123}, - {"memequal", funcTag, 124}, - {"memequal0", funcTag, 125}, - {"memequal8", funcTag, 125}, - {"memequal16", funcTag, 125}, - {"memequal32", funcTag, 125}, - {"memequal64", funcTag, 125}, - {"memequal128", funcTag, 125}, - {"f32equal", funcTag, 126}, - {"f64equal", funcTag, 126}, - {"c64equal", funcTag, 126}, - {"c128equal", funcTag, 126}, - {"strequal", funcTag, 126}, - {"interequal", funcTag, 126}, - {"nilinterequal", funcTag, 126}, - {"memhash", funcTag, 127}, - {"memhash0", funcTag, 128}, - {"memhash8", funcTag, 128}, - {"memhash16", funcTag, 128}, - {"memhash32", funcTag, 128}, - {"memhash64", funcTag, 128}, - {"memhash128", funcTag, 128}, - {"f32hash", funcTag, 129}, - {"f64hash", funcTag, 129}, - {"c64hash", funcTag, 129}, - {"c128hash", funcTag, 129}, - {"strhash", funcTag, 129}, - {"interhash", funcTag, 129}, - {"nilinterhash", funcTag, 129}, - {"int64div", funcTag, 130}, - {"uint64div", funcTag, 131}, - {"int64mod", funcTag, 130}, - {"uint64mod", funcTag, 131}, - {"float64toint64", funcTag, 132}, - {"float64touint64", funcTag, 133}, - {"float64touint32", funcTag, 134}, - {"int64tofloat64", funcTag, 135}, - {"int64tofloat32", funcTag, 137}, - {"uint64tofloat64", funcTag, 138}, - {"uint64tofloat32", funcTag, 139}, - {"uint32tofloat64", funcTag, 140}, - {"complex128div", funcTag, 141}, - {"getcallerpc", funcTag, 142}, - {"getcallersp", funcTag, 142}, + {"memmove", funcTag, 121}, + {"memclrNoHeapPointers", funcTag, 122}, + {"memclrHasPointers", funcTag, 122}, + {"memequal", funcTag, 123}, + {"memequal0", funcTag, 124}, + {"memequal8", funcTag, 124}, + {"memequal16", funcTag, 124}, + {"memequal32", funcTag, 124}, + {"memequal64", funcTag, 124}, + {"memequal128", funcTag, 124}, + {"f32equal", funcTag, 125}, + {"f64equal", funcTag, 125}, + {"c64equal", funcTag, 125}, + {"c128equal", funcTag, 125}, + {"strequal", funcTag, 125}, + {"interequal", funcTag, 125}, + {"nilinterequal", funcTag, 125}, + {"memhash", funcTag, 126}, + {"memhash0", funcTag, 127}, + {"memhash8", funcTag, 127}, + {"memhash16", funcTag, 127}, + {"memhash32", funcTag, 127}, + {"memhash64", funcTag, 127}, + {"memhash128", funcTag, 127}, + {"f32hash", funcTag, 128}, + {"f64hash", funcTag, 128}, + {"c64hash", funcTag, 128}, + {"c128hash", funcTag, 128}, + {"strhash", funcTag, 128}, + {"interhash", funcTag, 128}, + {"nilinterhash", funcTag, 128}, + {"int64div", funcTag, 129}, + {"uint64div", funcTag, 130}, + {"int64mod", funcTag, 129}, + {"uint64mod", funcTag, 130}, + {"float64toint64", funcTag, 131}, + {"float64touint64", funcTag, 132}, + {"float64touint32", funcTag, 133}, + {"int64tofloat64", funcTag, 134}, + {"int64tofloat32", funcTag, 136}, + {"uint64tofloat64", funcTag, 137}, + {"uint64tofloat32", funcTag, 138}, + {"uint32tofloat64", funcTag, 139}, + {"complex128div", funcTag, 140}, + {"getcallerpc", funcTag, 141}, + {"getcallersp", funcTag, 141}, {"racefuncenter", funcTag, 31}, {"racefuncexit", funcTag, 9}, {"raceread", funcTag, 31}, {"racewrite", funcTag, 31}, - {"racereadrange", funcTag, 143}, - {"racewriterange", funcTag, 143}, - {"msanread", funcTag, 143}, - {"msanwrite", funcTag, 143}, - {"msanmove", funcTag, 144}, - {"asanread", funcTag, 143}, - {"asanwrite", funcTag, 143}, - {"checkptrAlignment", funcTag, 145}, - {"checkptrArithmetic", funcTag, 147}, - {"libfuzzerTraceCmp1", funcTag, 148}, - {"libfuzzerTraceCmp2", funcTag, 149}, - {"libfuzzerTraceCmp4", funcTag, 150}, - {"libfuzzerTraceCmp8", funcTag, 151}, - {"libfuzzerTraceConstCmp1", funcTag, 148}, - {"libfuzzerTraceConstCmp2", funcTag, 149}, - {"libfuzzerTraceConstCmp4", funcTag, 150}, - {"libfuzzerTraceConstCmp8", funcTag, 151}, - {"libfuzzerHookStrCmp", funcTag, 152}, - {"libfuzzerHookEqualFold", funcTag, 152}, - {"addCovMeta", funcTag, 154}, + {"racereadrange", funcTag, 142}, + {"racewriterange", funcTag, 142}, + {"msanread", funcTag, 142}, + {"msanwrite", funcTag, 142}, + {"msanmove", funcTag, 143}, + {"asanread", funcTag, 142}, + {"asanwrite", funcTag, 142}, + {"checkptrAlignment", funcTag, 144}, + {"checkptrArithmetic", funcTag, 146}, + {"libfuzzerTraceCmp1", funcTag, 147}, + {"libfuzzerTraceCmp2", funcTag, 148}, + {"libfuzzerTraceCmp4", funcTag, 149}, + {"libfuzzerTraceCmp8", funcTag, 150}, + {"libfuzzerTraceConstCmp1", funcTag, 147}, + {"libfuzzerTraceConstCmp2", funcTag, 148}, + {"libfuzzerTraceConstCmp4", funcTag, 149}, + {"libfuzzerTraceConstCmp8", funcTag, 150}, + {"libfuzzerHookStrCmp", funcTag, 151}, + {"libfuzzerHookEqualFold", funcTag, 151}, + {"addCovMeta", funcTag, 153}, {"x86HasPOPCNT", varTag, 6}, {"x86HasSSE41", varTag, 6}, {"x86HasFMA", varTag, 6}, {"armHasVFPv4", varTag, 6}, {"arm64HasATOMICS", varTag, 6}, - {"asanregisterglobals", funcTag, 123}, + {"asanregisterglobals", funcTag, 122}, } func runtimeTypes() []*types.Type { - var typs [155]*types.Type + var typs [154]*types.Type typs[0] = types.ByteType typs[1] = types.NewPtr(typs[0]) typs[2] = types.Types[types.TANY] @@ -358,40 +357,39 @@ func runtimeTypes() []*types.Type { typs[118] = newSig(params(typs[3], typs[15], typs[15], typs[15], typs[1]), params(typs[117])) typs[119] = newSig(params(typs[1], typs[7], typs[22]), nil) typs[120] = newSig(params(typs[7], typs[22]), nil) - typs[121] = newSig(params(typs[5], typs[5]), params(typs[5], typs[6])) - typs[122] = newSig(params(typs[3], typs[3], typs[5]), nil) - typs[123] = newSig(params(typs[7], typs[5]), nil) - typs[124] = newSig(params(typs[3], typs[3], typs[5]), params(typs[6])) - typs[125] = newSig(params(typs[3], typs[3]), params(typs[6])) - typs[126] = newSig(params(typs[7], typs[7]), params(typs[6])) - typs[127] = newSig(params(typs[3], typs[5], typs[5]), params(typs[5])) - typs[128] = newSig(params(typs[7], typs[5]), params(typs[5])) - typs[129] = newSig(params(typs[3], typs[5]), params(typs[5])) - typs[130] = newSig(params(typs[22], typs[22]), params(typs[22])) - typs[131] = newSig(params(typs[24], typs[24]), params(typs[24])) - typs[132] = newSig(params(typs[20]), params(typs[22])) - typs[133] = newSig(params(typs[20]), params(typs[24])) - typs[134] = newSig(params(typs[20]), params(typs[62])) - typs[135] = newSig(params(typs[22]), params(typs[20])) - typs[136] = types.Types[types.TFLOAT32] - typs[137] = newSig(params(typs[22]), params(typs[136])) - typs[138] = newSig(params(typs[24]), params(typs[20])) - typs[139] = newSig(params(typs[24]), params(typs[136])) - typs[140] = newSig(params(typs[62]), params(typs[20])) - typs[141] = newSig(params(typs[26], typs[26]), params(typs[26])) - typs[142] = newSig(nil, params(typs[5])) - typs[143] = newSig(params(typs[5], typs[5]), nil) - typs[144] = newSig(params(typs[5], typs[5], typs[5]), nil) - typs[145] = newSig(params(typs[7], typs[1], typs[5]), nil) - typs[146] = types.NewSlice(typs[7]) - typs[147] = newSig(params(typs[7], typs[146]), nil) - typs[148] = newSig(params(typs[66], typs[66], typs[17]), nil) - typs[149] = newSig(params(typs[60], typs[60], typs[17]), nil) - typs[150] = newSig(params(typs[62], typs[62], typs[17]), nil) - typs[151] = newSig(params(typs[24], typs[24], typs[17]), nil) - typs[152] = newSig(params(typs[28], typs[28], typs[17]), nil) - typs[153] = types.NewArray(typs[0], 16) - typs[154] = newSig(params(typs[7], typs[62], typs[153], typs[28], typs[15], typs[66], typs[66]), params(typs[62])) + typs[121] = newSig(params(typs[3], typs[3], typs[5]), nil) + typs[122] = newSig(params(typs[7], typs[5]), nil) + typs[123] = newSig(params(typs[3], typs[3], typs[5]), params(typs[6])) + typs[124] = newSig(params(typs[3], typs[3]), params(typs[6])) + typs[125] = newSig(params(typs[7], typs[7]), params(typs[6])) + typs[126] = newSig(params(typs[3], typs[5], typs[5]), params(typs[5])) + typs[127] = newSig(params(typs[7], typs[5]), params(typs[5])) + typs[128] = newSig(params(typs[3], typs[5]), params(typs[5])) + typs[129] = newSig(params(typs[22], typs[22]), params(typs[22])) + typs[130] = newSig(params(typs[24], typs[24]), params(typs[24])) + typs[131] = newSig(params(typs[20]), params(typs[22])) + typs[132] = newSig(params(typs[20]), params(typs[24])) + typs[133] = newSig(params(typs[20]), params(typs[62])) + typs[134] = newSig(params(typs[22]), params(typs[20])) + typs[135] = types.Types[types.TFLOAT32] + typs[136] = newSig(params(typs[22]), params(typs[135])) + typs[137] = newSig(params(typs[24]), params(typs[20])) + typs[138] = newSig(params(typs[24]), params(typs[135])) + typs[139] = newSig(params(typs[62]), params(typs[20])) + typs[140] = newSig(params(typs[26], typs[26]), params(typs[26])) + typs[141] = newSig(nil, params(typs[5])) + typs[142] = newSig(params(typs[5], typs[5]), nil) + typs[143] = newSig(params(typs[5], typs[5], typs[5]), nil) + typs[144] = newSig(params(typs[7], typs[1], typs[5]), nil) + typs[145] = types.NewSlice(typs[7]) + typs[146] = newSig(params(typs[7], typs[145]), nil) + typs[147] = newSig(params(typs[66], typs[66], typs[17]), nil) + typs[148] = newSig(params(typs[60], typs[60], typs[17]), nil) + typs[149] = newSig(params(typs[62], typs[62], typs[17]), nil) + typs[150] = newSig(params(typs[24], typs[24], typs[17]), nil) + typs[151] = newSig(params(typs[28], typs[28], typs[17]), nil) + typs[152] = types.NewArray(typs[0], 16) + typs[153] = newSig(params(typs[7], typs[62], typs[152], typs[28], typs[15], typs[66], typs[66]), params(typs[62])) return typs[:] } diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go index cb481f40ef..fe2473b936 100644 --- a/src/cmd/compile/internal/walk/builtin.go +++ b/src/cmd/compile/internal/walk/builtin.go @@ -748,11 +748,23 @@ func walkUnsafeSlice(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { return walkExpr(typecheck.Expr(h), init) } - // mem, overflow := runtime.mulUintptr(et.size, len) + // mem, overflow := math.mulUintptr(et.size, len) mem := typecheck.TempAt(base.Pos, ir.CurFunc, types.Types[types.TUINTPTR]) overflow := typecheck.TempAt(base.Pos, ir.CurFunc, types.Types[types.TBOOL]) - fn := typecheck.LookupRuntime("mulUintptr") - call := mkcall1(fn, fn.Type().ResultsTuple(), init, ir.NewInt(base.Pos, sliceType.Elem().Size()), typecheck.Conv(typecheck.Conv(len, lenType), types.Types[types.TUINTPTR])) + + decl := types.NewSignature(nil, + []*types.Field{ + types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]), + types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]), + }, + []*types.Field{ + types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]), + types.NewField(base.Pos, nil, types.Types[types.TBOOL]), + }) + + fn := ir.NewFunc(n.Pos(), n.Pos(), math_MulUintptr, decl) + + call := mkcall1(fn.Nname, fn.Type().ResultsTuple(), init, ir.NewInt(base.Pos, sliceType.Elem().Size()), typecheck.Conv(typecheck.Conv(len, lenType), types.Types[types.TUINTPTR])) appendWalkStmt(init, ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{mem, overflow}, []ir.Node{call})) // if overflow || mem > -uintptr(ptr) { @@ -778,6 +790,8 @@ func walkUnsafeSlice(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { return walkExpr(typecheck.Expr(h), init) } +var math_MulUintptr = &types.Sym{Pkg: types.NewPkg("runtime/internal/math", "math"), Name: "MulUintptr"} + func walkUnsafeString(n *ir.BinaryExpr, init *ir.Nodes) ir.Node { ptr := safeExpr(n.X, init) len := safeExpr(n.Y, init) diff --git a/src/runtime/slice.go b/src/runtime/slice.go index a7d5769f47..7e714097cd 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -117,12 +117,6 @@ func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer { return makeslice(et, len, cap) } -// This is a wrapper over runtime/internal/math.MulUintptr, -// so the compiler can recognize and treat it as an intrinsic. -func mulUintptr(a, b uintptr) (uintptr, bool) { - return math.MulUintptr(a, b) -} - // growslice allocates new backing store for a slice. // // arguments: