buzbee | efc6369 | 2012-11-14 16:31:52 -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 | /* This file contains codegen for the Thumb2 ISA. */ |
| 18 | |
| 19 | #include "oat_compilation_unit.h" |
| 20 | #include "oat/runtime/oat_support_entrypoints.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 21 | #include "arm_lir.h" |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 22 | #include "codegen_arm.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 23 | #include "../codegen_util.h" |
| 24 | #include "../ralloc_util.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | |
| 29 | /* Return the position of an ssa name within the argument list */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 30 | static int InPosition(CompilationUnit* cu, int s_reg) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 31 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 32 | int v_reg = SRegToVReg(cu, s_reg); |
| 33 | return v_reg - cu->num_regs; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Describe an argument. If it's already in an arg register, just leave it |
| 38 | * there. NOTE: all live arg registers must be locked prior to this call |
| 39 | * to avoid having them allocated as a temp by downstream utilities. |
| 40 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 41 | RegLocation ArmCodegen::ArgLoc(CompilationUnit* cu, RegLocation loc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 42 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 43 | int arg_num = InPosition(cu, loc.s_reg_low); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 44 | if (loc.wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 45 | if (arg_num == 2) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 46 | // Bad case - half in register, half in frame. Just punt |
| 47 | loc.location = kLocInvalid; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 48 | } else if (arg_num < 2) { |
| 49 | loc.low_reg = rARM_ARG1 + arg_num; |
| 50 | loc.high_reg = loc.low_reg + 1; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 51 | loc.location = kLocPhysReg; |
| 52 | } else { |
| 53 | loc.location = kLocDalvikFrame; |
| 54 | } |
| 55 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 56 | if (arg_num < 3) { |
| 57 | loc.low_reg = rARM_ARG1 + arg_num; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 58 | loc.location = kLocPhysReg; |
| 59 | } else { |
| 60 | loc.location = kLocDalvikFrame; |
| 61 | } |
| 62 | } |
| 63 | return loc; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Load an argument. If already in a register, just return. If in |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 68 | * the frame, we can't use the normal LoadValue() because it assumed |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 69 | * a proper frame - and we're frameless. |
| 70 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 71 | static RegLocation LoadArg(CompilationUnit* cu, RegLocation loc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 72 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 73 | Codegen* cg = cu->cg.get(); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 74 | if (loc.location == kLocDalvikFrame) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 75 | int start = (InPosition(cu, loc.s_reg_low) + 1) * sizeof(uint32_t); |
| 76 | loc.low_reg = AllocTemp(cu); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 77 | cg->LoadWordDisp(cu, rARM_SP, start, loc.low_reg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 78 | if (loc.wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 79 | loc.high_reg = AllocTemp(cu); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 80 | cg->LoadWordDisp(cu, rARM_SP, start + sizeof(uint32_t), loc.high_reg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 81 | } |
| 82 | loc.location = kLocPhysReg; |
| 83 | } |
| 84 | return loc; |
| 85 | } |
| 86 | |
| 87 | /* Lock any referenced arguments that arrive in registers */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 88 | static void LockLiveArgs(CompilationUnit* cu, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 89 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 90 | int first_in = cu->num_regs; |
| 91 | const int num_arg_regs = 3; // TODO: generalize & move to RegUtil.cc |
| 92 | for (int i = 0; i < mir->ssa_rep->num_uses; i++) { |
| 93 | int v_reg = SRegToVReg(cu, mir->ssa_rep->uses[i]); |
| 94 | int InPosition = v_reg - first_in; |
| 95 | if (InPosition < num_arg_regs) { |
| 96 | LockTemp(cu, rARM_ARG1 + InPosition); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* Find the next MIR, which may be in a following basic block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 102 | static MIR* GetNextMir(CompilationUnit* cu, BasicBlock** p_bb, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 103 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 104 | BasicBlock* bb = *p_bb; |
| 105 | MIR* orig_mir = mir; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 106 | while (bb != NULL) { |
| 107 | if (mir != NULL) { |
| 108 | mir = mir->next; |
| 109 | } |
| 110 | if (mir != NULL) { |
| 111 | return mir; |
| 112 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 113 | bb = bb->fall_through; |
| 114 | *p_bb = bb; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 115 | if (bb) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 116 | mir = bb->first_mir_insn; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 117 | if (mir != NULL) { |
| 118 | return mir; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 123 | return orig_mir; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 124 | } |
| 125 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 126 | /* Used for the "verbose" listing */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 127 | //TODO: move to common code |
| 128 | void ArmCodegen::GenPrintLabel(CompilationUnit *cu, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 129 | { |
| 130 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 131 | char* inst_str = cu->verbose ? |
| 132 | GetDalvikDisassembly(cu, mir->dalvikInsn, "") : NULL; |
| 133 | MarkBoundary(cu, mir->offset, inst_str); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 134 | /* Don't generate the SSA annotation unless verbose mode is on */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 135 | if (cu->verbose && mir->ssa_rep) { |
| 136 | char* ssa_string = GetSSAString(cu, mir->ssa_rep); |
| 137 | NewLIR1(cu, kPseudoSSARep, reinterpret_cast<uintptr_t>(ssa_string)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 141 | static MIR* SpecialIGet(CompilationUnit* cu, BasicBlock** bb, MIR* mir, |
| 142 | OpSize size, bool long_or_double, bool is_object) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 143 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 144 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 145 | int field_offset; |
| 146 | bool is_volatile; |
| 147 | uint32_t field_idx = mir->dalvikInsn.vC; |
| 148 | bool fast_path = FastInstance(cu, field_idx, field_offset, is_volatile, false); |
| 149 | if (!fast_path || !(mir->optimization_flags & MIR_IGNORE_NULL_CHECK)) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 150 | return NULL; |
| 151 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 152 | RegLocation rl_obj = GetSrc(cu, mir, 0); |
| 153 | LockLiveArgs(cu, mir); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 154 | rl_obj = ArmCodegen::ArgLoc(cu, rl_obj); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 155 | RegLocation rl_dest; |
| 156 | if (long_or_double) { |
| 157 | rl_dest = GetReturnWide(cu, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 158 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 159 | rl_dest = GetReturn(cu, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 160 | } |
| 161 | // Point of no return - no aborts after this |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 162 | ArmCodegen::GenPrintLabel(cu, mir); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 163 | rl_obj = LoadArg(cu, rl_obj); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 164 | cg->GenIGet(cu, field_idx, mir->optimization_flags, size, rl_dest, rl_obj, |
| 165 | long_or_double, is_object); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 166 | return GetNextMir(cu, bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 167 | } |
| 168 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 169 | static MIR* SpecialIPut(CompilationUnit* cu, BasicBlock** bb, MIR* mir, |
| 170 | OpSize size, bool long_or_double, bool is_object) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 171 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 172 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 173 | int field_offset; |
| 174 | bool is_volatile; |
| 175 | uint32_t field_idx = mir->dalvikInsn.vC; |
| 176 | bool fast_path = FastInstance(cu, field_idx, field_offset, is_volatile, false); |
| 177 | if (!fast_path || !(mir->optimization_flags & MIR_IGNORE_NULL_CHECK)) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 178 | return NULL; |
| 179 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 180 | RegLocation rl_src; |
| 181 | RegLocation rl_obj; |
| 182 | LockLiveArgs(cu, mir); |
| 183 | if (long_or_double) { |
| 184 | rl_src = GetSrcWide(cu, mir, 0); |
| 185 | rl_obj = GetSrc(cu, mir, 2); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 186 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 187 | rl_src = GetSrc(cu, mir, 0); |
| 188 | rl_obj = GetSrc(cu, mir, 1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 189 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 190 | rl_src = ArmCodegen::ArgLoc(cu, rl_src); |
| 191 | rl_obj = ArmCodegen::ArgLoc(cu, rl_obj); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 192 | // Reject if source is split across registers & frame |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 193 | if (rl_obj.location == kLocInvalid) { |
| 194 | ResetRegPool(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 195 | return NULL; |
| 196 | } |
| 197 | // Point of no return - no aborts after this |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 198 | ArmCodegen::GenPrintLabel(cu, mir); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 199 | rl_obj = LoadArg(cu, rl_obj); |
| 200 | rl_src = LoadArg(cu, rl_src); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 201 | cg->GenIPut(cu, field_idx, mir->optimization_flags, size, rl_src, rl_obj, |
| 202 | long_or_double, is_object); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 203 | return GetNextMir(cu, bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 204 | } |
| 205 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 206 | static MIR* SpecialIdentity(CompilationUnit* cu, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 207 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 208 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 209 | RegLocation rl_src; |
| 210 | RegLocation rl_dest; |
| 211 | bool wide = (mir->ssa_rep->num_uses == 2); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 212 | if (wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 213 | rl_src = GetSrcWide(cu, mir, 0); |
| 214 | rl_dest = GetReturnWide(cu, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 215 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 216 | rl_src = GetSrc(cu, mir, 0); |
| 217 | rl_dest = GetReturn(cu, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 218 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 219 | LockLiveArgs(cu, mir); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 220 | rl_src = ArmCodegen::ArgLoc(cu, rl_src); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 221 | if (rl_src.location == kLocInvalid) { |
| 222 | ResetRegPool(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 223 | return NULL; |
| 224 | } |
| 225 | // Point of no return - no aborts after this |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 226 | ArmCodegen::GenPrintLabel(cu, mir); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 227 | rl_src = LoadArg(cu, rl_src); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 228 | if (wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 229 | cg->StoreValueWide(cu, rl_dest, rl_src); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 230 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 231 | cg->StoreValue(cu, rl_dest, rl_src); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 232 | } |
| 233 | return mir; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Special-case code genration for simple non-throwing leaf methods. |
| 238 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 239 | void ArmCodegen::GenSpecialCase(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 240 | SpecialCaseHandler special_case) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 241 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 242 | cu->current_dalvik_offset = mir->offset; |
| 243 | MIR* next_mir = NULL; |
| 244 | switch (special_case) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 245 | case kNullMethod: |
| 246 | DCHECK(mir->dalvikInsn.opcode == Instruction::RETURN_VOID); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 247 | next_mir = mir; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 248 | break; |
| 249 | case kConstFunction: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 250 | ArmCodegen::GenPrintLabel(cu, mir); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 251 | LoadConstant(cu, rARM_RET0, mir->dalvikInsn.vB); |
| 252 | next_mir = GetNextMir(cu, &bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 253 | break; |
| 254 | case kIGet: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 255 | next_mir = SpecialIGet(cu, &bb, mir, kWord, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 256 | break; |
| 257 | case kIGetBoolean: |
| 258 | case kIGetByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 259 | next_mir = SpecialIGet(cu, &bb, mir, kUnsignedByte, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 260 | break; |
| 261 | case kIGetObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 262 | next_mir = SpecialIGet(cu, &bb, mir, kWord, false, true); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 263 | break; |
| 264 | case kIGetChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 265 | next_mir = SpecialIGet(cu, &bb, mir, kUnsignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 266 | break; |
| 267 | case kIGetShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 268 | next_mir = SpecialIGet(cu, &bb, mir, kSignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 269 | break; |
| 270 | case kIGetWide: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 271 | next_mir = SpecialIGet(cu, &bb, mir, kLong, true, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 272 | break; |
| 273 | case kIPut: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 274 | next_mir = SpecialIPut(cu, &bb, mir, kWord, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 275 | break; |
| 276 | case kIPutBoolean: |
| 277 | case kIPutByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 278 | next_mir = SpecialIPut(cu, &bb, mir, kUnsignedByte, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 279 | break; |
| 280 | case kIPutObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 281 | next_mir = SpecialIPut(cu, &bb, mir, kWord, false, true); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 282 | break; |
| 283 | case kIPutChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 284 | next_mir = SpecialIPut(cu, &bb, mir, kUnsignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 285 | break; |
| 286 | case kIPutShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 287 | next_mir = SpecialIPut(cu, &bb, mir, kSignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 288 | break; |
| 289 | case kIPutWide: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 290 | next_mir = SpecialIPut(cu, &bb, mir, kLong, true, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 291 | break; |
| 292 | case kIdentity: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 293 | next_mir = SpecialIdentity(cu, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 294 | break; |
| 295 | default: |
| 296 | return; |
| 297 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 298 | if (next_mir != NULL) { |
| 299 | cu->current_dalvik_offset = next_mir->offset; |
| 300 | if (special_case != kIdentity) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 301 | ArmCodegen::GenPrintLabel(cu, next_mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 302 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 303 | NewLIR1(cu, kThumbBx, rARM_LR); |
| 304 | cu->core_spill_mask = 0; |
| 305 | cu->num_core_spills = 0; |
| 306 | cu->fp_spill_mask = 0; |
| 307 | cu->num_fp_spills = 0; |
| 308 | cu->frame_size = 0; |
| 309 | cu->core_vmap_table.clear(); |
| 310 | cu->fp_vmap_table.clear(); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * The sparse table in the literal pool is an array of <key,displacement> |
| 316 | * pairs. For each set, we'll load them as a pair using ldmia. |
| 317 | * This means that the register number of the temp we use for the key |
| 318 | * must be lower than the reg for the displacement. |
| 319 | * |
| 320 | * The test loop will look something like: |
| 321 | * |
| 322 | * adr rBase, <table> |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 323 | * ldr r_val, [rARM_SP, v_reg_off] |
| 324 | * mov r_idx, #table_size |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 325 | * lp: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 326 | * ldmia rBase!, {r_key, r_disp} |
| 327 | * sub r_idx, #1 |
| 328 | * cmp r_val, r_key |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 329 | * ifeq |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 330 | * add rARM_PC, r_disp ; This is the branch from which we compute displacement |
| 331 | * cbnz r_idx, lp |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 332 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 333 | void ArmCodegen::GenSparseSwitch(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 334 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 335 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
| 336 | if (cu->verbose) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 337 | DumpSparseSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 338 | } |
| 339 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 340 | SwitchTable *tab_rec = |
| 341 | static_cast<SwitchTable*>(NewMem(cu, sizeof(SwitchTable), true, kAllocData)); |
| 342 | tab_rec->table = table; |
| 343 | tab_rec->vaddr = cu->current_dalvik_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 344 | int size = table[1]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 345 | tab_rec->targets = static_cast<LIR**>(NewMem(cu, size * sizeof(LIR*), true, kAllocLIR)); |
| 346 | InsertGrowableList(cu, &cu->switch_tables, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 347 | |
| 348 | // Get the switch value |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 349 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
| 350 | int rBase = AllocTemp(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 351 | /* Allocate key and disp temps */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 352 | int r_key = AllocTemp(cu); |
| 353 | int r_disp = AllocTemp(cu); |
| 354 | // Make sure r_key's register number is less than r_disp's number for ldmia |
| 355 | if (r_key > r_disp) { |
| 356 | int tmp = r_disp; |
| 357 | r_disp = r_key; |
| 358 | r_key = tmp; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 359 | } |
| 360 | // Materialize a pointer to the switch table |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 361 | NewLIR3(cu, kThumb2Adr, rBase, 0, reinterpret_cast<uintptr_t>(tab_rec)); |
| 362 | // Set up r_idx |
| 363 | int r_idx = AllocTemp(cu); |
| 364 | LoadConstant(cu, r_idx, size); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 365 | // Establish loop branch target |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 366 | LIR* target = NewLIR0(cu, kPseudoTargetLabel); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 367 | // Load next key/disp |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 368 | NewLIR2(cu, kThumb2LdmiaWB, rBase, (1 << r_key) | (1 << r_disp)); |
| 369 | OpRegReg(cu, kOpCmp, r_key, rl_src.low_reg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 370 | // Go if match. NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 371 | OpIT(cu, kCondEq, ""); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 372 | LIR* switch_branch = NewLIR1(cu, kThumb2AddPCR, r_disp); |
| 373 | tab_rec->anchor = switch_branch; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 374 | // Needs to use setflags encoding here |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 375 | NewLIR3(cu, kThumb2SubsRRI12, r_idx, r_idx, 1); |
| 376 | OpCondBranch(cu, kCondNe, target); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 380 | void ArmCodegen::GenPackedSwitch(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 381 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 382 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
| 383 | if (cu->verbose) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 384 | DumpPackedSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 385 | } |
| 386 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 387 | SwitchTable *tab_rec = |
| 388 | static_cast<SwitchTable*>(NewMem(cu, sizeof(SwitchTable), true, kAllocData)); |
| 389 | tab_rec->table = table; |
| 390 | tab_rec->vaddr = cu->current_dalvik_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 391 | int size = table[1]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 392 | tab_rec->targets = static_cast<LIR**>(NewMem(cu, size * sizeof(LIR*), true, kAllocLIR)); |
| 393 | InsertGrowableList(cu, &cu->switch_tables, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 394 | |
| 395 | // Get the switch value |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 396 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
| 397 | int table_base = AllocTemp(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 398 | // Materialize a pointer to the switch table |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 399 | NewLIR3(cu, kThumb2Adr, table_base, 0, reinterpret_cast<uintptr_t>(tab_rec)); |
| 400 | int low_key = s4FromSwitchData(&table[2]); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 401 | int keyReg; |
| 402 | // Remove the bias, if necessary |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 403 | if (low_key == 0) { |
| 404 | keyReg = rl_src.low_reg; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 405 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 406 | keyReg = AllocTemp(cu); |
| 407 | OpRegRegImm(cu, kOpSub, keyReg, rl_src.low_reg, low_key); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 408 | } |
| 409 | // Bounds check - if < 0 or >= size continue following switch |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 410 | OpRegImm(cu, kOpCmp, keyReg, size-1); |
| 411 | LIR* branch_over = OpCondBranch(cu, kCondHi, NULL); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 412 | |
| 413 | // Load the displacement from the switch table |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 414 | int disp_reg = AllocTemp(cu); |
| 415 | LoadBaseIndexed(cu, table_base, keyReg, disp_reg, 2, kWord); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 416 | |
| 417 | // ..and go! NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 418 | LIR* switch_branch = NewLIR1(cu, kThumb2AddPCR, disp_reg); |
| 419 | tab_rec->anchor = switch_branch; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 420 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 421 | /* branch_over target here */ |
| 422 | LIR* target = NewLIR0(cu, kPseudoTargetLabel); |
| 423 | branch_over->target = target; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Array data table format: |
| 428 | * ushort ident = 0x0300 magic value |
| 429 | * ushort width width of each element in the table |
| 430 | * uint size number of elements in the table |
| 431 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 432 | * padding at the end) |
| 433 | * |
| 434 | * Total size is 4+(width * size + 1)/2 16-bit code units. |
| 435 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 436 | void ArmCodegen::GenFillArrayData(CompilationUnit* cu, uint32_t table_offset, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 437 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 438 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 439 | // Add the table to the list - we'll process it later |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 440 | FillArrayData *tab_rec = |
| 441 | static_cast<FillArrayData*>(NewMem(cu, sizeof(FillArrayData), true, kAllocData)); |
| 442 | tab_rec->table = table; |
| 443 | tab_rec->vaddr = cu->current_dalvik_offset; |
| 444 | uint16_t width = tab_rec->table[1]; |
| 445 | uint32_t size = tab_rec->table[2] | ((static_cast<uint32_t>(tab_rec->table[3])) << 16); |
| 446 | tab_rec->size = (size * width) + 8; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 447 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 448 | InsertGrowableList(cu, &cu->fill_array_data, reinterpret_cast<uintptr_t>(tab_rec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 449 | |
| 450 | // Making a call - use explicit registers |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 451 | FlushAllRegs(cu); /* Everything to home location */ |
| 452 | LoadValueDirectFixed(cu, rl_src, r0); |
| 453 | LoadWordDisp(cu, rARM_SELF, ENTRYPOINT_OFFSET(pHandleFillArrayDataFromCode), |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 454 | rARM_LR); |
| 455 | // Materialize a pointer to the fill data image |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 456 | NewLIR3(cu, kThumb2Adr, r1, 0, reinterpret_cast<uintptr_t>(tab_rec)); |
| 457 | ClobberCalleeSave(cu); |
| 458 | LIR* call_inst = OpReg(cu, kOpBlx, rARM_LR); |
| 459 | MarkSafepointPC(cu, call_inst); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* |
| 463 | * Handle simple case (thin lock) inline. If it's complicated, bail |
| 464 | * out to the heavyweight lock/unlock routines. We'll use dedicated |
| 465 | * registers here in order to be in the right position in case we |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 466 | * to bail to oat[Lock/Unlock]Object(self, object) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 467 | * |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 468 | * r0 -> self pointer [arg0 for oat[Lock/Unlock]Object |
| 469 | * r1 -> object [arg1 for oat[Lock/Unlock]Object |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 470 | * r2 -> intial contents of object->lock, later result of strex |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 471 | * r3 -> self->thread_id |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 472 | * r12 -> allow to be used by utilities as general temp |
| 473 | * |
| 474 | * The result of the strex is 0 if we acquire the lock. |
| 475 | * |
| 476 | * See comments in Sync.c for the layout of the lock word. |
| 477 | * Of particular interest to this code is the test for the |
| 478 | * simple case - which we handle inline. For monitor enter, the |
| 479 | * simple case is thin lock, held by no-one. For monitor exit, |
| 480 | * the simple case is thin lock, held by the unlocking thread with |
| 481 | * a recurse count of 0. |
| 482 | * |
| 483 | * A minor complication is that there is a field in the lock word |
| 484 | * unrelated to locking: the hash state. This field must be ignored, but |
| 485 | * preserved. |
| 486 | * |
| 487 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 488 | void ArmCodegen::GenMonitorEnter(CompilationUnit* cu, int opt_flags, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 489 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 490 | FlushAllRegs(cu); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 491 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 492 | LoadValueDirectFixed(cu, rl_src, r0); // Get obj |
| 493 | LockCallTemps(cu); // Prepare for explicit register usage |
| 494 | GenNullCheck(cu, rl_src.s_reg_low, r0, opt_flags); |
| 495 | LoadWordDisp(cu, rARM_SELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
| 496 | NewLIR3(cu, kThumb2Ldrex, r1, r0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 497 | Object::MonitorOffset().Int32Value() >> 2); // Get object->lock |
| 498 | // Align owner |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 499 | OpRegImm(cu, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
| 500 | // Is lock unheld on lock or held by us (==thread_id) on unlock? |
| 501 | NewLIR4(cu, kThumb2Bfi, r2, r1, 0, LW_LOCK_OWNER_SHIFT - 1); |
| 502 | NewLIR3(cu, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
| 503 | OpRegImm(cu, kOpCmp, r1, 0); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 504 | OpIT(cu, kCondEq, ""); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 505 | NewLIR4(cu, kThumb2Strex, r1, r2, r0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 506 | Object::MonitorOffset().Int32Value() >> 2); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 507 | OpRegImm(cu, kOpCmp, r1, 0); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 508 | OpIT(cu, kCondNe, "T"); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 509 | // Go expensive route - artLockObjectFromCode(self, obj); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 510 | LoadWordDisp(cu, rARM_SELF, ENTRYPOINT_OFFSET(pLockObjectFromCode), rARM_LR); |
| 511 | ClobberCalleeSave(cu); |
| 512 | LIR* call_inst = OpReg(cu, kOpBlx, rARM_LR); |
| 513 | MarkSafepointPC(cu, call_inst); |
| 514 | GenMemBarrier(cu, kLoadLoad); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /* |
| 518 | * For monitor unlock, we don't have to use ldrex/strex. Once |
| 519 | * we've determined that the lock is thin and that we own it with |
| 520 | * a zero recursion count, it's safe to punch it back to the |
| 521 | * initial, unlock thin state with a store word. |
| 522 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 523 | void ArmCodegen::GenMonitorExit(CompilationUnit* cu, int opt_flags, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 524 | { |
| 525 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 526 | FlushAllRegs(cu); |
| 527 | LoadValueDirectFixed(cu, rl_src, r0); // Get obj |
| 528 | LockCallTemps(cu); // Prepare for explicit register usage |
| 529 | GenNullCheck(cu, rl_src.s_reg_low, r0, opt_flags); |
| 530 | LoadWordDisp(cu, r0, Object::MonitorOffset().Int32Value(), r1); // Get lock |
| 531 | LoadWordDisp(cu, rARM_SELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
| 532 | // Is lock unheld on lock or held by us (==thread_id) on unlock? |
| 533 | OpRegRegImm(cu, kOpAnd, r3, r1, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 534 | (LW_HASH_STATE_MASK << LW_HASH_STATE_SHIFT)); |
| 535 | // Align owner |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 536 | OpRegImm(cu, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
| 537 | NewLIR3(cu, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
| 538 | OpRegReg(cu, kOpSub, r1, r2); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 539 | OpIT(cu, kCondEq, "EE"); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 540 | StoreWordDisp(cu, r0, Object::MonitorOffset().Int32Value(), r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 541 | // Go expensive route - UnlockObjectFromCode(obj); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 542 | LoadWordDisp(cu, rARM_SELF, ENTRYPOINT_OFFSET(pUnlockObjectFromCode), rARM_LR); |
| 543 | ClobberCalleeSave(cu); |
| 544 | LIR* call_inst = OpReg(cu, kOpBlx, rARM_LR); |
| 545 | MarkSafepointPC(cu, call_inst); |
| 546 | GenMemBarrier(cu, kStoreLoad); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /* |
| 550 | * Mark garbage collection card. Skip if the value we're storing is null. |
| 551 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 552 | void ArmCodegen::MarkGCCard(CompilationUnit* cu, int val_reg, int tgt_addr_reg) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 553 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 554 | int reg_card_base = AllocTemp(cu); |
| 555 | int reg_card_no = AllocTemp(cu); |
| 556 | LIR* branch_over = OpCmpImmBranch(cu, kCondEq, val_reg, 0, NULL); |
| 557 | LoadWordDisp(cu, rARM_SELF, Thread::CardTableOffset().Int32Value(), reg_card_base); |
| 558 | OpRegRegImm(cu, kOpLsr, reg_card_no, tgt_addr_reg, CardTable::kCardShift); |
| 559 | StoreBaseIndexed(cu, reg_card_base, reg_card_no, reg_card_base, 0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 560 | kUnsignedByte); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 561 | LIR* target = NewLIR0(cu, kPseudoTargetLabel); |
| 562 | branch_over->target = target; |
| 563 | FreeTemp(cu, reg_card_base); |
| 564 | FreeTemp(cu, reg_card_no); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 565 | } |
| 566 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 567 | void ArmCodegen::GenEntrySequence(CompilationUnit* cu, RegLocation* ArgLocs, RegLocation rl_method) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 568 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 569 | int spill_count = cu->num_core_spills + cu->num_fp_spills; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 570 | /* |
| 571 | * On entry, r0, r1, r2 & r3 are live. Let the register allocation |
| 572 | * mechanism know so it doesn't try to use any of them when |
| 573 | * expanding the frame or flushing. This leaves the utility |
| 574 | * code with a single temp: r12. This should be enough. |
| 575 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 576 | LockTemp(cu, r0); |
| 577 | LockTemp(cu, r1); |
| 578 | LockTemp(cu, r2); |
| 579 | LockTemp(cu, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 580 | |
| 581 | /* |
| 582 | * We can safely skip the stack overflow check if we're |
| 583 | * a leaf *and* our frame size < fudge factor. |
| 584 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 585 | bool skip_overflow_check = ((cu->attrs & METHOD_IS_LEAF) && |
| 586 | (static_cast<size_t>(cu->frame_size) < |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 587 | Thread::kStackOverflowReservedBytes)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 588 | NewLIR0(cu, kPseudoMethodEntry); |
| 589 | if (!skip_overflow_check) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 590 | /* Load stack limit */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 591 | LoadWordDisp(cu, rARM_SELF, Thread::StackEndOffset().Int32Value(), r12); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 592 | } |
| 593 | /* Spill core callee saves */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 594 | NewLIR1(cu, kThumb2Push, cu->core_spill_mask); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 595 | /* Need to spill any FP regs? */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 596 | if (cu->num_fp_spills) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 597 | /* |
| 598 | * NOTE: fp spills are a little different from core spills in that |
| 599 | * they are pushed as a contiguous block. When promoting from |
| 600 | * the fp set, we must allocate all singles from s16..highest-promoted |
| 601 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 602 | NewLIR1(cu, kThumb2VPushCS, cu->num_fp_spills); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 603 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 604 | if (!skip_overflow_check) { |
| 605 | OpRegRegImm(cu, kOpSub, rARM_LR, rARM_SP, cu->frame_size - (spill_count * 4)); |
| 606 | GenRegRegCheck(cu, kCondCc, rARM_LR, r12, kThrowStackOverflow); |
| 607 | OpRegCopy(cu, rARM_SP, rARM_LR); // Establish stack |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 608 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 609 | OpRegImm(cu, kOpSub, rARM_SP, cu->frame_size - (spill_count * 4)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 610 | } |
| 611 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 612 | FlushIns(cu, ArgLocs, rl_method); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 613 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 614 | FreeTemp(cu, r0); |
| 615 | FreeTemp(cu, r1); |
| 616 | FreeTemp(cu, r2); |
| 617 | FreeTemp(cu, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 618 | } |
| 619 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 620 | void ArmCodegen::GenExitSequence(CompilationUnit* cu) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 621 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 622 | int spill_count = cu->num_core_spills + cu->num_fp_spills; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 623 | /* |
| 624 | * In the exit path, r0/r1 are live - make sure they aren't |
| 625 | * allocated by the register utilities as temps. |
| 626 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 627 | LockTemp(cu, r0); |
| 628 | LockTemp(cu, r1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 629 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 630 | NewLIR0(cu, kPseudoMethodExit); |
| 631 | OpRegImm(cu, kOpAdd, rARM_SP, cu->frame_size - (spill_count * 4)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 632 | /* Need to restore any FP callee saves? */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 633 | if (cu->num_fp_spills) { |
| 634 | NewLIR1(cu, kThumb2VPopCS, cu->num_fp_spills); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 635 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 636 | if (cu->core_spill_mask & (1 << rARM_LR)) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 637 | /* Unspill rARM_LR to rARM_PC */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 638 | cu->core_spill_mask &= ~(1 << rARM_LR); |
| 639 | cu->core_spill_mask |= (1 << rARM_PC); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 640 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 641 | NewLIR1(cu, kThumb2Pop, cu->core_spill_mask); |
| 642 | if (!(cu->core_spill_mask & (1 << rARM_PC))) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 643 | /* We didn't pop to rARM_PC, so must do a bv rARM_LR */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 644 | NewLIR1(cu, kThumbBx, rARM_LR); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | } // namespace art |