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