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