annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java @ 11251:e428ffc7a0ad

new PureFunctionMacroNode
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 07 Aug 2013 18:33:44 +0200
parents a0401b1f7cc4
children ef6915cf1e59
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 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
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
25 import java.util.concurrent.*;
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
26
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
27 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5501
diff changeset
28 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
29 import com.oracle.graal.debug.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.graph.*;
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
31 import com.oracle.graal.graph.Graph.NodeChangedListener;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.nodes.calc.*;
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
34 import com.oracle.graal.nodes.extended.*;
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
35 import com.oracle.graal.nodes.java.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
36 import com.oracle.graal.nodes.spi.*;
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
37 import com.oracle.graal.nodes.type.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.nodes.util.*;
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
39 import com.oracle.graal.phases.*;
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
40 import com.oracle.graal.phases.tiers.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
42 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
43
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 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
45 private static final DebugMetric METRIC_CANONICALIZED_NODES = Debug.metric("CanonicalizedNodes");
4eb9895d9afe Refactoring of the debug framework. Move compiler thread implementation to its own file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5061
diff changeset
46 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
47 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
48 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
49 private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes");
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
50 public 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
51
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
52 private final boolean canonicalizeReads;
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
53
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
54 public interface CustomCanonicalizer {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
55
9102
908cac5f443c Change the parameter to the custom canonicalizer to always be of ValueNode type.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9049
diff changeset
56 ValueNode canonicalize(ValueNode node);
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
57 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
58
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
59 public CanonicalizerPhase(boolean canonicalizeReads) {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
60 this.canonicalizeReads = canonicalizeReads;
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
61 }
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
62
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 @Override
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
64 protected void run(StructuredGraph graph, PhaseContext context) {
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
65 new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads).run(graph);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
66 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
67
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
68 public static class Instance extends Phase {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
69
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
70 private final int newNodesMark;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
71 private final Assumptions assumptions;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
72 private final MetaAccessProvider runtime;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
73 private final CustomCanonicalizer customCanonicalizer;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
74 private final Iterable<Node> initWorkingSet;
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
75 private final boolean canonicalizeReads;
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
76
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
77 private NodeWorkList workList;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
78 private Tool tool;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
79
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
80 public Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads) {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
81 this(runtime, assumptions, canonicalizeReads, null, 0, null);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
82 }
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
83
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
84 /**
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
85 * @param runtime
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
86 * @param assumptions
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
87 * @param workingSet the initial working set of nodes on which the canonicalizer works,
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
88 * should be an auto-grow node bitmap
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
89 * @param customCanonicalizer
10421
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
90 * @param canonicalizeReads flag to indicate if
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
91 * {@link LoadFieldNode#canonical(CanonicalizerTool)} and
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
92 * {@link ReadNode#canonical(CanonicalizerTool)} should canonicalize reads of
1669d8b5863a aot verify: check if string constant is really a interned string; javadoc updates
Bernhard Urban <bernhard.urban@jku.at>
parents: 9965
diff changeset
93 * constant fields.
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
94 */
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
95 public Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads, Iterable<Node> workingSet, CustomCanonicalizer customCanonicalizer) {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
96 this(runtime, assumptions, canonicalizeReads, workingSet, 0, customCanonicalizer);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
97 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
98
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
99 /**
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
100 * @param newNodesMark only the {@linkplain Graph#getNewNodes(int) new nodes} specified by
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
101 * this mark are processed otherwise all nodes in the graph are processed
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
102 */
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
103 public Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads, int newNodesMark, CustomCanonicalizer customCanonicalizer) {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
104 this(runtime, assumptions, canonicalizeReads, null, newNodesMark, customCanonicalizer);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
105 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
106
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
107 public Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads, Iterable<Node> workingSet, int newNodesMark, CustomCanonicalizer customCanonicalizer) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
108 super("Canonicalizer");
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
109 this.newNodesMark = newNodesMark;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
110 this.assumptions = assumptions;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
111 this.runtime = runtime;
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
112 this.canonicalizeReads = canonicalizeReads;
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
113 this.customCanonicalizer = customCanonicalizer;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
114 this.initWorkingSet = workingSet;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
115 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
116
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
117 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
118 protected void run(StructuredGraph graph) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
119 if (initWorkingSet == null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
120 workList = graph.createNodeWorkList(newNodesMark == 0, MAX_ITERATION_PER_NODE);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
121 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
122 workList = graph.createNodeWorkList(false, MAX_ITERATION_PER_NODE);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
123 workList.addAll(initWorkingSet);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
124 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
125 if (newNodesMark > 0) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
126 workList.addAll(graph.getNewNodes(newNodesMark));
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
127 }
9965
6c13b749d3f9 Tool: make class non-static
Bernhard Urban <bernhard.urban@jku.at>
parents: 9916
diff changeset
128 tool = new Tool();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
129 processWorkSet(graph);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
130 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
131
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
132 private void processWorkSet(StructuredGraph graph) {
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
133 NodeChangedListener nodeChangedListener = new NodeChangedListener() {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
134
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
135 @Override
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
136 public void nodeChanged(Node node) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
137 workList.addAgain(node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
138 }
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
139 };
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
140 graph.trackInputChange(nodeChangedListener);
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
141 graph.trackUsagesDroppedZero(nodeChangedListener);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
142
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
143 for (Node n : workList) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
144 processNode(n, graph);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
145 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
146
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
147 graph.stopTrackingInputChange();
9331
199c77760850 Rename InputChangedListener => NodeChangedListener. Add event for usage count of a node dropping to 0.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9329
diff changeset
148 graph.stopTrackingUsagesDroppedZero();
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
149 }
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 private void processNode(Node node, StructuredGraph graph) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
152 if (node.isAlive()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
153 METRIC_PROCESSED_NODES.increment();
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 if (tryGlobalValueNumbering(node, graph)) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
156 return;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
157 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
158 int mark = graph.getMark();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
159 if (!tryKillUnused(node)) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
160 if (!tryCanonicalize(node, graph)) {
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
161 if (tryInferStamp(node, graph)) {
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
162 // the improved stamp may enable additional canonicalization
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
163 tryCanonicalize(node, graph);
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
164 }
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
165 }
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
166 }
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
167
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
168 for (Node newNode : graph.getNewNodes(mark)) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
169 workList.add(newNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
170 }
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
171 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
172 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
173
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
174 private static boolean tryKillUnused(Node node) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
175 if (node.isAlive() && GraphUtil.isFloatingNode().apply(node) && node.usages().isEmpty()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
176 GraphUtil.killWithUnusedFloatingInputs(node);
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
177 return true;
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
178 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
179 return false;
5419
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
180 }
3c16d338888e Merge Canonicalizer and GVN Phases
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5380
diff changeset
181
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
182 public static boolean tryGlobalValueNumbering(Node node, StructuredGraph graph) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
183 if (node.getNodeClass().valueNumberable()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
184 Node newNode = graph.findDuplicate(node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
185 if (newNode != null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
186 assert !(node instanceof FixedNode || newNode instanceof FixedNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
187 node.replaceAtUsages(newNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
188 node.safeDelete();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
189 METRIC_GLOBAL_VALUE_NUMBERING_HITS.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
190 Debug.log("GVN applied and new node is %1s", newNode);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
191 return true;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
192 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
193 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
194 return false;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
195 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
196
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
197 public boolean tryCanonicalize(final Node node, final StructuredGraph graph) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
198 boolean result = baseTryCanonicalize(node, graph);
9102
908cac5f443c Change the parameter to the custom canonicalizer to always be of ValueNode type.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9049
diff changeset
199 if (!result && customCanonicalizer != null && node instanceof ValueNode) {
908cac5f443c Change the parameter to the custom canonicalizer to always be of ValueNode type.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9049
diff changeset
200 ValueNode valueNode = (ValueNode) node;
908cac5f443c Change the parameter to the custom canonicalizer to always be of ValueNode type.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9049
diff changeset
201 ValueNode canonical = customCanonicalizer.canonicalize(valueNode);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
202 result = performReplacement(node, graph, canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
203 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
204 return result;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
205 }
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
206
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
207 public boolean baseTryCanonicalize(final Node node, final StructuredGraph graph) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
208 if (node instanceof Canonicalizable) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
209 assert !(node instanceof Simplifiable);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
210 METRIC_CANONICALIZATION_CONSIDERED_NODES.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
211 return Debug.scope("CanonicalizeNode", node, new Callable<Boolean>() {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
212
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
213 public Boolean call() {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
214 ValueNode canonical = ((Canonicalizable) node).canonical(tool);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
215 return performReplacement(node, graph, canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
216 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
217 });
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
218 } else if (node instanceof Simplifiable) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
219 Debug.log("Canonicalizer: simplifying %s", node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
220 METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
221 Debug.scope("SimplifyNode", node, new Runnable() {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7522
diff changeset
222
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
223 public void run() {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
224 ((Simplifiable) node).simplify(tool);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
225 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
226 });
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
227 }
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
228 return node.isDeleted();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
229 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
230
9904
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
231 // @formatter:off
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
232 // cases: original node:
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
233 // |Floating|Fixed-unconnected|Fixed-connected|
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
234 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
235 // null| 1 | X | 3 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
236 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
237 // Floating| 2 | X | 4 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
238 // canonical node: --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
239 // Fixed-unconnected| X | X | 5 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
240 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
241 // Fixed-connected| 2 | X | 6 |
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
242 // --------------------------------------------
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
243 // X: must not happen (checked with assertions)
77c4b6c9d6e2 CanonicalizerPhase: move comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 9331
diff changeset
244 // @formatter:on
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
245 private boolean performReplacement(final Node node, final StructuredGraph graph, ValueNode canonical) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
246 if (canonical == node) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
247 Debug.log("Canonicalizer: work on %s", node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
248 return false;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
249 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
250 Debug.log("Canonicalizer: replacing %s with %s", node, canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
251 METRIC_CANONICALIZED_NODES.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
252 if (node instanceof FloatingNode) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
253 if (canonical == null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
254 // case 1
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
255 graph.removeFloating((FloatingNode) node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
256 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
257 // case 2
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
258 assert !(canonical instanceof FixedNode) || (canonical.predecessor() != null || canonical instanceof StartNode || canonical instanceof MergeNode) : node + " -> " + canonical +
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
259 " : replacement should be floating or fixed and connected";
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
260 graph.replaceFloating((FloatingNode) node, canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
261 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
262 } else {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
263 assert node instanceof FixedWithNextNode && node.predecessor() != null : node + " -> " + canonical + " : node should be fixed & connected (" + node.predecessor() + ")";
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
264 FixedWithNextNode fixedWithNext = (FixedWithNextNode) node;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
265
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
266 // When removing a fixed node, new canonicalization opportunities for its
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
267 // successor
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
268 // may arise
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
269 assert fixedWithNext.next() != null;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
270 tool.addToWorkList(fixedWithNext.next());
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
271
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
272 if (canonical == null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
273 // case 3
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
274 graph.removeFixed(fixedWithNext);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
275 } else if (canonical instanceof FloatingNode) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
276 // case 4
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
277 graph.replaceFixedWithFloating(fixedWithNext, (FloatingNode) canonical);
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
278 } else {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
279 assert canonical instanceof FixedNode;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
280 if (canonical.predecessor() == null) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
281 assert !canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " shouldn't have successors";
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
282 // case 5
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
283 graph.replaceFixedWithFixed(fixedWithNext, (FixedWithNextNode) canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
284 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
285 assert canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " should have successors";
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
286 // case 6
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
287 node.replaceAtUsages(canonical);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
288 graph.removeFixed(fixedWithNext);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
289 }
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
290 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
291 }
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
292 return true;
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
293 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
294 }
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7256
diff changeset
295
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
296 /**
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
297 * Calls {@link ValueNode#inferStamp()} on the node and, if it returns true (which means
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
298 * that the stamp has changed), re-queues the node's usages . If the stamp has changed then
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
299 * this method also checks if the stamp now describes a constant integer value, in which
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
300 * case the node is replaced with a constant.
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
301 */
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
302 private boolean tryInferStamp(Node node, StructuredGraph graph) {
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
303 if (node.isAlive() && node instanceof ValueNode) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
304 ValueNode valueNode = (ValueNode) node;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
305 METRIC_INFER_STAMP_CALLED.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
306 if (valueNode.inferStamp()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
307 METRIC_STAMP_CHANGED.increment();
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
308 if (valueNode.stamp() instanceof IntegerStamp && valueNode.integerStamp().lowerBound() == valueNode.integerStamp().upperBound()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
309 ValueNode replacement = ConstantNode.forIntegerKind(valueNode.kind(), valueNode.integerStamp().lowerBound(), graph);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
310 Debug.log("Canonicalizer: replacing %s with %s (inferStamp)", valueNode, replacement);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
311 valueNode.replaceAtUsages(replacement);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
312 } else {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
313 for (Node usage : valueNode.usages()) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
314 workList.addAgain(usage);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
315 }
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
316 return true;
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
317 }
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
318 }
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
319 }
10856
a0401b1f7cc4 Retry canonicalization after inferStamp.
Roland Schatz <roland.schatz@oracle.com>
parents: 10421
diff changeset
320 return false;
5657
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
321 }
d71eb56d6bb0 new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents: 5558
diff changeset
322
9965
6c13b749d3f9 Tool: make class non-static
Bernhard Urban <bernhard.urban@jku.at>
parents: 9916
diff changeset
323 private final class Tool implements SimplifierTool {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
325 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
326 public void deleteBranch(FixedNode branch) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
327 branch.predecessor().replaceFirstSuccessor(branch, null);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
328 GraphUtil.killCFG(branch);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
329 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
330
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
331 /**
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
332 * @return an object that can be used for recording assumptions or {@code null} if
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
333 * assumptions are not allowed in the current context.
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
334 */
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
335 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
336 public Assumptions assumptions() {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
337 return assumptions;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
338 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
339
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
340 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
341 public MetaAccessProvider runtime() {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
342 return runtime;
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
343 }
4310
72d099e5be61 more CanonicalizerPhase simplifications, added Simplifiable interface
Lukas Stadler <lukas.stadler@jku.at>
parents: 4309
diff changeset
344
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
345 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
346 public void addToWorkList(Node node) {
9965
6c13b749d3f9 Tool: make class non-static
Bernhard Urban <bernhard.urban@jku.at>
parents: 9916
diff changeset
347 workList.addAgain(node);
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
348 }
7326
6939a5af19d5 Be sure to remove framestate of merge when removing empty diamond shape
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7315
diff changeset
349
9049
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
350 @Override
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
351 public void removeIfUnused(Node node) {
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
352 tryKillUnused(node);
6d376d09880b Make CanonicalizerPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 7827
diff changeset
353 }
9908
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
354
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
355 @Override
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
356 public boolean canonicalizeReads() {
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
357 return canonicalizeReads;
91295caf53b6 CanonicalizerPhase: add OptCanonicalizeReads option (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 9907
diff changeset
358 }
7326
6939a5af19d5 Be sure to remove framestate of merge when removing empty diamond shape
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7315
diff changeset
359 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
360 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
361 }