43972
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.core.phases;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.core.common.GraalOptions.ConditionalElimination;
|
|
28 |
import static org.graalvm.compiler.core.common.GraalOptions.ImmutableCode;
|
|
29 |
import static org.graalvm.compiler.core.common.GraalOptions.LoopPeeling;
|
|
30 |
import static org.graalvm.compiler.core.common.GraalOptions.LoopUnswitch;
|
|
31 |
import static org.graalvm.compiler.core.common.GraalOptions.OptConvertDeoptsToGuards;
|
|
32 |
import static org.graalvm.compiler.core.common.GraalOptions.OptLoopTransform;
|
46344
|
33 |
import static org.graalvm.compiler.core.common.GraalOptions.OptReadElimination;
|
43972
|
34 |
import static org.graalvm.compiler.core.common.GraalOptions.PartialEscapeAnalysis;
|
|
35 |
import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Optional;
|
|
36 |
|
|
37 |
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
|
38 |
import org.graalvm.compiler.loop.LoopPolicies;
|
|
39 |
import org.graalvm.compiler.loop.phases.LoopFullUnrollPhase;
|
|
40 |
import org.graalvm.compiler.loop.phases.LoopPeelingPhase;
|
|
41 |
import org.graalvm.compiler.loop.phases.LoopUnswitchingPhase;
|
|
42 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
43 |
import org.graalvm.compiler.options.Option;
|
46344
|
44 |
import org.graalvm.compiler.options.OptionKey;
|
43972
|
45 |
import org.graalvm.compiler.options.OptionType;
|
46344
|
46 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
47 |
import org.graalvm.compiler.phases.PhaseSuite;
|
|
48 |
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
54084
|
49 |
import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
|
43972
|
50 |
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
|
|
51 |
import org.graalvm.compiler.phases.common.IncrementalCanonicalizerPhase;
|
|
52 |
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
|
|
53 |
import org.graalvm.compiler.phases.common.LoweringPhase;
|
52910
|
54 |
import org.graalvm.compiler.phases.common.NodeCounterPhase;
|
43972
|
55 |
import org.graalvm.compiler.phases.common.RemoveValueProxyPhase;
|
|
56 |
import org.graalvm.compiler.phases.common.inlining.InliningPhase;
|
52910
|
57 |
import org.graalvm.compiler.phases.common.inlining.policy.GreedyInliningPolicy;
|
43972
|
58 |
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
46344
|
59 |
import org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase;
|
43972
|
60 |
import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
|
|
61 |
|
|
62 |
public class HighTier extends PhaseSuite<HighTierContext> {
|
|
63 |
|
|
64 |
public static class Options {
|
|
65 |
|
|
66 |
// @formatter:off
|
|
67 |
@Option(help = "Enable inlining", type = OptionType.Expert)
|
46344
|
68 |
public static final OptionKey<Boolean> Inline = new OptionKey<>(true);
|
43972
|
69 |
// @formatter:on
|
|
70 |
}
|
|
71 |
|
46344
|
72 |
public HighTier(OptionValues options) {
|
43972
|
73 |
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
46344
|
74 |
if (ImmutableCode.getValue(options)) {
|
43972
|
75 |
canonicalizer.disableReadCanonicalization();
|
|
76 |
}
|
|
77 |
|
|
78 |
appendPhase(canonicalizer);
|
|
79 |
|
49451
|
80 |
if (NodeCounterPhase.Options.NodeCounters.getValue(options)) {
|
50858
|
81 |
appendPhase(new NodeCounterPhase(NodeCounterPhase.Stage.INIT));
|
49451
|
82 |
}
|
|
83 |
|
46344
|
84 |
if (Options.Inline.getValue(options)) {
|
52910
|
85 |
appendPhase(new InliningPhase(new GreedyInliningPolicy(null), canonicalizer));
|
43972
|
86 |
appendPhase(new DeadCodeEliminationPhase(Optional));
|
|
87 |
}
|
|
88 |
|
50858
|
89 |
if (NodeCounterPhase.Options.NodeCounters.getValue(options)) {
|
|
90 |
appendPhase(new NodeCounterPhase(NodeCounterPhase.Stage.EARLY));
|
|
91 |
}
|
|
92 |
|
46344
|
93 |
if (OptConvertDeoptsToGuards.getValue(options)) {
|
43972
|
94 |
appendPhase(new IncrementalCanonicalizerPhase<>(canonicalizer, new ConvertDeoptimizeToGuardPhase()));
|
|
95 |
}
|
|
96 |
|
46344
|
97 |
if (ConditionalElimination.getValue(options)) {
|
|
98 |
appendPhase(new IterativeConditionalEliminationPhase(canonicalizer, false));
|
|
99 |
}
|
|
100 |
|
43972
|
101 |
LoopPolicies loopPolicies = createLoopPolicies();
|
55509
|
102 |
appendPhase(new LoopFullUnrollPhase(canonicalizer, loopPolicies));
|
43972
|
103 |
|
46344
|
104 |
if (OptLoopTransform.getValue(options)) {
|
|
105 |
if (LoopPeeling.getValue(options)) {
|
55509
|
106 |
appendPhase(new IncrementalCanonicalizerPhase<>(canonicalizer, new LoopPeelingPhase(loopPolicies)));
|
43972
|
107 |
}
|
46344
|
108 |
if (LoopUnswitch.getValue(options)) {
|
55509
|
109 |
appendPhase(new IncrementalCanonicalizerPhase<>(canonicalizer, new LoopUnswitchingPhase(loopPolicies)));
|
43972
|
110 |
}
|
|
111 |
}
|
|
112 |
|
46344
|
113 |
if (PartialEscapeAnalysis.getValue(options)) {
|
|
114 |
appendPhase(new PartialEscapePhase(true, canonicalizer, options));
|
43972
|
115 |
}
|
46344
|
116 |
|
|
117 |
if (OptReadElimination.getValue(options)) {
|
|
118 |
appendPhase(new EarlyReadEliminationPhase(canonicalizer));
|
|
119 |
}
|
|
120 |
|
43972
|
121 |
appendPhase(new RemoveValueProxyPhase());
|
|
122 |
|
50858
|
123 |
if (NodeCounterPhase.Options.NodeCounters.getValue(options)) {
|
|
124 |
appendPhase(new NodeCounterPhase(NodeCounterPhase.Stage.LATE));
|
|
125 |
}
|
|
126 |
|
43972
|
127 |
appendPhase(new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER));
|
|
128 |
}
|
|
129 |
|
|
130 |
public LoopPolicies createLoopPolicies() {
|
|
131 |
return new DefaultLoopPolicies();
|
|
132 |
}
|
|
133 |
}
|