use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.
the class ObjectCloneNode method getLoweredSnippetGraph.
@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
ResolvedJavaType type = StampTool.typeOrNull(getObject());
if (type != null) {
if (type.isArray()) {
Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
if (method != null) {
final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
final Replacements replacements = tool.getReplacements();
StructuredGraph snippetGraph = null;
DebugContext debug = getDebug();
try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
} catch (Throwable e) {
throw debug.handle(e);
}
assert snippetGraph != null : "ObjectCloneSnippets should be installed";
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
}
assert false : "unhandled array type " + type.getComponentType().getJavaKind();
} else {
Assumptions assumptions = graph().getAssumptions();
type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
if (type != null) {
StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
newGraph.addAfterFixed(newGraph.start(), newInstance);
ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
newGraph.addAfterFixed(newInstance, returnNode);
for (ResolvedJavaField field : type.getInstanceFields(true)) {
LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
newGraph.addBeforeFixed(returnNode, load);
newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
}
assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
return lowerReplacement(newGraph, tool);
}
}
}
assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
return null;
}
use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.
the class HotSpotGraalCompiler method getIntrinsicGraph.
/**
* Gets a graph produced from the intrinsic for a given method that can be compiled and
* installed for the method.
*
* @param method
* @param compilationId
* @param options
* @param debug
* @return an intrinsic graph that can be compiled and installed for {@code method} or null
*/
@SuppressWarnings("try")
public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, HotSpotProviders providers, CompilationIdentifier compilationId, OptionValues options, DebugContext debug) {
Replacements replacements = providers.getReplacements();
Bytecode subst = replacements.getSubstitutionBytecode(method);
if (subst != null) {
ResolvedJavaMethod substMethod = subst.getMethod();
assert !substMethod.equals(method);
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(substMethod).compilationId(compilationId).build();
try (DebugContext.Scope scope = debug.scope("GetIntrinsicGraph", graph)) {
Plugins plugins = new Plugins(providers.getGraphBuilderPlugins());
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
IntrinsicContext initialReplacementContext = new IntrinsicContext(method, substMethod, subst.getOrigin(), ROOT_COMPILATION);
new GraphBuilderPhase.Instance(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext).apply(graph);
assert !graph.isFrozen();
return graph;
} catch (Throwable e) {
debug.handle(e);
}
}
return null;
}
use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.
the class SharedRuntimeConfigurationBuilder method build.
public SharedRuntimeConfigurationBuilder build() {
wordTypes = new WordTypes(metaAccess, FrameAccess.getWordKind());
Providers p = createProviders(null, null, null, null, null, null, null, null);
StampProvider stampProvider = createStampProvider(p);
p = createProviders(null, null, null, null, null, null, stampProvider, null);
ConstantReflectionProvider constantReflection = createConstantReflectionProvider(p);
ConstantFieldProvider constantFieldProvider = createConstantFieldProvider(p);
createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, null);
SnippetReflectionProvider snippetReflection = createSnippetReflectionProvider();
createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, snippetReflection);
ForeignCallsProvider foreignCalls = createForeignCallsProvider();
p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, null, null, stampProvider, snippetReflection);
LoweringProvider lowerer = createLoweringProvider(p);
p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, stampProvider, snippetReflection);
Replacements replacements = createReplacements(p, snippetReflection);
p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
EnumMap<ConfigKind, Backend> backends = new EnumMap<>(ConfigKind.class);
for (ConfigKind config : ConfigKind.values()) {
RegisterConfig registerConfig = new SubstrateAMD64RegisterConfig(config, metaAccess, ConfigurationValues.getTarget());
CodeCacheProvider codeCacheProvider = createCodeCacheProvider(registerConfig);
Providers newProviders = createProviders(codeCacheProvider, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
backends.put(config, GraalConfiguration.instance().createBackend(newProviders));
}
runtimeConfig = new RuntimeConfiguration(p, snippetReflection, backends, wordTypes);
return this;
}
Aggregations