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.OptDeoptimizationGrouping;
|
|
30 |
import static org.graalvm.compiler.core.common.GraalOptions.OptFloatingReads;
|
46640
|
31 |
import static org.graalvm.compiler.core.common.GraalOptions.OptLoopTransform;
|
|
32 |
import static org.graalvm.compiler.core.common.GraalOptions.PartialUnroll;
|
43972
|
33 |
import static org.graalvm.compiler.core.common.GraalOptions.ReassociateInvariants;
|
|
34 |
import static org.graalvm.compiler.core.common.GraalOptions.VerifyHeapAtReturn;
|
55509
|
35 |
import static org.graalvm.compiler.core.common.SpeculativeExecutionAttacksMitigations.GuardTargets;
|
|
36 |
import static org.graalvm.compiler.core.common.SpeculativeExecutionAttacksMitigations.NonDeoptGuardTargets;
|
|
37 |
import static org.graalvm.compiler.core.common.SpeculativeExecutionAttacksMitigations.Options.MitigateSpeculativeExecutionAttacks;
|
43972
|
38 |
|
46640
|
39 |
import org.graalvm.compiler.loop.DefaultLoopPolicies;
|
|
40 |
import org.graalvm.compiler.loop.LoopPolicies;
|
|
41 |
import org.graalvm.compiler.loop.phases.LoopPartialUnrollPhase;
|
43972
|
42 |
import org.graalvm.compiler.loop.phases.LoopSafepointEliminationPhase;
|
|
43 |
import org.graalvm.compiler.loop.phases.ReassociateInvariantPhase;
|
|
44 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
46344
|
45 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
46 |
import org.graalvm.compiler.phases.PhaseSuite;
|
|
47 |
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
|
|
48 |
import org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase;
|
|
49 |
import org.graalvm.compiler.phases.common.FloatingReadPhase;
|
|
50 |
import org.graalvm.compiler.phases.common.FrameStateAssignmentPhase;
|
|
51 |
import org.graalvm.compiler.phases.common.GuardLoweringPhase;
|
|
52 |
import org.graalvm.compiler.phases.common.IncrementalCanonicalizerPhase;
|
52578
|
53 |
import org.graalvm.compiler.phases.common.InsertGuardFencesPhase;
|
43972
|
54 |
import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase;
|
|
55 |
import org.graalvm.compiler.phases.common.LockEliminationPhase;
|
|
56 |
import org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase;
|
|
57 |
import org.graalvm.compiler.phases.common.LoweringPhase;
|
58299
|
58 |
import org.graalvm.compiler.phases.common.OptimizeDivPhase;
|
43972
|
59 |
import org.graalvm.compiler.phases.common.VerifyHeapAtReturnPhase;
|
55509
|
60 |
import org.graalvm.compiler.phases.common.WriteBarrierAdditionPhase;
|
43972
|
61 |
import org.graalvm.compiler.phases.tiers.MidTierContext;
|
|
62 |
|
|
63 |
public class MidTier extends PhaseSuite<MidTierContext> {
|
|
64 |
|
46344
|
65 |
public MidTier(OptionValues options) {
|
43972
|
66 |
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
|
46344
|
67 |
if (ImmutableCode.getValue(options)) {
|
43972
|
68 |
canonicalizer.disableReadCanonicalization();
|
|
69 |
}
|
|
70 |
|
|
71 |
appendPhase(new LockEliminationPhase());
|
|
72 |
|
46344
|
73 |
if (OptFloatingReads.getValue(options)) {
|
|
74 |
appendPhase(new IncrementalCanonicalizerPhase<>(canonicalizer, new FloatingReadPhase()));
|
43972
|
75 |
}
|
|
76 |
|
46344
|
77 |
if (ConditionalElimination.getValue(options)) {
|
43972
|
78 |
appendPhase(new IterativeConditionalEliminationPhase(canonicalizer, true));
|
|
79 |
}
|
|
80 |
|
46344
|
81 |
appendPhase(new LoopSafepointEliminationPhase());
|
43972
|
82 |
|
|
83 |
appendPhase(new LoopSafepointInsertionPhase());
|
|
84 |
|
46344
|
85 |
appendPhase(new GuardLoweringPhase());
|
43972
|
86 |
|
52578
|
87 |
if (MitigateSpeculativeExecutionAttacks.getValue(options) == GuardTargets || MitigateSpeculativeExecutionAttacks.getValue(options) == NonDeoptGuardTargets) {
|
|
88 |
appendPhase(new InsertGuardFencesPhase());
|
|
89 |
}
|
|
90 |
|
46344
|
91 |
if (VerifyHeapAtReturn.getValue(options)) {
|
43972
|
92 |
appendPhase(new VerifyHeapAtReturnPhase());
|
|
93 |
}
|
|
94 |
|
|
95 |
appendPhase(new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER));
|
|
96 |
|
58299
|
97 |
appendPhase(new OptimizeDivPhase());
|
|
98 |
|
43972
|
99 |
appendPhase(new FrameStateAssignmentPhase());
|
|
100 |
|
46640
|
101 |
LoopPolicies loopPolicies = createLoopPolicies();
|
|
102 |
if (OptLoopTransform.getValue(options)) {
|
|
103 |
if (PartialUnroll.getValue(options)) {
|
|
104 |
appendPhase(new LoopPartialUnrollPhase(loopPolicies, canonicalizer));
|
|
105 |
}
|
|
106 |
}
|
46344
|
107 |
if (ReassociateInvariants.getValue(options)) {
|
43972
|
108 |
appendPhase(new ReassociateInvariantPhase());
|
|
109 |
}
|
|
110 |
|
46344
|
111 |
if (OptDeoptimizationGrouping.getValue(options)) {
|
43972
|
112 |
appendPhase(new DeoptimizationGroupingPhase());
|
|
113 |
}
|
|
114 |
|
|
115 |
appendPhase(canonicalizer);
|
55509
|
116 |
|
|
117 |
appendPhase(new WriteBarrierAdditionPhase());
|
43972
|
118 |
}
|
46640
|
119 |
|
|
120 |
public LoopPolicies createLoopPolicies() {
|
|
121 |
return new DefaultLoopPolicies();
|
|
122 |
}
|
43972
|
123 |
}
|