001/*
002 * Copyright (c) 2015, 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.compiler.common;
024
025import static com.oracle.graal.compiler.common.BackendOptions.UserOptions.*;
026import static com.oracle.graal.compiler.common.GraalOptions.*;
027import jdk.internal.jvmci.options.*;
028import jdk.internal.jvmci.options.DerivedOptionValue.OptionSupplier;
029
030/**
031 * Options to control the backend configuration.
032 */
033public final class BackendOptions {
034
035    public static class UserOptions {
036        // @formatter:off
037        @Option(help = "Destruct SSA LIR eagerly (before other LIR phases).", type = OptionType.Debug)
038        public static final OptionValue<Boolean> LIREagerSSADestruction = new OptionValue<>(false);
039        @Option(help = "Enable Linear Scan on SSI form.", type = OptionType.Debug)
040        public static final OptionValue<Boolean> LIROptSSILinearScan = new OptionValue<>(false);
041        @Option(help = "Enable experimental Trace Register Allocation.", type = OptionType.Debug)
042        public static final OptionValue<Boolean> TraceRA = new OptionValue<>(false);
043        // @formatter:on
044    }
045
046    /* Enable SSI Construction. */
047    public static final DerivedOptionValue<Boolean> EnableSSIConstruction = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
048        private static final long serialVersionUID = -7375589337502162545L;
049
050        public Boolean get() {
051            return LIROptSSILinearScan.getValue() || TraceRA.getValue();
052        }
053    });
054
055    /* Create SSA LIR during LIR generation. */
056    public static final DerivedOptionValue<Boolean> ConstructionSSAlirDuringLirBuilding = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
057        private static final long serialVersionUID = 7657622005438210681L;
058
059        public Boolean get() {
060            return SSA_LIR.getValue() || EnableSSIConstruction.getValue();
061        }
062    });
063
064    public enum LSRAVariant {
065        NONSSA_LSAR,
066        SSA_LSRA,
067        SSI_LSRA
068    }
069
070    public static final DerivedOptionValue<LSRAVariant> LinearScanVariant = new DerivedOptionValue<>(new OptionSupplier<LSRAVariant>() {
071        private static final long serialVersionUID = 364925071685235153L;
072
073        public LSRAVariant get() {
074            if (LIROptSSILinearScan.getValue()) {
075                return LSRAVariant.SSI_LSRA;
076            }
077            if (SSA_LIR.getValue() && !LIREagerSSADestruction.getValue()) {
078                return LSRAVariant.SSA_LSRA;
079            }
080            return LSRAVariant.NONSSA_LSAR;
081        }
082    });
083
084    /* Does the backend emit stack to stack moves?. */
085    public static final DerivedOptionValue<Boolean> ShouldOptimizeStackToStackMoves = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
086        private static final long serialVersionUID = 2366072840509944317L;
087
088        public Boolean get() {
089            switch (LinearScanVariant.getValue()) {
090                case SSA_LSRA:
091                case SSI_LSRA:
092                    return true;
093            }
094            if (TraceRA.getValue()) {
095                return true;
096            }
097            return false;
098        }
099    });
100
101}