1 /* 2 * Copyright (c) 2014, 2014, 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 package org.graalvm.compiler.nodes.calc; 24 25 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_1; 26 27 import org.graalvm.compiler.core.common.type.Stamp; 28 import org.graalvm.compiler.graph.NodeClass; 29 import org.graalvm.compiler.graph.spi.Canonicalizable; 30 import org.graalvm.compiler.nodeinfo.NodeInfo; 31 import org.graalvm.compiler.nodes.ValueNode; 32 33 /** 34 * The {@code UnaryNode} class is the base of arithmetic and bit logic operations with exactly one 35 * input. 36 */ 37 @NodeInfo(size = SIZE_1) 38 public abstract class UnaryNode extends FloatingNode implements Canonicalizable.Unary<ValueNode> { 39 40 public static final NodeClass<UnaryNode> TYPE = NodeClass.create(UnaryNode.class); 41 @Input protected ValueNode value; 42 43 @Override 44 public ValueNode getValue() { 45 return value; 46 } 47 48 /** 49 * Creates a new UnaryNode instance. 50 * 51 * @param stamp the result type of this instruction 52 * @param value the input instruction 53 */ 54 protected UnaryNode(NodeClass<? extends UnaryNode> c, Stamp stamp, ValueNode value) { 55 super(c, stamp); 56 this.value = value; 57 } 58 59 @Override 60 public boolean inferStamp() { 61 return updateStamp(foldStamp(value.stamp())); 62 } 63 64 /** 65 * Compute an improved for this node using the passed in stamp. The stamp must be compatible 66 * with the current value of {@link #value}. This code is used to provide the default 67 * implementation of {@link #inferStamp()} and may be used by external optimizations. 68 * 69 * @param newStamp 70 */ 71 public Stamp foldStamp(Stamp newStamp) { 72 return stamp(); 73 } 74 }