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); |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 281 | // Result known at compile time? |
| 282 | if (rl_src[0].is_const && rl_src[1].is_const) { |
| 283 | bool is_taken = EvaluateBranch(opcode, cu->constant_values[rl_src[0].orig_sreg], |
| 284 | cu->constant_values[rl_src[1].orig_sreg]); |
| 285 | if (is_taken && backward_branch) { |
| 286 | cg->GenSuspendTest(cu, opt_flags); |
| 287 | } |
| 288 | int id = is_taken ? bb->taken->id : bb->fall_through->id; |
| 289 | cg->OpUnconditionalBranch(cu, &label_list[id]); |
| 290 | } else { |
| 291 | if (backward_branch) { |
| 292 | cg->GenSuspendTest(cu, opt_flags); |
| 293 | } |
| 294 | cg->GenCompareAndBranch(cu, opcode, rl_src[0], rl_src[1], taken, |
| 295 | fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 296 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 297 | break; |
| 298 | } |
| 299 | |
| 300 | case Instruction::IF_EQZ: |
| 301 | case Instruction::IF_NEZ: |
| 302 | case Instruction::IF_LTZ: |
| 303 | case Instruction::IF_GEZ: |
| 304 | case Instruction::IF_GTZ: |
| 305 | case Instruction::IF_LEZ: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 306 | LIR* taken = &label_list[bb->taken->id]; |
| 307 | LIR* fall_through = &label_list[bb->fall_through->id]; |
| 308 | bool backward_branch; |
| 309 | backward_branch = (bb->taken->start_offset <= mir->offset); |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 310 | // Result known at compile time? |
| 311 | if (rl_src[0].is_const) { |
| 312 | bool is_taken = EvaluateBranch(opcode, cu->constant_values[rl_src[0].orig_sreg], 0); |
| 313 | if (is_taken && backward_branch) { |
| 314 | cg->GenSuspendTest(cu, opt_flags); |
| 315 | } |
| 316 | int id = is_taken ? bb->taken->id : bb->fall_through->id; |
| 317 | cg->OpUnconditionalBranch(cu, &label_list[id]); |
| 318 | } else { |
| 319 | if (backward_branch) { |
| 320 | cg->GenSuspendTest(cu, opt_flags); |
| 321 | } |
| 322 | cg->GenCompareZeroAndBranch(cu, opcode, rl_src[0], taken, fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 323 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 324 | break; |
| 325 | } |
| 326 | |
| 327 | case Instruction::AGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 328 | 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] | 329 | break; |
| 330 | case Instruction::AGET: |
| 331 | case Instruction::AGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 332 | 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] | 333 | break; |
| 334 | case Instruction::AGET_BOOLEAN: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 335 | 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] | 336 | break; |
| 337 | case Instruction::AGET_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 338 | 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] | 339 | break; |
| 340 | case Instruction::AGET_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 341 | 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] | 342 | break; |
| 343 | case Instruction::AGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 344 | 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] | 345 | break; |
| 346 | case Instruction::APUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 347 | 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] | 348 | break; |
| 349 | case Instruction::APUT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 350 | 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] | 351 | break; |
| 352 | case Instruction::APUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 353 | 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] | 354 | break; |
| 355 | case Instruction::APUT_SHORT: |
| 356 | case Instruction::APUT_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 357 | 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] | 358 | break; |
| 359 | case Instruction::APUT_BYTE: |
| 360 | case Instruction::APUT_BOOLEAN: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 361 | cg->GenArrayPut(cu, opt_flags, kUnsignedByte, rl_src[1], rl_src[2], |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 362 | rl_src[0], 0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 363 | break; |
| 364 | |
| 365 | case Instruction::IGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 366 | 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] | 367 | break; |
| 368 | |
| 369 | case Instruction::IGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 370 | 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] | 371 | break; |
| 372 | |
| 373 | case Instruction::IGET: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 374 | 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] | 375 | break; |
| 376 | |
| 377 | case Instruction::IGET_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 378 | 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] | 379 | break; |
| 380 | |
| 381 | case Instruction::IGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 382 | 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] | 383 | break; |
| 384 | |
| 385 | case Instruction::IGET_BOOLEAN: |
| 386 | case Instruction::IGET_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 387 | 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] | 388 | break; |
| 389 | |
| 390 | case Instruction::IPUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 391 | 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] | 392 | break; |
| 393 | |
| 394 | case Instruction::IPUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 395 | 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] | 396 | break; |
| 397 | |
| 398 | case Instruction::IPUT: |
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, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 400 | break; |
| 401 | |
| 402 | case Instruction::IPUT_BOOLEAN: |
| 403 | case Instruction::IPUT_BYTE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 404 | 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] | 405 | break; |
| 406 | |
| 407 | case Instruction::IPUT_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 408 | 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] | 409 | break; |
| 410 | |
| 411 | case Instruction::IPUT_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 412 | 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] | 413 | break; |
| 414 | |
| 415 | case Instruction::SGET_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 416 | cg->GenSget(cu, vB, rl_dest, false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 417 | break; |
| 418 | case Instruction::SGET: |
| 419 | case Instruction::SGET_BOOLEAN: |
| 420 | case Instruction::SGET_BYTE: |
| 421 | case Instruction::SGET_CHAR: |
| 422 | case Instruction::SGET_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 423 | cg->GenSget(cu, vB, rl_dest, false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 424 | break; |
| 425 | |
| 426 | case Instruction::SGET_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 427 | cg->GenSget(cu, vB, rl_dest, true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 428 | break; |
| 429 | |
| 430 | case Instruction::SPUT_OBJECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 431 | cg->GenSput(cu, vB, rl_src[0], false, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 432 | break; |
| 433 | |
| 434 | case Instruction::SPUT: |
| 435 | case Instruction::SPUT_BOOLEAN: |
| 436 | case Instruction::SPUT_BYTE: |
| 437 | case Instruction::SPUT_CHAR: |
| 438 | case Instruction::SPUT_SHORT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 439 | cg->GenSput(cu, vB, rl_src[0], false, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 440 | break; |
| 441 | |
| 442 | case Instruction::SPUT_WIDE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 443 | cg->GenSput(cu, vB, rl_src[0], true, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 444 | break; |
| 445 | |
| 446 | case Instruction::INVOKE_STATIC_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 447 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 448 | break; |
| 449 | case Instruction::INVOKE_STATIC: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 450 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kStatic, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 451 | break; |
| 452 | |
| 453 | case Instruction::INVOKE_DIRECT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 454 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kDirect, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 455 | break; |
| 456 | case Instruction::INVOKE_DIRECT_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 457 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kDirect, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 458 | break; |
| 459 | |
| 460 | case Instruction::INVOKE_VIRTUAL: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 461 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kVirtual, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 462 | break; |
| 463 | case Instruction::INVOKE_VIRTUAL_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 464 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kVirtual, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 465 | break; |
| 466 | |
| 467 | case Instruction::INVOKE_SUPER: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 468 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kSuper, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 469 | break; |
| 470 | case Instruction::INVOKE_SUPER_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 471 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kSuper, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 472 | break; |
| 473 | |
| 474 | case Instruction::INVOKE_INTERFACE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 475 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kInterface, false)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 476 | break; |
| 477 | case Instruction::INVOKE_INTERFACE_RANGE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 478 | cg->GenInvoke(cu, cg->NewMemCallInfo(cu, bb, mir, kInterface, true)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 479 | break; |
| 480 | |
| 481 | case Instruction::NEG_INT: |
| 482 | case Instruction::NOT_INT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 483 | 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] | 484 | break; |
| 485 | |
| 486 | case Instruction::NEG_LONG: |
| 487 | case Instruction::NOT_LONG: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 488 | 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] | 489 | break; |
| 490 | |
| 491 | case Instruction::NEG_FLOAT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 492 | 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] | 493 | break; |
| 494 | |
| 495 | case Instruction::NEG_DOUBLE: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 496 | 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] | 497 | break; |
| 498 | |
| 499 | case Instruction::INT_TO_LONG: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 500 | cg->GenIntToLong(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 501 | break; |
| 502 | |
| 503 | case Instruction::LONG_TO_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 504 | rl_src[0] = UpdateLocWide(cu, rl_src[0]); |
| 505 | rl_src[0] = WideToNarrow(cu, rl_src[0]); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 506 | cg->StoreValue(cu, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 507 | break; |
| 508 | |
| 509 | case Instruction::INT_TO_BYTE: |
| 510 | case Instruction::INT_TO_SHORT: |
| 511 | case Instruction::INT_TO_CHAR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 512 | cg->GenIntNarrowing(cu, opcode, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case Instruction::INT_TO_FLOAT: |
| 516 | case Instruction::INT_TO_DOUBLE: |
| 517 | case Instruction::LONG_TO_FLOAT: |
| 518 | case Instruction::LONG_TO_DOUBLE: |
| 519 | case Instruction::FLOAT_TO_INT: |
| 520 | case Instruction::FLOAT_TO_LONG: |
| 521 | case Instruction::FLOAT_TO_DOUBLE: |
| 522 | case Instruction::DOUBLE_TO_INT: |
| 523 | case Instruction::DOUBLE_TO_LONG: |
| 524 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 525 | cg->GenConversion(cu, opcode, rl_dest, rl_src[0]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 528 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 529 | case Instruction::ADD_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 530 | case Instruction::ADD_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 531 | case Instruction::MUL_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 532 | case Instruction::MUL_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 533 | case Instruction::AND_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 534 | case Instruction::AND_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 535 | case Instruction::OR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 536 | case Instruction::OR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 537 | case Instruction::XOR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 538 | case Instruction::XOR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 539 | if (rl_src[0].is_const && |
| 540 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[0].orig_sreg])) { |
| 541 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[1], |
| 542 | cu->constant_values[rl_src[0].orig_sreg]); |
| 543 | } else if (rl_src[1].is_const && |
| 544 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[1].orig_sreg])) { |
| 545 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], |
| 546 | cu->constant_values[rl_src[1].orig_sreg]); |
| 547 | } else { |
| 548 | cg->GenArithOpInt(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
| 549 | } |
| 550 | break; |
| 551 | |
| 552 | case Instruction::SUB_INT: |
| 553 | case Instruction::SUB_INT_2ADDR: |
| 554 | case Instruction::DIV_INT: |
| 555 | case Instruction::DIV_INT_2ADDR: |
| 556 | case Instruction::REM_INT: |
| 557 | case Instruction::REM_INT_2ADDR: |
| 558 | case Instruction::SHL_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 559 | case Instruction::SHL_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 560 | case Instruction::SHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 561 | case Instruction::SHR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 562 | case Instruction::USHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 563 | case Instruction::USHR_INT_2ADDR: |
buzbee | e6285f9 | 2012-12-06 15:57:46 -0800 | [diff] [blame^] | 564 | if (rl_src[1].is_const && |
| 565 | cu->cg->InexpensiveConstant(0, cu->constant_values[rl_src[1].orig_sreg])) { |
| 566 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], |
| 567 | cu->constant_values[rl_src[1].orig_sreg]); |
| 568 | } else { |
| 569 | cg->GenArithOpInt(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
| 570 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 571 | break; |
| 572 | |
| 573 | case Instruction::ADD_LONG: |
| 574 | case Instruction::SUB_LONG: |
| 575 | case Instruction::MUL_LONG: |
| 576 | case Instruction::DIV_LONG: |
| 577 | case Instruction::REM_LONG: |
| 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: |
| 583 | case Instruction::MUL_LONG_2ADDR: |
| 584 | case Instruction::DIV_LONG_2ADDR: |
| 585 | case Instruction::REM_LONG_2ADDR: |
| 586 | case Instruction::AND_LONG_2ADDR: |
| 587 | case Instruction::OR_LONG_2ADDR: |
| 588 | case Instruction::XOR_LONG_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 589 | cg->GenArithOpLong(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 590 | break; |
| 591 | |
| 592 | case Instruction::SHL_LONG: |
| 593 | case Instruction::SHR_LONG: |
| 594 | case Instruction::USHR_LONG: |
| 595 | case Instruction::SHL_LONG_2ADDR: |
| 596 | case Instruction::SHR_LONG_2ADDR: |
| 597 | case Instruction::USHR_LONG_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 598 | cg->GenShiftOpLong(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::ADD_FLOAT: |
| 602 | case Instruction::SUB_FLOAT: |
| 603 | case Instruction::MUL_FLOAT: |
| 604 | case Instruction::DIV_FLOAT: |
| 605 | case Instruction::REM_FLOAT: |
| 606 | case Instruction::ADD_FLOAT_2ADDR: |
| 607 | case Instruction::SUB_FLOAT_2ADDR: |
| 608 | case Instruction::MUL_FLOAT_2ADDR: |
| 609 | case Instruction::DIV_FLOAT_2ADDR: |
| 610 | case Instruction::REM_FLOAT_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 611 | cg->GenArithOpFloat(cu, opcode, rl_dest, rl_src[0], rl_src[1]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 612 | break; |
| 613 | |
| 614 | case Instruction::ADD_DOUBLE: |
| 615 | case Instruction::SUB_DOUBLE: |
| 616 | case Instruction::MUL_DOUBLE: |
| 617 | case Instruction::DIV_DOUBLE: |
| 618 | case Instruction::REM_DOUBLE: |
| 619 | case Instruction::ADD_DOUBLE_2ADDR: |
| 620 | case Instruction::SUB_DOUBLE_2ADDR: |
| 621 | case Instruction::MUL_DOUBLE_2ADDR: |
| 622 | case Instruction::DIV_DOUBLE_2ADDR: |
| 623 | case Instruction::REM_DOUBLE_2ADDR: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 624 | cg->GenArithOpDouble(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::RSUB_INT: |
| 628 | case Instruction::ADD_INT_LIT16: |
| 629 | case Instruction::MUL_INT_LIT16: |
| 630 | case Instruction::DIV_INT_LIT16: |
| 631 | case Instruction::REM_INT_LIT16: |
| 632 | case Instruction::AND_INT_LIT16: |
| 633 | case Instruction::OR_INT_LIT16: |
| 634 | case Instruction::XOR_INT_LIT16: |
| 635 | case Instruction::ADD_INT_LIT8: |
| 636 | case Instruction::RSUB_INT_LIT8: |
| 637 | case Instruction::MUL_INT_LIT8: |
| 638 | case Instruction::DIV_INT_LIT8: |
| 639 | case Instruction::REM_INT_LIT8: |
| 640 | case Instruction::AND_INT_LIT8: |
| 641 | case Instruction::OR_INT_LIT8: |
| 642 | case Instruction::XOR_INT_LIT8: |
| 643 | case Instruction::SHL_INT_LIT8: |
| 644 | case Instruction::SHR_INT_LIT8: |
| 645 | case Instruction::USHR_INT_LIT8: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 646 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src[0], vC); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | default: |
| 650 | res = true; |
| 651 | } |
| 652 | return res; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 653 | } |
| 654 | |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 655 | // Process extended MIR instructions |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 656 | static void HandleExtendedMethodMIR(CompilationUnit* cu, BasicBlock* bb, MIR* mir) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 657 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 658 | Codegen* cg = cu->cg.get(); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 659 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 660 | case kMirOpCopy: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 661 | RegLocation rl_src = GetSrc(cu, mir, 0); |
| 662 | RegLocation rl_dest = GetDest(cu, mir); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 663 | cg->StoreValue(cu, rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 664 | break; |
| 665 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 666 | case kMirOpFusedCmplFloat: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 667 | cg->GenFusedFPCmpBranch(cu, bb, mir, false /*gt bias*/, false /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 668 | break; |
| 669 | case kMirOpFusedCmpgFloat: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 670 | cg->GenFusedFPCmpBranch(cu, bb, mir, true /*gt bias*/, false /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 671 | break; |
| 672 | case kMirOpFusedCmplDouble: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 673 | cg->GenFusedFPCmpBranch(cu, bb, mir, false /*gt bias*/, true /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 674 | break; |
| 675 | case kMirOpFusedCmpgDouble: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 676 | cg->GenFusedFPCmpBranch(cu, bb, mir, true /*gt bias*/, true /*double*/); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 677 | break; |
| 678 | case kMirOpFusedCmpLong: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 679 | cg->GenFusedLongCmpBranch(cu, bb, mir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 680 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 681 | default: |
| 682 | break; |
| 683 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 684 | } |
| 685 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 686 | // Handle the content in each basic block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 687 | static bool MethodBlockCodeGen(CompilationUnit* cu, BasicBlock* bb) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 688 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 689 | if (bb->block_type == kDead) return false; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 690 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 691 | cu->current_dalvik_offset = bb->start_offset; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 692 | MIR* mir; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 693 | LIR* label_list = cu->block_label_list; |
| 694 | int block_id = bb->id; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 695 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 696 | cu->cur_block = bb; |
| 697 | label_list[block_id].operands[0] = bb->start_offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 698 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 699 | // Insert the block label. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 700 | label_list[block_id].opcode = kPseudoNormalBlockLabel; |
| 701 | AppendLIR(cu, &label_list[block_id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 702 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 703 | LIR* head_lir = NULL; |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 704 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 705 | // If this is a catch block, export the start address. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 706 | if (bb->catch_entry) { |
| 707 | head_lir = NewLIR0(cu, kPseudoExportedPC); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 708 | } |
| 709 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 710 | // Free temp registers and reset redundant store tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 711 | ResetRegPool(cu); |
| 712 | ResetDefTracking(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 713 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 714 | ClobberAllRegs(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 715 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 716 | if (bb->block_type == kEntryBlock) { |
| 717 | int start_vreg = cu->num_dalvik_registers - cu->num_ins; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 718 | cg->GenEntrySequence(cu, &cu->reg_location[start_vreg], |
| 719 | cu->reg_location[cu->method_sreg]); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 720 | } else if (bb->block_type == kExitBlock) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 721 | cg->GenExitSequence(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 722 | } |
| 723 | |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 724 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 725 | ResetRegPool(cu); |
| 726 | if (cu->disable_opt & (1 << kTrackLiveTemps)) { |
| 727 | ClobberAllRegs(cu); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 728 | } |
| 729 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 730 | if (cu->disable_opt & (1 << kSuppressLoads)) { |
| 731 | ResetDefTracking(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 732 | } |
| 733 | |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 734 | #ifndef NDEBUG |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 735 | // Reset temp tracking sanity check. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 736 | cu->live_sreg = INVALID_SREG; |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 737 | #endif |
| 738 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 739 | cu->current_dalvik_offset = mir->offset; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 740 | int opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 741 | LIR* boundary_lir; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 742 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 743 | // Mark the beginning of a Dalvik instruction for line tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 744 | char* inst_str = cu->verbose ? |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 745 | GetDalvikDisassembly(cu, mir) : NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 746 | boundary_lir = MarkBoundary(cu, mir->offset, inst_str); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 747 | // Remember the first LIR for this block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 748 | if (head_lir == NULL) { |
| 749 | head_lir = boundary_lir; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 750 | // Set the first boundary_lir as a scheduling barrier. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 751 | head_lir->def_mask = ENCODE_ALL; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 752 | } |
| 753 | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 754 | if (opcode == kMirOpCheck) { |
| 755 | // Combine check and work halves of throwing instruction. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 756 | MIR* work_half = mir->meta.throw_insn; |
| 757 | mir->dalvikInsn.opcode = work_half->dalvikInsn.opcode; |
| 758 | opcode = work_half->dalvikInsn.opcode; |
| 759 | SSARepresentation* ssa_rep = work_half->ssa_rep; |
| 760 | work_half->ssa_rep = mir->ssa_rep; |
| 761 | mir->ssa_rep = ssa_rep; |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 762 | work_half->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpCheckPart2); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | if (opcode >= kMirOpFirst) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 766 | HandleExtendedMethodMIR(cu, bb, mir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 767 | continue; |
| 768 | } |
| 769 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 770 | bool not_handled = CompileDalvikInstruction(cu, mir, bb, label_list); |
| 771 | if (not_handled) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 772 | LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s)", |
| 773 | mir->offset, opcode, |
| 774 | Instruction::Name(mir->dalvikInsn.opcode)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 778 | if (head_lir) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 779 | // Eliminate redundant loads/stores and delay stores into later slots. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 780 | ApplyLocalOptimizations(cu, head_lir, cu->last_lir_insn); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 781 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 782 | // Generate an unconditional branch to the fallthrough block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 783 | if (bb->fall_through) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 784 | cg->OpUnconditionalBranch(cu, &label_list[bb->fall_through->id]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 788 | } |
| 789 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 790 | void SpecialMIR2LIR(CompilationUnit* cu, SpecialCaseHandler special_case) |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 791 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 792 | Codegen* cg = cu->cg.get(); |
| 793 | // Find the first DalvikByteCode block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 794 | int num_reachable_blocks = cu->num_reachable_blocks; |
| 795 | const GrowableList *block_list = &cu->block_list; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 796 | BasicBlock*bb = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 797 | for (int idx = 0; idx < num_reachable_blocks; idx++) { |
| 798 | int dfs_index = cu->dfs_order.elem_list[idx]; |
| 799 | bb = reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, dfs_index)); |
| 800 | if (bb->block_type == kDalvikByteCode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 801 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 802 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 803 | } |
| 804 | if (bb == NULL) { |
| 805 | return; |
| 806 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 807 | DCHECK_EQ(bb->start_offset, 0); |
| 808 | DCHECK(bb->first_mir_insn != NULL); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 809 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 810 | // Get the first instruction. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 811 | MIR* mir = bb->first_mir_insn; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 812 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 813 | // Free temp registers and reset redundant store tracking. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 814 | ResetRegPool(cu); |
| 815 | ResetDefTracking(cu); |
| 816 | ClobberAllRegs(cu); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 817 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 818 | cg->GenSpecialCase(cu, bb, mir, special_case); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 819 | } |
| 820 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 821 | void MethodMIR2LIR(CompilationUnit* cu) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 822 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 823 | Codegen* cg = cu->cg.get(); |
| 824 | // Hold the labels of each block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 825 | cu->block_label_list = |
| 826 | static_cast<LIR*>(NewMem(cu, sizeof(LIR) * cu->num_blocks, true, kAllocLIR)); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 827 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 828 | DataFlowAnalysisDispatcher(cu, MethodBlockCodeGen, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 829 | kPreOrderDFSTraversal, false /* Iterative */); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 830 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 831 | cg->HandleSuspendLaunchPads(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 832 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 833 | cg->HandleThrowLaunchPads(cu); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 834 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 835 | cg->HandleIntrinsicLaunchPads(cu); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 836 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 837 | if (!(cu->disable_opt & (1 << kSafeOptimizations))) { |
| 838 | RemoveRedundantBranches(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 839 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 840 | } |
| 841 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 842 | } // namespace art |