1 /* 2 * Copyright (c) 2014, 2018, 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 26 package org.graalvm.compiler.hotspot.aarch64; 27 28 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; 29 import org.graalvm.compiler.debug.DebugHandlersFactory; 30 import org.graalvm.compiler.graph.Node; 31 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 32 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 33 import org.graalvm.compiler.hotspot.meta.DefaultHotSpotLoweringProvider; 34 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 35 import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider; 36 import org.graalvm.compiler.nodes.calc.FloatConvertNode; 37 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode; 38 import org.graalvm.compiler.nodes.calc.RemNode; 39 import org.graalvm.compiler.nodes.spi.LoweringTool; 40 import org.graalvm.compiler.options.OptionValues; 41 import org.graalvm.compiler.replacements.aarch64.AArch64FloatArithmeticSnippets; 42 import org.graalvm.compiler.replacements.aarch64.AArch64IntegerArithmeticSnippets; 43 44 import jdk.vm.ci.code.TargetDescription; 45 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; 46 import jdk.vm.ci.meta.MetaAccessProvider; 47 48 public class AArch64HotSpotLoweringProvider extends DefaultHotSpotLoweringProvider { 49 50 private AArch64IntegerArithmeticSnippets integerArithmeticSnippets; 51 private AArch64FloatArithmeticSnippets floatArithmeticSnippets; 52 53 public AArch64HotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, 54 HotSpotConstantReflectionProvider constantReflection, TargetDescription target) { 55 super(runtime, metaAccess, foreignCalls, registers, constantReflection, target); 56 } 57 58 @Override 59 public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) { 60 integerArithmeticSnippets = new AArch64IntegerArithmeticSnippets(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget()); 61 floatArithmeticSnippets = new AArch64FloatArithmeticSnippets(options, factories, providers, providers.getSnippetReflection(), providers.getCodeCache().getTarget()); 62 super.initialize(options, factories, providers, config); 63 } 64 65 @Override 66 public void lower(Node n, LoweringTool tool) { 67 if (n instanceof IntegerDivRemNode) { 68 integerArithmeticSnippets.lower((IntegerDivRemNode) n, tool); 69 } else if (n instanceof RemNode) { 70 floatArithmeticSnippets.lower((RemNode) n, tool); 71 } else if (n instanceof FloatConvertNode) { 72 // AMD64 has custom lowerings for ConvertNodes, HotSpotLoweringProvider does not expect 73 // to see a ConvertNode and throws an error, just do nothing here. 74 } else { 75 super.lower(n, tool); 76 } 77 } 78 }