# HG changeset patch # User Christian Wimmer # Date 1354230339 28800 # Node ID 0c59b76e6689b32b810539509654c2c564eadb82 # Parent 3656236c7d272500713b8a573a4122550fb8e9be Eliminate bogus conversion that Constant.asLong() performed; simplify asXxx methods so that they do not have control flow. diff -r 3656236c7d27 -r 0c59b76e6689 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java Thu Nov 29 12:17:02 2012 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Constant.java Thu Nov 29 15:05:39 2012 -0800 @@ -194,108 +194,65 @@ } /** - * Converts this constant to a primitive int. + * Returns the primitive int value this constant represents. The constant must have a {@link Kind#getStackKind()} of + * {@link Kind#Int}, or kind {@link Kind#Jsr}. * - * @return the int value of this constant + * @return the constant value */ public int asInt() { - if (getKind().getStackKind() == Kind.Int || getKind() == Kind.Jsr) { - return (int) primitive; - } - throw new Error("Constant is not int: " + this); + assert getKind().getStackKind() == Kind.Int || getKind() == Kind.Jsr; + return (int) primitive; } /** - * Converts this constant to a primitive boolean. + * Returns the primitive boolean value this constant represents. The constant must have kind {@link Kind#Boolean}. * - * @return the boolean value of this constant + * @return the constant value */ public boolean asBoolean() { - if (getKind() == Kind.Boolean) { - return primitive != 0L; - } - throw new Error("Constant is not boolean: " + this); - } - - /** - * Converts this constant to a primitive long. - * - * @return the long value of this constant - */ - public long asLong() { - switch (getKind().getStackKind()) { - case Jsr: - case Int: - case Long: - return primitive; - case Float: - return (long) asFloat(); - case Double: - return (long) asDouble(); - default: - throw new Error("Constant is not long: " + this); - } + assert getKind() == Kind.Boolean; + return primitive != 0L; } /** - * Converts this constant to a primitive float. + * Returns the primitive long value this constant represents. The constant must have kind {@link Kind#Long}, a + * {@link Kind#getStackKind()} of {@link Kind#Int}, or kind {@link Kind#Jsr}. * - * @return the float value of this constant + * @return the constant value */ - public float asFloat() { - if (getKind() == Kind.Float) { - return Float.intBitsToFloat((int) primitive); - } - throw new Error("Constant is not float: " + this); - } - - /** - * Converts this constant to a primitive double. - * - * @return the double value of this constant - */ - public double asDouble() { - if (getKind() == Kind.Float) { - return Float.intBitsToFloat((int) primitive); - } - if (getKind() == Kind.Double) { - return Double.longBitsToDouble(primitive); - } - throw new Error("Constant is not double: " + this); + public long asLong() { + assert getKind() == Kind.Long || getKind().getStackKind() == Kind.Int || getKind() == Kind.Jsr; + return primitive; } /** - * Converts this constant to the object reference it represents. + * Returns the primitive float value this constant represents. The constant must have kind {@link Kind#Float}. * - * @return the object which this constant represents + * @return the constant value */ - public Object asObject() { - if (getKind() == Kind.Object) { - return object; - } - throw new Error("Constant is not object: " + this); + public float asFloat() { + assert getKind() == Kind.Float; + return Float.intBitsToFloat((int) primitive); } /** - * Converts this constant to the jsr reference it represents. + * Returns the primitive double value this constant represents. The constant must have kind {@link Kind#Double}. * - * @return the object which this constant represents + * @return the constant value */ - public int asJsr() { - if (getKind() == Kind.Jsr) { - return (int) primitive; - } - throw new Error("Constant is not jsr: " + this); + public double asDouble() { + assert getKind() == Kind.Double; + return Double.longBitsToDouble(primitive); } /** - * Unchecked access to a primitive value. + * Returns the object reference this constant represents. The constant must have kind {@link Kind#Object}. + * + * @return the constant value */ - public long asPrimitive() { - if (getKind() == Kind.Object) { - throw new Error("Constant is not primitive: " + this); - } - return primitive; + public Object asObject() { + assert getKind() == Kind.Object; + return object; } /** diff -r 3656236c7d27 -r 0c59b76e6689 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Thu Nov 29 12:17:02 2012 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Thu Nov 29 15:05:39 2012 -0800 @@ -137,7 +137,9 @@ } else { if (value.getKind() == Kind.Int || value.getKind() == Kind.Long) { return forInteger(value.getKind(), value.asLong(), value.asLong(), value.asLong() & IntegerStamp.defaultMask(value.getKind())); - } else if (value.getKind() == Kind.Float || value.getKind() == Kind.Double) { + } else if (value.getKind() == Kind.Float) { + return forFloat(value.getKind(), value.asFloat(), value.asFloat(), !Float.isNaN(value.asFloat())); + } else if (value.getKind() == Kind.Double) { return forFloat(value.getKind(), value.asDouble(), value.asDouble(), !Double.isNaN(value.asDouble())); } return forKind(value.getKind().getStackKind());