1 /* 2 * Copyright (c) 2013, 2016, 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 package org.graalvm.compiler.hotspot.sparc; 24 25 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.BPR; 26 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.Annul.ANNUL; 27 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.BranchPredict.PREDICT_TAKEN; 28 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.RCondition.Rc_z; 29 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL; 30 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG; 31 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK; 32 import static org.graalvm.compiler.lir.sparc.SPARCMove.loadFromConstantTable; 33 import static jdk.vm.ci.code.ValueUtil.asRegister; 34 35 import org.graalvm.compiler.asm.Label; 36 import org.graalvm.compiler.asm.sparc.SPARCAddress; 37 import org.graalvm.compiler.asm.sparc.SPARCAssembler.CC; 38 import org.graalvm.compiler.asm.sparc.SPARCAssembler.ConditionFlag; 39 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler; 40 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler.ScratchRegister; 41 import org.graalvm.compiler.core.common.CompressEncoding; 42 import org.graalvm.compiler.lir.LIRInstructionClass; 43 import org.graalvm.compiler.lir.StandardOp.LoadConstantOp; 44 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 45 import org.graalvm.compiler.lir.sparc.SPARCDelayedControlTransfer; 46 import org.graalvm.compiler.lir.sparc.SPARCLIRInstruction; 47 import org.graalvm.compiler.lir.sparc.SPARCTailDelayedLIRInstruction; 48 49 import jdk.vm.ci.code.Register; 50 import jdk.vm.ci.code.ValueUtil; 51 import jdk.vm.ci.hotspot.HotSpotConstant; 52 import jdk.vm.ci.meta.AllocatableValue; 53 import jdk.vm.ci.meta.Constant; 54 55 public class SPARCHotSpotMove { 56 57 public static class LoadHotSpotObjectConstantInline extends SPARCLIRInstruction implements SPARCTailDelayedLIRInstruction, LoadConstantOp { 58 public static final LIRInstructionClass<LoadHotSpotObjectConstantInline> TYPE = LIRInstructionClass.create(LoadHotSpotObjectConstantInline.class); 59 60 public static final SizeEstimate SIZE = SizeEstimate.create(8); 61 private HotSpotConstant constant; 62 @Def({REG, STACK}) AllocatableValue result; 63 64 public LoadHotSpotObjectConstantInline(HotSpotConstant constant, AllocatableValue result) { 65 super(TYPE, SIZE); 66 this.constant = constant; 67 this.result = result; 68 } 69 70 @Override 71 protected void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 72 crb.recordInlineDataInCode(constant); 73 if (constant.isCompressed()) { 74 masm.setw(0, asRegister(result), true); 75 } else { 76 masm.setx(0, asRegister(result), true); 77 } 78 } 79 80 @Override 81 public AllocatableValue getResult() { 82 return result; 83 } 84 85 @Override 86 public Constant getConstant() { 87 return constant; 88 } 89 } 90 91 public static class LoadHotSpotObjectConstantFromTable extends SPARCLIRInstruction implements SPARCTailDelayedLIRInstruction { 92 public static final LIRInstructionClass<LoadHotSpotObjectConstantFromTable> TYPE = LIRInstructionClass.create(LoadHotSpotObjectConstantFromTable.class); 93 94 public static final SizeEstimate SIZE = SizeEstimate.create(2, 8); 95 private final HotSpotConstant constant; 96 @Use({REG}) private AllocatableValue constantTableBase; 97 @Def({REG, STACK}) AllocatableValue result; 98 99 public LoadHotSpotObjectConstantFromTable(HotSpotConstant constant, AllocatableValue result, AllocatableValue constantTableBase) { 100 super(TYPE, SIZE); 101 this.constant = constant; 102 this.result = result; 103 this.constantTableBase = constantTableBase; 104 } 105 106 @Override 107 protected void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 108 try (ScratchRegister scratch = masm.getScratchRegister()) { 109 boolean isStack = ValueUtil.isStackSlot(result); 110 Register register; 111 if (isStack) { 112 register = scratch.getRegister(); 113 } else { 114 register = asRegister(result); 115 } 116 int bytes = loadFromConstantTable(crb, masm, asRegister(constantTableBase), constant, register, SPARCDelayedControlTransfer.DUMMY); 117 if (isStack) { 118 masm.st(register, (SPARCAddress) crb.asAddress(result), bytes); 119 } 120 } 121 } 122 } 123 124 public static final class CompressPointer extends SPARCLIRInstruction { 125 public static final LIRInstructionClass<CompressPointer> TYPE = LIRInstructionClass.create(CompressPointer.class); 126 public static final SizeEstimate SIZE = SizeEstimate.create(5); 127 128 private final CompressEncoding encoding; 129 private final boolean nonNull; 130 131 @Def({REG}) protected AllocatableValue result; 132 @Use({REG}) protected AllocatableValue input; 133 @Alive({REG, ILLEGAL}) protected AllocatableValue baseRegister; 134 135 public CompressPointer(AllocatableValue result, AllocatableValue input, AllocatableValue baseRegister, CompressEncoding encoding, boolean nonNull) { 136 super(TYPE, SIZE); 137 this.result = result; 138 this.input = input; 139 this.baseRegister = baseRegister; 140 this.encoding = encoding; 141 this.nonNull = nonNull; 142 } 143 144 @Override 145 public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 146 Register inputRegister = asRegister(input); 147 Register resReg = asRegister(result); 148 if (encoding.hasBase()) { 149 Register baseReg = asRegister(baseRegister); 150 if (!nonNull) { 151 masm.cmp(inputRegister, baseReg); 152 masm.movcc(ConditionFlag.Equal, CC.Xcc, baseReg, resReg); 153 masm.sub(resReg, baseReg, resReg); 154 } else { 155 masm.sub(inputRegister, baseReg, resReg); 156 } 157 if (encoding.getShift() != 0) { 158 masm.srlx(resReg, encoding.getShift(), resReg); 159 } 160 } else { 161 masm.srlx(inputRegister, encoding.getShift(), resReg); 162 } 163 } 164 } 165 166 public static final class UncompressPointer extends SPARCLIRInstruction { 167 public static final LIRInstructionClass<UncompressPointer> TYPE = LIRInstructionClass.create(UncompressPointer.class); 168 public static final SizeEstimate SIZE = SizeEstimate.create(4); 169 170 private final CompressEncoding encoding; 171 private final boolean nonNull; 172 173 @Def({REG}) protected AllocatableValue result; 174 @Use({REG}) protected AllocatableValue input; 175 @Alive({REG, ILLEGAL}) protected AllocatableValue baseRegister; 176 177 public UncompressPointer(AllocatableValue result, AllocatableValue input, AllocatableValue baseRegister, CompressEncoding encoding, boolean nonNull) { 178 super(TYPE, SIZE); 179 this.result = result; 180 this.input = input; 181 this.baseRegister = baseRegister; 182 this.encoding = encoding; 183 this.nonNull = nonNull; 184 } 185 186 @Override 187 public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 188 Register inputRegister = asRegister(input); 189 Register resReg = asRegister(result); 190 Register secondaryInput; 191 if (encoding.getShift() != 0) { 192 masm.sll(inputRegister, encoding.getShift(), resReg); 193 secondaryInput = resReg; 194 } else { 195 secondaryInput = inputRegister; 196 } 197 198 if (encoding.hasBase()) { 199 if (nonNull) { 200 masm.add(secondaryInput, asRegister(baseRegister), resReg); 201 } else { 202 Label done = new Label(); 203 BPR.emit(masm, Rc_z, ANNUL, PREDICT_TAKEN, secondaryInput, done); 204 masm.add(asRegister(baseRegister), secondaryInput, resReg); 205 masm.bind(done); 206 } 207 } 208 } 209 } 210 211 }