55509
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
|
|
25 |
package org.graalvm.compiler.replacements.amd64;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_512;
|
|
28 |
|
|
29 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
|
|
30 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
31 |
import org.graalvm.compiler.graph.NodeClass;
|
|
32 |
import org.graalvm.compiler.graph.NodeInputList;
|
|
33 |
import org.graalvm.compiler.nodeinfo.InputType;
|
|
34 |
import org.graalvm.compiler.nodeinfo.NodeCycles;
|
|
35 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
36 |
import org.graalvm.compiler.nodes.DeoptimizingNode;
|
|
37 |
import org.graalvm.compiler.nodes.FixedWithNextNode;
|
|
38 |
import org.graalvm.compiler.nodes.FrameState;
|
|
39 |
import org.graalvm.compiler.nodes.NamedLocationIdentity;
|
|
40 |
import org.graalvm.compiler.nodes.ValueNode;
|
|
41 |
import org.graalvm.compiler.nodes.ValueNodeUtil;
|
|
42 |
import org.graalvm.compiler.nodes.memory.MemoryAccess;
|
|
43 |
import org.graalvm.compiler.nodes.memory.MemoryNode;
|
|
44 |
import org.graalvm.compiler.nodes.spi.Lowerable;
|
|
45 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
46 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
|
47 |
|
|
48 |
import jdk.vm.ci.meta.JavaKind;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* This node is a placeholder for all variants of intrinsified indexof-operations. It may be lowered
|
|
52 |
* to a {@link AMD64ArrayIndexOfNode} or a specialized snippet.
|
|
53 |
*/
|
|
54 |
@NodeInfo(size = SIZE_512, cycles = NodeCycles.CYCLES_UNKNOWN)
|
|
55 |
public class AMD64ArrayIndexOfDispatchNode extends FixedWithNextNode implements Lowerable, MemoryAccess, DeoptimizingNode.DeoptBefore {
|
|
56 |
|
|
57 |
public static final NodeClass<AMD64ArrayIndexOfDispatchNode> TYPE = NodeClass.create(AMD64ArrayIndexOfDispatchNode.class);
|
|
58 |
|
|
59 |
private final ForeignCallDescriptor stubCallDescriptor;
|
|
60 |
private final JavaKind arrayKind;
|
|
61 |
private final JavaKind valueKind;
|
|
62 |
private final boolean findTwoConsecutive;
|
|
63 |
|
|
64 |
@Input private ValueNode arrayPointer;
|
|
65 |
@Input private ValueNode arrayLength;
|
|
66 |
@Input private ValueNode fromIndex;
|
|
67 |
@Input private NodeInputList<ValueNode> searchValues;
|
|
68 |
|
|
69 |
@OptionalInput(InputType.Memory) private MemoryNode lastLocationAccess;
|
|
70 |
@OptionalInput(InputType.State) protected FrameState stateBefore;
|
|
71 |
|
|
72 |
public AMD64ArrayIndexOfDispatchNode(@ConstantNodeParameter ForeignCallDescriptor stubCallDescriptor, @ConstantNodeParameter JavaKind arrayKind, @ConstantNodeParameter JavaKind valueKind,
|
|
73 |
@ConstantNodeParameter boolean findTwoConsecutive, ValueNode arrayPointer, ValueNode arrayLength, ValueNode fromIndex, ValueNode... searchValues) {
|
|
74 |
super(TYPE, StampFactory.forKind(JavaKind.Int));
|
|
75 |
this.stubCallDescriptor = stubCallDescriptor;
|
|
76 |
this.arrayKind = arrayKind;
|
|
77 |
this.valueKind = valueKind;
|
|
78 |
this.findTwoConsecutive = findTwoConsecutive;
|
|
79 |
this.arrayPointer = arrayPointer;
|
|
80 |
this.arrayLength = arrayLength;
|
|
81 |
this.fromIndex = fromIndex;
|
|
82 |
this.searchValues = new NodeInputList<>(this, searchValues);
|
|
83 |
}
|
|
84 |
|
|
85 |
public boolean isFindTwoConsecutive() {
|
|
86 |
return findTwoConsecutive;
|
|
87 |
}
|
|
88 |
|
|
89 |
public ValueNode getArrayPointer() {
|
|
90 |
return arrayPointer;
|
|
91 |
}
|
|
92 |
|
|
93 |
public ValueNode getArrayLength() {
|
|
94 |
return arrayLength;
|
|
95 |
}
|
|
96 |
|
|
97 |
public ValueNode getFromIndex() {
|
|
98 |
return fromIndex;
|
|
99 |
}
|
|
100 |
|
|
101 |
public NodeInputList<ValueNode> getSearchValues() {
|
|
102 |
return searchValues;
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
public boolean canDeoptimize() {
|
|
107 |
return true;
|
|
108 |
}
|
|
109 |
|
|
110 |
@Override
|
|
111 |
public void setStateBefore(FrameState f) {
|
|
112 |
updateUsages(stateBefore, f);
|
|
113 |
stateBefore = f;
|
|
114 |
}
|
|
115 |
|
|
116 |
@Override
|
|
117 |
public FrameState stateBefore() {
|
|
118 |
return stateBefore;
|
|
119 |
}
|
|
120 |
|
|
121 |
public ForeignCallDescriptor getStubCallDescriptor() {
|
|
122 |
return stubCallDescriptor;
|
|
123 |
}
|
|
124 |
|
|
125 |
public int getNumberOfValues() {
|
|
126 |
return searchValues.size();
|
|
127 |
}
|
|
128 |
|
|
129 |
public JavaKind getArrayKind() {
|
|
130 |
return arrayKind;
|
|
131 |
}
|
|
132 |
|
|
133 |
public JavaKind getValueKind() {
|
|
134 |
return valueKind;
|
|
135 |
}
|
|
136 |
|
|
137 |
public JavaKind getComparisonKind() {
|
|
138 |
return findTwoConsecutive ? (valueKind == JavaKind.Byte ? JavaKind.Char : JavaKind.Int) : valueKind;
|
|
139 |
}
|
|
140 |
|
|
141 |
public ValueNode[] getStubCallArgs() {
|
|
142 |
ValueNode[] ret = new ValueNode[searchValues.size() + 3];
|
|
143 |
ret[0] = arrayPointer;
|
|
144 |
ret[1] = arrayLength;
|
|
145 |
ret[2] = fromIndex;
|
|
146 |
for (int i = 0; i < searchValues.size(); i++) {
|
|
147 |
ret[3 + i] = searchValues.get(i);
|
|
148 |
}
|
|
149 |
return ret;
|
|
150 |
}
|
|
151 |
|
|
152 |
public AMD64ArrayIndexOfDispatchNode(@ConstantNodeParameter ForeignCallDescriptor stubCallDescriptor, @ConstantNodeParameter JavaKind arrayKind, @ConstantNodeParameter JavaKind valueKind,
|
|
153 |
ValueNode arrayPointer, ValueNode arrayLength, ValueNode fromIndex, ValueNode... searchValues) {
|
|
154 |
this(stubCallDescriptor, arrayKind, valueKind, false, arrayPointer, arrayLength, fromIndex, searchValues);
|
|
155 |
}
|
|
156 |
|
|
157 |
@Override
|
|
158 |
public LocationIdentity getLocationIdentity() {
|
|
159 |
return NamedLocationIdentity.getArrayLocation(arrayKind);
|
|
160 |
}
|
|
161 |
|
|
162 |
@Override
|
|
163 |
public void lower(LoweringTool tool) {
|
|
164 |
tool.getLowerer().lower(this, tool);
|
|
165 |
}
|
|
166 |
|
|
167 |
@Override
|
|
168 |
public MemoryNode getLastLocationAccess() {
|
|
169 |
return lastLocationAccess;
|
|
170 |
}
|
|
171 |
|
|
172 |
@Override
|
|
173 |
public void setLastLocationAccess(MemoryNode lla) {
|
|
174 |
updateUsages(ValueNodeUtil.asNode(lastLocationAccess), ValueNodeUtil.asNode(lla));
|
|
175 |
lastLocationAccess = lla;
|
|
176 |
}
|
|
177 |
|
|
178 |
@NodeIntrinsic
|
|
179 |
private static native int optimizedArrayIndexOf(
|
|
180 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
181 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
182 |
@ConstantNodeParameter JavaKind valueKind,
|
|
183 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
184 |
Object array, int arrayLength, int fromIndex, byte v1);
|
|
185 |
|
|
186 |
@NodeIntrinsic
|
|
187 |
private static native int optimizedArrayIndexOf(
|
|
188 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
189 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
190 |
@ConstantNodeParameter JavaKind valueKind,
|
|
191 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
192 |
Object array, int arrayLength, int fromIndex, byte v1, byte v2);
|
|
193 |
|
|
194 |
@NodeIntrinsic
|
|
195 |
private static native int optimizedArrayIndexOf(
|
|
196 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
197 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
198 |
@ConstantNodeParameter JavaKind valueKind,
|
|
199 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
200 |
Object array, int arrayLength, int fromIndex, byte v1, byte v2, byte v3);
|
|
201 |
|
|
202 |
@NodeIntrinsic
|
|
203 |
private static native int optimizedArrayIndexOf(
|
|
204 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
205 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
206 |
@ConstantNodeParameter JavaKind valueKind,
|
|
207 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
208 |
Object array, int arrayLength, int fromIndex, byte v1, byte v2, byte v3, byte v4);
|
|
209 |
|
|
210 |
@NodeIntrinsic
|
|
211 |
private static native int optimizedArrayIndexOf(
|
|
212 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
213 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
214 |
@ConstantNodeParameter JavaKind valueKind,
|
|
215 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
216 |
Object array, int arrayLength, int fromIndex, char v1);
|
|
217 |
|
|
218 |
@NodeIntrinsic
|
|
219 |
private static native int optimizedArrayIndexOf(
|
|
220 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
221 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
222 |
@ConstantNodeParameter JavaKind valueKind,
|
|
223 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
224 |
Object array, int arrayLength, int fromIndex, char v1, char v2);
|
|
225 |
|
|
226 |
@NodeIntrinsic
|
|
227 |
private static native int optimizedArrayIndexOf(
|
|
228 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
229 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
230 |
@ConstantNodeParameter JavaKind valueKind,
|
|
231 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
232 |
Object array, int arrayLength, int fromIndex, char v1, char v2, char v3);
|
|
233 |
|
|
234 |
@NodeIntrinsic
|
|
235 |
private static native int optimizedArrayIndexOf(
|
|
236 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
237 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
238 |
@ConstantNodeParameter JavaKind valueKind,
|
|
239 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
240 |
Object array, int arrayLength, int fromIndex, char v1, char v2, char v3, char v4);
|
|
241 |
|
|
242 |
@NodeIntrinsic
|
|
243 |
private static native int optimizedArrayIndexOf(
|
|
244 |
@ConstantNodeParameter ForeignCallDescriptor descriptor,
|
|
245 |
@ConstantNodeParameter JavaKind arrayKind,
|
|
246 |
@ConstantNodeParameter JavaKind valueKind,
|
|
247 |
@ConstantNodeParameter boolean findTwoConsecutive,
|
|
248 |
Object array, int arrayLength, int fromIndex, int searchValue);
|
|
249 |
|
|
250 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, byte v1) {
|
|
251 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Byte, false, array, arrayLength, fromIndex, v1);
|
|
252 |
}
|
|
253 |
|
|
254 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, byte v1, byte v2) {
|
|
255 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Byte, false, array, arrayLength, fromIndex, v1, v2);
|
|
256 |
}
|
|
257 |
|
|
258 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, byte v1, byte v2, byte v3) {
|
|
259 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Byte, false, array, arrayLength, fromIndex, v1, v2, v3);
|
|
260 |
}
|
|
261 |
|
|
262 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, byte v1, byte v2, byte v3, byte v4) {
|
|
263 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Byte, false, array, arrayLength, fromIndex, v1, v2, v3, v4);
|
|
264 |
}
|
|
265 |
|
|
266 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, char v1) {
|
|
267 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Char, false, array, arrayLength, fromIndex, v1);
|
|
268 |
}
|
|
269 |
|
|
270 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, char v1, char v2) {
|
|
271 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2);
|
|
272 |
}
|
|
273 |
|
|
274 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, char v1, char v2, char v3) {
|
|
275 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2, v3);
|
|
276 |
}
|
|
277 |
|
|
278 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, char v1, char v2, char v3, char v4) {
|
|
279 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2, v3, v4);
|
|
280 |
}
|
|
281 |
|
|
282 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, char[] array, int arrayLength, int fromIndex, char v1) {
|
|
283 |
return optimizedArrayIndexOf(descriptor, JavaKind.Char, JavaKind.Char, false, array, arrayLength, fromIndex, v1);
|
|
284 |
}
|
|
285 |
|
|
286 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, char[] array, int arrayLength, int fromIndex, char v1, char v2) {
|
|
287 |
return optimizedArrayIndexOf(descriptor, JavaKind.Char, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2);
|
|
288 |
}
|
|
289 |
|
|
290 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, char[] array, int arrayLength, int fromIndex, char v1, char v2, char v3) {
|
|
291 |
return optimizedArrayIndexOf(descriptor, JavaKind.Char, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2, v3);
|
|
292 |
}
|
|
293 |
|
|
294 |
public static int indexOf(@ConstantNodeParameter ForeignCallDescriptor descriptor, char[] array, int arrayLength, int fromIndex, char v1, char v2, char v3, char v4) {
|
|
295 |
return optimizedArrayIndexOf(descriptor, JavaKind.Char, JavaKind.Char, false, array, arrayLength, fromIndex, v1, v2, v3, v4);
|
|
296 |
}
|
|
297 |
|
|
298 |
public static int indexOf2ConsecutiveBytes(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, int values) {
|
|
299 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Byte, true, array, arrayLength, fromIndex, values);
|
|
300 |
}
|
|
301 |
|
|
302 |
public static int indexOf2ConsecutiveChars(@ConstantNodeParameter ForeignCallDescriptor descriptor, byte[] array, int arrayLength, int fromIndex, int values) {
|
|
303 |
return optimizedArrayIndexOf(descriptor, JavaKind.Byte, JavaKind.Char, true, array, arrayLength, fromIndex, values);
|
|
304 |
}
|
|
305 |
|
|
306 |
public static int indexOf2ConsecutiveChars(@ConstantNodeParameter ForeignCallDescriptor descriptor, char[] array, int arrayLength, int fromIndex, int values) {
|
|
307 |
return optimizedArrayIndexOf(descriptor, JavaKind.Char, JavaKind.Char, true, array, arrayLength, fromIndex, values);
|
|
308 |
}
|
|
309 |
}
|