Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java @ 15791:308cedd2aaa2
better stamps for IntegerRemNode
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Tue, 20 May 2014 16:17:16 +0200 |
parents | 10c6705dbe9a |
children | 83433cf49019 |
rev | line source |
---|---|
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.type; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
25 import java.util.*; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
26 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15132
diff
changeset
|
28 import com.oracle.graal.compiler.common.type.*; |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
29 import com.oracle.graal.nodes.*; |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
30 import com.oracle.graal.nodes.calc.*; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 /** |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 * Helper class that is used to keep all stamp-related operations in one place. |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 */ |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
35 public class StampTool { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 public static Stamp negate(Stamp stamp) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 if (stamp instanceof IntegerStamp) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 IntegerStamp integerStamp = (IntegerStamp) stamp; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
40 int bits = integerStamp.getBits(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
41 if (integerStamp.lowerBound() != IntegerStamp.defaultMinValue(bits)) { |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
42 // TODO(ls) check if the mask calculation is correct... |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
43 return StampFactory.forInteger(bits, -integerStamp.upperBound(), -integerStamp.lowerBound()); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
45 } else if (stamp instanceof FloatStamp) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
46 FloatStamp floatStamp = (FloatStamp) stamp; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
47 return new FloatStamp(floatStamp.getBits(), -floatStamp.upperBound(), -floatStamp.lowerBound(), floatStamp.isNonNaN()); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
48 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
49 |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
50 return stamp.unrestricted(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
53 public static Stamp not(Stamp stamp) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
54 if (stamp instanceof IntegerStamp) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
55 IntegerStamp integerStamp = (IntegerStamp) stamp; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
56 int bits = integerStamp.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
57 long defaultMask = IntegerStamp.defaultMask(bits); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
58 return new IntegerStamp(bits, ~integerStamp.upperBound(), ~integerStamp.lowerBound(), (~integerStamp.upMask()) & defaultMask, (~integerStamp.downMask()) & defaultMask); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
59 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
60 return stamp.unrestricted(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
61 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
62 |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 public static Stamp meet(Collection<? extends StampProvider> values) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7489
diff
changeset
|
64 Iterator<? extends StampProvider> iterator = values.iterator(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
65 if (iterator.hasNext()) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
66 Stamp stamp = iterator.next().stamp(); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
67 while (iterator.hasNext()) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
68 stamp = stamp.meet(iterator.next().stamp()); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
69 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
70 return stamp; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
71 } else { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
72 return StampFactory.forVoid(); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
73 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
75 |
11265 | 76 public static Stamp add(Stamp stamp1, Stamp stamp2) { |
77 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
78 return add((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
79 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
80 return StampFactory.illegal(); |
11265 | 81 } |
82 | |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
83 private static long carryBits(long x, long y) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
84 return (x + y) ^ x ^ y; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
85 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
86 |
11265 | 87 public static Stamp sub(Stamp stamp1, Stamp stamp2) { |
88 return add(stamp1, StampTool.negate(stamp2)); | |
89 } | |
90 | |
91 public static Stamp div(Stamp stamp1, Stamp stamp2) { | |
92 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
93 return div((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
94 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
95 return StampFactory.illegal(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
96 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
97 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
98 public static Stamp div(IntegerStamp stamp1, IntegerStamp stamp2) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
99 assert stamp1.getBits() == stamp2.getBits(); |
6299
1ed726759f65
Add helper methods to IntegerStamp for sign, use them
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5657
diff
changeset
|
100 if (stamp2.isStrictlyPositive()) { |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
101 long lowerBound = stamp1.lowerBound() / stamp2.lowerBound(); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
102 long upperBound = stamp1.upperBound() / stamp2.lowerBound(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
103 return StampFactory.forInteger(stamp1.getBits(), lowerBound, upperBound); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
105 return stamp1.unrestricted(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
106 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
107 |
15791
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
108 public static Stamp rem(Stamp stamp1, Stamp stamp2) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
109 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
110 return rem((IntegerStamp) stamp1, (IntegerStamp) stamp2); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
111 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
112 return StampFactory.illegal(); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
113 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
114 |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
115 public static Stamp rem(IntegerStamp stamp1, IntegerStamp stamp2) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
116 assert stamp1.getBits() == stamp2.getBits(); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
117 long magnitude; // the maximum absolute value of the result |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
118 if (stamp2.lowerBound() == IntegerStamp.defaultMinValue(stamp2.getBits())) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
119 // Math.abs(...) - 1 does not work in this case |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
120 magnitude = IntegerStamp.defaultMaxValue(stamp2.getBits()); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
121 } else { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
122 magnitude = Math.max(Math.abs(stamp2.lowerBound()), Math.abs(stamp2.upperBound())) - 1; |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
123 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
124 long lowerBound = Math.max(stamp1.lowerBound(), -magnitude); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
125 if (stamp1.upperBound() > magnitude) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
126 // if the result can wrap around at the upper bound, it can reach any value between 0 |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
127 // and magnitude |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
128 lowerBound = Math.min(lowerBound, 0); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
129 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
130 long upperBound = Math.min(stamp1.upperBound(), magnitude); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
131 if (stamp1.lowerBound() < -magnitude) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
132 // if the result can wrap around at the lower bound, it can reach any value between |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
133 // -magnitude and 0 |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
134 upperBound = Math.max(upperBound, 0); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
135 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
136 return StampFactory.forInteger(stamp1.getBits(), lowerBound, upperBound); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
137 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
138 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
139 private static boolean addOverflowsPositively(long x, long y, int bits) { |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
140 long result = x + y; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
141 if (bits == 64) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
142 return (~x & ~y & result) < 0; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
143 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
144 return result > IntegerStamp.defaultMaxValue(bits); |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
145 } |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
146 } |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
147 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
148 private static boolean addOverflowsNegatively(long x, long y, int bits) { |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
149 long result = x + y; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
150 if (bits == 64) { |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
151 return (x & y & ~result) < 0; |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
152 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
153 return result < IntegerStamp.defaultMinValue(bits); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
154 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
155 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
156 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
157 public static IntegerStamp add(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
158 int bits = stamp1.getBits(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
159 assert bits == stamp2.getBits(); |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
160 |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
161 if (stamp1.isUnrestricted()) { |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
162 return stamp1; |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
163 } else if (stamp2.isUnrestricted()) { |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
164 return stamp2; |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
165 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
166 long defaultMask = IntegerStamp.defaultMask(bits); |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
167 long variableBits = (stamp1.downMask() ^ stamp1.upMask()) | (stamp2.downMask() ^ stamp2.upMask()); |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
168 long variableBitsWithCarry = variableBits | (carryBits(stamp1.downMask(), stamp2.downMask()) ^ carryBits(stamp1.upMask(), stamp2.upMask())); |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
169 long newDownMask = (stamp1.downMask() + stamp2.downMask()) & ~variableBitsWithCarry; |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
170 long newUpMask = (stamp1.downMask() + stamp2.downMask()) | variableBitsWithCarry; |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
171 |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
172 newDownMask &= defaultMask; |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
173 newUpMask &= defaultMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
175 long lowerBound; |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
176 long upperBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
177 boolean lowerOverflowsPositively = addOverflowsPositively(stamp1.lowerBound(), stamp2.lowerBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
178 boolean upperOverflowsPositively = addOverflowsPositively(stamp1.upperBound(), stamp2.upperBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
179 boolean lowerOverflowsNegatively = addOverflowsNegatively(stamp1.lowerBound(), stamp2.lowerBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
180 boolean upperOverflowsNegatively = addOverflowsNegatively(stamp1.upperBound(), stamp2.upperBound(), bits); |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
181 if ((lowerOverflowsNegatively && !upperOverflowsNegatively) || (!lowerOverflowsPositively && upperOverflowsPositively)) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
182 lowerBound = IntegerStamp.defaultMinValue(bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
183 upperBound = IntegerStamp.defaultMaxValue(bits); |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
184 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
185 lowerBound = SignExtendNode.signExtend((stamp1.lowerBound() + stamp2.lowerBound()) & defaultMask, bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
186 upperBound = SignExtendNode.signExtend((stamp1.upperBound() + stamp2.upperBound()) & defaultMask, bits); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
187 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
188 IntegerStamp limit = StampFactory.forInteger(bits, lowerBound, upperBound); |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
189 newUpMask &= limit.upMask(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
190 upperBound = SignExtendNode.signExtend(upperBound & newUpMask, bits); |
12677
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
191 newDownMask |= limit.downMask(); |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
192 lowerBound |= newDownMask; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
193 return new IntegerStamp(bits, lowerBound, upperBound, newDownMask, newUpMask); |
10045
a4e7a7dc74f3
better stamps for OrNodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
194 } |
a4e7a7dc74f3
better stamps for OrNodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
195 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
196 public static Stamp sub(IntegerStamp stamp1, IntegerStamp stamp2) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
197 if (stamp1.isUnrestricted() || stamp2.isUnrestricted()) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
198 return stamp1.unrestricted(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
199 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
200 return add(stamp1, (IntegerStamp) StampTool.negate(stamp2)); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
201 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
202 |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
203 private static Stamp stampForMask(int bits, long downMask, long upMask) { |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
204 long lowerBound; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
205 long upperBound; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
206 if (((upMask >>> (bits - 1)) & 1) == 0) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
207 lowerBound = downMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
208 upperBound = upMask; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
209 } else if (((downMask >>> (bits - 1)) & 1) == 1) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
210 lowerBound = downMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
211 upperBound = upMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
212 } else { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
213 lowerBound = downMask | (-1L << (bits - 1)); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
214 upperBound = IntegerStamp.defaultMaxValue(bits) & upMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
215 } |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
216 lowerBound = IntegerConvertNode.convert(lowerBound, bits, false); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
217 upperBound = IntegerConvertNode.convert(upperBound, bits, false); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
218 return new IntegerStamp(bits, lowerBound, upperBound, downMask, upMask); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
219 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
220 |
11265 | 221 public static Stamp and(Stamp stamp1, Stamp stamp2) { |
222 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
223 return and((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
224 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
225 return StampFactory.illegal(); |
11265 | 226 } |
227 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
228 public static Stamp and(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
229 assert stamp1.getBits() == stamp2.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
230 return stampForMask(stamp1.getBits(), stamp1.downMask() & stamp2.downMask(), stamp1.upMask() & stamp2.upMask()); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
231 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
232 |
11265 | 233 public static Stamp or(Stamp stamp1, Stamp stamp2) { |
234 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
235 return or((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
236 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
237 return StampFactory.illegal(); |
11265 | 238 } |
239 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
240 public static Stamp or(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
241 assert stamp1.getBits() == stamp2.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
242 return stampForMask(stamp1.getBits(), stamp1.downMask() | stamp2.downMask(), stamp1.upMask() | stamp2.upMask()); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
243 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
244 |
11265 | 245 public static Stamp xor(Stamp stamp1, Stamp stamp2) { |
246 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
247 return xor((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
248 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
249 return StampFactory.illegal(); |
11265 | 250 } |
251 | |
7489
8461d937ac18
Better for Load/Read stamps for non-stack kinds
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7302
diff
changeset
|
252 public static Stamp xor(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
253 assert stamp1.getBits() == stamp2.getBits(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
254 long variableBits = (stamp1.downMask() ^ stamp1.upMask()) | (stamp2.downMask() ^ stamp2.upMask()); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
255 long newDownMask = (stamp1.downMask() ^ stamp2.downMask()) & ~variableBits; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
256 long newUpMask = (stamp1.downMask() ^ stamp2.downMask()) | variableBits; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
257 return stampForMask(stamp1.getBits(), newDownMask, newUpMask); |
7489
8461d937ac18
Better for Load/Read stamps for non-stack kinds
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7302
diff
changeset
|
258 } |
8461d937ac18
Better for Load/Read stamps for non-stack kinds
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7302
diff
changeset
|
259 |
11265 | 260 public static Stamp unsignedRightShift(Stamp value, Stamp shift) { |
261 if (value instanceof IntegerStamp && shift instanceof IntegerStamp) { | |
262 return unsignedRightShift((IntegerStamp) value, (IntegerStamp) shift); | |
263 } | |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
264 return value.illegal(); |
11265 | 265 } |
266 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
267 public static Stamp unsignedRightShift(IntegerStamp value, IntegerStamp shift) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
268 int bits = value.getBits(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
269 if (shift.lowerBound() == shift.upperBound()) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
270 long shiftMask = bits > 32 ? 0x3FL : 0x1FL; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
271 long shiftCount = shift.lowerBound() & shiftMask; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
272 if (shiftCount != 0) { |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
273 long lowerBound; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
274 long upperBound; |
12538
ae36dae46d50
Fix StampTool.unsignedRightShift
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
275 long downMask = value.downMask() >>> shiftCount; |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
276 long upMask = value.upMask() >>> shiftCount; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
277 if (value.lowerBound() < 0) { |
12538
ae36dae46d50
Fix StampTool.unsignedRightShift
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
278 lowerBound = downMask; |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
279 upperBound = upMask; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
280 } else { |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
281 lowerBound = value.lowerBound() >>> shiftCount; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
282 upperBound = value.upperBound() >>> shiftCount; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
283 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
284 return new IntegerStamp(bits, lowerBound, upperBound, downMask, upMask); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
285 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
286 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
287 long mask = IntegerStamp.upMaskFor(bits, value.lowerBound(), value.upperBound()); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
288 return stampForMask(bits, 0, mask); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
289 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
290 |
11265 | 291 public static Stamp leftShift(Stamp value, Stamp shift) { |
292 if (value instanceof IntegerStamp && shift instanceof IntegerStamp) { | |
293 return leftShift((IntegerStamp) value, (IntegerStamp) shift); | |
294 } | |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
295 return value.illegal(); |
11265 | 296 } |
297 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
298 public static Stamp leftShift(IntegerStamp value, IntegerStamp shift) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
299 int bits = value.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
300 long defaultMask = IntegerStamp.defaultMask(bits); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
301 if (value.upMask() == 0) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
302 return value; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
303 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
304 int shiftBits = bits > 32 ? 6 : 5; |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
305 long shiftMask = bits > 32 ? 0x3FL : 0x1FL; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
306 if ((shift.lowerBound() >>> shiftBits) == (shift.upperBound() >>> shiftBits)) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
307 long downMask = defaultMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
308 long upMask = 0; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
309 for (long i = shift.lowerBound(); i <= shift.upperBound(); i++) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
310 if (shift.contains(i)) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
311 downMask &= value.downMask() << (i & shiftMask); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
312 upMask |= value.upMask() << (i & shiftMask); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
313 } |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
314 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
315 Stamp result = stampForMask(bits, downMask, upMask & defaultMask); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
316 return result; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
317 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
318 return value.unrestricted(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
319 } |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
320 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
321 public static Stamp signExtend(Stamp input, int resultBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
322 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
323 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
324 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
325 assert inputBits <= resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
326 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
327 long defaultMask = IntegerStamp.defaultMask(resultBits); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
328 long downMask = SignExtendNode.signExtend(inputStamp.downMask(), inputBits) & defaultMask; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
329 long upMask = SignExtendNode.signExtend(inputStamp.upMask(), inputBits) & defaultMask; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
330 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
331 return new IntegerStamp(resultBits, inputStamp.lowerBound(), inputStamp.upperBound(), downMask, upMask); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
332 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
333 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
334 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
335 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
336 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
337 public static Stamp zeroExtend(Stamp input, int resultBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
338 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
339 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
340 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
341 assert inputBits <= resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
342 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
343 long downMask = ZeroExtendNode.zeroExtend(inputStamp.downMask(), inputBits); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
344 long upMask = ZeroExtendNode.zeroExtend(inputStamp.upMask(), inputBits); |
14015
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
345 |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
346 if (inputStamp.lowerBound() < 0 && inputStamp.upperBound() >= 0) { |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
347 // signed range including 0 and -1 |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
348 // after sign extension, the whole range from 0 to MAX_INT is possible |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
349 return stampForMask(resultBits, downMask, upMask); |
14010
c7c9624f8ca2
Fix corner case in stamp computation of zero extension.
Roland Schatz <roland.schatz@oracle.com>
parents:
14000
diff
changeset
|
350 } |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
351 |
14015
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
352 long lowerBound = ZeroExtendNode.zeroExtend(inputStamp.lowerBound(), inputBits); |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
353 long upperBound = ZeroExtendNode.zeroExtend(inputStamp.upperBound(), inputBits); |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
354 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
355 return new IntegerStamp(resultBits, lowerBound, upperBound, downMask, upMask); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
356 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
357 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
358 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
359 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
360 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
361 public static Stamp narrowingConversion(Stamp input, int resultBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
362 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
363 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
364 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
365 assert resultBits <= inputBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
366 if (resultBits == inputBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
367 return inputStamp; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
368 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
369 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
370 final long upperBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
371 if (inputStamp.lowerBound() < IntegerStamp.defaultMinValue(resultBits)) { |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
372 upperBound = IntegerStamp.defaultMaxValue(resultBits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
373 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
374 upperBound = saturate(inputStamp.upperBound(), resultBits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
375 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
376 final long lowerBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
377 if (inputStamp.upperBound() > IntegerStamp.defaultMaxValue(resultBits)) { |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
378 lowerBound = IntegerStamp.defaultMinValue(resultBits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
379 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
380 lowerBound = saturate(inputStamp.lowerBound(), resultBits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
381 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
382 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
383 long defaultMask = IntegerStamp.defaultMask(resultBits); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
384 long newDownMask = inputStamp.downMask() & defaultMask; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
385 long newUpMask = inputStamp.upMask() & defaultMask; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
386 long newLowerBound = SignExtendNode.signExtend((lowerBound | newDownMask) & newUpMask, resultBits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
387 long newUpperBound = SignExtendNode.signExtend((upperBound | newDownMask) & newUpMask, resultBits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
388 return new IntegerStamp(resultBits, newLowerBound, newUpperBound, newDownMask, newUpMask); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
389 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
390 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
391 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
392 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
393 |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12562
diff
changeset
|
394 public static IntegerStamp narrowingKindConversion(IntegerStamp fromStamp, Kind toKind) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
395 assert toKind == Kind.Byte || toKind == Kind.Char || toKind == Kind.Short || toKind == Kind.Int; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
396 final long upperBound; |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
397 if (fromStamp.lowerBound() < toKind.getMinValue()) { |
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
398 upperBound = toKind.getMaxValue(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
399 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
400 upperBound = saturate(fromStamp.upperBound(), toKind); |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
401 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
402 final long lowerBound; |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
403 if (fromStamp.upperBound() > toKind.getMaxValue()) { |
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
404 lowerBound = toKind.getMinValue(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
405 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
406 lowerBound = saturate(fromStamp.lowerBound(), toKind); |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
407 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
408 |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
409 long defaultMask = IntegerStamp.defaultMask(toKind.getBitCount()); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
410 long intMask = IntegerStamp.defaultMask(32); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
411 long newUpMask = signExtend(fromStamp.upMask() & defaultMask, toKind) & intMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
412 long newDownMask = signExtend(fromStamp.downMask() & defaultMask, toKind) & intMask; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
413 return new IntegerStamp(toKind.getStackKind().getBitCount(), (int) ((lowerBound | newDownMask) & newUpMask), (int) ((upperBound | newDownMask) & newUpMask), newDownMask, newUpMask); |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
414 } |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
415 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
416 private static long signExtend(long value, Kind valueKind) { |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
417 if (valueKind != Kind.Char && valueKind != Kind.Long && (value >>> (valueKind.getBitCount() - 1) & 1) == 1) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
418 return value | (-1L << valueKind.getBitCount()); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
419 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
420 return value; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
421 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
422 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
423 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
424 private static long saturate(long v, int bits) { |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
425 if (bits < 64) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
426 long max = IntegerStamp.defaultMaxValue(bits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
427 if (v > max) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
428 return max; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
429 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
430 long min = IntegerStamp.defaultMinValue(bits); |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
431 if (v < min) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
432 return min; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
433 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
434 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
435 return v; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
436 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
437 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
438 private static long saturate(long v, Kind kind) { |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
439 long max = kind.getMaxValue(); |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
440 if (v > max) { |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
441 return max; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
442 } |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
443 long min = kind.getMinValue(); |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
444 if (v < min) { |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
445 return min; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
446 } |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
447 return v; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
448 } |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
449 |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
450 /** |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
451 * Compute the stamp resulting from the unsigned comparison being true. |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
452 * |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
453 * @return null if it's can't be true or it nothing useful can be encoded. |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
454 */ |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
455 public static Stamp unsignedCompare(Stamp stamp, Stamp stamp2) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
456 IntegerStamp x = (IntegerStamp) stamp; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
457 IntegerStamp y = (IntegerStamp) stamp2; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
458 if (x == x.unrestricted() && y == y.unrestricted()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
459 // Don't know anything. |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
460 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
461 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
462 // c <| n, where c is a constant and n is known to be positive. |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
463 if (x.lowerBound() == x.upperBound()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
464 if (y.isPositive()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
465 if (x.lowerBound() == (1 << x.getBits()) - 1) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
466 // Constant is MAX_VALUE which must fail. |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
467 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
468 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
469 if (x.lowerBound() <= y.lowerBound()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
470 // Test will fail. Return illegalStamp instead? |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
471 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
472 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
473 // If the test succeeds then this proves that n is at greater than c so the bounds |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
474 // are [c+1..-n.upperBound)]. |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
475 return StampFactory.forInteger(x.getBits(), x.lowerBound() + 1, y.upperBound()); |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
476 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
477 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
478 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
479 // n <| c, where c is a strictly positive constant |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
480 if (y.lowerBound() == y.upperBound() && y.isStrictlyPositive()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
481 // The test proves that n is positive and less than c, [0..c-1] |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
482 return StampFactory.forInteger(y.getBits(), 0, y.lowerBound() - 1); |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
483 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
484 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
485 } |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
486 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
487 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
488 * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
489 * value which is known to be always null. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
490 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
491 * @param node the node to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
492 * @return true if this node represents a legal object value which is known to be always null |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
493 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
494 public static boolean isObjectAlwaysNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
495 return isObjectAlwaysNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
496 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
497 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
498 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
499 * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
500 * stamp whose values are known to be always null. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
501 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
502 * @param stamp the stamp to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
503 * @return true if this stamp represents a legal object stamp whose values are known to be |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
504 * always null |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
505 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
506 public static boolean isObjectAlwaysNull(Stamp stamp) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
507 if (stamp instanceof ObjectStamp && stamp.isLegal()) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
508 return ((ObjectStamp) stamp).alwaysNull(); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
509 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
510 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
511 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
512 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
513 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
514 * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
515 * value which is known to never be null. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
516 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
517 * @param node the node to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
518 * @return true if this node represents a legal object value which is known to never be null |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
519 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
520 public static boolean isObjectNonNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
521 return isObjectNonNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
522 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
523 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
524 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
525 * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
526 * stamp whose values known to be always null. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
527 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
528 * @param stamp the stamp to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
529 * @return true if this stamp represents a legal object stamp whose values are known to be |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
530 * always null |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
531 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
532 public static boolean isObjectNonNull(Stamp stamp) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
533 if (stamp instanceof ObjectStamp && stamp.isLegal()) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
534 return ((ObjectStamp) stamp).nonNull(); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
535 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
536 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
537 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
538 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
539 /** |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
540 * Returns the {@linkplain ResolvedJavaType Java type} this {@linkplain ValueNode} has if it is |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
541 * a {@linkplain Stamp#isLegal() legal} Object value. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
542 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
543 * @param node the node to check |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
544 * @return the Java type this value has if it is a legal Object type, null otherwise |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
545 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
546 public static ResolvedJavaType typeOrNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
547 return typeOrNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
548 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
549 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
550 /** |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
551 * Returns the {@linkplain ResolvedJavaType Java type} this {@linkplain Stamp} has if it is a |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
552 * {@linkplain Stamp#isLegal() legal} Object stamp. |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
553 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
554 * @param stamp the stamp to check |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
555 * @return the Java type this stamp has if it is a legal Object stamp, null otherwise |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
556 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
557 public static ResolvedJavaType typeOrNull(Stamp stamp) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
558 if (stamp instanceof ObjectStamp && stamp.isLegal()) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
559 return ((ObjectStamp) stamp).type(); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
560 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
561 return null; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
562 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
563 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
564 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
565 * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
566 * value whose Java type is known exactly. If this method returns true then the |
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
567 * {@linkplain ResolvedJavaType Java type} returned by {@link #typeOrNull(ValueNode)} is the |
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
568 * concrete dynamic/runtime Java type of this value. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
569 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
570 * @param node the node to check |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
571 * @return true if this node represents a legal object value whose Java type is known exactly |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
572 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
573 public static boolean isExactType(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
574 return isExactType(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
575 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
576 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
577 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
578 * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
579 * stamp whose {@linkplain ResolvedJavaType Java type} is known exactly. If this method returns |
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
580 * true then the Java type returned by {@link #typeOrNull(Stamp)} is the only concrete |
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
581 * dynamic/runtime Java type possible for values of this stamp. |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
582 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
583 * @param stamp the stamp to check |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
584 * @return true if this node represents a legal object stamp whose Java type is known exactly |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
585 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
586 public static boolean isExactType(Stamp stamp) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
587 if (stamp instanceof ObjectStamp && stamp.isLegal()) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
588 return ((ObjectStamp) stamp).isExactType(); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
589 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
590 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
591 } |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
592 } |