1 /*
   2  * Copyright (c) 2015, 2016, 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 package org.graalvm.compiler.lir.phases;
  24 
  25 import static org.graalvm.compiler.lir.phases.LIRPhase.Options.LIROptimization;
  26 
  27 import org.graalvm.compiler.lir.ControlFlowOptimizer;
  28 import org.graalvm.compiler.lir.EdgeMoveOptimizer;
  29 import org.graalvm.compiler.lir.NullCheckOptimizer;
  30 import org.graalvm.compiler.lir.RedundantMoveElimination;
  31 import org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase.PostAllocationOptimizationContext;
  32 import org.graalvm.compiler.lir.profiling.MethodProfilingPhase;
  33 import org.graalvm.compiler.lir.profiling.MoveProfilingPhase;
  34 import org.graalvm.compiler.options.NestedBooleanOptionKey;
  35 import org.graalvm.compiler.options.Option;
  36 import org.graalvm.compiler.options.OptionKey;
  37 import org.graalvm.compiler.options.OptionType;
  38 import org.graalvm.compiler.options.OptionValues;
  39 
  40 public class PostAllocationOptimizationStage extends LIRPhaseSuite<PostAllocationOptimizationContext> {
  41     public static class Options {
  42         // @formatter:off
  43         @Option(help = "", type = OptionType.Debug)
  44         public static final NestedBooleanOptionKey LIROptEdgeMoveOptimizer = new NestedBooleanOptionKey(LIROptimization, true);
  45         @Option(help = "", type = OptionType.Debug)
  46         public static final NestedBooleanOptionKey LIROptControlFlowOptimizer = new NestedBooleanOptionKey(LIROptimization, true);
  47         @Option(help = "", type = OptionType.Debug)
  48         public static final NestedBooleanOptionKey LIROptRedundantMoveElimination = new NestedBooleanOptionKey(LIROptimization, true);
  49         @Option(help = "", type = OptionType.Debug)
  50         public static final NestedBooleanOptionKey LIROptNullCheckOptimizer = new NestedBooleanOptionKey(LIROptimization, true);
  51         @Option(help = "Enables profiling of move types on LIR level. " +
  52                        "Move types are for example stores (register to stack), " +
  53                        "constant loads (constant to register) or copies (register to register).", type = OptionType.Debug)
  54         public static final OptionKey<Boolean> LIRProfileMoves = new OptionKey<>(false);
  55         @Option(help = "Enables profiling of methods.", type = OptionType.Debug)
  56         public static final OptionKey<Boolean> LIRProfileMethods = new OptionKey<>(false);
  57         // @formatter:on
  58     }
  59 
  60     public PostAllocationOptimizationStage(OptionValues options) {
  61         if (Options.LIROptEdgeMoveOptimizer.getValue(options)) {
  62             appendPhase(new EdgeMoveOptimizer());
  63         }
  64         if (Options.LIROptControlFlowOptimizer.getValue(options)) {
  65             appendPhase(new ControlFlowOptimizer());
  66         }
  67         if (Options.LIROptRedundantMoveElimination.getValue(options)) {
  68             appendPhase(new RedundantMoveElimination());
  69         }
  70         if (Options.LIROptNullCheckOptimizer.getValue(options)) {
  71             appendPhase(new NullCheckOptimizer());
  72         }
  73         if (Options.LIRProfileMoves.getValue(options)) {
  74             appendPhase(new MoveProfilingPhase());
  75         }
  76         if (Options.LIRProfileMethods.getValue(options)) {
  77             appendPhase(new MethodProfilingPhase());
  78         }
  79     }
  80 }