Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java @ 16452:41906973537e
better stamps for left shifts with fixed shift amount
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Thu, 10 Jul 2014 14:04:52 +0200 |
parents | d8aa3ea65d39 |
children | 0d3a4532a28c |
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(); |
16043
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
117 // zero is always possible |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
118 long lowerBound = Math.min(stamp1.lowerBound(), 0); |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
119 long upperBound = Math.max(stamp1.upperBound(), 0); |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
120 |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
121 long magnitude; // the maximum absolute value of the result, derived from stamp2 |
15791
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
122 if (stamp2.lowerBound() == IntegerStamp.defaultMinValue(stamp2.getBits())) { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
123 // Math.abs(...) - 1 does not work in this case |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
124 magnitude = IntegerStamp.defaultMaxValue(stamp2.getBits()); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
125 } else { |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
126 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
|
127 } |
16043
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
128 lowerBound = Math.max(lowerBound, -magnitude); |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
129 upperBound = Math.min(upperBound, magnitude); |
369a3f9d1ceb
Fix bug in inferred stamp of IntegerRemNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
16003
diff
changeset
|
130 |
15791
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
131 return StampFactory.forInteger(stamp1.getBits(), lowerBound, upperBound); |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
132 } |
308cedd2aaa2
better stamps for IntegerRemNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15380
diff
changeset
|
133 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
134 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
|
135 long result = x + y; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
136 if (bits == 64) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
137 return (~x & ~y & result) < 0; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
139 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
|
140 } |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
141 } |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
142 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
143 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
|
144 long result = x + y; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
145 if (bits == 64) { |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
146 return (x & y & ~result) < 0; |
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
147 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
148 return result < IntegerStamp.defaultMinValue(bits); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
149 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
150 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
152 public static IntegerStamp add(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
153 int bits = stamp1.getBits(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
154 assert bits == stamp2.getBits(); |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
155 |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
156 if (stamp1.isUnrestricted()) { |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
157 return stamp1; |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
158 } else if (stamp2.isUnrestricted()) { |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
159 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
|
160 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 |
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 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
|
168 newUpMask &= defaultMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 |
12677
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 lowerBound; |
e53aa17b8fdf
Fix some more problems in StampTool.add and simplify the overflow condition
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12656
diff
changeset
|
171 long upperBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
172 boolean lowerOverflowsPositively = addOverflowsPositively(stamp1.lowerBound(), stamp2.lowerBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
173 boolean upperOverflowsPositively = addOverflowsPositively(stamp1.upperBound(), stamp2.upperBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
174 boolean lowerOverflowsNegatively = addOverflowsNegatively(stamp1.lowerBound(), stamp2.lowerBound(), bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
175 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
|
176 if ((lowerOverflowsNegatively && !upperOverflowsNegatively) || (!lowerOverflowsPositively && upperOverflowsPositively)) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
177 lowerBound = IntegerStamp.defaultMinValue(bits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
178 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
|
179 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
180 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
|
181 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
|
182 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
183 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
|
184 newUpMask &= limit.upMask(); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
185 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
|
186 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
|
187 lowerBound |= newDownMask; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
188 return new IntegerStamp(bits, lowerBound, upperBound, newDownMask, newUpMask); |
10045
a4e7a7dc74f3
better stamps for OrNodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
189 } |
a4e7a7dc74f3
better stamps for OrNodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
190 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
191 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
|
192 if (stamp1.isUnrestricted() || stamp2.isUnrestricted()) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
193 return stamp1.unrestricted(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
194 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
195 return add(stamp1, (IntegerStamp) StampTool.negate(stamp2)); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
196 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
197 |
16158
d8aa3ea65d39
add stampForMask to public interface of StampTool
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16043
diff
changeset
|
198 public 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
|
199 long lowerBound; |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
200 long upperBound; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
201 if (((upMask >>> (bits - 1)) & 1) == 0) { |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
202 lowerBound = downMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
203 upperBound = upMask; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
204 } 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
|
205 lowerBound = downMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
206 upperBound = upMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
207 } else { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
208 lowerBound = downMask | (-1L << (bits - 1)); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
209 upperBound = IntegerStamp.defaultMaxValue(bits) & upMask; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
210 } |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
211 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
|
212 upperBound = IntegerConvertNode.convert(upperBound, bits, false); |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
213 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
|
214 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
215 |
11265 | 216 public static Stamp and(Stamp stamp1, Stamp stamp2) { |
217 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
218 return and((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
219 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
220 return StampFactory.illegal(); |
11265 | 221 } |
222 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
223 public static Stamp and(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
224 assert stamp1.getBits() == stamp2.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
225 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
|
226 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
227 |
11265 | 228 public static Stamp or(Stamp stamp1, Stamp stamp2) { |
229 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
230 return or((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
231 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
232 return StampFactory.illegal(); |
11265 | 233 } |
234 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
235 public static Stamp or(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
236 assert stamp1.getBits() == stamp2.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
237 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
|
238 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
239 |
11265 | 240 public static Stamp xor(Stamp stamp1, Stamp stamp2) { |
241 if (stamp1 instanceof IntegerStamp && stamp2 instanceof IntegerStamp) { | |
242 return xor((IntegerStamp) stamp1, (IntegerStamp) stamp2); | |
243 } | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
244 return StampFactory.illegal(); |
11265 | 245 } |
246 | |
7489
8461d937ac18
Better for Load/Read stamps for non-stack kinds
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7302
diff
changeset
|
247 public static Stamp xor(IntegerStamp stamp1, IntegerStamp stamp2) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
248 assert stamp1.getBits() == stamp2.getBits(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
249 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
|
250 long newDownMask = (stamp1.downMask() ^ stamp2.downMask()) & ~variableBits; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
251 long newUpMask = (stamp1.downMask() ^ stamp2.downMask()) | variableBits; |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
252 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
|
253 } |
8461d937ac18
Better for Load/Read stamps for non-stack kinds
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
7302
diff
changeset
|
254 |
11265 | 255 public static Stamp unsignedRightShift(Stamp value, Stamp shift) { |
256 if (value instanceof IntegerStamp && shift instanceof IntegerStamp) { | |
257 return unsignedRightShift((IntegerStamp) value, (IntegerStamp) shift); | |
258 } | |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
259 return value.illegal(); |
11265 | 260 } |
261 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
262 public static Stamp unsignedRightShift(IntegerStamp value, IntegerStamp shift) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
263 int bits = value.getBits(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
264 if (shift.lowerBound() == shift.upperBound()) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
265 long shiftMask = bits > 32 ? 0x3FL : 0x1FL; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
266 long shiftCount = shift.lowerBound() & shiftMask; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
267 if (shiftCount != 0) { |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
268 long lowerBound; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
269 long upperBound; |
12538
ae36dae46d50
Fix StampTool.unsignedRightShift
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
270 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
|
271 long upMask = value.upMask() >>> shiftCount; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
272 if (value.lowerBound() < 0) { |
12538
ae36dae46d50
Fix StampTool.unsignedRightShift
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
273 lowerBound = downMask; |
12562
035474349265
Serveral fixes to StampTool.add and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
12538
diff
changeset
|
274 upperBound = upMask; |
7302
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
275 } else { |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
276 lowerBound = value.lowerBound() >>> shiftCount; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
277 upperBound = value.upperBound() >>> shiftCount; |
f9f40467383e
Fixes for new Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
278 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
279 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
|
280 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
281 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
282 long mask = IntegerStamp.upMaskFor(bits, value.lowerBound(), value.upperBound()); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
283 return stampForMask(bits, 0, mask); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
284 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
285 |
11265 | 286 public static Stamp leftShift(Stamp value, Stamp shift) { |
287 if (value instanceof IntegerStamp && shift instanceof IntegerStamp) { | |
288 return leftShift((IntegerStamp) value, (IntegerStamp) shift); | |
289 } | |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
290 return value.illegal(); |
11265 | 291 } |
292 | |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
293 public static Stamp leftShift(IntegerStamp value, IntegerStamp shift) { |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
294 int bits = value.getBits(); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
295 long defaultMask = IntegerStamp.defaultMask(bits); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
296 if (value.upMask() == 0) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
297 return value; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
298 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
299 int shiftBits = bits > 32 ? 6 : 5; |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
300 long shiftMask = bits > 32 ? 0x3FL : 0x1FL; |
16452
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
301 if (shift.lowerBound() == shift.upperBound()) { |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
302 int shiftAmount = (int) (shift.lowerBound() & shiftMask); |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
303 if (shiftAmount == 0) { |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
304 return value; |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
305 } |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
306 // the mask of bits that will be lost or shifted into the sign bit |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
307 long removedBits = -1L << (bits - shiftAmount - 1); |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
308 if ((value.lowerBound() & removedBits) == 0 && (value.upperBound() & removedBits) == 0) { |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
309 // use a better stamp if neither lower nor upper bound can lose bits |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
310 return new IntegerStamp(bits, value.lowerBound() << shiftAmount, value.upperBound() << shiftAmount, value.downMask() << shiftAmount, value.upMask() << shiftAmount); |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
311 } |
41906973537e
better stamps for left shifts with fixed shift amount
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16158
diff
changeset
|
312 } |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
313 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
|
314 long downMask = defaultMask; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
315 long upMask = 0; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
316 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
|
317 if (shift.contains(i)) { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
318 downMask &= value.downMask() << (i & shiftMask); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
319 upMask |= value.upMask() << (i & shiftMask); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
320 } |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
321 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
322 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
|
323 return result; |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
324 } |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
325 return value.unrestricted(); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
326 } |
6313
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
327 |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
328 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
|
329 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
330 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
331 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
332 assert inputBits <= resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
333 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
338 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
|
339 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
340 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
341 } |
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 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
344 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
|
345 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
346 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
347 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
348 assert inputBits <= resultBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
349 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
350 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
|
351 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
|
352 |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
353 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
|
354 // signed range including 0 and -1 |
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
355 // 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
|
356 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
|
357 } |
14000
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
358 |
14015
0354f629431a
Bug fixes in StampTool.(zero|sign)Extend.
Roland Schatz <roland.schatz@oracle.com>
parents:
14010
diff
changeset
|
359 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
|
360 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
|
361 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
362 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
|
363 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
364 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
365 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
366 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
367 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
368 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
|
369 if (input instanceof IntegerStamp) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
370 IntegerStamp inputStamp = (IntegerStamp) input; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
371 int inputBits = inputStamp.getBits(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
372 assert resultBits <= inputBits; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
373 if (resultBits == inputBits) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
374 return inputStamp; |
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 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
377 final long upperBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
378 if (inputStamp.lowerBound() < IntegerStamp.defaultMinValue(resultBits)) { |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
379 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
|
380 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
381 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
|
382 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
383 final long lowerBound; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
384 if (inputStamp.upperBound() > IntegerStamp.defaultMaxValue(resultBits)) { |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
385 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
|
386 } else { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
387 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
|
388 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
389 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
390 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
|
391 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
|
392 long newUpMask = inputStamp.upMask() & defaultMask; |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
393 long newLowerBound = SignExtendNode.signExtend((lowerBound | newDownMask) & newUpMask, resultBits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
394 long newUpperBound = SignExtendNode.signExtend((upperBound | newDownMask) & newUpMask, resultBits); |
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
395 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
|
396 } else { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
397 return input.illegal(); |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
398 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
399 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
400 |
12656
9334392ed279
Refactor ConvertNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
12562
diff
changeset
|
401 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
|
402 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
|
403 final long upperBound; |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
404 if (fromStamp.lowerBound() < toKind.getMinValue()) { |
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
405 upperBound = toKind.getMaxValue(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
406 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
407 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
|
408 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
409 final long lowerBound; |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
410 if (fromStamp.upperBound() > toKind.getMaxValue()) { |
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
411 lowerBound = toKind.getMinValue(); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
412 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
413 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
|
414 } |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
415 |
13999
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
416 long defaultMask = IntegerStamp.defaultMask(toKind.getBitCount()); |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
417 long intMask = IntegerStamp.defaultMask(32); |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 } |
f2b300c6e621
Refactor Stamp hierarchy.
Roland Schatz <roland.schatz@oracle.com>
parents:
12677
diff
changeset
|
422 |
11352
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
423 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
|
424 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
|
425 return value | (-1L << valueKind.getBitCount()); |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
426 } else { |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
427 return value; |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
428 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
429 } |
8185c119d731
"always set" bit mask on IntegerStamps
Lukas Stadler <lukas.stadler@jku.at>
parents:
11265
diff
changeset
|
430 |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
431 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
|
432 if (bits < 64) { |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
433 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
|
434 if (v > max) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
435 return max; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
436 } |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
437 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
|
438 if (v < min) { |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
439 return min; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
440 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
441 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
442 return v; |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
443 } |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
444 |
958c99d0790c
Split convert node into separate nodes for different conversions.
Roland Schatz <roland.schatz@oracle.com>
parents:
13999
diff
changeset
|
445 private static long saturate(long v, Kind kind) { |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
446 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
|
447 if (v > max) { |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
448 return max; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
449 } |
6328
6e66d97a16ae
Clean up Kind class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6313
diff
changeset
|
450 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
|
451 if (v < min) { |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
452 return min; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
453 } |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
454 return v; |
7ac010ae8c97
Add inferStamp for a number of ConvertNode's operations
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
6299
diff
changeset
|
455 } |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
456 |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
457 /** |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
458 * 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
|
459 * |
14863
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
460 * @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
|
461 */ |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
462 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
|
463 IntegerStamp x = (IntegerStamp) stamp; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
464 IntegerStamp y = (IntegerStamp) stamp2; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
465 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
|
466 // Don't know anything. |
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 // 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
|
470 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
|
471 if (y.isPositive()) { |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
472 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
|
473 // 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
|
474 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
475 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
476 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
|
477 // 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
|
478 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
479 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
480 // 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
|
481 // are [c+1..-n.upperBound)]. |
15131
9c1e53adc159
Remove unsigned flag from IntegerStamp.
Roland Schatz <roland.schatz@oracle.com>
parents:
14863
diff
changeset
|
482 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
|
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 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
486 // 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
|
487 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
|
488 // 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
|
489 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
|
490 } |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
491 return null; |
ea712c41c5a2
merge unsigned compare guards with constant indexes or limits
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
14021
diff
changeset
|
492 } |
15260
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 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
495 * 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
|
496 * 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
|
497 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
498 * @param node the node to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
499 * @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
|
500 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
501 public static boolean isObjectAlwaysNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
502 return isObjectAlwaysNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
503 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
504 |
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 * 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
|
507 * 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
|
508 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
509 * @param stamp the stamp to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
510 * @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
|
511 * always null |
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 public static boolean isObjectAlwaysNull(Stamp stamp) { |
16003
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
514 if (stamp instanceof AbstractObjectStamp && stamp.isLegal()) { |
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
515 return ((AbstractObjectStamp) stamp).alwaysNull(); |
15260
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 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
518 } |
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 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
521 * 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
|
522 * 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
|
523 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
524 * @param node the node to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
525 * @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
|
526 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
527 public static boolean isObjectNonNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
528 return isObjectNonNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
529 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
530 |
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 * 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
|
533 * 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
|
534 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
535 * @param stamp the stamp to check |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
536 * @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
|
537 * always null |
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 public static boolean isObjectNonNull(Stamp stamp) { |
16003
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
540 if (stamp instanceof AbstractObjectStamp && stamp.isLegal()) { |
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
541 return ((AbstractObjectStamp) stamp).nonNull(); |
15260
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 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
544 } |
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 /** |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
547 * 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
|
548 * 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
|
549 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
550 * @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
|
551 * @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
|
552 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
553 public static ResolvedJavaType typeOrNull(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
554 return typeOrNull(node.stamp()); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
555 } |
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 /** |
15380
10c6705dbe9a
StampTool: fix typo and change "java" to "Java"
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15260
diff
changeset
|
558 * 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
|
559 * {@linkplain Stamp#isLegal() legal} Object stamp. |
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 * @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
|
562 * @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
|
563 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
564 public static ResolvedJavaType typeOrNull(Stamp stamp) { |
16003
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
565 if (stamp instanceof AbstractObjectStamp && stamp.isLegal()) { |
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
566 return ((AbstractObjectStamp) stamp).type(); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
567 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
568 return null; |
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 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
571 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
572 * 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
|
573 * 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
|
574 * {@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
|
575 * 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
|
576 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
577 * @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
|
578 * @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
|
579 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
580 public static boolean isExactType(ValueNode node) { |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
581 return isExactType(node.stamp()); |
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 |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
584 /** |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
585 * 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
|
586 * 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
|
587 * 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
|
588 * 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
|
589 * |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
590 * @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
|
591 * @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
|
592 */ |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
593 public static boolean isExactType(Stamp stamp) { |
16003
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
594 if (stamp instanceof AbstractObjectStamp && stamp.isLegal()) { |
83433cf49019
Fix incorrect null check in oop compression.
Roland Schatz <roland.schatz@oracle.com>
parents:
15791
diff
changeset
|
595 return ((AbstractObjectStamp) stamp).isExactType(); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
596 } |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
597 return false; |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
598 } |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
599 } |