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