mirror of
https://github.com/golang/go
synced 2024-10-05 20:21:21 -06:00
[dev.ssa] cmd/compile: use function calls instead of special ops for panics
There's no need for special ops for panicindex and panicslice. Just use regular runtime calls. Change-Id: I71b9b73f4f1ebce1220fdc1e7b7f65cfcf4b7bae Reviewed-on: https://go-review.googlesource.com/14726 Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
8c5bfcc52b
commit
3a70bf9c0c
@ -2312,7 +2312,7 @@ func (s *state) boundsCheck(idx, len *ssa.Value) {
|
|||||||
|
|
||||||
// bounds check
|
// bounds check
|
||||||
cmp := s.newValue2(ssa.OpIsInBounds, Types[TBOOL], idx, len)
|
cmp := s.newValue2(ssa.OpIsInBounds, Types[TBOOL], idx, len)
|
||||||
s.check(cmp, ssa.OpPanicIndexCheck)
|
s.check(cmp, Panicindex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sliceBoundsCheck generates slice bounds checking code. Checks if 0 <= idx <= len, branches to exit if not.
|
// sliceBoundsCheck generates slice bounds checking code. Checks if 0 <= idx <= len, branches to exit if not.
|
||||||
@ -2326,11 +2326,11 @@ func (s *state) sliceBoundsCheck(idx, len *ssa.Value) {
|
|||||||
|
|
||||||
// bounds check
|
// bounds check
|
||||||
cmp := s.newValue2(ssa.OpIsSliceInBounds, Types[TBOOL], idx, len)
|
cmp := s.newValue2(ssa.OpIsSliceInBounds, Types[TBOOL], idx, len)
|
||||||
s.check(cmp, ssa.OpPanicSliceCheck)
|
s.check(cmp, panicslice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If cmp (a bool) is true, panic using the given op.
|
// If cmp (a bool) is true, panic using the given function.
|
||||||
func (s *state) check(cmp *ssa.Value, panicOp ssa.Op) {
|
func (s *state) check(cmp *ssa.Value, fn *Node) {
|
||||||
b := s.endBlock()
|
b := s.endBlock()
|
||||||
b.Kind = ssa.BlockIf
|
b.Kind = ssa.BlockIf
|
||||||
b.Control = cmp
|
b.Control = cmp
|
||||||
@ -2340,12 +2340,10 @@ func (s *state) check(cmp *ssa.Value, panicOp ssa.Op) {
|
|||||||
b.AddEdgeTo(bNext)
|
b.AddEdgeTo(bNext)
|
||||||
b.AddEdgeTo(bPanic)
|
b.AddEdgeTo(bPanic)
|
||||||
s.startBlock(bPanic)
|
s.startBlock(bPanic)
|
||||||
// The panic check takes/returns memory to ensure that the right
|
// The panic call takes/returns memory to ensure that the right
|
||||||
// memory state is observed if the panic happens.
|
// memory state is observed if the panic happens.
|
||||||
chk := s.newValue1(panicOp, ssa.TypeMem, s.mem())
|
s.rtcall(fn, false, nil)
|
||||||
s.endBlock()
|
|
||||||
bPanic.Kind = ssa.BlockExit
|
|
||||||
bPanic.Control = chk
|
|
||||||
s.startBlock(bNext)
|
s.startBlock(bNext)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3700,16 +3698,6 @@ func (s *genState) genValue(v *ssa.Value) {
|
|||||||
q.From.Reg = x86.REG_AX
|
q.From.Reg = x86.REG_AX
|
||||||
q.To.Type = obj.TYPE_MEM
|
q.To.Type = obj.TYPE_MEM
|
||||||
q.To.Reg = r
|
q.To.Reg = r
|
||||||
case ssa.OpAMD64LoweredPanicIndexCheck:
|
|
||||||
p := Prog(obj.ACALL)
|
|
||||||
p.To.Type = obj.TYPE_MEM
|
|
||||||
p.To.Name = obj.NAME_EXTERN
|
|
||||||
p.To.Sym = Linksym(Panicindex.Sym)
|
|
||||||
case ssa.OpAMD64LoweredPanicSliceCheck:
|
|
||||||
p := Prog(obj.ACALL)
|
|
||||||
p.To.Type = obj.TYPE_MEM
|
|
||||||
p.To.Name = obj.NAME_EXTERN
|
|
||||||
p.To.Sym = Linksym(panicslice.Sym)
|
|
||||||
case ssa.OpAMD64LoweredGetG:
|
case ssa.OpAMD64LoweredGetG:
|
||||||
r := regnum(v)
|
r := regnum(v)
|
||||||
// See the comments in cmd/internal/obj/x86/obj6.go
|
// See the comments in cmd/internal/obj/x86/obj6.go
|
||||||
|
@ -287,8 +287,6 @@
|
|||||||
(IsSliceInBounds idx len) -> (SETBE (CMPQ idx len))
|
(IsSliceInBounds idx len) -> (SETBE (CMPQ idx len))
|
||||||
|
|
||||||
(PanicNilCheck ptr mem) -> (LoweredPanicNilCheck ptr mem)
|
(PanicNilCheck ptr mem) -> (LoweredPanicNilCheck ptr mem)
|
||||||
(PanicIndexCheck mem) -> (LoweredPanicIndexCheck mem)
|
|
||||||
(PanicSliceCheck mem) -> (LoweredPanicSliceCheck mem)
|
|
||||||
(GetG) -> (LoweredGetG)
|
(GetG) -> (LoweredGetG)
|
||||||
|
|
||||||
(Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <config.Frontend().TypeUInt64()> [size]) mem)
|
(Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <config.Frontend().TypeUInt64()> [size]) mem)
|
||||||
|
@ -403,8 +403,6 @@ func init() {
|
|||||||
|
|
||||||
// Pseudo-ops
|
// Pseudo-ops
|
||||||
{name: "LoweredPanicNilCheck", reg: gp10},
|
{name: "LoweredPanicNilCheck", reg: gp10},
|
||||||
{name: "LoweredPanicIndexCheck"},
|
|
||||||
{name: "LoweredPanicSliceCheck"},
|
|
||||||
{name: "LoweredGetG", reg: gp01},
|
{name: "LoweredGetG", reg: gp01},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,8 +326,6 @@ var genericOps = []opData{
|
|||||||
|
|
||||||
// Pseudo-ops
|
// Pseudo-ops
|
||||||
{name: "PanicNilCheck"}, // trigger a dereference fault; arg0=nil ptr, arg1=mem, returns mem
|
{name: "PanicNilCheck"}, // trigger a dereference fault; arg0=nil ptr, arg1=mem, returns mem
|
||||||
{name: "PanicIndexCheck"}, // trigger a bounds check failure, arg0=mem, returns mem
|
|
||||||
{name: "PanicSliceCheck"}, // trigger a slice bounds check failure, arg0=mem, returns mem
|
|
||||||
{name: "GetG"}, // runtime.getg() (read g pointer)
|
{name: "GetG"}, // runtime.getg() (read g pointer)
|
||||||
|
|
||||||
// Indexing operations
|
// Indexing operations
|
||||||
|
@ -270,8 +270,6 @@ const (
|
|||||||
OpAMD64REPMOVSB
|
OpAMD64REPMOVSB
|
||||||
OpAMD64InvertFlags
|
OpAMD64InvertFlags
|
||||||
OpAMD64LoweredPanicNilCheck
|
OpAMD64LoweredPanicNilCheck
|
||||||
OpAMD64LoweredPanicIndexCheck
|
|
||||||
OpAMD64LoweredPanicSliceCheck
|
|
||||||
OpAMD64LoweredGetG
|
OpAMD64LoweredGetG
|
||||||
|
|
||||||
OpAdd8
|
OpAdd8
|
||||||
@ -513,8 +511,6 @@ const (
|
|||||||
OpIsInBounds
|
OpIsInBounds
|
||||||
OpIsSliceInBounds
|
OpIsSliceInBounds
|
||||||
OpPanicNilCheck
|
OpPanicNilCheck
|
||||||
OpPanicIndexCheck
|
|
||||||
OpPanicSliceCheck
|
|
||||||
OpGetG
|
OpGetG
|
||||||
OpArrayIndex
|
OpArrayIndex
|
||||||
OpPtrIndex
|
OpPtrIndex
|
||||||
@ -3115,14 +3111,6 @@ var opcodeTable = [...]opInfo{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "LoweredPanicIndexCheck",
|
|
||||||
reg: regInfo{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "LoweredPanicSliceCheck",
|
|
||||||
reg: regInfo{},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "LoweredGetG",
|
name: "LoweredGetG",
|
||||||
reg: regInfo{
|
reg: regInfo{
|
||||||
@ -4088,14 +4076,6 @@ var opcodeTable = [...]opInfo{
|
|||||||
name: "PanicNilCheck",
|
name: "PanicNilCheck",
|
||||||
generic: true,
|
generic: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "PanicIndexCheck",
|
|
||||||
generic: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "PanicSliceCheck",
|
|
||||||
generic: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "GetG",
|
name: "GetG",
|
||||||
generic: true,
|
generic: true,
|
||||||
|
@ -6905,22 +6905,6 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
|
|||||||
goto end6f8a8c559a167d1f0a5901d09a1fb248
|
goto end6f8a8c559a167d1f0a5901d09a1fb248
|
||||||
end6f8a8c559a167d1f0a5901d09a1fb248:
|
end6f8a8c559a167d1f0a5901d09a1fb248:
|
||||||
;
|
;
|
||||||
case OpPanicIndexCheck:
|
|
||||||
// match: (PanicIndexCheck mem)
|
|
||||||
// cond:
|
|
||||||
// result: (LoweredPanicIndexCheck mem)
|
|
||||||
{
|
|
||||||
mem := v.Args[0]
|
|
||||||
v.Op = OpAMD64LoweredPanicIndexCheck
|
|
||||||
v.AuxInt = 0
|
|
||||||
v.Aux = nil
|
|
||||||
v.resetArgs()
|
|
||||||
v.AddArg(mem)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
goto enda5014ba73d3550a5b66424044395c70f
|
|
||||||
enda5014ba73d3550a5b66424044395c70f:
|
|
||||||
;
|
|
||||||
case OpPanicNilCheck:
|
case OpPanicNilCheck:
|
||||||
// match: (PanicNilCheck ptr mem)
|
// match: (PanicNilCheck ptr mem)
|
||||||
// cond:
|
// cond:
|
||||||
@ -6939,22 +6923,6 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
|
|||||||
goto enda02b1ad5a6f929b782190145f2c8628b
|
goto enda02b1ad5a6f929b782190145f2c8628b
|
||||||
enda02b1ad5a6f929b782190145f2c8628b:
|
enda02b1ad5a6f929b782190145f2c8628b:
|
||||||
;
|
;
|
||||||
case OpPanicSliceCheck:
|
|
||||||
// match: (PanicSliceCheck mem)
|
|
||||||
// cond:
|
|
||||||
// result: (LoweredPanicSliceCheck mem)
|
|
||||||
{
|
|
||||||
mem := v.Args[0]
|
|
||||||
v.Op = OpAMD64LoweredPanicSliceCheck
|
|
||||||
v.AuxInt = 0
|
|
||||||
v.Aux = nil
|
|
||||||
v.resetArgs()
|
|
||||||
v.AddArg(mem)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
goto end238ed0074810b55bd2bba7b45cdeed68
|
|
||||||
end238ed0074810b55bd2bba7b45cdeed68:
|
|
||||||
;
|
|
||||||
case OpRsh16Ux16:
|
case OpRsh16Ux16:
|
||||||
// match: (Rsh16Ux16 <t> x y)
|
// match: (Rsh16Ux16 <t> x y)
|
||||||
// cond:
|
// cond:
|
||||||
|
Loading…
Reference in New Issue
Block a user