aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuoqi Chen <chenguoqi@loongson.cn>2023-08-16 08:28:28 +0800
committerGopher Robot <gobot@golang.org>2023-11-21 19:04:25 +0000
commit4e6bbbe61f554dbd9ed78fcd55ff46fe59736785 (patch)
treefcd7d16c4e3684b727f86f1f4c92a0a86da8aff4 /src
parentf6f141ab80853b0b45f7e33aa148e497ceeb7d38 (diff)
downloadgo-4e6bbbe61f554dbd9ed78fcd55ff46fe59736785.tar.xz
reflect, runtime: add reflect support for regABI on loong64
Update #40724 Co-authored-by: Xiaolin Zhao <zhaoxiaolin@loongson.cn> Change-Id: I0549fd1a2192ffb041034ff41bf0cc4be0b1662c Reviewed-on: https://go-review.googlesource.com/c/go/+/521784 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/reflect/asm_loong64.s77
-rw-r--r--src/runtime/stkframe.go2
2 files changed, 64 insertions, 15 deletions
diff --git a/src/reflect/asm_loong64.s b/src/reflect/asm_loong64.s
index 341a6d55c1..520f0afdd5 100644
--- a/src/reflect/asm_loong64.s
+++ b/src/reflect/asm_loong64.s
@@ -7,34 +7,83 @@
#define REGCTXT R29
+// The frames of each of the two functions below contain two locals, at offsets
+// that are known to the runtime.
+//
+// The first local is a bool called retValid with a whole pointer-word reserved
+// for it on the stack. The purpose of this word is so that the runtime knows
+// whether the stack-allocated return space contains valid values for stack
+// scanning.
+//
+// The second local is an abi.RegArgs value whose offset is also known to the
+// runtime, so that a stack map for it can be constructed, since it contains
+// pointers visible to the GC.
+#define LOCAL_RETVALID 40
+#define LOCAL_REGARGS 48
+
+// The frame size of the functions below is
+// 32 (args of callReflect) + 8 (bool + padding) + 392 (abi.RegArgs) = 432.
+
// makeFuncStub is the code half of the function returned by MakeFunc.
// See the comment on the declaration of makeFuncStub in makefunc.go
// for more details.
// No arg size here, runtime pulls arg map out of the func value.
-TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$432
NO_LOCAL_POINTERS
+ ADDV $LOCAL_REGARGS, R3, R25 // spillArgs using R25
+ JAL runtime·spillArgs(SB)
+ MOVV REGCTXT, 32(R3) // save REGCTXT > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
+
+#ifdef GOEXPERIMENT_regabiargs
+ MOVV REGCTXT, R4
+ MOVV R25, R5
+#else
MOVV REGCTXT, 8(R3)
- MOVV $argframe+0(FP), R19
- MOVV R19, 16(R3)
- MOVB R0, 40(R3)
- ADDV $40, R3, R19
- MOVV R19, 24(R3)
- MOVV R0, 32(R3)
+ MOVV R25, 16(R3)
+#endif
+ JAL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
+ MOVV 32(R3), REGCTXT // restore REGCTXT
+
+ MOVV REGCTXT, 8(R3)
+ MOVV $argframe+0(FP), R20
+ MOVV R20, 16(R3)
+ MOVV R0, LOCAL_RETVALID(R3)
+ ADDV $LOCAL_RETVALID, R3, R20
+ MOVV R20, 24(R3)
+ ADDV $LOCAL_REGARGS, R3, R20
+ MOVV R20, 32(R3)
JAL ·callReflect(SB)
+ ADDV $LOCAL_REGARGS, R3, R25 //unspillArgs using R25
+ JAL runtime·unspillArgs(SB)
RET
// methodValueCall is the code half of the function returned by makeMethodValue.
// See the comment on the declaration of methodValueCall in makefunc.go
// for more details.
// No arg size here; runtime pulls arg map out of the func value.
-TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$432
NO_LOCAL_POINTERS
+ ADDV $LOCAL_REGARGS, R3, R25 // spillArgs using R25
+ JAL runtime·spillArgs(SB)
+ MOVV REGCTXT, 32(R3) // save REGCTXT > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
+#ifdef GOEXPERIMENT_regabiargs
+ MOVV REGCTXT, R4
+ MOVV R25, R5
+#else
+ MOVV REGCTXT, 8(R3)
+ MOVV R25, 16(R3)
+#endif
+ JAL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
+ MOVV 32(R3), REGCTXT // restore REGCTXT
MOVV REGCTXT, 8(R3)
- MOVV $argframe+0(FP), R19
- MOVV R19, 16(R3)
- MOVB R0, 40(R3)
- ADDV $40, R3, R19
- MOVV R19, 24(R3)
- MOVV R0, 32(R3)
+ MOVV $argframe+0(FP), R20
+ MOVV R20, 16(R3)
+ MOVB R0, LOCAL_RETVALID(R3)
+ ADDV $LOCAL_RETVALID, R3, R20
+ MOVV R20, 24(R3)
+ ADDV $LOCAL_REGARGS, R3, R20
+ MOVV R20, 32(R3) // frame size to 32+SP as callreflect args)
JAL ·callMethod(SB)
+ ADDV $LOCAL_REGARGS, R3, R25 // unspillArgs using R25
+ JAL runtime·unspillArgs(SB)
RET
diff --git a/src/runtime/stkframe.go b/src/runtime/stkframe.go
index a2f40c92d5..becb729e59 100644
--- a/src/runtime/stkframe.go
+++ b/src/runtime/stkframe.go
@@ -234,7 +234,7 @@ func (frame *stkframe) getStackMap(debug bool) (locals, args bitvector, objs []s
}
// stack objects.
- if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
+ if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
unsafe.Sizeof(abi.RegArgs{}) > 0 && isReflect {
// For reflect.makeFuncStub and reflect.methodValueCall,
// we need to fake the stack object record.