annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java @ 8415:2361bf148c06

rename packages: *snippets* -> *replacements*
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Mar 2013 22:23:14 +0100
parents graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/InstanceOfSnippetsTemplates.java@d9347ee39fbe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
23 package com.oracle.graal.replacements;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6696
diff changeset
25 import static com.oracle.graal.nodes.calc.CompareNode.*;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.util.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28
7034
89df4e71940a More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6950
diff changeset
29 import com.oracle.graal.api.code.*;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import com.oracle.graal.api.meta.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.graph.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.nodes.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.nodes.calc.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.nodes.java.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.spi.*;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.nodes.util.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
37 import com.oracle.graal.replacements.SnippetTemplate.*;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
40 * Helper class for lowering {@link InstanceOfNode}s with snippets. The majority of the complexity
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
41 * in such a lowering derives from the fact that {@link InstanceOfNode} is a floating node. A
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
42 * snippet used to lower an {@link InstanceOfNode} will almost always incorporate control flow and
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
43 * replacing a floating node with control flow is not trivial.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 * <p>
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
45 * The mechanism implemented in this class ensures that the graph for an instanceof snippet is
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
46 * instantiated once per {@link InstanceOfNode} being lowered. The result produced is then re-used
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
47 * by all usages of the node. Additionally, if there is a single usage that is an {@link IfNode},
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
48 * the control flow in the snippet is connected directly to the true and false successors of the
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
49 * {@link IfNode}. This avoids materializing the instanceof test as a boolean which is then retested
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
50 * by the {@link IfNode}.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 */
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 8178
diff changeset
52 public abstract class InstanceOfSnippetsTemplates<T extends Snippets> extends AbstractTemplates<T> {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7066 7034
diff changeset
54 public InstanceOfSnippetsTemplates(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target, Class<T> snippetsClass) {
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7066 7034
diff changeset
55 super(runtime, assumptions, target, snippetsClass);
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 * The key and arguments used to retrieve and instantiate an instanceof snippet template.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 public static class KeyAndArguments {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
62
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 public final Key key;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 public final Arguments arguments;
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
65
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 public KeyAndArguments(Key key, Arguments arguments) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 this.key = key;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 this.arguments = arguments;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 * Gets the key and arguments used to retrieve and instantiate an instanceof snippet template.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 protected abstract KeyAndArguments getKeyAndArguments(InstanceOfUsageReplacer replacer, LoweringTool tool);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
78 public void lower(FloatingNode instanceOf, LoweringTool tool) {
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
79 assert instanceOf instanceof InstanceOfNode || instanceOf instanceof InstanceOfDynamicNode;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 List<Node> usages = instanceOf.usages().snapshot();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 int nUsages = usages.size();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 Instantiation instantiation = new Instantiation();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 for (Node usage : usages) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 final StructuredGraph graph = (StructuredGraph) usage.graph();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 InstanceOfUsageReplacer replacer = createReplacer(instanceOf, tool, nUsages, instantiation, usage, graph);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 if (instantiation.isInitialized()) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 // No need to re-instantiate the snippet - just re-use its result
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 replacer.replaceUsingInstantiation();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 } else {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 KeyAndArguments keyAndArguments = getKeyAndArguments(replacer, tool);
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6696
diff changeset
94 SnippetTemplate template = cache.get(keyAndArguments.key, assumptions);
8178
67ee3325c285 added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents: 7899
diff changeset
95 template.instantiate(runtime, instanceOf, replacer, tool, keyAndArguments.arguments);
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 assert instanceOf.usages().isEmpty();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 if (!instanceOf.isDeleted()) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 GraphUtil.killWithUnusedFloatingInputs(instanceOf);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
106 * Gets the specific replacer object used to replace the usage of an instanceof node with the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
107 * result of an instantiated instanceof snippet.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108 */
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
109 protected InstanceOfUsageReplacer createReplacer(FloatingNode instanceOf, LoweringTool tool, int nUsages, Instantiation instantiation, Node usage, final StructuredGraph graph) {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 InstanceOfUsageReplacer replacer;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
111 if (usage instanceof IfNode) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
112 replacer = new IfUsageReplacer(instantiation, ConstantNode.forInt(1, graph), ConstantNode.forInt(0, graph), instanceOf, (IfNode) usage, nUsages == 1, tool);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
113 } else {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114 assert usage instanceof ConditionalNode : "unexpected usage of " + instanceOf + ": " + usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
115 ConditionalNode c = (ConditionalNode) usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
116 replacer = new ConditionalUsageReplacer(instantiation, c.trueValue(), c.falseValue(), instanceOf, c);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
117 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
118 return replacer;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
119 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
121 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
122 * The result of an instantiating an instanceof snippet. This enables a snippet instantiation to
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
123 * be re-used which reduces compile time and produces better code.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125 public static final class Instantiation {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
126
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 private PhiNode result;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128 private CompareNode condition;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 private ValueNode trueValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130 private ValueNode falseValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133 * Determines if the instantiation has occurred.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
135 boolean isInitialized() {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
136 return result != null;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
137 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 void initialize(PhiNode phi, ValueNode t, ValueNode f) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
140 assert !isInitialized();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 this.result = phi;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 this.trueValue = t;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 this.falseValue = f;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
145
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 * Gets the result of this instantiation as a condition.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
148 *
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 * @param testValue the returned condition is true if the result is equal to this value
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 CompareNode asCondition(ValueNode testValue) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
152 assert isInitialized();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 if (condition == null || condition.y() != testValue) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 // Re-use previously generated condition if the trueValue for the test is the same
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 condition = createCompareNode(Condition.EQ, result, testValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
157 return condition;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
159
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 * Gets the result of the instantiation as a materialized value.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
162 *
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
163 * @param t the true value for the materialization
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
164 * @param f the false value for the materialization
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
165 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166 ValueNode asMaterialization(ValueNode t, ValueNode f) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 assert isInitialized();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
168 if (t == this.trueValue && f == this.falseValue) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 // Can simply use the phi result if the same materialized values are expected.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 return result;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171 } else {
7724
ac3579b4adc9 remove MaterializeNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
172 return t.graph().unique(new ConditionalNode(asCondition(trueValue), t, f));
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
174 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
175 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
176
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
177 /**
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
178 * Replaces a usage of an {@link InstanceOfNode} or {@link InstanceOfDynamicNode}.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
180 public abstract static class InstanceOfUsageReplacer implements UsageReplacer {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
181
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 public final Instantiation instantiation;
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
183 public final FloatingNode instanceOf;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184 public final ValueNode trueValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 public final ValueNode falseValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
186
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
187 public InstanceOfUsageReplacer(Instantiation instantiation, FloatingNode instanceOf, ValueNode trueValue, ValueNode falseValue) {
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
188 assert instanceOf instanceof InstanceOfNode || instanceOf instanceof InstanceOfDynamicNode;
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
189 this.instantiation = instantiation;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 this.instanceOf = instanceOf;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191 this.trueValue = trueValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 this.falseValue = falseValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
193 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
194
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
195 /**
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
196 * Does the replacement based on a previously snippet instantiation.
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
197 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 public abstract void replaceUsingInstantiation();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
200
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
201 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
202 * Replaces an {@link IfNode} usage of an {@link InstanceOfNode} or
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
203 * {@link InstanceOfDynamicNode}.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
204 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
205 public static class IfUsageReplacer extends InstanceOfUsageReplacer {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
206
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
207 private final boolean solitaryUsage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
208 private final IfNode usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209 private final boolean sameBlock;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
211 public IfUsageReplacer(Instantiation instantiation, ValueNode trueValue, ValueNode falseValue, FloatingNode instanceOf, IfNode usage, boolean solitaryUsage, LoweringTool tool) {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212 super(instantiation, instanceOf, trueValue, falseValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 this.sameBlock = tool.getBlockFor(usage) == tool.getBlockFor(instanceOf);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 this.solitaryUsage = solitaryUsage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 this.usage = usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
218 @Override
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
219 public void replaceUsingInstantiation() {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
220 usage.replaceFirstInput(instanceOf, instantiation.asCondition(trueValue));
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222
7899
21ccfe2e180b small clarification for InstanceOfSnippetsTemplates
Lukas Stadler <lukas.stadler@jku.at>
parents: 7863
diff changeset
223 private boolean usageFollowsInstantiation() {
21ccfe2e180b small clarification for InstanceOfSnippetsTemplates
Lukas Stadler <lukas.stadler@jku.at>
parents: 7863
diff changeset
224 return instantiation.result != null && instantiation.result.merge().next() == usage;
21ccfe2e180b small clarification for InstanceOfSnippetsTemplates
Lukas Stadler <lukas.stadler@jku.at>
parents: 7863
diff changeset
225 }
21ccfe2e180b small clarification for InstanceOfSnippetsTemplates
Lukas Stadler <lukas.stadler@jku.at>
parents: 7863
diff changeset
226
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
227 @Override
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
228 public void replace(ValueNode oldNode, ValueNode newNode) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
229 assert newNode instanceof PhiNode;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
230 assert oldNode == instanceOf;
7899
21ccfe2e180b small clarification for InstanceOfSnippetsTemplates
Lukas Stadler <lukas.stadler@jku.at>
parents: 7863
diff changeset
231 if (sameBlock && solitaryUsage && usageFollowsInstantiation()) {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
232 removeIntermediateMaterialization(newNode);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
233 } else {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
234 newNode.inferStamp();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
235 instantiation.initialize((PhiNode) newNode, trueValue, falseValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
236 usage.replaceFirstInput(oldNode, instantiation.asCondition(trueValue));
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
237 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
238 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
239
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
240 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
241 * Directly wires the incoming edges of the merge at the end of the snippet to the outgoing
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
242 * edges of the IfNode that uses the materialized result.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
243 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
244 private void removeIntermediateMaterialization(ValueNode newNode) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
245 IfNode ifNode = usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
246 PhiNode phi = (PhiNode) newNode;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
247 MergeNode merge = phi.merge();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
248 assert merge.stateAfter() == null;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
249
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
250 List<EndNode> mergePredecessors = merge.cfgPredecessors().snapshot();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
251 assert phi.valueCount() == mergePredecessors.size();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
252
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
253 List<EndNode> falseEnds = new ArrayList<>(mergePredecessors.size());
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
254 List<EndNode> trueEnds = new ArrayList<>(mergePredecessors.size());
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
255
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
256 int endIndex = 0;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
257 for (EndNode end : mergePredecessors) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
258 ValueNode endValue = phi.valueAt(endIndex++);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
259 if (endValue == trueValue) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
260 trueEnds.add(end);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
261 } else {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
262 assert endValue == falseValue;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
263 falseEnds.add(end);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
264 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
265 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
266
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
267 BeginNode trueSuccessor = ifNode.trueSuccessor();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
268 BeginNode falseSuccessor = ifNode.falseSuccessor();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
269 ifNode.setTrueSuccessor(null);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
270 ifNode.setFalseSuccessor(null);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
271
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
272 connectEnds(merge, trueEnds, trueSuccessor);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
273 connectEnds(merge, falseEnds, falseSuccessor);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
274
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
275 GraphUtil.killCFG(merge);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
276 GraphUtil.killCFG(ifNode);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
277
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
278 assert !merge.isAlive() : merge;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
279 assert !phi.isAlive() : phi;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
280 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
281
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
282 private static void connectEnds(MergeNode merge, List<EndNode> ends, BeginNode successor) {
6696
2ec25815d84e When InstanceOfNode is lowered to always true or always false condition, then the no longer used branch needs to be removed from graph.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6663
diff changeset
283 if (ends.size() == 0) {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
284 // InstanceOf has been lowered to always true or always false - this successor is
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
285 // therefore unreachable.
6696
2ec25815d84e When InstanceOfNode is lowered to always true or always false condition, then the no longer used branch needs to be removed from graph.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6663
diff changeset
286 GraphUtil.killCFG(successor);
2ec25815d84e When InstanceOfNode is lowered to always true or always false condition, then the no longer used branch needs to be removed from graph.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6663
diff changeset
287 } else if (ends.size() == 1) {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
288 EndNode end = ends.get(0);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
289 ((FixedWithNextNode) end.predecessor()).setNext(successor);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
290 merge.removeEnd(end);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
291 GraphUtil.killCFG(end);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
292 } else {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
293 assert ends.size() > 1;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
294 MergeNode newMerge = merge.graph().add(new MergeNode());
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
295
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
296 for (EndNode end : ends) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
297 newMerge.addForwardEnd(end);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
298 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
299 newMerge.setNext(successor);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
300 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
301 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
302 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
303
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
304 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
305 * Replaces a {@link ConditionalNode} usage of an {@link InstanceOfNode} or
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7278
diff changeset
306 * {@link InstanceOfDynamicNode}.
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
307 */
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
308 public static class ConditionalUsageReplacer extends InstanceOfUsageReplacer {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
309
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
310 public final ConditionalNode usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
311
7278
346336325337 added intrinsification of Class.isInstance()
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
312 public ConditionalUsageReplacer(Instantiation instantiation, ValueNode trueValue, ValueNode falseValue, FloatingNode instanceOf, ConditionalNode usage) {
6663
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
313 super(instantiation, instanceOf, trueValue, falseValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
314 this.usage = usage;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
315 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
316
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
317 @Override
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
318 public void replaceUsingInstantiation() {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
319 ValueNode newValue = instantiation.asMaterialization(trueValue, falseValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
320 usage.replaceAtUsages(newValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
321 usage.clearInputs();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
322 assert usage.usages().isEmpty();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
323 GraphUtil.killWithUnusedFloatingInputs(usage);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
324 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
325
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
326 @Override
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
327 public void replace(ValueNode oldNode, ValueNode newNode) {
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
328 assert newNode instanceof PhiNode;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
329 assert oldNode == instanceOf;
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
330 newNode.inferStamp();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
331 instantiation.initialize((PhiNode) newNode, trueValue, falseValue);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
332 usage.replaceAtUsages(newNode);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
333 usage.clearInputs();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
334 assert usage.usages().isEmpty();
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
335 GraphUtil.killWithUnusedFloatingInputs(usage);
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
336 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
337 }
04944369f982 refactored complex snippet-based lowering mechanism for InstanceOfNodes into non-HotSpot specific project
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
338 }