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 package org.graalvm.compiler.core.sparc; 25 26 import static jdk.vm.ci.sparc.SPARCKind.BYTE; 27 import static jdk.vm.ci.sparc.SPARCKind.HWORD; 28 import static jdk.vm.ci.sparc.SPARCKind.WORD; 29 import static jdk.vm.ci.sparc.SPARCKind.XWORD; 30 31 import org.graalvm.compiler.core.common.LIRKind; 32 import org.graalvm.compiler.core.gen.NodeMatchRules; 33 import org.graalvm.compiler.core.match.ComplexMatchResult; 34 import org.graalvm.compiler.core.match.MatchRule; 35 import org.graalvm.compiler.debug.GraalError; 36 import org.graalvm.compiler.lir.LIRFrameState; 37 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 38 import org.graalvm.compiler.nodes.DeoptimizingNode; 39 import org.graalvm.compiler.nodes.calc.SignExtendNode; 40 import org.graalvm.compiler.nodes.calc.ZeroExtendNode; 41 import org.graalvm.compiler.nodes.memory.Access; 42 43 import jdk.vm.ci.sparc.SPARCKind; 44 45 /** 46 * This class implements the SPARC specific portion of the LIR generator. 47 */ 48 public class SPARCNodeMatchRules extends NodeMatchRules { 49 50 public SPARCNodeMatchRules(LIRGeneratorTool gen) { 51 super(gen); 52 } 53 54 protected LIRFrameState getState(Access access) { 55 if (access instanceof DeoptimizingNode) { 56 return state((DeoptimizingNode) access); 57 } 58 return null; 59 } 60 61 private ComplexMatchResult emitSignExtendMemory(Access access, int fromBits, int toBits) { 62 assert fromBits <= toBits && toBits <= 64; 63 SPARCKind toKind = null; 64 SPARCKind fromKind = null; 65 if (fromBits == toBits) { 66 return null; 67 } 68 toKind = toBits > 32 ? XWORD : WORD; 69 switch (fromBits) { 70 case 8: 71 fromKind = BYTE; 72 break; 73 case 16: 74 fromKind = HWORD; 75 break; 76 case 32: 77 fromKind = WORD; 78 break; 79 default: 80 throw GraalError.unimplemented("unsupported sign extension (" + fromBits + " bit -> " + toBits + " bit)"); 110 SPARCKind localFromKind = fromKind; 111 SPARCKind localToKind = toKind; 112 return builder -> { 113 // Loads are always zero extending load 114 return getLIRGeneratorTool().emitZeroExtendLoad(LIRKind.value(localFromKind), LIRKind.value(localToKind), operand(access.getAddress()), getState(access)); 115 }; 116 } 117 118 @MatchRule("(SignExtend Read=access)") 119 @MatchRule("(SignExtend FloatingRead=access)") 120 public ComplexMatchResult signExtend(SignExtendNode root, Access access) { 121 return emitSignExtendMemory(access, root.getInputBits(), root.getResultBits()); 122 } 123 124 @MatchRule("(ZeroExtend Read=access)") 125 @MatchRule("(ZeroExtend FloatingRead=access)") 126 public ComplexMatchResult zeroExtend(ZeroExtendNode root, Access access) { 127 return emitZeroExtendMemory(access, root.getInputBits(), root.getResultBits()); 128 } 129 130 @Override 131 public SPARCLIRGenerator getLIRGeneratorTool() { 132 return (SPARCLIRGenerator) super.getLIRGeneratorTool(); 133 } 134 135 protected SPARCArithmeticLIRGenerator getArithmeticLIRGenerator() { 136 return (SPARCArithmeticLIRGenerator) getLIRGeneratorTool().getArithmetic(); 137 } 138 } | 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 package org.graalvm.compiler.core.sparc; 25 26 import static jdk.vm.ci.sparc.SPARCKind.BYTE; 27 import static jdk.vm.ci.sparc.SPARCKind.HWORD; 28 import static jdk.vm.ci.sparc.SPARCKind.WORD; 29 import static jdk.vm.ci.sparc.SPARCKind.XWORD; 30 31 import org.graalvm.compiler.core.common.LIRKind; 32 import org.graalvm.compiler.core.common.calc.Condition; 33 import org.graalvm.compiler.core.gen.NodeMatchRules; 34 import org.graalvm.compiler.core.match.ComplexMatchResult; 35 import org.graalvm.compiler.core.match.MatchRule; 36 import org.graalvm.compiler.debug.GraalError; 37 import org.graalvm.compiler.lir.LIRFrameState; 38 import org.graalvm.compiler.lir.LabelRef; 39 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 40 import org.graalvm.compiler.lir.sparc.SPARCAddressValue; 41 import org.graalvm.compiler.nodes.DeoptimizingNode; 42 import org.graalvm.compiler.nodes.IfNode; 43 import org.graalvm.compiler.nodes.ValueNode; 44 import org.graalvm.compiler.nodes.calc.CompareNode; 45 import org.graalvm.compiler.nodes.calc.SignExtendNode; 46 import org.graalvm.compiler.nodes.calc.ZeroExtendNode; 47 import org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode; 48 import org.graalvm.compiler.nodes.memory.Access; 49 import org.graalvm.compiler.nodes.memory.LIRLowerableAccess; 50 51 import jdk.vm.ci.meta.JavaConstant; 52 import jdk.vm.ci.meta.Value; 53 import jdk.vm.ci.sparc.SPARCKind; 54 55 /** 56 * This class implements the SPARC specific portion of the LIR generator. 57 */ 58 public class SPARCNodeMatchRules extends NodeMatchRules { 59 60 public SPARCNodeMatchRules(LIRGeneratorTool gen) { 61 super(gen); 62 } 63 64 protected LIRFrameState getState(Access access) { 65 if (access instanceof DeoptimizingNode) { 66 return state((DeoptimizingNode) access); 67 } 68 return null; 69 } 70 71 protected LIRKind getLirKind(LIRLowerableAccess access) { 72 return gen.getLIRKind(access.getAccessStamp()); 73 } 74 75 private ComplexMatchResult emitSignExtendMemory(Access access, int fromBits, int toBits) { 76 assert fromBits <= toBits && toBits <= 64; 77 SPARCKind toKind = null; 78 SPARCKind fromKind = null; 79 if (fromBits == toBits) { 80 return null; 81 } 82 toKind = toBits > 32 ? XWORD : WORD; 83 switch (fromBits) { 84 case 8: 85 fromKind = BYTE; 86 break; 87 case 16: 88 fromKind = HWORD; 89 break; 90 case 32: 91 fromKind = WORD; 92 break; 93 default: 94 throw GraalError.unimplemented("unsupported sign extension (" + fromBits + " bit -> " + toBits + " bit)"); 124 SPARCKind localFromKind = fromKind; 125 SPARCKind localToKind = toKind; 126 return builder -> { 127 // Loads are always zero extending load 128 return getLIRGeneratorTool().emitZeroExtendLoad(LIRKind.value(localFromKind), LIRKind.value(localToKind), operand(access.getAddress()), getState(access)); 129 }; 130 } 131 132 @MatchRule("(SignExtend Read=access)") 133 @MatchRule("(SignExtend FloatingRead=access)") 134 public ComplexMatchResult signExtend(SignExtendNode root, Access access) { 135 return emitSignExtendMemory(access, root.getInputBits(), root.getResultBits()); 136 } 137 138 @MatchRule("(ZeroExtend Read=access)") 139 @MatchRule("(ZeroExtend FloatingRead=access)") 140 public ComplexMatchResult zeroExtend(ZeroExtendNode root, Access access) { 141 return emitZeroExtendMemory(access, root.getInputBits(), root.getResultBits()); 142 } 143 144 @MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))") 145 @MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))") 146 @MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))") 147 @MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))") 148 public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) { 149 JavaConstant constant = value.asJavaConstant(); 150 assert compare.condition() == Condition.EQ; 151 if (constant != null && cas.usages().count() == 1) { 152 long constantValue = constant.asLong(); 153 boolean successIsTrue; 154 if (constantValue == 0) { 155 successIsTrue = false; 156 } else if (constantValue == 1) { 157 successIsTrue = true; 158 } else { 159 return null; 160 } 161 return builder -> { 162 LIRKind kind = getLirKind(cas); 163 LabelRef trueLabel = getLIRBlock(root.trueSuccessor()); 164 LabelRef falseLabel = getLIRBlock(root.falseSuccessor()); 165 double trueLabelProbability = root.probability(root.trueSuccessor()); 166 Value expectedValue = operand(cas.getExpectedValue()); 167 Value newValue = operand(cas.getNewValue()); 168 SPARCAddressValue address = (SPARCAddressValue) operand(cas.getAddress()); 169 Condition condition = successIsTrue ? Condition.EQ : Condition.NE; 170 171 Value result = getLIRGeneratorTool().emitValueCompareAndSwap(address, expectedValue, newValue); 172 getLIRGeneratorTool().emitCompareBranch(kind.getPlatformKind(), result, expectedValue, condition, false, trueLabel, falseLabel, trueLabelProbability); 173 return null; 174 }; 175 } 176 return null; 177 } 178 179 @Override 180 public SPARCLIRGenerator getLIRGeneratorTool() { 181 return (SPARCLIRGenerator) super.getLIRGeneratorTool(); 182 } 183 184 protected SPARCArithmeticLIRGenerator getArithmeticLIRGenerator() { 185 return (SPARCArithmeticLIRGenerator) getLIRGeneratorTool().getArithmetic(); 186 } 187 } |