Skip to content

Commit 36a2b09

Browse files
committed
Backup only the lower 128bits of the XMM callee save registers on Windows
1 parent 396dbc7 commit 36a2b09

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/alloc/SaveCalleeSaveRegisters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ private static RegisterMap<AllocatableValue> saveAtEntry(LIR lir, LIRGeneratorTo
7979
List<Register> allocatables = lirGenRes.getRegisterConfig().getAllocatableRegisters();
8080
RegisterMap<AllocatableValue> saveMap = new RegisterMap<>(arch);
8181
for (Register register : calleeSaveRegisters) {
82-
PlatformKind registerPlatformKind = arch.getLargestStorableKind(register.getRegisterCategory());
82+
PlatformKind registerPlatformKind = lirGenRes.getRegisterConfig().getCalleeSaveRegisterStorageKind(arch, register);
8383
LIRKind lirKind = LIRKind.value(registerPlatformKind);
8484
RegisterValue registerValue = register.asValue(lirKind);
85+
// Force a non-allocatable register to be saved to a stack slot
86+
// so as to avoid unnecessary register pressure.
8587
AllocatableValue saveVariable = allocatables.contains(registerValue.getRegister()) ? lirGen.newVariable(lirKind) : lirGenRes.getFrameMapBuilder().allocateSpillSlot(lirKind);
8688
LIRInstruction save = lirGen.getSpillMoveFactory().createMove(saveVariable, registerValue);
8789
buffer.append(insertionIndex, save);

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import static jdk.vm.ci.amd64.AMD64.xmm7;
6565
import static jdk.vm.ci.amd64.AMD64.xmm8;
6666
import static jdk.vm.ci.amd64.AMD64.xmm9;
67+
import static jdk.vm.ci.amd64.AMD64Kind.V128_QWORD;
6768

6869
import java.util.ArrayList;
6970
import java.util.Arrays;
@@ -87,6 +88,7 @@
8788
import jdk.graal.compiler.core.common.LIRKind;
8889
import jdk.vm.ci.amd64.AMD64;
8990
import jdk.vm.ci.amd64.AMD64Kind;
91+
import jdk.vm.ci.code.Architecture;
9092
import jdk.vm.ci.code.CallingConvention;
9193
import jdk.vm.ci.code.CallingConvention.Type;
9294
import jdk.vm.ci.code.Register;
@@ -239,6 +241,15 @@ public List<Register> getCalleeSaveRegisters() {
239241
return calleeSaveRegisters;
240242
}
241243

244+
@Override
245+
public PlatformKind getCalleeSaveRegisterStorageKind(Architecture arch, Register calleeSaveRegister) {
246+
if (Platform.includedIn(Platform.WINDOWS.class) && AMD64.XMM.equals(calleeSaveRegister.getRegisterCategory())) {
247+
VMError.guarantee(calleeSaveRegister.encoding() >= xmm6.encoding() && calleeSaveRegister.encoding() <= xmm15.encoding(), "unexpected callee saved register");
248+
return V128_QWORD;
249+
}
250+
return SubstrateRegisterConfig.super.getCalleeSaveRegisterStorageKind(arch, calleeSaveRegister);
251+
}
252+
242253
@Override
243254
public List<Register> getCallerSaveRegisters() {
244255
return getAllocatableRegisters();
@@ -410,7 +421,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
410421
kinds = Arrays.copyOf(kinds, kinds.length + 1);
411422
locations = Arrays.copyOf(locations, locations.length + 1);
412423
kinds[kinds.length - 1] = JavaKind.Int;
413-
locations[locations.length - 1] = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD));
424+
locations[locations.length - 1] = rax.asValue(LIRKind.value(AMD64Kind.DWORD));
414425
if (type.customABI()) {
415426
var extendsParametersAssignment = Arrays.copyOf(type.fixedParameterAssignment, type.fixedParameterAssignment.length + 1);
416427
extendsParametersAssignment[extendsParametersAssignment.length - 1] = AssignedLocation.forRegister(rax, JavaKind.Long);

0 commit comments

Comments
 (0)