annotate graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 6431:2e376f8ea4e2

added snippet for lowering NewMultiArrayNodes
author Doug Simon <doug.simon@oracle.com>
date Tue, 25 Sep 2012 09:09:19 +0200
parents e5768e936147
children de9c0c4b7c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.snippets;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.lang.reflect.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import java.util.*;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
27 import java.util.Map.Entry;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.util.concurrent.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
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.compiler.loop.*;
6ec0857cdf46 added support for snippet templates which are snippet 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.compiler.phases.*;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 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
35 import com.oracle.graal.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
36 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
37 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
38 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
39 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
40 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
41 import com.oracle.graal.nodes.util.*;
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
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
58 * and the arguments used to specialized the snippet.
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<>();
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
156 private final MetaAccessProvider runtime;
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
157
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
158
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
159 public Cache(MetaAccessProvider runtime) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
160 this.runtime = runtime;
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
161 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
162
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
163 /**
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
164 * 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
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 public SnippetTemplate get(final SnippetTemplate.Key key) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
167 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
168 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
169 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
170 @Override
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
171 public SnippetTemplate call() throws Exception {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
172 return new SnippetTemplate(runtime, key);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
173 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
174 });
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
175 //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
176 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
177 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
178 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
179 }
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
180 }
5481
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 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
183 protected final Cache cache;
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 protected final CodeCacheProvider 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
185 protected Class<T> snippetsClass;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
186 public AbstractTemplates(CodeCacheProvider runtime, Class<T> snippetsClass) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
187 this.runtime = 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
188 this.snippetsClass = snippetsClass;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
189 this.cache = new Cache(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
190 }
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
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
192 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
193 try {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
194 ResolvedJavaMethod snippet = runtime.getResolvedJavaMethod(snippetsClass.getDeclaredMethod(name, 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
195 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
196 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
197 } 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
198 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
199 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
200 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
201 }
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
202
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
203 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
204 * 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
205 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
206 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
207 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
208 if (p != null) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
209 return true;
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 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
212 return false;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
213 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
214
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
215 /**
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216 * 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
217 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
218 public SnippetTemplate(MetaAccessProvider runtime, 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
219 ResolvedJavaMethod method = key.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
220 assert Modifier.isStatic(method.accessFlags()) : "snippet method must be static: " + method;
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
221 Signature signature = method.signature();
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
222
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
223 // Copy snippet graph, replacing constant parameters with given arguments
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
224 StructuredGraph snippetGraph = (StructuredGraph) method.compilerStorage().get(Graph.class);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
225 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
226 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
227 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
228
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
229 int parameterCount = signature.argumentCount(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
230 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
231
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
232 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
233 VarargsParameter[] varargsParameterAnnotations = new VarargsParameter[parameterCount];
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
234 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
235 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
236 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
237 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
238 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
239 Object arg = key.get(name);
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
240 Kind kind = signature.argumentKindAt(i);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
241 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
242 } 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
243 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
244 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
245 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
246 Object array = ((Varargs) key.get(name)).array;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
247 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
248 replacements.put(snippetGraph.getLocal(i), placeholder);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
249 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
250 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
251 } 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
252 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
253 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
254 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
255 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
256 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
257
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
258 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
259 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
260 // 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
261 new SnippetIntrinsificationPhase(runtime, new BoxingMethodPool(runtime), false).apply(snippetCopy);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
262
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
263 new CanonicalizerPhase(null, runtime, null, 0, null).apply(snippetCopy);
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
264 }
5466
af07e798947d lifted fast subtype check into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5428
diff changeset
265
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
266 // 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
267 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
268 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
269 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
270 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
271 assert snippetCopy.getLocal(i) == 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
272 Object array = ((Varargs) key.get(vp.value())).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
273 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
274 LocalNode[] locals = new LocalNode[length];
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
275 Stamp stamp = StampFactory.forKind(runtime.getResolvedJavaType(array.getClass().getComponentType()).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
276 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
277 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
278 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
279 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
280 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
281 }
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 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
283
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 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
285 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
294 }
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 } 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
296 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
297 if (p != null) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
298 LocalNode local = snippetCopy.getLocal(i);
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
299 assert local != null;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
300 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
301 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
302 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
303 }
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
304
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
305 // 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
306 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
307 do {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
308 exploded = false;
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
309 ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
310 if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
311 LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
312 if (loopBegin != null) {
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
313 LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
314 int mark = snippetCopy.getMark();
5681
7482f7d08455 Don't try to fold conditions when there is no runtime available
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5670
diff changeset
315 LoopTransformations.fullUnroll(loop, runtime);
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
316 new CanonicalizerPhase(null, runtime, null, mark, null).apply(snippetCopy);
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
317 }
5490
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
318 FixedNode explodeLoopNext = explodeLoop.next();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
319 explodeLoop.clearSuccessors();
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
320 explodeLoop.replaceAtPredecessor(explodeLoopNext);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
321 explodeLoop.replaceAtUsages(null);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
322 GraphUtil.killCFG(explodeLoop);
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5489 5482
diff changeset
323 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
324 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
325 } 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
326
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
327 // 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
328 // of side-effects that prevent deoptimizing to a point before the snippet).
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
329 Node curSideEffectNode = null;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
330 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
331 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
332 if (node instanceof ValueNode && ((ValueNode) node).stamp() == StampFactory.forNodeIntrinsic()) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
333 assert curStampNode == null : "Currently limited to stamp node (but this can be converted to a List if necessary)";
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
334 curStampNode = node;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
335 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
336 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
337 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
338 FrameState frameState = stateSplit.stateAfter();
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
339 if (stateSplit.hasSideEffect()) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
340 assert curSideEffectNode == null : "Currently limited to one side-effecting node (but this can be converted to a List if necessary)";
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
341 curSideEffectNode = node;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
342 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
343 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
344 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
345 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
346 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
347 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
348
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
349 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
350
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
351 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
352
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
353 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
354 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
355 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
356
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
357 Map<Integer, JumpNode[]> jumpsMap = new HashMap<>();
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 for (JumpNode jump : snippet.getNodes().filter(JumpNode.class).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
359 FixedNode next = jump.next();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
360
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
361 // Remove the nodes after the jump
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 jump.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
363 GraphUtil.killCFG(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
364 JumpNode[] jumpsForIndex = jumpsMap.get(jump.successorIndex());
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 if (jumpsForIndex == 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
366 jumpsMap.put(jump.successorIndex(), new JumpNode[] {jump});
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 } 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
368 jumpsForIndex = Arrays.copyOf(jumpsForIndex, jumpsForIndex.length + 1);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
369 jumpsForIndex[jumpsForIndex.length - 1] = jump;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
370 jumpsMap.put(jump.successorIndex(), jumpsForIndex);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
371 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
372 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
373
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
374 this.jumps = new JumpNode[jumpsMap.size()][];
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
375 for (Map.Entry<Integer, JumpNode[]> e : jumpsMap.entrySet()) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
376 int successorIndex = e.getKey();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
377 assert successorIndex >= 0 && successorIndex < this.jumps.length;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
378 assert this.jumps[successorIndex] == null;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
379 this.jumps[successorIndex] = e.getValue();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
380 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
381
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
382 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
383
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
384 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
385 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
386 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
387 // 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
388 } 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
389 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
390 if (node instanceof ReturnNode) {
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
391 assert this.jumps.length == 0 : "snippet with Jump node(s) cannot have a return node";
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
392 retNode = (ReturnNode) node;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
393 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
394 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
395 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
396
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
397 this.sideEffectNode = curSideEffectNode;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
398 this.stampNode = curStampNode;
5428
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
399 this.returnNode = retNode;
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
400 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
401
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
402 private static boolean checkAllVarargPlaceholdersAreDeleted(int parameterCount, ConstantNode[] placeholders) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
403 for (int i = 0; i < parameterCount; i++) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
404 if (placeholders[i] != null) {
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
405 assert placeholders[i].isDeleted() : placeholders[i];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
406 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
407 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
408 return true;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
409 }
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
410
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
411 private static boolean checkConstantArgument(final ResolvedJavaMethod method, Signature signature, int i, String name, Object arg, Kind kind) {
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
412 if (kind.isObject()) {
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
413 Class<?> type = signature.argumentTypeAt(i, method.holder()).resolve(method.holder()).toJava();
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
414 assert arg == null || type.isInstance(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
415 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
416 } else {
5574
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
417 assert arg != null && kind.toBoxedJavaClass() == arg.getClass() :
13624e51918a allow null for @ConstantParameter values
Doug Simon <doug.simon@oracle.com>
parents: 5572
diff changeset
418 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
419 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
420 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
421 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
422
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
423 private static boolean checkVarargs(final ResolvedJavaMethod method, Signature signature, int i, String name, Varargs 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
424 Object arg = varargs.array;
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
425 ResolvedJavaType type = (ResolvedJavaType) signature.argumentTypeAt(i, method.holder());
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 Class< ? > javaType = type.toJava();
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
427 assert javaType.isArray() : "varargs parameter must be an array type";
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
428 assert javaType.isInstance(arg) : "value for " + name + " is not a " + javaType.getName() + " instance: " + arg;
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
429 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
430 }
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
431
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
432 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
433 * 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
434 */
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
435 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
436
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
437 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
438 * 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
439 * 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
440 */
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
441 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
442
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
443 /**
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
444 * 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
445 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
446 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
447
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
448 /**
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
449 * Node that inherits the {@link StateSplit#stateAfter()} 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
450 */
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
451 private final Node sideEffectNode;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
452
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
453 /**
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
454 * 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
455 */
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
456 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
457
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
458 /**
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
459 * 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
460 */
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
461 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
462
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
463 /**
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
464 * The {@link JumpNode}s in the snippet, indexed by {@linkplain ControlSplitNode#blockSuccessor(int) successor} indexes.
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
465 * There may be more than one jump per successor index which explains why this is a 2-dimensional 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
466 */
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
467 private final JumpNode[][] jumps;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
468
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
469 /**
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
470 * 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
471 *
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
472 * @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
473 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
474 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
475 IdentityHashMap<Node, Node> replacements = new IdentityHashMap<>();
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
476
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
477 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
478 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
479 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
480 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
481 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
482 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
483 if (argument instanceof ValueNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
484 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
485 } else {
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
486 Kind kind = ((LocalNode) parameter).kind();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
487 assert argument != null || kind.isObject() : 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
488 Constant constant = Constant.forBoxed(kind, argument);
5572
8f9c9d372e31 small renaming and doc fixes
Lukas Stadler <lukas.stadler@jku.at>
parents: 5547
diff changeset
489 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
490 }
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
491 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
492 assert parameter instanceof LocalNode[];
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
493 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
494 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
495 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
496 int length = locals.length;
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
497 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
498 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
499 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
500 assert local != null;
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
501 Object value = Array.get(array, j);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
502 if (value instanceof ValueNode) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
503 replacements.put(local, (ValueNode) value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
504 } else {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
505 Constant constant = Constant.forBoxed(local.kind(), value);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
506 ConstantNode element = ConstantNode.forConstant(constant, runtime, replaceeGraph);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
507 replacements.put(local, element);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6408
diff changeset
508 }
5481
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
509 }
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
510 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
511 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
512 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
513 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
514
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
515 /**
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
516 * 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
517 *
6ec0857cdf46 added support for snippet templates which are snippet 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 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
519 * @param replacee the node that will be replaced
6ec0857cdf46 added support for snippet templates which are snippet 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 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
523 public Map<Node, Node> 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
524 FixedWithNextNode replacee, 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
525
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
526 // 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
527 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
528 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
529 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
530 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
531 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
532 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
533 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
534 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
535
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
536 // 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
537 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
538 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
539 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
540 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
541
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
542 if (sideEffectNode != null) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
543 assert ((StateSplit) replacee).hasSideEffect();
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
544 Node sideEffectDup = duplicates.get(sideEffectNode);
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
545 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
546 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
547 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
548 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
549 ((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
550 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
551
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
552 // Replace all usages of the replacee with the value returned by 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
553 Node returnValue = 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
554 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
555 if (returnNode.result() instanceof LocalNode) {
6ec0857cdf46 added support for snippet templates which are snippet 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 returnValue = replacements.get(returnNode.result());
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
557 } 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
558 returnValue = duplicates.get(returnNode.result());
6ec0857cdf46 added support for snippet templates which are snippet 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 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
560 assert returnValue != null || replacee.usages().isEmpty();
6ec0857cdf46 added support for snippet templates which are snippet 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 replacee.replaceAtUsages(returnValue);
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
562
6ec0857cdf46 added support for snippet templates which are snippet 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 Node returnDuplicate = duplicates.get(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
564 returnDuplicate.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
565 returnDuplicate.replaceAndDelete(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
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
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
568 // 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
569 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
570 replacee.replaceAtUsages(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
571 GraphUtil.killCFG(replacee);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
572
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
573 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
574 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
575 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
576
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
577 /**
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 * 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
579 *
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
580 * @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
581 * @param replacee the node that will be replaced
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 * @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
583 * @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
584 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
585 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
586 FloatingNode replacee,
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 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
588
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 // 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
590 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
591 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
592 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
593 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
594 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
595 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
596 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
597 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
598
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 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
600 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
601 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
602 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
603 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
604
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
605 if (sideEffectNode != null) {
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
606 assert ((StateSplit) replacee).hasSideEffect();
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
607 Node sideEffectDup = duplicates.get(sideEffectNode);
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
608 ((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
609 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
610 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
611 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
612 ((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
613 }
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
614
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
615 // 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
616 assert returnNode != 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
617 Node returnValue = 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
618 if (returnNode.result() instanceof LocalNode) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
619 returnValue = 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
620 } 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
621 returnValue = 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
622 }
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
623 assert returnValue != null || replacee.usages().isEmpty();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
624 replacee.replaceAtUsages(returnValue);
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
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 Node returnDuplicate = duplicates.get(returnNode);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
627 returnDuplicate.clearInputs();
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 returnDuplicate.replaceAndDelete(next);
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
629
6ec0857cdf46 added support for snippet templates which are snippet 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 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
631 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
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 /**
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
634 * Replaces a given floating node that is an input to a {@link ControlSplitNode} 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
635 * The {@linkplain JumpNode jumps} in the snippet are connected to the successors of the control split 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
636 *
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
637 * @param replacee the node that will be replaced
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
638 * @param controlSplitNode the node replaced by this wheCFG 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
639 * @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
640 */
6407
46d426e79bed Snippets need only a MetaAccessProvider, not a CodeCacheProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6386
diff changeset
641 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
642 FloatingNode replacee,
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
643 ControlSplitNode controlSplitNode,
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
644 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
645
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
646 // 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
647 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
648 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
649 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
650 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
651 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
652 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
653 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
654 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
655
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
656
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
657 int successorIndex = 0;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
658 for (JumpNode[] jumpsForIndex : jumps) {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
659 fixEdge(controlSplitNode, jumpsForIndex, successorIndex++, duplicates);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
660 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
661
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
662 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
663 controlSplitNode.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
664 controlSplitNode.replaceAtUsages(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
665
6408
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
666 assert sideEffectNode == null;
e5768e936147 Allow snippets to inherit the stateAfter and stamp from the replacee
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6407
diff changeset
667 assert stampNode == 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
668 assert returnNode == 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
669 GraphUtil.killCFG(controlSplitNode);
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
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 Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
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 }
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
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 private static void fixEdge(ControlSplitNode splitAnchor, JumpNode[] jumpsForIndex, int successorIndex, Map<Node, Node> duplicates) {
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 BeginNode blockSuccessor = splitAnchor.blockSuccessor(successorIndex);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
676 splitAnchor.setBlockSuccessor(successorIndex, 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
677 if (jumpsForIndex.length == 1) {
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 JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[0]);
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 jump.replaceAtPredecessor(blockSuccessor);
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 GraphUtil.killCFG(jump);
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 } 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
682 StructuredGraph graph = (StructuredGraph) splitAnchor.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
683 MergeNode merge = graph.add(new MergeNode());
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 for (int i = 0; i < jumpsForIndex.length; 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
685 EndNode end = graph.add(new EndNode());
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 JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[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
687 jump.replaceAtPredecessor(end);
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 merge.addForwardEnd(end);
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 GraphUtil.killCFG(jump);
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 }
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 merge.setNext(blockSuccessor);
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
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
695 @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
696 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
697 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
698 String sep = "";
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
699 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
700 String name = e.getKey();
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
701 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
702 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
703 sep = ", ";
e26e6dca0bcf added @Parameter and @Constant annotations which simplify creation and instantiation of snippets
Doug Simon <doug.simon@oracle.com>
parents: 5467
diff changeset
704 if (value instanceof LocalNode) {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
705 LocalNode local = (LocalNode) value;
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
706 buf.append(local.kind().javaName).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
707 } else {
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
708 LocalNode[] locals = (LocalNode[]) value;
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5719
diff changeset
709 String kind = locals.length == 0 ? "?" : locals[0].kind().javaName;
5482
9f4783c0269e folded -G:+CheckcastCounters functionality into checkcast snippets
Doug Simon <doug.simon@oracle.com>
parents: 5481
diff changeset
710 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
711 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
712 }
6ec0857cdf46 added support for snippet templates which are snippet graphs specialized by binding a constant to at least one of the snippet's parameters
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
713 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
714 }
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
715
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
716 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
717 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
718 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
719 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
720 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
721 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
722 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
723 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
724 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
725 expected.add(name);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
726 Kind kind = signature.argumentKindAt(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
727 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
728 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
729 } 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
730 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
731 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
732 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
733 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
734 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
735 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
736 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
737 } 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
738 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
739 "@" + 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
740 "@" + 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
741 "@" + 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
742 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
743 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
744 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
745 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
746 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
747 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
748 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
749 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
750 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
751 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
752 " 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
753 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
754 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
755 }
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
756 }