• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.FillArrayData;
7 import com.android.tools.r8.code.FillArrayDataPayload;
8 import com.android.tools.r8.dex.Constants;
9 import com.android.tools.r8.ir.conversion.DexBuilder;
10 import com.android.tools.r8.utils.InternalOptions;
11 import java.util.Arrays;
12 
13 public class NewArrayFilledData extends Instruction {
14 
15   public final int element_width;
16   public final long size;
17   public final short[] data;
18 
19   // Primitive array with fill-array-data. The type is not known from the original Dex instruction.
NewArrayFilledData(Value src, int element_width, long size, short[] data)20   public NewArrayFilledData(Value src, int element_width, long size, short[] data) {
21     super(null, src);
22     this.element_width = element_width;
23     this.size = size;
24     this.data = data;
25   }
26 
src()27   public Value src() {
28     return inValues.get(0);
29   }
30 
createPayload()31   public FillArrayDataPayload createPayload() {
32     return new FillArrayDataPayload(element_width, size, data);
33   }
34 
35   @Override
buildDex(DexBuilder builder)36   public void buildDex(DexBuilder builder) {
37     int src = builder.allocatedRegister(src(), getNumber());
38     builder.addFillArrayData(this, new FillArrayData(src));
39   }
40 
41   @Override
identicalNonValueParts(Instruction other)42   public boolean identicalNonValueParts(Instruction other) {
43     NewArrayFilledData o = other.asNewArrayFilledData();
44     return o.element_width == element_width
45         && o.size == size
46         && Arrays.equals(o.data, data);
47   }
48 
49   @Override
compareNonValueParts(Instruction other)50   public int compareNonValueParts(Instruction other) {
51     NewArrayFilledData o = other.asNewArrayFilledData();
52     int result;
53     result = element_width - o.element_width;
54     if (result != 0) {
55       return result;
56     }
57     result = Long.signum(size - o.size);
58     if (result != 0) {
59       return result;
60     }
61     assert data.length == o.data.length;
62     for (int i = 0; i < data.length; i++) {
63       result = data[i] - o.data[i];
64       if (result != 0) {
65         return result;
66       }
67     }
68     return 0;
69   }
70 
71   @Override
maxInValueRegister()72   public int maxInValueRegister() {
73     return Constants.U8BIT_MAX;
74   }
75 
76   @Override
maxOutValueRegister()77   public int maxOutValueRegister() {
78     assert false : "NewArrayFilledData defines no values.";
79     return 0;
80   }
81 
82   @Override
canBeDeadCode(IRCode code, InternalOptions options)83   public boolean canBeDeadCode(IRCode code, InternalOptions options) {
84     // Side-effects its input values.
85     return false;
86   }
87 
88   @Override
isNewArrayFilledData()89   public boolean isNewArrayFilledData() {
90     return true;
91   }
92 
93   @Override
asNewArrayFilledData()94   public NewArrayFilledData asNewArrayFilledData() {
95     return this;
96   }
97 }
98