blob: 5ec5bc28b2d17d8094d6573e4bd6b80731768faa [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
buzbeeeaf09bc2012-11-15 14:51:41 -080017#include "compiler_internals.h"
buzbeeefc63692012-11-14 16:31:52 -080018#include "dataflow.h"
buzbee67bf8852011-08-17 17:51:35 -070019
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080020namespace art {
21
buzbee67bf8852011-08-17 17:51:35 -070022/*
23 * Main table containing data flow attributes for each bytecode. The
24 * first kNumPackedOpcodes entries are for Dalvik bytecode
25 * instructions, where extended opcode at the MIR level are appended
26 * afterwards.
27 *
28 * TODO - many optimization flags are incomplete - they will only limit the
29 * scope of optimizations but will not cause mis-optimizations.
30 */
buzbeeba938cb2012-02-03 14:47:55 -080031const int oatDataFlowAttributes[kMirOpLast] = {
Bill Buzbeea114add2012-05-03 15:00:40 -070032 // 00 NOP
33 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -070034
Bill Buzbeea114add2012-05-03 15:00:40 -070035 // 01 MOVE vA, vB
36 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070037
Bill Buzbeea114add2012-05-03 15:00:40 -070038 // 02 MOVE_FROM16 vAA, vBBBB
39 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070040
Bill Buzbeea114add2012-05-03 15:00:40 -070041 // 03 MOVE_16 vAAAA, vBBBB
42 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070043
Bill Buzbeea114add2012-05-03 15:00:40 -070044 // 04 MOVE_WIDE vA, vB
buzbeebff24652012-05-06 16:22:05 -070045 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070046
Bill Buzbeea114add2012-05-03 15:00:40 -070047 // 05 MOVE_WIDE_FROM16 vAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070048 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070049
Bill Buzbeea114add2012-05-03 15:00:40 -070050 // 06 MOVE_WIDE_16 vAAAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070051 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070052
Bill Buzbeea114add2012-05-03 15:00:40 -070053 // 07 MOVE_OBJECT vA, vB
buzbeebff24652012-05-06 16:22:05 -070054 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070055
Bill Buzbeea114add2012-05-03 15:00:40 -070056 // 08 MOVE_OBJECT_FROM16 vAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070057 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070058
Bill Buzbeea114add2012-05-03 15:00:40 -070059 // 09 MOVE_OBJECT_16 vAAAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070060 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070061
Bill Buzbeea114add2012-05-03 15:00:40 -070062 // 0A MOVE_RESULT vAA
63 DF_DA,
buzbee67bf8852011-08-17 17:51:35 -070064
Bill Buzbeea114add2012-05-03 15:00:40 -070065 // 0B MOVE_RESULT_WIDE vAA
buzbeebff24652012-05-06 16:22:05 -070066 DF_DA | DF_A_WIDE,
buzbee67bf8852011-08-17 17:51:35 -070067
Bill Buzbeea114add2012-05-03 15:00:40 -070068 // 0C MOVE_RESULT_OBJECT vAA
buzbeebff24652012-05-06 16:22:05 -070069 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070070
Bill Buzbeea114add2012-05-03 15:00:40 -070071 // 0D MOVE_EXCEPTION vAA
buzbee2a83e8f2012-07-13 16:42:30 -070072 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070073
Bill Buzbeea114add2012-05-03 15:00:40 -070074 // 0E RETURN_VOID
75 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -070076
Bill Buzbeea114add2012-05-03 15:00:40 -070077 // 0F RETURN vAA
78 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -070079
Bill Buzbeea114add2012-05-03 15:00:40 -070080 // 10 RETURN_WIDE vAA
buzbeebff24652012-05-06 16:22:05 -070081 DF_UA | DF_A_WIDE,
buzbee67bf8852011-08-17 17:51:35 -070082
Bill Buzbeea114add2012-05-03 15:00:40 -070083 // 11 RETURN_OBJECT vAA
buzbeebff24652012-05-06 16:22:05 -070084 DF_UA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070085
Bill Buzbeea114add2012-05-03 15:00:40 -070086 // 12 CONST_4 vA, #+B
87 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070088
Bill Buzbeea114add2012-05-03 15:00:40 -070089 // 13 CONST_16 vAA, #+BBBB
90 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070091
Bill Buzbeea114add2012-05-03 15:00:40 -070092 // 14 CONST vAA, #+BBBBBBBB
93 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070094
Bill Buzbeea114add2012-05-03 15:00:40 -070095 // 15 CONST_HIGH16 VAA, #+BBBB0000
96 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070097
Bill Buzbeea114add2012-05-03 15:00:40 -070098 // 16 CONST_WIDE_16 vAA, #+BBBB
buzbeebff24652012-05-06 16:22:05 -070099 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700100
Bill Buzbeea114add2012-05-03 15:00:40 -0700101 // 17 CONST_WIDE_32 vAA, #+BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700102 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700103
Bill Buzbeea114add2012-05-03 15:00:40 -0700104 // 18 CONST_WIDE vAA, #+BBBBBBBBBBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700105 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700106
Bill Buzbeea114add2012-05-03 15:00:40 -0700107 // 19 CONST_WIDE_HIGH16 vAA, #+BBBB000000000000
buzbeebff24652012-05-06 16:22:05 -0700108 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700109
Bill Buzbeea114add2012-05-03 15:00:40 -0700110 // 1A CONST_STRING vAA, string@BBBB
buzbeebff24652012-05-06 16:22:05 -0700111 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700112
Bill Buzbeea114add2012-05-03 15:00:40 -0700113 // 1B CONST_STRING_JUMBO vAA, string@BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700114 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700115
Bill Buzbeea114add2012-05-03 15:00:40 -0700116 // 1C CONST_CLASS vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700117 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700118
Bill Buzbeea114add2012-05-03 15:00:40 -0700119 // 1D MONITOR_ENTER vAA
buzbeebff24652012-05-06 16:22:05 -0700120 DF_UA | DF_NULL_CHK_0 | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700121
Bill Buzbeea114add2012-05-03 15:00:40 -0700122 // 1E MONITOR_EXIT vAA
buzbeebff24652012-05-06 16:22:05 -0700123 DF_UA | DF_NULL_CHK_0 | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700124
Bill Buzbeea114add2012-05-03 15:00:40 -0700125 // 1F CHK_CAST vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700126 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700127
Bill Buzbeea114add2012-05-03 15:00:40 -0700128 // 20 INSTANCE_OF vA, vB, type@CCCC
buzbeebff24652012-05-06 16:22:05 -0700129 DF_DA | DF_UB | DF_CORE_A | DF_REF_B | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700130
Bill Buzbeea114add2012-05-03 15:00:40 -0700131 // 21 ARRAY_LENGTH vA, vB
buzbeebff24652012-05-06 16:22:05 -0700132 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_CORE_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700133
Bill Buzbeea114add2012-05-03 15:00:40 -0700134 // 22 NEW_INSTANCE vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700135 DF_DA | DF_NON_NULL_DST | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700136
Bill Buzbeea114add2012-05-03 15:00:40 -0700137 // 23 NEW_ARRAY vA, vB, type@CCCC
buzbeebff24652012-05-06 16:22:05 -0700138 DF_DA | DF_UB | DF_NON_NULL_DST | DF_REF_A | DF_CORE_B | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700139
Bill Buzbeea114add2012-05-03 15:00:40 -0700140 // 24 FILLED_NEW_ARRAY {vD, vE, vF, vG, vA}
141 DF_FORMAT_35C | DF_NON_NULL_RET | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700142
Bill Buzbeea114add2012-05-03 15:00:40 -0700143 // 25 FILLED_NEW_ARRAY_RANGE {vCCCC .. vNNNN}, type@BBBB
144 DF_FORMAT_3RC | DF_NON_NULL_RET | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700145
Bill Buzbeea114add2012-05-03 15:00:40 -0700146 // 26 FILL_ARRAY_DATA vAA, +BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700147 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700148
Bill Buzbeea114add2012-05-03 15:00:40 -0700149 // 27 THROW vAA
buzbeebff24652012-05-06 16:22:05 -0700150 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700151
Bill Buzbeea114add2012-05-03 15:00:40 -0700152 // 28 GOTO
153 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700154
Bill Buzbeea114add2012-05-03 15:00:40 -0700155 // 29 GOTO_16
156 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700157
Bill Buzbeea114add2012-05-03 15:00:40 -0700158 // 2A GOTO_32
159 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700160
Bill Buzbeea114add2012-05-03 15:00:40 -0700161 // 2B PACKED_SWITCH vAA, +BBBBBBBB
162 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700163
Bill Buzbeea114add2012-05-03 15:00:40 -0700164 // 2C SPARSE_SWITCH vAA, +BBBBBBBB
165 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700166
Bill Buzbeea114add2012-05-03 15:00:40 -0700167 // 2D CMPL_FLOAT vAA, vBB, vCC
168 DF_DA | DF_UB | DF_UC | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700169
Bill Buzbeea114add2012-05-03 15:00:40 -0700170 // 2E CMPG_FLOAT vAA, vBB, vCC
171 DF_DA | DF_UB | DF_UC | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700172
Bill Buzbeea114add2012-05-03 15:00:40 -0700173 // 2F CMPL_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700174 DF_DA | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700175
Bill Buzbeea114add2012-05-03 15:00:40 -0700176 // 30 CMPG_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700177 DF_DA | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700178
Bill Buzbeea114add2012-05-03 15:00:40 -0700179 // 31 CMP_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700180 DF_DA | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700181
Bill Buzbeea114add2012-05-03 15:00:40 -0700182 // 32 IF_EQ vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700183 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700184
Bill Buzbeea114add2012-05-03 15:00:40 -0700185 // 33 IF_NE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700186 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700187
Bill Buzbeea114add2012-05-03 15:00:40 -0700188 // 34 IF_LT vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700189 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700190
Bill Buzbeea114add2012-05-03 15:00:40 -0700191 // 35 IF_GE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700192 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700193
Bill Buzbeea114add2012-05-03 15:00:40 -0700194 // 36 IF_GT vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700195 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700196
Bill Buzbeea114add2012-05-03 15:00:40 -0700197 // 37 IF_LE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700198 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700199
Bill Buzbeea114add2012-05-03 15:00:40 -0700200 // 38 IF_EQZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700201 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700202
Bill Buzbeea114add2012-05-03 15:00:40 -0700203 // 39 IF_NEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700204 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700205
Bill Buzbeea114add2012-05-03 15:00:40 -0700206 // 3A IF_LTZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700207 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700208
Bill Buzbeea114add2012-05-03 15:00:40 -0700209 // 3B IF_GEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700210 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700211
Bill Buzbeea114add2012-05-03 15:00:40 -0700212 // 3C IF_GTZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700213 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700214
Bill Buzbeea114add2012-05-03 15:00:40 -0700215 // 3D IF_LEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700216 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700217
Bill Buzbeea114add2012-05-03 15:00:40 -0700218 // 3E UNUSED_3E
219 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700220
Bill Buzbeea114add2012-05-03 15:00:40 -0700221 // 3F UNUSED_3F
222 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700223
Bill Buzbeea114add2012-05-03 15:00:40 -0700224 // 40 UNUSED_40
225 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700226
Bill Buzbeea114add2012-05-03 15:00:40 -0700227 // 41 UNUSED_41
228 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700229
Bill Buzbeea114add2012-05-03 15:00:40 -0700230 // 42 UNUSED_42
231 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700232
Bill Buzbeea114add2012-05-03 15:00:40 -0700233 // 43 UNUSED_43
234 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700235
Bill Buzbeea114add2012-05-03 15:00:40 -0700236 // 44 AGET vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700237 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700238
Bill Buzbeea114add2012-05-03 15:00:40 -0700239 // 45 AGET_WIDE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700240 DF_DA | DF_A_WIDE | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700241
Bill Buzbeea114add2012-05-03 15:00:40 -0700242 // 46 AGET_OBJECT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700243 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_A | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700244
Bill Buzbeea114add2012-05-03 15:00:40 -0700245 // 47 AGET_BOOLEAN vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700246 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700247
Bill Buzbeea114add2012-05-03 15:00:40 -0700248 // 48 AGET_BYTE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700249 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700250
Bill Buzbeea114add2012-05-03 15:00:40 -0700251 // 49 AGET_CHAR vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700252 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700253
Bill Buzbeea114add2012-05-03 15:00:40 -0700254 // 4A AGET_SHORT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700255 DF_DA | DF_UB | DF_UC | DF_NULL_CHK_0 | DF_RANGE_CHK_1 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700256
Bill Buzbeea114add2012-05-03 15:00:40 -0700257 // 4B APUT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700258 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700259
Bill Buzbeea114add2012-05-03 15:00:40 -0700260 // 4C APUT_WIDE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700261 DF_UA | DF_A_WIDE | DF_UB | DF_UC | DF_NULL_CHK_2 | DF_RANGE_CHK_3 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700262
Bill Buzbeea114add2012-05-03 15:00:40 -0700263 // 4D APUT_OBJECT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700264 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_A | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700265
Bill Buzbeea114add2012-05-03 15:00:40 -0700266 // 4E APUT_BOOLEAN vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700267 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700268
Bill Buzbeea114add2012-05-03 15:00:40 -0700269 // 4F APUT_BYTE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700270 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700271
Bill Buzbeea114add2012-05-03 15:00:40 -0700272 // 50 APUT_CHAR vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700273 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700274
Bill Buzbeea114add2012-05-03 15:00:40 -0700275 // 51 APUT_SHORT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700276 DF_UA | DF_UB | DF_UC | DF_NULL_CHK_1 | DF_RANGE_CHK_2 | DF_REF_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700277
Bill Buzbeea114add2012-05-03 15:00:40 -0700278 // 52 IGET vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700279 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700280
Bill Buzbeea114add2012-05-03 15:00:40 -0700281 // 53 IGET_WIDE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700282 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700283
Bill Buzbeea114add2012-05-03 15:00:40 -0700284 // 54 IGET_OBJECT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700285 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700286
Bill Buzbeea114add2012-05-03 15:00:40 -0700287 // 55 IGET_BOOLEAN vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700288 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700289
Bill Buzbeea114add2012-05-03 15:00:40 -0700290 // 56 IGET_BYTE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700291 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700292
Bill Buzbeea114add2012-05-03 15:00:40 -0700293 // 57 IGET_CHAR vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700294 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700295
Bill Buzbeea114add2012-05-03 15:00:40 -0700296 // 58 IGET_SHORT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700297 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700298
Bill Buzbeea114add2012-05-03 15:00:40 -0700299 // 59 IPUT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700300 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700301
Bill Buzbeea114add2012-05-03 15:00:40 -0700302 // 5A IPUT_WIDE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700303 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700304
Bill Buzbeea114add2012-05-03 15:00:40 -0700305 // 5B IPUT_OBJECT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700306 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700307
Bill Buzbeea114add2012-05-03 15:00:40 -0700308 // 5C IPUT_BOOLEAN vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700309 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700310
Bill Buzbeea114add2012-05-03 15:00:40 -0700311 // 5D IPUT_BYTE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700312 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700313
Bill Buzbeea114add2012-05-03 15:00:40 -0700314 // 5E IPUT_CHAR vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700315 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700316
Bill Buzbeea114add2012-05-03 15:00:40 -0700317 // 5F IPUT_SHORT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700318 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700319
Bill Buzbeea114add2012-05-03 15:00:40 -0700320 // 60 SGET vAA, field@BBBB
321 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700322
Bill Buzbeea114add2012-05-03 15:00:40 -0700323 // 61 SGET_WIDE vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700324 DF_DA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700325
Bill Buzbeea114add2012-05-03 15:00:40 -0700326 // 62 SGET_OBJECT vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700327 DF_DA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700328
Bill Buzbeea114add2012-05-03 15:00:40 -0700329 // 63 SGET_BOOLEAN vAA, field@BBBB
330 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700331
Bill Buzbeea114add2012-05-03 15:00:40 -0700332 // 64 SGET_BYTE vAA, field@BBBB
333 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700334
Bill Buzbeea114add2012-05-03 15:00:40 -0700335 // 65 SGET_CHAR vAA, field@BBBB
336 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700337
Bill Buzbeea114add2012-05-03 15:00:40 -0700338 // 66 SGET_SHORT vAA, field@BBBB
339 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700340
Bill Buzbeea114add2012-05-03 15:00:40 -0700341 // 67 SPUT vAA, field@BBBB
342 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700343
Bill Buzbeea114add2012-05-03 15:00:40 -0700344 // 68 SPUT_WIDE vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700345 DF_UA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700346
Bill Buzbeea114add2012-05-03 15:00:40 -0700347 // 69 SPUT_OBJECT vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700348 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700349
Bill Buzbeea114add2012-05-03 15:00:40 -0700350 // 6A SPUT_BOOLEAN vAA, field@BBBB
351 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700352
Bill Buzbeea114add2012-05-03 15:00:40 -0700353 // 6B SPUT_BYTE vAA, field@BBBB
354 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700355
Bill Buzbeea114add2012-05-03 15:00:40 -0700356 // 6C SPUT_CHAR vAA, field@BBBB
357 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700358
Bill Buzbeea114add2012-05-03 15:00:40 -0700359 // 6D SPUT_SHORT vAA, field@BBBB
360 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700361
Bill Buzbeea114add2012-05-03 15:00:40 -0700362 // 6E INVOKE_VIRTUAL {vD, vE, vF, vG, vA}
363 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700364
Bill Buzbeea114add2012-05-03 15:00:40 -0700365 // 6F INVOKE_SUPER {vD, vE, vF, vG, vA}
366 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700367
Bill Buzbeea114add2012-05-03 15:00:40 -0700368 // 70 INVOKE_DIRECT {vD, vE, vF, vG, vA}
369 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700370
Bill Buzbeea114add2012-05-03 15:00:40 -0700371 // 71 INVOKE_STATIC {vD, vE, vF, vG, vA}
372 DF_FORMAT_35C | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700373
Bill Buzbeea114add2012-05-03 15:00:40 -0700374 // 72 INVOKE_INTERFACE {vD, vE, vF, vG, vA}
375 DF_FORMAT_35C | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700376
Bill Buzbeea114add2012-05-03 15:00:40 -0700377 // 73 UNUSED_73
378 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700379
Bill Buzbeea114add2012-05-03 15:00:40 -0700380 // 74 INVOKE_VIRTUAL_RANGE {vCCCC .. vNNNN}
381 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700382
Bill Buzbeea114add2012-05-03 15:00:40 -0700383 // 75 INVOKE_SUPER_RANGE {vCCCC .. vNNNN}
384 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700385
Bill Buzbeea114add2012-05-03 15:00:40 -0700386 // 76 INVOKE_DIRECT_RANGE {vCCCC .. vNNNN}
387 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700388
Bill Buzbeea114add2012-05-03 15:00:40 -0700389 // 77 INVOKE_STATIC_RANGE {vCCCC .. vNNNN}
390 DF_FORMAT_3RC | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700391
Bill Buzbeea114add2012-05-03 15:00:40 -0700392 // 78 INVOKE_INTERFACE_RANGE {vCCCC .. vNNNN}
393 DF_FORMAT_3RC | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700394
Bill Buzbeea114add2012-05-03 15:00:40 -0700395 // 79 UNUSED_79
396 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700397
Bill Buzbeea114add2012-05-03 15:00:40 -0700398 // 7A UNUSED_7A
399 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700400
Bill Buzbeea114add2012-05-03 15:00:40 -0700401 // 7B NEG_INT vA, vB
402 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700403
Bill Buzbeea114add2012-05-03 15:00:40 -0700404 // 7C NOT_INT vA, vB
405 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700406
Bill Buzbeea114add2012-05-03 15:00:40 -0700407 // 7D NEG_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700408 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700409
Bill Buzbeea114add2012-05-03 15:00:40 -0700410 // 7E NOT_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700411 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700412
Bill Buzbeea114add2012-05-03 15:00:40 -0700413 // 7F NEG_FLOAT vA, vB
414 DF_DA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700415
Bill Buzbeea114add2012-05-03 15:00:40 -0700416 // 80 NEG_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700417 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700418
Bill Buzbeea114add2012-05-03 15:00:40 -0700419 // 81 INT_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700420 DF_DA | DF_A_WIDE | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700421
Bill Buzbeea114add2012-05-03 15:00:40 -0700422 // 82 INT_TO_FLOAT vA, vB
423 DF_DA | DF_UB | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700424
Bill Buzbeea114add2012-05-03 15:00:40 -0700425 // 83 INT_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700426 DF_DA | DF_A_WIDE | DF_UB | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700427
Bill Buzbeea114add2012-05-03 15:00:40 -0700428 // 84 LONG_TO_INT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700429 DF_DA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700430
Bill Buzbeea114add2012-05-03 15:00:40 -0700431 // 85 LONG_TO_FLOAT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700432 DF_DA | DF_UB | DF_B_WIDE | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700433
Bill Buzbeea114add2012-05-03 15:00:40 -0700434 // 86 LONG_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700435 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700436
Bill Buzbeea114add2012-05-03 15:00:40 -0700437 // 87 FLOAT_TO_INT vA, vB
438 DF_DA | DF_UB | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700439
Bill Buzbeea114add2012-05-03 15:00:40 -0700440 // 88 FLOAT_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700441 DF_DA | DF_A_WIDE | DF_UB | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700442
Bill Buzbeea114add2012-05-03 15:00:40 -0700443 // 89 FLOAT_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700444 DF_DA | DF_A_WIDE | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700445
Bill Buzbeea114add2012-05-03 15:00:40 -0700446 // 8A DOUBLE_TO_INT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700447 DF_DA | DF_UB | DF_B_WIDE | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700448
Bill Buzbeea114add2012-05-03 15:00:40 -0700449 // 8B DOUBLE_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700450 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700451
Bill Buzbeea114add2012-05-03 15:00:40 -0700452 // 8C DOUBLE_TO_FLOAT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700453 DF_DA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700454
Bill Buzbeea114add2012-05-03 15:00:40 -0700455 // 8D INT_TO_BYTE vA, vB
456 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700457
Bill Buzbeea114add2012-05-03 15:00:40 -0700458 // 8E INT_TO_CHAR vA, vB
459 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700460
Bill Buzbeea114add2012-05-03 15:00:40 -0700461 // 8F INT_TO_SHORT vA, vB
462 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700463
Bill Buzbeea114add2012-05-03 15:00:40 -0700464 // 90 ADD_INT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700465 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700466
Bill Buzbeea114add2012-05-03 15:00:40 -0700467 // 91 SUB_INT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700468 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700469
Bill Buzbeea114add2012-05-03 15:00:40 -0700470 // 92 MUL_INT vAA, vBB, vCC
471 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700472
Bill Buzbeea114add2012-05-03 15:00:40 -0700473 // 93 DIV_INT vAA, vBB, vCC
474 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700475
Bill Buzbeea114add2012-05-03 15:00:40 -0700476 // 94 REM_INT vAA, vBB, vCC
477 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700478
Bill Buzbeea114add2012-05-03 15:00:40 -0700479 // 95 AND_INT vAA, vBB, vCC
480 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700481
Bill Buzbeea114add2012-05-03 15:00:40 -0700482 // 96 OR_INT vAA, vBB, vCC
483 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700484
Bill Buzbeea114add2012-05-03 15:00:40 -0700485 // 97 XOR_INT vAA, vBB, vCC
486 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700487
Bill Buzbeea114add2012-05-03 15:00:40 -0700488 // 98 SHL_INT vAA, vBB, vCC
489 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700490
Bill Buzbeea114add2012-05-03 15:00:40 -0700491 // 99 SHR_INT vAA, vBB, vCC
492 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700493
Bill Buzbeea114add2012-05-03 15:00:40 -0700494 // 9A USHR_INT vAA, vBB, vCC
495 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700496
Bill Buzbeea114add2012-05-03 15:00:40 -0700497 // 9B ADD_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700498 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700499
Bill Buzbeea114add2012-05-03 15:00:40 -0700500 // 9C SUB_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700501 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700502
Bill Buzbeea114add2012-05-03 15:00:40 -0700503 // 9D MUL_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700504 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700505
Bill Buzbeea114add2012-05-03 15:00:40 -0700506 // 9E DIV_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700507 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700508
Bill Buzbeea114add2012-05-03 15:00:40 -0700509 // 9F REM_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700510 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700511
Bill Buzbeea114add2012-05-03 15:00:40 -0700512 // A0 AND_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700513 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700514
Bill Buzbeea114add2012-05-03 15:00:40 -0700515 // A1 OR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700516 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700517
Bill Buzbeea114add2012-05-03 15:00:40 -0700518 // A2 XOR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700519 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700520
Bill Buzbeea114add2012-05-03 15:00:40 -0700521 // A3 SHL_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700522 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700523
Bill Buzbeea114add2012-05-03 15:00:40 -0700524 // A4 SHR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700525 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700526
Bill Buzbeea114add2012-05-03 15:00:40 -0700527 // A5 USHR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700528 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700529
Bill Buzbeea114add2012-05-03 15:00:40 -0700530 // A6 ADD_FLOAT vAA, vBB, vCC
531 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700532
Bill Buzbeea114add2012-05-03 15:00:40 -0700533 // A7 SUB_FLOAT vAA, vBB, vCC
534 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700535
Bill Buzbeea114add2012-05-03 15:00:40 -0700536 // A8 MUL_FLOAT vAA, vBB, vCC
537 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700538
Bill Buzbeea114add2012-05-03 15:00:40 -0700539 // A9 DIV_FLOAT vAA, vBB, vCC
540 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700541
Bill Buzbeea114add2012-05-03 15:00:40 -0700542 // AA REM_FLOAT vAA, vBB, vCC
543 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700544
Bill Buzbeea114add2012-05-03 15:00:40 -0700545 // AB ADD_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700546 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700547
Bill Buzbeea114add2012-05-03 15:00:40 -0700548 // AC SUB_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700549 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700550
Bill Buzbeea114add2012-05-03 15:00:40 -0700551 // AD MUL_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700552 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700553
Bill Buzbeea114add2012-05-03 15:00:40 -0700554 // AE DIV_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700555 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700556
Bill Buzbeea114add2012-05-03 15:00:40 -0700557 // AF REM_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700558 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_UC | DF_C_WIDE | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700559
Bill Buzbeea114add2012-05-03 15:00:40 -0700560 // B0 ADD_INT_2ADDR vA, vB
561 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700562
Bill Buzbeea114add2012-05-03 15:00:40 -0700563 // B1 SUB_INT_2ADDR vA, vB
564 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700565
Bill Buzbeea114add2012-05-03 15:00:40 -0700566 // B2 MUL_INT_2ADDR vA, vB
567 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700568
Bill Buzbeea114add2012-05-03 15:00:40 -0700569 // B3 DIV_INT_2ADDR vA, vB
570 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700571
Bill Buzbeea114add2012-05-03 15:00:40 -0700572 // B4 REM_INT_2ADDR vA, vB
573 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700574
Bill Buzbeea114add2012-05-03 15:00:40 -0700575 // B5 AND_INT_2ADDR vA, vB
576 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700577
Bill Buzbeea114add2012-05-03 15:00:40 -0700578 // B6 OR_INT_2ADDR vA, vB
579 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700580
Bill Buzbeea114add2012-05-03 15:00:40 -0700581 // B7 XOR_INT_2ADDR vA, vB
582 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700583
Bill Buzbeea114add2012-05-03 15:00:40 -0700584 // B8 SHL_INT_2ADDR vA, vB
585 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700586
Bill Buzbeea114add2012-05-03 15:00:40 -0700587 // B9 SHR_INT_2ADDR vA, vB
588 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700589
Bill Buzbeea114add2012-05-03 15:00:40 -0700590 // BA USHR_INT_2ADDR vA, vB
591 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700592
Bill Buzbeea114add2012-05-03 15:00:40 -0700593 // BB ADD_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700594 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700595
Bill Buzbeea114add2012-05-03 15:00:40 -0700596 // BC SUB_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700597 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700598
Bill Buzbeea114add2012-05-03 15:00:40 -0700599 // BD MUL_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700600 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700601
Bill Buzbeea114add2012-05-03 15:00:40 -0700602 // BE DIV_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700603 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700604
Bill Buzbeea114add2012-05-03 15:00:40 -0700605 // BF REM_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700606 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700607
Bill Buzbeea114add2012-05-03 15:00:40 -0700608 // C0 AND_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700609 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700610
Bill Buzbeea114add2012-05-03 15:00:40 -0700611 // C1 OR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700612 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700613
Bill Buzbeea114add2012-05-03 15:00:40 -0700614 // C2 XOR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700615 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700616
Bill Buzbeea114add2012-05-03 15:00:40 -0700617 // C3 SHL_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700618 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700619
Bill Buzbeea114add2012-05-03 15:00:40 -0700620 // C4 SHR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700621 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700622
Bill Buzbeea114add2012-05-03 15:00:40 -0700623 // C5 USHR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700624 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700625
Bill Buzbeea114add2012-05-03 15:00:40 -0700626 // C6 ADD_FLOAT_2ADDR vA, vB
627 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700628
Bill Buzbeea114add2012-05-03 15:00:40 -0700629 // C7 SUB_FLOAT_2ADDR vA, vB
630 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700631
Bill Buzbeea114add2012-05-03 15:00:40 -0700632 // C8 MUL_FLOAT_2ADDR vA, vB
633 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700634
Bill Buzbeea114add2012-05-03 15:00:40 -0700635 // C9 DIV_FLOAT_2ADDR vA, vB
636 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700637
Bill Buzbeea114add2012-05-03 15:00:40 -0700638 // CA REM_FLOAT_2ADDR vA, vB
639 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700640
Bill Buzbeea114add2012-05-03 15:00:40 -0700641 // CB ADD_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700642 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700643
Bill Buzbeea114add2012-05-03 15:00:40 -0700644 // CC SUB_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700645 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700646
Bill Buzbeea114add2012-05-03 15:00:40 -0700647 // CD MUL_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700648 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700649
Bill Buzbeea114add2012-05-03 15:00:40 -0700650 // CE DIV_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700651 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700652
Bill Buzbeea114add2012-05-03 15:00:40 -0700653 // CF REM_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700654 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700655
Bill Buzbeea114add2012-05-03 15:00:40 -0700656 // D0 ADD_INT_LIT16 vA, vB, #+CCCC
657 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700658
Bill Buzbeea114add2012-05-03 15:00:40 -0700659 // D1 RSUB_INT vA, vB, #+CCCC
660 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700661
Bill Buzbeea114add2012-05-03 15:00:40 -0700662 // D2 MUL_INT_LIT16 vA, vB, #+CCCC
663 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700664
Bill Buzbeea114add2012-05-03 15:00:40 -0700665 // D3 DIV_INT_LIT16 vA, vB, #+CCCC
666 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700667
Bill Buzbeea114add2012-05-03 15:00:40 -0700668 // D4 REM_INT_LIT16 vA, vB, #+CCCC
669 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700670
Bill Buzbeea114add2012-05-03 15:00:40 -0700671 // D5 AND_INT_LIT16 vA, vB, #+CCCC
672 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700673
Bill Buzbeea114add2012-05-03 15:00:40 -0700674 // D6 OR_INT_LIT16 vA, vB, #+CCCC
675 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700676
Bill Buzbeea114add2012-05-03 15:00:40 -0700677 // D7 XOR_INT_LIT16 vA, vB, #+CCCC
678 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700679
Bill Buzbeea114add2012-05-03 15:00:40 -0700680 // D8 ADD_INT_LIT8 vAA, vBB, #+CC
buzbeebff24652012-05-06 16:22:05 -0700681 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700682
Bill Buzbeea114add2012-05-03 15:00:40 -0700683 // D9 RSUB_INT_LIT8 vAA, vBB, #+CC
684 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700685
Bill Buzbeea114add2012-05-03 15:00:40 -0700686 // DA MUL_INT_LIT8 vAA, vBB, #+CC
687 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700688
Bill Buzbeea114add2012-05-03 15:00:40 -0700689 // DB DIV_INT_LIT8 vAA, vBB, #+CC
690 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700691
Bill Buzbeea114add2012-05-03 15:00:40 -0700692 // DC REM_INT_LIT8 vAA, vBB, #+CC
693 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700694
Bill Buzbeea114add2012-05-03 15:00:40 -0700695 // DD AND_INT_LIT8 vAA, vBB, #+CC
696 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700697
Bill Buzbeea114add2012-05-03 15:00:40 -0700698 // DE OR_INT_LIT8 vAA, vBB, #+CC
699 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700700
Bill Buzbeea114add2012-05-03 15:00:40 -0700701 // DF XOR_INT_LIT8 vAA, vBB, #+CC
702 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700703
Bill Buzbeea114add2012-05-03 15:00:40 -0700704 // E0 SHL_INT_LIT8 vAA, vBB, #+CC
705 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700706
Bill Buzbeea114add2012-05-03 15:00:40 -0700707 // E1 SHR_INT_LIT8 vAA, vBB, #+CC
708 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700709
Bill Buzbeea114add2012-05-03 15:00:40 -0700710 // E2 USHR_INT_LIT8 vAA, vBB, #+CC
711 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700712
Bill Buzbeea114add2012-05-03 15:00:40 -0700713 // E3 IGET_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700714 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700715
Bill Buzbeea114add2012-05-03 15:00:40 -0700716 // E4 IPUT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700717 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700718
Bill Buzbeea114add2012-05-03 15:00:40 -0700719 // E5 SGET_VOLATILE
720 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700721
Bill Buzbeea114add2012-05-03 15:00:40 -0700722 // E6 SPUT_VOLATILE
723 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700724
Bill Buzbeea114add2012-05-03 15:00:40 -0700725 // E7 IGET_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700726 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700727
Bill Buzbeea114add2012-05-03 15:00:40 -0700728 // E8 IGET_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700729 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700730
Bill Buzbeea114add2012-05-03 15:00:40 -0700731 // E9 IPUT_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700732 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700733
Bill Buzbeea114add2012-05-03 15:00:40 -0700734 // EA SGET_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700735 DF_DA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700736
Bill Buzbeea114add2012-05-03 15:00:40 -0700737 // EB SPUT_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700738 DF_UA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700739
Bill Buzbeea114add2012-05-03 15:00:40 -0700740 // EC BREAKPOINT
741 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700742
Bill Buzbeea114add2012-05-03 15:00:40 -0700743 // ED THROW_VERIFICATION_ERROR
744 DF_NOP | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700745
Bill Buzbeea114add2012-05-03 15:00:40 -0700746 // EE EXECUTE_INLINE
747 DF_FORMAT_35C,
buzbee67bf8852011-08-17 17:51:35 -0700748
Bill Buzbeea114add2012-05-03 15:00:40 -0700749 // EF EXECUTE_INLINE_RANGE
750 DF_FORMAT_3RC,
buzbee67bf8852011-08-17 17:51:35 -0700751
Bill Buzbeea114add2012-05-03 15:00:40 -0700752 // F0 INVOKE_OBJECT_INIT_RANGE
753 DF_NOP | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700754
Bill Buzbeea114add2012-05-03 15:00:40 -0700755 // F1 RETURN_VOID_BARRIER
756 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700757
Bill Buzbeea114add2012-05-03 15:00:40 -0700758 // F2 IGET_QUICK
759 DF_DA | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700760
Bill Buzbeea114add2012-05-03 15:00:40 -0700761 // F3 IGET_WIDE_QUICK
buzbeebff24652012-05-06 16:22:05 -0700762 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700763
Bill Buzbeea114add2012-05-03 15:00:40 -0700764 // F4 IGET_OBJECT_QUICK
765 DF_DA | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700766
Bill Buzbeea114add2012-05-03 15:00:40 -0700767 // F5 IPUT_QUICK
768 DF_UA | DF_UB | DF_NULL_CHK_1,
buzbee67bf8852011-08-17 17:51:35 -0700769
Bill Buzbeea114add2012-05-03 15:00:40 -0700770 // F6 IPUT_WIDE_QUICK
buzbeebff24652012-05-06 16:22:05 -0700771 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2,
buzbee67bf8852011-08-17 17:51:35 -0700772
Bill Buzbeea114add2012-05-03 15:00:40 -0700773 // F7 IPUT_OBJECT_QUICK
774 DF_UA | DF_UB | DF_NULL_CHK_1,
buzbee67bf8852011-08-17 17:51:35 -0700775
Bill Buzbeea114add2012-05-03 15:00:40 -0700776 // F8 INVOKE_VIRTUAL_QUICK
777 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700778
Bill Buzbeea114add2012-05-03 15:00:40 -0700779 // F9 INVOKE_VIRTUAL_QUICK_RANGE
780 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700781
Bill Buzbeea114add2012-05-03 15:00:40 -0700782 // FA INVOKE_SUPER_QUICK
783 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700784
Bill Buzbeea114add2012-05-03 15:00:40 -0700785 // FB INVOKE_SUPER_QUICK_RANGE
786 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700787
Bill Buzbeea114add2012-05-03 15:00:40 -0700788 // FC IPUT_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700789 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700790
Bill Buzbeea114add2012-05-03 15:00:40 -0700791 // FD SGET_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700792 DF_DA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700793
Bill Buzbeea114add2012-05-03 15:00:40 -0700794 // FE SPUT_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700795 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700796
Bill Buzbeea114add2012-05-03 15:00:40 -0700797 // FF UNUSED_FF
798 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700799
Bill Buzbeea114add2012-05-03 15:00:40 -0700800 // Beginning of extended MIR opcodes
801 // 100 MIR_PHI
buzbeebff24652012-05-06 16:22:05 -0700802 DF_DA | DF_NULL_TRANSFER_N,
buzbee84fd6932012-03-29 16:44:16 -0700803
Bill Buzbeea114add2012-05-03 15:00:40 -0700804 // 101 MIR_COPY
805 DF_DA | DF_UB | DF_IS_MOVE,
buzbee84fd6932012-03-29 16:44:16 -0700806
Bill Buzbeea114add2012-05-03 15:00:40 -0700807 // 102 MIR_FUSED_CMPL_FLOAT
808 DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700809
Bill Buzbeea114add2012-05-03 15:00:40 -0700810 // 103 MIR_FUSED_CMPG_FLOAT
811 DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700812
Bill Buzbeea114add2012-05-03 15:00:40 -0700813 // 104 MIR_FUSED_CMPL_DOUBLE
buzbeebff24652012-05-06 16:22:05 -0700814 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700815
Bill Buzbeea114add2012-05-03 15:00:40 -0700816 // 105 MIR_FUSED_CMPG_DOUBLE
buzbeebff24652012-05-06 16:22:05 -0700817 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700818
Bill Buzbeea114add2012-05-03 15:00:40 -0700819 // 106 MIR_FUSED_CMP_LONG
buzbeebff24652012-05-06 16:22:05 -0700820 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee84fd6932012-03-29 16:44:16 -0700821
Bill Buzbeea114add2012-05-03 15:00:40 -0700822 // 107 MIR_NOP
823 DF_NOP,
buzbee84fd6932012-03-29 16:44:16 -0700824
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700825 // 108 MIR_NULL_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700826 0,
buzbee84fd6932012-03-29 16:44:16 -0700827
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700828 // 109 MIR_RANGE_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700829 0,
buzbee84fd6932012-03-29 16:44:16 -0700830
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700831 // 110 MIR_DIV_ZERO_CHECK
832 0,
833
834 // 111 MIR_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700835 0,
buzbee67bf8852011-08-17 17:51:35 -0700836};
837
buzbeee1965672012-03-11 18:39:19 -0700838/* Return the base virtual register for a SSA name */
839int SRegToVReg(const CompilationUnit* cUnit, int ssaReg)
buzbee67bf8852011-08-17 17:51:35 -0700840{
buzbeecbd6d442012-11-17 14:11:25 -0800841 DCHECK_LT(ssaReg, static_cast<int>(cUnit->ssaBaseVRegs->numUsed));
Bill Buzbeea114add2012-05-03 15:00:40 -0700842 return GET_ELEM_N(cUnit->ssaBaseVRegs, int, ssaReg);
buzbee67bf8852011-08-17 17:51:35 -0700843}
844
buzbeee1965672012-03-11 18:39:19 -0700845int SRegToSubscript(const CompilationUnit* cUnit, int ssaReg)
846{
buzbeecbd6d442012-11-17 14:11:25 -0800847 DCHECK(ssaReg < static_cast<int>(cUnit->ssaSubscripts->numUsed));
Bill Buzbeea114add2012-05-03 15:00:40 -0700848 return GET_ELEM_N(cUnit->ssaSubscripts, int, ssaReg);
buzbeee1965672012-03-11 18:39:19 -0700849}
850
buzbee84fd6932012-03-29 16:44:16 -0700851int getSSAUseCount(CompilationUnit* cUnit, int sReg)
852{
buzbeecbd6d442012-11-17 14:11:25 -0800853 DCHECK(sReg < static_cast<int>(cUnit->rawUseCounts.numUsed));
Bill Buzbeea114add2012-05-03 15:00:40 -0700854 return cUnit->rawUseCounts.elemList[sReg];
buzbee84fd6932012-03-29 16:44:16 -0700855}
856
857
buzbeeba938cb2012-02-03 14:47:55 -0800858char* oatGetDalvikDisassembly(CompilationUnit* cUnit,
Elliott Hughesadb8c672012-03-06 16:49:32 -0800859 const DecodedInstruction& insn, const char* note)
buzbee67bf8852011-08-17 17:51:35 -0700860{
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700861 std::string str;
862 int opcode = insn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700863 int dfAttributes = oatDataFlowAttributes[opcode];
864 int flags;
865 char* ret;
buzbee67bf8852011-08-17 17:51:35 -0700866
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700867 if (opcode >= kMirOpFirst) {
868 if (opcode == kMirOpPhi) {
869 str.append("PHI");
870 } else if (opcode == kMirOpCheck) {
871 str.append("Check");
buzbee67bf8852011-08-17 17:51:35 -0700872 } else {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700873 str.append(StringPrintf("Opcode %#x", opcode));
buzbee67bf8852011-08-17 17:51:35 -0700874 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700875 flags = 0;
876 } else {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700877 str.append(Instruction::Name(insn.opcode));
Ian Rogersa75a0132012-09-28 11:41:42 -0700878 flags = Instruction::FlagsOf(insn.opcode);
Bill Buzbeea114add2012-05-03 15:00:40 -0700879 }
buzbee67bf8852011-08-17 17:51:35 -0700880
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700881 if (note) {
882 str.append(note);
883 }
buzbee67bf8852011-08-17 17:51:35 -0700884
Bill Buzbeea114add2012-05-03 15:00:40 -0700885 /* For branches, decode the instructions to print out the branch targets */
886 if (flags & Instruction::kBranch) {
887 Instruction::Format dalvikFormat = Instruction::FormatOf(insn.opcode);
888 int offset = 0;
889 switch (dalvikFormat) {
890 case Instruction::k21t:
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700891 str.append(StringPrintf(" v%d,", insn.vA));
buzbeecbd6d442012-11-17 14:11:25 -0800892 offset = insn.vB;
Bill Buzbeea114add2012-05-03 15:00:40 -0700893 break;
894 case Instruction::k22t:
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700895 str.append(StringPrintf(" v%d, v%d,", insn.vA, insn.vB));
buzbeecbd6d442012-11-17 14:11:25 -0800896 offset = insn.vC;
Bill Buzbeea114add2012-05-03 15:00:40 -0700897 break;
898 case Instruction::k10t:
899 case Instruction::k20t:
900 case Instruction::k30t:
buzbeecbd6d442012-11-17 14:11:25 -0800901 offset = insn.vA;
Bill Buzbeea114add2012-05-03 15:00:40 -0700902 break;
903 default:
buzbeecbd6d442012-11-17 14:11:25 -0800904 LOG(FATAL) << "Unexpected branch format " << dalvikFormat << " from " << insn.opcode;
buzbee67bf8852011-08-17 17:51:35 -0700905 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700906 str.append(StringPrintf(" (%c%x)",
907 offset > 0 ? '+' : '-',
908 offset > 0 ? offset : -offset));
Bill Buzbeea114add2012-05-03 15:00:40 -0700909 } else if (dfAttributes & DF_FORMAT_35C) {
910 unsigned int i;
911 for (i = 0; i < insn.vA; i++) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700912 if (i != 0) str.append(",");
913 str.append(StringPrintf(" v%d", insn.arg[i]));
buzbee67bf8852011-08-17 17:51:35 -0700914 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700915 }
916 else if (dfAttributes & DF_FORMAT_3RC) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700917 str.append(StringPrintf(" v%d..v%d", insn.vC, insn.vC + insn.vA - 1));
Bill Buzbeea114add2012-05-03 15:00:40 -0700918 } else {
919 if (dfAttributes & DF_A_IS_REG) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700920 str.append(StringPrintf(" v%d", insn.vA));
buzbee67bf8852011-08-17 17:51:35 -0700921 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700922 if (dfAttributes & DF_B_IS_REG) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700923 str.append(StringPrintf(", v%d", insn.vB));
buzbeecbd6d442012-11-17 14:11:25 -0800924 } else if (static_cast<int>(opcode) < static_cast<int>(kMirOpFirst)) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700925 str.append(StringPrintf(", (#%d)", insn.vB));
Bill Buzbeea114add2012-05-03 15:00:40 -0700926 }
927 if (dfAttributes & DF_C_IS_REG) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700928 str.append(StringPrintf(", v%d", insn.vC));
buzbeecbd6d442012-11-17 14:11:25 -0800929 } else if (static_cast<int>(opcode) < static_cast<int>(kMirOpFirst)) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700930 str.append(StringPrintf(", (#%d)", insn.vC));
Bill Buzbeea114add2012-05-03 15:00:40 -0700931 }
932 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700933 int length = str.length() + 1;
buzbeecbd6d442012-11-17 14:11:25 -0800934 ret = static_cast<char*>(oatNew(cUnit, length, false, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700935 strncpy(ret, str.c_str(), length);
Bill Buzbeea114add2012-05-03 15:00:40 -0700936 return ret;
buzbee67bf8852011-08-17 17:51:35 -0700937}
938
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700939std::string getSSAName(const CompilationUnit* cUnit, int ssaReg)
buzbee67bf8852011-08-17 17:51:35 -0700940{
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700941 return StringPrintf("v%d_%d", SRegToVReg(cUnit, ssaReg),
942 SRegToSubscript(cUnit, ssaReg));
buzbee67bf8852011-08-17 17:51:35 -0700943}
944
945/*
946 * Dalvik instruction disassembler with optional SSA printing.
947 */
buzbee31a4a6f2012-02-28 15:36:15 -0800948char* oatFullDisassembler(CompilationUnit* cUnit, const MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -0700949{
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700950 std::string str;
Bill Buzbeea114add2012-05-03 15:00:40 -0700951 const DecodedInstruction* insn = &mir->dalvikInsn;
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700952 int opcode = insn->opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700953 int dfAttributes = oatDataFlowAttributes[opcode];
954 char* ret;
955 int length;
buzbee67bf8852011-08-17 17:51:35 -0700956
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700957 if (opcode >= kMirOpFirst) {
958 if (opcode == kMirOpPhi) {
buzbeecbd6d442012-11-17 14:11:25 -0800959 int* incoming = reinterpret_cast<int*>(mir->dalvikInsn.vB);
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700960 str.append(StringPrintf("PHI %s = (%s",
961 getSSAName(cUnit, mir->ssaRep->defs[0]).c_str(),
962 getSSAName(cUnit, mir->ssaRep->uses[0]).c_str()));
963 str.append(StringPrintf(":%d",incoming[0]));
Bill Buzbeea114add2012-05-03 15:00:40 -0700964 int i;
965 for (i = 1; i < mir->ssaRep->numUses; i++) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700966 str.append(StringPrintf(", %s:%d",
967 getSSAName(cUnit, mir->ssaRep->uses[i]).c_str(),
968 incoming[i]));
Bill Buzbeea114add2012-05-03 15:00:40 -0700969 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700970 str.append(")");
971 } else if (opcode == kMirOpCheck) {
972 str.append("Check ");
973 str.append(Instruction::Name(mir->meta.throwInsn->dalvikInsn.opcode));
974 } else if (opcode == kMirOpNop) {
975 str.append("MirNop");
buzbee67bf8852011-08-17 17:51:35 -0700976 } else {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700977 str.append(StringPrintf("Opcode %#x", opcode));
buzbee67bf8852011-08-17 17:51:35 -0700978 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700979 goto done;
980 } else {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700981 str.append(Instruction::Name(insn->opcode));
Bill Buzbeea114add2012-05-03 15:00:40 -0700982 }
buzbee67bf8852011-08-17 17:51:35 -0700983
Bill Buzbeea114add2012-05-03 15:00:40 -0700984 /* For branches, decode the instructions to print out the branch targets */
Ian Rogersa75a0132012-09-28 11:41:42 -0700985 if (Instruction::FlagsOf(insn->opcode) & Instruction::kBranch) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700986 Instruction::Format dalvikFormat = Instruction::FormatOf(insn->opcode);
987 int delta = 0;
988 switch (dalvikFormat) {
989 case Instruction::k21t:
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700990 str.append(StringPrintf(" %s, ",
991 getSSAName(cUnit, mir->ssaRep->uses[0]).c_str()));
buzbeecbd6d442012-11-17 14:11:25 -0800992 delta = insn->vB;
Bill Buzbeea114add2012-05-03 15:00:40 -0700993 break;
994 case Instruction::k22t:
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700995 str.append(StringPrintf(" %s, %s, ",
996 getSSAName(cUnit, mir->ssaRep->uses[0]).c_str(),
997 getSSAName(cUnit, mir->ssaRep->uses[1]).c_str()));
buzbeecbd6d442012-11-17 14:11:25 -0800998 delta = insn->vC;
Bill Buzbeea114add2012-05-03 15:00:40 -0700999 break;
1000 case Instruction::k10t:
1001 case Instruction::k20t:
1002 case Instruction::k30t:
buzbeecbd6d442012-11-17 14:11:25 -08001003 delta = insn->vA;
Bill Buzbeea114add2012-05-03 15:00:40 -07001004 break;
1005 default:
buzbeecbd6d442012-11-17 14:11:25 -08001006 LOG(FATAL) << "Unexpected branch format: " << dalvikFormat;
Bill Buzbeea114add2012-05-03 15:00:40 -07001007 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001008 str.append(StringPrintf(" %04x", mir->offset + delta));
Bill Buzbeea114add2012-05-03 15:00:40 -07001009 } else if (dfAttributes & (DF_FORMAT_35C | DF_FORMAT_3RC)) {
1010 unsigned int i;
1011 for (i = 0; i < insn->vA; i++) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001012 if (i != 0) str.append(",");
1013 str.append(" ");
1014 str.append(getSSAName(cUnit, mir->ssaRep->uses[i]));
Bill Buzbeea114add2012-05-03 15:00:40 -07001015 }
1016 } else {
1017 int udIdx;
1018 if (mir->ssaRep->numDefs) {
1019
1020 for (udIdx = 0; udIdx < mir->ssaRep->numDefs; udIdx++) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001021 str.append(" ");
1022 str.append(getSSAName(cUnit, mir->ssaRep->defs[udIdx]));
Bill Buzbeea114add2012-05-03 15:00:40 -07001023 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001024 str.append(",");
Bill Buzbeea114add2012-05-03 15:00:40 -07001025 }
1026 if (mir->ssaRep->numUses) {
1027 /* No leading ',' for the first use */
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001028 str.append(" ");
1029 str.append(getSSAName(cUnit, mir->ssaRep->uses[0]));
Bill Buzbeea114add2012-05-03 15:00:40 -07001030 for (udIdx = 1; udIdx < mir->ssaRep->numUses; udIdx++) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001031 str.append(", ");
1032 str.append(getSSAName(cUnit, mir->ssaRep->uses[udIdx]));
Bill Buzbeea114add2012-05-03 15:00:40 -07001033 }
1034 }
1035 if (static_cast<int>(opcode) < static_cast<int>(kMirOpFirst)) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001036 Instruction::Format dalvikFormat = Instruction::FormatOf(insn->opcode);
buzbee67bf8852011-08-17 17:51:35 -07001037 switch (dalvikFormat) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001038 case Instruction::k11n: // op vA, #+B
1039 case Instruction::k21s: // op vAA, #+BBBB
1040 case Instruction::k21h: // op vAA, #+BBBB00000[00000000]
1041 case Instruction::k31i: // op vAA, #+BBBBBBBB
1042 case Instruction::k51l: // op vAA, #+BBBBBBBBBBBBBBBB
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001043 str.append(StringPrintf(" #%#x", insn->vB));
Bill Buzbeea114add2012-05-03 15:00:40 -07001044 break;
1045 case Instruction::k21c: // op vAA, thing@BBBB
1046 case Instruction::k31c: // op vAA, thing@BBBBBBBB
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001047 str.append(StringPrintf(" @%#x", insn->vB));
Bill Buzbeea114add2012-05-03 15:00:40 -07001048 break;
1049 case Instruction::k22b: // op vAA, vBB, #+CC
1050 case Instruction::k22s: // op vA, vB, #+CCCC
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001051 str.append(StringPrintf(" #%#x", insn->vC));
Bill Buzbeea114add2012-05-03 15:00:40 -07001052 break;
1053 case Instruction::k22c: // op vA, vB, thing@CCCC
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001054 str.append(StringPrintf(" @%#x", insn->vC));
Bill Buzbeea114add2012-05-03 15:00:40 -07001055 break;
1056 /* No need for special printing */
1057 default:
1058 break;
buzbee67bf8852011-08-17 17:51:35 -07001059 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001060 }
1061 }
buzbee67bf8852011-08-17 17:51:35 -07001062
1063done:
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001064 length = str.length() + 1;
buzbeecbd6d442012-11-17 14:11:25 -08001065 ret = static_cast<char*>(oatNew(cUnit, length, false, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001066 strncpy(ret, str.c_str(), length);
Bill Buzbeea114add2012-05-03 15:00:40 -07001067 return ret;
buzbee67bf8852011-08-17 17:51:35 -07001068}
1069
Elliott Hughesc1f143d2011-12-01 17:31:10 -08001070char* oatGetSSAString(CompilationUnit* cUnit, SSARepresentation* ssaRep)
buzbee67bf8852011-08-17 17:51:35 -07001071{
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001072 std::string str;
Bill Buzbeea114add2012-05-03 15:00:40 -07001073 char* ret;
1074 int i;
buzbee67bf8852011-08-17 17:51:35 -07001075
Bill Buzbeea114add2012-05-03 15:00:40 -07001076 for (i = 0; i < ssaRep->numDefs; i++) {
1077 int ssaReg = ssaRep->defs[i];
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001078 str.append(StringPrintf("s%d(v%d_%d) ", ssaReg,
1079 SRegToVReg(cUnit, ssaReg),
1080 SRegToSubscript(cUnit, ssaReg)));
Bill Buzbeea114add2012-05-03 15:00:40 -07001081 }
1082
1083 if (ssaRep->numDefs) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001084 str.append("<- ");
Bill Buzbeea114add2012-05-03 15:00:40 -07001085 }
1086
1087 for (i = 0; i < ssaRep->numUses; i++) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001088 int ssaReg = ssaRep->uses[i];
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001089 str.append(StringPrintf("s%d(v%d_%d) ", ssaReg, SRegToVReg(cUnit, ssaReg),
1090 SRegToSubscript(cUnit, ssaReg)));
Bill Buzbeea114add2012-05-03 15:00:40 -07001091 }
buzbee67bf8852011-08-17 17:51:35 -07001092
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001093 int length = str.length() + 1;
buzbeecbd6d442012-11-17 14:11:25 -08001094 ret = static_cast<char*>(oatNew(cUnit, length, false, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001095 strncpy(ret, str.c_str(), length);
Bill Buzbeea114add2012-05-03 15:00:40 -07001096 return ret;
buzbee67bf8852011-08-17 17:51:35 -07001097}
1098
1099/* Any register that is used before being defined is considered live-in */
buzbee31a4a6f2012-02-28 15:36:15 -08001100inline void handleLiveInUse(CompilationUnit* cUnit, ArenaBitVector* useV,
1101 ArenaBitVector* defV, ArenaBitVector* liveInV,
1102 int dalvikRegId)
buzbee67bf8852011-08-17 17:51:35 -07001103{
Bill Buzbeea114add2012-05-03 15:00:40 -07001104 oatSetBit(cUnit, useV, dalvikRegId);
1105 if (!oatIsBitSet(defV, dalvikRegId)) {
1106 oatSetBit(cUnit, liveInV, dalvikRegId);
1107 }
buzbee67bf8852011-08-17 17:51:35 -07001108}
1109
1110/* Mark a reg as being defined */
buzbee31a4a6f2012-02-28 15:36:15 -08001111inline void handleDef(CompilationUnit* cUnit, ArenaBitVector* defV,
1112 int dalvikRegId)
buzbee67bf8852011-08-17 17:51:35 -07001113{
Bill Buzbeea114add2012-05-03 15:00:40 -07001114 oatSetBit(cUnit, defV, dalvikRegId);
buzbee67bf8852011-08-17 17:51:35 -07001115}
1116
1117/*
1118 * Find out live-in variables for natural loops. Variables that are live-in in
1119 * the main loop body are considered to be defined in the entry block.
1120 */
1121bool oatFindLocalLiveIn(CompilationUnit* cUnit, BasicBlock* bb)
1122{
Bill Buzbeea114add2012-05-03 15:00:40 -07001123 MIR* mir;
1124 ArenaBitVector *useV, *defV, *liveInV;
buzbee67bf8852011-08-17 17:51:35 -07001125
Bill Buzbeea114add2012-05-03 15:00:40 -07001126 if (bb->dataFlowInfo == NULL) return false;
buzbee67bf8852011-08-17 17:51:35 -07001127
Bill Buzbeea114add2012-05-03 15:00:40 -07001128 useV = bb->dataFlowInfo->useV =
1129 oatAllocBitVector(cUnit, cUnit->numDalvikRegisters, false, kBitMapUse);
1130 defV = bb->dataFlowInfo->defV =
1131 oatAllocBitVector(cUnit, cUnit->numDalvikRegisters, false, kBitMapDef);
1132 liveInV = bb->dataFlowInfo->liveInV =
1133 oatAllocBitVector(cUnit, cUnit->numDalvikRegisters, false,
1134 kBitMapLiveIn);
buzbee67bf8852011-08-17 17:51:35 -07001135
Bill Buzbeea114add2012-05-03 15:00:40 -07001136 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
1137 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
1138 DecodedInstruction *dInsn = &mir->dalvikInsn;
buzbee67bf8852011-08-17 17:51:35 -07001139
Bill Buzbeea114add2012-05-03 15:00:40 -07001140 if (dfAttributes & DF_HAS_USES) {
1141 if (dfAttributes & DF_UA) {
1142 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vA);
buzbeebff24652012-05-06 16:22:05 -07001143 if (dfAttributes & DF_A_WIDE) {
1144 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vA+1);
1145 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001146 }
1147 if (dfAttributes & DF_UB) {
1148 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vB);
buzbeebff24652012-05-06 16:22:05 -07001149 if (dfAttributes & DF_B_WIDE) {
1150 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vB+1);
1151 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001152 }
1153 if (dfAttributes & DF_UC) {
1154 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vC);
buzbeebff24652012-05-06 16:22:05 -07001155 if (dfAttributes & DF_C_WIDE) {
1156 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vC+1);
1157 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001158 }
buzbee67bf8852011-08-17 17:51:35 -07001159 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001160 if (dfAttributes & DF_FORMAT_35C) {
1161 for (unsigned int i = 0; i < dInsn->vA; i++) {
1162 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->arg[i]);
1163 }
1164 }
1165 if (dfAttributes & DF_FORMAT_3RC) {
1166 for (unsigned int i = 0; i < dInsn->vA; i++) {
1167 handleLiveInUse(cUnit, useV, defV, liveInV, dInsn->vC+i);
1168 }
1169 }
1170 if (dfAttributes & DF_HAS_DEFS) {
1171 handleDef(cUnit, defV, dInsn->vA);
buzbeebff24652012-05-06 16:22:05 -07001172 if (dfAttributes & DF_A_WIDE) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001173 handleDef(cUnit, defV, dInsn->vA+1);
1174 }
1175 }
1176 }
1177 return true;
buzbee67bf8852011-08-17 17:51:35 -07001178}
1179
buzbeee1965672012-03-11 18:39:19 -07001180int addNewSReg(CompilationUnit* cUnit, int vReg)
1181{
Bill Buzbeea114add2012-05-03 15:00:40 -07001182 // Compiler temps always have a subscript of 0
1183 int subscript = (vReg < 0) ? 0 : ++cUnit->SSALastDefs[vReg];
1184 int ssaReg = cUnit->numSSARegs++;
1185 oatInsertGrowableList(cUnit, cUnit->ssaBaseVRegs, vReg);
1186 oatInsertGrowableList(cUnit, cUnit->ssaSubscripts, subscript);
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001187 std::string ssaName = getSSAName(cUnit, ssaReg);
buzbeecbd6d442012-11-17 14:11:25 -08001188 char* name = static_cast<char*>(oatNew(cUnit, ssaName.length() + 1, false, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001189 strncpy(name, ssaName.c_str(), ssaName.length() + 1);
buzbeecbd6d442012-11-17 14:11:25 -08001190 oatInsertGrowableList(cUnit, cUnit->ssaStrings, reinterpret_cast<uintptr_t>(name));
Bill Buzbeea114add2012-05-03 15:00:40 -07001191 DCHECK_EQ(cUnit->ssaBaseVRegs->numUsed, cUnit->ssaSubscripts->numUsed);
1192 return ssaReg;
buzbeee1965672012-03-11 18:39:19 -07001193}
1194
buzbee67bf8852011-08-17 17:51:35 -07001195/* Find out the latest SSA register for a given Dalvik register */
buzbee31a4a6f2012-02-28 15:36:15 -08001196void handleSSAUse(CompilationUnit* cUnit, int* uses, int dalvikReg,
1197 int regIndex)
buzbee67bf8852011-08-17 17:51:35 -07001198{
Bill Buzbeea114add2012-05-03 15:00:40 -07001199 DCHECK((dalvikReg >= 0) && (dalvikReg < cUnit->numDalvikRegisters));
1200 uses[regIndex] = cUnit->vRegToSSAMap[dalvikReg];
buzbee67bf8852011-08-17 17:51:35 -07001201}
1202
1203/* Setup a new SSA register for a given Dalvik register */
buzbee31a4a6f2012-02-28 15:36:15 -08001204void handleSSADef(CompilationUnit* cUnit, int* defs, int dalvikReg,
1205 int regIndex)
buzbee67bf8852011-08-17 17:51:35 -07001206{
Bill Buzbeea114add2012-05-03 15:00:40 -07001207 DCHECK((dalvikReg >= 0) && (dalvikReg < cUnit->numDalvikRegisters));
1208 int ssaReg = addNewSReg(cUnit, dalvikReg);
1209 cUnit->vRegToSSAMap[dalvikReg] = ssaReg;
1210 defs[regIndex] = ssaReg;
buzbee67bf8852011-08-17 17:51:35 -07001211}
1212
buzbeeec5adf32011-09-11 15:25:43 -07001213/* Look up new SSA names for format_35c instructions */
buzbee31a4a6f2012-02-28 15:36:15 -08001214void dataFlowSSAFormat35C(CompilationUnit* cUnit, MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -07001215{
Bill Buzbeea114add2012-05-03 15:00:40 -07001216 DecodedInstruction *dInsn = &mir->dalvikInsn;
1217 int numUses = dInsn->vA;
1218 int i;
buzbee67bf8852011-08-17 17:51:35 -07001219
Bill Buzbeea114add2012-05-03 15:00:40 -07001220 mir->ssaRep->numUses = numUses;
buzbeecbd6d442012-11-17 14:11:25 -08001221 mir->ssaRep->uses = static_cast<int*>(oatNew(cUnit, sizeof(int) * numUses, true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001222 // NOTE: will be filled in during type & size inference pass
buzbeecbd6d442012-11-17 14:11:25 -08001223 mir->ssaRep->fpUse = static_cast<bool*>(oatNew(cUnit, sizeof(bool) * numUses, true,
1224 kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001225
Bill Buzbeea114add2012-05-03 15:00:40 -07001226 for (i = 0; i < numUses; i++) {
1227 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->arg[i], i);
1228 }
buzbee67bf8852011-08-17 17:51:35 -07001229}
1230
buzbeeec5adf32011-09-11 15:25:43 -07001231/* Look up new SSA names for format_3rc instructions */
buzbee31a4a6f2012-02-28 15:36:15 -08001232void dataFlowSSAFormat3RC(CompilationUnit* cUnit, MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -07001233{
Bill Buzbeea114add2012-05-03 15:00:40 -07001234 DecodedInstruction *dInsn = &mir->dalvikInsn;
1235 int numUses = dInsn->vA;
1236 int i;
buzbee67bf8852011-08-17 17:51:35 -07001237
Bill Buzbeea114add2012-05-03 15:00:40 -07001238 mir->ssaRep->numUses = numUses;
buzbeecbd6d442012-11-17 14:11:25 -08001239 mir->ssaRep->uses = static_cast<int*>(oatNew(cUnit, sizeof(int) * numUses, true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001240 // NOTE: will be filled in during type & size inference pass
buzbeecbd6d442012-11-17 14:11:25 -08001241 mir->ssaRep->fpUse = static_cast<bool*>(oatNew(cUnit, sizeof(bool) * numUses, true,
1242 kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001243
Bill Buzbeea114add2012-05-03 15:00:40 -07001244 for (i = 0; i < numUses; i++) {
1245 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vC+i, i);
1246 }
buzbee67bf8852011-08-17 17:51:35 -07001247}
1248
1249/* Entry function to convert a block into SSA representation */
1250bool oatDoSSAConversion(CompilationUnit* cUnit, BasicBlock* bb)
1251{
Bill Buzbeea114add2012-05-03 15:00:40 -07001252 MIR* mir;
buzbee67bf8852011-08-17 17:51:35 -07001253
Bill Buzbeea114add2012-05-03 15:00:40 -07001254 if (bb->dataFlowInfo == NULL) return false;
buzbee67bf8852011-08-17 17:51:35 -07001255
Bill Buzbeea114add2012-05-03 15:00:40 -07001256 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
buzbeecbd6d442012-11-17 14:11:25 -08001257 mir->ssaRep = static_cast<struct SSARepresentation *>(oatNew(cUnit, sizeof(SSARepresentation),
1258 true, kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001259
Bill Buzbeea114add2012-05-03 15:00:40 -07001260 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
buzbee67bf8852011-08-17 17:51:35 -07001261
Bill Buzbeea114add2012-05-03 15:00:40 -07001262 // If not a pseudo-op, note non-leaf or can throw
1263 if (static_cast<int>(mir->dalvikInsn.opcode) <
1264 static_cast<int>(kNumPackedOpcodes)) {
Ian Rogersa75a0132012-09-28 11:41:42 -07001265 int flags = Instruction::FlagsOf(mir->dalvikInsn.opcode);
buzbeecefd1872011-09-09 09:59:52 -07001266
Bill Buzbeea114add2012-05-03 15:00:40 -07001267 if (flags & Instruction::kThrow) {
1268 cUnit->attrs &= ~METHOD_IS_THROW_FREE;
1269 }
buzbeecefd1872011-09-09 09:59:52 -07001270
Bill Buzbeea114add2012-05-03 15:00:40 -07001271 if (flags & Instruction::kInvoke) {
1272 cUnit->attrs &= ~METHOD_IS_LEAF;
1273 }
buzbee67bf8852011-08-17 17:51:35 -07001274 }
1275
Bill Buzbeea114add2012-05-03 15:00:40 -07001276 int numUses = 0;
buzbee67bf8852011-08-17 17:51:35 -07001277
Bill Buzbeea114add2012-05-03 15:00:40 -07001278 if (dfAttributes & DF_FORMAT_35C) {
1279 dataFlowSSAFormat35C(cUnit, mir);
1280 continue;
buzbee5abfa3e2012-01-31 17:01:43 -08001281 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001282
1283 if (dfAttributes & DF_FORMAT_3RC) {
1284 dataFlowSSAFormat3RC(cUnit, mir);
1285 continue;
1286 }
1287
1288 if (dfAttributes & DF_HAS_USES) {
1289 if (dfAttributes & DF_UA) {
1290 numUses++;
buzbeebff24652012-05-06 16:22:05 -07001291 if (dfAttributes & DF_A_WIDE) {
1292 numUses ++;
1293 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001294 }
1295 if (dfAttributes & DF_UB) {
1296 numUses++;
buzbeebff24652012-05-06 16:22:05 -07001297 if (dfAttributes & DF_B_WIDE) {
1298 numUses ++;
1299 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001300 }
1301 if (dfAttributes & DF_UC) {
1302 numUses++;
buzbeebff24652012-05-06 16:22:05 -07001303 if (dfAttributes & DF_C_WIDE) {
1304 numUses ++;
1305 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001306 }
1307 }
1308
1309 if (numUses) {
1310 mir->ssaRep->numUses = numUses;
buzbeecbd6d442012-11-17 14:11:25 -08001311 mir->ssaRep->uses = static_cast<int*>(oatNew(cUnit, sizeof(int) * numUses, false,
1312 kAllocDFInfo));
1313 mir->ssaRep->fpUse = static_cast<bool*>(oatNew(cUnit, sizeof(bool) * numUses, false,
1314 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001315 }
1316
1317 int numDefs = 0;
1318
1319 if (dfAttributes & DF_HAS_DEFS) {
1320 numDefs++;
buzbeebff24652012-05-06 16:22:05 -07001321 if (dfAttributes & DF_A_WIDE) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001322 numDefs++;
1323 }
1324 }
1325
1326 if (numDefs) {
1327 mir->ssaRep->numDefs = numDefs;
buzbeecbd6d442012-11-17 14:11:25 -08001328 mir->ssaRep->defs = static_cast<int*>(oatNew(cUnit, sizeof(int) * numDefs, false,
1329 kAllocDFInfo));
1330 mir->ssaRep->fpDef = static_cast<bool*>(oatNew(cUnit, sizeof(bool) * numDefs, false,
1331 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001332 }
1333
1334 DecodedInstruction *dInsn = &mir->dalvikInsn;
1335
1336 if (dfAttributes & DF_HAS_USES) {
1337 numUses = 0;
1338 if (dfAttributes & DF_UA) {
1339 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_A;
1340 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vA, numUses++);
buzbeebff24652012-05-06 16:22:05 -07001341 if (dfAttributes & DF_A_WIDE) {
1342 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_A;
1343 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vA+1, numUses++);
1344 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001345 }
1346 if (dfAttributes & DF_UB) {
1347 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_B;
1348 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vB, numUses++);
buzbeebff24652012-05-06 16:22:05 -07001349 if (dfAttributes & DF_B_WIDE) {
1350 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_B;
1351 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vB+1, numUses++);
1352 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001353 }
1354 if (dfAttributes & DF_UC) {
1355 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_C;
1356 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vC, numUses++);
buzbeebff24652012-05-06 16:22:05 -07001357 if (dfAttributes & DF_C_WIDE) {
1358 mir->ssaRep->fpUse[numUses] = dfAttributes & DF_FP_C;
1359 handleSSAUse(cUnit, mir->ssaRep->uses, dInsn->vC+1, numUses++);
1360 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001361 }
1362 }
1363 if (dfAttributes & DF_HAS_DEFS) {
1364 mir->ssaRep->fpDef[0] = dfAttributes & DF_FP_A;
1365 handleSSADef(cUnit, mir->ssaRep->defs, dInsn->vA, 0);
buzbeebff24652012-05-06 16:22:05 -07001366 if (dfAttributes & DF_A_WIDE) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001367 mir->ssaRep->fpDef[1] = dfAttributes & DF_FP_A;
1368 handleSSADef(cUnit, mir->ssaRep->defs, dInsn->vA+1, 1);
1369 }
1370 }
1371 }
1372
1373 if (!cUnit->disableDataflow) {
1374 /*
1375 * Take a snapshot of Dalvik->SSA mapping at the end of each block. The
1376 * input to PHI nodes can be derived from the snapshot of all
1377 * predecessor blocks.
1378 */
1379 bb->dataFlowInfo->vRegToSSAMap =
buzbeecbd6d442012-11-17 14:11:25 -08001380 static_cast<int*>(oatNew(cUnit, sizeof(int) * cUnit->numDalvikRegisters, false,
1381 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001382
1383 memcpy(bb->dataFlowInfo->vRegToSSAMap, cUnit->vRegToSSAMap,
1384 sizeof(int) * cUnit->numDalvikRegisters);
1385 }
1386 return true;
buzbee67bf8852011-08-17 17:51:35 -07001387}
1388
1389/* Setup a constant value for opcodes thare have the DF_SETS_CONST attribute */
buzbee31a4a6f2012-02-28 15:36:15 -08001390void setConstant(CompilationUnit* cUnit, int ssaReg, int value)
buzbee67bf8852011-08-17 17:51:35 -07001391{
Bill Buzbeea114add2012-05-03 15:00:40 -07001392 oatSetBit(cUnit, cUnit->isConstantV, ssaReg);
1393 cUnit->constantValues[ssaReg] = value;
buzbee67bf8852011-08-17 17:51:35 -07001394}
1395
1396bool oatDoConstantPropagation(CompilationUnit* cUnit, BasicBlock* bb)
1397{
Bill Buzbeea114add2012-05-03 15:00:40 -07001398 MIR* mir;
1399 ArenaBitVector *isConstantV = cUnit->isConstantV;
buzbee67bf8852011-08-17 17:51:35 -07001400
Bill Buzbeea114add2012-05-03 15:00:40 -07001401 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
1402 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
buzbee67bf8852011-08-17 17:51:35 -07001403
Bill Buzbeea114add2012-05-03 15:00:40 -07001404 DecodedInstruction *dInsn = &mir->dalvikInsn;
buzbee67bf8852011-08-17 17:51:35 -07001405
Bill Buzbeea114add2012-05-03 15:00:40 -07001406 if (!(dfAttributes & DF_HAS_DEFS)) continue;
buzbee67bf8852011-08-17 17:51:35 -07001407
Bill Buzbeea114add2012-05-03 15:00:40 -07001408 /* Handle instructions that set up constants directly */
1409 if (dfAttributes & DF_SETS_CONST) {
1410 if (dfAttributes & DF_DA) {
1411 switch (dInsn->opcode) {
1412 case Instruction::CONST_4:
1413 case Instruction::CONST_16:
1414 case Instruction::CONST:
1415 setConstant(cUnit, mir->ssaRep->defs[0], dInsn->vB);
1416 break;
1417 case Instruction::CONST_HIGH16:
1418 setConstant(cUnit, mir->ssaRep->defs[0], dInsn->vB << 16);
1419 break;
buzbeebff24652012-05-06 16:22:05 -07001420 case Instruction::CONST_WIDE_16:
1421 case Instruction::CONST_WIDE_32:
1422 setConstant(cUnit, mir->ssaRep->defs[0], dInsn->vB);
1423 setConstant(cUnit, mir->ssaRep->defs[1], 0);
1424 break;
1425 case Instruction::CONST_WIDE:
buzbeecbd6d442012-11-17 14:11:25 -08001426 setConstant(cUnit, mir->ssaRep->defs[0], static_cast<int>(dInsn->vB_wide));
1427 setConstant(cUnit, mir->ssaRep->defs[1], static_cast<int>(dInsn->vB_wide >> 32));
buzbeebff24652012-05-06 16:22:05 -07001428 break;
1429 case Instruction::CONST_WIDE_HIGH16:
1430 setConstant(cUnit, mir->ssaRep->defs[0], 0);
1431 setConstant(cUnit, mir->ssaRep->defs[1], dInsn->vB << 16);
1432 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001433 default:
1434 break;
buzbeebff24652012-05-06 16:22:05 -07001435 }
buzbee2cfc6392012-05-07 14:51:40 -07001436 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001437 /* Handle instructions that set up constants directly */
buzbee2cfc6392012-05-07 14:51:40 -07001438 } else if (dfAttributes & DF_IS_MOVE) {
1439 int i;
buzbee67bf8852011-08-17 17:51:35 -07001440
buzbee2cfc6392012-05-07 14:51:40 -07001441 for (i = 0; i < mir->ssaRep->numUses; i++) {
1442 if (!oatIsBitSet(isConstantV, mir->ssaRep->uses[i])) break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001443 }
1444 /* Move a register holding a constant to another register */
1445 if (i == mir->ssaRep->numUses) {
1446 setConstant(cUnit, mir->ssaRep->defs[0],
1447 cUnit->constantValues[mir->ssaRep->uses[0]]);
buzbeebff24652012-05-06 16:22:05 -07001448 if (dfAttributes & DF_A_WIDE) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001449 setConstant(cUnit, mir->ssaRep->defs[1],
1450 cUnit->constantValues[mir->ssaRep->uses[1]]);
buzbee67bf8852011-08-17 17:51:35 -07001451 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001452 }
buzbee67bf8852011-08-17 17:51:35 -07001453 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001454 }
1455 /* TODO: implement code to handle arithmetic operations */
1456 return true;
buzbee67bf8852011-08-17 17:51:35 -07001457}
1458
1459/* Setup the basic data structures for SSA conversion */
1460void oatInitializeSSAConversion(CompilationUnit* cUnit)
1461{
Bill Buzbeea114add2012-05-03 15:00:40 -07001462 int i;
1463 int numDalvikReg = cUnit->numDalvikRegisters;
buzbee67bf8852011-08-17 17:51:35 -07001464
buzbeecbd6d442012-11-17 14:11:25 -08001465 cUnit->ssaBaseVRegs =
1466 static_cast<GrowableList*>(oatNew(cUnit, sizeof(GrowableList), false, kAllocDFInfo));
1467 cUnit->ssaSubscripts =
1468 static_cast<GrowableList*>(oatNew(cUnit, sizeof(GrowableList), false, kAllocDFInfo));
1469 cUnit->ssaStrings =
1470 static_cast<GrowableList*>(oatNew(cUnit, sizeof(GrowableList), false, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001471 // Create the ssa mappings, estimating the max size
1472 oatInitGrowableList(cUnit, cUnit->ssaBaseVRegs,
1473 numDalvikReg + cUnit->defCount + 128,
1474 kListSSAtoDalvikMap);
1475 oatInitGrowableList(cUnit, cUnit->ssaSubscripts,
1476 numDalvikReg + cUnit->defCount + 128,
1477 kListSSAtoDalvikMap);
buzbee2cfc6392012-05-07 14:51:40 -07001478 oatInitGrowableList(cUnit, cUnit->ssaStrings,
1479 numDalvikReg + cUnit->defCount + 128,
1480 kListSSAtoDalvikMap);
Bill Buzbeea114add2012-05-03 15:00:40 -07001481 /*
1482 * Initial number of SSA registers is equal to the number of Dalvik
1483 * registers.
1484 */
1485 cUnit->numSSARegs = numDalvikReg;
buzbee67bf8852011-08-17 17:51:35 -07001486
Bill Buzbeea114add2012-05-03 15:00:40 -07001487 /*
1488 * Initialize the SSA2Dalvik map list. For the first numDalvikReg elements,
1489 * the subscript is 0 so we use the ENCODE_REG_SUB macro to encode the value
1490 * into "(0 << 16) | i"
1491 */
1492 for (i = 0; i < numDalvikReg; i++) {
1493 oatInsertGrowableList(cUnit, cUnit->ssaBaseVRegs, i);
1494 oatInsertGrowableList(cUnit, cUnit->ssaSubscripts, 0);
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001495 std::string ssaName = getSSAName(cUnit, i);
buzbeecbd6d442012-11-17 14:11:25 -08001496 char* name = static_cast<char*>(oatNew(cUnit, ssaName.length() + 1, true, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001497 strncpy(name, ssaName.c_str(), ssaName.length() + 1);
buzbeecbd6d442012-11-17 14:11:25 -08001498 oatInsertGrowableList(cUnit, cUnit->ssaStrings, reinterpret_cast<uintptr_t>(name));
Bill Buzbeea114add2012-05-03 15:00:40 -07001499 }
buzbee67bf8852011-08-17 17:51:35 -07001500
Bill Buzbeea114add2012-05-03 15:00:40 -07001501 /*
1502 * Initialize the DalvikToSSAMap map. There is one entry for each
1503 * Dalvik register, and the SSA names for those are the same.
1504 */
buzbeecbd6d442012-11-17 14:11:25 -08001505 cUnit->vRegToSSAMap =
1506 static_cast<int*>(oatNew(cUnit, sizeof(int) * numDalvikReg, false, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001507 /* Keep track of the higest def for each dalvik reg */
buzbeecbd6d442012-11-17 14:11:25 -08001508 cUnit->SSALastDefs =
1509 static_cast<int*>(oatNew(cUnit, sizeof(int) * numDalvikReg, false, kAllocDFInfo));
buzbeef0cde542011-09-13 14:55:02 -07001510
Bill Buzbeea114add2012-05-03 15:00:40 -07001511 for (i = 0; i < numDalvikReg; i++) {
1512 cUnit->vRegToSSAMap[i] = i;
1513 cUnit->SSALastDefs[i] = 0;
1514 }
buzbee67bf8852011-08-17 17:51:35 -07001515
Bill Buzbeea114add2012-05-03 15:00:40 -07001516 /* Add ssa reg for Method* */
1517 cUnit->methodSReg = addNewSReg(cUnit, SSA_METHOD_BASEREG);
buzbeee1965672012-03-11 18:39:19 -07001518
Bill Buzbeea114add2012-05-03 15:00:40 -07001519 /*
1520 * Allocate the BasicBlockDataFlow structure for the entry and code blocks
1521 */
1522 GrowableListIterator iterator;
buzbee67bf8852011-08-17 17:51:35 -07001523
Bill Buzbeea114add2012-05-03 15:00:40 -07001524 oatGrowableListIteratorInit(&cUnit->blockList, &iterator);
buzbee67bf8852011-08-17 17:51:35 -07001525
Bill Buzbeea114add2012-05-03 15:00:40 -07001526 while (true) {
buzbeecbd6d442012-11-17 14:11:25 -08001527 BasicBlock* bb = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iterator));
Bill Buzbeea114add2012-05-03 15:00:40 -07001528 if (bb == NULL) break;
1529 if (bb->hidden == true) continue;
1530 if (bb->blockType == kDalvikByteCode ||
1531 bb->blockType == kEntryBlock ||
1532 bb->blockType == kExitBlock) {
buzbeecbd6d442012-11-17 14:11:25 -08001533 bb->dataFlowInfo = static_cast<BasicBlockDataFlow*>(oatNew(cUnit, sizeof(BasicBlockDataFlow),
1534 true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001535 }
1536 }
buzbee67bf8852011-08-17 17:51:35 -07001537}
1538
1539/* Clear the visited flag for each BB */
buzbee31a4a6f2012-02-28 15:36:15 -08001540bool oatClearVisitedFlag(struct CompilationUnit* cUnit, struct BasicBlock* bb)
buzbee67bf8852011-08-17 17:51:35 -07001541{
Bill Buzbeea114add2012-05-03 15:00:40 -07001542 bb->visited = false;
1543 return true;
buzbee67bf8852011-08-17 17:51:35 -07001544}
1545
1546void oatDataFlowAnalysisDispatcher(CompilationUnit* cUnit,
Bill Buzbeea114add2012-05-03 15:00:40 -07001547 bool (*func)(CompilationUnit*, BasicBlock*),
1548 DataFlowAnalysisMode dfaMode,
1549 bool isIterative)
buzbee67bf8852011-08-17 17:51:35 -07001550{
Bill Buzbeea114add2012-05-03 15:00:40 -07001551 bool change = true;
buzbee67bf8852011-08-17 17:51:35 -07001552
Bill Buzbeea114add2012-05-03 15:00:40 -07001553 while (change) {
1554 change = false;
buzbee67bf8852011-08-17 17:51:35 -07001555
Bill Buzbeea114add2012-05-03 15:00:40 -07001556 switch (dfaMode) {
1557 /* Scan all blocks and perform the operations specified in func */
1558 case kAllNodes:
1559 {
1560 GrowableListIterator iterator;
1561 oatGrowableListIteratorInit(&cUnit->blockList, &iterator);
1562 while (true) {
buzbeecbd6d442012-11-17 14:11:25 -08001563 BasicBlock* bb = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iterator));
Bill Buzbeea114add2012-05-03 15:00:40 -07001564 if (bb == NULL) break;
1565 if (bb->hidden == true) continue;
1566 change |= (*func)(cUnit, bb);
1567 }
buzbee67bf8852011-08-17 17:51:35 -07001568 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001569 break;
1570 /* Scan reachable blocks and perform the ops specified in func. */
1571 case kReachableNodes:
1572 {
1573 int numReachableBlocks = cUnit->numReachableBlocks;
1574 int idx;
1575 const GrowableList *blockList = &cUnit->blockList;
1576
1577 for (idx = 0; idx < numReachableBlocks; idx++) {
1578 int blockIdx = cUnit->dfsOrder.elemList[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001579 BasicBlock* bb =
1580 reinterpret_cast<BasicBlock*>( oatGrowableListGetElement(blockList, blockIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -07001581 change |= (*func)(cUnit, bb);
1582 }
1583 }
1584 break;
1585
1586 /* Scan reachable blocks by pre-order dfs and invoke func on each. */
1587 case kPreOrderDFSTraversal:
1588 {
1589 int numReachableBlocks = cUnit->numReachableBlocks;
1590 int idx;
1591 const GrowableList *blockList = &cUnit->blockList;
1592
1593 for (idx = 0; idx < numReachableBlocks; idx++) {
1594 int dfsIdx = cUnit->dfsOrder.elemList[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001595 BasicBlock* bb =
1596 reinterpret_cast<BasicBlock*>(oatGrowableListGetElement(blockList, dfsIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -07001597 change |= (*func)(cUnit, bb);
1598 }
1599 }
1600 break;
1601 /* Scan reachable blocks post-order dfs and invoke func on each. */
1602 case kPostOrderDFSTraversal:
1603 {
1604 int numReachableBlocks = cUnit->numReachableBlocks;
1605 int idx;
1606 const GrowableList *blockList = &cUnit->blockList;
1607
1608 for (idx = numReachableBlocks - 1; idx >= 0; idx--) {
1609 int dfsIdx = cUnit->dfsOrder.elemList[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001610 BasicBlock* bb =
1611 reinterpret_cast<BasicBlock *>( oatGrowableListGetElement(blockList, dfsIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -07001612 change |= (*func)(cUnit, bb);
1613 }
1614 }
1615 break;
1616 /* Scan reachable post-order dom tree and invoke func on each. */
1617 case kPostOrderDOMTraversal:
1618 {
1619 int numReachableBlocks = cUnit->numReachableBlocks;
1620 int idx;
1621 const GrowableList *blockList = &cUnit->blockList;
1622
1623 for (idx = 0; idx < numReachableBlocks; idx++) {
1624 int domIdx = cUnit->domPostOrderTraversal.elemList[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001625 BasicBlock* bb =
1626 reinterpret_cast<BasicBlock*>( oatGrowableListGetElement(blockList, domIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -07001627 change |= (*func)(cUnit, bb);
1628 }
1629 }
1630 break;
1631 /* Scan reachable blocks reverse post-order dfs, invoke func on each */
1632 case kReversePostOrderTraversal:
1633 {
1634 int numReachableBlocks = cUnit->numReachableBlocks;
1635 int idx;
1636 const GrowableList *blockList = &cUnit->blockList;
1637
1638 for (idx = numReachableBlocks - 1; idx >= 0; idx--) {
1639 int revIdx = cUnit->dfsPostOrder.elemList[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001640 BasicBlock* bb =
1641 reinterpret_cast<BasicBlock*>(oatGrowableListGetElement(blockList, revIdx));
Bill Buzbeea114add2012-05-03 15:00:40 -07001642 change |= (*func)(cUnit, bb);
1643 }
1644 }
1645 break;
1646 default:
buzbeecbd6d442012-11-17 14:11:25 -08001647 LOG(FATAL) << "Unknown traversal mode: " << dfaMode;
buzbee67bf8852011-08-17 17:51:35 -07001648 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001649 /* If isIterative is false, exit the loop after the first iteration */
1650 change &= isIterative;
1651 }
buzbee67bf8852011-08-17 17:51:35 -07001652}
buzbee43a36422011-09-14 14:00:13 -07001653
buzbeee1965672012-03-11 18:39:19 -07001654/* Advance to next strictly dominated MIR node in an extended basic block */
Bill Buzbeea114add2012-05-03 15:00:40 -07001655MIR* advanceMIR(CompilationUnit* cUnit, BasicBlock** pBb, MIR* mir,
1656 ArenaBitVector* bv, bool clearMark) {
1657 BasicBlock* bb = *pBb;
1658 if (mir != NULL) {
1659 mir = mir->next;
1660 if (mir == NULL) {
1661 bb = bb->fallThrough;
1662 if ((bb == NULL) || bb->predecessors->numUsed != 1) {
1663 mir = NULL;
1664 } else {
1665 if (bv) {
1666 oatSetBit(cUnit, bv, bb->id);
buzbeee1965672012-03-11 18:39:19 -07001667 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001668 *pBb = bb;
1669 mir = bb->firstMIRInsn;
1670 }
buzbeee1965672012-03-11 18:39:19 -07001671 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001672 }
1673 if (mir && clearMark) {
1674 mir->optimizationFlags &= ~MIR_MARK;
1675 }
1676 return mir;
buzbeee1965672012-03-11 18:39:19 -07001677}
1678
buzbeefc9e6fa2012-03-23 15:14:29 -07001679/*
1680 * To be used at an invoke mir. If the logically next mir node represents
1681 * a move-result, return it. Else, return NULL. If a move-result exists,
1682 * it is required to immediately follow the invoke with no intervening
1683 * opcodes or incoming arcs. However, if the result of the invoke is not
1684 * used, a move-result may not be present.
1685 */
buzbee15bf9802012-06-12 17:49:27 -07001686MIR* oatFindMoveResult(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir)
buzbeefc9e6fa2012-03-23 15:14:29 -07001687{
Bill Buzbeea114add2012-05-03 15:00:40 -07001688 BasicBlock* tbb = bb;
1689 mir = advanceMIR(cUnit, &tbb, mir, NULL, false);
1690 while (mir != NULL) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001691 int opcode = mir->dalvikInsn.opcode;
buzbee15bf9802012-06-12 17:49:27 -07001692 if ((mir->dalvikInsn.opcode == Instruction::MOVE_RESULT) ||
buzbee52ed7762012-06-13 23:43:14 -07001693 (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) ||
buzbee15bf9802012-06-12 17:49:27 -07001694 (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_WIDE)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001695 break;
1696 }
1697 // Keep going if pseudo op, otherwise terminate
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001698 if (opcode < kNumPackedOpcodes) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001699 mir = NULL;
1700 } else {
1701 mir = advanceMIR(cUnit, &tbb, mir, NULL, false);
1702 }
1703 }
1704 return mir;
buzbeefc9e6fa2012-03-23 15:14:29 -07001705}
1706
buzbee239c4e72012-03-16 08:42:29 -07001707void squashDupRangeChecks(CompilationUnit* cUnit, BasicBlock** pBp, MIR* mir,
Bill Buzbeea114add2012-05-03 15:00:40 -07001708 int arraySreg, int indexSreg)
buzbee239c4e72012-03-16 08:42:29 -07001709{
Bill Buzbeea114add2012-05-03 15:00:40 -07001710 while (true) {
1711 mir = advanceMIR(cUnit, pBp, mir, NULL, false);
1712 if (!mir) {
1713 break;
buzbee239c4e72012-03-16 08:42:29 -07001714 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001715 if ((mir->ssaRep == NULL) ||
1716 (mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
1717 continue;
1718 }
1719 int checkArray = INVALID_SREG;
1720 int checkIndex = INVALID_SREG;
1721 switch (mir->dalvikInsn.opcode) {
1722 case Instruction::AGET:
1723 case Instruction::AGET_OBJECT:
1724 case Instruction::AGET_BOOLEAN:
1725 case Instruction::AGET_BYTE:
1726 case Instruction::AGET_CHAR:
1727 case Instruction::AGET_SHORT:
1728 case Instruction::AGET_WIDE:
1729 checkArray = mir->ssaRep->uses[0];
1730 checkIndex = mir->ssaRep->uses[1];
1731 break;
1732 case Instruction::APUT:
1733 case Instruction::APUT_OBJECT:
1734 case Instruction::APUT_SHORT:
1735 case Instruction::APUT_CHAR:
1736 case Instruction::APUT_BYTE:
1737 case Instruction::APUT_BOOLEAN:
1738 checkArray = mir->ssaRep->uses[1];
1739 checkIndex = mir->ssaRep->uses[2];
1740 break;
1741 case Instruction::APUT_WIDE:
1742 checkArray = mir->ssaRep->uses[2];
1743 checkIndex = mir->ssaRep->uses[3];
1744 default:
1745 break;
1746 }
1747 if (checkArray == INVALID_SREG) {
1748 continue;
1749 }
1750 if ((arraySreg == checkArray) && (indexSreg == checkIndex)) {
1751 if (cUnit->printMe) {
1752 LOG(INFO) << "Squashing range check @ 0x" << std::hex << mir->offset;
1753 }
1754 mir->optimizationFlags |= MIR_IGNORE_RANGE_CHECK;
1755 }
1756 }
buzbee239c4e72012-03-16 08:42:29 -07001757}
1758
buzbeee1965672012-03-11 18:39:19 -07001759/* Allocate a compiler temp, return Sreg. Reuse existing if no conflict */
1760int allocCompilerTempSreg(CompilationUnit* cUnit, ArenaBitVector* bv)
1761{
Bill Buzbeea114add2012-05-03 15:00:40 -07001762 for (int i = 0; i < cUnit->numCompilerTemps; i++) {
buzbeecbd6d442012-11-17 14:11:25 -08001763 CompilerTemp* ct = reinterpret_cast<CompilerTemp*>(cUnit->compilerTemps.elemList[i]);
Bill Buzbeea114add2012-05-03 15:00:40 -07001764 ArenaBitVector* tBv = ct->bv;
1765 if (!oatTestBitVectors(bv, tBv)) {
1766 // Combine live maps and reuse existing temp
1767 oatUnifyBitVectors(tBv, tBv, bv);
1768 return ct->sReg;
buzbeee1965672012-03-11 18:39:19 -07001769 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001770 }
buzbeee1965672012-03-11 18:39:19 -07001771
Bill Buzbeea114add2012-05-03 15:00:40 -07001772 // Create a new compiler temp & associated live bitmap
buzbeecbd6d442012-11-17 14:11:25 -08001773 CompilerTemp* ct =
1774 static_cast<CompilerTemp*>(oatNew(cUnit, sizeof(CompilerTemp), true, kAllocMisc));
Bill Buzbeea114add2012-05-03 15:00:40 -07001775 ArenaBitVector *nBv = oatAllocBitVector(cUnit, cUnit->numBlocks, true,
1776 kBitMapMisc);
1777 oatCopyBitVector(nBv, bv);
1778 ct->bv = nBv;
1779 ct->sReg = addNewSReg(cUnit, SSA_CTEMP_BASEREG - cUnit->numCompilerTemps);
1780 cUnit->numCompilerTemps++;
buzbeecbd6d442012-11-17 14:11:25 -08001781 oatInsertGrowableList(cUnit, &cUnit->compilerTemps, reinterpret_cast<uintptr_t>(ct));
1782 DCHECK_EQ(cUnit->numCompilerTemps, static_cast<int>(cUnit->compilerTemps.numUsed));
Bill Buzbeea114add2012-05-03 15:00:40 -07001783 return ct->sReg;
buzbeee1965672012-03-11 18:39:19 -07001784}
1785
1786/* Creata a new MIR node for a new pseudo op. */
Bill Buzbeea114add2012-05-03 15:00:40 -07001787MIR* rawMIR(CompilationUnit* cUnit, Instruction::Code opcode, int defs,
1788 int uses)
buzbeee1965672012-03-11 18:39:19 -07001789{
buzbeecbd6d442012-11-17 14:11:25 -08001790 MIR* res = static_cast<MIR*>(oatNew(cUnit, sizeof(MIR), true, kAllocMIR));
1791 res->ssaRep = static_cast<struct SSARepresentation*>
1792 (oatNew(cUnit, sizeof(SSARepresentation), true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001793 if (uses) {
1794 res->ssaRep->numUses = uses;
buzbeecbd6d442012-11-17 14:11:25 -08001795 res->ssaRep->uses = static_cast<int*>(oatNew(cUnit, sizeof(int) * uses, false, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001796 }
1797 if (defs) {
1798 res->ssaRep->numDefs = defs;
buzbeecbd6d442012-11-17 14:11:25 -08001799 res->ssaRep->defs = static_cast<int*>(oatNew(cUnit, sizeof(int) * defs, false, kAllocDFInfo));
1800 res->ssaRep->fpDef = static_cast<bool*>(oatNew(cUnit, sizeof(bool) * defs, true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001801 }
1802 res->dalvikInsn.opcode = opcode;
1803 return res;
buzbeee1965672012-03-11 18:39:19 -07001804}
1805
1806/* Do some MIR-level basic block optimizations */
1807bool basicBlockOpt(CompilationUnit* cUnit, BasicBlock* bb)
1808{
Bill Buzbeea114add2012-05-03 15:00:40 -07001809 int numTemps = 0;
buzbeee1965672012-03-11 18:39:19 -07001810
Bill Buzbeea114add2012-05-03 15:00:40 -07001811 for (MIR* mir = bb->firstMIRInsn; mir; mir = mir->next) {
1812 // Look for interesting opcodes, skip otherwise
1813 Instruction::Code opcode = mir->dalvikInsn.opcode;
1814 switch (opcode) {
1815 case Instruction::AGET:
1816 case Instruction::AGET_OBJECT:
1817 case Instruction::AGET_BOOLEAN:
1818 case Instruction::AGET_BYTE:
1819 case Instruction::AGET_CHAR:
1820 case Instruction::AGET_SHORT:
1821 case Instruction::AGET_WIDE:
1822 if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
1823 int arrSreg = mir->ssaRep->uses[0];
1824 int idxSreg = mir->ssaRep->uses[1];
1825 BasicBlock* tbb = bb;
1826 squashDupRangeChecks(cUnit, &tbb, mir, arrSreg, idxSreg);
buzbeee1965672012-03-11 18:39:19 -07001827 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001828 break;
1829 case Instruction::APUT:
1830 case Instruction::APUT_OBJECT:
1831 case Instruction::APUT_SHORT:
1832 case Instruction::APUT_CHAR:
1833 case Instruction::APUT_BYTE:
1834 case Instruction::APUT_BOOLEAN:
1835 case Instruction::APUT_WIDE:
1836 if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) {
1837 int start = (opcode == Instruction::APUT_WIDE) ? 2 : 1;
1838 int arrSreg = mir->ssaRep->uses[start];
1839 int idxSreg = mir->ssaRep->uses[start + 1];
1840 BasicBlock* tbb = bb;
1841 squashDupRangeChecks(cUnit, &tbb, mir, arrSreg, idxSreg);
1842 }
1843 break;
1844 case Instruction::CMPL_FLOAT:
1845 case Instruction::CMPL_DOUBLE:
1846 case Instruction::CMPG_FLOAT:
1847 case Instruction::CMPG_DOUBLE:
1848 case Instruction::CMP_LONG:
buzbeeca7a5e42012-08-20 11:12:18 -07001849 if (cUnit->genBitcode) {
1850 // Bitcode doesn't allow this optimization.
1851 break;
1852 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001853 if (mir->next != NULL) {
1854 MIR* mirNext = mir->next;
1855 Instruction::Code brOpcode = mirNext->dalvikInsn.opcode;
1856 ConditionCode ccode = kCondNv;
1857 switch(brOpcode) {
1858 case Instruction::IF_EQZ:
1859 ccode = kCondEq;
1860 break;
1861 case Instruction::IF_NEZ:
1862 ccode = kCondNe;
1863 break;
1864 case Instruction::IF_LTZ:
1865 ccode = kCondLt;
1866 break;
1867 case Instruction::IF_GEZ:
1868 ccode = kCondGe;
1869 break;
1870 case Instruction::IF_GTZ:
1871 ccode = kCondGt;
1872 break;
1873 case Instruction::IF_LEZ:
1874 ccode = kCondLe;
1875 break;
1876 default:
1877 break;
1878 }
1879 // Make sure result of cmp is used by next insn and nowhere else
1880 if ((ccode != kCondNv) &&
1881 (mir->ssaRep->defs[0] == mirNext->ssaRep->uses[0]) &&
1882 (getSSAUseCount(cUnit, mir->ssaRep->defs[0]) == 1)) {
1883 mirNext->dalvikInsn.arg[0] = ccode;
1884 switch(opcode) {
1885 case Instruction::CMPL_FLOAT:
1886 mirNext->dalvikInsn.opcode =
1887 static_cast<Instruction::Code>(kMirOpFusedCmplFloat);
1888 break;
1889 case Instruction::CMPL_DOUBLE:
1890 mirNext->dalvikInsn.opcode =
1891 static_cast<Instruction::Code>(kMirOpFusedCmplDouble);
1892 break;
1893 case Instruction::CMPG_FLOAT:
1894 mirNext->dalvikInsn.opcode =
1895 static_cast<Instruction::Code>(kMirOpFusedCmpgFloat);
1896 break;
1897 case Instruction::CMPG_DOUBLE:
1898 mirNext->dalvikInsn.opcode =
1899 static_cast<Instruction::Code>(kMirOpFusedCmpgDouble);
1900 break;
1901 case Instruction::CMP_LONG:
1902 mirNext->dalvikInsn.opcode =
1903 static_cast<Instruction::Code>(kMirOpFusedCmpLong);
1904 break;
buzbeecbd6d442012-11-17 14:11:25 -08001905 default: LOG(ERROR) << "Unexpected opcode: " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07001906 }
1907 mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
1908 mirNext->ssaRep->numUses = mir->ssaRep->numUses;
1909 mirNext->ssaRep->uses = mir->ssaRep->uses;
1910 mirNext->ssaRep->fpUse = mir->ssaRep->fpUse;
1911 mirNext->ssaRep->numDefs = 0;
1912 mir->ssaRep->numUses = 0;
1913 mir->ssaRep->numDefs = 0;
1914 }
1915 }
1916 break;
1917 default:
1918 break;
buzbeee1965672012-03-11 18:39:19 -07001919 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001920 }
buzbeee1965672012-03-11 18:39:19 -07001921
Bill Buzbeea114add2012-05-03 15:00:40 -07001922 if (numTemps > cUnit->numCompilerTemps) {
1923 cUnit->numCompilerTemps = numTemps;
1924 }
1925 return true;
buzbeee1965672012-03-11 18:39:19 -07001926}
1927
buzbee31a4a6f2012-02-28 15:36:15 -08001928bool nullCheckEliminationInit(struct CompilationUnit* cUnit,
1929 struct BasicBlock* bb)
buzbee43a36422011-09-14 14:00:13 -07001930{
Bill Buzbeea114add2012-05-03 15:00:40 -07001931 if (bb->dataFlowInfo == NULL) return false;
1932 bb->dataFlowInfo->endingNullCheckV =
1933 oatAllocBitVector(cUnit, cUnit->numSSARegs, false, kBitMapNullCheck);
1934 oatClearAllBits(bb->dataFlowInfo->endingNullCheckV);
1935 return true;
buzbee43a36422011-09-14 14:00:13 -07001936}
1937
buzbeed1643e42012-09-05 14:06:51 -07001938/* Collect stats on number of checks removed */
1939bool countChecks( struct CompilationUnit* cUnit, struct BasicBlock* bb)
1940{
1941 if (bb->dataFlowInfo == NULL) return false;
1942 for (MIR* mir = bb->firstMIRInsn; mir; mir = mir->next) {
1943 if (mir->ssaRep == NULL) {
1944 continue;
1945 }
1946 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
1947 if (dfAttributes & DF_HAS_NULL_CHKS) {
1948 cUnit->checkstats->nullChecks++;
1949 if (mir->optimizationFlags & MIR_IGNORE_NULL_CHECK) {
1950 cUnit->checkstats->nullChecksEliminated++;
1951 }
1952 }
1953 if (dfAttributes & DF_HAS_RANGE_CHKS) {
1954 cUnit->checkstats->rangeChecks++;
1955 if (mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK) {
1956 cUnit->checkstats->rangeChecksEliminated++;
1957 }
1958 }
1959 }
1960 return false;
1961}
1962
buzbee0967a252012-09-14 10:43:54 -07001963/* Try to make common case the fallthrough path */
1964bool layoutBlocks(struct CompilationUnit* cUnit, struct BasicBlock* bb)
1965{
1966 // TODO: For now, just looking for direct throws. Consider generalizing for profile feedback
1967 if (!bb->explicitThrow) {
1968 return false;
1969 }
1970 BasicBlock* walker = bb;
1971 while (true) {
1972 // Check termination conditions
1973 if ((walker->blockType == kEntryBlock) || (walker->predecessors->numUsed != 1)) {
1974 break;
1975 }
1976 BasicBlock* prev = GET_ELEM_N(walker->predecessors, BasicBlock*, 0);
1977 if (prev->conditionalBranch) {
1978 if (prev->fallThrough == walker) {
1979 // Already done - return
1980 break;
1981 }
1982 DCHECK_EQ(walker, prev->taken);
1983 // Got one. Flip it and exit
1984 Instruction::Code opcode = prev->lastMIRInsn->dalvikInsn.opcode;
1985 switch (opcode) {
1986 case Instruction::IF_EQ: opcode = Instruction::IF_NE; break;
1987 case Instruction::IF_NE: opcode = Instruction::IF_EQ; break;
1988 case Instruction::IF_LT: opcode = Instruction::IF_GE; break;
1989 case Instruction::IF_GE: opcode = Instruction::IF_LT; break;
1990 case Instruction::IF_GT: opcode = Instruction::IF_LE; break;
1991 case Instruction::IF_LE: opcode = Instruction::IF_GT; break;
1992 case Instruction::IF_EQZ: opcode = Instruction::IF_NEZ; break;
1993 case Instruction::IF_NEZ: opcode = Instruction::IF_EQZ; break;
1994 case Instruction::IF_LTZ: opcode = Instruction::IF_GEZ; break;
1995 case Instruction::IF_GEZ: opcode = Instruction::IF_LTZ; break;
1996 case Instruction::IF_GTZ: opcode = Instruction::IF_LEZ; break;
1997 case Instruction::IF_LEZ: opcode = Instruction::IF_GTZ; break;
buzbeecbd6d442012-11-17 14:11:25 -08001998 default: LOG(FATAL) << "Unexpected opcode " << opcode;
buzbee0967a252012-09-14 10:43:54 -07001999 }
2000 prev->lastMIRInsn->dalvikInsn.opcode = opcode;
2001 BasicBlock* tBB = prev->taken;
2002 prev->taken = prev->fallThrough;
2003 prev->fallThrough = tBB;
2004 break;
2005 }
2006 walker = prev;
2007 }
2008 return false;
2009}
2010
buzbeed1643e42012-09-05 14:06:51 -07002011/* Combine any basic blocks terminated by instructions that we now know can't throw */
2012bool combineBlocks(struct CompilationUnit* cUnit, struct BasicBlock* bb)
2013{
2014 // Loop here to allow combining a sequence of blocks
2015 while (true) {
2016 // Check termination conditions
2017 if ((bb->firstMIRInsn == NULL)
2018 || (bb->dataFlowInfo == NULL)
2019 || (bb->blockType == kExceptionHandling)
2020 || (bb->blockType == kExitBlock)
2021 || (bb->blockType == kDead)
2022 || ((bb->taken == NULL) || (bb->taken->blockType != kExceptionHandling))
2023 || (bb->successorBlockList.blockListType != kNotUsed)
buzbeecbd6d442012-11-17 14:11:25 -08002024 || (static_cast<int>(bb->lastMIRInsn->dalvikInsn.opcode) != kMirOpCheck)) {
buzbeed1643e42012-09-05 14:06:51 -07002025 break;
2026 }
2027
2028 // Test the kMirOpCheck instruction
2029 MIR* mir = bb->lastMIRInsn;
2030 // Grab the attributes from the paired opcode
2031 MIR* throwInsn = mir->meta.throwInsn;
2032 int dfAttributes = oatDataFlowAttributes[throwInsn->dalvikInsn.opcode];
buzbee0967a252012-09-14 10:43:54 -07002033 bool canCombine = true;
2034 if (dfAttributes & DF_HAS_NULL_CHKS) {
2035 canCombine &= ((throwInsn->optimizationFlags & MIR_IGNORE_NULL_CHECK) != 0);
2036 }
2037 if (dfAttributes & DF_HAS_RANGE_CHKS) {
2038 canCombine &= ((throwInsn->optimizationFlags & MIR_IGNORE_RANGE_CHECK) != 0);
2039 }
2040 if (!canCombine) {
buzbeed1643e42012-09-05 14:06:51 -07002041 break;
2042 }
2043 // OK - got one. Combine
2044 BasicBlock* bbNext = bb->fallThrough;
2045 DCHECK(!bbNext->catchEntry);
2046 DCHECK_EQ(bbNext->predecessors->numUsed, 1U);
2047 MIR* tMir = bb->lastMIRInsn->prev;
2048 // Overwrite the kOpCheck insn with the paired opcode
2049 DCHECK_EQ(bbNext->firstMIRInsn, throwInsn);
2050 *bb->lastMIRInsn = *throwInsn;
2051 bb->lastMIRInsn->prev = tMir;
2052 // Use the successor info from the next block
2053 bb->successorBlockList = bbNext->successorBlockList;
2054 // Use the ending block linkage from the next block
2055 bb->fallThrough = bbNext->fallThrough;
2056 bb->taken->blockType = kDead; // Kill the unused exception block
2057 bb->taken = bbNext->taken;
2058 // Include the rest of the instructions
2059 bb->lastMIRInsn = bbNext->lastMIRInsn;
2060
2061 /*
2062 * NOTE: we aren't updating all dataflow info here. Should either make sure this pass
2063 * happens after uses of iDominated, domFrontier or update the dataflow info here.
2064 */
2065
2066 // Kill bbNext and remap now-dead id to parent
2067 bbNext->blockType = kDead;
2068 cUnit->blockIdMap.Overwrite(bbNext->id, bb->id);
2069
2070 // Now, loop back and see if we can keep going
2071 }
2072 return false;
2073}
2074
buzbee43a36422011-09-14 14:00:13 -07002075/* Eliminate unnecessary null checks for a basic block. */
buzbee31a4a6f2012-02-28 15:36:15 -08002076bool eliminateNullChecks( struct CompilationUnit* cUnit, struct BasicBlock* bb)
buzbee43a36422011-09-14 14:00:13 -07002077{
Bill Buzbeea114add2012-05-03 15:00:40 -07002078 if (bb->dataFlowInfo == NULL) return false;
2079
2080 /*
2081 * Set initial state. Be conservative with catch
2082 * blocks and start with no assumptions about null check
2083 * status (except for "this").
2084 */
2085 if ((bb->blockType == kEntryBlock) | bb->catchEntry) {
2086 oatClearAllBits(cUnit->tempSSARegisterV);
2087 if ((cUnit->access_flags & kAccStatic) == 0) {
2088 // If non-static method, mark "this" as non-null
2089 int thisReg = cUnit->numDalvikRegisters - cUnit->numIns;
2090 oatSetBit(cUnit, cUnit->tempSSARegisterV, thisReg);
2091 }
2092 } else {
2093 // Starting state is intesection of all incoming arcs
2094 GrowableListIterator iter;
2095 oatGrowableListIteratorInit(bb->predecessors, &iter);
buzbeecbd6d442012-11-17 14:11:25 -08002096 BasicBlock* predBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter));
Bill Buzbeea114add2012-05-03 15:00:40 -07002097 DCHECK(predBB != NULL);
2098 oatCopyBitVector(cUnit->tempSSARegisterV,
2099 predBB->dataFlowInfo->endingNullCheckV);
2100 while (true) {
buzbeecbd6d442012-11-17 14:11:25 -08002101 predBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter));
Bill Buzbeea114add2012-05-03 15:00:40 -07002102 if (!predBB) break;
2103 if ((predBB->dataFlowInfo == NULL) ||
2104 (predBB->dataFlowInfo->endingNullCheckV == NULL)) {
2105 continue;
2106 }
2107 oatIntersectBitVectors(cUnit->tempSSARegisterV,
2108 cUnit->tempSSARegisterV,
2109 predBB->dataFlowInfo->endingNullCheckV);
2110 }
2111 }
2112
2113 // Walk through the instruction in the block, updating as necessary
2114 for (MIR* mir = bb->firstMIRInsn; mir; mir = mir->next) {
2115 if (mir->ssaRep == NULL) {
2116 continue;
2117 }
2118 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
2119
2120 // Mark target of NEW* as non-null
2121 if (dfAttributes & DF_NON_NULL_DST) {
2122 oatSetBit(cUnit, cUnit->tempSSARegisterV, mir->ssaRep->defs[0]);
2123 }
2124
2125 // Mark non-null returns from invoke-style NEW*
2126 if (dfAttributes & DF_NON_NULL_RET) {
2127 MIR* nextMir = mir->next;
2128 // Next should be an MOVE_RESULT_OBJECT
2129 if (nextMir &&
2130 nextMir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) {
2131 // Mark as null checked
2132 oatSetBit(cUnit, cUnit->tempSSARegisterV, nextMir->ssaRep->defs[0]);
2133 } else {
2134 if (nextMir) {
buzbeecbd6d442012-11-17 14:11:25 -08002135 LOG(WARNING) << "Unexpected opcode following new: " << nextMir->dalvikInsn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07002136 } else if (bb->fallThrough) {
2137 // Look in next basic block
2138 struct BasicBlock* nextBB = bb->fallThrough;
2139 for (MIR* tmir = nextBB->firstMIRInsn; tmir;
2140 tmir =tmir->next) {
buzbeecbd6d442012-11-17 14:11:25 -08002141 if (static_cast<int>(tmir->dalvikInsn.opcode) >= static_cast<int>(kMirOpFirst)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002142 continue;
2143 }
2144 // First non-pseudo should be MOVE_RESULT_OBJECT
2145 if (tmir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) {
2146 // Mark as null checked
2147 oatSetBit(cUnit, cUnit->tempSSARegisterV, tmir->ssaRep->defs[0]);
2148 } else {
buzbeecbd6d442012-11-17 14:11:25 -08002149 LOG(WARNING) << "Unexpected op after new: " << tmir->dalvikInsn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07002150 }
2151 break;
2152 }
2153 }
2154 }
2155 }
buzbee5abfa3e2012-01-31 17:01:43 -08002156
buzbee43a36422011-09-14 14:00:13 -07002157 /*
Bill Buzbeea114add2012-05-03 15:00:40 -07002158 * Propagate nullcheck state on register copies (including
2159 * Phi pseudo copies. For the latter, nullcheck state is
2160 * the "and" of all the Phi's operands.
buzbee43a36422011-09-14 14:00:13 -07002161 */
Bill Buzbeea114add2012-05-03 15:00:40 -07002162 if (dfAttributes & (DF_NULL_TRANSFER_0 | DF_NULL_TRANSFER_N)) {
2163 int tgtSreg = mir->ssaRep->defs[0];
2164 int operands = (dfAttributes & DF_NULL_TRANSFER_0) ? 1 :
2165 mir->ssaRep->numUses;
2166 bool nullChecked = true;
2167 for (int i = 0; i < operands; i++) {
2168 nullChecked &= oatIsBitSet(cUnit->tempSSARegisterV,
2169 mir->ssaRep->uses[i]);
2170 }
2171 if (nullChecked) {
2172 oatSetBit(cUnit, cUnit->tempSSARegisterV, tgtSreg);
2173 }
buzbee43a36422011-09-14 14:00:13 -07002174 }
2175
Bill Buzbeea114add2012-05-03 15:00:40 -07002176 // Already nullchecked?
buzbeed1643e42012-09-05 14:06:51 -07002177 if ((dfAttributes & DF_HAS_NULL_CHKS) && !(mir->optimizationFlags & MIR_IGNORE_NULL_CHECK)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002178 int srcIdx;
2179 if (dfAttributes & DF_NULL_CHK_1) {
2180 srcIdx = 1;
2181 } else if (dfAttributes & DF_NULL_CHK_2) {
2182 srcIdx = 2;
2183 } else {
2184 srcIdx = 0;
2185 }
2186 int srcSreg = mir->ssaRep->uses[srcIdx];
2187 if (oatIsBitSet(cUnit->tempSSARegisterV, srcSreg)) {
2188 // Eliminate the null check
2189 mir->optimizationFlags |= MIR_IGNORE_NULL_CHECK;
2190 } else {
2191 // Mark sReg as null-checked
2192 oatSetBit(cUnit, cUnit->tempSSARegisterV, srcSreg);
buzbee43a36422011-09-14 14:00:13 -07002193 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002194 }
2195 }
buzbee43a36422011-09-14 14:00:13 -07002196
Bill Buzbeea114add2012-05-03 15:00:40 -07002197 // Did anything change?
2198 bool res = oatCompareBitVectors(bb->dataFlowInfo->endingNullCheckV,
2199 cUnit->tempSSARegisterV);
2200 if (res) {
2201 oatCopyBitVector(bb->dataFlowInfo->endingNullCheckV,
2202 cUnit->tempSSARegisterV);
2203 }
2204 return res;
buzbee43a36422011-09-14 14:00:13 -07002205}
2206
2207void oatMethodNullCheckElimination(CompilationUnit *cUnit)
2208{
Bill Buzbeea114add2012-05-03 15:00:40 -07002209 if (!(cUnit->disableOpt & (1 << kNullCheckElimination))) {
2210 DCHECK(cUnit->tempSSARegisterV != NULL);
2211 oatDataFlowAnalysisDispatcher(cUnit, nullCheckEliminationInit, kAllNodes,
2212 false /* isIterative */);
2213 oatDataFlowAnalysisDispatcher(cUnit, eliminateNullChecks,
2214 kPreOrderDFSTraversal,
2215 true /* isIterative */);
2216 }
buzbee43a36422011-09-14 14:00:13 -07002217}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -08002218
buzbeed1643e42012-09-05 14:06:51 -07002219void oatMethodBasicBlockCombine(CompilationUnit* cUnit)
2220{
2221 oatDataFlowAnalysisDispatcher(cUnit, combineBlocks, kPreOrderDFSTraversal, false);
2222}
2223
buzbee0967a252012-09-14 10:43:54 -07002224void oatMethodCodeLayout(CompilationUnit* cUnit)
2225{
2226 oatDataFlowAnalysisDispatcher(cUnit, layoutBlocks, kAllNodes, false);
2227}
2228
buzbeed1643e42012-09-05 14:06:51 -07002229void oatDumpCheckStats(CompilationUnit *cUnit)
2230{
buzbeecbd6d442012-11-17 14:11:25 -08002231 Checkstats* stats =
2232 static_cast<Checkstats*>(oatNew(cUnit, sizeof(Checkstats), true, kAllocDFInfo));
buzbeed1643e42012-09-05 14:06:51 -07002233 cUnit->checkstats = stats;
2234 oatDataFlowAnalysisDispatcher(cUnit, countChecks, kAllNodes, false /* isIterative */);
2235 if (stats->nullChecks > 0) {
buzbeecbd6d442012-11-17 14:11:25 -08002236 float eliminated = static_cast<float>(stats->nullChecksEliminated);
2237 float checks = static_cast<float>(stats->nullChecks);
buzbeed1643e42012-09-05 14:06:51 -07002238 LOG(INFO) << "Null Checks: " << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " "
2239 << stats->nullChecksEliminated << " of " << stats->nullChecks << " -> "
buzbeecbd6d442012-11-17 14:11:25 -08002240 << (eliminated/checks) * 100.0 << "%";
buzbeed1643e42012-09-05 14:06:51 -07002241 }
2242 if (stats->rangeChecks > 0) {
buzbeecbd6d442012-11-17 14:11:25 -08002243 float eliminated = static_cast<float>(stats->rangeChecksEliminated);
2244 float checks = static_cast<float>(stats->rangeChecks);
buzbeed1643e42012-09-05 14:06:51 -07002245 LOG(INFO) << "Range Checks: " << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " "
2246 << stats->rangeChecksEliminated << " of " << stats->rangeChecks << " -> "
buzbeecbd6d442012-11-17 14:11:25 -08002247 << (eliminated/checks) * 100.0 << "%";
buzbeed1643e42012-09-05 14:06:51 -07002248 }
2249}
2250
buzbeee1965672012-03-11 18:39:19 -07002251void oatMethodBasicBlockOptimization(CompilationUnit *cUnit)
2252{
Bill Buzbeea114add2012-05-03 15:00:40 -07002253 if (!(cUnit->disableOpt & (1 << kBBOpt))) {
2254 oatInitGrowableList(cUnit, &cUnit->compilerTemps, 6, kListMisc);
2255 DCHECK_EQ(cUnit->numCompilerTemps, 0);
buzbeeca7a5e42012-08-20 11:12:18 -07002256 oatDataFlowAnalysisDispatcher(cUnit, basicBlockOpt,
2257 kAllNodes, false /* isIterative */);
Bill Buzbeea114add2012-05-03 15:00:40 -07002258 }
buzbeee1965672012-03-11 18:39:19 -07002259}
2260
buzbee239c4e72012-03-16 08:42:29 -07002261void addLoopHeader(CompilationUnit* cUnit, BasicBlock* header,
Bill Buzbeea114add2012-05-03 15:00:40 -07002262 BasicBlock* backEdge)
buzbee239c4e72012-03-16 08:42:29 -07002263{
Bill Buzbeea114add2012-05-03 15:00:40 -07002264 GrowableListIterator iter;
2265 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter);
buzbeecbd6d442012-11-17 14:11:25 -08002266 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter));
2267 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002268 if (loop->header == header) {
2269 oatInsertGrowableList(cUnit, &loop->incomingBackEdges,
buzbeecbd6d442012-11-17 14:11:25 -08002270 reinterpret_cast<uintptr_t>(backEdge));
Bill Buzbeea114add2012-05-03 15:00:40 -07002271 return;
buzbee239c4e72012-03-16 08:42:29 -07002272 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002273 }
buzbeecbd6d442012-11-17 14:11:25 -08002274 LoopInfo* info = static_cast<LoopInfo*>(oatNew(cUnit, sizeof(LoopInfo), true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07002275 info->header = header;
2276 oatInitGrowableList(cUnit, &info->incomingBackEdges, 2, kListMisc);
buzbeecbd6d442012-11-17 14:11:25 -08002277 oatInsertGrowableList(cUnit, &info->incomingBackEdges, reinterpret_cast<uintptr_t>(backEdge));
2278 oatInsertGrowableList(cUnit, &cUnit->loopHeaders, reinterpret_cast<uintptr_t>(info));
buzbee239c4e72012-03-16 08:42:29 -07002279}
2280
2281bool findBackEdges(struct CompilationUnit* cUnit, struct BasicBlock* bb)
2282{
Bill Buzbeea114add2012-05-03 15:00:40 -07002283 if ((bb->dataFlowInfo == NULL) || (bb->lastMIRInsn == NULL)) {
buzbee239c4e72012-03-16 08:42:29 -07002284 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07002285 }
2286 Instruction::Code opcode = bb->lastMIRInsn->dalvikInsn.opcode;
Ian Rogersa75a0132012-09-28 11:41:42 -07002287 if (Instruction::FlagsOf(opcode) & Instruction::kBranch) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002288 if (bb->taken && (bb->taken->startOffset <= bb->startOffset)) {
2289 DCHECK(bb->dominators != NULL);
2290 if (oatIsBitSet(bb->dominators, bb->taken->id)) {
2291 if (cUnit->printMe) {
2292 LOG(INFO) << "Loop backedge from 0x"
2293 << std::hex << bb->lastMIRInsn->offset
2294 << " to 0x" << std::hex << bb->taken->startOffset;
2295 }
2296 addLoopHeader(cUnit, bb->taken, bb);
2297 }
2298 }
2299 }
2300 return false;
buzbee239c4e72012-03-16 08:42:29 -07002301}
2302
2303void addBlocksToLoop(CompilationUnit* cUnit, ArenaBitVector* blocks,
Bill Buzbeea114add2012-05-03 15:00:40 -07002304 BasicBlock* bb, int headId)
buzbee239c4e72012-03-16 08:42:29 -07002305{
Bill Buzbeea114add2012-05-03 15:00:40 -07002306 if (!oatIsBitSet(bb->dominators, headId) ||
2307 oatIsBitSet(blocks, bb->id)) {
2308 return;
2309 }
2310 oatSetBit(cUnit, blocks, bb->id);
2311 GrowableListIterator iter;
2312 oatGrowableListIteratorInit(bb->predecessors, &iter);
2313 BasicBlock* predBB;
buzbeecbd6d442012-11-17 14:11:25 -08002314 for (predBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter)); predBB;
2315 predBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002316 addBlocksToLoop(cUnit, blocks, predBB, headId);
2317 }
buzbee239c4e72012-03-16 08:42:29 -07002318}
2319
2320void oatDumpLoops(CompilationUnit *cUnit)
2321{
Bill Buzbeea114add2012-05-03 15:00:40 -07002322 GrowableListIterator iter;
2323 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter);
buzbeecbd6d442012-11-17 14:11:25 -08002324 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter));
2325 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002326 LOG(INFO) << "Loop head block id " << loop->header->id
2327 << ", offset 0x" << std::hex << loop->header->startOffset
2328 << ", Depth: " << loop->header->nestingDepth;
buzbee239c4e72012-03-16 08:42:29 -07002329 GrowableListIterator iter;
Bill Buzbeea114add2012-05-03 15:00:40 -07002330 oatGrowableListIteratorInit(&loop->incomingBackEdges, &iter);
2331 BasicBlock* edgeBB;
buzbeecbd6d442012-11-17 14:11:25 -08002332 for (edgeBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter)); edgeBB;
2333 edgeBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002334 LOG(INFO) << " Backedge block id " << edgeBB->id
2335 << ", offset 0x" << std::hex << edgeBB->startOffset;
2336 ArenaBitVectorIterator bIter;
2337 oatBitVectorIteratorInit(loop->blocks, &bIter);
2338 for (int bbId = oatBitVectorIteratorNext(&bIter); bbId != -1;
2339 bbId = oatBitVectorIteratorNext(&bIter)) {
2340 BasicBlock *bb;
buzbeecbd6d442012-11-17 14:11:25 -08002341 bb = reinterpret_cast<BasicBlock*>(oatGrowableListGetElement(&cUnit->blockList, bbId));
Bill Buzbeea114add2012-05-03 15:00:40 -07002342 LOG(INFO) << " (" << bb->id << ", 0x" << std::hex
2343 << bb->startOffset << ")";
2344 }
buzbee239c4e72012-03-16 08:42:29 -07002345 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002346 }
buzbee239c4e72012-03-16 08:42:29 -07002347}
2348
2349void oatMethodLoopDetection(CompilationUnit *cUnit)
2350{
Bill Buzbeea114add2012-05-03 15:00:40 -07002351 if (cUnit->disableOpt & (1 << kPromoteRegs)) {
2352 return;
2353 }
2354 oatInitGrowableList(cUnit, &cUnit->loopHeaders, 6, kListMisc);
2355 // Find the loop headers
buzbeecbd6d442012-11-17 14:11:25 -08002356 oatDataFlowAnalysisDispatcher(cUnit, findBackEdges, kAllNodes, false /* isIterative */);
Bill Buzbeea114add2012-05-03 15:00:40 -07002357 GrowableListIterator iter;
2358 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter);
2359 // Add blocks to each header
buzbeecbd6d442012-11-17 14:11:25 -08002360 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter));
2361 loop; loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002362 loop->blocks = oatAllocBitVector(cUnit, cUnit->numBlocks, true,
2363 kBitMapMisc);
2364 oatSetBit(cUnit, loop->blocks, loop->header->id);
buzbee239c4e72012-03-16 08:42:29 -07002365 GrowableListIterator iter;
Bill Buzbeea114add2012-05-03 15:00:40 -07002366 oatGrowableListIteratorInit(&loop->incomingBackEdges, &iter);
2367 BasicBlock* edgeBB;
buzbeecbd6d442012-11-17 14:11:25 -08002368 for (edgeBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter)); edgeBB;
2369 edgeBB = reinterpret_cast<BasicBlock*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002370 addBlocksToLoop(cUnit, loop->blocks, edgeBB, loop->header->id);
buzbee239c4e72012-03-16 08:42:29 -07002371 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002372 }
2373 // Compute the nesting depth of each header
2374 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter);
buzbeecbd6d442012-11-17 14:11:25 -08002375 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter));
2376 loop; loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002377 GrowableListIterator iter2;
2378 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter2);
2379 LoopInfo* loop2;
buzbeecbd6d442012-11-17 14:11:25 -08002380 for (loop2 = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter2));
2381 loop2; loop2 = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter2))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002382 if (oatIsBitSet(loop2->blocks, loop->header->id)) {
2383 loop->header->nestingDepth++;
2384 }
buzbee239c4e72012-03-16 08:42:29 -07002385 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002386 }
2387 // Assign nesting depth to each block in all loops
2388 oatGrowableListIteratorInit(&cUnit->loopHeaders, &iter);
buzbeecbd6d442012-11-17 14:11:25 -08002389 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter));
2390 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(oatGrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002391 ArenaBitVectorIterator bIter;
2392 oatBitVectorIteratorInit(loop->blocks, &bIter);
2393 for (int bbId = oatBitVectorIteratorNext(&bIter); bbId != -1;
2394 bbId = oatBitVectorIteratorNext(&bIter)) {
2395 BasicBlock *bb;
buzbeecbd6d442012-11-17 14:11:25 -08002396 bb = reinterpret_cast<BasicBlock*>(oatGrowableListGetElement(&cUnit->blockList, bbId));
Bill Buzbeea114add2012-05-03 15:00:40 -07002397 bb->nestingDepth = std::max(bb->nestingDepth,
2398 loop->header->nestingDepth);
buzbee239c4e72012-03-16 08:42:29 -07002399 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002400 }
2401 if (cUnit->printMe) {
2402 oatDumpLoops(cUnit);
2403 }
buzbee239c4e72012-03-16 08:42:29 -07002404}
2405
2406/*
buzbee9c044ce2012-03-18 13:24:07 -07002407 * This function will make a best guess at whether the invoke will
2408 * end up using Method*. It isn't critical to get it exactly right,
2409 * and attempting to do would involve more complexity than it's
2410 * worth.
2411 */
2412bool invokeUsesMethodStar(CompilationUnit* cUnit, MIR* mir)
2413{
Bill Buzbeea114add2012-05-03 15:00:40 -07002414 InvokeType type;
2415 Instruction::Code opcode = mir->dalvikInsn.opcode;
2416 switch (opcode) {
2417 case Instruction::INVOKE_STATIC:
2418 case Instruction::INVOKE_STATIC_RANGE:
2419 type = kStatic;
2420 break;
2421 case Instruction::INVOKE_DIRECT:
2422 case Instruction::INVOKE_DIRECT_RANGE:
2423 type = kDirect;
2424 break;
2425 case Instruction::INVOKE_VIRTUAL:
2426 case Instruction::INVOKE_VIRTUAL_RANGE:
2427 type = kVirtual;
2428 break;
2429 case Instruction::INVOKE_INTERFACE:
2430 case Instruction::INVOKE_INTERFACE_RANGE:
2431 return false;
2432 case Instruction::INVOKE_SUPER_RANGE:
2433 case Instruction::INVOKE_SUPER:
2434 type = kSuper;
2435 break;
2436 default:
buzbeecbd6d442012-11-17 14:11:25 -08002437 LOG(WARNING) << "Unexpected invoke op: " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07002438 return false;
2439 }
2440 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker,
Ian Rogers00f7d0e2012-07-19 15:28:27 -07002441 *cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -07002442 cUnit->code_item, cUnit->method_idx,
2443 cUnit->access_flags);
2444 // TODO: add a flag so we don't counts the stats for this twice
2445 uint32_t dexMethodIdx = mir->dalvikInsn.vB;
2446 int vtableIdx;
2447 uintptr_t directCode;
2448 uintptr_t directMethod;
2449 bool fastPath =
2450 cUnit->compiler->ComputeInvokeInfo(dexMethodIdx, &mUnit, type,
2451 vtableIdx, directCode,
2452 directMethod) &&
2453 !SLOW_INVOKE_PATH;
2454 return (((type == kDirect) || (type == kStatic)) &&
2455 fastPath && ((directCode == 0) || (directMethod == 0)));
buzbee9c044ce2012-03-18 13:24:07 -07002456}
2457
2458/*
buzbee239c4e72012-03-16 08:42:29 -07002459 * Count uses, weighting by loop nesting depth. This code only
2460 * counts explicitly used sRegs. A later phase will add implicit
2461 * counts for things such as Method*, null-checked references, etc.
2462 */
2463bool countUses(struct CompilationUnit* cUnit, struct BasicBlock* bb)
2464{
Bill Buzbeea114add2012-05-03 15:00:40 -07002465 if (bb->blockType != kDalvikByteCode) {
buzbee239c4e72012-03-16 08:42:29 -07002466 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07002467 }
2468 for (MIR* mir = bb->firstMIRInsn; (mir != NULL); mir = mir->next) {
2469 if (mir->ssaRep == NULL) {
2470 continue;
2471 }
buzbeecbd6d442012-11-17 14:11:25 -08002472 uint32_t weight = std::min(16U, static_cast<uint32_t>(bb->nestingDepth));
Bill Buzbeea114add2012-05-03 15:00:40 -07002473 for (int i = 0; i < mir->ssaRep->numUses; i++) {
2474 int sReg = mir->ssaRep->uses[i];
buzbeecbd6d442012-11-17 14:11:25 -08002475 DCHECK_LT(sReg, static_cast<int>(cUnit->useCounts.numUsed));
Bill Buzbeea114add2012-05-03 15:00:40 -07002476 cUnit->rawUseCounts.elemList[sReg]++;
2477 cUnit->useCounts.elemList[sReg] += (1 << weight);
2478 }
2479 if (!(cUnit->disableOpt & (1 << kPromoteCompilerTemps))) {
2480 int dfAttributes = oatDataFlowAttributes[mir->dalvikInsn.opcode];
2481 // Implicit use of Method* ? */
2482 if (dfAttributes & DF_UMS) {
2483 /*
2484 * Some invokes will not use Method* - need to perform test similar
2485 * to that found in genInvoke() to decide whether to count refs
2486 * for Method* on invoke-class opcodes.
2487 * TODO: refactor for common test here, save results for genInvoke
2488 */
2489 int usesMethodStar = true;
2490 if ((dfAttributes & (DF_FORMAT_35C | DF_FORMAT_3RC)) &&
2491 !(dfAttributes & DF_NON_NULL_RET)) {
2492 usesMethodStar &= invokeUsesMethodStar(cUnit, mir);
2493 }
2494 if (usesMethodStar) {
2495 cUnit->rawUseCounts.elemList[cUnit->methodSReg]++;
2496 cUnit->useCounts.elemList[cUnit->methodSReg] += (1 << weight);
2497 }
2498 }
2499 }
2500 }
2501 return false;
buzbee239c4e72012-03-16 08:42:29 -07002502}
2503
2504void oatMethodUseCount(CompilationUnit *cUnit)
2505{
buzbeecbd6d442012-11-17 14:11:25 -08002506 oatInitGrowableList(cUnit, &cUnit->useCounts, cUnit->numSSARegs + 32, kListMisc);
2507 oatInitGrowableList(cUnit, &cUnit->rawUseCounts, cUnit->numSSARegs + 32, kListMisc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002508 // Initialize list
2509 for (int i = 0; i < cUnit->numSSARegs; i++) {
2510 oatInsertGrowableList(cUnit, &cUnit->useCounts, 0);
2511 oatInsertGrowableList(cUnit, &cUnit->rawUseCounts, 0);
2512 }
2513 if (cUnit->disableOpt & (1 << kPromoteRegs)) {
2514 return;
2515 }
2516 oatDataFlowAnalysisDispatcher(cUnit, countUses,
2517 kAllNodes, false /* isIterative */);
buzbee239c4e72012-03-16 08:42:29 -07002518}
2519
Elliott Hughes11d1b0c2012-01-23 16:57:47 -08002520} // namespace art