comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ConvertDeoptimizeToGuardPhase.java @ 4548:f55914bc1d67

Added experimental ConvertDeoptimizeToGuardPhase.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 09 Feb 2012 21:26:26 +0100
parents
children 7cb57ac24ab8
comparison
equal deleted inserted replaced
4547:a3cdfa2be94e 4548:f55914bc1d67
1 /*
2 * Copyright (c) 2011, 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 package com.oracle.max.graal.compiler.phases;
24
25 import java.util.*;
26
27 import com.oracle.max.graal.graph.*;
28 import com.oracle.max.graal.nodes.*;
29
30 public class ConvertDeoptimizeToGuardPhase extends Phase {
31
32 private static BeginNode findBeginNode(Node startNode) {
33 Node n = startNode;
34 while (true) {
35 if (n instanceof BeginNode) {
36 return (BeginNode) n;
37 } else {
38 n = n.predecessor();
39 }
40 }
41 }
42
43 @Override
44 protected void run(final StructuredGraph graph) {
45 List<DeoptimizeNode> nodes = graph.getNodes(DeoptimizeNode.class).snapshot();
46 if (nodes.size() == 0) {
47 return;
48 }
49
50 for (DeoptimizeNode d : nodes) {
51 BeginNode myBeginNode = findBeginNode(d);
52 Node controlSplit = myBeginNode.predecessor();
53
54 if (controlSplit instanceof IfNode) {
55 IfNode ifNode = (IfNode) controlSplit;
56 BeginNode otherBegin = ifNode.trueSuccessor();
57 BooleanNode conditionNode = ifNode.compare();
58 if (myBeginNode == ifNode.trueSuccessor()) {
59 conditionNode = conditionNode.negate();
60 otherBegin = ifNode.falseSuccessor();
61 }
62 BeginNode ifBlockBegin = findBeginNode(ifNode);
63 graph.unique(new GuardNode(conditionNode, ifBlockBegin));
64 otherBegin.replaceAtUsages(ifBlockBegin);
65 FixedNode next = otherBegin.next();
66 otherBegin.setNext(null);
67 ifNode.replaceAtPredecessors(next);
68 }
69 }
70
71 new DeadCodeEliminationPhase().apply(graph);
72 }
73 }