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