annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FrameStateAssignmentPhase.java @ 11626:340e67bf1758

Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 13 Sep 2013 14:47:04 +0200
parents ae619d70bf4b
children 1ca5e39d0433
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
23 package com.oracle.graal.phases.common;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import java.util.*;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
26
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
27 import com.oracle.graal.graph.*;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.graph.iterators.*;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
11626
340e67bf1758 Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11579
diff changeset
30 import com.oracle.graal.nodes.StructuredGraph.GuardsStage;
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
31 import com.oracle.graal.nodes.util.*;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
32 import com.oracle.graal.phases.*;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33 import com.oracle.graal.phases.graph.*;
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
34 import com.oracle.graal.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
35
8983
6c4ac1a8cd20 Run dead code elimination after framestate assignment
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8957
diff changeset
36 public class FrameStateAssignmentPhase extends Phase {
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37
9730
d58ebf85443e spelling fix
Doug Simon <doug.simon@oracle.com>
parents: 9633
diff changeset
38 private static class FrameStateAssignmentClosure extends NodeIteratorClosure<FrameState> {
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
39
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
40 @Override
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
41 protected FrameState processNode(FixedNode node, FrameState currentState) {
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
42 if (node instanceof DeoptimizingNode) {
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
43 DeoptimizingNode deopt = (DeoptimizingNode) node;
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
44 if (deopt.canDeoptimize() && deopt.getDeoptimizationState() == null) {
9878
d0a007fb65af simplify FrameStateAssignmentPhase, add guarantee that every DeoptimizingNode has a FrameState
Lukas Stadler <lukas.stadler@jku.at>
parents: 9730
diff changeset
45 GraalInternalError.guarantee(currentState != null, "no FrameState at DeoptimizingNode %s", deopt);
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
46 deopt.setDeoptimizationState(currentState);
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
47 }
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
48 }
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
49
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
50 if (node instanceof StateSplit) {
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
51 StateSplit stateSplit = (StateSplit) node;
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
52 if (stateSplit.stateAfter() != null) {
9633
5207bb46598e simplify "clever" code in FrameStateAssignmentPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 9624
diff changeset
53 FrameState newState = stateSplit.stateAfter();
5207bb46598e simplify "clever" code in FrameStateAssignmentPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 9624
diff changeset
54 stateSplit.setStateAfter(null);
5207bb46598e simplify "clever" code in FrameStateAssignmentPhase
Lukas Stadler <lukas.stadler@jku.at>
parents: 9624
diff changeset
55 return newState;
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
56 }
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
57 }
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
58 return currentState;
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
61 @Override
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
62 protected FrameState merge(MergeNode merge, List<FrameState> states) {
9878
d0a007fb65af simplify FrameStateAssignmentPhase, add guarantee that every DeoptimizingNode has a FrameState
Lukas Stadler <lukas.stadler@jku.at>
parents: 9730
diff changeset
63 return merge.stateAfter() != null ? merge.stateAfter() : singleFrameState(merge, states);
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
64 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
65
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
66 @Override
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
67 protected FrameState afterSplit(AbstractBeginNode node, FrameState oldState) {
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
68 return oldState;
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
70
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
71 @Override
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
72 protected Map<LoopExitNode, FrameState> processLoop(LoopBeginNode loop, FrameState initialState) {
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
73 return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
74 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
75 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
76
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
77 @Override
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
78 protected void run(StructuredGraph graph) {
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
79 assert checkFixedDeopts(graph);
9730
d58ebf85443e spelling fix
Doug Simon <doug.simon@oracle.com>
parents: 9633
diff changeset
80 ReentrantNodeIterator.apply(new FrameStateAssignmentClosure(), graph.start(), null, null);
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9878
diff changeset
81
11626
340e67bf1758 Rename GuardsPhase to GuardsStage to avoid confusion with existing Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11579
diff changeset
82 graph.setGuardsPhase(GuardsStage.AFTER_FSA);
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
83 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
84
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
85 private static boolean checkFixedDeopts(StructuredGraph graph) {
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
86 NodePredicate isFloatingNode = GraphUtil.isFloatingNode();
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
87 for (Node n : graph.getNodes().filterInterface(DeoptimizingNode.class)) {
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
88 if (((DeoptimizingNode) n).canDeoptimize() && isFloatingNode.apply(n)) {
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
89 return false;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
90 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
91 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
92 return true;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
93 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
94
9624
87eafaddf9d9 let ReentrantBlockIterator.processBlock return the next state
Lukas Stadler <lukas.stadler@jku.at>
parents: 9387
diff changeset
95 private static FrameState singleFrameState(@SuppressWarnings("unused") MergeNode merge, List<FrameState> states) {
9878
d0a007fb65af simplify FrameStateAssignmentPhase, add guarantee that every DeoptimizingNode has a FrameState
Lukas Stadler <lukas.stadler@jku.at>
parents: 9730
diff changeset
96 FrameState singleState = states.get(0);
9381
addc2a25d727 Implement merging of frame states if they differ at a merge that does not have its own frame state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8983
diff changeset
97 for (int i = 1; i < states.size(); ++i) {
9878
d0a007fb65af simplify FrameStateAssignmentPhase, add guarantee that every DeoptimizingNode has a FrameState
Lukas Stadler <lukas.stadler@jku.at>
parents: 9730
diff changeset
98 if (states.get(i) != singleState) {
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
99 return null;
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
100 }
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
101 }
9878
d0a007fb65af simplify FrameStateAssignmentPhase, add guarantee that every DeoptimizingNode has a FrameState
Lukas Stadler <lukas.stadler@jku.at>
parents: 9730
diff changeset
102 return singleState;
9381
addc2a25d727 Implement merging of frame states if they differ at a merge that does not have its own frame state.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8983
diff changeset
103 }
8957
1af9b5d75139 Move framestate assignement to the hir
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
104 }