package org.graalvm.compiler.nodes;
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0;
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.spi.Canonicalizable;
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.extended.GuardingNode;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import org.graalvm.compiler.nodes.spi.ValueProxy;
import org.graalvm.compiler.nodes.spi.Virtualizable;
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import jdk.vm.ci.meta.JavaKind;
@NodeInfo(cycles = CYCLES_0, size = SIZE_0)
public final class GuardedValueNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Canonicalizable, ValueProxy {
public static final NodeClass<GuardedValueNode> TYPE = NodeClass.create(GuardedValueNode.class);
@Input ValueNode object;
public GuardedValueNode(ValueNode object, GuardingNode guard) {
super(TYPE, object.stamp(NodeView.DEFAULT), guard);
this.object = object;
}
public static ValueNode create(ValueNode object, GuardingNode guard) {
if (guard == null) {
return object;
}
return new GuardedValueNode(object, guard);
}
public ValueNode object() {
return object;
}
@Override
public void generate(NodeLIRBuilderTool generator) {
if (object.getStackKind() != JavaKind.Void && object.getStackKind() != JavaKind.Illegal) {
generator.setResult(this, generator.operand(object));
}
}
@Override
public boolean inferStamp() {
return updateStamp(object().stamp(NodeView.DEFAULT));
}
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode alias = tool.getAlias(object());
if (alias instanceof VirtualObjectNode) {
tool.replaceWithVirtual((VirtualObjectNode) alias);
}
}
@Override
public Node canonical(CanonicalizerTool tool) {
if (guard == null) {
if (stamp(NodeView.DEFAULT).equals(object().stamp(NodeView.DEFAULT))) {
return object();
} else {
return PiNode.create(object(), stamp(NodeView.DEFAULT));
}
}
return this;
}
@Override
public ValueNode getOriginalNode() {
return object;
}
}