37 import org.graalvm.compiler.core.common.type.StampFactory;
38 import org.graalvm.compiler.debug.GraalError;
39 import org.graalvm.compiler.graph.Node;
40 import org.graalvm.compiler.graph.NodeClass;
41 import org.graalvm.compiler.graph.iterators.NodeIterable;
42 import org.graalvm.compiler.lir.ConstantValue;
43 import org.graalvm.compiler.nodeinfo.NodeInfo;
44 import org.graalvm.compiler.nodeinfo.Verbosity;
45 import org.graalvm.compiler.nodes.calc.FloatingNode;
46 import org.graalvm.compiler.nodes.spi.ArrayLengthProvider;
47 import org.graalvm.compiler.nodes.spi.LIRLowerable;
48 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
49
50 import jdk.vm.ci.code.CodeUtil;
51 import jdk.vm.ci.meta.Constant;
52 import jdk.vm.ci.meta.ConstantReflectionProvider;
53 import jdk.vm.ci.meta.JavaConstant;
54 import jdk.vm.ci.meta.JavaKind;
55 import jdk.vm.ci.meta.MetaAccessProvider;
56 import jdk.vm.ci.meta.PrimitiveConstant;
57
58 /**
59 * The {@code ConstantNode} represents a {@link Constant constant}.
60 */
61 @NodeInfo(nameTemplate = "C({p#rawvalue}) {p#stampKind}", cycles = CYCLES_0, size = SIZE_1)
62 public final class ConstantNode extends FloatingNode implements LIRLowerable, ArrayLengthProvider {
63
64 public static final NodeClass<ConstantNode> TYPE = NodeClass.create(ConstantNode.class);
65
66 protected final Constant value;
67
68 private final int stableDimension;
69 private final boolean isDefaultStable;
70
71 private static ConstantNode createPrimitive(JavaConstant value) {
72 assert value.getJavaKind() != JavaKind.Object;
73 return new ConstantNode(value, StampFactory.forConstant(value));
74 }
75
76 /**
82 this(value, stamp, 0, false);
83 }
84
85 private ConstantNode(Constant value, Stamp stamp, int stableDimension, boolean isDefaultStable) {
86 super(TYPE, stamp);
87 assert stamp != null && stamp.isCompatible(value) : stamp + " " + value;
88 this.value = value;
89 this.stableDimension = stableDimension;
90 if (stableDimension == 0) {
91 /*
92 * Ensure that isDefaultStable has a canonical value to avoid having two constant nodes
93 * that only differ in this field. The value of isDefaultStable is only used when we
94 * have a stable array dimension.
95 */
96 this.isDefaultStable = false;
97 } else {
98 this.isDefaultStable = isDefaultStable;
99 }
100 }
101
102 /**
103 * @return the constant value represented by this node
104 */
105 public Constant getValue() {
106 return value;
107 }
108
109 /**
110 * @return the number of stable dimensions if this is a stable array, otherwise 0
111 */
112 public int getStableDimension() {
113 return stableDimension;
114 }
115
116 /**
117 * @return true if this is a stable array and the default elements are considered stable
118 */
119 public boolean isDefaultStable() {
120 return isDefaultStable;
121 }
529 @Override
530 public String toString(Verbosity verbosity) {
531 if (verbosity == Verbosity.Name) {
532 return super.toString(Verbosity.Name) + "(" + value.toValueString() + ", " + stamp(NodeView.DEFAULT).unrestricted().toString() + ")";
533 } else {
534 return super.toString(verbosity);
535 }
536 }
537
538 @Override
539 public ValueNode findLength(FindLengthMode mode, ConstantReflectionProvider constantReflection) {
540 if (constantReflection == null || !(value instanceof JavaConstant) || ((JavaConstant) value).isNull()) {
541 return null;
542 }
543 Integer length = constantReflection.readArrayLength((JavaConstant) value);
544 if (length == null) {
545 return null;
546 }
547 return ConstantNode.forInt(length);
548 }
549 }
|
37 import org.graalvm.compiler.core.common.type.StampFactory;
38 import org.graalvm.compiler.debug.GraalError;
39 import org.graalvm.compiler.graph.Node;
40 import org.graalvm.compiler.graph.NodeClass;
41 import org.graalvm.compiler.graph.iterators.NodeIterable;
42 import org.graalvm.compiler.lir.ConstantValue;
43 import org.graalvm.compiler.nodeinfo.NodeInfo;
44 import org.graalvm.compiler.nodeinfo.Verbosity;
45 import org.graalvm.compiler.nodes.calc.FloatingNode;
46 import org.graalvm.compiler.nodes.spi.ArrayLengthProvider;
47 import org.graalvm.compiler.nodes.spi.LIRLowerable;
48 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
49
50 import jdk.vm.ci.code.CodeUtil;
51 import jdk.vm.ci.meta.Constant;
52 import jdk.vm.ci.meta.ConstantReflectionProvider;
53 import jdk.vm.ci.meta.JavaConstant;
54 import jdk.vm.ci.meta.JavaKind;
55 import jdk.vm.ci.meta.MetaAccessProvider;
56 import jdk.vm.ci.meta.PrimitiveConstant;
57 import jdk.vm.ci.meta.ResolvedJavaType;
58
59 /**
60 * The {@code ConstantNode} represents a {@link Constant constant}.
61 */
62 @NodeInfo(nameTemplate = "C({p#rawvalue}) {p#stampKind}", cycles = CYCLES_0, size = SIZE_1)
63 public final class ConstantNode extends FloatingNode implements LIRLowerable, ArrayLengthProvider {
64
65 public static final NodeClass<ConstantNode> TYPE = NodeClass.create(ConstantNode.class);
66
67 protected final Constant value;
68
69 private final int stableDimension;
70 private final boolean isDefaultStable;
71
72 private static ConstantNode createPrimitive(JavaConstant value) {
73 assert value.getJavaKind() != JavaKind.Object;
74 return new ConstantNode(value, StampFactory.forConstant(value));
75 }
76
77 /**
83 this(value, stamp, 0, false);
84 }
85
86 private ConstantNode(Constant value, Stamp stamp, int stableDimension, boolean isDefaultStable) {
87 super(TYPE, stamp);
88 assert stamp != null && stamp.isCompatible(value) : stamp + " " + value;
89 this.value = value;
90 this.stableDimension = stableDimension;
91 if (stableDimension == 0) {
92 /*
93 * Ensure that isDefaultStable has a canonical value to avoid having two constant nodes
94 * that only differ in this field. The value of isDefaultStable is only used when we
95 * have a stable array dimension.
96 */
97 this.isDefaultStable = false;
98 } else {
99 this.isDefaultStable = isDefaultStable;
100 }
101 }
102
103 public ConstantNode(@InjectedNodeParameter Stamp stamp, @InjectedNodeParameter ConstantReflectionProvider constantReflection, @ConstantNodeParameter ResolvedJavaType type) {
104 this(constantReflection.asJavaClass(type), stamp);
105 }
106
107 /**
108 * @return the constant value represented by this node
109 */
110 public Constant getValue() {
111 return value;
112 }
113
114 /**
115 * @return the number of stable dimensions if this is a stable array, otherwise 0
116 */
117 public int getStableDimension() {
118 return stableDimension;
119 }
120
121 /**
122 * @return true if this is a stable array and the default elements are considered stable
123 */
124 public boolean isDefaultStable() {
125 return isDefaultStable;
126 }
534 @Override
535 public String toString(Verbosity verbosity) {
536 if (verbosity == Verbosity.Name) {
537 return super.toString(Verbosity.Name) + "(" + value.toValueString() + ", " + stamp(NodeView.DEFAULT).unrestricted().toString() + ")";
538 } else {
539 return super.toString(verbosity);
540 }
541 }
542
543 @Override
544 public ValueNode findLength(FindLengthMode mode, ConstantReflectionProvider constantReflection) {
545 if (constantReflection == null || !(value instanceof JavaConstant) || ((JavaConstant) value).isNull()) {
546 return null;
547 }
548 Integer length = constantReflection.readArrayLength((JavaConstant) value);
549 if (length == null) {
550 return null;
551 }
552 return ConstantNode.forInt(length);
553 }
554
555 @NodeIntrinsic
556 public static native Class<?> forClass(@ConstantNodeParameter ResolvedJavaType type);
557 }
|