annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 7271:9c06e8bd8769

added phase to remove unnecessary frame states from substitution snippets fixed debug scope used for snippet installation to capture all phases of installing a specific snippet with a filter (i.e. -G:MethodFilter) set for that snippet
author Doug Simon <doug.simon@oracle.com>
date Tue, 18 Dec 2012 17:32:44 +0100
parents c85aecfee9e4
children 2912b72d840a dc3e86fd3be1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.snippets;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.lang.reflect.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import java.util.*;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
27 import java.util.Map.Entry;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.util.concurrent.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
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: 7015
diff changeset
30 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5503
diff changeset
31 import com.oracle.graal.api.meta.*;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.debug.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.graph.*;
6523
c8763a2deb0c rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6521
diff changeset
34 import com.oracle.graal.loop.*;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.nodes.*;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
36 import com.oracle.graal.nodes.calc.*;
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
37 import com.oracle.graal.nodes.extended.*;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
38 import com.oracle.graal.nodes.java.*;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
39 import com.oracle.graal.nodes.type.*;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 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
41 import com.oracle.graal.phases.common.*;
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
42 import com.oracle.graal.snippets.Snippet.ConstantParameter;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
43 import com.oracle.graal.snippets.Snippet.Parameter;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
44 import com.oracle.graal.snippets.Snippet.Varargs;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
45 import com.oracle.graal.snippets.Snippet.VarargsParameter;
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
46 import com.oracle.graal.snippets.nodes.*;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 * A snippet template is a graph created by parsing a snippet method and then
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
50 * specialized by binding constants to the snippet's {@link ConstantParameter} parameters.
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
51 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
52 * Snippet templates can be managed in a {@link Cache}.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 */
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 public class SnippetTemplate {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
57 * A snippet template key encapsulates the method from which a snippet was built
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
58 * and the arguments used to specialize the snippet.
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
59 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
60 * @see Cache
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
62 public static class Key implements Iterable<Map.Entry<String, Object>> {
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
63 public final ResolvedJavaMethod method;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
64 private final HashMap<String, Object> map = new HashMap<>();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
65 private int hash;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
66
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
67 public Key(ResolvedJavaMethod method) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
68 this.method = method;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
69 this.hash = method.hashCode();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
70 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
71
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
72 public Key add(String name, Object value) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
73 assert !map.containsKey(name);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
74 map.put(name, value);
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
75 hash = hash ^ name.hashCode();
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
76 if (value != null) {
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
77 hash *= (value.hashCode() + 1);
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
78 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
79 return this;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
80 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
81
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
82 public int length() {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
83 return map.size();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
84 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
85
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
86 public Object get(String name) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
87 return map.get(name);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
88 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
89
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
90 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
91 public Iterator<Entry<String, Object>> iterator() {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
92 return map.entrySet().iterator();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
93 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
94
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
95 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
96 public boolean equals(Object obj) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
97 if (obj instanceof Key) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
98 Key other = (Key) obj;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
99 return other.method == method && other.map.equals(map);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
100 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
101 return false;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
102 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
103
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
104 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
105 public int hashCode() {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
106 return hash;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
107 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
108
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 @Override
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 public String toString() {
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5681
diff changeset
111 return MetaUtil.format("%h.%n", method) + map.toString();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
112 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
113
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
114 public Set<String> names() {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
115 return map.keySet();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
116 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
117 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
118
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
119 /**
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
120 * Arguments used to instantiate a template.
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
121 */
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
122 public static class Arguments implements Iterable<Map.Entry<String, Object>> {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
123 private final HashMap<String, Object> map = new HashMap<>();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
124
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
125 public static Arguments arguments(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
126 return new Arguments().add(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
127 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
128
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
129 public Arguments add(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
130 assert !map.containsKey(name);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
131 map.put(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
132 return this;
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
133 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
134
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
135 public int length() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
136 return map.size();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
137 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
138
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
139 @Override
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
140 public Iterator<Entry<String, Object>> iterator() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
141 return map.entrySet().iterator();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
142 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
143
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
144 @Override
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
145 public String toString() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
146 return map.toString();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
147 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
148 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
149
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
150 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
151 * A collection of snippet templates accessed by a {@link Key} instance.
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
152 */
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
153 public static class Cache {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
154
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
155 private final ConcurrentHashMap<SnippetTemplate.Key, SnippetTemplate> templates = new ConcurrentHashMap<>();
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
156 private final MetaAccessProvider runtime;
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: 7015
diff changeset
157 private final TargetDescription target;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
158
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
159
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: 7015
diff changeset
160 public Cache(MetaAccessProvider runtime, TargetDescription target) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
161 this.runtime = runtime;
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: 7015
diff changeset
162 this.target = target;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
163 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
164
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
165 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
166 * Gets a template for a given key, creating it first if necessary.
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
167 */
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
168 public SnippetTemplate get(final SnippetTemplate.Key key, final Assumptions assumptions) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
169 SnippetTemplate template = templates.get(key);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
170 if (template == null) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
171 template = Debug.scope("SnippetSpecialization", key.method, new Callable<SnippetTemplate>() {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
172 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
173 public SnippetTemplate call() throws Exception {
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
174 return new SnippetTemplate(runtime, assumptions, target, key);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
175 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
176 });
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
177 //System.out.println(key + " -> " + template);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
178 templates.put(key, template);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
179 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
180 return template;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
181 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
182 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
183
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
184 public abstract static class AbstractTemplates<T extends SnippetsInterface> {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
185 protected final Cache cache;
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
186 protected final MetaAccessProvider runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
187 protected final Assumptions assumptions;
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
188 protected Class<?> snippetsClass;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
189
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
190 public AbstractTemplates(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target, Class<T> snippetsClass) {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
191 this.runtime = runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
192 this.assumptions = assumptions;
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
193 if (snippetsClass == null) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
194 assert this instanceof SnippetsInterface;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
195 this.snippetsClass = getClass();
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
196 } else {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
197 this.snippetsClass = snippetsClass;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
198 }
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: 7015
diff changeset
199 this.cache = new Cache(runtime, target);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
200 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
201
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
202 protected ResolvedJavaMethod snippet(String name, Class<?>... parameterTypes) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
203 try {
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
204 ResolvedJavaMethod snippet = runtime.lookupJavaMethod(snippetsClass.getDeclaredMethod(name, parameterTypes));
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
205 assert snippet.getAnnotation(Snippet.class) != null : "snippet is not annotated with @" + Snippet.class.getSimpleName();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
206 return snippet;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
207 } catch (NoSuchMethodException e) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
208 throw new GraalInternalError(e);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
209 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
210 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
211 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
212
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
213 private static final Object UNUSED_PARAMETER = "DEAD PARAMETER";
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
216 * Determines if any parameter of a given method is annotated with {@link ConstantParameter}.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
217 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
218 public static boolean hasConstantParameter(ResolvedJavaMethod method) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
219 for (ConstantParameter p : MetaUtil.getParameterAnnotations(ConstantParameter.class, method)) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
220 if (p != null) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
221 return true;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
222 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
223 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
224 return false;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
225 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
226
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
227 /**
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
228 * Creates a snippet template.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
229 */
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
230 public SnippetTemplate(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target, SnippetTemplate.Key key) {
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
231 ResolvedJavaMethod method = key.method;
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
232 assert Modifier.isStatic(method.getModifiers()) : "snippet method must be static: " + method;
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
233 Signature signature = method.getSignature();
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
234
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
235 // Copy snippet graph, replacing constant parameters with given arguments
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
236 StructuredGraph snippetGraph = (StructuredGraph) method.getCompilerStorage().get(Graph.class);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
237 StructuredGraph snippetCopy = new StructuredGraph(snippetGraph.name, snippetGraph.method());
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
238 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
239 replacements.put(snippetGraph.start(), snippetCopy.start());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
240
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
241 int parameterCount = signature.getParameterCount(false);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
242 assert checkTemplate(key, parameterCount, method, signature);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
243
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
244 Parameter[] parameterAnnotations = new Parameter[parameterCount];
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
245 VarargsParameter[] varargsParameterAnnotations = new VarargsParameter[parameterCount];
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
246 ConstantNode[] placeholders = new ConstantNode[parameterCount];
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
247 for (int i = 0; i < parameterCount; i++) {
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5681
diff changeset
248 ConstantParameter c = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, method);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
249 if (c != null) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
250 String name = c.value();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
251 Object arg = key.get(name);
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
252 Kind kind = signature.getParameterKind(i);
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
253 Constant constantArg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
254 if (arg instanceof Constant) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
255 constantArg = (Constant) arg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
256 } else {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
257 constantArg = Constant.forBoxed(kind, arg);
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
258 }
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
259 replacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(constantArg, runtime, snippetCopy));
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
260 } else {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
261 VarargsParameter vp = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, method);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
262 if (vp != null) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
263 String name = vp.value();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
264 Varargs varargs = (Varargs) key.get(name);
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
265 Object array = varargs.getArray();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
266 ConstantNode placeholder = ConstantNode.forObject(array, runtime, snippetCopy);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
267 replacements.put(snippetGraph.getLocal(i), placeholder);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
268 placeholders[i] = placeholder;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
269 varargsParameterAnnotations[i] = vp;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
270 } else {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
271 parameterAnnotations[i] = MetaUtil.getParameterAnnotation(Parameter.class, i, method);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
272 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
273 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
274 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
275 snippetCopy.addDuplicates(snippetGraph.getNodes(), replacements);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
276
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
277 Debug.dump(snippetCopy, "Before specialization");
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
278 if (!replacements.isEmpty()) {
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
279 // Do deferred intrinsification of node intrinsics
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
280 new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy);
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: 7015
diff changeset
281 new WordTypeRewriterPhase(target.wordKind).apply(snippetCopy);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
282
7099
3656236c7d27 Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7098
diff changeset
283 new CanonicalizerPhase(null, runtime, assumptions, 0).apply(snippetCopy);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
284 }
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
285
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
286 // Gather the template parameters
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
287 parameters = new HashMap<>();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
288 for (int i = 0; i < parameterCount; i++) {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
289 VarargsParameter vp = varargsParameterAnnotations[i];
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
290 if (vp != null) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
291 assert snippetCopy.getLocal(i) == null;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
292 Varargs varargs = (Varargs) key.get(vp.value());
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
293 Object array = varargs.getArray();
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
294 int length = Array.getLength(array);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
295 LocalNode[] locals = new LocalNode[length];
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
296 Stamp stamp = varargs.getArgStamp();
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
297 for (int j = 0; j < length; j++) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
298 assert (parameterCount & 0xFFFF) == parameterCount;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
299 int idx = i << 16 | j;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
300 LocalNode local = snippetCopy.unique(new LocalNode(idx, stamp));
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
301 locals[j] = local;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
302 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
303 parameters.put(vp.value(), locals);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
304
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
305 ConstantNode placeholder = placeholders[i];
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
306 assert placeholder != null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
307 for (Node usage : placeholder.usages().snapshot()) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
308 if (usage instanceof LoadIndexedNode) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
309 LoadIndexedNode loadIndexed = (LoadIndexedNode) usage;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
310 Debug.dump(snippetCopy, "Before replacing %s", loadIndexed);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
311 LoadSnippetVarargParameterNode loadSnippetParameter = snippetCopy.add(new LoadSnippetVarargParameterNode(locals, loadIndexed.index(), loadIndexed.stamp()));
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
312 snippetCopy.replaceFixedWithFixed(loadIndexed, loadSnippetParameter);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
313 Debug.dump(snippetCopy, "After replacing %s", loadIndexed);
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
314 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
315 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
316 } else {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
317 Parameter p = parameterAnnotations[i];
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
318 if (p != null) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
319 LocalNode local = snippetCopy.getLocal(i);
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
320 if (local == null) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
321 // Parameter value was eliminated
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
322 parameters.put(p.value(), UNUSED_PARAMETER);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
323 } else {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
324 parameters.put(p.value(), local);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
325 }
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
326 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
327 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
328 }
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
329
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
330 // Do any required loop explosion
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
331 boolean exploded = false;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
332 do {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
333 exploded = false;
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
334 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
335 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
336 LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
337 if (loopBegin != null) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
338 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
339 int mark = snippetCopy.getMark();
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
340 LoopTransformations.fullUnroll(loop, runtime, null);
7099
3656236c7d27 Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7098
diff changeset
341 new CanonicalizerPhase(null, runtime, assumptions, mark).apply(snippetCopy);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
342 }
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
343 FixedNode explodeLoopNext = explodeLoop.next();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
344 explodeLoop.clearSuccessors();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
345 explodeLoop.replaceAtPredecessor(explodeLoopNext);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
346 explodeLoop.replaceAtUsages(null);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
347 GraphUtil.killCFG(explodeLoop);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
348 exploded = true;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
349 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
350 } while (exploded);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
351
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
352 // Remove all frame states from inlined snippet graph. Snippets must be atomic (i.e. free
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
353 // of side-effects that prevent deoptimizing to a point before the snippet).
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: 7015
diff changeset
354 List<Node> curSideEffectNodes = new ArrayList<>();
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
355 Node curStampNode = null;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
356 for (Node node : snippetCopy.getNodes()) {
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
357 if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) {
6496
16d1411409b4 moved AMD64 specific code into com.oracle.graal.compiler.amd64
Doug Simon <doug.simon@oracle.com>
parents: 6449
diff changeset
358 assert curStampNode == null : "Currently limited to one stamp node (but this can be converted to a List if necessary)";
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
359 curStampNode = node;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
360 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
361 if (node instanceof StateSplit) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
362 StateSplit stateSplit = (StateSplit) node;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
363 FrameState frameState = stateSplit.stateAfter();
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
364 if (stateSplit.hasSideEffect()) {
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: 7015
diff changeset
365 curSideEffectNodes.add(node);
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
366 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
367 if (frameState != null) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
368 stateSplit.setStateAfter(null);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
369 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
370 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
371 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
372
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
373 new DeadCodeEliminationPhase().apply(snippetCopy);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
374
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
375 assert checkAllVarargPlaceholdersAreDeleted(parameterCount, placeholders);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
376
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
377 this.snippet = snippetCopy;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
378 ReturnNode retNode = null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
379 StartNode entryPointNode = snippet.start();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
380
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
381 new DeadCodeEliminationPhase().apply(snippetCopy);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
382
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
383 nodes = new ArrayList<>(snippet.getNodeCount());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
384 for (Node node : snippet.getNodes()) {
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
385 if (node == entryPointNode || node == entryPointNode.stateAfter()) {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
386 // Do nothing.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
387 } else {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
388 nodes.add(node);
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
389 if (node instanceof ReturnNode) {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
390 retNode = (ReturnNode) node;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
391 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
392 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
393 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
394
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: 7015
diff changeset
395 this.sideEffectNodes = curSideEffectNodes;
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
396 this.stampNode = curStampNode;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
397 this.returnNode = retNode;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
398 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
399
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
400 private static boolean checkAllVarargPlaceholdersAreDeleted(int parameterCount, ConstantNode[] placeholders) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
401 for (int i = 0; i < parameterCount; i++) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
402 if (placeholders[i] != null) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
403 assert placeholders[i].isDeleted() : placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
404 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
405 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
406 return true;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
407 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
408
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5540
diff changeset
409 private static boolean checkConstantArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) {
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
410 ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass());
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
411 if (WordTypeRewriterPhase.isWord(type)) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
412 assert arg instanceof Constant : method + ": word constant parameters must be passed boxed in a Constant value: " + arg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
413 return true;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
414 }
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7081
diff changeset
415 if (kind == Kind.Object) {
7015
62818f156081 added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
416 assert arg == null || type.isInstance(Constant.forObject(arg)) :
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
417 method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
418 } else {
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
419 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() :
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
420 method + ": wrong value kind for " + name + ": expected " + kind + ", got " + (arg == null ? "null" : arg.getClass().getSimpleName());
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
421 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
422 return true;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
423 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
424
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
425 private static boolean checkVarargs(final ResolvedJavaMethod method, Signature signature, int i, String name, Varargs varargs) {
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6653
diff changeset
426 Object arg = varargs.getArray();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
427 ResolvedJavaType type = (ResolvedJavaType) signature.getParameterType(i, method.getDeclaringClass());
7060
06d5f450f32b rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents: 7034
diff changeset
428 assert type.isArray() : "varargs parameter must be an array type";
7015
62818f156081 added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
429 assert type.isInstance(Constant.forObject(arg)) : "value for " + name + " is not a " + MetaUtil.toJavaName(type) + " instance: " + arg;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
430 return true;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
431 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
432
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
433 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
434 * The graph built from the snippet method.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
435 */
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
436 private final StructuredGraph snippet;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
437
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
438 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
439 * The named parameters of this template that must be bound to values during instantiation.
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
440 * For a parameter that is still live after specialization, the value in this map is either
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
441 * a {@link LocalNode} instance or a {@link LocalNode} array. For an eliminated parameter,
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
442 * the value is identical to the key.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
443 */
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
444 private final Map<String, Object> parameters;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
445
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
446 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
447 * The return node (if any) of the snippet.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
448 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
449 private final ReturnNode returnNode;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
450
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
451 /**
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: 7015
diff changeset
452 * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during instantiation.
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
453 */
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: 7015
diff changeset
454 private final List<Node> sideEffectNodes;
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
455
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
456 /**
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
457 * Node that inherits the {@link ValueNode#stamp()} from the replacee during instantiation.
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
458 */
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
459 private final Node stampNode;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
460
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
461 /**
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
462 * The nodes to be inlined when this specialization is instantiated.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
463 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
464 private final ArrayList<Node> nodes;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
465
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
466 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
467 * Gets the instantiation-time bindings to this template's parameters.
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
468 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
469 * @return the map that will be used to bind arguments to parameters when inlining this template
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
470 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
471 private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider runtime, SnippetTemplate.Arguments args) {
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
472 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
6449
de9c0c4b7c9b added sanity assertion to snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 6431
diff changeset
473 assert args.length() == parameters.size() : "number of args (" + args.length() + ") != number of parameters (" + parameters.size() + ")";
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
474 for (Map.Entry<String, Object> e : args) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
475 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
476 Object parameter = parameters.get(name);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
477 assert parameter != null : this + " has no parameter named " + name;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
478 Object argument = e.getValue();
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
479 if (parameter instanceof LocalNode) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
480 if (argument instanceof ValueNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
481 replacements.put((LocalNode) parameter, (ValueNode) argument);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
482 } else {
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
483 Kind kind = ((LocalNode) parameter).kind();
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7081
diff changeset
484 assert argument != null || kind == Kind.Object : this + " cannot accept null for non-object parameter named " + name;
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5531
diff changeset
485 Constant constant = Constant.forBoxed(kind, argument);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
486 replacements.put((LocalNode) parameter, ConstantNode.forConstant(constant, runtime, replaceeGraph));
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
487 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
488 } else if (parameter instanceof LocalNode[]) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
489 LocalNode[] locals = (LocalNode[]) parameter;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
490 Object array = argument;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
491 assert array != null && array.getClass().isArray();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
492 int length = locals.length;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
493 assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
494 for (int j = 0; j < length; j++) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
495 LocalNode local = locals[j];
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
496 assert local != null;
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
497 Object value = Array.get(array, j);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
498 if (value instanceof ValueNode) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
499 replacements.put(local, (ValueNode) value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
500 } else {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
501 Constant constant = Constant.forBoxed(local.kind(), value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
502 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
503 replacements.put(local, element);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
504 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
505 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
506 } else {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
507 assert parameter == UNUSED_PARAMETER : "unexpected entry for parameter: " + name + " -> " + parameter;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
508 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
509 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
510 return replacements;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
511 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
512
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
513 /**
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
514 * Logic for replacing a snippet-lowered node at its usages with the return value
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
515 * of the snippet. An alternative to the
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
516 * {@linkplain SnippetTemplate#DEFAULT_REPLACER default} replacement logic can be used to
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
517 * handle mismatches between the stamp of the node being lowered and the
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
518 * stamp of the snippet's return value.
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
519 */
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
520 public interface UsageReplacer {
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
521 /**
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
522 * Replaces all usages of {@code oldNode} with direct or indirect usages of {@code newNode}.
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
523 */
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
524 void replace(ValueNode oldNode, ValueNode newNode);
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
525 }
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
526
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
527 /**
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
528 * Represents the default {@link UsageReplacer usage replacer} logic which
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
529 * simply delegates to {@link Node#replaceAtUsages(Node)}.
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
530 */
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
531 public static final UsageReplacer DEFAULT_REPLACER = new UsageReplacer() {
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
532 @Override
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
533 public void replace(ValueNode oldNode, ValueNode newNode) {
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
534 oldNode.replaceAtUsages(newNode);
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
535 }
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
536 };
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
537
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
538 /**
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
539 * Replaces a given fixed node with this specialized snippet.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
540 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
541 * @param runtime
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
542 * @param replacee the node that will be replaced
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
543 * @param replacer object that replaces the usages of {@code replacee}
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
544 * @param args the arguments to be bound to the flattened positional parameters of the snippet
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6302
diff changeset
545 * @return the map of duplicated nodes (original -> duplicate)
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
546 */
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
547 public Map<Node, Node> instantiate(MetaAccessProvider runtime,
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
548 FixedWithNextNode replacee,
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
549 UsageReplacer replacer,
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
550 SnippetTemplate.Arguments args) {
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
551
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
552 // Inline the snippet nodes, replacing parameters with the given args in the process
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
553 String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}";
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
554 StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
555 StartNode entryPointNode = snippet.start();
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
556 FixedNode firstCFGNode = entryPointNode.next();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
557 StructuredGraph replaceeGraph = (StructuredGraph) replacee.graph();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
558 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, runtime, args);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
559 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, replacements);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
560 Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
561
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
562 // Re-wire the control flow graph around the replacee
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
563 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
564 replacee.replaceAtPredecessor(firstCFGNodeDuplicate);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
565 FixedNode next = replacee.next();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
566 replacee.setNext(null);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
567
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: 7015
diff changeset
568 if (replacee instanceof StateSplit) {
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: 7015
diff changeset
569 for (Node sideEffectNode : sideEffectNodes) {
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: 7015
diff changeset
570 assert ((StateSplit) replacee).hasSideEffect();
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: 7015
diff changeset
571 Node sideEffectDup = duplicates.get(sideEffectNode);
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: 7015
diff changeset
572 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
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: 7015
diff changeset
573 }
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
574 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
575 if (stampNode != null) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
576 Node stampDup = duplicates.get(stampNode);
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
577 ((ValueNode) stampDup).setStamp(((ValueNode) replacee).stamp());
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
578 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
579
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
580 // Replace all usages of the replacee with the value returned by the snippet
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
581 ValueNode returnValue = null;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
582 if (returnNode != null) {
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
583 if (returnNode.result() instanceof LocalNode) {
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
584 returnValue = (ValueNode) replacements.get(returnNode.result());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
585 } else {
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
586 returnValue = (ValueNode) duplicates.get(returnNode.result());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
587 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
588 assert returnValue != null || replacee.usages().isEmpty();
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
589 replacer.replace(replacee, returnValue);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
590
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
591 Node returnDuplicate = duplicates.get(returnNode);
6653
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
592 if (returnDuplicate.isAlive()) {
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
593 returnDuplicate.clearInputs();
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
594 returnDuplicate.replaceAndDelete(next);
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
595 }
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
596 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
597
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
598 // Remove the replacee from its graph
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
599 replacee.clearInputs();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
600 replacee.replaceAtUsages(null);
6588
b89b5038ad7e removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents: 6574
diff changeset
601 GraphUtil.killCFG(replacee);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
602
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
603 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6302
diff changeset
604 return duplicates;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
605 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
606
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
607 /**
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
608 * Gets a copy of the specialized graph.
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
609 */
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
610 public StructuredGraph copySpecializedGraph() {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
611 return snippet.copy();
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
612 }
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
613
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
614 /**
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
615 * Replaces a given floating node with this specialized snippet.
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
616 *
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
617 * @param runtime
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
618 * @param replacee the node that will be replaced
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
619 * @param replacer object that replaces the usages of {@code replacee}
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
620 * @param lastFixedNode the CFG of the snippet is inserted after this node
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
621 * @param args the arguments to be bound to the flattened positional parameters of the snippet
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
622 */
6534
feb579677b58 SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
623 public void instantiate(MetaAccessProvider runtime,
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
624 FloatingNode replacee,
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
625 UsageReplacer replacer,
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
626 FixedWithNextNode lastFixedNode, SnippetTemplate.Arguments args) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
627
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
628 // Inline the snippet nodes, replacing parameters with the given args in the process
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
629 String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}";
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
630 StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
631 StartNode entryPointNode = snippet.start();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
632 FixedNode firstCFGNode = entryPointNode.next();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
633 StructuredGraph replaceeGraph = (StructuredGraph) replacee.graph();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
634 IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, runtime, args);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
635 Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, replacements);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
636 Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
637
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
638 assert lastFixedNode != null : replaceeGraph;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
639 FixedNode next = lastFixedNode.next();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
640 lastFixedNode.setNext(null);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
641 FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
642 replaceeGraph.addAfterFixed(lastFixedNode, firstCFGNodeDuplicate);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
643
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: 7015
diff changeset
644 if (replacee instanceof StateSplit) {
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: 7015
diff changeset
645 for (Node sideEffectNode : sideEffectNodes) {
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: 7015
diff changeset
646 assert ((StateSplit) replacee).hasSideEffect();
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: 7015
diff changeset
647 Node sideEffectDup = duplicates.get(sideEffectNode);
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: 7015
diff changeset
648 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
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: 7015
diff changeset
649 }
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
650 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
651 if (stampNode != null) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
652 Node stampDup = duplicates.get(stampNode);
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
653 ((ValueNode) stampDup).setStamp(((ValueNode) replacee).stamp());
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
654 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
655
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
656 // Replace all usages of the replacee with the value returned by the snippet
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
657 assert returnNode != null : replaceeGraph;
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
658 ValueNode returnValue = null;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
659 if (returnNode.result() instanceof LocalNode) {
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
660 returnValue = (ValueNode) replacements.get(returnNode.result());
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
661 } else {
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
662 returnValue = (ValueNode) duplicates.get(returnNode.result());
5670
29684ae5a194 Make sure snippet instentiation doesn't produce dead nodes and remove redundant DCE
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5574
diff changeset
663 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
664 assert returnValue != null || replacee.usages().isEmpty();
6568
d8408e5563e5 added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
665 replacer.replace(replacee, returnValue);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
666
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
667 Node returnDuplicate = duplicates.get(returnNode);
6653
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
668 if (returnDuplicate.isAlive()) {
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
669 returnDuplicate.clearInputs();
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
670 returnDuplicate.replaceAndDelete(next);
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
671 }
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
672
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
673 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
674 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
675
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
676 @Override
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
677 public String toString() {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
678 StringBuilder buf = new StringBuilder(snippet.toString()).append('(');
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
679 String sep = "";
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
680 for (Map.Entry<String, Object> e : parameters.entrySet()) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
681 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
682 Object value = e.getValue();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
683 buf.append(sep);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
684 sep = ", ";
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
685 if (value == UNUSED_PARAMETER) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
686 buf.append("<unused> ").append(name);
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
687 } else if (value instanceof LocalNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
688 LocalNode local = (LocalNode) value;
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
689 buf.append(local.kind().getJavaName()).append(' ').append(name);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
690 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
691 LocalNode[] locals = (LocalNode[]) value;
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
692 String kind = locals.length == 0 ? "?" : locals[0].kind().getJavaName();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
693 buf.append(kind).append('[').append(locals.length).append("] ").append(name);
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
694 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
695 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
696 return buf.append(')').toString();
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
697 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
698
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
699 private static boolean checkTemplate(SnippetTemplate.Key key, int parameterCount, ResolvedJavaMethod method, Signature signature) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
700 Set<String> expected = new HashSet<>();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
701 for (int i = 0; i < parameterCount; i++) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
702 ConstantParameter c = MetaUtil.getParameterAnnotation(ConstantParameter.class, i, method);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
703 VarargsParameter vp = MetaUtil.getParameterAnnotation(VarargsParameter.class, i, method);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
704 Parameter p = MetaUtil.getParameterAnnotation(Parameter.class, i, method);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
705 if (c != null) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
706 assert vp == null && p == null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
707 String name = c.value();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
708 expected.add(name);
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6534
diff changeset
709 Kind kind = signature.getParameterKind(i);
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
710 assert key.names().contains(name) : "key for " + method + " is missing \"" + name + "\": " + key;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
711 assert checkConstantArgument(method, signature, i, c.value(), key.get(name), kind);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
712 } else if (vp != null) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
713 assert p == null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
714 String name = vp.value();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
715 expected.add(name);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
716 assert key.names().contains(name) : "key for " + method + " is missing \"" + name + "\": " + key;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
717 assert key.get(name) instanceof Varargs;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
718 Varargs varargs = (Varargs) key.get(name);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
719 assert checkVarargs(method, signature, i, name, varargs);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
720 } else {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
721 assert p != null : method + ": parameter " + i + " must be annotated with exactly one of " +
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
722 "@" + ConstantParameter.class.getSimpleName() + " or " +
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
723 "@" + VarargsParameter.class.getSimpleName() + " or " +
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
724 "@" + Parameter.class.getSimpleName();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
725 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
726 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
727 if (!key.names().containsAll(expected)) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
728 expected.removeAll(key.names());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
729 assert false : expected + " missing from key " + key;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
730 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
731 if (!expected.containsAll(key.names())) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
732 Set<String> namesCopy = new HashSet<>(key.names());
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
733 namesCopy.removeAll(expected);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
734 assert false : "parameter(s) " + namesCopy + " should be annotated with @" + ConstantParameter.class.getSimpleName() +
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
735 " or @" + VarargsParameter.class.getSimpleName() + " in " + MetaUtil.format("%H.%n(%p)", method);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
736 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
737 return true;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
738 }
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
739 }