< prev index next >

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

Print this page




  42 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  43 import org.graalvm.compiler.nodes.memory.ReadNode;
  44 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  45 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  46 import org.graalvm.compiler.nodes.spi.ValueProxy;
  47 import org.graalvm.compiler.nodes.spi.Virtualizable;
  48 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  49 import org.graalvm.compiler.nodes.type.StampTool;
  50 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  51 
  52 //JaCoCo Exclude
  53 
  54 import jdk.vm.ci.meta.ResolvedJavaType;
  55 
  56 /**
  57  * A node that changes the type of its input, usually narrowing it. For example, a {@link PiNode}
  58  * refines the type of a receiver during type-guarded inlining to be the type tested by the guard.
  59  *
  60  * In contrast to a {@link GuardedValueNode}, a {@link PiNode} is useless as soon as the type of its
  61  * input is as narrow or narrower than the {@link PiNode}'s type. The {@link PiNode}, and therefore
  62  * also the scheduling restriction enforced by the anchor, will go away.
  63  */
  64 @NodeInfo(cycles = CYCLES_0, size = SIZE_0)
  65 public class PiNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, IterableNodeType, Canonicalizable, ValueProxy {
  66 
  67     public static final NodeClass<PiNode> TYPE = NodeClass.create(PiNode.class);
  68     @Input ValueNode object;
  69     protected final Stamp piStamp;
  70 
  71     public ValueNode object() {
  72         return object;
  73     }
  74 
  75     protected PiNode(NodeClass<? extends PiNode> c, ValueNode object, Stamp stamp, GuardingNode guard) {
  76         super(c, stamp, guard);
  77         this.object = object;
  78         this.piStamp = stamp;
  79         assert piStamp.isCompatible(object.stamp()) : "Object stamp not compatible to piStamp";
  80         inferStamp();
  81     }
  82 
  83     public PiNode(ValueNode object, Stamp stamp) {
  84         this(object, stamp, null);
  85     }
  86 
  87     public PiNode(ValueNode object, Stamp stamp, ValueNode anchor) {
  88         this(TYPE, object, stamp, (GuardingNode) anchor);
  89     }
  90 
  91     public PiNode(ValueNode object, ValueNode anchor) {
  92         this(object, AbstractPointerStamp.pointerNonNull(object.stamp()), anchor);
  93     }
  94 
  95     public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
  96         this(object, StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType), nonNull || StampTool.isPointerNonNull(object.stamp())));
  97     }
  98 
  99     public static ValueNode create(ValueNode object, Stamp stamp) {
 100         ValueNode value = canonical(object, stamp, null);
 101         if (value != null) {
 102             return value;
 103         }
 104         return new PiNode(object, stamp);
 105     }
 106 
 107     public static ValueNode create(ValueNode object, Stamp stamp, ValueNode anchor) {
 108         ValueNode value = canonical(object, stamp, (GuardingNode) anchor);
 109         if (value != null) {
 110             return value;
 111         }
 112         return new PiNode(object, stamp, anchor);
 113     }
 114 
 115     public static ValueNode create(ValueNode object, ValueNode anchor) {
 116         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp());
 117         ValueNode value = canonical(object, stamp, (GuardingNode) anchor);
 118         if (value != null) {
 119             return value;
 120         }
 121         return new PiNode(object, stamp, anchor);
 122     }
 123 
 124     @SuppressWarnings("unused")
 125     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ValueNode anchor) {
 126         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp());
 127         ValueNode value = canonical(object, stamp, (GuardingNode) anchor);
 128         if (value == null) {
 129             value = new PiNode(object, stamp, anchor);
 130         }
 131         b.push(JavaKind.Object, b.append(value));
 132         return true;
 133     }
 134 
 135     @SuppressWarnings("unused")
 136     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
 137         Stamp stamp = StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType), nonNull || StampTool.isPointerNonNull(object.stamp()));
 138         ValueNode value = canonical(object, stamp, null);
 139         if (value == null) {
 140             value = new PiNode(object, stamp);
 141         }
 142         b.push(JavaKind.Object, b.append(value));
 143         return true;
 144     }
 145 
 146     public final Stamp piStamp() {
 147         return piStamp;
 148     }
 149 





 150     @Override
 151     public void generate(NodeLIRBuilderTool generator) {
 152         if (generator.hasOperand(object)) {
 153             generator.setResult(this, generator.operand(object));
 154         }
 155     }
 156 
 157     @Override
 158     public boolean inferStamp() {
 159         return updateStamp(computeStamp());
 160     }
 161 
 162     private Stamp computeStamp() {
 163         return piStamp.improveWith(object().stamp());
 164     }
 165 
 166     @Override
 167     public void virtualize(VirtualizerTool tool) {
 168         ValueNode alias = tool.getAlias(object());
 169         if (alias instanceof VirtualObjectNode) {


 239 
 240     /**
 241      * Casts an object to have an exact, non-null stamp representing {@link Class}.
 242      */
 243     public static Class<?> asNonNullObject(Object object) {
 244         return asNonNullClassIntrinsic(object, Object.class, false, true);
 245     }
 246 
 247     @NodeIntrinsic(PiNode.class)
 248     private static native Class<?> asNonNullClassIntrinsic(Object object, @ConstantNodeParameter Class<?> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull);
 249 
 250     /**
 251      * Changes the stamp of an object inside a snippet to be the stamp of the node replaced by the
 252      * snippet.
 253      */
 254     @NodeIntrinsic(PiNode.Placeholder.class)
 255     public static native Object piCastToSnippetReplaceeStamp(Object object);
 256 
 257     /**
 258      * Changes the stamp of an object and ensures the newly stamped value is non-null and does not
 259      * float above a given anchor.
 260      */
 261     @NodeIntrinsic
 262     public static native Object piCastNonNull(Object object, GuardingNode anchor);
 263 
 264     /**
 265      * Changes the stamp of an object and ensures the newly stamped value is non-null and does not
 266      * float above a given anchor.
 267      */
 268     @NodeIntrinsic
 269     public static native Class<?> piCastNonNullClass(Class<?> type, GuardingNode anchor);
 270 
 271     /**
 272      * Changes the stamp of an object to represent a given type and to indicate that the object is
 273      * not null.
 274      */
 275     public static Object piCastNonNull(Object object, @ConstantNodeParameter Class<?> toType) {
 276         return piCast(object, toType, false, true);
 277     }
 278 
 279     @NodeIntrinsic
 280     public static native Object piCast(Object object, @ConstantNodeParameter Class<?> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull);
 281 
 282     /**
 283      * A placeholder node in a snippet that will be replaced with a {@link PiNode} when the snippet
 284      * is instantiated.
 285      */
 286     @NodeInfo(cycles = CYCLES_0, size = SIZE_0)
 287     public static class Placeholder extends FloatingGuardedNode {
 288 
 289         public static final NodeClass<Placeholder> TYPE = NodeClass.create(Placeholder.class);




  42 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
  43 import org.graalvm.compiler.nodes.memory.ReadNode;
  44 import org.graalvm.compiler.nodes.spi.LIRLowerable;
  45 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  46 import org.graalvm.compiler.nodes.spi.ValueProxy;
  47 import org.graalvm.compiler.nodes.spi.Virtualizable;
  48 import org.graalvm.compiler.nodes.spi.VirtualizerTool;
  49 import org.graalvm.compiler.nodes.type.StampTool;
  50 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  51 
  52 //JaCoCo Exclude
  53 
  54 import jdk.vm.ci.meta.ResolvedJavaType;
  55 
  56 /**
  57  * A node that changes the type of its input, usually narrowing it. For example, a {@link PiNode}
  58  * refines the type of a receiver during type-guarded inlining to be the type tested by the guard.
  59  *
  60  * In contrast to a {@link GuardedValueNode}, a {@link PiNode} is useless as soon as the type of its
  61  * input is as narrow or narrower than the {@link PiNode}'s type. The {@link PiNode}, and therefore
  62  * also the scheduling restriction enforced by the guard, will go away.
  63  */
  64 @NodeInfo(cycles = CYCLES_0, size = SIZE_0)
  65 public class PiNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, IterableNodeType, Canonicalizable, ValueProxy {
  66 
  67     public static final NodeClass<PiNode> TYPE = NodeClass.create(PiNode.class);
  68     @Input ValueNode object;
  69     protected Stamp piStamp;
  70 
  71     public ValueNode object() {
  72         return object;
  73     }
  74 
  75     protected PiNode(NodeClass<? extends PiNode> c, ValueNode object, Stamp stamp, GuardingNode guard) {
  76         super(c, stamp, guard);
  77         this.object = object;
  78         this.piStamp = stamp;
  79         assert piStamp.isCompatible(object.stamp()) : "Object stamp not compatible to piStamp";
  80         inferStamp();
  81     }
  82 
  83     public PiNode(ValueNode object, Stamp stamp) {
  84         this(object, stamp, null);
  85     }
  86 
  87     public PiNode(ValueNode object, Stamp stamp, ValueNode guard) {
  88         this(TYPE, object, stamp, (GuardingNode) guard);
  89     }
  90 
  91     public PiNode(ValueNode object, ValueNode guard) {
  92         this(object, AbstractPointerStamp.pointerNonNull(object.stamp()), guard);
  93     }
  94 
  95     public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
  96         this(object, StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType), nonNull || StampTool.isPointerNonNull(object.stamp())));
  97     }
  98 
  99     public static ValueNode create(ValueNode object, Stamp stamp) {
 100         ValueNode value = canonical(object, stamp, null);
 101         if (value != null) {
 102             return value;
 103         }
 104         return new PiNode(object, stamp);
 105     }
 106 
 107     public static ValueNode create(ValueNode object, Stamp stamp, ValueNode guard) {
 108         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 109         if (value != null) {
 110             return value;
 111         }
 112         return new PiNode(object, stamp, guard);
 113     }
 114 
 115     public static ValueNode create(ValueNode object, ValueNode guard) {
 116         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp());
 117         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 118         if (value != null) {
 119             return value;
 120         }
 121         return new PiNode(object, stamp, guard);
 122     }
 123 
 124     @SuppressWarnings("unused")
 125     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ValueNode guard) {
 126         Stamp stamp = AbstractPointerStamp.pointerNonNull(object.stamp());
 127         ValueNode value = canonical(object, stamp, (GuardingNode) guard);
 128         if (value == null) {
 129             value = new PiNode(object, stamp, guard);
 130         }
 131         b.push(JavaKind.Object, b.append(value));
 132         return true;
 133     }
 134 
 135     @SuppressWarnings("unused")
 136     public static boolean intrinsify(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
 137         Stamp stamp = StampFactory.object(exactType ? TypeReference.createExactTrusted(toType) : TypeReference.createWithoutAssumptions(toType), nonNull || StampTool.isPointerNonNull(object.stamp()));
 138         ValueNode value = canonical(object, stamp, null);
 139         if (value == null) {
 140             value = new PiNode(object, stamp);
 141         }
 142         b.push(JavaKind.Object, b.append(value));
 143         return true;
 144     }
 145 
 146     public final Stamp piStamp() {
 147         return piStamp;
 148     }
 149 
 150     public void strengthenPiStamp(Stamp newPiStamp) {
 151         assert this.piStamp.join(newPiStamp).equals(newPiStamp) : "stamp can only improve";
 152         this.piStamp = newPiStamp;
 153     }
 154 
 155     @Override
 156     public void generate(NodeLIRBuilderTool generator) {
 157         if (generator.hasOperand(object)) {
 158             generator.setResult(this, generator.operand(object));
 159         }
 160     }
 161 
 162     @Override
 163     public boolean inferStamp() {
 164         return updateStamp(computeStamp());
 165     }
 166 
 167     private Stamp computeStamp() {
 168         return piStamp.improveWith(object().stamp());
 169     }
 170 
 171     @Override
 172     public void virtualize(VirtualizerTool tool) {
 173         ValueNode alias = tool.getAlias(object());
 174         if (alias instanceof VirtualObjectNode) {


 244 
 245     /**
 246      * Casts an object to have an exact, non-null stamp representing {@link Class}.
 247      */
 248     public static Class<?> asNonNullObject(Object object) {
 249         return asNonNullClassIntrinsic(object, Object.class, false, true);
 250     }
 251 
 252     @NodeIntrinsic(PiNode.class)
 253     private static native Class<?> asNonNullClassIntrinsic(Object object, @ConstantNodeParameter Class<?> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull);
 254 
 255     /**
 256      * Changes the stamp of an object inside a snippet to be the stamp of the node replaced by the
 257      * snippet.
 258      */
 259     @NodeIntrinsic(PiNode.Placeholder.class)
 260     public static native Object piCastToSnippetReplaceeStamp(Object object);
 261 
 262     /**
 263      * Changes the stamp of an object and ensures the newly stamped value is non-null and does not
 264      * float above a given guard.
 265      */
 266     @NodeIntrinsic
 267     public static native Object piCastNonNull(Object object, GuardingNode guard);
 268 
 269     /**
 270      * Changes the stamp of an object and ensures the newly stamped value is non-null and does not
 271      * float above a given guard.
 272      */
 273     @NodeIntrinsic
 274     public static native Class<?> piCastNonNullClass(Class<?> type, GuardingNode guard);
 275 
 276     /**
 277      * Changes the stamp of an object to represent a given type and to indicate that the object is
 278      * not null.
 279      */
 280     public static Object piCastNonNull(Object object, @ConstantNodeParameter Class<?> toType) {
 281         return piCast(object, toType, false, true);
 282     }
 283 
 284     @NodeIntrinsic
 285     public static native Object piCast(Object object, @ConstantNodeParameter Class<?> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull);
 286 
 287     /**
 288      * A placeholder node in a snippet that will be replaced with a {@link PiNode} when the snippet
 289      * is instantiated.
 290      */
 291     @NodeInfo(cycles = CYCLES_0, size = SIZE_0)
 292     public static class Placeholder extends FloatingGuardedNode {
 293 
 294         public static final NodeClass<Placeholder> TYPE = NodeClass.create(Placeholder.class);


< prev index next >