annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConvertUnreachedToGuardPhase.java @ 7530:5e3d1a68664e

applied mx eclipseformat to all Java files
author Doug Simon <doug.simon@oracle.com>
date Wed, 23 Jan 2013 16:34:57 +0100
parents b1ebd583be14
children 0b646334c5f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
23 package com.oracle.graal.phases.common;
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import com.oracle.graal.api.code.*;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
26 import com.oracle.graal.api.meta.*;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
27 import com.oracle.graal.graph.*;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
28 import com.oracle.graal.nodes.*;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.extended.*;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30 import com.oracle.graal.nodes.util.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6522
diff changeset
31 import com.oracle.graal.phases.*;
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
32
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
33 public class ConvertUnreachedToGuardPhase extends Phase {
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
35 private OptimisticOptimizations opt;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37 public ConvertUnreachedToGuardPhase(OptimisticOptimizations opt) {
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
38 this.opt = opt;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
39 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
40
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
41 @Override
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
42 protected void run(StructuredGraph graph) {
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43 if (!opt.removeNeverExecutedCode()) {
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
44 return;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
45 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
46 for (Node node : graph.getNodes()) {
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
47 if (node instanceof IfNode) {
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
48 IfNode ifNode = (IfNode) node;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
49 BeginNode insertGuard = null;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
50 BeginNode delete = null;
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
51 boolean inverted = false;
7257
b1ebd583be14 Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6563
diff changeset
52 if (ifNode.probability(ifNode.trueSuccessor()) == 0) {
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
53 insertGuard = ifNode.falseSuccessor();
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
54 delete = ifNode.trueSuccessor();
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55 inverted = true;
7257
b1ebd583be14 Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6563
diff changeset
56 } else if (ifNode.probability(ifNode.falseSuccessor()) == 0) {
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
57 insertGuard = ifNode.trueSuccessor();
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
58 delete = ifNode.falseSuccessor();
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60 if (insertGuard != null) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
61 GuardNode guard = graph.unique(new GuardNode(ifNode.condition(), BeginNode.prevBegin(ifNode), DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile,
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
62 inverted, ifNode.leafGraphId()));
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
63 graph.addBeforeFixed(ifNode, graph.add(new ValueAnchorNode(guard)));
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
64 GraphUtil.killCFG(delete);
7257
b1ebd583be14 Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 6563
diff changeset
65 graph.removeSplit(ifNode, inverted ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
5695
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
66 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
67 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
68 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
70 }
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
71
a63ed5993987 Add leadGraphID to IfNOde so that we can convert them to deopts
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
72 }