buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #include "object_utils.h" |
| 18 | |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 19 | #include "../compiler_internals.h" |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 20 | #include "local_optimizations.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 21 | #include "codegen_util.h" |
| 22 | #include "ralloc_util.h" |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 23 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 24 | namespace art { |
| 25 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 26 | /* |
| 27 | * Target-independent code generation. Use only high-level |
| 28 | * load/store utilities here, or target-dependent genXX() handlers |
| 29 | * when necessary. |
| 30 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 31 | static bool CompileDalvikInstruction(CompilationUnit* cu, MIR* mir, BasicBlock* bb, |
| 32 | LIR* label_list) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 33 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 34 | Codegen* cg = cu->cg.get(); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 35 | bool res = false; // Assume success |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 36 | RegLocation rl_src[3]; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 37 | RegLocation rl_dest = GetBadLoc(); |
| 38 | RegLocation rl_result = GetBadLoc(); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 39 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 40 | int opt_flags = mir->optimization_flags; |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 41 | uint32_t vB = mir->dalvikInsn.vB; |
| 42 | uint32_t vC = mir->dalvikInsn.vC; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 43 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 44 | // Prep Src and Dest locations. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 45 | int next_sreg = 0; |
| 46 | int next_loc = 0; |
| 47 | int attrs = oat_data_flow_attributes[opcode]; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 48 | rl_src[0] = rl_src[1] = rl_src[2] = GetBadLoc(); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 49 | if (attrs & DF_UA) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 50 | if (attrs & DF_A_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 51 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
| 52 | next_sreg+= 2; |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 53 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 54 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
| 55 | next_sreg++; |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 56 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 57 | } |
| 58 | if (attrs & DF_UB) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 59 | if (attrs & DF_B_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 60 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
| 61 | next_sreg+= 2; |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 62 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 63 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
| 64 | next_sreg++; |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 65 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 66 | } |
| 67 | if (attrs & DF_UC) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 68 | if (attrs & DF_C_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 69 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 70 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 71 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 72 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 73 | } |
| 74 | if (attrs & DF_DA) { |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 75 | if (attrs & DF_A_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 76 | rl_dest = GetDestWide(cu, mir); |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 77 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 78 | rl_dest = GetDest(cu, mir); |
buzbee | bff2465 | 2012-05-06 16:22:05 -0700 | [diff] [blame] | 79 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 80 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | switch (opcode) { |
| 82 | case Instruction::NOP: |
| 83 | break; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 84 | |
Ian Rogers | 474b6da | 2012-09-25 00:20:38 -0700 | [diff] [blame] | 85 | case Instruction::MOVE_EXCEPTION: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 86 | cg->GenMoveException(cu, rl_dest); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 87 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 88 | case Instruction::RETURN_VOID: |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 89 | if (((cu->access_flags & kAccConstructor) != 0) && |
| 90 | cu->compiler->RequiresConstructorBarrier(Thread::Current(), cu->dex_file, |
| 91 | cu->class_def_idx)) { |
| 92 | cg->GenMemBarrier(cu, kStoreStore); |
| 93 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 94 | if (!(cu->attrs & METHOD_IS_LEAF)) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 95 | cg->GenSuspendTest(cu, opt_flags); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 96 | } |
| 97 | break; |
| 98 | |
| 99 | case Instruction::RETURN: |
| 100 | case Instruction::RETURN_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 101 | if (!(cu->attrs & METHOD_IS_LEAF)) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 102 | cg->GenSuspendTest(cu, opt_flags); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 103 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 104 | cg->StoreValue(cu, GetReturn(cu, cu->shorty[0] == 'F'), rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 105 | break; |
| 106 | |
| 107 | case Instruction::RETURN_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 108 | if (!(cu->attrs & METHOD_IS_LEAF)) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 109 | cg->GenSuspendTest(cu, opt_flags); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 110 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 111 | cg->StoreValueWide(cu, GetReturnWide(cu, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 112 | cu->shorty[0] == 'D'), rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 113 | break; |
| 114 | |
| 115 | case Instruction::MOVE_RESULT_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 116 | if (opt_flags & MIR_INLINED) |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 117 | break; // Nop - combined w/ previous invoke. |
| 118 | cg->StoreValueWide(cu, rl_dest, GetReturnWide(cu, rl_dest.fp)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case Instruction::MOVE_RESULT: |
| 122 | case Instruction::MOVE_RESULT_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 123 | if (opt_flags & MIR_INLINED) |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 124 | break; // Nop - combined w/ previous invoke. |
| 125 | cg->StoreValue(cu, rl_dest, GetReturn(cu, rl_dest.fp)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 126 | break; |
| 127 | |
| 128 | case Instruction::MOVE: |
| 129 | case Instruction::MOVE_OBJECT: |
| 130 | case Instruction::MOVE_16: |
| 131 | case Instruction::MOVE_OBJECT_16: |
| 132 | case Instruction::MOVE_FROM16: |
| 133 | case Instruction::MOVE_OBJECT_FROM16: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 134 | cg->StoreValue(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 135 | break; |
| 136 | |
| 137 | case Instruction::MOVE_WIDE: |
| 138 | case Instruction::MOVE_WIDE_16: |
| 139 | case Instruction::MOVE_WIDE_FROM16: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 140 | cg->StoreValueWide(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 141 | break; |
| 142 | |
| 143 | case Instruction::CONST: |
| 144 | case Instruction::CONST_4: |
| 145 | case Instruction::CONST_16: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 146 | rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 147 | cg->LoadConstantNoClobber(cu, rl_result.low_reg, vB); |
| 148 | cg->StoreValue(cu, rl_dest, rl_result); |
buzbee | 7da142f | 2012-11-29 16:33:42 -0800 | [diff] [blame] | 149 | if (vB == 0) { |
| 150 | cg->Workaround7250540(cu, rl_dest, rl_result.low_reg); |
| 151 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 152 | break; |
| 153 | |
| 154 | case Instruction::CONST_HIGH16: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 155 | rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 156 | cg->LoadConstantNoClobber(cu, rl_result.low_reg, vB << 16); |
| 157 | cg->StoreValue(cu, rl_dest, rl_result); |
buzbee | 7da142f | 2012-11-29 16:33:42 -0800 | [diff] [blame] | 158 | if (vB == 0) { |
| 159 | cg->Workaround7250540(cu, rl_dest, rl_result.low_reg); |
| 160 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 161 | break; |
| 162 | |
| 163 | case Instruction::CONST_WIDE_16: |
| 164 | case Instruction::CONST_WIDE_32: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 165 | rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 166 | cg->LoadConstantValueWide(cu, rl_result.low_reg, rl_result.high_reg, vB, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 167 | (vB & 0x80000000) ? -1 : 0); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 168 | cg->StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 169 | break; |
| 170 | |
| 171 | case Instruction::CONST_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 172 | rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 173 | cg->LoadConstantValueWide(cu, rl_result.low_reg, rl_result.high_reg, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 174 | mir->dalvikInsn.vB_wide & 0xffffffff, |
| 175 | (mir->dalvikInsn.vB_wide >> 32) & 0xffffffff); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 176 | cg->StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 177 | break; |
| 178 | |
| 179 | case Instruction::CONST_WIDE_HIGH16: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 180 | rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 181 | cg->LoadConstantValueWide(cu, rl_result.low_reg, rl_result.high_reg, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 182 | 0, vB << 16); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 183 | cg->StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 184 | break; |
| 185 | |
| 186 | case Instruction::MONITOR_ENTER: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 187 | cg->GenMonitorEnter(cu, opt_flags, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 188 | break; |
| 189 | |
| 190 | case Instruction::MONITOR_EXIT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 191 | cg->GenMonitorExit(cu, opt_flags, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 192 | break; |
| 193 | |
| 194 | case Instruction::CHECK_CAST: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 195 | cg->GenCheckCast(cu, vB, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 196 | break; |
| 197 | |
| 198 | case Instruction::INSTANCE_OF: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 199 | cg->GenInstanceof(cu, vC, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 200 | break; |
| 201 | |
| 202 | case Instruction::NEW_INSTANCE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 203 | cg->GenNewInstance(cu, vB, rl_dest); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 204 | break; |
| 205 | |
| 206 | case Instruction::THROW: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 207 | cg->GenThrow(cu, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 208 | break; |
| 209 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 210 | case Instruction::ARRAY_LENGTH: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 211 | int len_offset; |
| 212 | len_offset = Array::LengthOffset().Int32Value(); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 213 | rl_src[0] = cg->LoadValue(cu, rl_src[0], kCoreReg); |
| 214 | cg->GenNullCheck(cu, rl_src[0].s_reg_low, rl_src[0].low_reg, opt_flags); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 215 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 216 | cg->LoadWordDisp(cu, rl_src[0].low_reg, len_offset, rl_result.low_reg); |
| 217 | cg->StoreValue(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 218 | break; |
| 219 | |
| 220 | case Instruction::CONST_STRING: |
| 221 | case Instruction::CONST_STRING_JUMBO: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 222 | cg->GenConstString(cu, vB, rl_dest); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 223 | break; |
| 224 | |
| 225 | case Instruction::CONST_CLASS: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 226 | cg->GenConstClass(cu, vB, rl_dest); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 227 | break; |
| 228 | |
| 229 | case Instruction::FILL_ARRAY_DATA: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 230 | cg->GenFillArrayData(cu, vB, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 231 | break; |
| 232 | |
| 233 | case Instruction::FILLED_NEW_ARRAY: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 234 | cg->GenFilledNewArray(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 235 | false /* not range */)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 236 | break; |
| 237 | |
| 238 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 239 | cg->GenFilledNewArray(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 240 | true /* range */)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 241 | break; |
| 242 | |
| 243 | case Instruction::NEW_ARRAY: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 244 | cg->GenNewArray(cu, vC, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 245 | break; |
| 246 | |
| 247 | case Instruction::GOTO: |
| 248 | case Instruction::GOTO_16: |
| 249 | case Instruction::GOTO_32: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 250 | if (bb->taken->start_offset <= mir->offset) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 251 | cg->GenSuspendTestAndBranch(cu, opt_flags, &label_list[bb->taken->id]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 252 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 253 | cg->OpUnconditionalBranch(cu, &label_list[bb->taken->id]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 254 | } |
| 255 | break; |
| 256 | |
| 257 | case Instruction::PACKED_SWITCH: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 258 | cg->GenPackedSwitch(cu, vB, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 259 | break; |
| 260 | |
| 261 | case Instruction::SPARSE_SWITCH: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 262 | cg->GenSparseSwitch(cu, vB, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 263 | break; |
| 264 | |
| 265 | case Instruction::CMPL_FLOAT: |
| 266 | case Instruction::CMPG_FLOAT: |
| 267 | case Instruction::CMPL_DOUBLE: |
| 268 | case Instruction::CMPG_DOUBLE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 269 | res = cg->GenCmpFP(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 270 | break; |
| 271 | |
| 272 | case Instruction::CMP_LONG: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 273 | cg->GenCmpLong(cu, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 274 | break; |
| 275 | |
| 276 | case Instruction::IF_EQ: |
| 277 | case Instruction::IF_NE: |
| 278 | case Instruction::IF_LT: |
| 279 | case Instruction::IF_GE: |
| 280 | case Instruction::IF_GT: |
| 281 | case Instruction::IF_LE: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 282 | LIR* taken = &label_list[bb->taken->id]; |
| 283 | LIR* fall_through = &label_list[bb->fall_through->id]; |
| 284 | bool backward_branch; |
| 285 | backward_branch = (bb->taken->start_offset <= mir->offset); |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 286 | // Result known at compile time? |
| 287 | if (rl_src[0].is_const && rl_src[1].is_const) { |
| 288 | bool is_taken = EvaluateBranch(opcode, cu->constant_values[rl_src[0].orig_sreg], |
| 289 | cu->constant_values[rl_src[1].orig_sreg]); |
| 290 | if (is_taken && backward_branch) { |
| 291 | cg->GenSuspendTest(cu, opt_flags); |
| 292 | } |
| 293 | int id = is_taken ? bb->taken->id : bb->fall_through->id; |
| 294 | cg->OpUnconditionalBranch(cu, &label_list[id]); |
| 295 | } else { |
| 296 | if (backward_branch) { |
| 297 | cg->GenSuspendTest(cu, opt_flags); |
| 298 | } |
| 299 | cg->GenCompareAndBranch(cu, opcode, rl_src[0], rl_src[1], taken, |
| 300 | fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 301 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | |
| 305 | case Instruction::IF_EQZ: |
| 306 | case Instruction::IF_NEZ: |
| 307 | case Instruction::IF_LTZ: |
| 308 | case Instruction::IF_GEZ: |
| 309 | case Instruction::IF_GTZ: |
| 310 | case Instruction::IF_LEZ: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 311 | LIR* taken = &label_list[bb->taken->id]; |
| 312 | LIR* fall_through = &label_list[bb->fall_through->id]; |
| 313 | bool backward_branch; |
| 314 | backward_branch = (bb->taken->start_offset <= mir->offset); |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 315 | // Result known at compile time? |
| 316 | if (rl_src[0].is_const) { |
| 317 | bool is_taken = EvaluateBranch(opcode, cu->constant_values[rl_src[0].orig_sreg], 0); |
| 318 | if (is_taken && backward_branch) { |
| 319 | cg->GenSuspendTest(cu, opt_flags); |
| 320 | } |
| 321 | int id = is_taken ? bb->taken->id : bb->fall_through->id; |
| 322 | cg->OpUnconditionalBranch(cu, &label_list[id]); |
| 323 | } else { |
| 324 | if (backward_branch) { |
| 325 | cg->GenSuspendTest(cu, opt_flags); |
| 326 | } |
| 327 | cg->GenCompareZeroAndBranch(cu, opcode, rl_src[0], taken, fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 328 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 329 | break; |
| 330 | } |
| 331 | |
| 332 | case Instruction::AGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 333 | cg->GenArrayGet(cu, opt_flags, kLong, rl_src[0], rl_src[1], rl_dest, 3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 334 | break; |
| 335 | case Instruction::AGET: |
| 336 | case Instruction::AGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 337 | cg->GenArrayGet(cu, opt_flags, kWord, rl_src[0], rl_src[1], rl_dest, 2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 338 | break; |
| 339 | case Instruction::AGET_BOOLEAN: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 340 | cg->GenArrayGet(cu, opt_flags, kUnsignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 341 | break; |
| 342 | case Instruction::AGET_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 343 | cg->GenArrayGet(cu, opt_flags, kSignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 344 | break; |
| 345 | case Instruction::AGET_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 346 | cg->GenArrayGet(cu, opt_flags, kUnsignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 347 | break; |
| 348 | case Instruction::AGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 349 | cg->GenArrayGet(cu, opt_flags, kSignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 350 | break; |
| 351 | case Instruction::APUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 352 | cg->GenArrayPut(cu, opt_flags, kLong, rl_src[1], rl_src[2], rl_src[0], 3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 353 | break; |
| 354 | case Instruction::APUT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 355 | cg->GenArrayPut(cu, opt_flags, kWord, rl_src[1], rl_src[2], rl_src[0], 2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 356 | break; |
| 357 | case Instruction::APUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 358 | cg->GenArrayObjPut(cu, opt_flags, rl_src[1], rl_src[2], rl_src[0], 2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 359 | break; |
| 360 | case Instruction::APUT_SHORT: |
| 361 | case Instruction::APUT_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 362 | cg->GenArrayPut(cu, opt_flags, kUnsignedHalf, rl_src[1], rl_src[2], rl_src[0], 1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 363 | break; |
| 364 | case Instruction::APUT_BYTE: |
| 365 | case Instruction::APUT_BOOLEAN: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 366 | cg->GenArrayPut(cu, opt_flags, kUnsignedByte, rl_src[1], rl_src[2], |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 367 | rl_src[0], 0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 368 | break; |
| 369 | |
| 370 | case Instruction::IGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 371 | cg->GenIGet(cu, vC, opt_flags, kWord, rl_dest, rl_src[0], false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 372 | break; |
| 373 | |
| 374 | case Instruction::IGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 375 | cg->GenIGet(cu, vC, opt_flags, kLong, rl_dest, rl_src[0], true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 376 | break; |
| 377 | |
| 378 | case Instruction::IGET: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 379 | cg->GenIGet(cu, vC, opt_flags, kWord, rl_dest, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 380 | break; |
| 381 | |
| 382 | case Instruction::IGET_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 383 | cg->GenIGet(cu, vC, opt_flags, kUnsignedHalf, rl_dest, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 384 | break; |
| 385 | |
| 386 | case Instruction::IGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 387 | cg->GenIGet(cu, vC, opt_flags, kSignedHalf, rl_dest, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | case Instruction::IGET_BOOLEAN: |
| 391 | case Instruction::IGET_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 392 | cg->GenIGet(cu, vC, opt_flags, kUnsignedByte, rl_dest, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 393 | break; |
| 394 | |
| 395 | case Instruction::IPUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 396 | cg->GenIPut(cu, vC, opt_flags, kLong, rl_src[0], rl_src[1], true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | case Instruction::IPUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 400 | cg->GenIPut(cu, vC, opt_flags, kWord, rl_src[0], rl_src[1], false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 401 | break; |
| 402 | |
| 403 | case Instruction::IPUT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 404 | cg->GenIPut(cu, vC, opt_flags, kWord, rl_src[0], rl_src[1], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 405 | break; |
| 406 | |
| 407 | case Instruction::IPUT_BOOLEAN: |
| 408 | case Instruction::IPUT_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 409 | cg->GenIPut(cu, vC, opt_flags, kUnsignedByte, rl_src[0], rl_src[1], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 410 | break; |
| 411 | |
| 412 | case Instruction::IPUT_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 413 | cg->GenIPut(cu, vC, opt_flags, kUnsignedHalf, rl_src[0], rl_src[1], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 414 | break; |
| 415 | |
| 416 | case Instruction::IPUT_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 417 | cg->GenIPut(cu, vC, opt_flags, kSignedHalf, rl_src[0], rl_src[1], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 418 | break; |
| 419 | |
| 420 | case Instruction::SGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 421 | cg->GenSget(cu, vB, rl_dest, false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 422 | break; |
| 423 | case Instruction::SGET: |
| 424 | case Instruction::SGET_BOOLEAN: |
| 425 | case Instruction::SGET_BYTE: |
| 426 | case Instruction::SGET_CHAR: |
| 427 | case Instruction::SGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 428 | cg->GenSget(cu, vB, rl_dest, false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 429 | break; |
| 430 | |
| 431 | case Instruction::SGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 432 | cg->GenSget(cu, vB, rl_dest, true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 433 | break; |
| 434 | |
| 435 | case Instruction::SPUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 436 | cg->GenSput(cu, vB, rl_src[0], false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 437 | break; |
| 438 | |
| 439 | case Instruction::SPUT: |
| 440 | case Instruction::SPUT_BOOLEAN: |
| 441 | case Instruction::SPUT_BYTE: |
| 442 | case Instruction::SPUT_CHAR: |
| 443 | case Instruction::SPUT_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 444 | cg->GenSput(cu, vB, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 445 | break; |
| 446 | |
| 447 | case Instruction::SPUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 448 | cg->GenSput(cu, vB, rl_src[0], true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 449 | break; |
| 450 | |
| 451 | case Instruction::INVOKE_STATIC_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 452 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 453 | break; |
| 454 | case Instruction::INVOKE_STATIC: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 455 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 456 | break; |
| 457 | |
| 458 | case Instruction::INVOKE_DIRECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 459 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kDirect, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 460 | break; |
| 461 | case Instruction::INVOKE_DIRECT_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 462 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kDirect, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 463 | break; |
| 464 | |
| 465 | case Instruction::INVOKE_VIRTUAL: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 466 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kVirtual, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 467 | break; |
| 468 | case Instruction::INVOKE_VIRTUAL_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 469 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kVirtual, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 470 | break; |
| 471 | |
| 472 | case Instruction::INVOKE_SUPER: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 473 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kSuper, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 474 | break; |
| 475 | case Instruction::INVOKE_SUPER_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 476 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kSuper, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
| 479 | case Instruction::INVOKE_INTERFACE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 480 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kInterface, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | break; |
| 482 | case Instruction::INVOKE_INTERFACE_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 483 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kInterface, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 484 | break; |
| 485 | |
| 486 | case Instruction::NEG_INT: |
| 487 | case Instruction::NOT_INT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 488 | res = cg->GenArithOpInt(cu, opcode, rl_dest, rl_src[0], rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 489 | break; |
| 490 | |
| 491 | case Instruction::NEG_LONG: |
| 492 | case Instruction::NOT_LONG: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 493 | res = cg->GenArithOpLong(cu, opcode, rl_dest, rl_src[0], rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 494 | break; |
| 495 | |
| 496 | case Instruction::NEG_FLOAT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 497 | res = cg->GenArithOpFloat(cu, opcode, rl_dest, rl_src[0], rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 498 | break; |
| 499 | |
| 500 | case Instruction::NEG_DOUBLE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 501 | res = cg->GenArithOpDouble(cu, opcode, rl_dest, rl_src[0], rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 502 | break; |
| 503 | |
| 504 | case Instruction::INT_TO_LONG: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 505 | cg->GenIntToLong(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 506 | break; |
| 507 | |
| 508 | case Instruction::LONG_TO_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 509 | rl_src[0] = UpdateLocWide(cu, rl_src[0]); |
| 510 | rl_src[0] = WideToNarrow(cu, rl_src[0]); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 511 | cg->StoreValue(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 512 | break; |
| 513 | |
| 514 | case Instruction::INT_TO_BYTE: |
| 515 | case Instruction::INT_TO_SHORT: |
| 516 | case Instruction::INT_TO_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 517 | cg->GenIntNarrowing(cu, opcode, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 518 | break; |
| 519 | |
| 520 | case Instruction::INT_TO_FLOAT: |
| 521 | case Instruction::INT_TO_DOUBLE: |
| 522 | case Instruction::LONG_TO_FLOAT: |
| 523 | case Instruction::LONG_TO_DOUBLE: |
| 524 | case Instruction::FLOAT_TO_INT: |
| 525 | case Instruction::FLOAT_TO_LONG: |
| 526 | case Instruction::FLOAT_TO_DOUBLE: |
| 527 | case Instruction::DOUBLE_TO_INT: |
| 528 | case Instruction::DOUBLE_TO_LONG: |
| 529 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 530 | cg->GenConversion(cu, opcode, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 531 | break; |
| 532 | |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 533 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 534 | case Instruction::ADD_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 535 | case Instruction::ADD_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 536 | case Instruction::MUL_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 537 | case Instruction::MUL_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 538 | case Instruction::AND_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 539 | case Instruction::AND_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 540 | case Instruction::OR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 541 | case Instruction::OR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 542 | case Instruction::XOR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 543 | case Instruction::XOR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 544 | if (rl_src[0].is_const && |
| 545 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[0].orig_sreg])) { |
| 546 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[1], |
| 547 | cu->constant_values[rl_src[0].orig_sreg]); |
| 548 | } else if (rl_src[1].is_const && |
| 549 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[1].orig_sreg])) { |
| 550 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], |
| 551 | cu->constant_values[rl_src[1].orig_sreg]); |
| 552 | } else { |
| 553 | cg->GenArithOpInt(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
| 554 | } |
| 555 | break; |
| 556 | |
| 557 | case Instruction::SUB_INT: |
| 558 | case Instruction::SUB_INT_2ADDR: |
| 559 | case Instruction::DIV_INT: |
| 560 | case Instruction::DIV_INT_2ADDR: |
| 561 | case Instruction::REM_INT: |
| 562 | case Instruction::REM_INT_2ADDR: |
| 563 | case Instruction::SHL_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 564 | case Instruction::SHL_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 565 | case Instruction::SHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 566 | case Instruction::SHR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 567 | case Instruction::USHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 568 | case Instruction::USHR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame] | 569 | if (rl_src[1].is_const && |
| 570 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[1].orig_sreg])) { |
| 571 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], |
| 572 | cu->constant_values[rl_src[1].orig_sreg]); |
| 573 | } else { |
| 574 | cg->GenArithOpInt(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
| 575 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 576 | break; |
| 577 | |
| 578 | case Instruction::ADD_LONG: |
| 579 | case Instruction::SUB_LONG: |
| 580 | case Instruction::MUL_LONG: |
| 581 | case Instruction::DIV_LONG: |
| 582 | case Instruction::REM_LONG: |
| 583 | case Instruction::AND_LONG: |
| 584 | case Instruction::OR_LONG: |
| 585 | case Instruction::XOR_LONG: |
| 586 | case Instruction::ADD_LONG_2ADDR: |
| 587 | case Instruction::SUB_LONG_2ADDR: |
| 588 | case Instruction::MUL_LONG_2ADDR: |
| 589 | case Instruction::DIV_LONG_2ADDR: |
| 590 | case Instruction::REM_LONG_2ADDR: |
| 591 | case Instruction::AND_LONG_2ADDR: |
| 592 | case Instruction::OR_LONG_2ADDR: |
| 593 | case Instruction::XOR_LONG_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 594 | cg->GenArithOpLong(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 595 | break; |
| 596 | |
| 597 | case Instruction::SHL_LONG: |
| 598 | case Instruction::SHR_LONG: |
| 599 | case Instruction::USHR_LONG: |
| 600 | case Instruction::SHL_LONG_2ADDR: |
| 601 | case Instruction::SHR_LONG_2ADDR: |
| 602 | case Instruction::USHR_LONG_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 603 | cg->GenShiftOpLong(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 604 | break; |
| 605 | |
| 606 | case Instruction::ADD_FLOAT: |
| 607 | case Instruction::SUB_FLOAT: |
| 608 | case Instruction::MUL_FLOAT: |
| 609 | case Instruction::DIV_FLOAT: |
| 610 | case Instruction::REM_FLOAT: |
| 611 | case Instruction::ADD_FLOAT_2ADDR: |
| 612 | case Instruction::SUB_FLOAT_2ADDR: |
| 613 | case Instruction::MUL_FLOAT_2ADDR: |
| 614 | case Instruction::DIV_FLOAT_2ADDR: |
| 615 | case Instruction::REM_FLOAT_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 616 | cg->GenArithOpFloat(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 617 | break; |
| 618 | |
| 619 | case Instruction::ADD_DOUBLE: |
| 620 | case Instruction::SUB_DOUBLE: |
| 621 | case Instruction::MUL_DOUBLE: |
| 622 | case Instruction::DIV_DOUBLE: |
| 623 | case Instruction::REM_DOUBLE: |
| 624 | case Instruction::ADD_DOUBLE_2ADDR: |
| 625 | case Instruction::SUB_DOUBLE_2ADDR: |
| 626 | case Instruction::MUL_DOUBLE_2ADDR: |
| 627 | case Instruction::DIV_DOUBLE_2ADDR: |
| 628 | case Instruction::REM_DOUBLE_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 629 | cg->GenArithOpDouble(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case Instruction::RSUB_INT: |
| 633 | case Instruction::ADD_INT_LIT16: |
| 634 | case Instruction::MUL_INT_LIT16: |
| 635 | case Instruction::DIV_INT_LIT16: |
| 636 | case Instruction::REM_INT_LIT16: |
| 637 | case Instruction::AND_INT_LIT16: |
| 638 | case Instruction::OR_INT_LIT16: |
| 639 | case Instruction::XOR_INT_LIT16: |
| 640 | case Instruction::ADD_INT_LIT8: |
| 641 | case Instruction::RSUB_INT_LIT8: |
| 642 | case Instruction::MUL_INT_LIT8: |
| 643 | case Instruction::DIV_INT_LIT8: |
| 644 | case Instruction::REM_INT_LIT8: |
| 645 | case Instruction::AND_INT_LIT8: |
| 646 | case Instruction::OR_INT_LIT8: |
| 647 | case Instruction::XOR_INT_LIT8: |
| 648 | case Instruction::SHL_INT_LIT8: |
| 649 | case Instruction::SHR_INT_LIT8: |
| 650 | case Instruction::USHR_INT_LIT8: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 651 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], vC); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 652 | break; |
| 653 | |
| 654 | default: |
| 655 | res = true; |
| 656 | } |
| 657 | return res; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 658 | } |
| 659 | |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 660 | // Process extended MIR instructions |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 661 | static void HandleExtendedMethodMIR(CompilationUnit* cu, BasicBlock* bb, MIR* mir) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 662 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 663 | Codegen* cg = cu->cg.get(); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 664 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 665 | case kMirOpCopy: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 666 | RegLocation rl_src = GetSrc(cu, mir, 0); |
| 667 | RegLocation rl_dest = GetDest(cu, mir); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 668 | cg->StoreValue(cu, rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 669 | break; |
| 670 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 671 | case kMirOpFusedCmplFloat: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 672 | cg->GenFusedFPCmpBranch(cu, bb, mir, false /*gt bias*/, false /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 673 | break; |
| 674 | case kMirOpFusedCmpgFloat: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 675 | cg->GenFusedFPCmpBranch(cu, bb, mir, true /*gt bias*/, false /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 676 | break; |
| 677 | case kMirOpFusedCmplDouble: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 678 | cg->GenFusedFPCmpBranch(cu, bb, mir, false /*gt bias*/, true /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 679 | break; |
| 680 | case kMirOpFusedCmpgDouble: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 681 | cg->GenFusedFPCmpBranch(cu, bb, mir, true /*gt bias*/, true /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 682 | break; |
| 683 | case kMirOpFusedCmpLong: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 684 | cg->GenFusedLongCmpBranch(cu, bb, mir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 685 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 686 | default: |
| 687 | break; |
| 688 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 689 | } |
| 690 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 691 | // Handle the content in each basic block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 692 | static bool MethodBlockCodeGen(CompilationUnit* cu, BasicBlock* bb) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 693 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 694 | if (bb->block_type == kDead) return false; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 695 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 696 | cu->current_dalvik_offset = bb->start_offset; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 697 | MIR* mir; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 698 | LIR* label_list = cu->block_label_list; |
| 699 | int block_id = bb->id; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 700 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 701 | cu->cur_block = bb; |
| 702 | label_list[block_id].operands[0] = bb->start_offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 703 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 704 | // Insert the block label. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 705 | label_list[block_id].opcode = kPseudoNormalBlockLabel; |
| 706 | AppendLIR(cu, &label_list[block_id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 707 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 708 | LIR* head_lir = NULL; |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 709 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 710 | // If this is a catch block, export the start address. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 711 | if (bb->catch_entry) { |
| 712 | head_lir = NewLIR0(cu, kPseudoExportedPC); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 713 | } |
| 714 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 715 | // Free temp registers and reset redundant store tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 716 | ResetRegPool(cu); |
| 717 | ResetDefTracking(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 718 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 719 | ClobberAllRegs(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 720 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 721 | if (bb->block_type == kEntryBlock) { |
| 722 | int start_vreg = cu->num_dalvik_registers - cu->num_ins; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 723 | cg->GenEntrySequence(cu, &cu->reg_location[start_vreg], |
| 724 | cu->reg_location[cu->method_sreg]); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 725 | } else if (bb->block_type == kExitBlock) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 726 | cg->GenExitSequence(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 727 | } |
| 728 | |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 729 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 730 | ResetRegPool(cu); |
| 731 | if (cu->disable_opt & (1 << kTrackLiveTemps)) { |
| 732 | ClobberAllRegs(cu); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 733 | } |
| 734 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 735 | if (cu->disable_opt & (1 << kSuppressLoads)) { |
| 736 | ResetDefTracking(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 737 | } |
| 738 | |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 739 | #ifndef NDEBUG |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 740 | // Reset temp tracking sanity check. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 741 | cu->live_sreg = INVALID_SREG; |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 742 | #endif |
| 743 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 744 | cu->current_dalvik_offset = mir->offset; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 745 | int opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 746 | LIR* boundary_lir; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 747 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 748 | // Mark the beginning of a Dalvik instruction for line tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 749 | char* inst_str = cu->verbose ? |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 750 | GetDalvikDisassembly(cu, mir) : NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 751 | boundary_lir = MarkBoundary(cu, mir->offset, inst_str); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 752 | // Remember the first LIR for this block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 753 | if (head_lir == NULL) { |
| 754 | head_lir = boundary_lir; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 755 | // Set the first boundary_lir as a scheduling barrier. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 756 | head_lir->def_mask = ENCODE_ALL; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 757 | } |
| 758 | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 759 | if (opcode == kMirOpCheck) { |
| 760 | // Combine check and work halves of throwing instruction. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 761 | MIR* work_half = mir->meta.throw_insn; |
| 762 | mir->dalvikInsn.opcode = work_half->dalvikInsn.opcode; |
| 763 | opcode = work_half->dalvikInsn.opcode; |
| 764 | SSARepresentation* ssa_rep = work_half->ssa_rep; |
| 765 | work_half->ssa_rep = mir->ssa_rep; |
| 766 | mir->ssa_rep = ssa_rep; |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 767 | work_half->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpCheckPart2); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (opcode >= kMirOpFirst) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 771 | HandleExtendedMethodMIR(cu, bb, mir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 772 | continue; |
| 773 | } |
| 774 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 775 | bool not_handled = CompileDalvikInstruction(cu, mir, bb, label_list); |
| 776 | if (not_handled) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 777 | LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s)", |
| 778 | mir->offset, opcode, |
| 779 | Instruction::Name(mir->dalvikInsn.opcode)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 783 | if (head_lir) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 784 | // Eliminate redundant loads/stores and delay stores into later slots. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 785 | ApplyLocalOptimizations(cu, head_lir, cu->last_lir_insn); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 786 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 787 | // Generate an unconditional branch to the fallthrough block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 788 | if (bb->fall_through) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 789 | cg->OpUnconditionalBranch(cu, &label_list[bb->fall_through->id]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 793 | } |
| 794 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 795 | void SpecialMIR2LIR(CompilationUnit* cu, SpecialCaseHandler special_case) |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 796 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 797 | Codegen* cg = cu->cg.get(); |
| 798 | // Find the first DalvikByteCode block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 799 | int num_reachable_blocks = cu->num_reachable_blocks; |
| 800 | const GrowableList *block_list = &cu->block_list; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 801 | BasicBlock*bb = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 802 | for (int idx = 0; idx < num_reachable_blocks; idx++) { |
| 803 | int dfs_index = cu->dfs_order.elem_list[idx]; |
| 804 | bb = reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, dfs_index)); |
| 805 | if (bb->block_type == kDalvikByteCode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 806 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 807 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 808 | } |
| 809 | if (bb == NULL) { |
| 810 | return; |
| 811 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 812 | DCHECK_EQ(bb->start_offset, 0); |
| 813 | DCHECK(bb->first_mir_insn != NULL); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 814 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 815 | // Get the first instruction. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 816 | MIR* mir = bb->first_mir_insn; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 817 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 818 | // Free temp registers and reset redundant store tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 819 | ResetRegPool(cu); |
| 820 | ResetDefTracking(cu); |
| 821 | ClobberAllRegs(cu); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 822 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 823 | cg->GenSpecialCase(cu, bb, mir, special_case); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 824 | } |
| 825 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 826 | void MethodMIR2LIR(CompilationUnit* cu) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 827 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 828 | Codegen* cg = cu->cg.get(); |
| 829 | // Hold the labels of each block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 830 | cu->block_label_list = |
| 831 | static_cast<LIR*>(NewMem(cu, sizeof(LIR) * cu->num_blocks, true, kAllocLIR)); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 832 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 833 | DataFlowAnalysisDispatcher(cu, MethodBlockCodeGen, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 834 | kPreOrderDFSTraversal, false /* Iterative */); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 835 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 836 | cg->HandleSuspendLaunchPads(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 837 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 838 | cg->HandleThrowLaunchPads(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 839 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 840 | cg->HandleIntrinsicLaunchPads(cu); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 841 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 842 | if (!(cu->disable_opt & (1 << kSafeOptimizations))) { |
| 843 | RemoveRedundantBranches(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 844 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 845 | } |
| 846 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 847 | } // namespace art |