1 /* 2 * Copyright (c) 2013, 2015, 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.nodes; 26 27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_0; 28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_0; 29 30 import org.graalvm.compiler.graph.Node; 31 import org.graalvm.compiler.graph.NodeClass; 32 import org.graalvm.compiler.graph.spi.Canonicalizable; 33 import org.graalvm.compiler.graph.spi.CanonicalizerTool; 34 import org.graalvm.compiler.nodeinfo.NodeInfo; 35 import org.graalvm.compiler.nodes.extended.GuardingNode; 36 import org.graalvm.compiler.nodes.spi.LIRLowerable; 37 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 38 import org.graalvm.compiler.nodes.spi.ValueProxy; 39 import org.graalvm.compiler.nodes.spi.Virtualizable; 40 import org.graalvm.compiler.nodes.spi.VirtualizerTool; 41 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; 42 43 import jdk.vm.ci.meta.JavaKind; 44 45 /** 46 * A node that changes the type of its input, usually narrowing it. For example, a GuardedValueNode 47 * is used to keep the nodes depending on guards inside a loop during speculative guard movement. 48 * 49 * A GuardedValueNode will only go away if its guard is null or {@link StructuredGraph#start()}. 50 */ 51 @NodeInfo(cycles = CYCLES_0, size = SIZE_0) 52 public final class GuardedValueNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Canonicalizable, ValueProxy { 53 54 public static final NodeClass<GuardedValueNode> TYPE = NodeClass.create(GuardedValueNode.class); 55 @Input ValueNode object; 56 GuardedValueNode(ValueNode object, GuardingNode guard)57 public GuardedValueNode(ValueNode object, GuardingNode guard) { 58 super(TYPE, object.stamp(NodeView.DEFAULT), guard); 59 this.object = object; 60 } 61 object()62 public ValueNode object() { 63 return object; 64 } 65 66 @Override generate(NodeLIRBuilderTool generator)67 public void generate(NodeLIRBuilderTool generator) { 68 if (object.getStackKind() != JavaKind.Void && object.getStackKind() != JavaKind.Illegal) { 69 generator.setResult(this, generator.operand(object)); 70 } 71 } 72 73 @Override inferStamp()74 public boolean inferStamp() { 75 return updateStamp(object().stamp(NodeView.DEFAULT)); 76 } 77 78 @Override virtualize(VirtualizerTool tool)79 public void virtualize(VirtualizerTool tool) { 80 ValueNode alias = tool.getAlias(object()); 81 if (alias instanceof VirtualObjectNode) { 82 tool.replaceWithVirtual((VirtualObjectNode) alias); 83 } 84 } 85 86 @Override canonical(CanonicalizerTool tool)87 public Node canonical(CanonicalizerTool tool) { 88 if (getGuard() == null) { 89 if (stamp(NodeView.DEFAULT).equals(object().stamp(NodeView.DEFAULT))) { 90 return object(); 91 } else { 92 return PiNode.create(object(), stamp(NodeView.DEFAULT)); 93 } 94 } 95 return this; 96 } 97 98 @Override getOriginalNode()99 public ValueNode getOriginalNode() { 100 return object; 101 } 102 } 103