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