001/*
002 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.replacements.sparc;
024
025import jdk.internal.jvmci.meta.*;
026import static com.oracle.graal.compiler.target.Backend.*;
027
028import com.oracle.graal.compiler.common.spi.*;
029import com.oracle.graal.graphbuilderconf.*;
030import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
031import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration;
032import com.oracle.graal.replacements.*;
033
034public class SPARCGraphBuilderPlugins {
035
036    public static void register(Plugins plugins, ForeignCallsProvider foreignCalls) {
037        InvocationPlugins invocationPlugins = plugins.getInvocationPlugins();
038        registerIntegerLongPlugins(invocationPlugins, IntegerSubstitutions.class, Kind.Int);
039        registerIntegerLongPlugins(invocationPlugins, LongSubstitutions.class, Kind.Long);
040        registerMathPlugins(invocationPlugins, foreignCalls);
041    }
042
043    private static void registerIntegerLongPlugins(InvocationPlugins plugins, Class<?> substituteDeclaringClass, Kind kind) {
044        Class<?> declaringClass = kind.toBoxedJavaClass();
045        Class<?> type = kind.toJavaClass();
046        Registration r = new Registration(plugins, declaringClass);
047        r.registerMethodSubstitution(substituteDeclaringClass, "numberOfLeadingZeros", type);
048        r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type);
049    }
050
051    private static void registerMathPlugins(InvocationPlugins plugins, ForeignCallsProvider foreignCalls) {
052        Registration r = new Registration(plugins, Math.class);
053        r.register1("sin", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_SIN));
054        r.register1("cos", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_COS));
055        r.register1("tan", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_TAN));
056        r.register1("exp", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_EXP));
057        r.register1("log", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_LOG));
058        r.register1("log10", Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_LOG10));
059        r.register2("pow", Double.TYPE, Double.TYPE, new ForeignCallPlugin(foreignCalls, ARITHMETIC_POW));
060    }
061}