annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 7313:570d8e4c6dfb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 07 Jan 2013 13:04:04 +0100
parents dc3e86fd3be1 2912b72d840a
children 5e3d1a68664e
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.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
47 import com.oracle.graal.word.*;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
48 import com.oracle.graal.word.phases.*;
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
49
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
50 /**
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
51 * 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
52 * 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
53 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
54 * 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
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 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
57
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
58 /**
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 * 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
60 * 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
61 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
62 * @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
63 */
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 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
65 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
66 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
67 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
68
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
69 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
70 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
71 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
72 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
73
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
74 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
75 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
76 map.put(name, value);
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
77 hash = hash ^ name.hashCode();
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
78 if (value != null) {
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
79 hash *= (value.hashCode() + 1);
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
80 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
81 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
82 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
83
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
84 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
85 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
86 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
87
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
88 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
89 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
90 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
91
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
92 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
93 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
94 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
95 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
96
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
97 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
98 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
99 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
100 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
101 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
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 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
104 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
105
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
106 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
107 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
108 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
109 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
110
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
111 @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
112 public String toString() {
5719
429accae15aa moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents: 5681
diff changeset
113 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
114 }
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
115
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 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
117 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
118 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
119 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
120
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
121 /**
5484
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
122 * Arguments used to instantiate a template.
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
123 */
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
124 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
125 private final HashMap<String, Object> map = new HashMap<>();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
126
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
127 public static Arguments arguments(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
128 return new Arguments().add(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
129 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
130
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
131 public Arguments add(String name, Object value) {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
132 assert !map.containsKey(name);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
133 map.put(name, value);
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
134 return this;
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
135 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
136
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
137 public int length() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
138 return map.size();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
139 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
140
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
141 @Override
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
142 public Iterator<Entry<String, Object>> iterator() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
143 return map.entrySet().iterator();
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
144 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
145
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
146 @Override
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
147 public String toString() {
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
148 return map.toString();
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 }
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
151
f70b1547c7bf small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents: 5482
diff changeset
152 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
153 * 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
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 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
156
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
157 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
158 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
159 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
160
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
161
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 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
163 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
164 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
165 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
166
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
167 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
168 * 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
169 */
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
170 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
171 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
172 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
173 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
174 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
175 public SnippetTemplate call() throws Exception {
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
176 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
177 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
178 });
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
179 //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
180 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
181 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
182 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
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 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
185
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
186 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
187 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
188 protected final MetaAccessProvider runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
189 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
190 protected Class<?> snippetsClass;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
191
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
192 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
193 this.runtime = runtime;
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
194 this.assumptions = assumptions;
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
195 if (snippetsClass == null) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
196 assert this instanceof SnippetsInterface;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
197 this.snippetsClass = getClass();
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
198 } else {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
199 this.snippetsClass = snippetsClass;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
200 }
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
201 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
202 }
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
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
204 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
205 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
206 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
207 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
208 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
209 } 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
210 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
211 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
212 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
213 }
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
214
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
215 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
216
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
217 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
218 * 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
219 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
220 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
221 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
222 if (p != null) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
223 return true;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
224 }
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 return false;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
227 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
228
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
229 /**
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
230 * 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
231 */
7075
Christian Haeubl <haeubl@ssw.jku.at>
parents: 7070 7034
diff changeset
232 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
233 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
234 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
235 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
236
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
237 // 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
238 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
239 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
240 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
241 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
242
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
243 int parameterCount = signature.getParameterCount(false);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
244 assert checkTemplate(runtime, key, parameterCount, method, signature);
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
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
246 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
247 VarargsParameter[] varargsParameterAnnotations = new VarargsParameter[parameterCount];
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 Constant constantArg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
256 if (arg instanceof Constant) {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
257 constantArg = (Constant) arg;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
258 } else {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
259 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
260 }
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
261 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
262 } 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
263 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
264 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
265 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
266 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
267 Object array = varargs.getArray();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
268 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
269 replacements.put(snippetGraph.getLocal(i), placeholder);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
270 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
271 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
272 } 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
273 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
274 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
275 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
276 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
277 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
278
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
279 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
280 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
281 // 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
282 new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
283 new WordTypeRewriterPhase(runtime, 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
284
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7271
diff changeset
285 new CanonicalizerPhase(null, runtime, assumptions, 0, null).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
286 }
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
287
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
288 // 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
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 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
306
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 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 }
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
317 }
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 } 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
319 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
320 if (p != null) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
321 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
322 if (local == null) {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
323 // 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
324 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
325 } else {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
326 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
327 }
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
328 }
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 }
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
331
5481
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 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
333 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
334 do {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
335 exploded = false;
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
336 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
337 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
338 LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
339 if (loopBegin != null) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
340 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
341 int mark = snippetCopy.getMark();
7064
8d16b9b2c51e first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6653
diff changeset
342 LoopTransformations.fullUnroll(loop, runtime, null);
7307
dc3e86fd3be1 Introduce cutomization capability for canonicalizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7271
diff changeset
343 new CanonicalizerPhase(null, runtime, assumptions, mark, null).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
344 }
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
345 FixedNode explodeLoopNext = explodeLoop.next();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
346 explodeLoop.clearSuccessors();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
347 explodeLoop.replaceAtPredecessor(explodeLoopNext);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
348 explodeLoop.replaceAtUsages(null);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
349 GraphUtil.killCFG(explodeLoop);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
350 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
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 } 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
353
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
354 // 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
355 // 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
356 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
357 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
358 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
359 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
360 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
361 curStampNode = node;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
362 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
363 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
364 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
365 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
366 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
367 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
368 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
369 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
370 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
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 }
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
373 }
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
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
375 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
376
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
377 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
378
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 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
380 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
381 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
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 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
384
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
385 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
386 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
387 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
388 // 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
389 } 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
390 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
391 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
392 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
393 }
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
394 }
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
395 }
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
396
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
397 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
398 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
399 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
400 }
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
401
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
402 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
403 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
404 if (placeholders[i] != null) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
405 assert placeholders[i].isDeleted() : placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
406 }
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 return true;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
409 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
410
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
411 private static boolean checkConstantArgument(MetaAccessProvider runtime, 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
412 ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
413 if (runtime.lookupJavaType(WordBase.class).isAssignableFrom(type)) {
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
414 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
415 return true;
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
416 }
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7081
diff changeset
417 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
418 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
419 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
420 } else {
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
421 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() :
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
422 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
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 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
425 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
426
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
427 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
428 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
429 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
430 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
431 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
432 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
433 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
434
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
435 /**
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
436 * 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
437 */
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
438 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
439
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
440 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
441 * 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
442 * 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
443 * 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
444 * 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
445 */
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
446 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
447
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 /**
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
449 * 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
450 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
451 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
452
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
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 * 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
455 */
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
456 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
457
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 * 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
460 */
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
461 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
462
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
463 /**
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
464 * 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
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 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
467
5481
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 * 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
470 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
471 * @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
472 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
473 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
474 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
6449
de9c0c4b7c9b added sanity assertion to snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents: 6431
diff changeset
475 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
476 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
477 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
478 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
479 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
480 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
481 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
482 if (argument instanceof ValueNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
483 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
484 } else {
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
485 Kind kind = ((LocalNode) parameter).kind();
7098
e23980f4a890 Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7081
diff changeset
486 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
487 Constant constant = Constant.forBoxed(kind, argument);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
488 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
489 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
490 } else if (parameter instanceof LocalNode[]) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
491 LocalNode[] locals = (LocalNode[]) parameter;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
492 int length = locals.length;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
493 List list = null;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
494 Object array = null;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
495 if (argument instanceof List) {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
496 list = (List) argument;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
497 assert list.size() == length : length + " != " + list.size();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
498 } else {
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
499 array = argument;
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
500 assert array != null && array.getClass().isArray();
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
501 assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
502 }
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
503
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
504 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
505 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
506 assert local != null;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
507 Object value = list != null ? list.get(j) : Array.get(array, j);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
508 if (value instanceof ValueNode) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
509 replacements.put(local, (ValueNode) value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
510 } else {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
511 Constant constant = Constant.forBoxed(local.kind(), value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
512 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
513 replacements.put(local, element);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
514 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
515 }
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
516 } else {
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
517 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
518 }
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
519 }
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
520 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
521 }
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
522
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
523 /**
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
524 * 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
525 * 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
526 * {@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
527 * 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
528 * 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
529 */
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 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
531 /**
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 * 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
533 */
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 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
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 * 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
539 * 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
540 */
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
541 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
542 @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
543 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
544 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
545 }
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
546 };
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
547
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 /**
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
549 * 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
550 *
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 * @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
552 * @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
553 * @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
554 * @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
555 * @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
556 */
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
557 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
558 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
559 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
560 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
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 // 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
563 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
564 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
565 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
566 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
567 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
568 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
569 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
570 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
571
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
572 // 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
573 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
574 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
575 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
576 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
577
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
578 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
579 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
580 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
581 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
582 ((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
583 }
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
584 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
585 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
586 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
587 ((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
588 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
589
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 // 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
591 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
592 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
593 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
594 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
595 } 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
596 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
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 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
599 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
600
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
601 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
602 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
603 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
604 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
605 }
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
606 }
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
607
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
608 // 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
609 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
610 replacee.replaceAtUsages(null);
6588
b89b5038ad7e removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents: 6574
diff changeset
611 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
612
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
613 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
614 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
615 }
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 /**
7141
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
618 * 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
619 */
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
620 public StructuredGraph copySpecializedGraph() {
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
621 return snippet.copy();
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
622 }
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
623
c85aecfee9e4 made snippet template specialization support ConstantParameters of type Word
Doug Simon <doug.simon@oracle.com>
parents: 7099
diff changeset
624 /**
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
625 * 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
626 *
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 * @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
628 * @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
629 * @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
630 * @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
631 * @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
632 */
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
633 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
634 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
635 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
636 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
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 // 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
639 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
640 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
641 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
642 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
643 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
644 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
645 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
646 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
647
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
648 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
649 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
650 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
651 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
652 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
653
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
654 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
655 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
656 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
657 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
658 ((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
659 }
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
660 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
661 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
662 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
663 ((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
664 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
665
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 // 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
667 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
668 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
669 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
670 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
671 } 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
672 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
673 }
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
674 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
675 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
676
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
677 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
678 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
679 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
680 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
681 }
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
682
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
683 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
684 }
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
685
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
686 @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
687 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
688 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
689 String sep = "";
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
690 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
691 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
692 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
693 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
694 sep = ", ";
7271
9c06e8bd8769 added phase to remove unnecessary frame states from substitution snippets
Doug Simon <doug.simon@oracle.com>
parents: 7141
diff changeset
695 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
696 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
697 } else if (value instanceof LocalNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
698 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
699 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
700 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
701 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
702 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
703 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
704 }
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
705 }
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
706 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
707 }
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
708
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
709 private static boolean checkTemplate(MetaAccessProvider runtime, SnippetTemplate.Key key, int parameterCount, ResolvedJavaMethod method, Signature signature) {
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 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
711 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
712 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
713 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
714 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
715 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
716 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
717 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
718 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
719 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
720 assert key.names().contains(name) : "key for " + method + " is missing \"" + name + "\": " + key;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7271
diff changeset
721 assert checkConstantArgument(runtime, method, signature, i, c.value(), key.get(name), kind);
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
722 } 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
723 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
724 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
725 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
726 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
727 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
728 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
729 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
730 } 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
731 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
732 "@" + 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
733 "@" + 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
734 "@" + 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
735 }
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 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
738 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
739 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
740 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
741 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
742 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
743 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
744 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
745 " 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
746 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
747 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
748 }
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
749 }