1 /* 2 * Copyright (c) 2015, 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 package org.graalvm.compiler.core.aarch64; 25 26 import org.graalvm.compiler.core.gen.NodeMatchRules; 27 import org.graalvm.compiler.core.match.ComplexMatchResult; 28 import org.graalvm.compiler.core.match.MatchRule; 29 import org.graalvm.compiler.lir.LIRFrameState; 30 import org.graalvm.compiler.lir.aarch64.AArch64AddressValue; 31 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 32 import org.graalvm.compiler.nodes.DeoptimizingNode; 33 import org.graalvm.compiler.nodes.calc.SignExtendNode; 34 import org.graalvm.compiler.nodes.calc.ZeroExtendNode; 35 import org.graalvm.compiler.nodes.memory.Access; 36 37 import jdk.vm.ci.aarch64.AArch64Kind; 38 39 public class AArch64NodeMatchRules extends NodeMatchRules { 40 41 public AArch64NodeMatchRules(LIRGeneratorTool gen) { 42 super(gen); 43 } 44 45 protected LIRFrameState getState(Access access) { 46 if (access instanceof DeoptimizingNode) { 47 return state((DeoptimizingNode) access); 48 } 49 return null; 50 } 51 52 protected AArch64Kind getMemoryKind(Access access) { 53 return (AArch64Kind) gen.getLIRKind(access.asNode().stamp()).getPlatformKind(); 54 } 55 56 @Override 57 public AArch64LIRGenerator getLIRGeneratorTool() { 58 return (AArch64LIRGenerator) gen; 59 } 60 61 protected AArch64ArithmeticLIRGenerator getArithmeticLIRGenerator() { 62 return (AArch64ArithmeticLIRGenerator) getLIRGeneratorTool().getArithmetic(); 63 } 64 65 @MatchRule("(ZeroExtend Read=access)") 66 @MatchRule("(ZeroExtend FloatingRead=access)") 67 public ComplexMatchResult zeroExtend(ZeroExtendNode root, Access access) { 68 AArch64Kind memoryKind = getMemoryKind(access); 69 return builder -> getArithmeticLIRGenerator().emitExtendMemory(false, memoryKind, root.getResultBits(), (AArch64AddressValue) operand(access.getAddress()), getState(access)); 70 } 71 72 @MatchRule("(SignExtend Read=access)") 73 @MatchRule("(SignExtend FloatingRead=access)") 74 public ComplexMatchResult signExtend(SignExtendNode root, Access access) { 75 AArch64Kind memoryKind = getMemoryKind(access); 76 return builder -> getArithmeticLIRGenerator().emitExtendMemory(true, memoryKind, root.getResultBits(), (AArch64AddressValue) operand(access.getAddress()), getState(access)); 77 } 78 }