1 /* 2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.lir.sparc; 26 27 import static jdk.vm.ci.code.ValueUtil.asStackSlot; 28 import static jdk.vm.ci.code.ValueUtil.isStackSlot; 29 import static org.graalvm.compiler.lir.sparc.SPARCDelayedControlTransfer.DUMMY; 30 31 import jdk.internal.vm.compiler.collections.EconomicSet; 32 import org.graalvm.compiler.asm.sparc.SPARCAddress; 33 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler; 34 import org.graalvm.compiler.lir.LIRInstructionClass; 35 import org.graalvm.compiler.lir.Opcode; 36 import org.graalvm.compiler.lir.StandardOp.SaveRegistersOp; 37 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 38 39 import jdk.vm.ci.code.Register; 40 import jdk.vm.ci.code.RegisterValue; 41 import jdk.vm.ci.code.StackSlot; 42 import jdk.vm.ci.meta.AllocatableValue; 43 import jdk.vm.ci.sparc.SPARC; 44 45 /** 46 * Saves registers to stack slots. 47 */ 48 @Opcode("SAVE_REGISTER") 49 public class SPARCSaveRegistersOp extends SaveRegistersOp implements SPARCLIRInstructionMixin { 50 public static final LIRInstructionClass<SPARCSaveRegistersOp> TYPE = LIRInstructionClass.create(SPARCSaveRegistersOp.class); 51 public static final Register RETURN_REGISTER_STORAGE = SPARC.d62; 52 public static final SizeEstimate SIZE = SizeEstimate.create(32); 53 private final SPARCLIRInstructionMixinStore store; 54 55 /** 56 * 57 * @param savedRegisters the registers saved by this operation which may be subject to 58 * {@linkplain #remove(EconomicSet) pruning} 59 * @param savedRegisterLocations the slots to which the registers are saved 60 */ 61 public SPARCSaveRegistersOp(Register[] savedRegisters, AllocatableValue[] savedRegisterLocations) { 62 super(TYPE, savedRegisters, savedRegisterLocations); 63 this.store = new SPARCLIRInstructionMixinStore(SIZE); 64 } 65 66 @Override 67 public void emitCode(CompilationResultBuilder crb) { 68 SPARCMacroAssembler masm = (SPARCMacroAssembler) crb.asm; 69 // Can be used with VIS3 70 // new Movxtod(SPARC.i0, RETURN_REGISTER_STORAGE).emit(masm); 71 // We abuse the first stackslot for transferring i0 to return_register_storage 72 // assert slots.length >= 1; 73 SPARCAddress slot0Address = (SPARCAddress) crb.asAddress(slots[0]); 74 masm.stx(SPARC.i0, slot0Address); 75 masm.lddf(slot0Address, RETURN_REGISTER_STORAGE); 76 77 // Now save the registers 78 for (int i = 0; i < savedRegisters.length; i++) { 79 if (savedRegisters[i] != null) { 80 assert isStackSlot(slots[i]) : "not a StackSlot: " + slots[i]; 81 Register savedRegister = savedRegisters[i]; 82 StackSlot slot = asStackSlot(slots[i]); 83 SPARCAddress slotAddress = (SPARCAddress) crb.asAddress(slot); 84 RegisterValue input = savedRegister.asValue(slot.getValueKind()); 85 SPARCMove.emitStore(input, slotAddress, slot.getPlatformKind(), DUMMY, null, crb, masm); 86 } 87 } 88 } 89 90 @Override 91 public SPARCLIRInstructionMixinStore getSPARCLIRInstructionStore() { 92 return store; 93 } 94 }