43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.nodes.calc;
|
|
24 |
|
48861
|
25 |
import org.graalvm.compiler.core.common.calc.CanonicalCondition;
|
43972
|
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 |
/**
|
46344
|
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 |
/**
|
43972
|
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 |
*/
|
48861
|
64 |
default boolean preservesOrder(CanonicalCondition op) {
|
43972
|
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
|
|
72 |
* @param value
|
|
73 |
* @param constantReflection
|
|
74 |
* @return true iff (c1 op value) == (convert(c1) op convert(value)) for value and all c1
|
|
75 |
*/
|
48861
|
76 |
default boolean preservesOrder(CanonicalCondition op, Constant value, ConstantReflectionProvider constantReflection) {
|
43972
|
77 |
return preservesOrder(op);
|
|
78 |
}
|
|
79 |
}
|