blob: 4d7e9d7a89bf54529c8e07aa1cf9b7533a186477 [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"
buzbee2502e002012-12-31 16:05:53 -080019#include "bb_opt.h"
buzbee67bf8852011-08-17 17:51:35 -070020
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080021namespace art {
22
buzbee67bf8852011-08-17 17:51:35 -070023/*
24 * Main table containing data flow attributes for each bytecode. The
25 * first kNumPackedOpcodes entries are for Dalvik bytecode
26 * instructions, where extended opcode at the MIR level are appended
27 * afterwards.
28 *
29 * TODO - many optimization flags are incomplete - they will only limit the
30 * scope of optimizations but will not cause mis-optimizations.
31 */
buzbeefa57c472012-11-21 12:06:18 -080032const int oat_data_flow_attributes[kMirOpLast] = {
Bill Buzbeea114add2012-05-03 15:00:40 -070033 // 00 NOP
34 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -070035
Bill Buzbeea114add2012-05-03 15:00:40 -070036 // 01 MOVE vA, vB
37 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070038
Bill Buzbeea114add2012-05-03 15:00:40 -070039 // 02 MOVE_FROM16 vAA, vBBBB
40 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070041
Bill Buzbeea114add2012-05-03 15:00:40 -070042 // 03 MOVE_16 vAAAA, vBBBB
43 DF_DA | DF_UB | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070044
Bill Buzbeea114add2012-05-03 15:00:40 -070045 // 04 MOVE_WIDE vA, vB
buzbeebff24652012-05-06 16:22:05 -070046 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070047
Bill Buzbeea114add2012-05-03 15:00:40 -070048 // 05 MOVE_WIDE_FROM16 vAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070049 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070050
Bill Buzbeea114add2012-05-03 15:00:40 -070051 // 06 MOVE_WIDE_16 vAAAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070052 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_IS_MOVE,
buzbee67bf8852011-08-17 17:51:35 -070053
Bill Buzbeea114add2012-05-03 15:00:40 -070054 // 07 MOVE_OBJECT vA, vB
buzbeebff24652012-05-06 16:22:05 -070055 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070056
Bill Buzbeea114add2012-05-03 15:00:40 -070057 // 08 MOVE_OBJECT_FROM16 vAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070058 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070059
Bill Buzbeea114add2012-05-03 15:00:40 -070060 // 09 MOVE_OBJECT_16 vAAAA, vBBBB
buzbeebff24652012-05-06 16:22:05 -070061 DF_DA | DF_UB | DF_NULL_TRANSFER_0 | DF_IS_MOVE | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -070062
Bill Buzbeea114add2012-05-03 15:00:40 -070063 // 0A MOVE_RESULT vAA
64 DF_DA,
buzbee67bf8852011-08-17 17:51:35 -070065
Bill Buzbeea114add2012-05-03 15:00:40 -070066 // 0B MOVE_RESULT_WIDE vAA
buzbeebff24652012-05-06 16:22:05 -070067 DF_DA | DF_A_WIDE,
buzbee67bf8852011-08-17 17:51:35 -070068
Bill Buzbeea114add2012-05-03 15:00:40 -070069 // 0C MOVE_RESULT_OBJECT vAA
buzbeebff24652012-05-06 16:22:05 -070070 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070071
Bill Buzbeea114add2012-05-03 15:00:40 -070072 // 0D MOVE_EXCEPTION vAA
buzbee2a83e8f2012-07-13 16:42:30 -070073 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070074
Bill Buzbeea114add2012-05-03 15:00:40 -070075 // 0E RETURN_VOID
76 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -070077
Bill Buzbeea114add2012-05-03 15:00:40 -070078 // 0F RETURN vAA
79 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -070080
Bill Buzbeea114add2012-05-03 15:00:40 -070081 // 10 RETURN_WIDE vAA
buzbeebff24652012-05-06 16:22:05 -070082 DF_UA | DF_A_WIDE,
buzbee67bf8852011-08-17 17:51:35 -070083
Bill Buzbeea114add2012-05-03 15:00:40 -070084 // 11 RETURN_OBJECT vAA
buzbeebff24652012-05-06 16:22:05 -070085 DF_UA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -070086
Bill Buzbeea114add2012-05-03 15:00:40 -070087 // 12 CONST_4 vA, #+B
88 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070089
Bill Buzbeea114add2012-05-03 15:00:40 -070090 // 13 CONST_16 vAA, #+BBBB
91 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070092
Bill Buzbeea114add2012-05-03 15:00:40 -070093 // 14 CONST vAA, #+BBBBBBBB
94 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070095
Bill Buzbeea114add2012-05-03 15:00:40 -070096 // 15 CONST_HIGH16 VAA, #+BBBB0000
97 DF_DA | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -070098
Bill Buzbeea114add2012-05-03 15:00:40 -070099 // 16 CONST_WIDE_16 vAA, #+BBBB
buzbeebff24652012-05-06 16:22:05 -0700100 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700101
Bill Buzbeea114add2012-05-03 15:00:40 -0700102 // 17 CONST_WIDE_32 vAA, #+BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700103 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700104
Bill Buzbeea114add2012-05-03 15:00:40 -0700105 // 18 CONST_WIDE vAA, #+BBBBBBBBBBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700106 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700107
Bill Buzbeea114add2012-05-03 15:00:40 -0700108 // 19 CONST_WIDE_HIGH16 vAA, #+BBBB000000000000
buzbeebff24652012-05-06 16:22:05 -0700109 DF_DA | DF_A_WIDE | DF_SETS_CONST,
buzbee67bf8852011-08-17 17:51:35 -0700110
Bill Buzbeea114add2012-05-03 15:00:40 -0700111 // 1A CONST_STRING vAA, string@BBBB
buzbeebff24652012-05-06 16:22:05 -0700112 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700113
Bill Buzbeea114add2012-05-03 15:00:40 -0700114 // 1B CONST_STRING_JUMBO vAA, string@BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700115 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700116
Bill Buzbeea114add2012-05-03 15:00:40 -0700117 // 1C CONST_CLASS vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700118 DF_DA | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700119
Bill Buzbeea114add2012-05-03 15:00:40 -0700120 // 1D MONITOR_ENTER vAA
buzbeebff24652012-05-06 16:22:05 -0700121 DF_UA | DF_NULL_CHK_0 | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700122
Bill Buzbeea114add2012-05-03 15:00:40 -0700123 // 1E MONITOR_EXIT vAA
buzbeebff24652012-05-06 16:22:05 -0700124 DF_UA | DF_NULL_CHK_0 | DF_REF_A,
buzbee67bf8852011-08-17 17:51:35 -0700125
Bill Buzbeea114add2012-05-03 15:00:40 -0700126 // 1F CHK_CAST vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700127 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700128
Bill Buzbeea114add2012-05-03 15:00:40 -0700129 // 20 INSTANCE_OF vA, vB, type@CCCC
buzbeebff24652012-05-06 16:22:05 -0700130 DF_DA | DF_UB | DF_CORE_A | DF_REF_B | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700131
Bill Buzbeea114add2012-05-03 15:00:40 -0700132 // 21 ARRAY_LENGTH vA, vB
buzbeebff24652012-05-06 16:22:05 -0700133 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_CORE_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700134
Bill Buzbeea114add2012-05-03 15:00:40 -0700135 // 22 NEW_INSTANCE vAA, type@BBBB
buzbeebff24652012-05-06 16:22:05 -0700136 DF_DA | DF_NON_NULL_DST | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700137
Bill Buzbeea114add2012-05-03 15:00:40 -0700138 // 23 NEW_ARRAY vA, vB, type@CCCC
buzbeebff24652012-05-06 16:22:05 -0700139 DF_DA | DF_UB | DF_NON_NULL_DST | DF_REF_A | DF_CORE_B | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700140
Bill Buzbeea114add2012-05-03 15:00:40 -0700141 // 24 FILLED_NEW_ARRAY {vD, vE, vF, vG, vA}
142 DF_FORMAT_35C | DF_NON_NULL_RET | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700143
Bill Buzbeea114add2012-05-03 15:00:40 -0700144 // 25 FILLED_NEW_ARRAY_RANGE {vCCCC .. vNNNN}, type@BBBB
145 DF_FORMAT_3RC | DF_NON_NULL_RET | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700146
Bill Buzbeea114add2012-05-03 15:00:40 -0700147 // 26 FILL_ARRAY_DATA vAA, +BBBBBBBB
buzbeebff24652012-05-06 16:22:05 -0700148 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700149
Bill Buzbeea114add2012-05-03 15:00:40 -0700150 // 27 THROW vAA
buzbeebff24652012-05-06 16:22:05 -0700151 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700152
Bill Buzbeea114add2012-05-03 15:00:40 -0700153 // 28 GOTO
154 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700155
Bill Buzbeea114add2012-05-03 15:00:40 -0700156 // 29 GOTO_16
157 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700158
Bill Buzbeea114add2012-05-03 15:00:40 -0700159 // 2A GOTO_32
160 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700161
Bill Buzbeea114add2012-05-03 15:00:40 -0700162 // 2B PACKED_SWITCH vAA, +BBBBBBBB
163 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700164
Bill Buzbeea114add2012-05-03 15:00:40 -0700165 // 2C SPARSE_SWITCH vAA, +BBBBBBBB
166 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700167
Bill Buzbeea114add2012-05-03 15:00:40 -0700168 // 2D CMPL_FLOAT vAA, vBB, vCC
169 DF_DA | DF_UB | DF_UC | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700170
Bill Buzbeea114add2012-05-03 15:00:40 -0700171 // 2E CMPG_FLOAT vAA, vBB, vCC
172 DF_DA | DF_UB | DF_UC | DF_FP_B | DF_FP_C | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700173
Bill Buzbeea114add2012-05-03 15:00:40 -0700174 // 2F CMPL_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700175 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 -0700176
Bill Buzbeea114add2012-05-03 15:00:40 -0700177 // 30 CMPG_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700178 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 -0700179
Bill Buzbeea114add2012-05-03 15:00:40 -0700180 // 31 CMP_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700181 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 -0700182
Bill Buzbeea114add2012-05-03 15:00:40 -0700183 // 32 IF_EQ vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700184 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700185
Bill Buzbeea114add2012-05-03 15:00:40 -0700186 // 33 IF_NE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700187 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700188
Bill Buzbeea114add2012-05-03 15:00:40 -0700189 // 34 IF_LT vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700190 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700191
Bill Buzbeea114add2012-05-03 15:00:40 -0700192 // 35 IF_GE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700193 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700194
Bill Buzbeea114add2012-05-03 15:00:40 -0700195 // 36 IF_GT vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700196 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700197
Bill Buzbeea114add2012-05-03 15:00:40 -0700198 // 37 IF_LE vA, vB, +CCCC
buzbee2a83e8f2012-07-13 16:42:30 -0700199 DF_UA | DF_UB,
buzbee67bf8852011-08-17 17:51:35 -0700200
Bill Buzbeea114add2012-05-03 15:00:40 -0700201 // 38 IF_EQZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700202 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700203
Bill Buzbeea114add2012-05-03 15:00:40 -0700204 // 39 IF_NEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700205 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700206
Bill Buzbeea114add2012-05-03 15:00:40 -0700207 // 3A IF_LTZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700208 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700209
Bill Buzbeea114add2012-05-03 15:00:40 -0700210 // 3B IF_GEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700211 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700212
Bill Buzbeea114add2012-05-03 15:00:40 -0700213 // 3C IF_GTZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700214 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700215
Bill Buzbeea114add2012-05-03 15:00:40 -0700216 // 3D IF_LEZ vAA, +BBBB
buzbee2a83e8f2012-07-13 16:42:30 -0700217 DF_UA,
buzbee67bf8852011-08-17 17:51:35 -0700218
Bill Buzbeea114add2012-05-03 15:00:40 -0700219 // 3E UNUSED_3E
220 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700221
Bill Buzbeea114add2012-05-03 15:00:40 -0700222 // 3F UNUSED_3F
223 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700224
Bill Buzbeea114add2012-05-03 15:00:40 -0700225 // 40 UNUSED_40
226 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700227
Bill Buzbeea114add2012-05-03 15:00:40 -0700228 // 41 UNUSED_41
229 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700230
Bill Buzbeea114add2012-05-03 15:00:40 -0700231 // 42 UNUSED_42
232 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700233
Bill Buzbeea114add2012-05-03 15:00:40 -0700234 // 43 UNUSED_43
235 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700236
Bill Buzbeea114add2012-05-03 15:00:40 -0700237 // 44 AGET vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700238 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 -0700239
Bill Buzbeea114add2012-05-03 15:00:40 -0700240 // 45 AGET_WIDE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700241 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 -0700242
Bill Buzbeea114add2012-05-03 15:00:40 -0700243 // 46 AGET_OBJECT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700244 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 -0700245
Bill Buzbeea114add2012-05-03 15:00:40 -0700246 // 47 AGET_BOOLEAN vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700247 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 -0700248
Bill Buzbeea114add2012-05-03 15:00:40 -0700249 // 48 AGET_BYTE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700250 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 -0700251
Bill Buzbeea114add2012-05-03 15:00:40 -0700252 // 49 AGET_CHAR vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700253 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 -0700254
Bill Buzbeea114add2012-05-03 15:00:40 -0700255 // 4A AGET_SHORT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700256 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 -0700257
Bill Buzbeea114add2012-05-03 15:00:40 -0700258 // 4B APUT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700259 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 -0700260
Bill Buzbeea114add2012-05-03 15:00:40 -0700261 // 4C APUT_WIDE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700262 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 -0700263
Bill Buzbeea114add2012-05-03 15:00:40 -0700264 // 4D APUT_OBJECT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700265 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 -0700266
Bill Buzbeea114add2012-05-03 15:00:40 -0700267 // 4E APUT_BOOLEAN vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700268 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 -0700269
Bill Buzbeea114add2012-05-03 15:00:40 -0700270 // 4F APUT_BYTE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700271 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 -0700272
Bill Buzbeea114add2012-05-03 15:00:40 -0700273 // 50 APUT_CHAR vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700274 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 -0700275
Bill Buzbeea114add2012-05-03 15:00:40 -0700276 // 51 APUT_SHORT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700277 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 -0700278
Bill Buzbeea114add2012-05-03 15:00:40 -0700279 // 52 IGET vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700280 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700281
Bill Buzbeea114add2012-05-03 15:00:40 -0700282 // 53 IGET_WIDE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700283 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700284
Bill Buzbeea114add2012-05-03 15:00:40 -0700285 // 54 IGET_OBJECT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700286 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700287
Bill Buzbeea114add2012-05-03 15:00:40 -0700288 // 55 IGET_BOOLEAN vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700289 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700290
Bill Buzbeea114add2012-05-03 15:00:40 -0700291 // 56 IGET_BYTE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700292 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700293
Bill Buzbeea114add2012-05-03 15:00:40 -0700294 // 57 IGET_CHAR vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700295 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700296
Bill Buzbeea114add2012-05-03 15:00:40 -0700297 // 58 IGET_SHORT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700298 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700299
Bill Buzbeea114add2012-05-03 15:00:40 -0700300 // 59 IPUT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700301 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700302
Bill Buzbeea114add2012-05-03 15:00:40 -0700303 // 5A IPUT_WIDE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700304 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700305
Bill Buzbeea114add2012-05-03 15:00:40 -0700306 // 5B IPUT_OBJECT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700307 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700308
Bill Buzbeea114add2012-05-03 15:00:40 -0700309 // 5C IPUT_BOOLEAN vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700310 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700311
Bill Buzbeea114add2012-05-03 15:00:40 -0700312 // 5D IPUT_BYTE vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700313 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700314
Bill Buzbeea114add2012-05-03 15:00:40 -0700315 // 5E IPUT_CHAR vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700316 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700317
Bill Buzbeea114add2012-05-03 15:00:40 -0700318 // 5F IPUT_SHORT vA, vB, field@CCCC
buzbeebff24652012-05-06 16:22:05 -0700319 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700320
Bill Buzbeea114add2012-05-03 15:00:40 -0700321 // 60 SGET vAA, field@BBBB
322 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700323
Bill Buzbeea114add2012-05-03 15:00:40 -0700324 // 61 SGET_WIDE vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700325 DF_DA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700326
Bill Buzbeea114add2012-05-03 15:00:40 -0700327 // 62 SGET_OBJECT vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700328 DF_DA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700329
Bill Buzbeea114add2012-05-03 15:00:40 -0700330 // 63 SGET_BOOLEAN vAA, field@BBBB
331 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700332
Bill Buzbeea114add2012-05-03 15:00:40 -0700333 // 64 SGET_BYTE vAA, field@BBBB
334 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700335
Bill Buzbeea114add2012-05-03 15:00:40 -0700336 // 65 SGET_CHAR vAA, field@BBBB
337 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700338
Bill Buzbeea114add2012-05-03 15:00:40 -0700339 // 66 SGET_SHORT vAA, field@BBBB
340 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700341
Bill Buzbeea114add2012-05-03 15:00:40 -0700342 // 67 SPUT vAA, field@BBBB
343 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700344
Bill Buzbeea114add2012-05-03 15:00:40 -0700345 // 68 SPUT_WIDE vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700346 DF_UA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700347
Bill Buzbeea114add2012-05-03 15:00:40 -0700348 // 69 SPUT_OBJECT vAA, field@BBBB
buzbeebff24652012-05-06 16:22:05 -0700349 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700350
Bill Buzbeea114add2012-05-03 15:00:40 -0700351 // 6A SPUT_BOOLEAN vAA, field@BBBB
352 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700353
Bill Buzbeea114add2012-05-03 15:00:40 -0700354 // 6B SPUT_BYTE vAA, field@BBBB
355 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700356
Bill Buzbeea114add2012-05-03 15:00:40 -0700357 // 6C SPUT_CHAR vAA, field@BBBB
358 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700359
Bill Buzbeea114add2012-05-03 15:00:40 -0700360 // 6D SPUT_SHORT vAA, field@BBBB
361 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700362
Bill Buzbeea114add2012-05-03 15:00:40 -0700363 // 6E INVOKE_VIRTUAL {vD, vE, vF, vG, vA}
364 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700365
Bill Buzbeea114add2012-05-03 15:00:40 -0700366 // 6F INVOKE_SUPER {vD, vE, vF, vG, vA}
367 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700368
Bill Buzbeea114add2012-05-03 15:00:40 -0700369 // 70 INVOKE_DIRECT {vD, vE, vF, vG, vA}
370 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700371
Bill Buzbeea114add2012-05-03 15:00:40 -0700372 // 71 INVOKE_STATIC {vD, vE, vF, vG, vA}
373 DF_FORMAT_35C | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700374
Bill Buzbeea114add2012-05-03 15:00:40 -0700375 // 72 INVOKE_INTERFACE {vD, vE, vF, vG, vA}
376 DF_FORMAT_35C | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700377
Bill Buzbeea114add2012-05-03 15:00:40 -0700378 // 73 UNUSED_73
379 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700380
Bill Buzbeea114add2012-05-03 15:00:40 -0700381 // 74 INVOKE_VIRTUAL_RANGE {vCCCC .. vNNNN}
382 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700383
Bill Buzbeea114add2012-05-03 15:00:40 -0700384 // 75 INVOKE_SUPER_RANGE {vCCCC .. vNNNN}
385 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700386
Bill Buzbeea114add2012-05-03 15:00:40 -0700387 // 76 INVOKE_DIRECT_RANGE {vCCCC .. vNNNN}
388 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700389
Bill Buzbeea114add2012-05-03 15:00:40 -0700390 // 77 INVOKE_STATIC_RANGE {vCCCC .. vNNNN}
391 DF_FORMAT_3RC | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700392
Bill Buzbeea114add2012-05-03 15:00:40 -0700393 // 78 INVOKE_INTERFACE_RANGE {vCCCC .. vNNNN}
394 DF_FORMAT_3RC | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700395
Bill Buzbeea114add2012-05-03 15:00:40 -0700396 // 79 UNUSED_79
397 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700398
Bill Buzbeea114add2012-05-03 15:00:40 -0700399 // 7A UNUSED_7A
400 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700401
Bill Buzbeea114add2012-05-03 15:00:40 -0700402 // 7B NEG_INT vA, vB
403 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700404
Bill Buzbeea114add2012-05-03 15:00:40 -0700405 // 7C NOT_INT vA, vB
406 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700407
Bill Buzbeea114add2012-05-03 15:00:40 -0700408 // 7D NEG_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700409 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700410
Bill Buzbeea114add2012-05-03 15:00:40 -0700411 // 7E NOT_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700412 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700413
Bill Buzbeea114add2012-05-03 15:00:40 -0700414 // 7F NEG_FLOAT vA, vB
415 DF_DA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700416
Bill Buzbeea114add2012-05-03 15:00:40 -0700417 // 80 NEG_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700418 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700419
Bill Buzbeea114add2012-05-03 15:00:40 -0700420 // 81 INT_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700421 DF_DA | DF_A_WIDE | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700422
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 // 82 INT_TO_FLOAT vA, vB
424 DF_DA | DF_UB | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700425
Bill Buzbeea114add2012-05-03 15:00:40 -0700426 // 83 INT_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700427 DF_DA | DF_A_WIDE | DF_UB | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700428
Bill Buzbeea114add2012-05-03 15:00:40 -0700429 // 84 LONG_TO_INT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700430 DF_DA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700431
Bill Buzbeea114add2012-05-03 15:00:40 -0700432 // 85 LONG_TO_FLOAT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700433 DF_DA | DF_UB | DF_B_WIDE | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700434
Bill Buzbeea114add2012-05-03 15:00:40 -0700435 // 86 LONG_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700436 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700437
Bill Buzbeea114add2012-05-03 15:00:40 -0700438 // 87 FLOAT_TO_INT vA, vB
439 DF_DA | DF_UB | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700440
Bill Buzbeea114add2012-05-03 15:00:40 -0700441 // 88 FLOAT_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700442 DF_DA | DF_A_WIDE | DF_UB | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700443
Bill Buzbeea114add2012-05-03 15:00:40 -0700444 // 89 FLOAT_TO_DOUBLE vA, vB
buzbeebff24652012-05-06 16:22:05 -0700445 DF_DA | DF_A_WIDE | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700446
Bill Buzbeea114add2012-05-03 15:00:40 -0700447 // 8A DOUBLE_TO_INT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700448 DF_DA | DF_UB | DF_B_WIDE | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700449
Bill Buzbeea114add2012-05-03 15:00:40 -0700450 // 8B DOUBLE_TO_LONG vA, vB
buzbeebff24652012-05-06 16:22:05 -0700451 DF_DA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_B | DF_CORE_A,
buzbee67bf8852011-08-17 17:51:35 -0700452
Bill Buzbeea114add2012-05-03 15:00:40 -0700453 // 8C DOUBLE_TO_FLOAT vA, vB
buzbeebff24652012-05-06 16:22:05 -0700454 DF_DA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700455
Bill Buzbeea114add2012-05-03 15:00:40 -0700456 // 8D INT_TO_BYTE vA, vB
457 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700458
Bill Buzbeea114add2012-05-03 15:00:40 -0700459 // 8E INT_TO_CHAR vA, vB
460 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700461
Bill Buzbeea114add2012-05-03 15:00:40 -0700462 // 8F INT_TO_SHORT vA, vB
463 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700464
Bill Buzbeea114add2012-05-03 15:00:40 -0700465 // 90 ADD_INT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700466 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700467
Bill Buzbeea114add2012-05-03 15:00:40 -0700468 // 91 SUB_INT vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700469 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700470
Bill Buzbeea114add2012-05-03 15:00:40 -0700471 // 92 MUL_INT vAA, vBB, vCC
472 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700473
Bill Buzbeea114add2012-05-03 15:00:40 -0700474 // 93 DIV_INT vAA, vBB, vCC
475 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700476
Bill Buzbeea114add2012-05-03 15:00:40 -0700477 // 94 REM_INT vAA, vBB, vCC
478 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700479
Bill Buzbeea114add2012-05-03 15:00:40 -0700480 // 95 AND_INT vAA, vBB, vCC
481 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700482
Bill Buzbeea114add2012-05-03 15:00:40 -0700483 // 96 OR_INT vAA, vBB, vCC
484 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700485
Bill Buzbeea114add2012-05-03 15:00:40 -0700486 // 97 XOR_INT vAA, vBB, vCC
487 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700488
Bill Buzbeea114add2012-05-03 15:00:40 -0700489 // 98 SHL_INT vAA, vBB, vCC
490 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700491
Bill Buzbeea114add2012-05-03 15:00:40 -0700492 // 99 SHR_INT vAA, vBB, vCC
493 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700494
Bill Buzbeea114add2012-05-03 15:00:40 -0700495 // 9A USHR_INT vAA, vBB, vCC
496 DF_DA | DF_UB | DF_UC | DF_CORE_A | DF_CORE_B | DF_CORE_C,
buzbee67bf8852011-08-17 17:51:35 -0700497
Bill Buzbeea114add2012-05-03 15:00:40 -0700498 // 9B ADD_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700499 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 -0700500
Bill Buzbeea114add2012-05-03 15:00:40 -0700501 // 9C SUB_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700502 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 -0700503
Bill Buzbeea114add2012-05-03 15:00:40 -0700504 // 9D MUL_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700505 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 -0700506
Bill Buzbeea114add2012-05-03 15:00:40 -0700507 // 9E DIV_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700508 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 -0700509
Bill Buzbeea114add2012-05-03 15:00:40 -0700510 // 9F REM_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700511 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 -0700512
Bill Buzbeea114add2012-05-03 15:00:40 -0700513 // A0 AND_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700514 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 -0700515
Bill Buzbeea114add2012-05-03 15:00:40 -0700516 // A1 OR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700517 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 -0700518
Bill Buzbeea114add2012-05-03 15:00:40 -0700519 // A2 XOR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700520 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 -0700521
Bill Buzbeea114add2012-05-03 15:00:40 -0700522 // A3 SHL_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700523 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 -0700524
Bill Buzbeea114add2012-05-03 15:00:40 -0700525 // A4 SHR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700526 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 -0700527
Bill Buzbeea114add2012-05-03 15:00:40 -0700528 // A5 USHR_LONG vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700529 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 -0700530
Bill Buzbeea114add2012-05-03 15:00:40 -0700531 // A6 ADD_FLOAT vAA, vBB, vCC
532 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700533
Bill Buzbeea114add2012-05-03 15:00:40 -0700534 // A7 SUB_FLOAT vAA, vBB, vCC
535 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700536
Bill Buzbeea114add2012-05-03 15:00:40 -0700537 // A8 MUL_FLOAT vAA, vBB, vCC
538 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700539
Bill Buzbeea114add2012-05-03 15:00:40 -0700540 // A9 DIV_FLOAT vAA, vBB, vCC
541 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700542
Bill Buzbeea114add2012-05-03 15:00:40 -0700543 // AA REM_FLOAT vAA, vBB, vCC
544 DF_DA | DF_UB | DF_UC | DF_FP_A | DF_FP_B | DF_FP_C,
buzbee67bf8852011-08-17 17:51:35 -0700545
Bill Buzbeea114add2012-05-03 15:00:40 -0700546 // AB ADD_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700547 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 -0700548
Bill Buzbeea114add2012-05-03 15:00:40 -0700549 // AC SUB_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700550 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 -0700551
Bill Buzbeea114add2012-05-03 15:00:40 -0700552 // AD MUL_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700553 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 -0700554
Bill Buzbeea114add2012-05-03 15:00:40 -0700555 // AE DIV_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700556 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 -0700557
Bill Buzbeea114add2012-05-03 15:00:40 -0700558 // AF REM_DOUBLE vAA, vBB, vCC
buzbeebff24652012-05-06 16:22:05 -0700559 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 -0700560
Bill Buzbeea114add2012-05-03 15:00:40 -0700561 // B0 ADD_INT_2ADDR vA, vB
562 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700563
Bill Buzbeea114add2012-05-03 15:00:40 -0700564 // B1 SUB_INT_2ADDR vA, vB
565 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700566
Bill Buzbeea114add2012-05-03 15:00:40 -0700567 // B2 MUL_INT_2ADDR vA, vB
568 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700569
Bill Buzbeea114add2012-05-03 15:00:40 -0700570 // B3 DIV_INT_2ADDR vA, vB
571 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700572
Bill Buzbeea114add2012-05-03 15:00:40 -0700573 // B4 REM_INT_2ADDR vA, vB
574 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700575
Bill Buzbeea114add2012-05-03 15:00:40 -0700576 // B5 AND_INT_2ADDR vA, vB
577 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700578
Bill Buzbeea114add2012-05-03 15:00:40 -0700579 // B6 OR_INT_2ADDR vA, vB
580 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700581
Bill Buzbeea114add2012-05-03 15:00:40 -0700582 // B7 XOR_INT_2ADDR vA, vB
583 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700584
Bill Buzbeea114add2012-05-03 15:00:40 -0700585 // B8 SHL_INT_2ADDR vA, vB
586 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700587
Bill Buzbeea114add2012-05-03 15:00:40 -0700588 // B9 SHR_INT_2ADDR vA, vB
589 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700590
Bill Buzbeea114add2012-05-03 15:00:40 -0700591 // BA USHR_INT_2ADDR vA, vB
592 DF_DA | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700593
Bill Buzbeea114add2012-05-03 15:00:40 -0700594 // BB ADD_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700595 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700596
Bill Buzbeea114add2012-05-03 15:00:40 -0700597 // BC SUB_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700598 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700599
Bill Buzbeea114add2012-05-03 15:00:40 -0700600 // BD MUL_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700601 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700602
Bill Buzbeea114add2012-05-03 15:00:40 -0700603 // BE DIV_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700604 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700605
Bill Buzbeea114add2012-05-03 15:00:40 -0700606 // BF REM_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700607 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700608
Bill Buzbeea114add2012-05-03 15:00:40 -0700609 // C0 AND_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700610 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700611
Bill Buzbeea114add2012-05-03 15:00:40 -0700612 // C1 OR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700613 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700614
Bill Buzbeea114add2012-05-03 15:00:40 -0700615 // C2 XOR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700616 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700617
Bill Buzbeea114add2012-05-03 15:00:40 -0700618 // C3 SHL_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700619 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700620
Bill Buzbeea114add2012-05-03 15:00:40 -0700621 // C4 SHR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700622 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700623
Bill Buzbeea114add2012-05-03 15:00:40 -0700624 // C5 USHR_LONG_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700625 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700626
Bill Buzbeea114add2012-05-03 15:00:40 -0700627 // C6 ADD_FLOAT_2ADDR vA, vB
628 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700629
Bill Buzbeea114add2012-05-03 15:00:40 -0700630 // C7 SUB_FLOAT_2ADDR vA, vB
631 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700632
Bill Buzbeea114add2012-05-03 15:00:40 -0700633 // C8 MUL_FLOAT_2ADDR vA, vB
634 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700635
Bill Buzbeea114add2012-05-03 15:00:40 -0700636 // C9 DIV_FLOAT_2ADDR vA, vB
637 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700638
Bill Buzbeea114add2012-05-03 15:00:40 -0700639 // CA REM_FLOAT_2ADDR vA, vB
640 DF_DA | DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700641
Bill Buzbeea114add2012-05-03 15:00:40 -0700642 // CB ADD_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700643 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700644
Bill Buzbeea114add2012-05-03 15:00:40 -0700645 // CC SUB_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700646 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700647
Bill Buzbeea114add2012-05-03 15:00:40 -0700648 // CD MUL_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700649 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700650
Bill Buzbeea114add2012-05-03 15:00:40 -0700651 // CE DIV_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700652 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700653
Bill Buzbeea114add2012-05-03 15:00:40 -0700654 // CF REM_DOUBLE_2ADDR vA, vB
buzbeebff24652012-05-06 16:22:05 -0700655 DF_DA | DF_A_WIDE | DF_UA | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee67bf8852011-08-17 17:51:35 -0700656
Bill Buzbeea114add2012-05-03 15:00:40 -0700657 // D0 ADD_INT_LIT16 vA, vB, #+CCCC
658 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700659
Bill Buzbeea114add2012-05-03 15:00:40 -0700660 // D1 RSUB_INT vA, vB, #+CCCC
661 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700662
Bill Buzbeea114add2012-05-03 15:00:40 -0700663 // D2 MUL_INT_LIT16 vA, vB, #+CCCC
664 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700665
Bill Buzbeea114add2012-05-03 15:00:40 -0700666 // D3 DIV_INT_LIT16 vA, vB, #+CCCC
667 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700668
Bill Buzbeea114add2012-05-03 15:00:40 -0700669 // D4 REM_INT_LIT16 vA, vB, #+CCCC
670 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700671
Bill Buzbeea114add2012-05-03 15:00:40 -0700672 // D5 AND_INT_LIT16 vA, vB, #+CCCC
673 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700674
Bill Buzbeea114add2012-05-03 15:00:40 -0700675 // D6 OR_INT_LIT16 vA, vB, #+CCCC
676 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700677
Bill Buzbeea114add2012-05-03 15:00:40 -0700678 // D7 XOR_INT_LIT16 vA, vB, #+CCCC
679 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700680
Bill Buzbeea114add2012-05-03 15:00:40 -0700681 // D8 ADD_INT_LIT8 vAA, vBB, #+CC
buzbeebff24652012-05-06 16:22:05 -0700682 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700683
Bill Buzbeea114add2012-05-03 15:00:40 -0700684 // D9 RSUB_INT_LIT8 vAA, vBB, #+CC
685 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700686
Bill Buzbeea114add2012-05-03 15:00:40 -0700687 // DA MUL_INT_LIT8 vAA, vBB, #+CC
688 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700689
Bill Buzbeea114add2012-05-03 15:00:40 -0700690 // DB DIV_INT_LIT8 vAA, vBB, #+CC
691 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700692
Bill Buzbeea114add2012-05-03 15:00:40 -0700693 // DC REM_INT_LIT8 vAA, vBB, #+CC
694 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700695
Bill Buzbeea114add2012-05-03 15:00:40 -0700696 // DD AND_INT_LIT8 vAA, vBB, #+CC
697 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700698
Bill Buzbeea114add2012-05-03 15:00:40 -0700699 // DE OR_INT_LIT8 vAA, vBB, #+CC
700 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700701
Bill Buzbeea114add2012-05-03 15:00:40 -0700702 // DF XOR_INT_LIT8 vAA, vBB, #+CC
703 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700704
Bill Buzbeea114add2012-05-03 15:00:40 -0700705 // E0 SHL_INT_LIT8 vAA, vBB, #+CC
706 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700707
Bill Buzbeea114add2012-05-03 15:00:40 -0700708 // E1 SHR_INT_LIT8 vAA, vBB, #+CC
709 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700710
Bill Buzbeea114add2012-05-03 15:00:40 -0700711 // E2 USHR_INT_LIT8 vAA, vBB, #+CC
712 DF_DA | DF_UB | DF_CORE_A | DF_CORE_B,
buzbee67bf8852011-08-17 17:51:35 -0700713
Bill Buzbeea114add2012-05-03 15:00:40 -0700714 // E3 IGET_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700715 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700716
Bill Buzbeea114add2012-05-03 15:00:40 -0700717 // E4 IPUT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700718 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700719
Bill Buzbeea114add2012-05-03 15:00:40 -0700720 // E5 SGET_VOLATILE
721 DF_DA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700722
Bill Buzbeea114add2012-05-03 15:00:40 -0700723 // E6 SPUT_VOLATILE
724 DF_UA | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700725
Bill Buzbeea114add2012-05-03 15:00:40 -0700726 // E7 IGET_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700727 DF_DA | DF_UB | DF_NULL_CHK_0 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700728
Bill Buzbeea114add2012-05-03 15:00:40 -0700729 // E8 IGET_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700730 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700731
Bill Buzbeea114add2012-05-03 15:00:40 -0700732 // E9 IPUT_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700733 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2 | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700734
Bill Buzbeea114add2012-05-03 15:00:40 -0700735 // EA SGET_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700736 DF_DA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700737
Bill Buzbeea114add2012-05-03 15:00:40 -0700738 // EB SPUT_WIDE_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700739 DF_UA | DF_A_WIDE | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700740
Bill Buzbeea114add2012-05-03 15:00:40 -0700741 // EC BREAKPOINT
742 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700743
Bill Buzbeea114add2012-05-03 15:00:40 -0700744 // ED THROW_VERIFICATION_ERROR
745 DF_NOP | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700746
Bill Buzbeea114add2012-05-03 15:00:40 -0700747 // EE EXECUTE_INLINE
748 DF_FORMAT_35C,
buzbee67bf8852011-08-17 17:51:35 -0700749
Bill Buzbeea114add2012-05-03 15:00:40 -0700750 // EF EXECUTE_INLINE_RANGE
751 DF_FORMAT_3RC,
buzbee67bf8852011-08-17 17:51:35 -0700752
Bill Buzbeea114add2012-05-03 15:00:40 -0700753 // F0 INVOKE_OBJECT_INIT_RANGE
754 DF_NOP | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700755
Bill Buzbeea114add2012-05-03 15:00:40 -0700756 // F1 RETURN_VOID_BARRIER
757 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700758
Bill Buzbeea114add2012-05-03 15:00:40 -0700759 // F2 IGET_QUICK
760 DF_DA | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700761
Bill Buzbeea114add2012-05-03 15:00:40 -0700762 // F3 IGET_WIDE_QUICK
buzbeebff24652012-05-06 16:22:05 -0700763 DF_DA | DF_A_WIDE | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700764
Bill Buzbeea114add2012-05-03 15:00:40 -0700765 // F4 IGET_OBJECT_QUICK
766 DF_DA | DF_UB | DF_NULL_CHK_0,
buzbee67bf8852011-08-17 17:51:35 -0700767
Bill Buzbeea114add2012-05-03 15:00:40 -0700768 // F5 IPUT_QUICK
769 DF_UA | DF_UB | DF_NULL_CHK_1,
buzbee67bf8852011-08-17 17:51:35 -0700770
Bill Buzbeea114add2012-05-03 15:00:40 -0700771 // F6 IPUT_WIDE_QUICK
buzbeebff24652012-05-06 16:22:05 -0700772 DF_UA | DF_A_WIDE | DF_UB | DF_NULL_CHK_2,
buzbee67bf8852011-08-17 17:51:35 -0700773
Bill Buzbeea114add2012-05-03 15:00:40 -0700774 // F7 IPUT_OBJECT_QUICK
775 DF_UA | DF_UB | DF_NULL_CHK_1,
buzbee67bf8852011-08-17 17:51:35 -0700776
Bill Buzbeea114add2012-05-03 15:00:40 -0700777 // F8 INVOKE_VIRTUAL_QUICK
778 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700779
Bill Buzbeea114add2012-05-03 15:00:40 -0700780 // F9 INVOKE_VIRTUAL_QUICK_RANGE
781 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700782
Bill Buzbeea114add2012-05-03 15:00:40 -0700783 // FA INVOKE_SUPER_QUICK
784 DF_FORMAT_35C | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700785
Bill Buzbeea114add2012-05-03 15:00:40 -0700786 // FB INVOKE_SUPER_QUICK_RANGE
787 DF_FORMAT_3RC | DF_NULL_CHK_OUT0 | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700788
Bill Buzbeea114add2012-05-03 15:00:40 -0700789 // FC IPUT_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700790 DF_UA | DF_UB | DF_NULL_CHK_1 | DF_REF_A | DF_REF_B,
buzbee67bf8852011-08-17 17:51:35 -0700791
Bill Buzbeea114add2012-05-03 15:00:40 -0700792 // FD SGET_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700793 DF_DA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700794
Bill Buzbeea114add2012-05-03 15:00:40 -0700795 // FE SPUT_OBJECT_VOLATILE
buzbeebff24652012-05-06 16:22:05 -0700796 DF_UA | DF_REF_A | DF_UMS,
buzbee67bf8852011-08-17 17:51:35 -0700797
Bill Buzbeea114add2012-05-03 15:00:40 -0700798 // FF UNUSED_FF
799 DF_NOP,
buzbee67bf8852011-08-17 17:51:35 -0700800
Bill Buzbeea114add2012-05-03 15:00:40 -0700801 // Beginning of extended MIR opcodes
802 // 100 MIR_PHI
buzbeebff24652012-05-06 16:22:05 -0700803 DF_DA | DF_NULL_TRANSFER_N,
buzbee84fd6932012-03-29 16:44:16 -0700804
Bill Buzbeea114add2012-05-03 15:00:40 -0700805 // 101 MIR_COPY
806 DF_DA | DF_UB | DF_IS_MOVE,
buzbee84fd6932012-03-29 16:44:16 -0700807
Bill Buzbeea114add2012-05-03 15:00:40 -0700808 // 102 MIR_FUSED_CMPL_FLOAT
809 DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700810
Bill Buzbeea114add2012-05-03 15:00:40 -0700811 // 103 MIR_FUSED_CMPG_FLOAT
812 DF_UA | DF_UB | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700813
Bill Buzbeea114add2012-05-03 15:00:40 -0700814 // 104 MIR_FUSED_CMPL_DOUBLE
buzbeebff24652012-05-06 16:22:05 -0700815 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700816
Bill Buzbeea114add2012-05-03 15:00:40 -0700817 // 105 MIR_FUSED_CMPG_DOUBLE
buzbeebff24652012-05-06 16:22:05 -0700818 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_FP_A | DF_FP_B,
buzbee84fd6932012-03-29 16:44:16 -0700819
Bill Buzbeea114add2012-05-03 15:00:40 -0700820 // 106 MIR_FUSED_CMP_LONG
buzbeebff24652012-05-06 16:22:05 -0700821 DF_UA | DF_A_WIDE | DF_UB | DF_B_WIDE | DF_CORE_A | DF_CORE_B,
buzbee84fd6932012-03-29 16:44:16 -0700822
Bill Buzbeea114add2012-05-03 15:00:40 -0700823 // 107 MIR_NOP
824 DF_NOP,
buzbee84fd6932012-03-29 16:44:16 -0700825
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700826 // 108 MIR_NULL_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700827 0,
buzbee84fd6932012-03-29 16:44:16 -0700828
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700829 // 109 MIR_RANGE_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700830 0,
buzbee84fd6932012-03-29 16:44:16 -0700831
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700832 // 110 MIR_DIV_ZERO_CHECK
833 0,
834
835 // 111 MIR_CHECK
Bill Buzbeea114add2012-05-03 15:00:40 -0700836 0,
buzbee67bf8852011-08-17 17:51:35 -0700837};
838
buzbeee1965672012-03-11 18:39:19 -0700839/* Return the base virtual register for a SSA name */
buzbeefa57c472012-11-21 12:06:18 -0800840int SRegToVReg(const CompilationUnit* cu, int ssa_reg)
buzbee67bf8852011-08-17 17:51:35 -0700841{
buzbeefa57c472012-11-21 12:06:18 -0800842 DCHECK_LT(ssa_reg, static_cast<int>(cu->ssa_base_vregs->num_used));
843 return GET_ELEM_N(cu->ssa_base_vregs, int, ssa_reg);
buzbee67bf8852011-08-17 17:51:35 -0700844}
845
buzbeefa57c472012-11-21 12:06:18 -0800846int SRegToSubscript(const CompilationUnit* cu, int ssa_reg)
buzbeee1965672012-03-11 18:39:19 -0700847{
buzbeefa57c472012-11-21 12:06:18 -0800848 DCHECK(ssa_reg < static_cast<int>(cu->ssa_subscripts->num_used));
849 return GET_ELEM_N(cu->ssa_subscripts, int, ssa_reg);
buzbeee1965672012-03-11 18:39:19 -0700850}
851
buzbeefa57c472012-11-21 12:06:18 -0800852static int GetSSAUseCount(CompilationUnit* cu, int s_reg)
buzbee84fd6932012-03-29 16:44:16 -0700853{
buzbeefa57c472012-11-21 12:06:18 -0800854 DCHECK(s_reg < static_cast<int>(cu->raw_use_counts.num_used));
855 return cu->raw_use_counts.elem_list[s_reg];
buzbee84fd6932012-03-29 16:44:16 -0700856}
857
buzbeea169e1d2012-12-05 14:26:44 -0800858static std::string GetSSAName(const CompilationUnit* cu, int ssa_reg)
buzbee67bf8852011-08-17 17:51:35 -0700859{
buzbeea169e1d2012-12-05 14:26:44 -0800860 return StringPrintf("v%d_%d", SRegToVReg(cu, ssa_reg), SRegToSubscript(cu, ssa_reg));
861}
862
863// Similar to GetSSAName, but if ssa name represents an immediate show that as well.
864static std::string GetSSANameWithConst(const CompilationUnit* cu, int ssa_reg, bool singles_only)
865{
buzbeed8506212012-12-20 14:15:05 -0800866 if (cu->reg_location == NULL) {
buzbee2502e002012-12-31 16:05:53 -0800867 // Pre-SSA - just use the standard name
868 return GetSSAName(cu, ssa_reg);
buzbeed8506212012-12-20 14:15:05 -0800869 }
buzbee4ef3e452012-12-14 13:35:28 -0800870 if (IsConst(cu, cu->reg_location[ssa_reg])) {
buzbeea169e1d2012-12-05 14:26:44 -0800871 if (!singles_only && cu->reg_location[ssa_reg].wide) {
buzbeea169e1d2012-12-05 14:26:44 -0800872 return StringPrintf("v%d_%d#0x%llx", SRegToVReg(cu, ssa_reg),
buzbee4ef3e452012-12-14 13:35:28 -0800873 SRegToSubscript(cu, ssa_reg),
874 ConstantValueWide(cu, cu->reg_location[ssa_reg]));
buzbeea169e1d2012-12-05 14:26:44 -0800875 } else {
buzbeea169e1d2012-12-05 14:26:44 -0800876 return StringPrintf("v%d_%d#0x%x", SRegToVReg(cu, ssa_reg),
buzbee4ef3e452012-12-14 13:35:28 -0800877 SRegToSubscript(cu, ssa_reg),
878 ConstantValue(cu, cu->reg_location[ssa_reg]));
buzbeea169e1d2012-12-05 14:26:44 -0800879 }
880 } else {
881 return StringPrintf("v%d_%d", SRegToVReg(cu, ssa_reg), SRegToSubscript(cu, ssa_reg));
882 }
883}
884
885
886char* GetDalvikDisassembly(CompilationUnit* cu, const MIR* mir)
887{
888 DecodedInstruction insn = mir->dalvikInsn;
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700889 std::string str;
buzbeea169e1d2012-12-05 14:26:44 -0800890 int flags = 0;
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700891 int opcode = insn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700892 char* ret;
buzbeea169e1d2012-12-05 14:26:44 -0800893 bool nop = false;
894 SSARepresentation* ssa_rep = mir->ssa_rep;
895 Instruction::Format dalvik_format = Instruction::k10x; // Default to no-operand format
896 int defs = (ssa_rep != NULL) ? ssa_rep->num_defs : 0;
897 int uses = (ssa_rep != NULL) ? ssa_rep->num_uses : 0;
898
899 // Handle special cases.
900 if ((opcode == kMirOpCheck) || (opcode == kMirOpCheckPart2)) {
901 str.append(extended_mir_op_names[opcode - kMirOpFirst]);
902 str.append(": ");
903 // Recover the original Dex instruction
904 insn = mir->meta.throw_insn->dalvikInsn;
905 ssa_rep = mir->meta.throw_insn->ssa_rep;
906 defs = ssa_rep->num_defs;
907 uses = ssa_rep->num_uses;
908 opcode = insn.opcode;
909 } else if (opcode == kMirOpNop) {
910 str.append("[");
911 insn.opcode = mir->meta.original_opcode;
912 opcode = mir->meta.original_opcode;
913 nop = true;
914 }
buzbee67bf8852011-08-17 17:51:35 -0700915
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700916 if (opcode >= kMirOpFirst) {
buzbeea169e1d2012-12-05 14:26:44 -0800917 str.append(extended_mir_op_names[opcode - kMirOpFirst]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700918 } else {
buzbeea169e1d2012-12-05 14:26:44 -0800919 dalvik_format = Instruction::FormatOf(insn.opcode);
Ian Rogersa75a0132012-09-28 11:41:42 -0700920 flags = Instruction::FlagsOf(insn.opcode);
buzbeea169e1d2012-12-05 14:26:44 -0800921 str.append(Instruction::Name(insn.opcode));
Bill Buzbeea114add2012-05-03 15:00:40 -0700922 }
buzbee67bf8852011-08-17 17:51:35 -0700923
buzbeea169e1d2012-12-05 14:26:44 -0800924 if (opcode == kMirOpPhi) {
925 int* incoming = reinterpret_cast<int*>(insn.vB);
926 str.append(StringPrintf(" %s = (%s",
927 GetSSANameWithConst(cu, ssa_rep->defs[0], true).c_str(),
928 GetSSANameWithConst(cu, ssa_rep->uses[0], true).c_str()));
929 str.append(StringPrintf(":%d",incoming[0]));
930 int i;
931 for (i = 1; i < uses; i++) {
932 str.append(StringPrintf(", %s:%d",
933 GetSSANameWithConst(cu, ssa_rep->uses[i], true).c_str(),
934 incoming[i]));
935 }
936 str.append(")");
937 } else if (flags & Instruction::kBranch) {
938 // For branches, decode the instructions to print out the branch targets.
Bill Buzbeea114add2012-05-03 15:00:40 -0700939 int offset = 0;
buzbeefa57c472012-11-21 12:06:18 -0800940 switch (dalvik_format) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700941 case Instruction::k21t:
buzbeea169e1d2012-12-05 14:26:44 -0800942 str.append(StringPrintf(" %s,", GetSSANameWithConst(cu, ssa_rep->uses[0], false).c_str()));
buzbeecbd6d442012-11-17 14:11:25 -0800943 offset = insn.vB;
Bill Buzbeea114add2012-05-03 15:00:40 -0700944 break;
945 case Instruction::k22t:
buzbeea169e1d2012-12-05 14:26:44 -0800946 str.append(StringPrintf(" %s, %s,", GetSSANameWithConst(cu, ssa_rep->uses[0], false).c_str(),
buzbeed8506212012-12-20 14:15:05 -0800947 GetSSANameWithConst(cu, ssa_rep->uses[1], false).c_str()));
buzbeecbd6d442012-11-17 14:11:25 -0800948 offset = insn.vC;
Bill Buzbeea114add2012-05-03 15:00:40 -0700949 break;
950 case Instruction::k10t:
951 case Instruction::k20t:
952 case Instruction::k30t:
buzbeecbd6d442012-11-17 14:11:25 -0800953 offset = insn.vA;
Bill Buzbeea114add2012-05-03 15:00:40 -0700954 break;
955 default:
buzbeefa57c472012-11-21 12:06:18 -0800956 LOG(FATAL) << "Unexpected branch format " << dalvik_format << " from " << insn.opcode;
buzbee67bf8852011-08-17 17:51:35 -0700957 }
buzbeea169e1d2012-12-05 14:26:44 -0800958 str.append(StringPrintf(" 0x%x (%c%x)", mir->offset + offset,
959 offset > 0 ? '+' : '-', offset > 0 ? offset : -offset));
Bill Buzbeea114add2012-05-03 15:00:40 -0700960 } else {
buzbeea169e1d2012-12-05 14:26:44 -0800961 // For invokes-style formats, treat wide regs as a pair of singles
962 bool show_singles = ((dalvik_format == Instruction::k35c) ||
963 (dalvik_format == Instruction::k3rc));
964 if (defs != 0) {
965 str.append(StringPrintf(" %s", GetSSANameWithConst(cu, ssa_rep->defs[0], false).c_str()));
966 if (uses != 0) {
967 str.append(", ");
Bill Buzbeea114add2012-05-03 15:00:40 -0700968 }
buzbee67bf8852011-08-17 17:51:35 -0700969 }
buzbeea169e1d2012-12-05 14:26:44 -0800970 for (int i = 0; i < uses; i++) {
971 str.append(
972 StringPrintf(" %s", GetSSANameWithConst(cu, ssa_rep->uses[i], show_singles).c_str()));
buzbeed8506212012-12-20 14:15:05 -0800973 if (!show_singles && (cu->reg_location != NULL) && cu->reg_location[i].wide) {
buzbeea169e1d2012-12-05 14:26:44 -0800974 // For the listing, skip the high sreg.
975 i++;
976 }
977 if (i != (uses -1)) {
978 str.append(",");
979 }
980 }
buzbeefa57c472012-11-21 12:06:18 -0800981 switch (dalvik_format) {
buzbeea169e1d2012-12-05 14:26:44 -0800982 case Instruction::k11n: // Add one immediate from vB
983 case Instruction::k21s:
984 case Instruction::k31i:
985 case Instruction::k21h:
986 str.append(StringPrintf(", #%d", insn.vB));
Bill Buzbeea114add2012-05-03 15:00:40 -0700987 break;
buzbeea169e1d2012-12-05 14:26:44 -0800988 case Instruction::k51l: // Add one wide immediate
989 str.append(StringPrintf(", #%lld", insn.vB_wide));
Bill Buzbeea114add2012-05-03 15:00:40 -0700990 break;
buzbeea169e1d2012-12-05 14:26:44 -0800991 case Instruction::k21c: // One register, one string/type/method index
992 case Instruction::k31c:
993 str.append(StringPrintf(", index #%d", insn.vB));
994 break;
995 case Instruction::k22c: // Two registers, one string/type/method index
996 str.append(StringPrintf(", index #%d", insn.vC));
997 break;
998 case Instruction::k22s: // Add one immediate from vC
999 case Instruction::k22b:
1000 str.append(StringPrintf(", #%d", insn.vC));
Bill Buzbeea114add2012-05-03 15:00:40 -07001001 break;
1002 default:
buzbeea169e1d2012-12-05 14:26:44 -08001003 ; // Nothing left to print
Bill Buzbeea114add2012-05-03 15:00:40 -07001004 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001005 }
buzbeea169e1d2012-12-05 14:26:44 -08001006 if (nop) {
1007 str.append("]--optimized away");
Bill Buzbeea114add2012-05-03 15:00:40 -07001008 }
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001009 int length = str.length() + 1;
buzbeefa57c472012-11-21 12:06:18 -08001010 ret = static_cast<char*>(NewMem(cu, length, false, kAllocDFInfo));
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001011 strncpy(ret, str.c_str(), length);
Bill Buzbeea114add2012-05-03 15:00:40 -07001012 return ret;
buzbee67bf8852011-08-17 17:51:35 -07001013}
1014
1015/* Any register that is used before being defined is considered live-in */
buzbeefa57c472012-11-21 12:06:18 -08001016static void HandleLiveInUse(CompilationUnit* cu, ArenaBitVector* use_v, ArenaBitVector* def_v,
1017 ArenaBitVector* live_in_v, int dalvik_reg_id)
buzbee67bf8852011-08-17 17:51:35 -07001018{
buzbeefa57c472012-11-21 12:06:18 -08001019 SetBit(cu, use_v, dalvik_reg_id);
1020 if (!IsBitSet(def_v, dalvik_reg_id)) {
1021 SetBit(cu, live_in_v, dalvik_reg_id);
Bill Buzbeea114add2012-05-03 15:00:40 -07001022 }
buzbee67bf8852011-08-17 17:51:35 -07001023}
1024
1025/* Mark a reg as being defined */
buzbeefa57c472012-11-21 12:06:18 -08001026static void HandleDef(CompilationUnit* cu, ArenaBitVector* def_v, int dalvik_reg_id)
buzbee67bf8852011-08-17 17:51:35 -07001027{
buzbeefa57c472012-11-21 12:06:18 -08001028 SetBit(cu, def_v, dalvik_reg_id);
buzbee67bf8852011-08-17 17:51:35 -07001029}
1030
1031/*
1032 * Find out live-in variables for natural loops. Variables that are live-in in
1033 * the main loop body are considered to be defined in the entry block.
1034 */
buzbeefa57c472012-11-21 12:06:18 -08001035bool FindLocalLiveIn(CompilationUnit* cu, BasicBlock* bb)
buzbee67bf8852011-08-17 17:51:35 -07001036{
Bill Buzbeea114add2012-05-03 15:00:40 -07001037 MIR* mir;
buzbeefa57c472012-11-21 12:06:18 -08001038 ArenaBitVector *use_v, *def_v, *live_in_v;
buzbee67bf8852011-08-17 17:51:35 -07001039
buzbeefa57c472012-11-21 12:06:18 -08001040 if (bb->data_flow_info == NULL) return false;
buzbee67bf8852011-08-17 17:51:35 -07001041
buzbeefa57c472012-11-21 12:06:18 -08001042 use_v = bb->data_flow_info->use_v =
1043 AllocBitVector(cu, cu->num_dalvik_registers, false, kBitMapUse);
1044 def_v = bb->data_flow_info->def_v =
1045 AllocBitVector(cu, cu->num_dalvik_registers, false, kBitMapDef);
1046 live_in_v = bb->data_flow_info->live_in_v =
1047 AllocBitVector(cu, cu->num_dalvik_registers, false,
Bill Buzbeea114add2012-05-03 15:00:40 -07001048 kBitMapLiveIn);
buzbee67bf8852011-08-17 17:51:35 -07001049
buzbee28c9a832012-11-21 15:39:13 -08001050 for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeefa57c472012-11-21 12:06:18 -08001051 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
1052 DecodedInstruction *d_insn = &mir->dalvikInsn;
buzbee67bf8852011-08-17 17:51:35 -07001053
buzbeefa57c472012-11-21 12:06:18 -08001054 if (df_attributes & DF_HAS_USES) {
1055 if (df_attributes & DF_UA) {
1056 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vA);
1057 if (df_attributes & DF_A_WIDE) {
1058 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vA+1);
buzbeebff24652012-05-06 16:22:05 -07001059 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001060 }
buzbeefa57c472012-11-21 12:06:18 -08001061 if (df_attributes & DF_UB) {
1062 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vB);
1063 if (df_attributes & DF_B_WIDE) {
1064 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vB+1);
buzbeebff24652012-05-06 16:22:05 -07001065 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001066 }
buzbeefa57c472012-11-21 12:06:18 -08001067 if (df_attributes & DF_UC) {
1068 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vC);
1069 if (df_attributes & DF_C_WIDE) {
1070 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vC+1);
buzbeebff24652012-05-06 16:22:05 -07001071 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001072 }
buzbee67bf8852011-08-17 17:51:35 -07001073 }
buzbeefa57c472012-11-21 12:06:18 -08001074 if (df_attributes & DF_FORMAT_35C) {
1075 for (unsigned int i = 0; i < d_insn->vA; i++) {
1076 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->arg[i]);
Bill Buzbeea114add2012-05-03 15:00:40 -07001077 }
1078 }
buzbeefa57c472012-11-21 12:06:18 -08001079 if (df_attributes & DF_FORMAT_3RC) {
1080 for (unsigned int i = 0; i < d_insn->vA; i++) {
1081 HandleLiveInUse(cu, use_v, def_v, live_in_v, d_insn->vC+i);
Bill Buzbeea114add2012-05-03 15:00:40 -07001082 }
1083 }
buzbeefa57c472012-11-21 12:06:18 -08001084 if (df_attributes & DF_HAS_DEFS) {
1085 HandleDef(cu, def_v, d_insn->vA);
1086 if (df_attributes & DF_A_WIDE) {
1087 HandleDef(cu, def_v, d_insn->vA+1);
Bill Buzbeea114add2012-05-03 15:00:40 -07001088 }
1089 }
1090 }
1091 return true;
buzbee67bf8852011-08-17 17:51:35 -07001092}
1093
buzbeefa57c472012-11-21 12:06:18 -08001094static int AddNewSReg(CompilationUnit* cu, int v_reg)
buzbeee1965672012-03-11 18:39:19 -07001095{
Bill Buzbeea114add2012-05-03 15:00:40 -07001096 // Compiler temps always have a subscript of 0
buzbeefa57c472012-11-21 12:06:18 -08001097 int subscript = (v_reg < 0) ? 0 : ++cu->ssa_last_defs[v_reg];
1098 int ssa_reg = cu->num_ssa_regs++;
1099 InsertGrowableList(cu, cu->ssa_base_vregs, v_reg);
1100 InsertGrowableList(cu, cu->ssa_subscripts, subscript);
1101 std::string ssa_name = GetSSAName(cu, ssa_reg);
1102 char* name = static_cast<char*>(NewMem(cu, ssa_name.length() + 1, false, kAllocDFInfo));
1103 strncpy(name, ssa_name.c_str(), ssa_name.length() + 1);
1104 InsertGrowableList(cu, cu->ssa_strings, reinterpret_cast<uintptr_t>(name));
1105 DCHECK_EQ(cu->ssa_base_vregs->num_used, cu->ssa_subscripts->num_used);
1106 return ssa_reg;
buzbeee1965672012-03-11 18:39:19 -07001107}
1108
buzbee67bf8852011-08-17 17:51:35 -07001109/* Find out the latest SSA register for a given Dalvik register */
buzbeefa57c472012-11-21 12:06:18 -08001110static void HandleSSAUse(CompilationUnit* cu, int* uses, int dalvik_reg, int reg_index)
buzbee67bf8852011-08-17 17:51:35 -07001111{
buzbeefa57c472012-11-21 12:06:18 -08001112 DCHECK((dalvik_reg >= 0) && (dalvik_reg < cu->num_dalvik_registers));
1113 uses[reg_index] = cu->vreg_to_ssa_map[dalvik_reg];
buzbee67bf8852011-08-17 17:51:35 -07001114}
1115
1116/* Setup a new SSA register for a given Dalvik register */
buzbeefa57c472012-11-21 12:06:18 -08001117static void HandleSSADef(CompilationUnit* cu, int* defs, int dalvik_reg, int reg_index)
buzbee67bf8852011-08-17 17:51:35 -07001118{
buzbeefa57c472012-11-21 12:06:18 -08001119 DCHECK((dalvik_reg >= 0) && (dalvik_reg < cu->num_dalvik_registers));
1120 int ssa_reg = AddNewSReg(cu, dalvik_reg);
1121 cu->vreg_to_ssa_map[dalvik_reg] = ssa_reg;
1122 defs[reg_index] = ssa_reg;
buzbee67bf8852011-08-17 17:51:35 -07001123}
1124
buzbeeec5adf32011-09-11 15:25:43 -07001125/* Look up new SSA names for format_35c instructions */
buzbeefa57c472012-11-21 12:06:18 -08001126static void DataFlowSSAFormat35C(CompilationUnit* cu, MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -07001127{
buzbeefa57c472012-11-21 12:06:18 -08001128 DecodedInstruction *d_insn = &mir->dalvikInsn;
1129 int num_uses = d_insn->vA;
Bill Buzbeea114add2012-05-03 15:00:40 -07001130 int i;
buzbee67bf8852011-08-17 17:51:35 -07001131
buzbeefa57c472012-11-21 12:06:18 -08001132 mir->ssa_rep->num_uses = num_uses;
1133 mir->ssa_rep->uses = static_cast<int*>(NewMem(cu, sizeof(int) * num_uses, true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001134 // NOTE: will be filled in during type & size inference pass
buzbeefa57c472012-11-21 12:06:18 -08001135 mir->ssa_rep->fp_use = static_cast<bool*>(NewMem(cu, sizeof(bool) * num_uses, true,
buzbeecbd6d442012-11-17 14:11:25 -08001136 kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001137
buzbeefa57c472012-11-21 12:06:18 -08001138 for (i = 0; i < num_uses; i++) {
1139 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->arg[i], i);
Bill Buzbeea114add2012-05-03 15:00:40 -07001140 }
buzbee67bf8852011-08-17 17:51:35 -07001141}
1142
buzbeeec5adf32011-09-11 15:25:43 -07001143/* Look up new SSA names for format_3rc instructions */
buzbeefa57c472012-11-21 12:06:18 -08001144static void DataFlowSSAFormat3RC(CompilationUnit* cu, MIR* mir)
buzbee67bf8852011-08-17 17:51:35 -07001145{
buzbeefa57c472012-11-21 12:06:18 -08001146 DecodedInstruction *d_insn = &mir->dalvikInsn;
1147 int num_uses = d_insn->vA;
Bill Buzbeea114add2012-05-03 15:00:40 -07001148 int i;
buzbee67bf8852011-08-17 17:51:35 -07001149
buzbeefa57c472012-11-21 12:06:18 -08001150 mir->ssa_rep->num_uses = num_uses;
1151 mir->ssa_rep->uses = static_cast<int*>(NewMem(cu, sizeof(int) * num_uses, true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001152 // NOTE: will be filled in during type & size inference pass
buzbeefa57c472012-11-21 12:06:18 -08001153 mir->ssa_rep->fp_use = static_cast<bool*>(NewMem(cu, sizeof(bool) * num_uses, true,
buzbeecbd6d442012-11-17 14:11:25 -08001154 kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001155
buzbeefa57c472012-11-21 12:06:18 -08001156 for (i = 0; i < num_uses; i++) {
1157 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vC+i, i);
Bill Buzbeea114add2012-05-03 15:00:40 -07001158 }
buzbee67bf8852011-08-17 17:51:35 -07001159}
1160
1161/* Entry function to convert a block into SSA representation */
buzbeefa57c472012-11-21 12:06:18 -08001162bool DoSSAConversion(CompilationUnit* cu, BasicBlock* bb)
buzbee67bf8852011-08-17 17:51:35 -07001163{
Bill Buzbeea114add2012-05-03 15:00:40 -07001164 MIR* mir;
buzbee67bf8852011-08-17 17:51:35 -07001165
buzbeefa57c472012-11-21 12:06:18 -08001166 if (bb->data_flow_info == NULL) return false;
buzbee67bf8852011-08-17 17:51:35 -07001167
buzbee28c9a832012-11-21 15:39:13 -08001168 for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeefa57c472012-11-21 12:06:18 -08001169 mir->ssa_rep = static_cast<struct SSARepresentation *>(NewMem(cu, sizeof(SSARepresentation),
buzbeecbd6d442012-11-17 14:11:25 -08001170 true, kAllocDFInfo));
buzbee67bf8852011-08-17 17:51:35 -07001171
buzbeefa57c472012-11-21 12:06:18 -08001172 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
buzbee67bf8852011-08-17 17:51:35 -07001173
Bill Buzbeea114add2012-05-03 15:00:40 -07001174 // If not a pseudo-op, note non-leaf or can throw
1175 if (static_cast<int>(mir->dalvikInsn.opcode) <
1176 static_cast<int>(kNumPackedOpcodes)) {
Ian Rogersa75a0132012-09-28 11:41:42 -07001177 int flags = Instruction::FlagsOf(mir->dalvikInsn.opcode);
buzbeecefd1872011-09-09 09:59:52 -07001178
Bill Buzbeea114add2012-05-03 15:00:40 -07001179 if (flags & Instruction::kThrow) {
buzbeefa57c472012-11-21 12:06:18 -08001180 cu->attrs &= ~METHOD_IS_THROW_FREE;
Bill Buzbeea114add2012-05-03 15:00:40 -07001181 }
buzbeecefd1872011-09-09 09:59:52 -07001182
Bill Buzbeea114add2012-05-03 15:00:40 -07001183 if (flags & Instruction::kInvoke) {
buzbeefa57c472012-11-21 12:06:18 -08001184 cu->attrs &= ~METHOD_IS_LEAF;
Bill Buzbeea114add2012-05-03 15:00:40 -07001185 }
buzbee67bf8852011-08-17 17:51:35 -07001186 }
1187
buzbeefa57c472012-11-21 12:06:18 -08001188 int num_uses = 0;
buzbee67bf8852011-08-17 17:51:35 -07001189
buzbeefa57c472012-11-21 12:06:18 -08001190 if (df_attributes & DF_FORMAT_35C) {
1191 DataFlowSSAFormat35C(cu, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -07001192 continue;
buzbee5abfa3e2012-01-31 17:01:43 -08001193 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001194
buzbeefa57c472012-11-21 12:06:18 -08001195 if (df_attributes & DF_FORMAT_3RC) {
1196 DataFlowSSAFormat3RC(cu, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -07001197 continue;
1198 }
1199
buzbeefa57c472012-11-21 12:06:18 -08001200 if (df_attributes & DF_HAS_USES) {
1201 if (df_attributes & DF_UA) {
1202 num_uses++;
1203 if (df_attributes & DF_A_WIDE) {
1204 num_uses ++;
buzbeebff24652012-05-06 16:22:05 -07001205 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001206 }
buzbeefa57c472012-11-21 12:06:18 -08001207 if (df_attributes & DF_UB) {
1208 num_uses++;
1209 if (df_attributes & DF_B_WIDE) {
1210 num_uses ++;
buzbeebff24652012-05-06 16:22:05 -07001211 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001212 }
buzbeefa57c472012-11-21 12:06:18 -08001213 if (df_attributes & DF_UC) {
1214 num_uses++;
1215 if (df_attributes & DF_C_WIDE) {
1216 num_uses ++;
buzbeebff24652012-05-06 16:22:05 -07001217 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001218 }
1219 }
1220
buzbeefa57c472012-11-21 12:06:18 -08001221 if (num_uses) {
1222 mir->ssa_rep->num_uses = num_uses;
1223 mir->ssa_rep->uses = static_cast<int*>(NewMem(cu, sizeof(int) * num_uses, false,
buzbeecbd6d442012-11-17 14:11:25 -08001224 kAllocDFInfo));
buzbeefa57c472012-11-21 12:06:18 -08001225 mir->ssa_rep->fp_use = static_cast<bool*>(NewMem(cu, sizeof(bool) * num_uses, false,
buzbeecbd6d442012-11-17 14:11:25 -08001226 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001227 }
1228
buzbeefa57c472012-11-21 12:06:18 -08001229 int num_defs = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -07001230
buzbeefa57c472012-11-21 12:06:18 -08001231 if (df_attributes & DF_HAS_DEFS) {
1232 num_defs++;
1233 if (df_attributes & DF_A_WIDE) {
1234 num_defs++;
Bill Buzbeea114add2012-05-03 15:00:40 -07001235 }
1236 }
1237
buzbeefa57c472012-11-21 12:06:18 -08001238 if (num_defs) {
1239 mir->ssa_rep->num_defs = num_defs;
1240 mir->ssa_rep->defs = static_cast<int*>(NewMem(cu, sizeof(int) * num_defs, false,
buzbeecbd6d442012-11-17 14:11:25 -08001241 kAllocDFInfo));
buzbeefa57c472012-11-21 12:06:18 -08001242 mir->ssa_rep->fp_def = static_cast<bool*>(NewMem(cu, sizeof(bool) * num_defs, false,
buzbeecbd6d442012-11-17 14:11:25 -08001243 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001244 }
1245
buzbeefa57c472012-11-21 12:06:18 -08001246 DecodedInstruction *d_insn = &mir->dalvikInsn;
Bill Buzbeea114add2012-05-03 15:00:40 -07001247
buzbeefa57c472012-11-21 12:06:18 -08001248 if (df_attributes & DF_HAS_USES) {
1249 num_uses = 0;
1250 if (df_attributes & DF_UA) {
1251 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_A;
1252 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vA, num_uses++);
1253 if (df_attributes & DF_A_WIDE) {
1254 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_A;
1255 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vA+1, num_uses++);
buzbeebff24652012-05-06 16:22:05 -07001256 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001257 }
buzbeefa57c472012-11-21 12:06:18 -08001258 if (df_attributes & DF_UB) {
1259 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_B;
1260 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vB, num_uses++);
1261 if (df_attributes & DF_B_WIDE) {
1262 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_B;
1263 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vB+1, num_uses++);
buzbeebff24652012-05-06 16:22:05 -07001264 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001265 }
buzbeefa57c472012-11-21 12:06:18 -08001266 if (df_attributes & DF_UC) {
1267 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_C;
1268 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vC, num_uses++);
1269 if (df_attributes & DF_C_WIDE) {
1270 mir->ssa_rep->fp_use[num_uses] = df_attributes & DF_FP_C;
1271 HandleSSAUse(cu, mir->ssa_rep->uses, d_insn->vC+1, num_uses++);
buzbeebff24652012-05-06 16:22:05 -07001272 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001273 }
1274 }
buzbeefa57c472012-11-21 12:06:18 -08001275 if (df_attributes & DF_HAS_DEFS) {
1276 mir->ssa_rep->fp_def[0] = df_attributes & DF_FP_A;
1277 HandleSSADef(cu, mir->ssa_rep->defs, d_insn->vA, 0);
1278 if (df_attributes & DF_A_WIDE) {
1279 mir->ssa_rep->fp_def[1] = df_attributes & DF_FP_A;
1280 HandleSSADef(cu, mir->ssa_rep->defs, d_insn->vA+1, 1);
Bill Buzbeea114add2012-05-03 15:00:40 -07001281 }
1282 }
1283 }
1284
buzbeefa57c472012-11-21 12:06:18 -08001285 if (!cu->disable_dataflow) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001286 /*
1287 * Take a snapshot of Dalvik->SSA mapping at the end of each block. The
1288 * input to PHI nodes can be derived from the snapshot of all
1289 * predecessor blocks.
1290 */
buzbeefa57c472012-11-21 12:06:18 -08001291 bb->data_flow_info->vreg_to_ssa_map =
1292 static_cast<int*>(NewMem(cu, sizeof(int) * cu->num_dalvik_registers, false,
buzbeecbd6d442012-11-17 14:11:25 -08001293 kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001294
buzbeefa57c472012-11-21 12:06:18 -08001295 memcpy(bb->data_flow_info->vreg_to_ssa_map, cu->vreg_to_ssa_map,
1296 sizeof(int) * cu->num_dalvik_registers);
Bill Buzbeea114add2012-05-03 15:00:40 -07001297 }
1298 return true;
buzbee67bf8852011-08-17 17:51:35 -07001299}
1300
1301/* Setup a constant value for opcodes thare have the DF_SETS_CONST attribute */
buzbee4ef3e452012-12-14 13:35:28 -08001302static void SetConstant(CompilationUnit* cu, int32_t ssa_reg, int value)
buzbee67bf8852011-08-17 17:51:35 -07001303{
buzbeefa57c472012-11-21 12:06:18 -08001304 SetBit(cu, cu->is_constant_v, ssa_reg);
1305 cu->constant_values[ssa_reg] = value;
buzbee67bf8852011-08-17 17:51:35 -07001306}
1307
buzbee4ef3e452012-12-14 13:35:28 -08001308static void SetConstantWide(CompilationUnit* cu, int ssa_reg, int64_t value)
1309{
1310 SetBit(cu, cu->is_constant_v, ssa_reg);
1311 cu->constant_values[ssa_reg] = Low32Bits(value);
1312 cu->constant_values[ssa_reg + 1] = High32Bits(value);
1313}
1314
buzbeefa57c472012-11-21 12:06:18 -08001315bool DoConstantPropogation(CompilationUnit* cu, BasicBlock* bb)
buzbee67bf8852011-08-17 17:51:35 -07001316{
Bill Buzbeea114add2012-05-03 15:00:40 -07001317 MIR* mir;
buzbeefa57c472012-11-21 12:06:18 -08001318 ArenaBitVector *is_constant_v = cu->is_constant_v;
buzbee67bf8852011-08-17 17:51:35 -07001319
buzbee28c9a832012-11-21 15:39:13 -08001320 for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeefa57c472012-11-21 12:06:18 -08001321 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
buzbee67bf8852011-08-17 17:51:35 -07001322
buzbeefa57c472012-11-21 12:06:18 -08001323 DecodedInstruction *d_insn = &mir->dalvikInsn;
buzbee67bf8852011-08-17 17:51:35 -07001324
buzbeefa57c472012-11-21 12:06:18 -08001325 if (!(df_attributes & DF_HAS_DEFS)) continue;
buzbee67bf8852011-08-17 17:51:35 -07001326
Bill Buzbeea114add2012-05-03 15:00:40 -07001327 /* Handle instructions that set up constants directly */
buzbeefa57c472012-11-21 12:06:18 -08001328 if (df_attributes & DF_SETS_CONST) {
1329 if (df_attributes & DF_DA) {
buzbee4ef3e452012-12-14 13:35:28 -08001330 int32_t vB = static_cast<int32_t>(d_insn->vB);
buzbeefa57c472012-11-21 12:06:18 -08001331 switch (d_insn->opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001332 case Instruction::CONST_4:
1333 case Instruction::CONST_16:
1334 case Instruction::CONST:
buzbee4ef3e452012-12-14 13:35:28 -08001335 SetConstant(cu, mir->ssa_rep->defs[0], vB);
Bill Buzbeea114add2012-05-03 15:00:40 -07001336 break;
1337 case Instruction::CONST_HIGH16:
buzbee4ef3e452012-12-14 13:35:28 -08001338 SetConstant(cu, mir->ssa_rep->defs[0], vB << 16);
Bill Buzbeea114add2012-05-03 15:00:40 -07001339 break;
buzbeebff24652012-05-06 16:22:05 -07001340 case Instruction::CONST_WIDE_16:
1341 case Instruction::CONST_WIDE_32:
buzbee4ef3e452012-12-14 13:35:28 -08001342 SetConstantWide(cu, mir->ssa_rep->defs[0], static_cast<int64_t>(vB));
buzbeebff24652012-05-06 16:22:05 -07001343 break;
1344 case Instruction::CONST_WIDE:
buzbee4ef3e452012-12-14 13:35:28 -08001345 SetConstantWide(cu, mir->ssa_rep->defs[0],d_insn->vB_wide);
buzbeebff24652012-05-06 16:22:05 -07001346 break;
1347 case Instruction::CONST_WIDE_HIGH16:
buzbee4ef3e452012-12-14 13:35:28 -08001348 SetConstantWide(cu, mir->ssa_rep->defs[0], static_cast<int64_t>(vB) << 48);
buzbeebff24652012-05-06 16:22:05 -07001349 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001350 default:
1351 break;
buzbeebff24652012-05-06 16:22:05 -07001352 }
buzbee2cfc6392012-05-07 14:51:40 -07001353 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001354 /* Handle instructions that set up constants directly */
buzbeefa57c472012-11-21 12:06:18 -08001355 } else if (df_attributes & DF_IS_MOVE) {
buzbee2cfc6392012-05-07 14:51:40 -07001356 int i;
buzbee67bf8852011-08-17 17:51:35 -07001357
buzbeefa57c472012-11-21 12:06:18 -08001358 for (i = 0; i < mir->ssa_rep->num_uses; i++) {
1359 if (!IsBitSet(is_constant_v, mir->ssa_rep->uses[i])) break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001360 }
1361 /* Move a register holding a constant to another register */
buzbeefa57c472012-11-21 12:06:18 -08001362 if (i == mir->ssa_rep->num_uses) {
1363 SetConstant(cu, mir->ssa_rep->defs[0],
1364 cu->constant_values[mir->ssa_rep->uses[0]]);
1365 if (df_attributes & DF_A_WIDE) {
1366 SetConstant(cu, mir->ssa_rep->defs[1],
1367 cu->constant_values[mir->ssa_rep->uses[1]]);
buzbee67bf8852011-08-17 17:51:35 -07001368 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001369 }
buzbee4ef3e452012-12-14 13:35:28 -08001370 } else if (df_attributes & DF_NULL_TRANSFER_N) {
1371 /*
1372 * Mark const sregs that appear in merges. Need to flush those to home location.
1373 * TUNING: instead of flushing on def, we could insert a flush on the appropriate
1374 * edge[s].
1375 */
1376 DCHECK_EQ(static_cast<int32_t>(d_insn->opcode), kMirOpPhi);
1377 for (int i = 0; i < mir->ssa_rep->num_uses; i++) {
1378 if (IsConst(cu, mir->ssa_rep->uses[i])) {
1379 SetBit(cu, cu->must_flush_constant_v, mir->ssa_rep->uses[i]);
1380 }
1381 }
buzbee67bf8852011-08-17 17:51:35 -07001382 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001383 }
1384 /* TODO: implement code to handle arithmetic operations */
1385 return true;
buzbee67bf8852011-08-17 17:51:35 -07001386}
1387
1388/* Setup the basic data structures for SSA conversion */
buzbeefa57c472012-11-21 12:06:18 -08001389void CompilerInitializeSSAConversion(CompilationUnit* cu)
buzbee67bf8852011-08-17 17:51:35 -07001390{
Bill Buzbeea114add2012-05-03 15:00:40 -07001391 int i;
buzbeefa57c472012-11-21 12:06:18 -08001392 int num_dalvik_reg = cu->num_dalvik_registers;
buzbee67bf8852011-08-17 17:51:35 -07001393
buzbeefa57c472012-11-21 12:06:18 -08001394 cu->ssa_base_vregs =
1395 static_cast<GrowableList*>(NewMem(cu, sizeof(GrowableList), false, kAllocDFInfo));
1396 cu->ssa_subscripts =
1397 static_cast<GrowableList*>(NewMem(cu, sizeof(GrowableList), false, kAllocDFInfo));
1398 cu->ssa_strings =
1399 static_cast<GrowableList*>(NewMem(cu, sizeof(GrowableList), false, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001400 // Create the ssa mappings, estimating the max size
buzbeefa57c472012-11-21 12:06:18 -08001401 CompilerInitGrowableList(cu, cu->ssa_base_vregs,
1402 num_dalvik_reg + cu->def_count + 128,
Bill Buzbeea114add2012-05-03 15:00:40 -07001403 kListSSAtoDalvikMap);
buzbeefa57c472012-11-21 12:06:18 -08001404 CompilerInitGrowableList(cu, cu->ssa_subscripts,
1405 num_dalvik_reg + cu->def_count + 128,
Bill Buzbeea114add2012-05-03 15:00:40 -07001406 kListSSAtoDalvikMap);
buzbeefa57c472012-11-21 12:06:18 -08001407 CompilerInitGrowableList(cu, cu->ssa_strings,
1408 num_dalvik_reg + cu->def_count + 128,
buzbee2cfc6392012-05-07 14:51:40 -07001409 kListSSAtoDalvikMap);
Bill Buzbeea114add2012-05-03 15:00:40 -07001410 /*
1411 * Initial number of SSA registers is equal to the number of Dalvik
1412 * registers.
1413 */
buzbeefa57c472012-11-21 12:06:18 -08001414 cu->num_ssa_regs = num_dalvik_reg;
buzbee67bf8852011-08-17 17:51:35 -07001415
Bill Buzbeea114add2012-05-03 15:00:40 -07001416 /*
buzbeefa57c472012-11-21 12:06:18 -08001417 * Initialize the SSA2Dalvik map list. For the first num_dalvik_reg elements,
Bill Buzbeea114add2012-05-03 15:00:40 -07001418 * the subscript is 0 so we use the ENCODE_REG_SUB macro to encode the value
1419 * into "(0 << 16) | i"
1420 */
buzbeefa57c472012-11-21 12:06:18 -08001421 for (i = 0; i < num_dalvik_reg; i++) {
1422 InsertGrowableList(cu, cu->ssa_base_vregs, i);
1423 InsertGrowableList(cu, cu->ssa_subscripts, 0);
1424 std::string ssa_name = GetSSAName(cu, i);
1425 char* name = static_cast<char*>(NewMem(cu, ssa_name.length() + 1, true, kAllocDFInfo));
1426 strncpy(name, ssa_name.c_str(), ssa_name.length() + 1);
1427 InsertGrowableList(cu, cu->ssa_strings, reinterpret_cast<uintptr_t>(name));
Bill Buzbeea114add2012-05-03 15:00:40 -07001428 }
buzbee67bf8852011-08-17 17:51:35 -07001429
Bill Buzbeea114add2012-05-03 15:00:40 -07001430 /*
1431 * Initialize the DalvikToSSAMap map. There is one entry for each
1432 * Dalvik register, and the SSA names for those are the same.
1433 */
buzbeefa57c472012-11-21 12:06:18 -08001434 cu->vreg_to_ssa_map =
1435 static_cast<int*>(NewMem(cu, sizeof(int) * num_dalvik_reg, false, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001436 /* Keep track of the higest def for each dalvik reg */
buzbeefa57c472012-11-21 12:06:18 -08001437 cu->ssa_last_defs =
1438 static_cast<int*>(NewMem(cu, sizeof(int) * num_dalvik_reg, false, kAllocDFInfo));
buzbeef0cde542011-09-13 14:55:02 -07001439
buzbeefa57c472012-11-21 12:06:18 -08001440 for (i = 0; i < num_dalvik_reg; i++) {
1441 cu->vreg_to_ssa_map[i] = i;
1442 cu->ssa_last_defs[i] = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -07001443 }
buzbee67bf8852011-08-17 17:51:35 -07001444
Bill Buzbeea114add2012-05-03 15:00:40 -07001445 /* Add ssa reg for Method* */
buzbeefa57c472012-11-21 12:06:18 -08001446 cu->method_sreg = AddNewSReg(cu, SSA_METHOD_BASEREG);
buzbeee1965672012-03-11 18:39:19 -07001447
Bill Buzbeea114add2012-05-03 15:00:40 -07001448 /*
1449 * Allocate the BasicBlockDataFlow structure for the entry and code blocks
1450 */
1451 GrowableListIterator iterator;
buzbee67bf8852011-08-17 17:51:35 -07001452
buzbeefa57c472012-11-21 12:06:18 -08001453 GrowableListIteratorInit(&cu->block_list, &iterator);
buzbee67bf8852011-08-17 17:51:35 -07001454
Bill Buzbeea114add2012-05-03 15:00:40 -07001455 while (true) {
buzbee52a77fc2012-11-20 19:50:46 -08001456 BasicBlock* bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iterator));
Bill Buzbeea114add2012-05-03 15:00:40 -07001457 if (bb == NULL) break;
1458 if (bb->hidden == true) continue;
buzbeefa57c472012-11-21 12:06:18 -08001459 if (bb->block_type == kDalvikByteCode ||
1460 bb->block_type == kEntryBlock ||
1461 bb->block_type == kExitBlock) {
1462 bb->data_flow_info = static_cast<BasicBlockDataFlow*>(NewMem(cu, sizeof(BasicBlockDataFlow),
buzbeecbd6d442012-11-17 14:11:25 -08001463 true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07001464 }
1465 }
buzbee67bf8852011-08-17 17:51:35 -07001466}
1467
1468/* Clear the visited flag for each BB */
buzbeefa57c472012-11-21 12:06:18 -08001469bool ClearVisitedFlag(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee67bf8852011-08-17 17:51:35 -07001470{
Bill Buzbeea114add2012-05-03 15:00:40 -07001471 bb->visited = false;
1472 return true;
buzbee67bf8852011-08-17 17:51:35 -07001473}
1474
buzbeefa57c472012-11-21 12:06:18 -08001475void DataFlowAnalysisDispatcher(CompilationUnit* cu,
Bill Buzbeea114add2012-05-03 15:00:40 -07001476 bool (*func)(CompilationUnit*, BasicBlock*),
buzbeefa57c472012-11-21 12:06:18 -08001477 DataFlowAnalysisMode dfa_mode,
1478 bool is_iterative)
buzbee67bf8852011-08-17 17:51:35 -07001479{
Bill Buzbeea114add2012-05-03 15:00:40 -07001480 bool change = true;
buzbee67bf8852011-08-17 17:51:35 -07001481
Bill Buzbeea114add2012-05-03 15:00:40 -07001482 while (change) {
1483 change = false;
buzbee67bf8852011-08-17 17:51:35 -07001484
buzbeefa57c472012-11-21 12:06:18 -08001485 switch (dfa_mode) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001486 /* Scan all blocks and perform the operations specified in func */
1487 case kAllNodes:
1488 {
1489 GrowableListIterator iterator;
buzbeefa57c472012-11-21 12:06:18 -08001490 GrowableListIteratorInit(&cu->block_list, &iterator);
Bill Buzbeea114add2012-05-03 15:00:40 -07001491 while (true) {
buzbee52a77fc2012-11-20 19:50:46 -08001492 BasicBlock* bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iterator));
Bill Buzbeea114add2012-05-03 15:00:40 -07001493 if (bb == NULL) break;
1494 if (bb->hidden == true) continue;
buzbeefa57c472012-11-21 12:06:18 -08001495 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001496 }
buzbee67bf8852011-08-17 17:51:35 -07001497 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001498 break;
1499 /* Scan reachable blocks and perform the ops specified in func. */
1500 case kReachableNodes:
1501 {
buzbeefa57c472012-11-21 12:06:18 -08001502 int num_reachable_blocks = cu->num_reachable_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -07001503 int idx;
buzbeefa57c472012-11-21 12:06:18 -08001504 const GrowableList *block_list = &cu->block_list;
Bill Buzbeea114add2012-05-03 15:00:40 -07001505
buzbeefa57c472012-11-21 12:06:18 -08001506 for (idx = 0; idx < num_reachable_blocks; idx++) {
1507 int block_idx = cu->dfs_order.elem_list[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001508 BasicBlock* bb =
buzbeefa57c472012-11-21 12:06:18 -08001509 reinterpret_cast<BasicBlock*>( GrowableListGetElement(block_list, block_idx));
1510 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001511 }
1512 }
1513 break;
1514
1515 /* Scan reachable blocks by pre-order dfs and invoke func on each. */
1516 case kPreOrderDFSTraversal:
1517 {
buzbeefa57c472012-11-21 12:06:18 -08001518 int num_reachable_blocks = cu->num_reachable_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -07001519 int idx;
buzbeefa57c472012-11-21 12:06:18 -08001520 const GrowableList *block_list = &cu->block_list;
Bill Buzbeea114add2012-05-03 15:00:40 -07001521
buzbeefa57c472012-11-21 12:06:18 -08001522 for (idx = 0; idx < num_reachable_blocks; idx++) {
1523 int dfs_idx = cu->dfs_order.elem_list[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001524 BasicBlock* bb =
buzbeefa57c472012-11-21 12:06:18 -08001525 reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, dfs_idx));
1526 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001527 }
1528 }
1529 break;
1530 /* Scan reachable blocks post-order dfs and invoke func on each. */
1531 case kPostOrderDFSTraversal:
1532 {
buzbeefa57c472012-11-21 12:06:18 -08001533 int num_reachable_blocks = cu->num_reachable_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -07001534 int idx;
buzbeefa57c472012-11-21 12:06:18 -08001535 const GrowableList *block_list = &cu->block_list;
Bill Buzbeea114add2012-05-03 15:00:40 -07001536
buzbeefa57c472012-11-21 12:06:18 -08001537 for (idx = num_reachable_blocks - 1; idx >= 0; idx--) {
1538 int dfs_idx = cu->dfs_order.elem_list[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001539 BasicBlock* bb =
buzbeefa57c472012-11-21 12:06:18 -08001540 reinterpret_cast<BasicBlock *>( GrowableListGetElement(block_list, dfs_idx));
1541 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001542 }
1543 }
1544 break;
1545 /* Scan reachable post-order dom tree and invoke func on each. */
1546 case kPostOrderDOMTraversal:
1547 {
buzbeefa57c472012-11-21 12:06:18 -08001548 int num_reachable_blocks = cu->num_reachable_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -07001549 int idx;
buzbeefa57c472012-11-21 12:06:18 -08001550 const GrowableList *block_list = &cu->block_list;
Bill Buzbeea114add2012-05-03 15:00:40 -07001551
buzbeefa57c472012-11-21 12:06:18 -08001552 for (idx = 0; idx < num_reachable_blocks; idx++) {
1553 int dom_idx = cu->dom_post_order_traversal.elem_list[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001554 BasicBlock* bb =
buzbeefa57c472012-11-21 12:06:18 -08001555 reinterpret_cast<BasicBlock*>( GrowableListGetElement(block_list, dom_idx));
1556 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001557 }
1558 }
1559 break;
1560 /* Scan reachable blocks reverse post-order dfs, invoke func on each */
1561 case kReversePostOrderTraversal:
1562 {
buzbeefa57c472012-11-21 12:06:18 -08001563 int num_reachable_blocks = cu->num_reachable_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -07001564 int idx;
buzbeefa57c472012-11-21 12:06:18 -08001565 const GrowableList *block_list = &cu->block_list;
Bill Buzbeea114add2012-05-03 15:00:40 -07001566
buzbeefa57c472012-11-21 12:06:18 -08001567 for (idx = num_reachable_blocks - 1; idx >= 0; idx--) {
1568 int rev_idx = cu->dfs_post_order.elem_list[idx];
buzbeecbd6d442012-11-17 14:11:25 -08001569 BasicBlock* bb =
buzbeefa57c472012-11-21 12:06:18 -08001570 reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, rev_idx));
1571 change |= (*func)(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001572 }
1573 }
1574 break;
1575 default:
buzbeefa57c472012-11-21 12:06:18 -08001576 LOG(FATAL) << "Unknown traversal mode: " << dfa_mode;
buzbee67bf8852011-08-17 17:51:35 -07001577 }
buzbeefa57c472012-11-21 12:06:18 -08001578 /* If is_iterative is false, exit the loop after the first iteration */
1579 change &= is_iterative;
Bill Buzbeea114add2012-05-03 15:00:40 -07001580 }
buzbee67bf8852011-08-17 17:51:35 -07001581}
buzbee43a36422011-09-14 14:00:13 -07001582
buzbeee1965672012-03-11 18:39:19 -07001583/* Advance to next strictly dominated MIR node in an extended basic block */
buzbee2502e002012-12-31 16:05:53 -08001584static MIR* AdvanceMIR(CompilationUnit* cu, BasicBlock** p_bb, MIR* mir)
1585{
buzbeefa57c472012-11-21 12:06:18 -08001586 BasicBlock* bb = *p_bb;
Bill Buzbeea114add2012-05-03 15:00:40 -07001587 if (mir != NULL) {
1588 mir = mir->next;
1589 if (mir == NULL) {
buzbeefa57c472012-11-21 12:06:18 -08001590 bb = bb->fall_through;
1591 if ((bb == NULL) || bb->predecessors->num_used != 1) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001592 mir = NULL;
1593 } else {
buzbeefa57c472012-11-21 12:06:18 -08001594 *p_bb = bb;
1595 mir = bb->first_mir_insn;
Bill Buzbeea114add2012-05-03 15:00:40 -07001596 }
buzbeee1965672012-03-11 18:39:19 -07001597 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001598 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001599 return mir;
buzbeee1965672012-03-11 18:39:19 -07001600}
1601
buzbeefc9e6fa2012-03-23 15:14:29 -07001602/*
1603 * To be used at an invoke mir. If the logically next mir node represents
1604 * a move-result, return it. Else, return NULL. If a move-result exists,
1605 * it is required to immediately follow the invoke with no intervening
1606 * opcodes or incoming arcs. However, if the result of the invoke is not
1607 * used, a move-result may not be present.
1608 */
buzbeefa57c472012-11-21 12:06:18 -08001609MIR* FindMoveResult(CompilationUnit* cu, BasicBlock* bb, MIR* mir)
buzbeefc9e6fa2012-03-23 15:14:29 -07001610{
Bill Buzbeea114add2012-05-03 15:00:40 -07001611 BasicBlock* tbb = bb;
buzbee2502e002012-12-31 16:05:53 -08001612 mir = AdvanceMIR(cu, &tbb, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -07001613 while (mir != NULL) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001614 int opcode = mir->dalvikInsn.opcode;
buzbee15bf9802012-06-12 17:49:27 -07001615 if ((mir->dalvikInsn.opcode == Instruction::MOVE_RESULT) ||
buzbee52ed7762012-06-13 23:43:14 -07001616 (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) ||
buzbee15bf9802012-06-12 17:49:27 -07001617 (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_WIDE)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001618 break;
1619 }
1620 // Keep going if pseudo op, otherwise terminate
Bill Buzbeec9f40dd2012-08-15 11:35:25 -07001621 if (opcode < kNumPackedOpcodes) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001622 mir = NULL;
1623 } else {
buzbee2502e002012-12-31 16:05:53 -08001624 mir = AdvanceMIR(cu, &tbb, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -07001625 }
1626 }
1627 return mir;
buzbeefc9e6fa2012-03-23 15:14:29 -07001628}
1629
buzbee2502e002012-12-31 16:05:53 -08001630static BasicBlock* NextDominatedBlock(CompilationUnit* cu, BasicBlock* bb)
buzbee239c4e72012-03-16 08:42:29 -07001631{
buzbee2502e002012-12-31 16:05:53 -08001632 DCHECK((bb->block_type == kEntryBlock) || (bb->block_type == kDalvikByteCode)
1633 || (bb->block_type == kExitBlock));
1634 bb = bb->fall_through;
1635 if (bb == NULL || (bb->predecessors->num_used != 1)) {
1636 return NULL;
Bill Buzbeea114add2012-05-03 15:00:40 -07001637 }
buzbee2502e002012-12-31 16:05:53 -08001638 DCHECK((bb->block_type == kDalvikByteCode) || (bb->block_type == kExitBlock));
1639 return bb;
buzbee239c4e72012-03-16 08:42:29 -07001640}
1641
buzbee2502e002012-12-31 16:05:53 -08001642/* Do some MIR-level extended basic block optimizations */
buzbeefa57c472012-11-21 12:06:18 -08001643static bool BasicBlockOpt(CompilationUnit* cu, BasicBlock* bb)
buzbeee1965672012-03-11 18:39:19 -07001644{
buzbeefa57c472012-11-21 12:06:18 -08001645 int num_temps = 0;
buzbee2502e002012-12-31 16:05:53 -08001646 BBOpt bb_opt(cu);
1647 while (bb != NULL) {
1648 for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
1649 // TUNING: use the returned value number for CSE.
1650 bb_opt.GetValueNumber(mir);
1651 // Look for interesting opcodes, skip otherwise
1652 Instruction::Code opcode = mir->dalvikInsn.opcode;
1653 switch (opcode) {
1654 case Instruction::CMPL_FLOAT:
1655 case Instruction::CMPL_DOUBLE:
1656 case Instruction::CMPG_FLOAT:
1657 case Instruction::CMPG_DOUBLE:
1658 case Instruction::CMP_LONG:
1659 if (cu->gen_bitcode) {
1660 // Bitcode doesn't allow this optimization.
1661 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001662 }
buzbee2502e002012-12-31 16:05:53 -08001663 if (mir->next != NULL) {
1664 MIR* mir_next = mir->next;
1665 Instruction::Code br_opcode = mir_next->dalvikInsn.opcode;
1666 ConditionCode ccode = kCondNv;
1667 switch(br_opcode) {
1668 case Instruction::IF_EQZ:
1669 ccode = kCondEq;
Bill Buzbeea114add2012-05-03 15:00:40 -07001670 break;
buzbee2502e002012-12-31 16:05:53 -08001671 case Instruction::IF_NEZ:
1672 ccode = kCondNe;
Bill Buzbeea114add2012-05-03 15:00:40 -07001673 break;
buzbee2502e002012-12-31 16:05:53 -08001674 case Instruction::IF_LTZ:
1675 ccode = kCondLt;
Bill Buzbeea114add2012-05-03 15:00:40 -07001676 break;
buzbee2502e002012-12-31 16:05:53 -08001677 case Instruction::IF_GEZ:
1678 ccode = kCondGe;
Bill Buzbeea114add2012-05-03 15:00:40 -07001679 break;
buzbee2502e002012-12-31 16:05:53 -08001680 case Instruction::IF_GTZ:
1681 ccode = kCondGt;
Bill Buzbeea114add2012-05-03 15:00:40 -07001682 break;
buzbee2502e002012-12-31 16:05:53 -08001683 case Instruction::IF_LEZ:
1684 ccode = kCondLe;
1685 break;
1686 default:
1687 break;
Bill Buzbeea114add2012-05-03 15:00:40 -07001688 }
buzbee2502e002012-12-31 16:05:53 -08001689 // Make sure result of cmp is used by next insn and nowhere else
1690 if ((ccode != kCondNv) &&
1691 (mir->ssa_rep->defs[0] == mir_next->ssa_rep->uses[0]) &&
1692 (GetSSAUseCount(cu, mir->ssa_rep->defs[0]) == 1)) {
1693 mir_next->dalvikInsn.arg[0] = ccode;
1694 switch(opcode) {
1695 case Instruction::CMPL_FLOAT:
1696 mir_next->dalvikInsn.opcode =
1697 static_cast<Instruction::Code>(kMirOpFusedCmplFloat);
1698 break;
1699 case Instruction::CMPL_DOUBLE:
1700 mir_next->dalvikInsn.opcode =
1701 static_cast<Instruction::Code>(kMirOpFusedCmplDouble);
1702 break;
1703 case Instruction::CMPG_FLOAT:
1704 mir_next->dalvikInsn.opcode =
1705 static_cast<Instruction::Code>(kMirOpFusedCmpgFloat);
1706 break;
1707 case Instruction::CMPG_DOUBLE:
1708 mir_next->dalvikInsn.opcode =
1709 static_cast<Instruction::Code>(kMirOpFusedCmpgDouble);
1710 break;
1711 case Instruction::CMP_LONG:
1712 mir_next->dalvikInsn.opcode =
1713 static_cast<Instruction::Code>(kMirOpFusedCmpLong);
1714 break;
1715 default: LOG(ERROR) << "Unexpected opcode: " << opcode;
1716 }
1717 mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
1718 mir_next->ssa_rep->num_uses = mir->ssa_rep->num_uses;
1719 mir_next->ssa_rep->uses = mir->ssa_rep->uses;
1720 mir_next->ssa_rep->fp_use = mir->ssa_rep->fp_use;
1721 mir_next->ssa_rep->num_defs = 0;
1722 mir->ssa_rep->num_uses = 0;
1723 mir->ssa_rep->num_defs = 0;
1724 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001725 }
buzbee2502e002012-12-31 16:05:53 -08001726 break;
buzbee4ef3e452012-12-14 13:35:28 -08001727 case Instruction::GOTO:
1728 case Instruction::GOTO_16:
1729 case Instruction::GOTO_32:
1730 case Instruction::IF_EQ:
1731 case Instruction::IF_NE:
1732 case Instruction::IF_LT:
1733 case Instruction::IF_GE:
1734 case Instruction::IF_GT:
1735 case Instruction::IF_LE:
1736 case Instruction::IF_EQZ:
1737 case Instruction::IF_NEZ:
1738 case Instruction::IF_LTZ:
1739 case Instruction::IF_GEZ:
1740 case Instruction::IF_GTZ:
1741 case Instruction::IF_LEZ:
1742 if (bb->taken->dominates_return) {
1743 mir->optimization_flags |= MIR_IGNORE_SUSPEND_CHECK;
1744 if (cu->verbose) {
1745 LOG(INFO) << "Suppressed suspend check at 0x" << std::hex << mir->offset;
1746 }
1747 }
1748 break;
buzbee2502e002012-12-31 16:05:53 -08001749 default:
1750 break;
1751 }
buzbeee1965672012-03-11 18:39:19 -07001752 }
buzbee2502e002012-12-31 16:05:53 -08001753 bb = NextDominatedBlock(cu, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07001754 }
buzbeee1965672012-03-11 18:39:19 -07001755
buzbeefa57c472012-11-21 12:06:18 -08001756 if (num_temps > cu->num_compiler_temps) {
1757 cu->num_compiler_temps = num_temps;
Bill Buzbeea114add2012-05-03 15:00:40 -07001758 }
1759 return true;
buzbeee1965672012-03-11 18:39:19 -07001760}
1761
buzbeefa57c472012-11-21 12:06:18 -08001762static bool NullCheckEliminationInit(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee43a36422011-09-14 14:00:13 -07001763{
buzbeefa57c472012-11-21 12:06:18 -08001764 if (bb->data_flow_info == NULL) return false;
1765 bb->data_flow_info->ending_null_check_v =
1766 AllocBitVector(cu, cu->num_ssa_regs, false, kBitMapNullCheck);
1767 ClearAllBits(bb->data_flow_info->ending_null_check_v);
Bill Buzbeea114add2012-05-03 15:00:40 -07001768 return true;
buzbee43a36422011-09-14 14:00:13 -07001769}
1770
buzbeed1643e42012-09-05 14:06:51 -07001771/* Collect stats on number of checks removed */
buzbeefa57c472012-11-21 12:06:18 -08001772static bool CountChecks( struct CompilationUnit* cu, struct BasicBlock* bb)
buzbeed1643e42012-09-05 14:06:51 -07001773{
buzbeefa57c472012-11-21 12:06:18 -08001774 if (bb->data_flow_info == NULL) return false;
buzbee28c9a832012-11-21 15:39:13 -08001775 for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeefa57c472012-11-21 12:06:18 -08001776 if (mir->ssa_rep == NULL) {
buzbeed1643e42012-09-05 14:06:51 -07001777 continue;
1778 }
buzbeefa57c472012-11-21 12:06:18 -08001779 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
1780 if (df_attributes & DF_HAS_NULL_CHKS) {
1781 cu->checkstats->null_checks++;
1782 if (mir->optimization_flags & MIR_IGNORE_NULL_CHECK) {
1783 cu->checkstats->null_checks_eliminated++;
buzbeed1643e42012-09-05 14:06:51 -07001784 }
1785 }
buzbeefa57c472012-11-21 12:06:18 -08001786 if (df_attributes & DF_HAS_RANGE_CHKS) {
1787 cu->checkstats->range_checks++;
1788 if (mir->optimization_flags & MIR_IGNORE_RANGE_CHECK) {
1789 cu->checkstats->range_checks_eliminated++;
buzbeed1643e42012-09-05 14:06:51 -07001790 }
1791 }
1792 }
1793 return false;
1794}
1795
buzbee0967a252012-09-14 10:43:54 -07001796/* Try to make common case the fallthrough path */
buzbeefa57c472012-11-21 12:06:18 -08001797static bool LayoutBlocks(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee0967a252012-09-14 10:43:54 -07001798{
1799 // TODO: For now, just looking for direct throws. Consider generalizing for profile feedback
buzbeefa57c472012-11-21 12:06:18 -08001800 if (!bb->explicit_throw) {
buzbee0967a252012-09-14 10:43:54 -07001801 return false;
1802 }
1803 BasicBlock* walker = bb;
1804 while (true) {
1805 // Check termination conditions
buzbeefa57c472012-11-21 12:06:18 -08001806 if ((walker->block_type == kEntryBlock) || (walker->predecessors->num_used != 1)) {
buzbee0967a252012-09-14 10:43:54 -07001807 break;
1808 }
1809 BasicBlock* prev = GET_ELEM_N(walker->predecessors, BasicBlock*, 0);
buzbeefa57c472012-11-21 12:06:18 -08001810 if (prev->conditional_branch) {
1811 if (prev->fall_through == walker) {
buzbee0967a252012-09-14 10:43:54 -07001812 // Already done - return
1813 break;
1814 }
1815 DCHECK_EQ(walker, prev->taken);
1816 // Got one. Flip it and exit
buzbeefa57c472012-11-21 12:06:18 -08001817 Instruction::Code opcode = prev->last_mir_insn->dalvikInsn.opcode;
buzbee0967a252012-09-14 10:43:54 -07001818 switch (opcode) {
1819 case Instruction::IF_EQ: opcode = Instruction::IF_NE; break;
1820 case Instruction::IF_NE: opcode = Instruction::IF_EQ; break;
1821 case Instruction::IF_LT: opcode = Instruction::IF_GE; break;
1822 case Instruction::IF_GE: opcode = Instruction::IF_LT; break;
1823 case Instruction::IF_GT: opcode = Instruction::IF_LE; break;
1824 case Instruction::IF_LE: opcode = Instruction::IF_GT; break;
1825 case Instruction::IF_EQZ: opcode = Instruction::IF_NEZ; break;
1826 case Instruction::IF_NEZ: opcode = Instruction::IF_EQZ; break;
1827 case Instruction::IF_LTZ: opcode = Instruction::IF_GEZ; break;
1828 case Instruction::IF_GEZ: opcode = Instruction::IF_LTZ; break;
1829 case Instruction::IF_GTZ: opcode = Instruction::IF_LEZ; break;
1830 case Instruction::IF_LEZ: opcode = Instruction::IF_GTZ; break;
buzbeecbd6d442012-11-17 14:11:25 -08001831 default: LOG(FATAL) << "Unexpected opcode " << opcode;
buzbee0967a252012-09-14 10:43:54 -07001832 }
buzbeefa57c472012-11-21 12:06:18 -08001833 prev->last_mir_insn->dalvikInsn.opcode = opcode;
1834 BasicBlock* t_bb = prev->taken;
1835 prev->taken = prev->fall_through;
1836 prev->fall_through = t_bb;
buzbee0967a252012-09-14 10:43:54 -07001837 break;
1838 }
1839 walker = prev;
1840 }
1841 return false;
1842}
1843
buzbeed1643e42012-09-05 14:06:51 -07001844/* Combine any basic blocks terminated by instructions that we now know can't throw */
buzbeefa57c472012-11-21 12:06:18 -08001845static bool CombineBlocks(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbeed1643e42012-09-05 14:06:51 -07001846{
1847 // Loop here to allow combining a sequence of blocks
1848 while (true) {
1849 // Check termination conditions
buzbeefa57c472012-11-21 12:06:18 -08001850 if ((bb->first_mir_insn == NULL)
1851 || (bb->data_flow_info == NULL)
1852 || (bb->block_type == kExceptionHandling)
1853 || (bb->block_type == kExitBlock)
1854 || (bb->block_type == kDead)
1855 || ((bb->taken == NULL) || (bb->taken->block_type != kExceptionHandling))
1856 || (bb->successor_block_list.block_list_type != kNotUsed)
1857 || (static_cast<int>(bb->last_mir_insn->dalvikInsn.opcode) != kMirOpCheck)) {
buzbeed1643e42012-09-05 14:06:51 -07001858 break;
1859 }
1860
1861 // Test the kMirOpCheck instruction
buzbeefa57c472012-11-21 12:06:18 -08001862 MIR* mir = bb->last_mir_insn;
buzbeed1643e42012-09-05 14:06:51 -07001863 // Grab the attributes from the paired opcode
buzbeefa57c472012-11-21 12:06:18 -08001864 MIR* throw_insn = mir->meta.throw_insn;
1865 int df_attributes = oat_data_flow_attributes[throw_insn->dalvikInsn.opcode];
1866 bool can_combine = true;
1867 if (df_attributes & DF_HAS_NULL_CHKS) {
1868 can_combine &= ((throw_insn->optimization_flags & MIR_IGNORE_NULL_CHECK) != 0);
buzbee0967a252012-09-14 10:43:54 -07001869 }
buzbeefa57c472012-11-21 12:06:18 -08001870 if (df_attributes & DF_HAS_RANGE_CHKS) {
1871 can_combine &= ((throw_insn->optimization_flags & MIR_IGNORE_RANGE_CHECK) != 0);
buzbee0967a252012-09-14 10:43:54 -07001872 }
buzbeefa57c472012-11-21 12:06:18 -08001873 if (!can_combine) {
buzbeed1643e42012-09-05 14:06:51 -07001874 break;
1875 }
1876 // OK - got one. Combine
buzbeefa57c472012-11-21 12:06:18 -08001877 BasicBlock* bb_next = bb->fall_through;
1878 DCHECK(!bb_next->catch_entry);
1879 DCHECK_EQ(bb_next->predecessors->num_used, 1U);
1880 MIR* t_mir = bb->last_mir_insn->prev;
buzbeed1643e42012-09-05 14:06:51 -07001881 // Overwrite the kOpCheck insn with the paired opcode
buzbeefa57c472012-11-21 12:06:18 -08001882 DCHECK_EQ(bb_next->first_mir_insn, throw_insn);
1883 *bb->last_mir_insn = *throw_insn;
1884 bb->last_mir_insn->prev = t_mir;
buzbeed1643e42012-09-05 14:06:51 -07001885 // Use the successor info from the next block
buzbeefa57c472012-11-21 12:06:18 -08001886 bb->successor_block_list = bb_next->successor_block_list;
buzbeed1643e42012-09-05 14:06:51 -07001887 // Use the ending block linkage from the next block
buzbeefa57c472012-11-21 12:06:18 -08001888 bb->fall_through = bb_next->fall_through;
1889 bb->taken->block_type = kDead; // Kill the unused exception block
1890 bb->taken = bb_next->taken;
buzbeed1643e42012-09-05 14:06:51 -07001891 // Include the rest of the instructions
buzbeefa57c472012-11-21 12:06:18 -08001892 bb->last_mir_insn = bb_next->last_mir_insn;
buzbeebbdd0532013-02-07 09:33:02 -08001893 /*
1894 * If lower-half of pair of blocks to combine contained a return, move the flag
1895 * to the newly combined block.
1896 */
1897 bb->terminated_by_return = bb_next->terminated_by_return;
buzbeed1643e42012-09-05 14:06:51 -07001898
1899 /*
1900 * NOTE: we aren't updating all dataflow info here. Should either make sure this pass
buzbeefa57c472012-11-21 12:06:18 -08001901 * happens after uses of i_dominated, dom_frontier or update the dataflow info here.
buzbeed1643e42012-09-05 14:06:51 -07001902 */
1903
buzbeefa57c472012-11-21 12:06:18 -08001904 // Kill bb_next and remap now-dead id to parent
1905 bb_next->block_type = kDead;
1906 cu->block_id_map.Overwrite(bb_next->id, bb->id);
buzbeed1643e42012-09-05 14:06:51 -07001907
1908 // Now, loop back and see if we can keep going
1909 }
1910 return false;
1911}
1912
buzbee43a36422011-09-14 14:00:13 -07001913/* Eliminate unnecessary null checks for a basic block. */
buzbeefa57c472012-11-21 12:06:18 -08001914static bool EliminateNullChecks( struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee43a36422011-09-14 14:00:13 -07001915{
buzbeefa57c472012-11-21 12:06:18 -08001916 if (bb->data_flow_info == NULL) return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07001917
1918 /*
1919 * Set initial state. Be conservative with catch
1920 * blocks and start with no assumptions about null check
1921 * status (except for "this").
1922 */
buzbeefa57c472012-11-21 12:06:18 -08001923 if ((bb->block_type == kEntryBlock) | bb->catch_entry) {
1924 ClearAllBits(cu->temp_ssa_register_v);
1925 if ((cu->access_flags & kAccStatic) == 0) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001926 // If non-static method, mark "this" as non-null
buzbeefa57c472012-11-21 12:06:18 -08001927 int this_reg = cu->num_dalvik_registers - cu->num_ins;
1928 SetBit(cu, cu->temp_ssa_register_v, this_reg);
Bill Buzbeea114add2012-05-03 15:00:40 -07001929 }
1930 } else {
1931 // Starting state is intesection of all incoming arcs
1932 GrowableListIterator iter;
buzbee52a77fc2012-11-20 19:50:46 -08001933 GrowableListIteratorInit(bb->predecessors, &iter);
buzbeefa57c472012-11-21 12:06:18 -08001934 BasicBlock* pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter));
1935 DCHECK(pred_bb != NULL);
1936 CopyBitVector(cu->temp_ssa_register_v,
1937 pred_bb->data_flow_info->ending_null_check_v);
Bill Buzbeea114add2012-05-03 15:00:40 -07001938 while (true) {
buzbeefa57c472012-11-21 12:06:18 -08001939 pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter));
1940 if (!pred_bb) break;
1941 if ((pred_bb->data_flow_info == NULL) ||
1942 (pred_bb->data_flow_info->ending_null_check_v == NULL)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001943 continue;
1944 }
buzbeefa57c472012-11-21 12:06:18 -08001945 IntersectBitVectors(cu->temp_ssa_register_v,
1946 cu->temp_ssa_register_v,
1947 pred_bb->data_flow_info->ending_null_check_v);
Bill Buzbeea114add2012-05-03 15:00:40 -07001948 }
1949 }
1950
1951 // Walk through the instruction in the block, updating as necessary
buzbee28c9a832012-11-21 15:39:13 -08001952 for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeefa57c472012-11-21 12:06:18 -08001953 if (mir->ssa_rep == NULL) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001954 continue;
1955 }
buzbeefa57c472012-11-21 12:06:18 -08001956 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
Bill Buzbeea114add2012-05-03 15:00:40 -07001957
1958 // Mark target of NEW* as non-null
buzbeefa57c472012-11-21 12:06:18 -08001959 if (df_attributes & DF_NON_NULL_DST) {
1960 SetBit(cu, cu->temp_ssa_register_v, mir->ssa_rep->defs[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -07001961 }
1962
1963 // Mark non-null returns from invoke-style NEW*
buzbeefa57c472012-11-21 12:06:18 -08001964 if (df_attributes & DF_NON_NULL_RET) {
1965 MIR* next_mir = mir->next;
Bill Buzbeea114add2012-05-03 15:00:40 -07001966 // Next should be an MOVE_RESULT_OBJECT
buzbeefa57c472012-11-21 12:06:18 -08001967 if (next_mir &&
1968 next_mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001969 // Mark as null checked
buzbeefa57c472012-11-21 12:06:18 -08001970 SetBit(cu, cu->temp_ssa_register_v, next_mir->ssa_rep->defs[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -07001971 } else {
buzbeefa57c472012-11-21 12:06:18 -08001972 if (next_mir) {
1973 LOG(WARNING) << "Unexpected opcode following new: " << next_mir->dalvikInsn.opcode;
1974 } else if (bb->fall_through) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001975 // Look in next basic block
buzbeefa57c472012-11-21 12:06:18 -08001976 struct BasicBlock* next_bb = bb->fall_through;
buzbee28c9a832012-11-21 15:39:13 -08001977 for (MIR* tmir = next_bb->first_mir_insn; tmir != NULL;
Bill Buzbeea114add2012-05-03 15:00:40 -07001978 tmir =tmir->next) {
buzbeecbd6d442012-11-17 14:11:25 -08001979 if (static_cast<int>(tmir->dalvikInsn.opcode) >= static_cast<int>(kMirOpFirst)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07001980 continue;
1981 }
1982 // First non-pseudo should be MOVE_RESULT_OBJECT
1983 if (tmir->dalvikInsn.opcode == Instruction::MOVE_RESULT_OBJECT) {
1984 // Mark as null checked
buzbeefa57c472012-11-21 12:06:18 -08001985 SetBit(cu, cu->temp_ssa_register_v, tmir->ssa_rep->defs[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -07001986 } else {
buzbeecbd6d442012-11-17 14:11:25 -08001987 LOG(WARNING) << "Unexpected op after new: " << tmir->dalvikInsn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07001988 }
1989 break;
1990 }
1991 }
1992 }
1993 }
buzbee5abfa3e2012-01-31 17:01:43 -08001994
buzbee43a36422011-09-14 14:00:13 -07001995 /*
Bill Buzbeea114add2012-05-03 15:00:40 -07001996 * Propagate nullcheck state on register copies (including
1997 * Phi pseudo copies. For the latter, nullcheck state is
1998 * the "and" of all the Phi's operands.
buzbee43a36422011-09-14 14:00:13 -07001999 */
buzbeefa57c472012-11-21 12:06:18 -08002000 if (df_attributes & (DF_NULL_TRANSFER_0 | DF_NULL_TRANSFER_N)) {
2001 int tgt_sreg = mir->ssa_rep->defs[0];
2002 int operands = (df_attributes & DF_NULL_TRANSFER_0) ? 1 :
2003 mir->ssa_rep->num_uses;
2004 bool null_checked = true;
Bill Buzbeea114add2012-05-03 15:00:40 -07002005 for (int i = 0; i < operands; i++) {
buzbeefa57c472012-11-21 12:06:18 -08002006 null_checked &= IsBitSet(cu->temp_ssa_register_v,
2007 mir->ssa_rep->uses[i]);
Bill Buzbeea114add2012-05-03 15:00:40 -07002008 }
buzbeefa57c472012-11-21 12:06:18 -08002009 if (null_checked) {
2010 SetBit(cu, cu->temp_ssa_register_v, tgt_sreg);
Bill Buzbeea114add2012-05-03 15:00:40 -07002011 }
buzbee43a36422011-09-14 14:00:13 -07002012 }
2013
Bill Buzbeea114add2012-05-03 15:00:40 -07002014 // Already nullchecked?
buzbeefa57c472012-11-21 12:06:18 -08002015 if ((df_attributes & DF_HAS_NULL_CHKS) && !(mir->optimization_flags & MIR_IGNORE_NULL_CHECK)) {
2016 int src_idx;
2017 if (df_attributes & DF_NULL_CHK_1) {
2018 src_idx = 1;
2019 } else if (df_attributes & DF_NULL_CHK_2) {
2020 src_idx = 2;
Bill Buzbeea114add2012-05-03 15:00:40 -07002021 } else {
buzbeefa57c472012-11-21 12:06:18 -08002022 src_idx = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -07002023 }
buzbeefa57c472012-11-21 12:06:18 -08002024 int src_sreg = mir->ssa_rep->uses[src_idx];
2025 if (IsBitSet(cu->temp_ssa_register_v, src_sreg)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002026 // Eliminate the null check
buzbeefa57c472012-11-21 12:06:18 -08002027 mir->optimization_flags |= MIR_IGNORE_NULL_CHECK;
Bill Buzbeea114add2012-05-03 15:00:40 -07002028 } else {
buzbeefa57c472012-11-21 12:06:18 -08002029 // Mark s_reg as null-checked
2030 SetBit(cu, cu->temp_ssa_register_v, src_sreg);
buzbee43a36422011-09-14 14:00:13 -07002031 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002032 }
2033 }
buzbee43a36422011-09-14 14:00:13 -07002034
Bill Buzbeea114add2012-05-03 15:00:40 -07002035 // Did anything change?
buzbeefa57c472012-11-21 12:06:18 -08002036 bool res = CompareBitVectors(bb->data_flow_info->ending_null_check_v,
2037 cu->temp_ssa_register_v);
Bill Buzbeea114add2012-05-03 15:00:40 -07002038 if (res) {
buzbeefa57c472012-11-21 12:06:18 -08002039 CopyBitVector(bb->data_flow_info->ending_null_check_v,
2040 cu->temp_ssa_register_v);
Bill Buzbeea114add2012-05-03 15:00:40 -07002041 }
2042 return res;
buzbee43a36422011-09-14 14:00:13 -07002043}
2044
buzbeefa57c472012-11-21 12:06:18 -08002045void NullCheckElimination(CompilationUnit *cu)
buzbee43a36422011-09-14 14:00:13 -07002046{
buzbeefa57c472012-11-21 12:06:18 -08002047 if (!(cu->disable_opt & (1 << kNullCheckElimination))) {
2048 DCHECK(cu->temp_ssa_register_v != NULL);
2049 DataFlowAnalysisDispatcher(cu, NullCheckEliminationInit, kAllNodes,
2050 false /* is_iterative */);
2051 DataFlowAnalysisDispatcher(cu, EliminateNullChecks,
Bill Buzbeea114add2012-05-03 15:00:40 -07002052 kPreOrderDFSTraversal,
buzbeefa57c472012-11-21 12:06:18 -08002053 true /* is_iterative */);
Bill Buzbeea114add2012-05-03 15:00:40 -07002054 }
buzbee43a36422011-09-14 14:00:13 -07002055}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -08002056
buzbeefa57c472012-11-21 12:06:18 -08002057void BasicBlockCombine(CompilationUnit* cu)
buzbeed1643e42012-09-05 14:06:51 -07002058{
buzbeefa57c472012-11-21 12:06:18 -08002059 DataFlowAnalysisDispatcher(cu, CombineBlocks, kPreOrderDFSTraversal, false);
buzbeed1643e42012-09-05 14:06:51 -07002060}
2061
buzbeefa57c472012-11-21 12:06:18 -08002062void CodeLayout(CompilationUnit* cu)
buzbee0967a252012-09-14 10:43:54 -07002063{
buzbeefa57c472012-11-21 12:06:18 -08002064 DataFlowAnalysisDispatcher(cu, LayoutBlocks, kAllNodes, false);
buzbee0967a252012-09-14 10:43:54 -07002065}
2066
buzbeefa57c472012-11-21 12:06:18 -08002067void DumpCheckStats(CompilationUnit *cu)
buzbeed1643e42012-09-05 14:06:51 -07002068{
buzbeecbd6d442012-11-17 14:11:25 -08002069 Checkstats* stats =
buzbeefa57c472012-11-21 12:06:18 -08002070 static_cast<Checkstats*>(NewMem(cu, sizeof(Checkstats), true, kAllocDFInfo));
2071 cu->checkstats = stats;
2072 DataFlowAnalysisDispatcher(cu, CountChecks, kAllNodes, false /* is_iterative */);
2073 if (stats->null_checks > 0) {
2074 float eliminated = static_cast<float>(stats->null_checks_eliminated);
2075 float checks = static_cast<float>(stats->null_checks);
2076 LOG(INFO) << "Null Checks: " << PrettyMethod(cu->method_idx, *cu->dex_file) << " "
2077 << stats->null_checks_eliminated << " of " << stats->null_checks << " -> "
buzbeecbd6d442012-11-17 14:11:25 -08002078 << (eliminated/checks) * 100.0 << "%";
buzbeed1643e42012-09-05 14:06:51 -07002079 }
buzbeefa57c472012-11-21 12:06:18 -08002080 if (stats->range_checks > 0) {
2081 float eliminated = static_cast<float>(stats->range_checks_eliminated);
2082 float checks = static_cast<float>(stats->range_checks);
2083 LOG(INFO) << "Range Checks: " << PrettyMethod(cu->method_idx, *cu->dex_file) << " "
2084 << stats->range_checks_eliminated << " of " << stats->range_checks << " -> "
buzbeecbd6d442012-11-17 14:11:25 -08002085 << (eliminated/checks) * 100.0 << "%";
buzbeed1643e42012-09-05 14:06:51 -07002086 }
2087}
2088
buzbee2502e002012-12-31 16:05:53 -08002089bool BuildExtendedBBList(struct CompilationUnit* cu, struct BasicBlock* bb)
2090{
2091 if (bb->visited) return false;
2092 if (!((bb->block_type == kEntryBlock) || (bb->block_type == kDalvikByteCode)
2093 || (bb->block_type == kExitBlock))) {
2094 // Ignore special blocks
2095 bb->visited = true;
2096 return false;
2097 }
2098 // Must be head of extended basic block.
2099 if (cu->verbose) {
2100 LOG(INFO) << "Extended bb head " << bb->id;
2101 }
buzbee4ef3e452012-12-14 13:35:28 -08002102 BasicBlock* start_bb = bb;
buzbee2502e002012-12-31 16:05:53 -08002103 cu->extended_basic_blocks.push_back(bb);
buzbeebbdd0532013-02-07 09:33:02 -08002104 bool terminated_by_return = false;
buzbee2502e002012-12-31 16:05:53 -08002105 // Visit blocks strictly dominated by this head.
2106 while (bb != NULL) {
2107 bb->visited = true;
buzbeebbdd0532013-02-07 09:33:02 -08002108 terminated_by_return |= bb->terminated_by_return;
buzbee2502e002012-12-31 16:05:53 -08002109 bb = NextDominatedBlock(cu, bb);
2110 if (cu->verbose && (bb != NULL)) {
2111 LOG(INFO) << "...added bb " << bb->id;
2112 }
2113 }
buzbeebbdd0532013-02-07 09:33:02 -08002114 if (terminated_by_return) {
buzbee4ef3e452012-12-14 13:35:28 -08002115 // This extended basic block contains a return, so mark all members.
2116 bb = start_bb;
2117 while (bb != NULL) {
2118 bb->dominates_return = true;
2119 bb = NextDominatedBlock(cu, bb);
2120 }
2121 }
buzbee2502e002012-12-31 16:05:53 -08002122 return false; // Not iterative - return value will be ignored
2123}
2124
buzbeefa57c472012-11-21 12:06:18 -08002125void BasicBlockOptimization(CompilationUnit *cu)
buzbeee1965672012-03-11 18:39:19 -07002126{
buzbeefa57c472012-11-21 12:06:18 -08002127 if (!(cu->disable_opt & (1 << kBBOpt))) {
2128 CompilerInitGrowableList(cu, &cu->compiler_temps, 6, kListMisc);
2129 DCHECK_EQ(cu->num_compiler_temps, 0);
buzbee2502e002012-12-31 16:05:53 -08002130 // Mark all blocks as not visited
2131 DataFlowAnalysisDispatcher(cu, ClearVisitedFlag,
buzbeefa57c472012-11-21 12:06:18 -08002132 kAllNodes, false /* is_iterative */);
buzbee2502e002012-12-31 16:05:53 -08002133 DataFlowAnalysisDispatcher(cu, BuildExtendedBBList,
2134 kPreOrderDFSTraversal,
2135 false /* is_iterative */);
2136 // Perform extended basic block optimizations.
2137 for (unsigned int i = 0; i < cu->extended_basic_blocks.size(); i++) {
2138 BasicBlockOpt(cu, cu->extended_basic_blocks[i]);
2139 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002140 }
buzbeee1965672012-03-11 18:39:19 -07002141}
2142
buzbeefa57c472012-11-21 12:06:18 -08002143static void AddLoopHeader(CompilationUnit* cu, BasicBlock* header,
2144 BasicBlock* back_edge)
buzbee239c4e72012-03-16 08:42:29 -07002145{
Bill Buzbeea114add2012-05-03 15:00:40 -07002146 GrowableListIterator iter;
buzbeefa57c472012-11-21 12:06:18 -08002147 GrowableListIteratorInit(&cu->loop_headers, &iter);
buzbee52a77fc2012-11-20 19:50:46 -08002148 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter));
2149 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002150 if (loop->header == header) {
buzbeefa57c472012-11-21 12:06:18 -08002151 InsertGrowableList(cu, &loop->incoming_back_edges,
2152 reinterpret_cast<uintptr_t>(back_edge));
Bill Buzbeea114add2012-05-03 15:00:40 -07002153 return;
buzbee239c4e72012-03-16 08:42:29 -07002154 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002155 }
buzbeefa57c472012-11-21 12:06:18 -08002156 LoopInfo* info = static_cast<LoopInfo*>(NewMem(cu, sizeof(LoopInfo), true, kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -07002157 info->header = header;
buzbeefa57c472012-11-21 12:06:18 -08002158 CompilerInitGrowableList(cu, &info->incoming_back_edges, 2, kListMisc);
2159 InsertGrowableList(cu, &info->incoming_back_edges, reinterpret_cast<uintptr_t>(back_edge));
2160 InsertGrowableList(cu, &cu->loop_headers, reinterpret_cast<uintptr_t>(info));
buzbee239c4e72012-03-16 08:42:29 -07002161}
2162
buzbeefa57c472012-11-21 12:06:18 -08002163static bool FindBackEdges(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee239c4e72012-03-16 08:42:29 -07002164{
buzbeefa57c472012-11-21 12:06:18 -08002165 if ((bb->data_flow_info == NULL) || (bb->last_mir_insn == NULL)) {
buzbee239c4e72012-03-16 08:42:29 -07002166 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07002167 }
buzbeefa57c472012-11-21 12:06:18 -08002168 Instruction::Code opcode = bb->last_mir_insn->dalvikInsn.opcode;
Ian Rogersa75a0132012-09-28 11:41:42 -07002169 if (Instruction::FlagsOf(opcode) & Instruction::kBranch) {
buzbeefa57c472012-11-21 12:06:18 -08002170 if (bb->taken && (bb->taken->start_offset <= bb->start_offset)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002171 DCHECK(bb->dominators != NULL);
buzbee52a77fc2012-11-20 19:50:46 -08002172 if (IsBitSet(bb->dominators, bb->taken->id)) {
buzbeefa57c472012-11-21 12:06:18 -08002173 if (cu->verbose) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002174 LOG(INFO) << "Loop backedge from 0x"
buzbeefa57c472012-11-21 12:06:18 -08002175 << std::hex << bb->last_mir_insn->offset
2176 << " to 0x" << std::hex << bb->taken->start_offset;
Bill Buzbeea114add2012-05-03 15:00:40 -07002177 }
buzbeefa57c472012-11-21 12:06:18 -08002178 AddLoopHeader(cu, bb->taken, bb);
Bill Buzbeea114add2012-05-03 15:00:40 -07002179 }
2180 }
2181 }
2182 return false;
buzbee239c4e72012-03-16 08:42:29 -07002183}
2184
buzbeefa57c472012-11-21 12:06:18 -08002185static void AddBlocksToLoop(CompilationUnit* cu, ArenaBitVector* blocks,
2186 BasicBlock* bb, int head_id)
buzbee239c4e72012-03-16 08:42:29 -07002187{
buzbeefa57c472012-11-21 12:06:18 -08002188 if (!IsBitSet(bb->dominators, head_id) ||
buzbee52a77fc2012-11-20 19:50:46 -08002189 IsBitSet(blocks, bb->id)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002190 return;
2191 }
buzbeefa57c472012-11-21 12:06:18 -08002192 SetBit(cu, blocks, bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -07002193 GrowableListIterator iter;
buzbee52a77fc2012-11-20 19:50:46 -08002194 GrowableListIteratorInit(bb->predecessors, &iter);
buzbeefa57c472012-11-21 12:06:18 -08002195 BasicBlock* pred_bb;
buzbee28c9a832012-11-21 15:39:13 -08002196 for (pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); pred_bb != NULL;
buzbeefa57c472012-11-21 12:06:18 -08002197 pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter))) {
2198 AddBlocksToLoop(cu, blocks, pred_bb, head_id);
Bill Buzbeea114add2012-05-03 15:00:40 -07002199 }
buzbee239c4e72012-03-16 08:42:29 -07002200}
2201
buzbeefa57c472012-11-21 12:06:18 -08002202static void DumpLoops(CompilationUnit *cu)
buzbee239c4e72012-03-16 08:42:29 -07002203{
Bill Buzbeea114add2012-05-03 15:00:40 -07002204 GrowableListIterator iter;
buzbeefa57c472012-11-21 12:06:18 -08002205 GrowableListIteratorInit(&cu->loop_headers, &iter);
buzbee52a77fc2012-11-20 19:50:46 -08002206 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter));
2207 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002208 LOG(INFO) << "Loop head block id " << loop->header->id
buzbeefa57c472012-11-21 12:06:18 -08002209 << ", offset 0x" << std::hex << loop->header->start_offset
2210 << ", Depth: " << loop->header->nesting_depth;
buzbee239c4e72012-03-16 08:42:29 -07002211 GrowableListIterator iter;
buzbeefa57c472012-11-21 12:06:18 -08002212 GrowableListIteratorInit(&loop->incoming_back_edges, &iter);
2213 BasicBlock* edge_bb;
buzbee28c9a832012-11-21 15:39:13 -08002214 for (edge_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); edge_bb != NULL;
buzbeefa57c472012-11-21 12:06:18 -08002215 edge_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter))) {
2216 LOG(INFO) << " Backedge block id " << edge_bb->id
2217 << ", offset 0x" << std::hex << edge_bb->start_offset;
2218 ArenaBitVectorIterator b_iter;
2219 BitVectorIteratorInit(loop->blocks, &b_iter);
2220 for (int bb_id = BitVectorIteratorNext(&b_iter); bb_id != -1;
2221 bb_id = BitVectorIteratorNext(&b_iter)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002222 BasicBlock *bb;
buzbeefa57c472012-11-21 12:06:18 -08002223 bb = reinterpret_cast<BasicBlock*>(GrowableListGetElement(&cu->block_list, bb_id));
Bill Buzbeea114add2012-05-03 15:00:40 -07002224 LOG(INFO) << " (" << bb->id << ", 0x" << std::hex
buzbeefa57c472012-11-21 12:06:18 -08002225 << bb->start_offset << ")";
Bill Buzbeea114add2012-05-03 15:00:40 -07002226 }
buzbee239c4e72012-03-16 08:42:29 -07002227 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002228 }
buzbee239c4e72012-03-16 08:42:29 -07002229}
2230
buzbeefa57c472012-11-21 12:06:18 -08002231void LoopDetection(CompilationUnit *cu)
buzbee239c4e72012-03-16 08:42:29 -07002232{
buzbeefa57c472012-11-21 12:06:18 -08002233 if (cu->disable_opt & (1 << kPromoteRegs)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002234 return;
2235 }
buzbeefa57c472012-11-21 12:06:18 -08002236 CompilerInitGrowableList(cu, &cu->loop_headers, 6, kListMisc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002237 // Find the loop headers
buzbeefa57c472012-11-21 12:06:18 -08002238 DataFlowAnalysisDispatcher(cu, FindBackEdges, kAllNodes, false /* is_iterative */);
Bill Buzbeea114add2012-05-03 15:00:40 -07002239 GrowableListIterator iter;
buzbeefa57c472012-11-21 12:06:18 -08002240 GrowableListIteratorInit(&cu->loop_headers, &iter);
Bill Buzbeea114add2012-05-03 15:00:40 -07002241 // Add blocks to each header
buzbee52a77fc2012-11-20 19:50:46 -08002242 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter));
buzbee28c9a832012-11-21 15:39:13 -08002243 loop != NULL; loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter))) {
buzbeefa57c472012-11-21 12:06:18 -08002244 loop->blocks = AllocBitVector(cu, cu->num_blocks, true,
Bill Buzbeea114add2012-05-03 15:00:40 -07002245 kBitMapMisc);
buzbeefa57c472012-11-21 12:06:18 -08002246 SetBit(cu, loop->blocks, loop->header->id);
buzbee239c4e72012-03-16 08:42:29 -07002247 GrowableListIterator iter;
buzbeefa57c472012-11-21 12:06:18 -08002248 GrowableListIteratorInit(&loop->incoming_back_edges, &iter);
2249 BasicBlock* edge_bb;
buzbee28c9a832012-11-21 15:39:13 -08002250 for (edge_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); edge_bb != NULL;
buzbeefa57c472012-11-21 12:06:18 -08002251 edge_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter))) {
2252 AddBlocksToLoop(cu, loop->blocks, edge_bb, loop->header->id);
buzbee239c4e72012-03-16 08:42:29 -07002253 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002254 }
2255 // Compute the nesting depth of each header
buzbeefa57c472012-11-21 12:06:18 -08002256 GrowableListIteratorInit(&cu->loop_headers, &iter);
buzbee52a77fc2012-11-20 19:50:46 -08002257 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter));
buzbee28c9a832012-11-21 15:39:13 -08002258 loop != NULL; loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter))) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002259 GrowableListIterator iter2;
buzbeefa57c472012-11-21 12:06:18 -08002260 GrowableListIteratorInit(&cu->loop_headers, &iter2);
Bill Buzbeea114add2012-05-03 15:00:40 -07002261 LoopInfo* loop2;
buzbee52a77fc2012-11-20 19:50:46 -08002262 for (loop2 = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter2));
buzbee28c9a832012-11-21 15:39:13 -08002263 loop2 != NULL; loop2 = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter2))) {
buzbee52a77fc2012-11-20 19:50:46 -08002264 if (IsBitSet(loop2->blocks, loop->header->id)) {
buzbeefa57c472012-11-21 12:06:18 -08002265 loop->header->nesting_depth++;
Bill Buzbeea114add2012-05-03 15:00:40 -07002266 }
buzbee239c4e72012-03-16 08:42:29 -07002267 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002268 }
2269 // Assign nesting depth to each block in all loops
buzbeefa57c472012-11-21 12:06:18 -08002270 GrowableListIteratorInit(&cu->loop_headers, &iter);
buzbee52a77fc2012-11-20 19:50:46 -08002271 for (LoopInfo* loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter));
2272 (loop != NULL); loop = reinterpret_cast<LoopInfo*>(GrowableListIteratorNext(&iter))) {
buzbeefa57c472012-11-21 12:06:18 -08002273 ArenaBitVectorIterator b_iter;
2274 BitVectorIteratorInit(loop->blocks, &b_iter);
2275 for (int bb_id = BitVectorIteratorNext(&b_iter); bb_id != -1;
2276 bb_id = BitVectorIteratorNext(&b_iter)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002277 BasicBlock *bb;
buzbeefa57c472012-11-21 12:06:18 -08002278 bb = reinterpret_cast<BasicBlock*>(GrowableListGetElement(&cu->block_list, bb_id));
2279 bb->nesting_depth = std::max(bb->nesting_depth,
2280 loop->header->nesting_depth);
buzbee239c4e72012-03-16 08:42:29 -07002281 }
Bill Buzbeea114add2012-05-03 15:00:40 -07002282 }
buzbeefa57c472012-11-21 12:06:18 -08002283 if (cu->verbose) {
2284 DumpLoops(cu);
Bill Buzbeea114add2012-05-03 15:00:40 -07002285 }
buzbee239c4e72012-03-16 08:42:29 -07002286}
2287
2288/*
buzbee9c044ce2012-03-18 13:24:07 -07002289 * This function will make a best guess at whether the invoke will
2290 * end up using Method*. It isn't critical to get it exactly right,
2291 * and attempting to do would involve more complexity than it's
2292 * worth.
2293 */
buzbeefa57c472012-11-21 12:06:18 -08002294static bool InvokeUsesMethodStar(CompilationUnit* cu, MIR* mir)
buzbee9c044ce2012-03-18 13:24:07 -07002295{
Bill Buzbeea114add2012-05-03 15:00:40 -07002296 InvokeType type;
2297 Instruction::Code opcode = mir->dalvikInsn.opcode;
2298 switch (opcode) {
2299 case Instruction::INVOKE_STATIC:
2300 case Instruction::INVOKE_STATIC_RANGE:
2301 type = kStatic;
2302 break;
2303 case Instruction::INVOKE_DIRECT:
2304 case Instruction::INVOKE_DIRECT_RANGE:
2305 type = kDirect;
2306 break;
2307 case Instruction::INVOKE_VIRTUAL:
2308 case Instruction::INVOKE_VIRTUAL_RANGE:
2309 type = kVirtual;
2310 break;
2311 case Instruction::INVOKE_INTERFACE:
2312 case Instruction::INVOKE_INTERFACE_RANGE:
2313 return false;
2314 case Instruction::INVOKE_SUPER_RANGE:
2315 case Instruction::INVOKE_SUPER:
2316 type = kSuper;
2317 break;
2318 default:
buzbeecbd6d442012-11-17 14:11:25 -08002319 LOG(WARNING) << "Unexpected invoke op: " << opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -07002320 return false;
2321 }
buzbeefa57c472012-11-21 12:06:18 -08002322 OatCompilationUnit m_unit(cu->class_loader, cu->class_linker,
TDYa127dc5daa02013-01-09 21:31:37 +08002323 *cu->dex_file, cu->code_item,
2324 cu->class_def_idx, cu->method_idx,
2325 cu->access_flags);
Bill Buzbeea114add2012-05-03 15:00:40 -07002326 // TODO: add a flag so we don't counts the stats for this twice
buzbeefa57c472012-11-21 12:06:18 -08002327 uint32_t dex_method_idx = mir->dalvikInsn.vB;
2328 int vtable_idx;
2329 uintptr_t direct_code;
2330 uintptr_t direct_method;
2331 bool fast_path =
2332 cu->compiler->ComputeInvokeInfo(dex_method_idx, &m_unit, type,
2333 vtable_idx, direct_code,
2334 direct_method) &&
Bill Buzbeea114add2012-05-03 15:00:40 -07002335 !SLOW_INVOKE_PATH;
2336 return (((type == kDirect) || (type == kStatic)) &&
buzbeefa57c472012-11-21 12:06:18 -08002337 fast_path && ((direct_code == 0) || (direct_method == 0)));
buzbee9c044ce2012-03-18 13:24:07 -07002338}
2339
2340/*
buzbee239c4e72012-03-16 08:42:29 -07002341 * Count uses, weighting by loop nesting depth. This code only
buzbeefa57c472012-11-21 12:06:18 -08002342 * counts explicitly used s_regs. A later phase will add implicit
buzbee239c4e72012-03-16 08:42:29 -07002343 * counts for things such as Method*, null-checked references, etc.
2344 */
buzbeefa57c472012-11-21 12:06:18 -08002345static bool CountUses(struct CompilationUnit* cu, struct BasicBlock* bb)
buzbee239c4e72012-03-16 08:42:29 -07002346{
buzbeefa57c472012-11-21 12:06:18 -08002347 if (bb->block_type != kDalvikByteCode) {
buzbee239c4e72012-03-16 08:42:29 -07002348 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -07002349 }
buzbeefa57c472012-11-21 12:06:18 -08002350 for (MIR* mir = bb->first_mir_insn; (mir != NULL); mir = mir->next) {
2351 if (mir->ssa_rep == NULL) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002352 continue;
2353 }
buzbeefa57c472012-11-21 12:06:18 -08002354 uint32_t weight = std::min(16U, static_cast<uint32_t>(bb->nesting_depth));
2355 for (int i = 0; i < mir->ssa_rep->num_uses; i++) {
2356 int s_reg = mir->ssa_rep->uses[i];
2357 DCHECK_LT(s_reg, static_cast<int>(cu->use_counts.num_used));
2358 cu->raw_use_counts.elem_list[s_reg]++;
2359 cu->use_counts.elem_list[s_reg] += (1 << weight);
Bill Buzbeea114add2012-05-03 15:00:40 -07002360 }
buzbeefa57c472012-11-21 12:06:18 -08002361 if (!(cu->disable_opt & (1 << kPromoteCompilerTemps))) {
2362 int df_attributes = oat_data_flow_attributes[mir->dalvikInsn.opcode];
Bill Buzbeea114add2012-05-03 15:00:40 -07002363 // Implicit use of Method* ? */
buzbeefa57c472012-11-21 12:06:18 -08002364 if (df_attributes & DF_UMS) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002365 /*
2366 * Some invokes will not use Method* - need to perform test similar
buzbee52a77fc2012-11-20 19:50:46 -08002367 * to that found in GenInvoke() to decide whether to count refs
Bill Buzbeea114add2012-05-03 15:00:40 -07002368 * for Method* on invoke-class opcodes.
buzbee52a77fc2012-11-20 19:50:46 -08002369 * TODO: refactor for common test here, save results for GenInvoke
Bill Buzbeea114add2012-05-03 15:00:40 -07002370 */
buzbeefa57c472012-11-21 12:06:18 -08002371 int uses_method_star = true;
2372 if ((df_attributes & (DF_FORMAT_35C | DF_FORMAT_3RC)) &&
2373 !(df_attributes & DF_NON_NULL_RET)) {
2374 uses_method_star &= InvokeUsesMethodStar(cu, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -07002375 }
buzbeefa57c472012-11-21 12:06:18 -08002376 if (uses_method_star) {
2377 cu->raw_use_counts.elem_list[cu->method_sreg]++;
2378 cu->use_counts.elem_list[cu->method_sreg] += (1 << weight);
Bill Buzbeea114add2012-05-03 15:00:40 -07002379 }
2380 }
2381 }
2382 }
2383 return false;
buzbee239c4e72012-03-16 08:42:29 -07002384}
2385
buzbeefa57c472012-11-21 12:06:18 -08002386void MethodUseCount(CompilationUnit *cu)
buzbee239c4e72012-03-16 08:42:29 -07002387{
buzbeefa57c472012-11-21 12:06:18 -08002388 CompilerInitGrowableList(cu, &cu->use_counts, cu->num_ssa_regs + 32, kListMisc);
2389 CompilerInitGrowableList(cu, &cu->raw_use_counts, cu->num_ssa_regs + 32, kListMisc);
Bill Buzbeea114add2012-05-03 15:00:40 -07002390 // Initialize list
buzbeefa57c472012-11-21 12:06:18 -08002391 for (int i = 0; i < cu->num_ssa_regs; i++) {
2392 InsertGrowableList(cu, &cu->use_counts, 0);
2393 InsertGrowableList(cu, &cu->raw_use_counts, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -07002394 }
buzbeefa57c472012-11-21 12:06:18 -08002395 if (cu->disable_opt & (1 << kPromoteRegs)) {
Bill Buzbeea114add2012-05-03 15:00:40 -07002396 return;
2397 }
buzbeefa57c472012-11-21 12:06:18 -08002398 DataFlowAnalysisDispatcher(cu, CountUses,
2399 kAllNodes, false /* is_iterative */);
buzbee239c4e72012-03-16 08:42:29 -07002400}
2401
Elliott Hughes11d1b0c2012-01-23 16:57:47 -08002402} // namespace art