aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervalsUse.java
blob: edf876ded13e927414be7de4e7e585d99e11abd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.regalloc;

import static com.android.tools.r8.dex.Constants.U16BIT_MAX;

public class LiveIntervalsUse implements Comparable<LiveIntervalsUse> {
  private final int position;
  private final int limit;
  private final boolean debugUse;

  public LiveIntervalsUse(int position, int limit) {
    this(position, limit, false);
  }

  public LiveIntervalsUse(int position, int limit, boolean debugUse) {
    this.position = position;
    this.limit = limit;
    this.debugUse = debugUse;
  }

  public int getPosition() {
    return position;
  }

  public int getLimit() {
    return limit;
  }

  @Override
  public int hashCode() {
    return position + limit * 7;
  }

  @Override
  public boolean equals(Object other) {
    if (!(other instanceof LiveIntervalsUse)) {
      return false;
    }
    LiveIntervalsUse o = (LiveIntervalsUse) other;
    return o.position == position && o.limit == limit;
  }

  @Override
  public int compareTo(LiveIntervalsUse o) {
    if (o.position != position) {
      return position - o.position;
    }
    return limit - o.limit;
  }

  public boolean hasConstraint() {
    return limit < U16BIT_MAX;
  }

  public boolean isDebugUse() {
    return debugUse;
  }
}