001/*
002 * Copyright (c) 2012, 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.java;
024
025import jdk.internal.jvmci.options.*;
026import jdk.internal.jvmci.options.DerivedOptionValue.*;
027
028import com.oracle.graal.graphbuilderconf.*;
029import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
030import com.oracle.graal.lir.phases.*;
031import com.oracle.graal.phases.*;
032import com.oracle.graal.phases.tiers.*;
033
034public class DefaultSuitesProvider implements SuitesProvider {
035
036    private final DerivedOptionValue<Suites> defaultSuites;
037    private final PhaseSuite<HighTierContext> defaultGraphBuilderSuite;
038    private final DerivedOptionValue<LIRSuites> defaultLIRSuites;
039
040    private class SuitesSupplier implements OptionSupplier<Suites> {
041
042        private static final long serialVersionUID = 2677805381215454728L;
043
044        public Suites get() {
045            return createSuites();
046        }
047
048    }
049
050    private class LIRSuitesSupplier implements OptionSupplier<LIRSuites> {
051
052        private static final long serialVersionUID = 312070237227476252L;
053
054        public LIRSuites get() {
055            return createLIRSuites();
056        }
057
058    }
059
060    public DefaultSuitesProvider(Plugins plugins) {
061        this.defaultGraphBuilderSuite = createGraphBuilderSuite(plugins);
062        this.defaultSuites = new DerivedOptionValue<>(new SuitesSupplier());
063        this.defaultLIRSuites = new DerivedOptionValue<>(new LIRSuitesSupplier());
064    }
065
066    public Suites getDefaultSuites() {
067        return defaultSuites.getValue();
068    }
069
070    public Suites createSuites() {
071        return Suites.createDefaultSuites();
072    }
073
074    public PhaseSuite<HighTierContext> getDefaultGraphBuilderSuite() {
075        return defaultGraphBuilderSuite;
076    }
077
078    protected PhaseSuite<HighTierContext> createGraphBuilderSuite(Plugins plugins) {
079        PhaseSuite<HighTierContext> suite = new PhaseSuite<>();
080        suite.appendPhase(new GraphBuilderPhase(GraphBuilderConfiguration.getDefault(plugins)));
081        return suite;
082    }
083
084    public LIRSuites getDefaultLIRSuites() {
085        return defaultLIRSuites.getValue();
086    }
087
088    public LIRSuites createLIRSuites() {
089        return Suites.createDefaultLIRSuites();
090    }
091
092}