# HG changeset patch # User Lukas Stadler # Date 1403688053 -7200 # Node ID a15b2562667228b8368c61ac75b8a8e08d8a2c31 # Parent 6beb6da182fcdecfe4f77d04f858c78360d8f0d0 implement Canonicalizable.Unary in the UnaryOpLogicNode hierarchy diff -r 6beb6da182fc -r a15b25626672 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/UnaryOpLogicNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/UnaryOpLogicNode.java Wed Jun 25 11:20:53 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/UnaryOpLogicNode.java Wed Jun 25 11:20:53 2014 +0200 @@ -22,10 +22,10 @@ */ package com.oracle.graal.nodes; -import com.oracle.graal.api.meta.ProfilingInfo.TriState; +import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.spi.*; -public abstract class UnaryOpLogicNode extends LogicNode implements LIRLowerable { +public abstract class UnaryOpLogicNode extends LogicNode implements LIRLowerable, Canonicalizable.Unary { @Input private ValueNode value; @@ -38,8 +38,6 @@ this.value = value; } - public abstract TriState evaluate(ValueNode forObject); - @Override public void generate(NodeLIRBuilderTool gen) { } diff -r 6beb6da182fc -r a15b25626672 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java Wed Jun 25 11:20:53 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java Wed Jun 25 11:20:53 2014 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,9 +23,7 @@ package com.oracle.graal.nodes.calc; import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.meta.ProfilingInfo.TriState; import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; @@ -34,7 +32,7 @@ /** * An IsNullNode will be true if the supplied value is null, and false if it is non-null. */ -public final class IsNullNode extends UnaryOpLogicNode implements Canonicalizable, LIRLowerable, Virtualizable, PiPushable { +public final class IsNullNode extends UnaryOpLogicNode implements LIRLowerable, Virtualizable, PiPushable { /** * Constructs a new IsNullNode instruction. @@ -58,30 +56,19 @@ } @Override - public Node canonical(CanonicalizerTool tool) { - switch (evaluate(getValue())) { - case FALSE: - return LogicConstantNode.contradiction(graph()); - case TRUE: - return LogicConstantNode.tautology(graph()); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { + Constant constant = forValue.asConstant(); + if (constant != null) { + assert constant.getKind() == Kind.Object; + return LogicConstantNode.forBoolean(constant.isNull()); + } + if (StampTool.isObjectNonNull(forValue.stamp())) { + return LogicConstantNode.contradiction(); } return this; } @Override - public TriState evaluate(ValueNode forObject) { - Constant constant = forObject.asConstant(); - if (constant != null) { - assert constant.getKind() == Kind.Object; - return TriState.get(constant.isNull()); - } - if (StampTool.isObjectNonNull(forObject.stamp())) { - return TriState.FALSE; - } - return TriState.UNKNOWN; - } - - @Override public void virtualize(VirtualizerTool tool) { if (tool.getObjectState(getValue()) != null) { tool.replaceWithValue(LogicConstantNode.contradiction(graph())); diff -r 6beb6da182fc -r a15b25626672 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java Wed Jun 25 11:20:53 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java Wed Jun 25 11:20:53 2014 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,9 +23,7 @@ package com.oracle.graal.nodes.java; import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.meta.ProfilingInfo.TriState; import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; @@ -34,7 +32,7 @@ /** * The {@code InstanceOfNode} represents an instanceof test. */ -public class InstanceOfNode extends UnaryOpLogicNode implements Canonicalizable, Lowerable, Virtualizable { +public class InstanceOfNode extends UnaryOpLogicNode implements Lowerable, Virtualizable { private final ResolvedJavaType type; private JavaTypeProfile profile; @@ -58,40 +56,14 @@ } @Override - public Node canonical(CanonicalizerTool tool) { - switch (evaluate(getValue())) { - case FALSE: - return LogicConstantNode.contradiction(graph()); - case TRUE: - return LogicConstantNode.tautology(graph()); - case UNKNOWN: - Stamp stamp = getValue().stamp(); - if (stamp instanceof ObjectStamp) { - ObjectStamp objectStamp = (ObjectStamp) stamp; - ResolvedJavaType stampType = objectStamp.type(); - if (stampType != null && type().isAssignableFrom(stampType)) { - if (!objectStamp.nonNull()) { - // the instanceof matches if the object is non-null, so return true - // depending on the null-ness. - IsNullNode isNull = graph().unique(new IsNullNode(getValue())); - return graph().unique(new LogicNegationNode(isNull)); - } - } - } - return this; - } - return this; - } - - @Override - public TriState evaluate(ValueNode forObject) { - Stamp stamp = forObject.stamp(); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { + Stamp stamp = forValue.stamp(); if (!(stamp instanceof ObjectStamp)) { - return TriState.UNKNOWN; + return this; } ObjectStamp objectStamp = (ObjectStamp) stamp; if (objectStamp.alwaysNull()) { - return TriState.FALSE; + return LogicConstantNode.contradiction(); } ResolvedJavaType stampType = objectStamp.type(); @@ -100,25 +72,32 @@ if (subType) { if (objectStamp.nonNull()) { // the instanceOf matches, so return true - return TriState.TRUE; + return LogicConstantNode.tautology(); } } else { if (objectStamp.isExactType()) { // since this type check failed for an exact type we know that it can never // succeed at run time. we also don't care about null values, since they will // also make the check fail. - return TriState.FALSE; + return LogicConstantNode.contradiction(); } else { boolean superType = stampType.isAssignableFrom(type()); if (!superType && !stampType.isInterface() && !type().isInterface()) { - return TriState.FALSE; + return LogicConstantNode.contradiction(); } // since the subtype comparison was only performed on a declared type we don't // really know if it might be true at run time... } } } - return TriState.UNKNOWN; + if (stampType != null && type().isAssignableFrom(stampType)) { + if (!objectStamp.nonNull()) { + // the instanceof matches if the object is non-null, so return true + // depending on the null-ness. + return new LogicNegationNode(new IsNullNode(forValue)); + } + } + return this; } /**