Skip to content

Commit 7a1679d

Browse files
committed
cmd/compile: move s390x over to new bounds check strategy
Change-Id: I86ed1a60165b729bb88a8a418da0ea1b59b3dc10 Reviewed-on: https://go-review.googlesource.com/c/go/+/682499 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Munday <[email protected]> Reviewed-by: Mark Freeman <[email protected]>
1 parent 9569381 commit 7a1679d

File tree

6 files changed

+225
-157
lines changed

6 files changed

+225
-157
lines changed

src/cmd/compile/internal/s390x/ssa.go

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"cmd/compile/internal/types"
1616
"cmd/internal/obj"
1717
"cmd/internal/obj/s390x"
18+
"internal/abi"
1819
)
1920

2021
// ssaMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
@@ -573,12 +574,92 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
573574
p.To.Name = obj.NAME_EXTERN
574575
// AuxInt encodes how many buffer entries we need.
575576
p.To.Sym = ir.Syms.GCWriteBarrier[v.AuxInt-1]
576-
case ssa.OpS390XLoweredPanicBoundsA, ssa.OpS390XLoweredPanicBoundsB, ssa.OpS390XLoweredPanicBoundsC:
577-
p := s.Prog(obj.ACALL)
577+
578+
case ssa.OpS390XLoweredPanicBoundsRR, ssa.OpS390XLoweredPanicBoundsRC, ssa.OpS390XLoweredPanicBoundsCR, ssa.OpS390XLoweredPanicBoundsCC:
579+
// Compute the constant we put in the PCData entry for this call.
580+
code, signed := ssa.BoundsKind(v.AuxInt).Code()
581+
xIsReg := false
582+
yIsReg := false
583+
xVal := 0
584+
yVal := 0
585+
switch v.Op {
586+
case ssa.OpS390XLoweredPanicBoundsRR:
587+
xIsReg = true
588+
xVal = int(v.Args[0].Reg() - s390x.REG_R0)
589+
yIsReg = true
590+
yVal = int(v.Args[1].Reg() - s390x.REG_R0)
591+
case ssa.OpS390XLoweredPanicBoundsRC:
592+
xIsReg = true
593+
xVal = int(v.Args[0].Reg() - s390x.REG_R0)
594+
c := v.Aux.(ssa.PanicBoundsC).C
595+
if c >= 0 && c <= abi.BoundsMaxConst {
596+
yVal = int(c)
597+
} else {
598+
// Move constant to a register
599+
yIsReg = true
600+
if yVal == xVal {
601+
yVal = 1
602+
}
603+
p := s.Prog(s390x.AMOVD)
604+
p.From.Type = obj.TYPE_CONST
605+
p.From.Offset = c
606+
p.To.Type = obj.TYPE_REG
607+
p.To.Reg = s390x.REG_R0 + int16(yVal)
608+
}
609+
case ssa.OpS390XLoweredPanicBoundsCR:
610+
yIsReg = true
611+
yVal := int(v.Args[0].Reg() - s390x.REG_R0)
612+
c := v.Aux.(ssa.PanicBoundsC).C
613+
if c >= 0 && c <= abi.BoundsMaxConst {
614+
xVal = int(c)
615+
} else {
616+
// Move constant to a register
617+
if xVal == yVal {
618+
xVal = 1
619+
}
620+
p := s.Prog(s390x.AMOVD)
621+
p.From.Type = obj.TYPE_CONST
622+
p.From.Offset = c
623+
p.To.Type = obj.TYPE_REG
624+
p.To.Reg = s390x.REG_R0 + int16(xVal)
625+
}
626+
case ssa.OpS390XLoweredPanicBoundsCC:
627+
c := v.Aux.(ssa.PanicBoundsCC).Cx
628+
if c >= 0 && c <= abi.BoundsMaxConst {
629+
xVal = int(c)
630+
} else {
631+
// Move constant to a register
632+
xIsReg = true
633+
p := s.Prog(s390x.AMOVD)
634+
p.From.Type = obj.TYPE_CONST
635+
p.From.Offset = c
636+
p.To.Type = obj.TYPE_REG
637+
p.To.Reg = s390x.REG_R0 + int16(xVal)
638+
}
639+
c = v.Aux.(ssa.PanicBoundsCC).Cy
640+
if c >= 0 && c <= abi.BoundsMaxConst {
641+
yVal = int(c)
642+
} else {
643+
// Move constant to a register
644+
yIsReg = true
645+
yVal = 1
646+
p := s.Prog(s390x.AMOVD)
647+
p.From.Type = obj.TYPE_CONST
648+
p.From.Offset = c
649+
p.To.Type = obj.TYPE_REG
650+
p.To.Reg = s390x.REG_R0 + int16(yVal)
651+
}
652+
}
653+
c := abi.BoundsEncode(code, signed, xIsReg, yIsReg, xVal, yVal)
654+
655+
p := s.Prog(obj.APCDATA)
656+
p.From.SetConst(abi.PCDATA_PanicBounds)
657+
p.To.SetConst(int64(c))
658+
p = s.Prog(obj.ACALL)
578659
p.To.Type = obj.TYPE_MEM
579660
p.To.Name = obj.NAME_EXTERN
580-
p.To.Sym = ssagen.BoundsCheckFunc[v.AuxInt]
581-
s.UseArgs(16) // space used in callee args area by assembly stubs
661+
p.To.Sym = ir.Syms.PanicBounds
662+
582663
case ssa.OpS390XFLOGR, ssa.OpS390XPOPCNT,
583664
ssa.OpS390XNEG, ssa.OpS390XNEGW,
584665
ssa.OpS390XMOVWBR, ssa.OpS390XMOVDBR:

src/cmd/compile/internal/ssa/_gen/S390X.rules

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,11 @@
458458
// Write barrier.
459459
(WB ...) => (LoweredWB ...)
460460

461-
(PanicBounds [kind] x y mem) && boundsABI(kind) == 0 => (LoweredPanicBoundsA [kind] x y mem)
462-
(PanicBounds [kind] x y mem) && boundsABI(kind) == 1 => (LoweredPanicBoundsB [kind] x y mem)
463-
(PanicBounds [kind] x y mem) && boundsABI(kind) == 2 => (LoweredPanicBoundsC [kind] x y mem)
461+
(PanicBounds ...) => (LoweredPanicBoundsRR ...)
462+
(LoweredPanicBoundsRR [kind] x (MOVDconst [c]) mem) => (LoweredPanicBoundsRC [kind] x {PanicBoundsC{C:c}} mem)
463+
(LoweredPanicBoundsRR [kind] (MOVDconst [c]) y mem) => (LoweredPanicBoundsCR [kind] {PanicBoundsC{C:c}} y mem)
464+
(LoweredPanicBoundsRC [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {PanicBoundsCC{Cx:c, Cy:p.C}} mem)
465+
(LoweredPanicBoundsCR [kind] {p} (MOVDconst [c]) mem) => (LoweredPanicBoundsCC [kind] {PanicBoundsCC{Cx:p.C, Cy:c}} mem)
464466

465467
// ***************************
466468
// Above: lowering rules

src/cmd/compile/internal/ssa/_gen/S390XOps.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func init() {
114114
sb = buildReg("SB")
115115
r0 = buildReg("R0")
116116
tmp = buildReg("R11") // R11 is used as a temporary in a small number of instructions.
117+
lr = buildReg("R14")
117118

118119
// R10 is reserved by the assembler.
119120
gp = buildReg("R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14")
@@ -518,12 +519,15 @@ func init() {
518519
// Returns a pointer to a write barrier buffer in R9.
519520
{name: "LoweredWB", argLength: 1, reg: regInfo{clobbers: (callerSave &^ gpg) | buildReg("R14") | r1, outputs: []regMask{r9}}, clobberFlags: true, aux: "Int64"},
520521

521-
// There are three of these functions so that they can have three different register inputs.
522-
// When we check 0 <= c <= cap (A), then 0 <= b <= c (B), then 0 <= a <= b (C), we want the
523-
// default registers to match so we don't need to copy registers around unnecessarily.
524-
{name: "LoweredPanicBoundsA", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r2, r3}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in generic.go).
525-
{name: "LoweredPanicBoundsB", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r1, r2}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in generic.go).
526-
{name: "LoweredPanicBoundsC", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r0, r1}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in generic.go).
522+
// LoweredPanicBoundsRR takes x and y, two values that caused a bounds check to fail.
523+
// the RC and CR versions are used when one of the arguments is a constant. CC is used
524+
// when both are constant (normally both 0, as prove derives the fact that a [0] bounds
525+
// failure means the length must have also been 0).
526+
// AuxInt contains a report code (see PanicBounds in genericOps.go).
527+
{name: "LoweredPanicBoundsRR", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{gp &^ lr, gp &^ lr}}, typ: "Mem", call: true}, // arg0=x, arg1=y, arg2=mem, returns memory.
528+
{name: "LoweredPanicBoundsRC", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{gp &^ lr}}, typ: "Mem", call: true}, // arg0=x, arg1=mem, returns memory.
529+
{name: "LoweredPanicBoundsCR", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{gp &^ lr}}, typ: "Mem", call: true}, // arg0=y, arg1=mem, returns memory.
530+
{name: "LoweredPanicBoundsCC", argLength: 1, aux: "PanicBoundsCC", reg: regInfo{}, typ: "Mem", call: true}, // arg0=mem, returns memory.
527531

528532
// Constant condition code values. The condition code can be 0, 1, 2 or 3.
529533
{name: "FlagEQ"}, // CC=0 (equal)

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 22 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssa/rewriteS390X.go

Lines changed: 88 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)