< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/ValueNode.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2009, 2018, 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 java.util.function.Predicate;
  28 
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.graph.Node;
  31 import org.graalvm.compiler.graph.NodeClass;
  32 import org.graalvm.compiler.graph.iterators.NodePredicate;
  33 import org.graalvm.compiler.nodeinfo.InputType;
  34 import org.graalvm.compiler.nodeinfo.NodeInfo;
  35 import org.graalvm.compiler.nodeinfo.Verbosity;
  36 import org.graalvm.compiler.nodes.spi.NodeValueMap;
  37 
  38 import jdk.vm.ci.meta.Constant;
  39 import jdk.vm.ci.meta.JavaConstant;
  40 import jdk.vm.ci.meta.JavaKind;

  41 
  42 /**
  43  * This class represents a value within the graph, including local variables, phis, and all other
  44  * instructions.
  45  */
  46 @NodeInfo
  47 public abstract class ValueNode extends org.graalvm.compiler.graph.Node implements ValueNodeInterface {
  48 
  49     public static final NodeClass<ValueNode> TYPE = NodeClass.create(ValueNode.class);
  50     /**
  51      * The kind of this value. This is {@link JavaKind#Void} for instructions that produce no value.
  52      * This kind is guaranteed to be a {@linkplain JavaKind#getStackKind() stack kind}.
  53      */
  54     protected Stamp stamp;
  55 
  56     public ValueNode(NodeClass<? extends ValueNode> c, Stamp stamp) {
  57         super(c);
  58         this.stamp = stamp;
  59     }
  60 


 144      *
 145      * @return the {@link JavaConstant} represented by this value if it is a constant; {@code null}
 146      *         otherwise
 147      */
 148     public final Constant asConstant() {
 149         if (this instanceof ConstantNode) {
 150             return ((ConstantNode) this).getValue();
 151         } else {
 152             return null;
 153         }
 154     }
 155 
 156     public final boolean isJavaConstant() {
 157         return isConstant() && asConstant() instanceof JavaConstant;
 158     }
 159 
 160     public final JavaConstant asJavaConstant() {
 161         Constant value = asConstant();
 162         if (value instanceof JavaConstant) {
 163             return (JavaConstant) value;













 164         } else {
 165             return null;
 166         }
 167     }
 168 
 169     @Override
 170     public ValueNode asNode() {
 171         return this;
 172     }
 173 
 174     @Override
 175     public boolean isAllowedUsageType(InputType type) {
 176         if (getStackKind() != JavaKind.Void && type == InputType.Value) {
 177             return true;
 178         } else {
 179             return super.isAllowedUsageType(type);
 180         }
 181     }
 182 
 183     /**


   1 /*
   2  * Copyright (c) 2009, 2019, 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 java.util.function.Predicate;
  28 
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.graph.Node;
  31 import org.graalvm.compiler.graph.NodeClass;
  32 import org.graalvm.compiler.graph.iterators.NodePredicate;
  33 import org.graalvm.compiler.nodeinfo.InputType;
  34 import org.graalvm.compiler.nodeinfo.NodeInfo;
  35 import org.graalvm.compiler.nodeinfo.Verbosity;
  36 import org.graalvm.compiler.nodes.spi.NodeValueMap;
  37 
  38 import jdk.vm.ci.meta.Constant;
  39 import jdk.vm.ci.meta.JavaConstant;
  40 import jdk.vm.ci.meta.JavaKind;
  41 import jdk.vm.ci.meta.SerializableConstant;
  42 
  43 /**
  44  * This class represents a value within the graph, including local variables, phis, and all other
  45  * instructions.
  46  */
  47 @NodeInfo
  48 public abstract class ValueNode extends org.graalvm.compiler.graph.Node implements ValueNodeInterface {
  49 
  50     public static final NodeClass<ValueNode> TYPE = NodeClass.create(ValueNode.class);
  51     /**
  52      * The kind of this value. This is {@link JavaKind#Void} for instructions that produce no value.
  53      * This kind is guaranteed to be a {@linkplain JavaKind#getStackKind() stack kind}.
  54      */
  55     protected Stamp stamp;
  56 
  57     public ValueNode(NodeClass<? extends ValueNode> c, Stamp stamp) {
  58         super(c);
  59         this.stamp = stamp;
  60     }
  61 


 145      *
 146      * @return the {@link JavaConstant} represented by this value if it is a constant; {@code null}
 147      *         otherwise
 148      */
 149     public final Constant asConstant() {
 150         if (this instanceof ConstantNode) {
 151             return ((ConstantNode) this).getValue();
 152         } else {
 153             return null;
 154         }
 155     }
 156 
 157     public final boolean isJavaConstant() {
 158         return isConstant() && asConstant() instanceof JavaConstant;
 159     }
 160 
 161     public final JavaConstant asJavaConstant() {
 162         Constant value = asConstant();
 163         if (value instanceof JavaConstant) {
 164             return (JavaConstant) value;
 165         } else {
 166             return null;
 167         }
 168     }
 169 
 170     public final boolean isSerializableConstant() {
 171         return isConstant() && asConstant() instanceof SerializableConstant;
 172     }
 173 
 174     public final SerializableConstant asSerializableConstant() {
 175         Constant value = asConstant();
 176         if (value instanceof SerializableConstant) {
 177             return (SerializableConstant) value;
 178         } else {
 179             return null;
 180         }
 181     }
 182 
 183     @Override
 184     public ValueNode asNode() {
 185         return this;
 186     }
 187 
 188     @Override
 189     public boolean isAllowedUsageType(InputType type) {
 190         if (getStackKind() != JavaKind.Void && type == InputType.Value) {
 191             return true;
 192         } else {
 193             return super.isAllowedUsageType(type);
 194         }
 195     }
 196 
 197     /**


< prev index next >