1 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file 2 // for details. All rights reserved. Use of this source code is governed by a 3 // BSD-style license that can be found in the LICENSE file. 4 5 package com.android.tools.r8.ir.regalloc; 6 7 import com.android.tools.r8.ir.code.MoveType; 8 9 /** 10 * A SpillMove represents either a phi move that transfers an SSA value to the SSA phi value or 11 * a spill or restore move that transfers the same SSA value between different registers because 12 * of spilling. 13 */ 14 class SpillMove { 15 MoveType type; 16 LiveIntervals from; 17 LiveIntervals to; 18 SpillMove(MoveType type, LiveIntervals to, LiveIntervals from)19 public SpillMove(MoveType type, LiveIntervals to, LiveIntervals from) { 20 this.type = type; 21 this.to = to; 22 this.from = from; 23 assert to.getRegister() != LinearScanRegisterAllocator.NO_REGISTER; 24 assert from.getRegister() != LinearScanRegisterAllocator.NO_REGISTER; 25 } 26 27 @Override hashCode()28 public int hashCode() { 29 return type.hashCode() + 3 * from.getRegister() + 5 * to.getRegister(); 30 } 31 updateMaxNonSpilled()32 public void updateMaxNonSpilled() { 33 int maxFrom = from.getMaxNonSpilledRegister(); 34 int maxTo = to.getMaxNonSpilledRegister(); 35 if (maxFrom > maxTo) { 36 to.setMaxNonSpilledRegister(maxFrom); 37 } else { 38 from.setMaxNonSpilledRegister(maxTo); 39 } 40 } 41 42 @Override equals(Object other)43 public boolean equals(Object other) { 44 if (other == this) { 45 return true; 46 } 47 if (!(other instanceof SpillMove)) { 48 return false; 49 } 50 SpillMove o = (SpillMove) other; 51 return type == o.type 52 && from.getRegister() == o.from.getRegister() 53 && to.getRegister() == o.to.getRegister() 54 && from.getSplitParent() == o.from.getSplitParent() 55 && to.getSplitParent() == o.to.getSplitParent(); 56 } 57 58 @Override toString()59 public String toString() { 60 return to.getRegister() + " <- " + from.getRegister() + " (" + type + ")"; 61 } 62 } 63