Mercurial > hg > truffle
diff graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnboxNode.java @ 19241:30c8d110b281
More Truffle graph builder plugins and parse time canonicalizations.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 10 Feb 2015 20:43:48 +0100 |
parents | f57d86eb036f |
children | 7e2c87dae93e |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnboxNode.java Tue Feb 10 15:10:56 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnboxNode.java Tue Feb 10 20:43:48 2015 +0100 @@ -31,15 +31,23 @@ import com.oracle.graal.nodes.spi.*; @NodeInfo -public class UnboxNode extends UnaryNode implements Virtualizable, Lowerable { +public final class UnboxNode extends UnaryNode implements Virtualizable, Lowerable { protected final Kind boxingKind; - public UnboxNode(ValueNode value, Kind boxingKind) { + protected UnboxNode(ValueNode value, Kind boxingKind) { super(StampFactory.forKind(boxingKind.getStackKind()), value); this.boxingKind = boxingKind; } + public static ValueNode create(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, ValueNode value, Kind boxingKind) { + ValueNode synonym = findSynonym(metaAccess, constantReflection, value, boxingKind); + if (synonym != null) { + return synonym; + } + return new UnboxNode(value, boxingKind); + } + public Kind getBoxingKind() { return boxingKind; } @@ -63,11 +71,19 @@ @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { + ValueNode synonym = findSynonym(tool.getMetaAccess(), tool.getConstantReflection(), forValue, boxingKind); + if (synonym != null) { + return synonym; + } + return this; + } + + private static ValueNode findSynonym(MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, ValueNode forValue, Kind boxingKind) { if (forValue.isConstant()) { JavaConstant constant = forValue.asJavaConstant(); - JavaConstant unboxed = tool.getConstantReflection().unboxPrimitive(constant); + JavaConstant unboxed = constantReflection.unboxPrimitive(constant); if (unboxed != null && unboxed.getKind() == boxingKind) { - return ConstantNode.forConstant(unboxed, tool.getMetaAccess()); + return ConstantNode.forConstant(unboxed, metaAccess); } } else if (forValue instanceof BoxNode) { BoxNode box = (BoxNode) forValue; @@ -75,7 +91,7 @@ return box.getValue(); } } - return this; + return null; } @NodeIntrinsic