Rewrite register hint to int

Change-Id: I912882d18634dbe6eab79746e0fea77ad604dcc7
diff --git a/src/main/java/com/android/tools/r8/cf/CfRegisterAllocator.java b/src/main/java/com/android/tools/r8/cf/CfRegisterAllocator.java
index ad077ea..418fcea 100644
--- a/src/main/java/com/android/tools/r8/cf/CfRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/cf/CfRegisterAllocator.java
@@ -319,7 +319,7 @@
 
   private void updateHints(LiveIntervals intervals) {
     for (Phi phi : intervals.getValue().uniquePhiUsers()) {
-      if (!phi.isValueOnStack() && phi.getLiveIntervals().getHint() == null) {
+      if (!phi.isValueOnStack() && !phi.getLiveIntervals().hasHint()) {
         phi.getLiveIntervals().setHint(intervals, unhandled);
         for (Value value : phi.getOperands()) {
           value.getLiveIntervals().setHint(intervals, unhandled);
@@ -329,7 +329,7 @@
   }
 
   private boolean tryHint(LiveIntervals unhandled) {
-    if (unhandled.getHint() == null) {
+    if (!unhandled.hasHint()) {
       return false;
     }
     boolean isWide = unhandled.getType().isWide();
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
index fe545c4..31fe227 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
@@ -1302,7 +1302,7 @@
   }
 
   private void setHintForDestRegOfCheckCast(LiveIntervals unhandledInterval) {
-    if (unhandledInterval.getHint() != null) {
+    if (unhandledInterval.hasHint()) {
       return;
     }
     Value value = unhandledInterval.getValue();
@@ -1322,7 +1322,7 @@
    * that is the left interval or the right interval if possible when intervals do not overlap.
    */
   private void setHintToPromote2AddrInstruction(LiveIntervals unhandledInterval) {
-    if (unhandledInterval.getHint() != null) {
+    if (unhandledInterval.hasHint()) {
       return;
     }
     Value value = unhandledInterval.getValue();
@@ -2355,14 +2355,14 @@
     // phi and do not have hints yet.
     for (Phi phi : value.uniquePhiUsers()) {
       LiveIntervals phiIntervals = phi.getLiveIntervals();
-      if (phiIntervals.getHint() == null) {
+      if (!phiIntervals.hasHint()) {
         phiIntervals.setHint(intervals, unhandled);
         for (int i = 0; i < phi.getOperands().size(); i++) {
           Value operand = phi.getOperand(i);
           LiveIntervals operandIntervals = operand.getLiveIntervals();
           BasicBlock pred = phi.getBlock().getPredecessors().get(i);
           operandIntervals = operandIntervals.getSplitCovering(pred.exit().getNumber());
-          if (operandIntervals.getHint() == null) {
+          if (!operandIntervals.hasHint()) {
             operandIntervals.setHint(intervals, unhandled);
           }
         }
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java b/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
index 4ecc6bd..3a8f340 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LiveIntervals.java
@@ -39,7 +39,7 @@
   private List<LiveRange> ranges = new ArrayList<>();
   private final TreeSet<LiveIntervalsUse> uses = new TreeSet<>();
   private int register = NO_REGISTER;
-  private Integer hint;
+  private int hint = NO_REGISTER;
   private boolean spilled = false;
   private boolean isInvokeRangeIntervals = false;
   private boolean usedInMonitorOperations = false;
@@ -87,6 +87,7 @@
   }
 
   public void setHint(LiveIntervals intervals, PriorityQueue<LiveIntervals> unhandled) {
+    assert intervals.hasRegister();
     // Do not set hints if they cannot be used anyway.
     if (!overlaps(intervals)) {
       // The hint is used in sorting the unhandled intervals. Therefore, if the hint changes
@@ -100,10 +101,11 @@
   }
 
   public boolean hasHint() {
-    return hint != null;
+    return hint != NO_REGISTER;
   }
 
-  public Integer getHint() {
+  public int getHint() {
+    assert hasHint();
     return hint;
   }
 
@@ -355,7 +357,7 @@
 
   public void clearRegisterAssignment() {
     register = NO_REGISTER;
-    hint = null;
+    hint = NO_REGISTER;
   }
 
   public boolean overlapsPosition(int position) {
@@ -595,14 +597,14 @@
     if (startDiff != 0) return startDiff;
     // Then sort by register number of hints to make sure that a phi
     // does not take a low register that is the hint for another phi.
-    if (hint != null && other.hint != null) {
-      int registerDiff = hint - other.hint;
+    if (hasHint() && other.hasHint()) {
+      int registerDiff = getHint() - other.getHint();
       if (registerDiff != 0) return registerDiff;
     }
     // Intervals with hints go first so intervals without hints
     // do not take registers from intervals with hints.
-    if (hint != null && other.hint == null) return -1;
-    if (hint == null && other.hint != null) return 1;
+    if (hasHint() && !other.hasHint()) return -1;
+    if (!hasHint() && other.hasHint()) return 1;
     // Tie-breaker: no values have equal numbers.
     int result = value.getNumber() - other.value.getNumber();
     assert result != 0;