annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java @ 22790:615f3bbbb174

Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 08 Oct 2015 17:41:33 -0700
parents 05183a084a08
children a421f21a0054
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
23 package com.oracle.graal.phases.common;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
22790
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
25 import jdk.vm.ci.meta.Constant;
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
26 import jdk.vm.ci.meta.ConstantReflectionProvider;
615f3bbbb174 Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22646
diff changeset
27 import jdk.vm.ci.meta.MetaAccessProvider;
22573
74b3e5c0209c suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
28
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
29 import com.oracle.graal.debug.Debug;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
30 import com.oracle.graal.debug.DebugMetric;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
31 import com.oracle.graal.graph.Graph;
19250
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19001
diff changeset
32 import com.oracle.graal.graph.Graph.Mark;
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19001
diff changeset
33 import com.oracle.graal.graph.Graph.NodeEventListener;
8ab925a6f724 made Assumptions be part of a StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19001
diff changeset
34 import com.oracle.graal.graph.Graph.NodeEventScope;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
35 import com.oracle.graal.graph.Node;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
36 import com.oracle.graal.graph.NodeClass;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
37 import com.oracle.graal.graph.NodeWorkList;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
38 import com.oracle.graal.graph.spi.Canonicalizable;
19607
b92530cb27df Move commutative GVN into CanonicalizerPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 19561
diff changeset
39 import com.oracle.graal.graph.spi.Canonicalizable.BinaryCommutative;
22646
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
40 import com.oracle.graal.graph.spi.SimplifierTool;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
41 import com.oracle.graal.nodeinfo.InputType;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
42 import com.oracle.graal.nodes.AbstractMergeNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
43 import com.oracle.graal.nodes.ConstantNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
44 import com.oracle.graal.nodes.ControlSinkNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
45 import com.oracle.graal.nodes.FixedNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
46 import com.oracle.graal.nodes.FixedWithNextNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
47 import com.oracle.graal.nodes.StartNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
48 import com.oracle.graal.nodes.StructuredGraph;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
49 import com.oracle.graal.nodes.ValueNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
50 import com.oracle.graal.nodes.calc.FloatingNode;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
51 import com.oracle.graal.nodes.util.GraphUtil;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
52 import com.oracle.graal.phases.BasePhase;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
53 import com.oracle.graal.phases.Phase;
05183a084a08 updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents: 22573
diff changeset
54 import com.oracle.graal.phases.tiers.PhaseContext;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
56 public class CanonicalizerPhase extends BasePhase<PhaseContext> {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
57
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 private static final int MAX_ITERATION_PER_NODE = 10;
5134
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
59 private static final DebugMetric METRIC_CANONICALIZED_NODES = Debug.metric("CanonicalizedNodes");
11586
9652640fae42 tightened option verifier to check all class initializers in the hierarchy of a class that declares at least one @Option
Doug Simon <doug.simon@oracle.com>
parents: 11575
diff changeset
60 private static final DebugMetric METRIC_PROCESSED_NODES = Debug.metric("ProcessedNodes");
5134
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
61 private static final DebugMetric METRIC_CANONICALIZATION_CONSIDERED_NODES = Debug.metric("CanonicalizationConsideredNodes");
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
62 private static final DebugMetric METRIC_INFER_STAMP_CALLED = Debug.metric("InferStampCalled");
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
63 private static final DebugMetric METRIC_STAMP_CHANGED = Debug.metric("StampChanged");
5134
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
64 private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes");
11586
9652640fae42 tightened option verifier to check all class initializers in the hierarchy of a class that declares at least one @Option
Doug Simon <doug.simon@oracle.com>
parents: 11575
diff changeset
65 private static final DebugMetric METRIC_GLOBAL_VALUE_NUMBERING_HITS = Debug.metric("GlobalValueNumberingHits");
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
67 private boolean canonicalizeReads = true;
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
68 private boolean simplify = true;
19754
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
69 private final CustomCanonicalizer customCanonicalizer;
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
70
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
71 public abstract static class CustomCanonicalizer {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
72
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
73 public Node canonicalize(Node node) {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
74 return node;
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
75 }
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
76
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
77 @SuppressWarnings("unused")
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
78 public void simplify(Node node, SimplifierTool tool) {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
79 }
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
80 }
18475
96528e410fab Backed out changeset 42854d32b658
Andreas Woess <andreas.woess@jku.at>
parents: 18474
diff changeset
81
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
82 public CanonicalizerPhase() {
19754
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
83 this(null);
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
84 }
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
85
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
86 public CanonicalizerPhase(CustomCanonicalizer customCanonicalizer) {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
87 this.customCanonicalizer = customCanonicalizer;
18475
96528e410fab Backed out changeset 42854d32b658
Andreas Woess <andreas.woess@jku.at>
parents: 18474
diff changeset
88 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
89
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
90 public void disableReadCanonicalization() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
91 canonicalizeReads = false;
18475
96528e410fab Backed out changeset 42854d32b658
Andreas Woess <andreas.woess@jku.at>
parents: 18474
diff changeset
92 }
96528e410fab Backed out changeset 42854d32b658
Andreas Woess <andreas.woess@jku.at>
parents: 18474
diff changeset
93
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
94 public void disableSimplification() {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
95 simplify = false;
16264
df2fd3857607 getter for canonicalizeReads in CanonicalizerPhase
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16257
diff changeset
96 }
df2fd3857607 getter for canonicalizeReads in CanonicalizerPhase
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16257
diff changeset
97
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
98 @Override
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
99 protected void run(StructuredGraph graph, PhaseContext context) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
100 new Instance(context).run(graph);
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
101 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
102
11575
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
103 /**
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
104 * @param newNodesMark only the {@linkplain Graph#getNewNodes(Mark) new nodes} specified by this
11575
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
105 * mark are processed
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
106 */
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
107 public void applyIncremental(StructuredGraph graph, PhaseContext context, Mark newNodesMark) {
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
108 applyIncremental(graph, context, newNodesMark, true);
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
109 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
110
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
111 public void applyIncremental(StructuredGraph graph, PhaseContext context, Mark newNodesMark, boolean dumpGraph) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
112 new Instance(context, newNodesMark).apply(graph, dumpGraph);
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
113 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
114
11575
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
115 /**
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
116 * @param workingSet the initial working set of nodes on which the canonicalizer works, should
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
117 * be an auto-grow node bitmap
00672122f256 Make inner class CanonicalizerPhase.Instance private.
Roland Schatz <roland.schatz@oracle.com>
parents: 11568
diff changeset
118 */
16553
c9d3d0964adb proper generic types for CanonicalizerPhase.applyIncremental
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16337
diff changeset
119 public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet) {
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
120 applyIncremental(graph, context, workingSet, true);
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
121 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
122
16553
c9d3d0964adb proper generic types for CanonicalizerPhase.applyIncremental
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16337
diff changeset
123 public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, boolean dumpGraph) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
124 new Instance(context, workingSet).apply(graph, dumpGraph);
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
125 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
126
16553
c9d3d0964adb proper generic types for CanonicalizerPhase.applyIncremental
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16337
diff changeset
127 public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, Mark newNodesMark) {
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
128 applyIncremental(graph, context, workingSet, newNodesMark, true);
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
129 }
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11565
diff changeset
130
16553
c9d3d0964adb proper generic types for CanonicalizerPhase.applyIncremental
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16337
diff changeset
131 public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, Mark newNodesMark, boolean dumpGraph) {
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
132 new Instance(context, workingSet, newNodesMark).apply(graph, dumpGraph);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
133 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
134
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
135 private final class Instance extends Phase {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
136
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
137 private final Mark newNodesMark;
12052
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
138 private final PhaseContext context;
16553
c9d3d0964adb proper generic types for CanonicalizerPhase.applyIncremental
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16337
diff changeset
139 private final Iterable<? extends Node> initWorkingSet;
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
140
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
141 private NodeWorkList workList;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
142 private Tool tool;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
143
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
144 private Instance(PhaseContext context) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
145 this(context, null, null);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
146 }
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
147
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
148 private Instance(PhaseContext context, Iterable<? extends Node> workingSet) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
149 this(context, workingSet, null);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
150 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
151
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
152 private Instance(PhaseContext context, Mark newNodesMark) {
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
153 this(context, null, newNodesMark);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
154 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
155
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
156 private Instance(PhaseContext context, Iterable<? extends Node> workingSet, Mark newNodesMark) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
157 super("Canonicalizer");
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
158 this.newNodesMark = newNodesMark;
12052
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
159 this.context = context;
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
160 this.initWorkingSet = workingSet;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
161 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
162
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
163 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
164 protected void run(StructuredGraph graph) {
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
165 boolean wholeGraph = newNodesMark == null || newNodesMark.isStart();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
166 if (initWorkingSet == null) {
15956
edc33e8715d5 NodeWorkList refactoring
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15866
diff changeset
167 workList = graph.createIterativeNodeWorkList(wholeGraph, MAX_ITERATION_PER_NODE);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
168 } else {
15956
edc33e8715d5 NodeWorkList refactoring
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15866
diff changeset
169 workList = graph.createIterativeNodeWorkList(false, MAX_ITERATION_PER_NODE);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
170 workList.addAll(initWorkingSet);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
171 }
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12570
diff changeset
172 if (!wholeGraph) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
173 workList.addAll(graph.getNewNodes(newNodesMark));
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
174 }
9965
6c13b749d3f9 Tool: make class non-static
Bernhard Urban <bernhard.urban@jku.at>
parents: 9916
diff changeset
175 tool = new Tool();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
176 processWorkSet(graph);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
177 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
178
22573
74b3e5c0209c suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
179 @SuppressWarnings("try")
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
180 private void processWorkSet(StructuredGraph graph) {
16241
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
181 NodeEventListener listener = new NodeEventListener() {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
182
16241
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
183 public void nodeAdded(Node node) {
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
184 workList.add(node);
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
185 }
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
186
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
187 public void inputChanged(Node node) {
15956
edc33e8715d5 NodeWorkList refactoring
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15866
diff changeset
188 workList.add(node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
189 }
16241
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
190
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
191 public void usagesDroppedToZero(Node node) {
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
192 workList.add(node);
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
193 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
194
16241
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
195 };
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
196 try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
197 for (Node n : workList) {
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
198 processNode(n);
c6ebc1997a55 added listener for nodes being added to a graph; consolidated all node event listeners into new NodeEventListener interface and made registering such listeners work in a try-with-resources statement so that de-registration is automatic
Doug Simon <doug.simon@oracle.com>
parents: 16239
diff changeset
199 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
200 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
201 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
202
11266
2290f6b53429 Stop dragging a graph around in the CanonilizerPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11265
diff changeset
203 private void processNode(Node node) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
204 if (node.isAlive()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
205 METRIC_PROCESSED_NODES.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
206
19410
61d3cb8e1280 Add generic parameter to NodeClass. Change Graph#getNodes(Class) to Graph#getNodes(NodeClass).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19250
diff changeset
207 NodeClass<?> nodeClass = node.getNodeClass();
11882
51059863da73 replace instanceof type tests for Canonicalizable and Simplifiable with extra boolean properties in NodeClass (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11881
diff changeset
208 if (tryGlobalValueNumbering(node, nodeClass)) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
209 return;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
210 }
11266
2290f6b53429 Stop dragging a graph around in the CanonilizerPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11265
diff changeset
211 StructuredGraph graph = (StructuredGraph) node.graph();
15387
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 14707
diff changeset
212 if (!GraphUtil.tryKillUnused(node)) {
11882
51059863da73 replace instanceof type tests for Canonicalizable and Simplifiable with extra boolean properties in NodeClass (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11881
diff changeset
213 if (!tryCanonicalize(node, nodeClass)) {
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
214 if (node instanceof ValueNode) {
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
215 ValueNode valueNode = (ValueNode) node;
11565
e231671f39d0 Try constant folding in canonicalizer even if tryInferStamp didn't change anything.
Roland Schatz <roland.schatz@oracle.com>
parents: 11267
diff changeset
216 boolean improvedStamp = tryInferStamp(valueNode);
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
217 Constant constant = valueNode.stamp().asConstant();
11565
e231671f39d0 Try constant folding in canonicalizer even if tryInferStamp didn't change anything.
Roland Schatz <roland.schatz@oracle.com>
parents: 11267
diff changeset
218 if (constant != null && !(node instanceof ConstantNode)) {
15592
07ca8c86d31c CanonicalizerPhase, on constant stamp, only replace at value usages.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15530
diff changeset
219 valueNode.replaceAtUsages(InputType.Value, ConstantNode.forConstant(valueNode.stamp(), constant, context.getMetaAccess(), graph));
15530
a51d48ac96d3 Fix bug in CanonicalizerPhase that could remove fixed nodes with side effects in a corner case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 15417
diff changeset
220 GraphUtil.tryKillUnused(valueNode);
11565
e231671f39d0 Try constant folding in canonicalizer even if tryInferStamp didn't change anything.
Roland Schatz <roland.schatz@oracle.com>
parents: 11267
diff changeset
221 } else if (improvedStamp) {
e231671f39d0 Try constant folding in canonicalizer even if tryInferStamp didn't change anything.
Roland Schatz <roland.schatz@oracle.com>
parents: 11267
diff changeset
222 // the improved stamp may enable additional canonicalization
15866
0456d9b10322 CanonicalizerPhase: canonicalize usages when stamp changes
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15592
diff changeset
223 if (!tryCanonicalize(valueNode, nodeClass)) {
0456d9b10322 CanonicalizerPhase: canonicalize usages when stamp changes
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15592
diff changeset
224 valueNode.usages().forEach(workList::add);
0456d9b10322 CanonicalizerPhase: canonicalize usages when stamp changes
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 15592
diff changeset
225 }
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
226 }
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
227 }
5808
7bc36486ef27 Slightly more sensible work order in Canonicalizer (not unused? -> not canonicalized? -> stamp) and be sure to kill unused
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
228 }
7bc36486ef27 Slightly more sensible work order in Canonicalizer (not unused? -> not canonicalized? -> stamp) and be sure to kill unused
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5806
diff changeset
229 }
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
230 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
231 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
232
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
233 public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
17316
e6e678c3818f only generate data fields equality method for leaf ValueNumberable nodes; no longer generate Node.isLeafNode()
Doug Simon <doug.simon@oracle.com>
parents: 17276
diff changeset
234 if (nodeClass.valueNumberable() && !nodeClass.isLeafNode()) {
11266
2290f6b53429 Stop dragging a graph around in the CanonilizerPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11265
diff changeset
235 Node newNode = node.graph().findDuplicate(node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
236 if (newNode != null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
237 assert !(node instanceof FixedNode || newNode instanceof FixedNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
238 node.replaceAtUsages(newNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
239 node.safeDelete();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
240 METRIC_GLOBAL_VALUE_NUMBERING_HITS.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
241 Debug.log("GVN applied and new node is %1s", newNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
242 return true;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
243 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
244 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
245 return false;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
246 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
247
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
248 private AutoCloseable getCanonicalizeableContractAssertion(Node node) {
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
249 boolean needsAssertion = false;
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
250 assert (needsAssertion = true) == true;
16257
7e87ec3d156a enable new-node assertion for all Canonicalizable node types
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16247
diff changeset
251 if (needsAssertion) {
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
252 Mark mark = node.graph().getMark();
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
253 return () -> {
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
254 assert mark.equals(node.graph().getMark()) : "new node created while canonicalizing " + node.getClass().getSimpleName() + " " + node + ": " +
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
255 node.graph().getNewNodes(mark).snapshot();
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
256 };
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
257 } else {
16337
67f3267a8846 code and javadoc cleanups in Canonicalizable and NodeClassIterable
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16264
diff changeset
258 return null;
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
259 }
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
260 }
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
261
22573
74b3e5c0209c suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents: 22300
diff changeset
262 @SuppressWarnings("try")
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
263 public boolean tryCanonicalize(final Node node, NodeClass<?> nodeClass) {
19754
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
264 if (customCanonicalizer != null) {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
265 Node canonical = customCanonicalizer.canonicalize(node);
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
266 if (performReplacement(node, canonical)) {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
267 return true;
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
268 } else {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
269 customCanonicalizer.simplify(node, tool);
19952
59c2d62927f7 Canonicalizer: tryCanonicalize: return early if the custom canonicalizer has simplified the node away
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19937
diff changeset
270 if (node.isDeleted()) {
59c2d62927f7 Canonicalizer: tryCanonicalize: return early if the custom canonicalizer has simplified the node away
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19937
diff changeset
271 return true;
59c2d62927f7 Canonicalizer: tryCanonicalize: return early if the custom canonicalizer has simplified the node away
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19937
diff changeset
272 }
19754
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
273 }
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
274 }
16239
de84713267fa use default methods to select Canonicalizable behavior
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16206
diff changeset
275 if (nodeClass.isCanonicalizable()) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
276 METRIC_CANONICALIZATION_CONSIDERED_NODES.increment();
19868
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
277 Node canonical;
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
278 try (AutoCloseable verify = getCanonicalizeableContractAssertion(node)) {
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
279 canonical = ((Canonicalizable) node).canonical(tool);
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
280 if (canonical == node && nodeClass.isCommutative()) {
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
281 canonical = ((BinaryCommutative<?>) node).maybeCommuteInputs();
16155
c903c4e693bf run simplification if canonicalization is unsuccessful
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16135
diff changeset
282 }
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13191
diff changeset
283 } catch (Throwable e) {
19937
f599ac162bb7 CanonicalizerPhase: can not use Debug.handle without a corresponding scope/sandbox
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 19868
diff changeset
284 throw new RuntimeException(e);
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13191
diff changeset
285 }
19868
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
286 if (performReplacement(node, canonical)) {
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
287 return true;
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
288 }
13605
3def004aaa2d Canonicalizer: allow nodes to implement simplifiable and canonicalizable
Bernhard Urban <bernhard.urban@jku.at>
parents: 13585
diff changeset
289 }
3def004aaa2d Canonicalizer: allow nodes to implement simplifiable and canonicalizable
Bernhard Urban <bernhard.urban@jku.at>
parents: 13585
diff changeset
290
19716
2fd45bb25118 Initial version of new dominator-based conditional elimination phase.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19609
diff changeset
291 if (nodeClass.isSimplifiable() && simplify) {
17264
324ab4ce5d43 reduce noise in CanonicalizerPhase log output
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16897
diff changeset
292 Debug.log(3, "Canonicalizer: simplifying %s", node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
293 METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment();
19868
7d933ffe6df6 Remove fine grained debug scopes in the canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19754
diff changeset
294 node.simplify(tool);
16155
c903c4e693bf run simplification if canonicalization is unsuccessful
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16135
diff changeset
295 return node.isDeleted();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
296 }
16155
c903c4e693bf run simplification if canonicalization is unsuccessful
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16135
diff changeset
297 return false;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
298 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
299
9904
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
300 // @formatter:off
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
301 // cases: original node:
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
302 // |Floating|Fixed-unconnected|Fixed-connected|
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11782
diff changeset
303 // --------------------------------------------
9904
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
304 // null| 1 | X | 3 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
305 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
306 // Floating| 2 | X | 4 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
307 // canonical node: --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
308 // Fixed-unconnected| X | X | 5 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
309 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
310 // Fixed-connected| 2 | X | 6 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
311 // --------------------------------------------
11782
106bd0ff2498 add support for a node to canonicalize itself to a ControlSinkNode
Doug Simon <doug.simon@oracle.com>
parents: 11666
diff changeset
312 // ControlSink| X | X | 7 |
106bd0ff2498 add support for a node to canonicalize itself to a ControlSinkNode
Doug Simon <doug.simon@oracle.com>
parents: 11666
diff changeset
313 // --------------------------------------------
9904
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
314 // X: must not happen (checked with assertions)
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
315 // @formatter:on
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
316 private boolean performReplacement(final Node node, Node newCanonical) {
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
317 if (newCanonical == node) {
17264
324ab4ce5d43 reduce noise in CanonicalizerPhase log output
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16897
diff changeset
318 Debug.log(3, "Canonicalizer: work on %1s", node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
319 return false;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
320 } else {
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
321 Node canonical = newCanonical;
14707
6ce6c4ccba8f initial support for memory arithmetic on x86
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14112
diff changeset
322 Debug.log("Canonicalizer: replacing %1s with %1s", node, canonical);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
323 METRIC_CANONICALIZED_NODES.increment();
11266
2290f6b53429 Stop dragging a graph around in the CanonilizerPhase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11265
diff changeset
324 StructuredGraph graph = (StructuredGraph) node.graph();
16206
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
325 if (canonical != null && !canonical.isAlive()) {
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
326 assert !canonical.isDeleted();
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
327 canonical = graph.addOrUniqueWithInputs(canonical);
2a1f3a8f76f1 handle Canonicalizable.Unary/Binary in CanonicalizerPhase and EquationalReasoner
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16157
diff changeset
328 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
329 if (node instanceof FloatingNode) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
330 if (canonical == null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
331 // case 1
16247
b35b25c68387 returning null Canonicalizer.canonical replaces usages with null
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16241
diff changeset
332 node.replaceAtUsages(null);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
333 graph.removeFloating((FloatingNode) node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
334 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
335 // case 2
19001
5a79fa76b489 Run eclipse format.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18995
diff changeset
336 assert !(canonical instanceof FixedNode) || (canonical.predecessor() != null || canonical instanceof StartNode || canonical instanceof AbstractMergeNode) : node + " -> " +
5a79fa76b489 Run eclipse format.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18995
diff changeset
337 canonical + " : replacement should be floating or fixed and connected";
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
338 graph.replaceFloating((FloatingNode) node, canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
339 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
340 } else {
12484
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
341 assert node instanceof FixedNode && node.predecessor() != null : node + " -> " + canonical + " : node should be fixed & connected (" + node.predecessor() + ")";
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
342 FixedNode fixed = (FixedNode) node;
11782
106bd0ff2498 add support for a node to canonicalize itself to a ControlSinkNode
Doug Simon <doug.simon@oracle.com>
parents: 11666
diff changeset
343 if (canonical instanceof ControlSinkNode) {
106bd0ff2498 add support for a node to canonicalize itself to a ControlSinkNode
Doug Simon <doug.simon@oracle.com>
parents: 11666
diff changeset
344 // case 7
14112
317bfc1ae64e CanonicalizerPhase: cosmetic simplification in performReplacement
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14023
diff changeset
345 fixed.replaceAtPredecessor(canonical);
12484
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
346 GraphUtil.killCFG(fixed);
11782
106bd0ff2498 add support for a node to canonicalize itself to a ControlSinkNode
Doug Simon <doug.simon@oracle.com>
parents: 11666
diff changeset
347 return true;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
348 } else {
12484
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
349 assert fixed instanceof FixedWithNextNode;
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
350 FixedWithNextNode fixedWithNext = (FixedWithNextNode) fixed;
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
351 // When removing a fixed node, new canonicalization
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
352 // opportunities for its successor may arise
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
353 assert fixedWithNext.next() != null;
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
354 tool.addToWorkList(fixedWithNext.next());
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
355 if (canonical == null) {
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
356 // case 3
16247
b35b25c68387 returning null Canonicalizer.canonical replaces usages with null
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16241
diff changeset
357 node.replaceAtUsages(null);
12484
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
358 graph.removeFixed(fixedWithNext);
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
359 } else if (canonical instanceof FloatingNode) {
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
360 // case 4
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
361 graph.replaceFixedWithFloating(fixedWithNext, (FloatingNode) canonical);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
362 } else {
12484
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
363 assert canonical instanceof FixedNode;
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
364 if (canonical.predecessor() == null) {
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
365 assert !canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " shouldn't have successors";
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
366 // case 5
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
367 graph.replaceFixedWithFixed(fixedWithNext, (FixedWithNextNode) canonical);
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
368 } else {
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
369 assert canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " should have successors";
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
370 // case 6
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
371 node.replaceAtUsages(canonical);
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
372 graph.removeFixed(fixedWithNext);
2d8a8980eda8 Canonicalize DynamicDeoptimize nodes back to Deoptimize when used with a constant reason&action
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12052
diff changeset
373 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
374 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
375 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
376 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
377 return true;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
378 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
379 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
380
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
381 /**
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
382 * Calls {@link ValueNode#inferStamp()} on the node and, if it returns true (which means
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
383 * that the stamp has changed), re-queues the node's usages. If the stamp has changed then
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
384 * this method also checks if the stamp now describes a constant integer value, in which
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
385 * case the node is replaced with a constant.
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
386 */
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
387 private boolean tryInferStamp(ValueNode node) {
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
388 if (node.isAlive()) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
389 METRIC_INFER_STAMP_CALLED.increment();
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
390 if (node.inferStamp()) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
391 METRIC_STAMP_CHANGED.increment();
11267
ceb2703b40b8 Re-introduce canonicalization when the stamp represents a singleton using Stamp.asConstant
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11266
diff changeset
392 for (Node usage : node.usages()) {
15956
edc33e8715d5 NodeWorkList refactoring
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15866
diff changeset
393 workList.add(usage);
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
394 }
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10856
diff changeset
395 return true;
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
396 }
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
397 }
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
398 return false;
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
399 }
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
400
9965
6c13b749d3f9 Tool: make class non-static
Bernhard Urban <bernhard.urban@jku.at>
parents: 9916
diff changeset
401 private final class Tool implements SimplifierTool {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
402
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
403 @Override
11879
7e57add9c0d5 broadened types in SimplifierTool interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11798
diff changeset
404 public void deleteBranch(Node branch) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
405 branch.predecessor().replaceFirstSuccessor(branch, null);
15417
b2381f53c77f pass SimplifierTool to GraphUtil.killCFG
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15387
diff changeset
406 GraphUtil.killCFG(branch, this);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
407 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
408
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
409 @Override
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11884
diff changeset
410 public MetaAccessProvider getMetaAccess() {
12052
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
411 return context.getMetaAccess();
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
412 }
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
413
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
414 @Override
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
415 public ConstantReflectionProvider getConstantReflection() {
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
416 return context.getConstantReflection();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
417 }
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
418
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
419 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
420 public void addToWorkList(Node node) {
15956
edc33e8715d5 NodeWorkList refactoring
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15866
diff changeset
421 workList.add(node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
422 }
7326
6939a5af19d5 Be sure to remove framestate of merge when removing empty diamond shape
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7315
diff changeset
423
16157
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16155
diff changeset
424 public void addToWorkList(Iterable<? extends Node> nodes) {
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16155
diff changeset
425 workList.addAll(nodes);
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16155
diff changeset
426 }
bd1202138e21 add SimplifierTool.addToWorkList for Iterable<Node>
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16155
diff changeset
427
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
428 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
429 public void removeIfUnused(Node node) {
15387
fd435374bb93 moved tryKillUnused to GraphUtil
Miguel Garcia <miguel.m.garcia@oracle.com>
parents: 14707
diff changeset
430 GraphUtil.tryKillUnused(node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
431 }
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
432
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
433 @Override
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
434 public boolean canonicalizeReads() {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
435 return canonicalizeReads;
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
436 }
20826
a4aa2116cfe0 Support node canonicalization when not all usages of a node are known yet
Christian Wimmer <christian.wimmer@oracle.com>
parents: 19952
diff changeset
437
a4aa2116cfe0 Support node canonicalization when not all usages of a node are known yet
Christian Wimmer <christian.wimmer@oracle.com>
parents: 19952
diff changeset
438 @Override
a4aa2116cfe0 Support node canonicalization when not all usages of a node are known yet
Christian Wimmer <christian.wimmer@oracle.com>
parents: 19952
diff changeset
439 public boolean allUsagesAvailable() {
a4aa2116cfe0 Support node canonicalization when not all usages of a node are known yet
Christian Wimmer <christian.wimmer@oracle.com>
parents: 19952
diff changeset
440 return true;
a4aa2116cfe0 Support node canonicalization when not all usages of a node are known yet
Christian Wimmer <christian.wimmer@oracle.com>
parents: 19952
diff changeset
441 }
7326
6939a5af19d5 Be sure to remove framestate of merge when removing empty diamond shape
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7315
diff changeset
442 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
443 }
19754
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
444
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
445 public boolean getCanonicalizeReads() {
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
446 return canonicalizeReads;
39de568cbb02 Reintroduce CustomCanonicalizer
Stefan Anzinger <stefan.anzinger@oracle.com>
parents: 19716
diff changeset
447 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
448 }