Mercurial > hg > graal-compiler
changeset 5890:c241963cda6d
added Stamp.join, used by PiNodes
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Mon, 20 Aug 2012 15:11:15 +0200 |
parents | 73d12bcca62e |
children | fd8832ae511d |
files | graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/FloatStamp.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/Stamp.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/WordStamp.java |
diffstat | 7 files changed, 110 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Mon Aug 20 15:11:15 2012 +0200 @@ -53,17 +53,6 @@ @Override public boolean inferStamp() { - if (object().stamp().nonNull() && !stamp().nonNull()) { - setStamp(StampFactory.declaredNonNull(objectStamp().type())); - return true; - } - if (object().objectStamp().alwaysNull() && !objectStamp().alwaysNull()) { - setStamp(StampFactory.alwaysNull()); - return true; - } - if (object().objectStamp().isExactType() && !objectStamp().isExactType()) { - setStamp(object().objectStamp()); - } - return super.inferStamp(); + return updateStamp(stamp().join(object().stamp())); } }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/FloatStamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/FloatStamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -106,6 +106,22 @@ } @Override + public Stamp join(Stamp otherStamp) { + FloatStamp other = (FloatStamp) otherStamp; + assert kind() == other.kind(); + double joinUpperBound = Math.min(upperBound, other.upperBound); + double joinLowerBound = Math.max(lowerBound, other.lowerBound); + boolean joinNonNaN = nonNaN || other.nonNaN; + if (joinLowerBound == lowerBound && joinUpperBound == upperBound && joinNonNaN == nonNaN) { + return this; + } else if (joinLowerBound == other.lowerBound && joinUpperBound == other.upperBound && joinNonNaN == other.nonNaN) { + return other; + } else { + return new FloatStamp(kind(), joinLowerBound, joinUpperBound, joinNonNaN); + } + } + + @Override public int hashCode() { final int prime = 31; int result = 1;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -58,6 +58,12 @@ } @Override + public Stamp join(Stamp other) { + assert ((GenericStamp) other).type == type; + return this; + } + + @Override public int hashCode() { return 31 + ((type == null) ? 0 : type.hashCode()); }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -119,6 +119,22 @@ } @Override + public Stamp join(Stamp otherStamp) { + IntegerStamp other = (IntegerStamp) otherStamp; + assert kind() == other.kind(); + long joinUpperBound = Math.min(upperBound, other.upperBound); + long joinLowerBound = Math.max(lowerBound, other.lowerBound); + long joinMask = mask & other.mask; + if (joinLowerBound == lowerBound && joinUpperBound == upperBound && joinMask == mask) { + return this; + } else if (joinLowerBound == other.lowerBound && joinUpperBound == other.upperBound && joinMask == other.mask) { + return other; + } else { + return new IntegerStamp(kind(), joinLowerBound, joinUpperBound, joinMask); + } + } + + @Override public int hashCode() { final int prime = 31; int result = 1;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -85,6 +85,9 @@ @Override public Stamp meet(Stamp otherStamp) { + if (this == otherStamp) { + return this; + } ObjectStamp other = (ObjectStamp) otherStamp; ResolvedJavaType meetType; boolean meetExactType; @@ -109,11 +112,48 @@ if (meetType == type && meetExactType == exactType && meetNonNull == nonNull && meetAlwaysNull == alwaysNull) { return this; + } else if (meetType == other.type && meetExactType == other.exactType && meetNonNull == other.nonNull && meetAlwaysNull == other.alwaysNull) { + return other; } else { return new ObjectStamp(meetType, meetExactType, meetNonNull, meetAlwaysNull); } } + @Override + public Stamp join(Stamp otherStamp) { + if (this == otherStamp) { + return this; + } + ObjectStamp other = (ObjectStamp) otherStamp; + ResolvedJavaType joinType; + boolean joinExactType = exactType || other.exactType; + boolean joinNonNull = nonNull || other.nonNull; + boolean joinAlwaysNull = alwaysNull || other.alwaysNull; + if (type == other.type) { + joinType = type; + } else if (type == null && other.type == null) { + joinType = null; + } else if (type == null) { + joinType = other.type; + } else if (other.type == null) { + joinType = type; + } else { + // both types are != null + if (other.type.isSubtypeOf(type)) { + joinType = other.type; + } else { + joinType = type; + } + } + if (joinType == type && joinExactType == exactType && joinNonNull == nonNull && joinAlwaysNull == alwaysNull) { + return this; + } else if (joinType == other.type && joinExactType == other.exactType && joinNonNull == other.nonNull && joinAlwaysNull == other.alwaysNull) { + return other; + } else { + return new ObjectStamp(joinType, joinExactType, joinNonNull, joinAlwaysNull); + } + } + private static ResolvedJavaType meetTypes(ResolvedJavaType a, ResolvedJavaType b) { if (a == b) { return a;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/Stamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/Stamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.nodes.type; import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.types.*; /** @@ -54,5 +55,17 @@ public abstract boolean alwaysDistinct(Stamp other); + /** + * Returns the union of this stamp and the given stamp. Typically used to create stamps for {@link PhiNode}s. + * @param other The stamp that will enlarge this stamp. + * @return The union of this stamp and the given stamp. + */ public abstract Stamp meet(Stamp other); + + /** + * Returns the intersection of this stamp and the given stamp. + * @param other The stamp that will tighten this stamp. + * @return The intersection of this stamp and the given stamp. + */ + public abstract Stamp join(Stamp other); }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/WordStamp.java Mon Aug 20 14:20:30 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/WordStamp.java Mon Aug 20 15:11:15 2012 +0200 @@ -57,10 +57,26 @@ @Override public Stamp meet(Stamp otherStamp) { WordStamp other = (WordStamp) otherStamp; - if (other.nonNull == nonNull) { + boolean meetNonNull = nonNull && other.nonNull; + if (meetNonNull == this.nonNull) { return this; + } else if (meetNonNull == other.nonNull) { + return other; } else { - return new WordStamp(kind(), nonNull && other.nonNull); + return new WordStamp(kind(), meetNonNull); + } + } + + @Override + public Stamp join(Stamp otherStamp) { + WordStamp other = (WordStamp) otherStamp; + boolean joinNonNull = nonNull || other.nonNull; + if (joinNonNull == this.nonNull) { + return this; + } else if (joinNonNull == other.nonNull) { + return other; + } else { + return new WordStamp(kind(), joinNonNull); } }