Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/EliminatePartiallyRedundantGuardsPhase.java @ 7932:d4e6c82cd6a1
Remove deferred write logic.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 05 Mar 2013 17:16:41 +0100 |
parents | 4a6646d8eb87 |
children | 0f6dd67470d9 |
rev | line source |
---|---|
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
4 * |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
8 * |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
14 * |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
18 * |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.phases.common; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
24 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
25 import java.util.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
26 import java.util.Map.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
27 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.api.code.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.api.meta.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.debug.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.graph.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.PhiNode.PhiType; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.phases.*; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
35 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
36 public class EliminatePartiallyRedundantGuardsPhase extends Phase { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
37 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
38 private static final DebugMetric metricPRGuardsEliminatedAtMerge = Debug.metric("PRGuardsEliminatedAtMerge"); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
39 private static final DebugMetric metricPRGuardsEliminatedAtSplit = Debug.metric("PRGuardsEliminatedAtSplit"); |
6671
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
40 |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
41 private final boolean eliminateAtSplit; |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
42 private final boolean eliminateAtMerge; |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
43 |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
44 public EliminatePartiallyRedundantGuardsPhase(boolean eliminateAtSplit, boolean eliminateAtMerge) { |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
45 assert eliminateAtMerge || eliminateAtSplit; |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
46 this.eliminateAtSplit = eliminateAtSplit; |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
47 this.eliminateAtMerge = eliminateAtMerge; |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
48 } |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
49 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
50 private static class Condition { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
51 |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7660
diff
changeset
|
52 final LogicNode conditionNode; |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
53 final boolean negated; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
54 |
7767
4a6646d8eb87
separate BooleanNode and ConstantNode hierarchy, rename BooleanNode to LogicNode and LogicNode to BitLogicNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7660
diff
changeset
|
55 public Condition(LogicNode conditionNode, boolean negated) { |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
56 this.conditionNode = conditionNode; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
57 this.negated = negated; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
58 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
59 |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
60 @Override |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
61 public int hashCode() { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
62 final int prime = 31; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
63 int result = 1; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
64 result = prime * result + ((conditionNode == null) ? 0 : conditionNode.hashCode()); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
65 result = prime * result + (negated ? 1231 : 1237); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
66 return result; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
67 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
68 |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
69 @Override |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
70 public boolean equals(Object obj) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
71 if (this == obj) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
72 return true; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
73 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
74 if (obj == null) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
75 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
76 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
77 if (getClass() != obj.getClass()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
78 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
79 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
80 Condition other = (Condition) obj; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
81 if (conditionNode == null) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
82 if (other.conditionNode != null) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
83 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
84 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
85 } else if (!conditionNode.equals(other.conditionNode)) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
86 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
87 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
88 if (negated != other.negated) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
89 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
90 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
91 return true; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
92 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
93 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
94 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
95 @Override |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
96 protected void run(StructuredGraph graph) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
97 boolean hits; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
98 do { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
99 hits = false; |
6671
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
100 if (eliminateAtMerge) { |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
101 for (MergeNode merge : graph.getNodes(MergeNode.class)) { |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
102 hits |= eliminateAtMerge(merge); |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
103 } |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
104 } |
6671
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
105 if (eliminateAtSplit) { |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
106 for (ControlSplitNode controlSplit : graph.getNodes().filter(ControlSplitNode.class)) { |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
107 hits |= eliminateAtControlSplit(controlSplit); |
bffb038abbe6
Add option for EliminatePartiallyRedundantGuards, eliminate at splits after IterativeConditionalElimination
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6669
diff
changeset
|
108 } |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
109 } |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
110 } while (hits); |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
111 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
112 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
113 private static boolean eliminateAtMerge(MergeNode merge) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
114 if (merge.forwardEndCount() < 2) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
115 return false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
116 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
117 Collection<GuardNode> hits = new LinkedList<>(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
118 for (GuardNode guard : merge.guards()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
119 if (guard.dependencies().size() != 1) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
120 continue; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
121 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
122 for (EndNode end : merge.forwardEnds()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
123 BeginNode begin = BeginNode.prevBegin(end); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
124 boolean found = false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
125 for (GuardNode predecessorGuard : begin.guards()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
126 if (predecessorGuard.dependencies().size() != 1) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
127 continue; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
128 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
129 if (guard.condition() == predecessorGuard.condition() && guard.negated() == predecessorGuard.negated()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
130 hits.add(guard); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
131 found = true; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
132 break; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
133 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
134 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
135 if (found) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
136 break; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
137 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
138 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
139 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
140 Graph graph = merge.graph(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
141 for (GuardNode guard : hits) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
142 PhiNode phi = graph.add(new PhiNode(PhiType.Guard, merge)); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
143 for (EndNode otherEnd : merge.forwardEnds()) { |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
144 phi.addInput(graph.unique(new GuardNode(guard.condition(), BeginNode.prevBegin(otherEnd), guard.reason(), guard.action(), guard.negated()))); |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
145 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
146 guard.replaceAndDelete(phi); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
147 metricPRGuardsEliminatedAtMerge.increment(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
148 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
149 return !hits.isEmpty(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
150 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
151 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
152 private static boolean eliminateAtControlSplit(ControlSplitNode controlSplit) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
153 Map<Condition, Collection<GuardNode>> conditionToGuard = new HashMap<>(); |
7257
b1ebd583be14
Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6671
diff
changeset
|
154 for (Node successor : controlSplit.successors()) { |
b1ebd583be14
Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6671
diff
changeset
|
155 BeginNode begin = (BeginNode) successor; |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
156 for (GuardNode guard : begin.guards()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
157 if (guard.dependencies().size() != 1) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
158 continue; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
159 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
160 Condition condition = new Condition(guard.condition(), guard.negated()); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
161 Collection<GuardNode> guards = conditionToGuard.get(condition); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
162 if (guards == null) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
163 guards = new LinkedList<>(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
164 conditionToGuard.put(condition, guards); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
165 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
166 guards.add(guard); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
167 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
168 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
169 |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
170 boolean hits = false; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
171 for (Entry<Condition, Collection<GuardNode>> entry : conditionToGuard.entrySet()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
172 Collection<GuardNode> guards = entry.getValue(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
173 if (guards.size() < 2) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
174 continue; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
175 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
176 DeoptimizationReason reason = null; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
177 DeoptimizationAction action = DeoptimizationAction.None; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
178 Set<BeginNode> begins = new HashSet<>(3); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
179 for (GuardNode guard : guards) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
180 BeginNode begin = (BeginNode) guard.dependencies().first(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
181 begins.add(begin); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
182 if (guard.action().ordinal() > action.ordinal()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
183 action = guard.action(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
184 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
185 if (reason == null) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
186 reason = guard.reason(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
187 } else if (reason != guard.reason()) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
188 reason = DeoptimizationReason.None; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
189 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
190 } |
7257
b1ebd583be14
Remove @Successor private final NodeSuccessorList<BeginNode> blockSuccessors from ControlSplitNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6671
diff
changeset
|
191 if (begins.size() == controlSplit.successors().count()) { |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
192 hits = true; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
193 Condition condition = entry.getKey(); |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
194 GuardNode newGuard = controlSplit.graph().unique(new GuardNode(condition.conditionNode, BeginNode.prevBegin(controlSplit), reason, action, condition.negated)); |
6669
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
195 for (GuardNode guard : guards) { |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
196 guard.replaceAndDelete(newGuard); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
197 metricPRGuardsEliminatedAtSplit.increment(); |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
198 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
199 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
200 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
201 return hits; |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
202 } |
7f6823cc5d26
Simple elimination of some partially redundant guards
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff
changeset
|
203 } |