24 25 import org.graalvm.compiler.core.common.calc.Condition; 26 import org.graalvm.compiler.nodes.ValueNode; 27 import org.graalvm.compiler.nodes.ValueNodeInterface; 28 29 import jdk.vm.ci.meta.Constant; 30 import jdk.vm.ci.meta.ConstantReflectionProvider; 31 32 /** 33 * Represents a conversion between primitive types. 34 */ 35 public interface ConvertNode extends ValueNodeInterface { 36 37 ValueNode getValue(); 38 39 Constant convert(Constant c, ConstantReflectionProvider constantReflection); 40 41 Constant reverse(Constant c, ConstantReflectionProvider constantReflection); 42 43 /** 44 * Check whether a conversion is lossless. 45 * 46 * @return true iff reverse(convert(c)) == c for all c 47 */ 48 boolean isLossless(); 49 50 /** 51 * Check whether a conversion preserves comparison order. 52 * 53 * @param op a comparison operator 54 * @return true iff (c1 op c2) == (convert(c1) op convert(c2)) for all c1, c2 55 */ 56 default boolean preservesOrder(Condition op) { 57 return isLossless(); 58 } 59 60 /** 61 * Check whether a conversion preserves comparison order against a particular constant value. 62 * 63 * @param op a comparison operator | 24 25 import org.graalvm.compiler.core.common.calc.Condition; 26 import org.graalvm.compiler.nodes.ValueNode; 27 import org.graalvm.compiler.nodes.ValueNodeInterface; 28 29 import jdk.vm.ci.meta.Constant; 30 import jdk.vm.ci.meta.ConstantReflectionProvider; 31 32 /** 33 * Represents a conversion between primitive types. 34 */ 35 public interface ConvertNode extends ValueNodeInterface { 36 37 ValueNode getValue(); 38 39 Constant convert(Constant c, ConstantReflectionProvider constantReflection); 40 41 Constant reverse(Constant c, ConstantReflectionProvider constantReflection); 42 43 /** 44 * Checks whether a null check may skip the conversion. This is true if in the conversion NULL 45 * is converted to NULL and if it is the only value converted to NULL. 46 * 47 * @return whether a null check may skip the conversion 48 */ 49 boolean mayNullCheckSkipConversion(); 50 51 /** 52 * Check whether a conversion is lossless. 53 * 54 * @return true iff reverse(convert(c)) == c for all c 55 */ 56 boolean isLossless(); 57 58 /** 59 * Check whether a conversion preserves comparison order. 60 * 61 * @param op a comparison operator 62 * @return true iff (c1 op c2) == (convert(c1) op convert(c2)) for all c1, c2 63 */ 64 default boolean preservesOrder(Condition op) { 65 return isLossless(); 66 } 67 68 /** 69 * Check whether a conversion preserves comparison order against a particular constant value. 70 * 71 * @param op a comparison operator |