annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java @ 21762:1025d6dc645a

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 06 Jun 2015 15:13:09 +0200
parents b14a218c5471
children 6714387f5323
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.phases.common;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
25 import com.oracle.jvmci.meta.JavaConstant;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
26 import com.oracle.jvmci.meta.TriState;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
27 import static com.oracle.jvmci.meta.DeoptimizationAction.*;
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21554
diff changeset
28 import static com.oracle.jvmci.meta.DeoptimizationReason.*;
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
29
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import java.util.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 import java.util.function.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
33 import com.oracle.graal.compiler.common.cfg.*;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.compiler.common.type.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.graph.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodeinfo.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.nodes.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 import com.oracle.graal.nodes.cfg.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.nodes.extended.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.nodes.java.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41 import com.oracle.graal.nodes.util.*;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.phases.*;
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
43 import com.oracle.graal.phases.common.LoweringPhase.Frame;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 import com.oracle.graal.phases.schedule.*;
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21160
diff changeset
45 import com.oracle.jvmci.debug.*;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 public class DominatorConditionalEliminationPhase extends Phase {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 private static final DebugMetric metricStampsRegistered = Debug.metric("StampsRegistered");
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 private static final DebugMetric metricStampsFound = Debug.metric("StampsFound");
19714
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
51 private final boolean fullSchedule;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52
19714
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
53 public DominatorConditionalEliminationPhase(boolean fullSchedule) {
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
54 this.fullSchedule = fullSchedule;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 private static final class InfoElement {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
58 private final Stamp stamp;
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
59 private final ValueNode guard;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 public InfoElement(Stamp stamp, ValueNode guard) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62 this.stamp = stamp;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 this.guard = guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 public Stamp getStamp() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 return stamp;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 public ValueNode getGuard() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 return guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 }
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
73
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
74 @Override
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
75 public String toString() {
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
76 return stamp + " -> " + guard;
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
77 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 private static final class Info {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
81 private final ArrayList<InfoElement> infos;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 public Info() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 infos = new ArrayList<>();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 public Iterable<InfoElement> getElements() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 return infos;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
90
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
91 public void pushElement(InfoElement element) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92 infos.add(element);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
94
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
95 public void popElement() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
96 infos.remove(infos.size() - 1);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
97 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
99
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 @Override
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 protected void run(StructuredGraph graph) {
19714
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
102
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
103 Function<Block, Iterable<? extends Node>> blockToNodes;
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
104 Function<Node, Block> nodeToBlock;
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
105 Block startBlock;
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
106
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
107 if (fullSchedule) {
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
108 SchedulePhase schedule = new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
109 schedule.apply(graph);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
110 ControlFlowGraph cfg = schedule.getCFG();
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
111 cfg.computePostdominators();
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
112 blockToNodes = b -> schedule.getBlockToNodesMap().get(b);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
113 nodeToBlock = n -> schedule.getNodeToBlockMap().get(n);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
114 startBlock = cfg.getStartBlock();
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
115 } else {
21619
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
116 ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
19714
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
117 cfg.computePostdominators();
19755
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
118 BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
119 for (Block b : cfg.getBlocks()) {
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
120 ArrayList<FixedNode> curNodes = new ArrayList<>();
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
121 for (FixedNode node : b.getNodes()) {
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
122 if (node instanceof AbstractBeginNode || node instanceof FixedGuardNode || node instanceof CheckCastNode || node instanceof ConditionAnchorNode || node instanceof IfNode) {
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
123 curNodes.add(node);
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
124 }
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
125 }
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
126 nodes.put(b, curNodes);
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
127 }
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
128 blockToNodes = b -> nodes.get(b);
19714
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
129 nodeToBlock = n -> cfg.blockFor(n);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
130 startBlock = cfg.getStartBlock();
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
131 }
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
132
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
133 Instance instance = new Instance(graph, blockToNodes, nodeToBlock);
b503dd4e723c Perform full schedule for conditional elimination only in a phase where floating guards are available.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19712
diff changeset
134 instance.processBlock(startBlock);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 private static class Instance {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138
21619
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
139 private NodeMap<Info> map;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
140 private Deque<LoopExitNode> loopExits;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
141 private final Function<Block, Iterable<? extends Node>> blockToNodes;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
142 private final Function<Node, Block> nodeToBlock;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
143
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
144 public Instance(StructuredGraph graph, Function<Block, Iterable<? extends Node>> blockToNodes, Function<Node, Block> nodeToBlock) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
145 map = graph.createNodeMap();
20040
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19946
diff changeset
146 loopExits = new ArrayDeque<>();
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
147 this.blockToNodes = blockToNodes;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
148 this.nodeToBlock = nodeToBlock;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
149 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
150
20928
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
151 public void processBlock(Block startBlock) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
152 LoweringPhase.processBlock(new InstanceFrame(startBlock, null));
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
153 }
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
154
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
155 public class InstanceFrame extends LoweringPhase.Frame<InstanceFrame> {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156 List<Runnable> undoOperations = new ArrayList<>();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
157
20928
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
158 public InstanceFrame(Block block, InstanceFrame parent) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
159 super(block, parent);
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
160 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161
20928
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
162 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
163 public Frame<?> enter(Block b) {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
164 return new InstanceFrame(b, this);
19724
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
165 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166
20928
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
167 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
168 public void preprocess() {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
169 Instance.this.preprocess(block, undoOperations);
19724
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
170 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
171
20928
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
172 @Override
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
173 public void postprocess() {
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
174 Instance.postprocess(undoOperations);
d9713313e88c Change recursive LoweringPhase.Round.processBlock to state machine with emulated stack. Also use the same traversal in DominatorConditionalEliminationPhase.Instance.processBlock. Required, as the recursive implementation exceeds the stack on SPARC.
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 20174
diff changeset
175 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
178 private static void postprocess(List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 for (Runnable r : undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180 r.run();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183
19724
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
184 private void preprocess(Block block, List<Runnable> undoOperations) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 AbstractBeginNode beginNode = block.getBeginNode();
19724
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
186 if (beginNode instanceof LoopExitNode && beginNode.isAlive()) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
187 LoopExitNode loopExitNode = (LoopExitNode) beginNode;
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
188 this.loopExits.push(loopExitNode);
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
189 undoOperations.add(() -> loopExits.pop());
21619
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
190 } else if (block.getDominator() != null &&
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
191 (block.getDominator().getLoopDepth() > block.getLoopDepth() || (block.getDominator().getLoopDepth() == block.getLoopDepth() && block.getDominator().getLoop() != block.getLoop()))) {
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
192 // We are exiting the loop, but there is not a single loop exit block along our
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
193 // dominator tree (e.g., we are a merge of two loop exits).
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
194 final NodeMap<Info> oldMap = map;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
195 final Deque<LoopExitNode> oldLoopExits = loopExits;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
196 map = map.graph().createNodeMap();
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
197 loopExits = new ArrayDeque<>();
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
198 undoOperations.add(() -> {
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
199 map = oldMap;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
200 loopExits = oldLoopExits;
b14a218c5471 Fix in the dominator based conditional elimination for the corner case of a loop exit merge.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21585
diff changeset
201 });
19724
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
202 }
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
203 for (Node n : blockToNodes.apply(block)) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
204 if (n.isAlive()) {
19a4fbe393d0 Fix for conditional elimination: Block could have been deleted, but dominated block is alive.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19721
diff changeset
205 processNode(n, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
206 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
207 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
208 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
209
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
210 private void processNode(Node node, List<Runnable> undoOperations) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211 if (node instanceof AbstractBeginNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 processAbstractBegin((AbstractBeginNode) node, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 } else if (node instanceof FixedGuardNode) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
214 processFixedGuard((FixedGuardNode) node, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 } else if (node instanceof GuardNode) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
216 processGuard((GuardNode) node, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
217 } else if (node instanceof CheckCastNode) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
218 processCheckCast((CheckCastNode) node);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 } else if (node instanceof ConditionAnchorNode) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
220 processConditionAnchor((ConditionAnchorNode) node);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221 } else if (node instanceof IfNode) {
19755
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
222 processIf((IfNode) node, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
224 return;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
225 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
226 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
227
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
228 private void processCheckCast(CheckCastNode node) {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
229 for (InfoElement infoElement : getInfoElements(node.object())) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
230 TriState result = node.tryFold(infoElement.getStamp());
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
231 if (result.isKnown()) {
21039
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
232 if (rewireGuards(infoElement.getGuard(), result.toBoolean(), (guard, checkCastResult) -> {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
233 if (checkCastResult) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
234 PiNode piNode = node.graph().unique(new PiNode(node.object(), node.stamp(), guard));
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
235 node.replaceAtUsages(piNode);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
236 GraphUtil.unlinkFixedNode(node);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
237 node.safeDelete();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
238 } else {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
239 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode));
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
240 node.replaceAtPredecessor(deopt);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
241 GraphUtil.killCFG(node);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
242 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
243 return true;
21039
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
244 })) {
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
245 return;
13a255e29236 Conditional Elimination: processCheckCast should return as soon as the checkcast has been transformed
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21038
diff changeset
246 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
247 }
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
248 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
249 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
250
19755
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
251 private void processIf(IfNode node, List<Runnable> undoOperations) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
252 tryProofCondition(node.condition(), (guard, result) -> {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
253 AbstractBeginNode survivingSuccessor = node.getSuccessor(result);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
254 survivingSuccessor.replaceAtUsages(InputType.Guard, guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
255 survivingSuccessor.replaceAtPredecessor(null);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
256 node.replaceAtPredecessor(survivingSuccessor);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
257 GraphUtil.killCFG(node);
21585
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
258 if (survivingSuccessor instanceof BeginNode) {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
259 undoOperations.add(() -> {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
260 if (survivingSuccessor.isAlive()) {
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
261 ((BeginNode) survivingSuccessor).trySimplify();
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
262 }
453284d62d64 Fix a bug in the dominator based conditional elimination.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 21556
diff changeset
263 });
19721
4df907480030 Simplify begin node immediately after removing if node.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19717
diff changeset
264 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
265 return true;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
266 });
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269 private void registerNewCondition(LogicNode condition, boolean negated, ValueNode guard, List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
270 if (condition instanceof UnaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271 UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) condition;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
272 Stamp newStamp = unaryLogicNode.getSucceedingStampForValue(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273 registerNewStamp(unaryLogicNode.getValue(), newStamp, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
274 } else if (condition instanceof BinaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
275 BinaryOpLogicNode binaryOpLogicNode = (BinaryOpLogicNode) condition;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
276 ValueNode x = binaryOpLogicNode.getX();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
277 if (!x.isConstant()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
278 Stamp newStampX = binaryOpLogicNode.getSucceedingStampForX(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
279 registerNewStamp(x, newStampX, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
280 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
281
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
282 ValueNode y = binaryOpLogicNode.getY();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
283 if (!y.isConstant()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
284 Stamp newStampY = binaryOpLogicNode.getSucceedingStampForY(negated);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
285 registerNewStamp(y, newStampY, guard, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
286 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
287 }
21036
953666b61a23 Always register stamps for the condition itself
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 20931
diff changeset
288 registerCondition(condition, negated, guard, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
289 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
290
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
291 private void registerCondition(LogicNode condition, boolean negated, ValueNode guard, List<Runnable> undoOperations) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
292 registerNewStamp(condition, negated ? StampFactory.contradiction() : StampFactory.tautology(), guard, undoOperations);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
293 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
294
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
295 private Iterable<InfoElement> getInfoElements(ValueNode proxiedValue) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
296 ValueNode value = GraphUtil.unproxify(proxiedValue);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
297 Info info = map.get(value);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
298 if (info == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
299 return Collections.emptyList();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
300 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
301 return info.getElements();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
302 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
303 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
304
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
305 private boolean rewireGuards(ValueNode guard, boolean result, GuardRewirer rewireGuardFunction) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
306 assert guard instanceof GuardingNode;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
307 metricStampsFound.increment();
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
308 ValueNode proxiedGuard = proxyGuard(guard);
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
309 return rewireGuardFunction.rewire(proxiedGuard, result);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
310 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
311
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
312 private ValueNode proxyGuard(ValueNode guard) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
313 ValueNode proxiedGuard = guard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
314 if (!this.loopExits.isEmpty()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
315 while (proxiedGuard instanceof GuardProxyNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
316 proxiedGuard = ((GuardProxyNode) proxiedGuard).value();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
317 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
318 Block guardBlock = nodeToBlock.apply(proxiedGuard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
319 assert guardBlock != null;
20040
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19946
diff changeset
320 for (Iterator<LoopExitNode> iter = loopExits.descendingIterator(); iter.hasNext();) {
f137f1974f60 removed uses of StringBuffer, Hashtable and Stack
Doug Simon <doug.simon@oracle.com>
parents: 19946
diff changeset
321 LoopExitNode loopExitNode = iter.next();
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
322 Block loopExitBlock = nodeToBlock.apply(loopExitNode);
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
323 if (guardBlock != loopExitBlock && AbstractControlFlowGraph.dominates(guardBlock, loopExitBlock)) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
324 Block loopBeginBlock = nodeToBlock.apply(loopExitNode.loopBegin());
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
325 if (!AbstractControlFlowGraph.dominates(guardBlock, loopBeginBlock) || guardBlock == loopBeginBlock) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
326 proxiedGuard = proxiedGuard.graph().unique(new GuardProxyNode((GuardingNode) proxiedGuard, loopExitNode));
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
327 }
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
328 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
329 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
330 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
331 return proxiedGuard;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
332 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
333
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
334 @FunctionalInterface
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
335 private interface GuardRewirer {
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
336 /**
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
337 * Called if the condition could be proven to have a constant value ({@code result})
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
338 * under {@code guard}.
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
339 *
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
340 * Return whether a transformation could be applied.
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
341 */
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
342 boolean rewire(ValueNode guard, boolean result);
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
343 }
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
344
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
345 private boolean tryProofCondition(LogicNode node, GuardRewirer rewireGuardFunction) {
21037
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
346 for (InfoElement infoElement : getInfoElements(node)) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
347 Stamp stamp = infoElement.getStamp();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
348 JavaConstant constant = (JavaConstant) stamp.asConstant();
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
349 if (constant != null) {
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
350 return rewireGuards(infoElement.getGuard(), constant.asBoolean(), rewireGuardFunction);
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
351 }
3fc34aafea30 Conditional elimination: check if conditional has known value already
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21036
diff changeset
352 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
353 if (node instanceof UnaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
354 UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) node;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
355 ValueNode value = unaryLogicNode.getValue();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
356 for (InfoElement infoElement : getInfoElements(value)) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
357 Stamp stamp = infoElement.getStamp();
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
358 TriState result = unaryLogicNode.tryFold(stamp);
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
359 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
360 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
362 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
363 } else if (node instanceof BinaryOpLogicNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
364 BinaryOpLogicNode binaryOpLogicNode = (BinaryOpLogicNode) node;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
365 for (InfoElement infoElement : getInfoElements(binaryOpLogicNode)) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
366 if (infoElement.getStamp().equals(StampFactory.contradiction())) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
367 return rewireGuards(infoElement.getGuard(), false, rewireGuardFunction);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
368 } else if (infoElement.getStamp().equals(StampFactory.tautology())) {
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
369 return rewireGuards(infoElement.getGuard(), true, rewireGuardFunction);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
370 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
371 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
372
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
373 ValueNode x = binaryOpLogicNode.getX();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
374 ValueNode y = binaryOpLogicNode.getY();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
375 for (InfoElement infoElement : getInfoElements(x)) {
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
376 TriState result = binaryOpLogicNode.tryFold(infoElement.getStamp(), y.stamp());
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
377 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
378 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
379 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
380 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
381
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
382 for (InfoElement infoElement : getInfoElements(y)) {
19717
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
383 TriState result = binaryOpLogicNode.tryFold(x.stamp(), infoElement.getStamp());
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
384 if (result.isKnown()) {
70d565f6e127 Convert API for tryFold from Boolean return value to TriState return value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19716
diff changeset
385 return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
386 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
387 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
388 } else if (node instanceof ShortCircuitOrNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
389 final ShortCircuitOrNode shortCircuitOrNode = (ShortCircuitOrNode) node;
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
390 if (this.loopExits.isEmpty()) {
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
391 return tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> {
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
392 if (result == !shortCircuitOrNode.isXNegated()) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
393 return rewireGuards(guard, true, rewireGuardFunction);
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
394 } else {
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
395 return tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> {
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
396 if (innerGuard == guard) {
21160
0c03a7b7081f fix in DominatorConditionalEliminationPhase for If/ShortCircuitOr with xNegated=true
Lukas Stadler <lukas.stadler@oracle.com>
parents: 21150
diff changeset
397 return rewireGuards(guard, innerResult ^ shortCircuitOrNode.isYNegated(), rewireGuardFunction);
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
398 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
399 return false;
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
400 });
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
401 }
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
402 });
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
403 }
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
404 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
405
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
406 return false;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
407 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
408
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
409 private void registerNewStamp(ValueNode proxiedValue, Stamp newStamp, ValueNode guard, List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
410 if (newStamp != null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
411 ValueNode value = GraphUtil.unproxify(proxiedValue);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
412 Info info = map.get(value);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
413 if (info == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
414 info = new Info();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
415 map.set(value, info);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
416 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
417 metricStampsRegistered.increment();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
418 final Info finalInfo = info;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
419 finalInfo.pushElement(new InfoElement(newStamp, guard));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
420 undoOperations.add(() -> finalInfo.popElement());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
421 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
422 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
423
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
424 private void processConditionAnchor(ConditionAnchorNode node) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
425 tryProofCondition(node.condition(), (guard, result) -> {
19946
212566f9cd69 Dom-based ConditionalElimination: fix fliped check in processConditionAnchor
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19755
diff changeset
426 if (result != node.isNegated()) {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
427 node.replaceAtUsages(guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
428 GraphUtil.unlinkFixedNode(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
429 GraphUtil.killWithUnusedFloatingInputs(node);
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
430 } else {
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
431 ValueAnchorNode valueAnchor = node.graph().add(new ValueAnchorNode(null));
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
432 node.replaceAtUsages(valueAnchor);
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
433 node.graph().replaceFixedWithFixed(node, valueAnchor);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
434 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
435 return true;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
436 });
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
437 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
438
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
439 private void processGuard(GuardNode node, List<Runnable> undoOperations) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
440 if (!tryProofCondition(node.condition(), (guard, result) -> {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
441 if (result != node.isNegated()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
442 node.replaceAndDelete(guard);
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
443 } else {
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
444 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.action(), node.reason()));
20174
56f721367c0d conditional elimination: use begin node from guard anchor instead of node to block map
Andreas Woess <andreas.woess@oracle.com>
parents: 20040
diff changeset
445 AbstractBeginNode beginNode = (AbstractBeginNode) node.getAnchor();
19755
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
446 FixedNode next = beginNode.next();
223e1d7b15b7 Make conditional elimination more robust wrt deleted begin nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19724
diff changeset
447 beginNode.setNext(deopt);
19712
055a095424a7 Fixes for new conditional elimination phase. Make it default.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19709
diff changeset
448 GraphUtil.killCFG(next);
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
449 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
450 return true;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
451 })) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
452 registerNewCondition(node.condition(), node.isNegated(), node, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
454 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
455
19716
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
456 private void processFixedGuard(FixedGuardNode node, List<Runnable> undoOperations) {
1a9bfa2c3cc9 Reduce number of inserted guard proxies.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19714
diff changeset
457 if (!tryProofCondition(node.condition(), (guard, result) -> {
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
458 if (result != node.isNegated()) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
459 node.replaceAtUsages(guard);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
460 GraphUtil.unlinkFixedNode(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
461 GraphUtil.killWithUnusedFloatingInputs(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
462 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
463 DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(node.getAction(), node.getReason()));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
464 deopt.setStateBefore(node.stateBefore());
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
465 node.replaceAtPredecessor(deopt);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
466 GraphUtil.killCFG(node);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
467 }
21038
6868faf48f02 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21037
diff changeset
468 return true;
19709
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
469 })) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
470 registerNewCondition(node.condition(), node.isNegated(), node, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
471 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
472 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
473
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
474 private void processAbstractBegin(AbstractBeginNode beginNode, List<Runnable> undoOperations) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
475 Node predecessor = beginNode.predecessor();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
476 if (predecessor instanceof IfNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
477 IfNode ifNode = (IfNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
478 boolean negated = (ifNode.falseSuccessor() == beginNode);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
479 LogicNode condition = ifNode.condition();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
480 registerNewCondition(condition, negated, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
481 } else if (predecessor instanceof TypeSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
482 TypeSwitchNode typeSwitch = (TypeSwitchNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
483 processTypeSwitch(beginNode, undoOperations, predecessor, typeSwitch);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
484 } else if (predecessor instanceof IntegerSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
485 IntegerSwitchNode integerSwitchNode = (IntegerSwitchNode) predecessor;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486 processIntegerSwitch(beginNode, undoOperations, predecessor, integerSwitchNode);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
489
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
490 private void processIntegerSwitch(AbstractBeginNode beginNode, List<Runnable> undoOperations, Node predecessor, IntegerSwitchNode integerSwitchNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
491 Stamp stamp = null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
492 for (int i = 0; i < integerSwitchNode.keyCount(); i++) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
493 if (integerSwitchNode.keySuccessor(i) == predecessor) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
494 if (stamp == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
495 stamp = StampFactory.forConstant(integerSwitchNode.keyAt(i));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
496 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
497 stamp = stamp.meet(StampFactory.forConstant(integerSwitchNode.keyAt(i)));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
498 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
499 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
500 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
501
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
502 if (stamp != null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
503 registerNewStamp(integerSwitchNode.value(), stamp, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
504 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
505 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
506
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
507 private void processTypeSwitch(AbstractBeginNode beginNode, List<Runnable> undoOperations, Node predecessor, TypeSwitchNode typeSwitch) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
508 ValueNode hub = typeSwitch.value();
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
509 if (hub instanceof LoadHubNode) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
510 LoadHubNode loadHub = (LoadHubNode) hub;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
511 Stamp stamp = null;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
512 for (int i = 0; i < typeSwitch.keyCount(); i++) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
513 if (typeSwitch.keySuccessor(i) == predecessor) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
514 if (stamp == null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
515 stamp = StampFactory.exactNonNull(typeSwitch.typeAt(i));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
516 } else {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
517 stamp = stamp.meet(StampFactory.exactNonNull(typeSwitch.typeAt(i)));
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
518 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
519 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
520 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
521 if (stamp != null) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
522 registerNewStamp(loadHub.getValue(), stamp, beginNode, undoOperations);
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
523 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
524 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
525 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
526 }
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
527 }