10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.lir.alloc.lsra; 24 25 /** 26 * Represents a range of integers from a start (inclusive) to an end (exclusive. 27 */ 28 public final class Range { 29 30 public static final Range EndMarker = new Range(Integer.MAX_VALUE, Integer.MAX_VALUE, null); 31 32 /** 33 * The start of the range, inclusive. 34 */ 35 public int from; 36 37 /** 38 * The end of the range, exclusive. 39 */ 40 public int to; 41 42 /** 43 * A link to allow the range to be put into a singly linked list. 44 */ 45 public Range next; 46 47 boolean intersects(Range r) { 48 return intersectsAt(r) != -1; 49 } 50 51 /** 52 * Creates a new range. 53 * 54 * @param from the start of the range, inclusive 55 * @param to the end of the range, exclusive 56 * @param next link to the next range in a linked list 57 */ 58 Range(int from, int to, Range next) { 59 this.from = from; 60 this.to = to; 61 this.next = next; 62 } 63 64 int intersectsAt(Range other) { 65 Range r1 = this; 66 Range r2 = other; 67 68 assert r2 != null : "null ranges not allowed"; 69 assert r1 != EndMarker && r2 != EndMarker : "empty ranges not allowed"; 70 71 do { 72 if (r1.from < r2.from) { 73 if (r1.to <= r2.from) { 74 r1 = r1.next; 75 if (r1 == EndMarker) { 76 return -1; 77 } 78 } else { 79 return r2.from; 80 } 81 } else { 82 if (r2.from < r1.from) { 83 if (r2.to <= r1.from) { 84 r2 = r2.next; 85 if (r2 == EndMarker) { 86 return -1; 87 } 88 } else { 89 return r1.from; 90 } 91 } else { // r1.from() == r2.from() 92 if (r1.from == r1.to) { 93 r1 = r1.next; 94 if (r1 == EndMarker) { 95 return -1; 96 } 97 } else { 98 if (r2.from == r2.to) { 99 r2 = r2.next; 100 if (r2 == EndMarker) { 101 return -1; 102 } 103 } else { 104 return r1.from; 105 } 106 } 107 } 108 } 109 } while (true); 110 } 111 112 @Override 113 public String toString() { 114 return "[" + from + ", " + to + "]"; 115 } 116 } | 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.lir.alloc.lsra; 24 25 /** 26 * Represents a range of integers from a start (inclusive) to an end (exclusive. 27 */ 28 public final class Range { 29 30 /** 31 * The start of the range, inclusive. 32 */ 33 public int from; 34 35 /** 36 * The end of the range, exclusive. 37 */ 38 public int to; 39 40 /** 41 * A link to allow the range to be put into a singly linked list. 42 */ 43 public Range next; 44 45 boolean intersects(Range r) { 46 return intersectsAt(r) != -1; 47 } 48 49 /** 50 * Creates a new range. 51 * 52 * @param from the start of the range, inclusive 53 * @param to the end of the range, exclusive 54 * @param next link to the next range in a linked list 55 */ 56 Range(int from, int to, Range next) { 57 this.from = from; 58 this.to = to; 59 this.next = next; 60 } 61 62 public boolean isEndMarker() { 63 assert from != Integer.MAX_VALUE || (to == Integer.MAX_VALUE && next == null); 64 return from == Integer.MAX_VALUE; 65 } 66 67 int intersectsAt(Range other) { 68 Range r1 = this; 69 Range r2 = other; 70 71 assert r2 != null : "null ranges not allowed"; 72 assert !r1.isEndMarker() && !r2.isEndMarker() : "empty ranges not allowed"; 73 74 do { 75 if (r1.from < r2.from) { 76 if (r1.to <= r2.from) { 77 r1 = r1.next; 78 if (r1.isEndMarker()) { 79 return -1; 80 } 81 } else { 82 return r2.from; 83 } 84 } else { 85 if (r2.from < r1.from) { 86 if (r2.to <= r1.from) { 87 r2 = r2.next; 88 if (r2.isEndMarker()) { 89 return -1; 90 } 91 } else { 92 return r1.from; 93 } 94 } else { // r1.from() == r2.from() 95 if (r1.from == r1.to) { 96 r1 = r1.next; 97 if (r1.isEndMarker()) { 98 return -1; 99 } 100 } else { 101 if (r2.from == r2.to) { 102 r2 = r2.next; 103 if (r2.isEndMarker()) { 104 return -1; 105 } 106 } else { 107 return r1.from; 108 } 109 } 110 } 111 } 112 } while (true); 113 } 114 115 @Override 116 public String toString() { 117 return "[" + from + ", " + to + "]"; 118 } 119 } |