Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [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 "arm64_lir.h" |
| 20 | #include "codegen_arm64.h" |
| 21 | #include "dex/quick/mir_to_lir-inl.h" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 26 | bool Arm64Mir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, |
| 27 | const InlineMethod& special) { |
| 28 | return Mir2Lir::GenSpecialCase(bb, mir, special); |
| 29 | } |
| 30 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 31 | /* |
| 32 | * The sparse table in the literal pool is an array of <key,displacement> |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 33 | * pairs. For each set, we'll load them as a pair using ldp. |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 34 | * The test loop will look something like: |
| 35 | * |
| 36 | * adr r_base, <table> |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 37 | * ldr r_val, [rA64_SP, v_reg_off] |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 38 | * mov r_idx, #table_size |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 39 | * loop: |
| 40 | * cbz r_idx, quit |
| 41 | * ldp r_key, r_disp, [r_base], #8 |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 42 | * sub r_idx, #1 |
| 43 | * cmp r_val, r_key |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 44 | * b.ne loop |
| 45 | * adr r_base, #0 ; This is the instruction from which we compute displacements |
| 46 | * add r_base, r_disp |
| 47 | * br r_base |
| 48 | * quit: |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 49 | */ |
| 50 | void Arm64Mir2Lir::GenSparseSwitch(MIR* mir, uint32_t table_offset, |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 51 | RegLocation rl_src) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 52 | const uint16_t* table = cu_->insns + current_dalvik_offset_ + table_offset; |
| 53 | if (cu_->verbose) { |
| 54 | DumpSparseSwitchTable(table); |
| 55 | } |
| 56 | // Add the table to the list - we'll process it later |
| 57 | SwitchTable *tab_rec = |
| 58 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
| 59 | tab_rec->table = table; |
| 60 | tab_rec->vaddr = current_dalvik_offset_; |
| 61 | uint32_t size = table[1]; |
| 62 | tab_rec->targets = static_cast<LIR**>(arena_->Alloc(size * sizeof(LIR*), kArenaAllocLIR)); |
| 63 | switch_tables_.Insert(tab_rec); |
| 64 | |
| 65 | // Get the switch value |
| 66 | rl_src = LoadValue(rl_src, kCoreReg); |
| 67 | RegStorage r_base = AllocTemp(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 68 | // Allocate key and disp temps. |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 69 | RegStorage r_key = AllocTemp(); |
| 70 | RegStorage r_disp = AllocTemp(); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 71 | // Materialize a pointer to the switch table |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 72 | NewLIR3(kA64Adr2xd, r_base.GetReg(), 0, WrapPointer(tab_rec)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 73 | // Set up r_idx |
| 74 | RegStorage r_idx = AllocTemp(); |
| 75 | LoadConstant(r_idx, size); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 76 | |
| 77 | // Entry of loop. |
| 78 | LIR* loop_entry = NewLIR0(kPseudoTargetLabel); |
| 79 | LIR* branch_out = NewLIR2(kA64Cbz2rt, r_idx.GetReg(), 0); |
| 80 | |
| 81 | // Load next key/disp. |
| 82 | NewLIR4(kA64LdpPost4rrXD, r_key.GetReg(), r_disp.GetReg(), r_base.GetReg(), 2); |
| 83 | OpRegRegImm(kOpSub, r_idx, r_idx, 1); |
| 84 | |
| 85 | // Go to next case, if key does not match. |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 86 | OpRegReg(kOpCmp, r_key, rl_src.reg); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 87 | OpCondBranch(kCondNe, loop_entry); |
| 88 | |
| 89 | // Key does match: branch to case label. |
| 90 | LIR* switch_label = NewLIR3(kA64Adr2xd, r_base.GetReg(), 0, -1); |
| 91 | tab_rec->anchor = switch_label; |
| 92 | |
| 93 | // Add displacement to base branch address and go! |
| 94 | OpRegRegRegShift(kOpAdd, r_base.GetReg(), r_base.GetReg(), r_disp.GetReg(), |
| 95 | ENCODE_NO_SHIFT, true); |
| 96 | NewLIR1(kA64Br1x, r_base.GetReg()); |
| 97 | |
| 98 | // Loop exit label. |
| 99 | LIR* loop_exit = NewLIR0(kPseudoTargetLabel); |
| 100 | branch_out->target = loop_exit; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | void Arm64Mir2Lir::GenPackedSwitch(MIR* mir, uint32_t table_offset, |
| 105 | RegLocation rl_src) { |
| 106 | const uint16_t* table = cu_->insns + current_dalvik_offset_ + table_offset; |
| 107 | if (cu_->verbose) { |
| 108 | DumpPackedSwitchTable(table); |
| 109 | } |
| 110 | // Add the table to the list - we'll process it later |
| 111 | SwitchTable *tab_rec = |
| 112 | static_cast<SwitchTable*>(arena_->Alloc(sizeof(SwitchTable), kArenaAllocData)); |
| 113 | tab_rec->table = table; |
| 114 | tab_rec->vaddr = current_dalvik_offset_; |
| 115 | uint32_t size = table[1]; |
| 116 | tab_rec->targets = |
| 117 | static_cast<LIR**>(arena_->Alloc(size * sizeof(LIR*), kArenaAllocLIR)); |
| 118 | switch_tables_.Insert(tab_rec); |
| 119 | |
| 120 | // Get the switch value |
| 121 | rl_src = LoadValue(rl_src, kCoreReg); |
| 122 | RegStorage table_base = AllocTemp(); |
| 123 | // Materialize a pointer to the switch table |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 124 | NewLIR3(kA64Adr2xd, table_base.GetReg(), 0, WrapPointer(tab_rec)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 125 | int low_key = s4FromSwitchData(&table[2]); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 126 | RegStorage key_reg; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 127 | // Remove the bias, if necessary |
| 128 | if (low_key == 0) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 129 | key_reg = rl_src.reg; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 130 | } else { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 131 | key_reg = AllocTemp(); |
| 132 | OpRegRegImm(kOpSub, key_reg, rl_src.reg, low_key); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 133 | } |
| 134 | // Bounds check - if < 0 or >= size continue following switch |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 135 | OpRegImm(kOpCmp, key_reg, size - 1); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 136 | LIR* branch_over = OpCondBranch(kCondHi, NULL); |
| 137 | |
| 138 | // Load the displacement from the switch table |
| 139 | RegStorage disp_reg = AllocTemp(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 140 | LoadBaseIndexed(table_base, key_reg, disp_reg, 2, k32); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 141 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 142 | // Get base branch address. |
| 143 | RegStorage branch_reg = AllocTemp(); |
| 144 | LIR* switch_label = NewLIR3(kA64Adr2xd, branch_reg.GetReg(), 0, -1); |
| 145 | tab_rec->anchor = switch_label; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 146 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 147 | // Add displacement to base branch address and go! |
| 148 | OpRegRegRegShift(kOpAdd, branch_reg.GetReg(), branch_reg.GetReg(), disp_reg.GetReg(), |
| 149 | ENCODE_NO_SHIFT, true); |
| 150 | NewLIR1(kA64Br1x, branch_reg.GetReg()); |
| 151 | |
| 152 | // branch_over target here |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 153 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 154 | branch_over->target = target; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Array data table format: |
| 159 | * ushort ident = 0x0300 magic value |
| 160 | * ushort width width of each element in the table |
| 161 | * uint size number of elements in the table |
| 162 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 163 | * padding at the end) |
| 164 | * |
| 165 | * Total size is 4+(width * size + 1)/2 16-bit code units. |
| 166 | */ |
| 167 | void Arm64Mir2Lir::GenFillArrayData(uint32_t table_offset, RegLocation rl_src) { |
| 168 | const uint16_t* table = cu_->insns + current_dalvik_offset_ + table_offset; |
| 169 | // Add the table to the list - we'll process it later |
| 170 | FillArrayData *tab_rec = |
| 171 | static_cast<FillArrayData*>(arena_->Alloc(sizeof(FillArrayData), kArenaAllocData)); |
| 172 | tab_rec->table = table; |
| 173 | tab_rec->vaddr = current_dalvik_offset_; |
| 174 | uint16_t width = tab_rec->table[1]; |
| 175 | uint32_t size = tab_rec->table[2] | ((static_cast<uint32_t>(tab_rec->table[3])) << 16); |
| 176 | tab_rec->size = (size * width) + 8; |
| 177 | |
| 178 | fill_array_data_.Insert(tab_rec); |
| 179 | |
| 180 | // Making a call - use explicit registers |
| 181 | FlushAllRegs(); /* Everything to home location */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 182 | LoadValueDirectFixed(rl_src, rs_x0); |
| 183 | LoadWordDisp(rs_rA64_SELF, A64_QUICK_ENTRYPOINT_INT_OFFS(pHandleFillArrayData), |
| 184 | rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 185 | // Materialize a pointer to the fill data image |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 186 | NewLIR3(kA64Adr2xd, rx1, 0, WrapPointer(tab_rec)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 187 | ClobberCallerSave(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 188 | LIR* call_inst = OpReg(kOpBlx, rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 189 | MarkSafepointPC(call_inst); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Handle unlocked -> thin locked transition inline or else call out to quick entrypoint. For more |
| 194 | * details see monitor.cc. |
| 195 | */ |
| 196 | void Arm64Mir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { |
| 197 | FlushAllRegs(); |
| 198 | // FIXME: need separate LoadValues for object references. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 199 | LoadValueDirectFixed(rl_src, rs_x0); // Get obj |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 200 | LockCallTemps(); // Prepare for explicit register usage |
| 201 | constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15. |
| 202 | if (kArchVariantHasGoodBranchPredictor) { |
| 203 | LIR* null_check_branch = nullptr; |
| 204 | if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) { |
| 205 | null_check_branch = nullptr; // No null check. |
| 206 | } else { |
| 207 | // If the null-check fails its handled by the slow-path to reduce exception related meta-data. |
| 208 | if (Runtime::Current()->ExplicitNullChecks()) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 209 | null_check_branch = OpCmpImmBranch(kCondEq, rs_x0, 0, NULL); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 210 | } |
| 211 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 212 | Load32Disp(rs_rA64_SELF, A64_THREAD_THIN_LOCK_ID_OFFSET, rs_x2); |
| 213 | NewLIR3(kA64Ldxr2rX, rx1, rx0, mirror::Object::MonitorOffset().Int32Value() >> 2); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 214 | MarkPossibleNullPointerException(opt_flags); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 215 | LIR* not_unlocked_branch = OpCmpImmBranch(kCondNe, rs_x1, 0, NULL); |
| 216 | NewLIR4(kA64Stxr3wrX, rx1, rx2, rx0, mirror::Object::MonitorOffset().Int32Value() >> 2); |
| 217 | LIR* lock_success_branch = OpCmpImmBranch(kCondEq, rs_x1, 0, NULL); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 218 | |
| 219 | |
| 220 | LIR* slow_path_target = NewLIR0(kPseudoTargetLabel); |
| 221 | not_unlocked_branch->target = slow_path_target; |
| 222 | if (null_check_branch != nullptr) { |
| 223 | null_check_branch->target = slow_path_target; |
| 224 | } |
| 225 | // TODO: move to a slow path. |
| 226 | // Go expensive route - artLockObjectFromCode(obj); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 227 | LoadWordDisp(rs_rA64_SELF, A64_QUICK_ENTRYPOINT_INT_OFFS(pLockObject), rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 228 | ClobberCallerSave(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 229 | LIR* call_inst = OpReg(kOpBlx, rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 230 | MarkSafepointPC(call_inst); |
| 231 | |
| 232 | LIR* success_target = NewLIR0(kPseudoTargetLabel); |
| 233 | lock_success_branch->target = success_target; |
| 234 | GenMemBarrier(kLoadLoad); |
| 235 | } else { |
| 236 | // Explicit null-check as slow-path is entered using an IT. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 237 | GenNullCheck(rs_x0, opt_flags); |
| 238 | Load32Disp(rs_rA64_SELF, A64_THREAD_THIN_LOCK_ID_OFFSET, rs_x2); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 239 | MarkPossibleNullPointerException(opt_flags); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 240 | NewLIR3(kA64Ldxr2rX, rx1, rx0, mirror::Object::MonitorOffset().Int32Value() >> 2); |
| 241 | OpRegImm(kOpCmp, rs_x1, 0); |
| 242 | OpIT(kCondEq, ""); |
| 243 | NewLIR4(kA64Stxr3wrX/*eq*/, rx1, rx2, rx0, mirror::Object::MonitorOffset().Int32Value() >> 2); |
| 244 | OpRegImm(kOpCmp, rs_x1, 0); |
| 245 | OpIT(kCondNe, "T"); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 246 | // Go expensive route - artLockObjectFromCode(self, obj); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 247 | LoadWordDisp/*ne*/(rs_rA64_SELF, A64_QUICK_ENTRYPOINT_INT_OFFS(pLockObject), rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 248 | ClobberCallerSave(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 249 | LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 250 | MarkSafepointPC(call_inst); |
| 251 | GenMemBarrier(kLoadLoad); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Handle thin locked -> unlocked transition inline or else call out to quick entrypoint. For more |
| 257 | * details see monitor.cc. Note the code below doesn't use ldrex/strex as the code holds the lock |
| 258 | * and can only give away ownership if its suspended. |
| 259 | */ |
| 260 | void Arm64Mir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { |
| 261 | FlushAllRegs(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 262 | LoadValueDirectFixed(rl_src, rs_x0); // Get obj |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 263 | LockCallTemps(); // Prepare for explicit register usage |
| 264 | LIR* null_check_branch = nullptr; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 265 | Load32Disp(rs_rA64_SELF, A64_THREAD_THIN_LOCK_ID_OFFSET, rs_x2); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 266 | constexpr bool kArchVariantHasGoodBranchPredictor = false; // TODO: true if cortex-A15. |
| 267 | if (kArchVariantHasGoodBranchPredictor) { |
| 268 | if ((opt_flags & MIR_IGNORE_NULL_CHECK) && !(cu_->disable_opt & (1 << kNullCheckElimination))) { |
| 269 | null_check_branch = nullptr; // No null check. |
| 270 | } else { |
| 271 | // If the null-check fails its handled by the slow-path to reduce exception related meta-data. |
| 272 | if (Runtime::Current()->ExplicitNullChecks()) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 273 | null_check_branch = OpCmpImmBranch(kCondEq, rs_x0, 0, NULL); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 274 | } |
| 275 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 276 | Load32Disp(rs_x0, mirror::Object::MonitorOffset().Int32Value(), rs_x1); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 277 | MarkPossibleNullPointerException(opt_flags); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 278 | LoadConstantNoClobber(rs_x3, 0); |
| 279 | LIR* slow_unlock_branch = OpCmpBranch(kCondNe, rs_x1, rs_x2, NULL); |
| 280 | Store32Disp(rs_x0, mirror::Object::MonitorOffset().Int32Value(), rs_x3); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 281 | LIR* unlock_success_branch = OpUnconditionalBranch(NULL); |
| 282 | |
| 283 | LIR* slow_path_target = NewLIR0(kPseudoTargetLabel); |
| 284 | slow_unlock_branch->target = slow_path_target; |
| 285 | if (null_check_branch != nullptr) { |
| 286 | null_check_branch->target = slow_path_target; |
| 287 | } |
| 288 | // TODO: move to a slow path. |
| 289 | // Go expensive route - artUnlockObjectFromCode(obj); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 290 | LoadWordDisp(rs_rA64_SELF, A64_QUICK_ENTRYPOINT_INT_OFFS(pUnlockObject), rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 291 | ClobberCallerSave(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 292 | LIR* call_inst = OpReg(kOpBlx, rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 293 | MarkSafepointPC(call_inst); |
| 294 | |
| 295 | LIR* success_target = NewLIR0(kPseudoTargetLabel); |
| 296 | unlock_success_branch->target = success_target; |
| 297 | GenMemBarrier(kStoreLoad); |
| 298 | } else { |
| 299 | // Explicit null-check as slow-path is entered using an IT. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 300 | GenNullCheck(rs_x0, opt_flags); |
| 301 | Load32Disp(rs_x0, mirror::Object::MonitorOffset().Int32Value(), rs_x1); // Get lock |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 302 | MarkPossibleNullPointerException(opt_flags); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 303 | Load32Disp(rs_rA64_SELF, Thread::ThinLockIdOffset<4>().Int32Value(), rs_x2); |
| 304 | LoadConstantNoClobber(rs_x3, 0); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 305 | // Is lock unheld on lock or held by us (==thread_id) on unlock? |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 306 | OpRegReg(kOpCmp, rs_x1, rs_x2); |
| 307 | OpIT(kCondEq, "EE"); |
| 308 | Store32Disp/*eq*/(rs_x0, mirror::Object::MonitorOffset().Int32Value(), rs_x3); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 309 | // Go expensive route - UnlockObjectFromCode(obj); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 310 | LoadWordDisp/*ne*/(rs_rA64_SELF, A64_QUICK_ENTRYPOINT_INT_OFFS(pUnlockObject), rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 311 | ClobberCallerSave(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 312 | LIR* call_inst = OpReg(kOpBlx/*ne*/, rs_rA64_LR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 313 | MarkSafepointPC(call_inst); |
| 314 | GenMemBarrier(kStoreLoad); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void Arm64Mir2Lir::GenMoveException(RegLocation rl_dest) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 319 | int ex_offset = A64_THREAD_EXCEPTION_INT_OFFS; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 320 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 321 | RegStorage reset_reg = AllocTemp(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 322 | Load32Disp(rs_rA64_SELF, ex_offset, rl_result.reg); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 323 | LoadConstant(reset_reg, 0); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 324 | Store32Disp(rs_rA64_SELF, ex_offset, reset_reg); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 325 | FreeTemp(reset_reg); |
| 326 | StoreValue(rl_dest, rl_result); |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Mark garbage collection card. Skip if the value we're storing is null. |
| 331 | */ |
| 332 | void Arm64Mir2Lir::MarkGCCard(RegStorage val_reg, RegStorage tgt_addr_reg) { |
| 333 | RegStorage reg_card_base = AllocTemp(); |
| 334 | RegStorage reg_card_no = AllocTemp(); |
| 335 | LIR* branch_over = OpCmpImmBranch(kCondEq, val_reg, 0, NULL); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 336 | LoadWordDisp(rs_rA64_SELF, A64_THREAD_CARD_TABLE_INT_OFFS, reg_card_base); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 337 | OpRegRegImm(kOpLsr, reg_card_no, tgt_addr_reg, gc::accounting::CardTable::kCardShift); |
| 338 | StoreBaseIndexed(reg_card_base, reg_card_no, reg_card_base, 0, kUnsignedByte); |
| 339 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 340 | branch_over->target = target; |
| 341 | FreeTemp(reg_card_base); |
| 342 | FreeTemp(reg_card_no); |
| 343 | } |
| 344 | |
| 345 | void Arm64Mir2Lir::GenEntrySequence(RegLocation* ArgLocs, RegLocation rl_method) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 346 | /* |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 347 | * On entry, x0, x1, x2 & x3 are live. Let the register allocation |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 348 | * mechanism know so it doesn't try to use any of them when |
| 349 | * expanding the frame or flushing. This leaves the utility |
| 350 | * code with a single temp: r12. This should be enough. |
| 351 | */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 352 | LockTemp(rs_x0); |
| 353 | LockTemp(rs_x1); |
| 354 | LockTemp(rs_x2); |
| 355 | LockTemp(rs_x3); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * We can safely skip the stack overflow check if we're |
| 359 | * a leaf *and* our frame size < fudge factor. |
| 360 | */ |
| 361 | bool skip_overflow_check = (mir_graph_->MethodIsLeaf() && |
| 362 | (static_cast<size_t>(frame_size_) < |
| 363 | Thread::kStackOverflowReservedBytes)); |
| 364 | NewLIR0(kPseudoMethodEntry); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 365 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 366 | if (!skip_overflow_check) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 367 | LoadWordDisp(rs_rA64_SELF, A64_THREAD_STACK_END_INT_OFFS, rs_x12); |
| 368 | OpRegImm64(kOpSub, rs_rA64_SP, frame_size_, /*is_wide*/true); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 369 | if (Runtime::Current()->ExplicitStackOverflowChecks()) { |
| 370 | /* Load stack limit */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 371 | // TODO(Arm64): fix the line below: |
| 372 | // GenRegRegCheck(kCondUlt, rA64_SP, r12, kThrowStackOverflow); |
| 373 | } else { |
| 374 | // Implicit stack overflow check. |
| 375 | // Generate a load from [sp, #-framesize]. If this is in the stack |
| 376 | // redzone we will get a segmentation fault. |
| 377 | // TODO(Arm64): does the following really work or do we need a reg != rA64_ZR? |
| 378 | Load32Disp(rs_rA64_SP, 0, rs_wzr); |
| 379 | MarkPossibleStackOverflowException(); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 380 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 381 | } else if (frame_size_ > 0) { |
| 382 | OpRegImm64(kOpSub, rs_rA64_SP, frame_size_, /*is_wide*/true); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 383 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 384 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 385 | /* Spill core callee saves */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 386 | if (core_spill_mask_) { |
| 387 | SpillCoreRegs(rs_rA64_SP, frame_size_, core_spill_mask_); |
| 388 | } |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 389 | /* Need to spill any FP regs? */ |
| 390 | if (num_fp_spills_) { |
| 391 | /* |
| 392 | * NOTE: fp spills are a little different from core spills in that |
| 393 | * they are pushed as a contiguous block. When promoting from |
| 394 | * the fp set, we must allocate all singles from s16..highest-promoted |
| 395 | */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 396 | // TODO(Arm64): SpillFPRegs(rA64_SP, frame_size_, core_spill_mask_); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | FlushIns(ArgLocs, rl_method); |
| 400 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 401 | FreeTemp(rs_x0); |
| 402 | FreeTemp(rs_x1); |
| 403 | FreeTemp(rs_x2); |
| 404 | FreeTemp(rs_x3); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void Arm64Mir2Lir::GenExitSequence() { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 408 | /* |
| 409 | * In the exit path, r0/r1 are live - make sure they aren't |
| 410 | * allocated by the register utilities as temps. |
| 411 | */ |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 412 | LockTemp(rs_x0); |
| 413 | LockTemp(rs_x1); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 414 | |
| 415 | NewLIR0(kPseudoMethodExit); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 416 | /* Need to restore any FP callee saves? */ |
| 417 | if (num_fp_spills_) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 418 | // TODO(Arm64): UnspillFPRegs(num_fp_spills_); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 419 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 420 | if (core_spill_mask_) { |
| 421 | UnSpillCoreRegs(rs_rA64_SP, frame_size_, core_spill_mask_); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 422 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 423 | |
| 424 | OpRegImm64(kOpAdd, rs_rA64_SP, frame_size_, /*is_wide*/true); |
| 425 | NewLIR0(kA64Ret); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void Arm64Mir2Lir::GenSpecialExitSequence() { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 429 | NewLIR0(kA64Ret); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | } // namespace art |