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