43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.replacements;
|
|
26 |
|
|
27 |
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
|
|
28 |
import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
|
|
29 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
30 |
import org.graalvm.compiler.core.common.type.StampFactory;
|
|
31 |
import org.graalvm.compiler.core.common.type.TypeReference;
|
|
32 |
import org.graalvm.compiler.debug.GraalError;
|
|
33 |
import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory.InjectionProvider;
|
52910
|
34 |
import org.graalvm.compiler.replacements.arraycopy.ArrayCopyForeignCalls;
|
43972
|
35 |
import org.graalvm.compiler.word.WordTypes;
|
|
36 |
|
58877
|
37 |
import jdk.vm.ci.code.TargetDescription;
|
43972
|
38 |
import jdk.vm.ci.meta.JavaKind;
|
|
39 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
40 |
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
41 |
|
|
42 |
public class NodeIntrinsificationProvider implements InjectionProvider {
|
|
43 |
|
58877
|
44 |
public static final TargetDescription INJECTED_TARGET = null;
|
|
45 |
|
43972
|
46 |
private final MetaAccessProvider metaAccess;
|
|
47 |
private final SnippetReflectionProvider snippetReflection;
|
|
48 |
private final ForeignCallsProvider foreignCalls;
|
|
49 |
private final WordTypes wordTypes;
|
58877
|
50 |
private final TargetDescription target;
|
43972
|
51 |
|
58877
|
52 |
public NodeIntrinsificationProvider(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, ForeignCallsProvider foreignCalls, WordTypes wordTypes, TargetDescription target) {
|
43972
|
53 |
this.metaAccess = metaAccess;
|
|
54 |
this.snippetReflection = snippetReflection;
|
|
55 |
this.foreignCalls = foreignCalls;
|
|
56 |
this.wordTypes = wordTypes;
|
58877
|
57 |
this.target = target;
|
43972
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
46371
|
61 |
public Stamp getInjectedStamp(Class<?> type, boolean nonNull) {
|
43972
|
62 |
JavaKind kind = JavaKind.fromJavaClass(type);
|
|
63 |
if (kind == JavaKind.Object) {
|
|
64 |
ResolvedJavaType returnType = metaAccess.lookupJavaType(type);
|
|
65 |
if (wordTypes.isWord(returnType)) {
|
|
66 |
return wordTypes.getWordStamp(returnType);
|
|
67 |
} else {
|
|
68 |
return StampFactory.object(TypeReference.createWithoutAssumptions(returnType), nonNull);
|
|
69 |
}
|
|
70 |
} else {
|
|
71 |
return StampFactory.forKind(kind);
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
@Override
|
|
76 |
public <T> T getInjectedArgument(Class<T> type) {
|
|
77 |
T injected = snippetReflection.getInjectedNodeIntrinsicParameter(type);
|
|
78 |
if (injected != null) {
|
|
79 |
return injected;
|
52910
|
80 |
} else if (type.equals(ForeignCallsProvider.class) || type.equals(ArrayCopyForeignCalls.class)) {
|
43972
|
81 |
return type.cast(foreignCalls);
|
|
82 |
} else if (type.equals(SnippetReflectionProvider.class)) {
|
|
83 |
return type.cast(snippetReflection);
|
52956
|
84 |
} else if (type.equals(WordTypes.class)) {
|
|
85 |
return type.cast(wordTypes);
|
58877
|
86 |
} else if (type.equals(TargetDescription.class)) {
|
|
87 |
return type.cast(target);
|
43972
|
88 |
} else {
|
|
89 |
throw new GraalError("Cannot handle injected argument of type %s.", type.getName());
|
|
90 |
}
|
|
91 |
}
|
|
92 |
}
|