< prev index next >

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

Print this page




  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.calc;
  26 
  27 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
  28 import org.graalvm.compiler.core.common.type.ObjectStamp;
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.graph.NodeClass;
  31 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  32 import org.graalvm.compiler.nodeinfo.NodeCycles;
  33 import org.graalvm.compiler.nodeinfo.NodeInfo;
  34 import org.graalvm.compiler.nodes.CompressionNode;
  35 import org.graalvm.compiler.nodes.LogicConstantNode;
  36 import org.graalvm.compiler.nodes.LogicNode;
  37 import org.graalvm.compiler.nodes.NodeView;
  38 import org.graalvm.compiler.nodes.PiNode;
  39 import org.graalvm.compiler.nodes.UnaryOpLogicNode;
  40 import org.graalvm.compiler.nodes.ValueNode;
  41 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  42 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  43 import org.graalvm.compiler.nodes.spi.Virtualizable;
  44 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  45 import org.graalvm.compiler.nodes.type.StampTool;
  46 import org.graalvm.compiler.nodes.util.GraphUtil;
  47 
  48 import jdk.vm.ci.meta.JavaConstant;
  49 import jdk.vm.ci.meta.TriState;
  50 
  51 /**
  52  * An IsNullNode will be true if the supplied value is null, and false if it is non-null.
  53  */
  54 @NodeInfo(cycles = NodeCycles.CYCLES_2)
  55 public final class IsNullNode extends UnaryOpLogicNode implements LIRLowerable, Virtualizable {
  56 
  57     public static final NodeClass<IsNullNode> TYPE = NodeClass.create(IsNullNode.class);
  58 
  59     /*
  60      * When linear pointer compression is enabled, compressed and uncompressed nulls differ.
  61      */
  62     private final JavaConstant nullConstant;
  63 
  64     private IsNullNode(ValueNode object, JavaConstant nullConstant) {
  65         super(TYPE, object);
  66         this.nullConstant = nullConstant;


  87     @Override
  88     public boolean verify() {
  89         assertTrue(getValue() != null, "is null input must not be null");
  90         assertTrue(getValue().stamp(NodeView.DEFAULT) instanceof AbstractPointerStamp, "input must be a pointer not %s", getValue().stamp(NodeView.DEFAULT));
  91         return super.verify();
  92     }
  93 
  94     @Override
  95     public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
  96         return canonicalized(this, forValue, nullConstant);
  97     }
  98 
  99     private static LogicNode canonicalized(IsNullNode node, ValueNode forValue, JavaConstant forNullConstant) {
 100         JavaConstant nullConstant = forNullConstant;
 101         ValueNode value = forValue;
 102         while (true) {
 103             if (StampTool.isPointerAlwaysNull(value)) {
 104                 return LogicConstantNode.tautology();
 105             } else if (StampTool.isPointerNonNull(value)) {
 106                 return LogicConstantNode.contradiction();
 107             }
 108 
 109             if (value instanceof PiNode) {
 110                 value = GraphUtil.skipPi(value);
 111                 continue;
 112             }
 113 
 114             if (value instanceof ConvertNode) {
 115                 ConvertNode convertNode = (ConvertNode) value;
 116                 if (convertNode.mayNullCheckSkipConversion()) {
 117                     value = convertNode.getValue();
 118                     continue;
 119                 }
 120                 /*
 121                  * CompressionNode.mayNullCheckSkipConversion returns false when linear pointer
 122                  * compression is enabled.
 123                  */
 124                 if (value instanceof CompressionNode) {
 125                     CompressionNode compressionNode = (CompressionNode) value;
 126                     nullConstant = compressionNode.nullConstant();
 127                     value = compressionNode.getValue();
 128                     continue;
 129                 }
 130             }
 131             /*




  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.calc;
  26 
  27 import org.graalvm.compiler.core.common.type.AbstractPointerStamp;
  28 import org.graalvm.compiler.core.common.type.ObjectStamp;
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.graph.NodeClass;
  31 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  32 import org.graalvm.compiler.nodeinfo.NodeCycles;
  33 import org.graalvm.compiler.nodeinfo.NodeInfo;
  34 import org.graalvm.compiler.nodes.CompressionNode;
  35 import org.graalvm.compiler.nodes.LogicConstantNode;
  36 import org.graalvm.compiler.nodes.LogicNode;
  37 import org.graalvm.compiler.nodes.NodeView;

  38 import org.graalvm.compiler.nodes.UnaryOpLogicNode;
  39 import org.graalvm.compiler.nodes.ValueNode;
  40 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  41 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  42 import org.graalvm.compiler.nodes.spi.Virtualizable;
  43 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  44 import org.graalvm.compiler.nodes.type.StampTool;

  45 
  46 import jdk.vm.ci.meta.JavaConstant;
  47 import jdk.vm.ci.meta.TriState;
  48 
  49 /**
  50  * An IsNullNode will be true if the supplied value is null, and false if it is non-null.
  51  */
  52 @NodeInfo(cycles = NodeCycles.CYCLES_2)
  53 public final class IsNullNode extends UnaryOpLogicNode implements LIRLowerable, Virtualizable {
  54 
  55     public static final NodeClass<IsNullNode> TYPE = NodeClass.create(IsNullNode.class);
  56 
  57     /*
  58      * When linear pointer compression is enabled, compressed and uncompressed nulls differ.
  59      */
  60     private final JavaConstant nullConstant;
  61 
  62     private IsNullNode(ValueNode object, JavaConstant nullConstant) {
  63         super(TYPE, object);
  64         this.nullConstant = nullConstant;


  85     @Override
  86     public boolean verify() {
  87         assertTrue(getValue() != null, "is null input must not be null");
  88         assertTrue(getValue().stamp(NodeView.DEFAULT) instanceof AbstractPointerStamp, "input must be a pointer not %s", getValue().stamp(NodeView.DEFAULT));
  89         return super.verify();
  90     }
  91 
  92     @Override
  93     public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
  94         return canonicalized(this, forValue, nullConstant);
  95     }
  96 
  97     private static LogicNode canonicalized(IsNullNode node, ValueNode forValue, JavaConstant forNullConstant) {
  98         JavaConstant nullConstant = forNullConstant;
  99         ValueNode value = forValue;
 100         while (true) {
 101             if (StampTool.isPointerAlwaysNull(value)) {
 102                 return LogicConstantNode.tautology();
 103             } else if (StampTool.isPointerNonNull(value)) {
 104                 return LogicConstantNode.contradiction();





 105             }
 106 
 107             if (value instanceof ConvertNode) {
 108                 ConvertNode convertNode = (ConvertNode) value;
 109                 if (convertNode.mayNullCheckSkipConversion()) {
 110                     value = convertNode.getValue();
 111                     continue;
 112                 }
 113                 /*
 114                  * CompressionNode.mayNullCheckSkipConversion returns false when linear pointer
 115                  * compression is enabled.
 116                  */
 117                 if (value instanceof CompressionNode) {
 118                     CompressionNode compressionNode = (CompressionNode) value;
 119                     nullConstant = compressionNode.nullConstant();
 120                     value = compressionNode.getValue();
 121                     continue;
 122                 }
 123             }
 124             /*


< prev index next >