Mercurial > hg > truffle
annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 7099:3656236c7d27
Cleanup of Kind class: remove use of Unsafe class
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 29 Nov 2012 12:17:02 -0800 |
parents | e23980f4a890 |
children | c85aecfee9e4 |
rev | line source |
---|---|
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.snippets; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.lang.reflect.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import java.util.*; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
27 import java.util.Map.Entry; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import java.util.concurrent.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5503
diff
changeset
|
31 import com.oracle.graal.api.meta.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.debug.*; |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.graph.*; |
6523
c8763a2deb0c
rename packages in graal.loop to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6521
diff
changeset
|
34 import com.oracle.graal.loop.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.nodes.*; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
36 import com.oracle.graal.nodes.calc.*; |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
37 import com.oracle.graal.nodes.extended.*; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
38 import com.oracle.graal.nodes.java.*; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
39 import com.oracle.graal.nodes.type.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 import com.oracle.graal.nodes.util.*; |
6526
ee651c726397
split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents:
6525
diff
changeset
|
41 import com.oracle.graal.phases.common.*; |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
42 import com.oracle.graal.snippets.Snippet.ConstantParameter; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
43 import com.oracle.graal.snippets.Snippet.Parameter; |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
44 import com.oracle.graal.snippets.Snippet.Varargs; |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
45 import com.oracle.graal.snippets.Snippet.VarargsParameter; |
5466
af07e798947d
lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5428
diff
changeset
|
46 import com.oracle.graal.snippets.nodes.*; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 /** |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 * A snippet template is a graph created by parsing a snippet method and then |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5531
diff
changeset
|
50 * specialized by binding constants to the snippet's {@link ConstantParameter} parameters. |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
51 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
52 * Snippet templates can be managed in a {@link Cache}. |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 */ |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 public class SnippetTemplate { |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
57 * A snippet template key encapsulates the method from which a snippet was built |
6568
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
58 * and the arguments used to specialize the snippet. |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
59 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
60 * @see Cache |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
62 public static class Key implements Iterable<Map.Entry<String, Object>> { |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
63 public final ResolvedJavaMethod method; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
64 private final HashMap<String, Object> map = new HashMap<>(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
65 private int hash; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
66 |
5541
b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5540
diff
changeset
|
67 public Key(ResolvedJavaMethod method) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
68 this.method = method; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
69 this.hash = method.hashCode(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
70 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
71 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
72 public Key add(String name, Object value) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
73 assert !map.containsKey(name); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
74 map.put(name, value); |
5574
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
75 hash = hash ^ name.hashCode(); |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
76 if (value != null) { |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
77 hash *= (value.hashCode() + 1); |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
78 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
79 return this; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
80 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
81 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
82 public int length() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
83 return map.size(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
84 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
85 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
86 public Object get(String name) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
87 return map.get(name); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
88 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
89 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
90 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
91 public Iterator<Entry<String, Object>> iterator() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
92 return map.entrySet().iterator(); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
93 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
94 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
95 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
96 public boolean equals(Object obj) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
97 if (obj instanceof Key) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
98 Key other = (Key) obj; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
99 return other.method == method && other.map.equals(map); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
100 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
101 return false; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
102 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
103 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
104 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
105 public int hashCode() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
106 return hash; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
107 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
108 |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 @Override |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 public String toString() { |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5681
diff
changeset
|
111 return MetaUtil.format("%h.%n", method) + map.toString(); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
112 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
113 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
114 public Set<String> names() { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
115 return map.keySet(); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
116 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
117 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
118 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
119 /** |
5484
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
120 * Arguments used to instantiate a template. |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
121 */ |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
122 public static class Arguments implements Iterable<Map.Entry<String, Object>> { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
123 private final HashMap<String, Object> map = new HashMap<>(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
124 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
125 public static Arguments arguments(String name, Object value) { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
126 return new Arguments().add(name, value); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
127 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
128 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
129 public Arguments add(String name, Object value) { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
130 assert !map.containsKey(name); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
131 map.put(name, value); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
132 return this; |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
133 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
134 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
135 public int length() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
136 return map.size(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
137 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
138 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
139 @Override |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
140 public Iterator<Entry<String, Object>> iterator() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
141 return map.entrySet().iterator(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
142 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
143 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
144 @Override |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
145 public String toString() { |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
146 return map.toString(); |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
147 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
148 } |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
149 |
f70b1547c7bf
small refactoring of snippet API
Doug Simon <doug.simon@oracle.com>
parents:
5482
diff
changeset
|
150 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
151 * A collection of snippet templates accessed by a {@link Key} instance. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
152 */ |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
153 public static class Cache { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
154 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
155 private final ConcurrentHashMap<SnippetTemplate.Key, SnippetTemplate> templates = new ConcurrentHashMap<>(); |
6534
feb579677b58
SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6526
diff
changeset
|
156 private final MetaAccessProvider runtime; |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
157 private final TargetDescription target; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
158 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
159 |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
160 public Cache(MetaAccessProvider runtime, TargetDescription target) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
161 this.runtime = runtime; |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
162 this.target = target; |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
164 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
165 /** |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
166 * Gets a template for a given key, creating it first if necessary. |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
167 */ |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
168 public SnippetTemplate get(final SnippetTemplate.Key key, final Assumptions assumptions) { |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
169 SnippetTemplate template = templates.get(key); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
170 if (template == null) { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
171 template = Debug.scope("SnippetSpecialization", key.method, new Callable<SnippetTemplate>() { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
172 @Override |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
173 public SnippetTemplate call() throws Exception { |
7075 | 174 return new SnippetTemplate(runtime, assumptions, target, key); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
175 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
176 }); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
177 //System.out.println(key + " -> " + template); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
178 templates.put(key, template); |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
179 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
180 return template; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
181 } |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
182 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
183 |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
184 public abstract static class AbstractTemplates<T extends SnippetsInterface> { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
185 protected final Cache cache; |
6534
feb579677b58
SnippetTemplate must not depend on CodeCacheProvider (only on MetaAccessProvider). This means that the hasSideEffect flag of a RuntimeCall must be already fixed in the RuntimeCall.Descriptor to avoid a lookup of the actual RuntimeCall using the CodeCacheProvider.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6526
diff
changeset
|
186 protected final MetaAccessProvider runtime; |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
187 protected final Assumptions assumptions; |
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
|
188 protected Class<T> snippetsClass; |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
189 |
7075 | 190 public AbstractTemplates(MetaAccessProvider runtime, Assumptions assumptions, TargetDescription target, Class<T> snippetsClass) { |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
191 this.runtime = runtime; |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
192 this.assumptions = assumptions; |
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.snippetsClass = snippetsClass; |
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
|
194 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
|
195 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
196 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 } 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
|
203 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
|
204 } |
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 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
206 } |
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
|
207 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
208 /** |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
209 * 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
|
210 */ |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
211 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
|
212 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
|
213 if (p != null) { |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
214 return true; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
215 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
216 } |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
217 return false; |
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
218 } |
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 /** |
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
|
221 * 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
|
222 */ |
7075 | 223 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
|
224 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
|
225 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
|
226 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
|
227 |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
228 // 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
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 int parameterCount = signature.getParameterCount(false); |
6302
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
235 assert checkTemplate(key, parameterCount, method, signature); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
236 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
237 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
|
238 VarargsParameter[] varargsParameterAnnotations = new VarargsParameter[parameterCount]; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 Kind kind = signature.getParameterKind(i); |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5547
diff
changeset
|
246 replacements.put(snippetGraph.getLocal(i), ConstantNode.forConstant(Constant.forBoxed(kind, arg), 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
|
247 } 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 Object array = varargs.getArray(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
253 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
|
254 replacements.put(snippetGraph.getLocal(i), placeholder); |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
255 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
|
256 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
|
257 } 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
|
258 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
|
259 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
260 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
261 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
262 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
|
263 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
264 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
|
265 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
|
266 // 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
|
267 new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy); |
7034
89df4e71940a
More flexible handling of stamp for word type: Define a singleton Stamp instance for words that is then re-written to the target-specific primitive word stamp by the WordTypeRewriterPhase. This allows nodes to have a word stamp without any dependency on global or static state.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7015
diff
changeset
|
268 new WordTypeRewriterPhase(target.wordKind).apply(snippetCopy); |
5760
87e8baf5447c
added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
269 |
7099
3656236c7d27
Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
270 new CanonicalizerPhase(null, runtime, assumptions, 0).apply(snippetCopy); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
271 } |
5466
af07e798947d
lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5428
diff
changeset
|
272 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
273 // 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
290 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
|
291 |
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 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 } |
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
|
302 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
303 } 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
|
304 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
|
305 if (p != null) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
306 LocalNode local = snippetCopy.getLocal(i); |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
307 assert local != null; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
308 parameters.put(p.value(), local); |
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
|
309 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
310 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
311 } |
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
|
312 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
313 // 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
|
314 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
|
315 do { |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
316 exploded = false; |
5490 | 317 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first(); |
318 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether | |
319 LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); | |
320 if (loopBegin != null) { | |
321 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); | |
322 int mark = snippetCopy.getMark(); | |
7064
8d16b9b2c51e
first part of refactoring the InliningPhase
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6653
diff
changeset
|
323 LoopTransformations.fullUnroll(loop, runtime, null); |
7099
3656236c7d27
Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7098
diff
changeset
|
324 new CanonicalizerPhase(null, runtime, assumptions, mark).apply(snippetCopy); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
325 } |
5490 | 326 FixedNode explodeLoopNext = explodeLoop.next(); |
327 explodeLoop.clearSuccessors(); | |
328 explodeLoop.replaceAtPredecessor(explodeLoopNext); | |
329 explodeLoop.replaceAtUsages(null); | |
330 GraphUtil.killCFG(explodeLoop); | |
331 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
|
332 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
333 } 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
|
334 |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
335 // 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
|
336 // 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 curStampNode = node; |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
343 } |
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 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
350 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
|
351 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
|
352 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
353 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
354 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
355 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
356 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
|
357 |
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
|
358 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
|
359 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
364 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
|
365 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 // 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
|
370 } 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
|
371 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
|
372 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
|
373 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
|
374 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
375 } |
6ec0857cdf46
added support for snippet templates which are snippet 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 |
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
|
378 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
|
379 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
|
380 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
|
381 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
382 |
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
|
383 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
|
384 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
|
385 if (placeholders[i] != null) { |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
386 assert placeholders[i].isDeleted() : placeholders[i]; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
387 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
388 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
389 return true; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
390 } |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
391 |
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
|
392 private static boolean checkConstantArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) { |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7081
diff
changeset
|
393 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
|
394 ResolvedJavaType type = signature.getParameterType(i, method.getDeclaringClass()).resolve(method.getDeclaringClass()); |
62818f156081
added ResolvedJavaType.isClass(Class c) to replace some uses of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents:
6950
diff
changeset
|
395 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
|
396 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
|
397 } else { |
5574
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
398 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : |
13624e51918a
allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents:
5572
diff
changeset
|
399 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
|
400 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
401 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
|
402 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
403 |
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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 } |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
411 |
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
|
412 /** |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
413 * 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
|
414 */ |
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
|
415 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
|
416 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
417 /** |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
418 * The named parameters of this template that must be bound to values during instantiation. |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
419 * Each value in this map is either a {@link LocalNode} instance or a {@link LocalNode} array. |
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
|
420 */ |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
421 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
|
422 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
423 /** |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
424 * 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
|
425 */ |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
426 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
|
427 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
428 /** |
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
|
429 * 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
|
430 */ |
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
|
431 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
|
432 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
433 /** |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
434 * 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
|
435 */ |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
436 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
|
437 |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
438 /** |
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 * 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
|
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 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
|
442 |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
443 /** |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
444 * 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
|
445 * |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
446 * @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
|
447 */ |
6407
46d426e79bed
Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6386
diff
changeset
|
448 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
|
449 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>(); |
6449
de9c0c4b7c9b
added sanity assertion to snippet instantiation
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
450 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
|
451 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
|
452 String name = e.getKey(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 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
|
457 if (argument instanceof ValueNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
458 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
|
459 } else { |
5540
a891c53a295b
Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5538
diff
changeset
|
460 Kind kind = ((LocalNode) parameter).kind(); |
7098
e23980f4a890
Cleanup of Kind class: remove isXxx methods
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7081
diff
changeset
|
461 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
|
462 Constant constant = Constant.forBoxed(kind, argument); |
5572
8f9c9d372e31
small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents:
5547
diff
changeset
|
463 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
|
464 } |
5428
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
465 } else { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
466 assert parameter instanceof LocalNode[]; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
467 LocalNode[] locals = (LocalNode[]) parameter; |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
468 Object array = argument; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
469 assert array != null && array.getClass().isArray(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
470 int length = locals.length; |
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
471 assert Array.getLength(array) == length : length + " != " + Array.getLength(array); |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
472 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
|
473 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
|
474 assert local != null; |
6431
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
475 Object value = Array.get(array, j); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
476 if (value instanceof ValueNode) { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
477 replacements.put(local, (ValueNode) value); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
478 } else { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
479 Constant constant = Constant.forBoxed(local.kind(), value); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
480 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
481 replacements.put(local, element); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6408
diff
changeset
|
482 } |
5481
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
483 } |
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
|
484 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
485 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
486 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
|
487 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
488 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
489 /** |
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
|
490 * 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
|
491 * 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
|
492 * {@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
|
493 * 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
|
494 * 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
|
495 */ |
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
|
496 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
|
497 /** |
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
|
498 * 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
|
499 */ |
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
|
500 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
|
501 } |
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
|
502 |
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
|
503 /** |
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
|
504 * 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
|
505 * 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
|
506 */ |
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
|
507 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
|
508 @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
|
509 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
|
510 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
|
511 } |
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
|
512 }; |
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
|
513 |
d8408e5563e5
added indirection for the replacement of a snippet-lowered node with the snippet's return value
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
514 /** |
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
|
515 * 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
|
516 * |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
517 * @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
|
518 * @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
|
519 * @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
|
520 * @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
|
521 * @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
|
522 */ |
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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
528 // 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
538 // 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 |
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
|
544 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
|
545 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
|
546 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
|
547 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
|
548 ((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
|
549 } |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
550 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
551 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
|
552 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
|
553 ((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
|
554 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
555 |
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 // 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 } 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
|
562 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
|
563 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
564 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
|
565 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
|
566 |
6ec0857cdf46
added support for snippet templates which are snippet 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 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
|
568 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
|
569 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
|
570 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
|
571 } |
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
|
572 } |
6ec0857cdf46
added support for snippet templates which are snippet 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 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
574 // 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
|
575 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
|
576 replacee.replaceAtUsages(null); |
6588
b89b5038ad7e
removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
6574
diff
changeset
|
577 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
|
578 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
579 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
|
580 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
|
581 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
582 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
583 /** |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
584 * 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
|
585 * |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
586 * @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
|
587 * @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
|
588 * @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
|
589 * @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
|
590 * @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
|
591 */ |
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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
597 // 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 |
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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 ((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
|
618 } |
6408
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
619 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
diff
changeset
|
620 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
|
621 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
|
622 ((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
|
623 } |
e5768e936147
Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6407
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 // 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 } 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
|
631 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
|
632 } |
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
|
633 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
|
634 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
|
635 |
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 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
|
637 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
|
638 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
|
639 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
|
640 } |
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
|
641 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
642 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
|
643 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
644 |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
645 @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
|
646 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
|
647 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
|
648 String sep = ""; |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
649 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
|
650 String name = e.getKey(); |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
651 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
|
652 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
|
653 sep = ", "; |
e26e6dca0bcf
added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents:
5467
diff
changeset
|
654 if (value instanceof LocalNode) { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
655 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
|
656 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
|
657 } else { |
5482
9f4783c0269e
folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents:
5481
diff
changeset
|
658 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
|
659 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
|
660 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
|
661 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
662 } |
6ec0857cdf46
added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
663 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
|
664 } |
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
|
665 |
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 private static boolean checkTemplate(SnippetTemplate.Key key, int parameterCount, ResolvedJavaMethod method, Signature signature) { |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 assert checkConstantArgument(method, signature, i, c.value(), key.get(name), kind); |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
679 } 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 } 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
|
688 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
|
689 "@" + 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
|
690 "@" + 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
|
691 "@" + 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
|
692 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
693 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 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
|
702 " 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
|
703 } |
5d7d9a6953bd
added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
5760
diff
changeset
|
704 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
|
705 } |
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
|
706 } |