package org.graalvm.compiler.replacements;
import java.lang.annotation.Annotation;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.graph.NodeInputList;
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.compiler.nodes.PluginReplacementNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedFoldInvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedNodeIntrinsicInvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginFactory;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginInjectionProvider;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
final class Plugin_SnippetCounterNode_add extends GeneratedNodeIntrinsicInvocationPlugin {
@Override
public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {
if (!b.isPluginEnabled(this)) {
return false;
}
org.graalvm.compiler.replacements.SnippetCounter arg0;
if (args[0].isConstant()) {
arg0 = snippetReflection.asObject(org.graalvm.compiler.replacements.SnippetCounter.class, args[0].asJavaConstant());
} else {
if (b.shouldDeferPlugin(this)) {
b.replacePlugin(this, targetMethod, args, PluginReplacementNode_SnippetCounterNode_add.FUNCTION);
return true;
}
assert b.canDeferPlugin(this) : b.getClass().toString();
return false;
}
ValueNode arg1 = args[1];
org.graalvm.compiler.replacements.SnippetCounterNode node = new org.graalvm.compiler.replacements.SnippetCounterNode(arg0, arg1);
b.add(node);
return true;
}
@Override
public Class<? extends Annotation> getSource() {
return org.graalvm.compiler.graph.Node.NodeIntrinsic.class;
}
private final org.graalvm.compiler.api.replacements.SnippetReflectionProvider snippetReflection;
Plugin_SnippetCounterNode_add(GeneratedPluginInjectionProvider injection) {
this.snippetReflection = injection.getInjectedArgument(org.graalvm.compiler.api.replacements.SnippetReflectionProvider.class);
}
}
final class PluginReplacementNode_SnippetCounterNode_add implements PluginReplacementNode.ReplacementFunction {
static PluginReplacementNode.ReplacementFunction FUNCTION = new PluginReplacementNode_SnippetCounterNode_add();
@Override
public boolean replace(GraphBuilderContext b, GeneratedPluginInjectionProvider injection, Stamp stamp, NodeInputList<ValueNode> args) {
org.graalvm.compiler.replacements.SnippetCounter arg0;
if (args.get(0).isConstant()) {
arg0 = injection.getInjectedArgument(org.graalvm.compiler.api.replacements.SnippetReflectionProvider.class).asObject(org.graalvm.compiler.replacements.SnippetCounter.class, args.get(0).asJavaConstant());
} else {
return false;
}
ValueNode arg1 = args.get(1);
org.graalvm.compiler.replacements.SnippetCounterNode node = new org.graalvm.compiler.replacements.SnippetCounterNode(arg0, arg1);
b.add(node);
return true;
}
}
final class Plugin_SnippetCounterSnippets_countOffset extends GeneratedFoldInvocationPlugin {
@Override
public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {
if (!b.isPluginEnabled(this)) {
return false;
}
if (b.shouldDeferPlugin(this)) {
b.replacePlugin(this, targetMethod, args, PluginReplacementNode_SnippetCounterSnippets_countOffset.FUNCTION);
return true;
}
int result = org.graalvm.compiler.replacements.SnippetCounterNode.SnippetCounterSnippets.countOffset();
JavaConstant constant = JavaConstant.forInt(result);
ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess(), b.getGraph());
b.push(JavaKind.Int, node);
b.notifyReplacedCall(targetMethod, node);
return true;
}
@Override
public Class<? extends Annotation> getSource() {
return org.graalvm.compiler.api.replacements.Fold.class;
}
}
final class PluginReplacementNode_SnippetCounterSnippets_countOffset implements PluginReplacementNode.ReplacementFunction {
static PluginReplacementNode.ReplacementFunction FUNCTION = new PluginReplacementNode_SnippetCounterSnippets_countOffset();
@Override
public boolean replace(GraphBuilderContext b, GeneratedPluginInjectionProvider injection, Stamp stamp, NodeInputList<ValueNode> args) {
int result = org.graalvm.compiler.replacements.SnippetCounterNode.SnippetCounterSnippets.countOffset();
JavaConstant constant = JavaConstant.forInt(result);
ConstantNode node = ConstantNode.forConstant(constant, b.getMetaAccess(), b.getGraph());
b.push(JavaKind.Int, node);
return true;
}
}
public class PluginFactory_SnippetCounterNode implements GeneratedPluginFactory {
@Override
public void registerPlugins(InvocationPlugins plugins, GeneratedPluginInjectionProvider injection) {
plugins.register(new Plugin_SnippetCounterNode_add(injection), org.graalvm.compiler.replacements.SnippetCounterNode.class, "add", org.graalvm.compiler.replacements.SnippetCounter.class, int.class);
plugins.register(new Plugin_SnippetCounterSnippets_countOffset(), org.graalvm.compiler.replacements.SnippetCounterNode.SnippetCounterSnippets.class, "countOffset");
}
}