1 // Copyright (c) 2016, 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 package com.android.tools.r8.ir.code; 5 6 import com.android.tools.r8.code.NewArray; 7 import com.android.tools.r8.dex.Constants; 8 import com.android.tools.r8.graph.DexType; 9 import com.android.tools.r8.ir.conversion.DexBuilder; 10 11 public class NewArrayEmpty extends Instruction { 12 13 public final DexType type; 14 15 public NewArrayEmpty(Value dest, Value size, DexType type) { 16 super(dest, size); 17 dest.markNeverNull(); 18 this.type = type; 19 } 20 21 public Value dest() { 22 return outValue; 23 } 24 25 public Value size() { 26 return inValues.get(0); 27 } 28 29 @Override 30 public void buildDex(DexBuilder builder) { 31 int size = builder.allocatedRegister(size(), getNumber()); 32 int dest = builder.allocatedRegister(dest(), getNumber()); 33 builder.add(this, new NewArray(dest, size, type)); 34 } 35 36 @Override 37 public int maxInValueRegister() { 38 return Constants.U4BIT_MAX; 39 } 40 41 @Override 42 public int maxOutValueRegister() { 43 return Constants.U4BIT_MAX; 44 } 45 46 @Override 47 public boolean instructionTypeCanThrow() { 48 // new-array throws if its size is negative, but can also potentially throw on out-of-memory. 49 return true; 50 } 51 52 @Override 53 public boolean identicalNonValueParts(Instruction other) { 54 return other.asNewArrayEmpty().type == type; 55 } 56 57 @Override 58 public int compareNonValueParts(Instruction other) { 59 return type.slowCompareTo(other.asNewArrayEmpty().type); 60 } 61 62 @Override 63 public boolean isNewArrayEmpty() { 64 return true; 65 } 66 67 @Override 68 public NewArrayEmpty asNewArrayEmpty() { 69 return this; 70 } 71 } 72