# HG changeset patch # User Lukas Stadler # Date 1359645161 -3600 # Node ID e3e8090cb46acbef17bc095c0279c1974c28996f # Parent 3a8b3b03ffa0c50b21a7d8054131351c355b89ca remove unused allocations during (full) canonicalization diff -r 3a8b3b03ffa0 -r e3e8090cb46a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Thu Jan 31 15:23:31 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Thu Jan 31 16:12:41 2013 +0100 @@ -31,7 +31,7 @@ /** * The {@code NewArrayNode} class is the base of all instructions that allocate arrays. */ -public abstract class NewArrayNode extends FixedWithNextNode implements Lowerable, VirtualizableAllocation, ArrayLengthProvider { +public abstract class NewArrayNode extends FixedWithNextNode implements Canonicalizable, Lowerable, VirtualizableAllocation, ArrayLengthProvider { @Input private ValueNode length; private final ResolvedJavaType elementType; @@ -100,6 +100,15 @@ } @Override + public ValueNode canonical(CanonicalizerTool tool) { + if (usages().isEmpty() && length.integerStamp().isPositive()) { + return null; + } else { + return this; + } + } + + @Override public void lower(LoweringTool tool) { tool.getRuntime().lower(this, tool); } diff -r 3a8b3b03ffa0 -r e3e8090cb46a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java Thu Jan 31 15:23:31 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewInstanceNode.java Thu Jan 31 16:12:41 2013 +0100 @@ -33,7 +33,7 @@ * The {@code NewInstanceNode} represents the allocation of an instance class object. */ @NodeInfo(nameTemplate = "New {p#instanceClass/s}") -public final class NewInstanceNode extends FixedWithNextNode implements VirtualizableAllocation, Lowerable, Node.IterableNodeType { +public final class NewInstanceNode extends FixedWithNextNode implements Node.IterableNodeType, Canonicalizable, Lowerable, VirtualizableAllocation { private final ResolvedJavaType instanceClass; private final boolean fillContents; @@ -78,6 +78,15 @@ } @Override + public ValueNode canonical(CanonicalizerTool tool) { + if (usages().isEmpty()) { + return null; + } else { + return this; + } + } + + @Override public void lower(LoweringTool tool) { tool.getRuntime().lower(this, tool); }