Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 19 | #include "arch/arm/asm_support_arm.h" |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 20 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 23 | #include "common_arm.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 24 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_arm.h" |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 29 | #include "linker/arm/relative_patcher_thumb2.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 32 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "utils/arm/assembler_arm.h" |
| 34 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 39 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 40 | template<class MirrorType> |
| 41 | class GcRoot; |
| 42 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 43 | namespace arm { |
| 44 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 45 | static bool ExpectedPairLayout(Location location) { |
| 46 | // We expected this for both core and fpu register pairs. |
| 47 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 48 | } |
| 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 51 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 53 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 55 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 56 | static constexpr SRegister kFpuCalleeSaves[] = |
| 57 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 58 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 59 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 60 | // S registers. Therefore there is no need to block it. |
| 61 | static constexpr DRegister DTMP = D31; |
| 62 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 63 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 64 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 65 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 66 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 67 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 68 | // the offset explicitly. |
| 69 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 70 | |
| 71 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 72 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 73 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 74 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 75 | |
| 76 | // The reserved entrypoint register for link-time generated thunks. |
| 77 | const Register kBakerCcEntrypointRegister = R4; |
| 78 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 79 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 80 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 81 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 83 | static inline void CheckLastTempIsBakerCcEntrypointRegister(HInstruction* instruction) { |
| 84 | DCHECK_EQ(static_cast<uint32_t>(kBakerCcEntrypointRegister), |
| 85 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 86 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 87 | DCHECK_EQ(kBakerCcEntrypointRegister, |
| 88 | instruction->GetLocations()->GetTemp( |
| 89 | instruction->GetLocations()->GetTempCount() - 1u).AsRegister<Register>()); |
| 90 | } |
| 91 | |
| 92 | static inline void EmitPlaceholderBne(CodeGeneratorARM* codegen, Label* bne_label) { |
| 93 | DCHECK(down_cast<Thumb2Assembler*>(codegen->GetAssembler())->IsForced32Bit()); |
| 94 | __ BindTrackedLabel(bne_label); |
| 95 | Label placeholder_label; |
| 96 | __ b(&placeholder_label, NE); // Placeholder, patched at link-time. |
| 97 | __ Bind(&placeholder_label); |
| 98 | } |
| 99 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 100 | static constexpr int kRegListThreshold = 4; |
| 101 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 102 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 103 | // for each live D registers they treat two corresponding S registers as live ones. |
| 104 | // |
| 105 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 106 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 107 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 108 | // - decreasing code size |
| 109 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 110 | // restored and then used in regular non SlowPath code as D register. |
| 111 | // |
| 112 | // For the following example (v means the S register is live): |
| 113 | // D names: | D0 | D1 | D2 | D4 | ... |
| 114 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 115 | // Live? | | v | v | v | v | v | v | | ... |
| 116 | // |
| 117 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 118 | // as D registers. |
| 119 | static size_t SaveContiguousSRegisterList(size_t first, |
| 120 | size_t last, |
| 121 | CodeGenerator* codegen, |
| 122 | size_t stack_offset) { |
| 123 | DCHECK_LE(first, last); |
| 124 | if ((first == last) && (first == 0)) { |
| 125 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 126 | return stack_offset; |
| 127 | } |
| 128 | if (first % 2 == 1) { |
| 129 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 130 | } |
| 131 | |
| 132 | bool save_last = false; |
| 133 | if (last % 2 == 0) { |
| 134 | save_last = true; |
| 135 | --last; |
| 136 | } |
| 137 | |
| 138 | if (first < last) { |
| 139 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 140 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 141 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 142 | |
| 143 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 144 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 145 | } else if (number_of_d_regs > 1) { |
| 146 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 147 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 148 | } |
| 149 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 150 | } |
| 151 | |
| 152 | if (save_last) { |
| 153 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 154 | } |
| 155 | |
| 156 | return stack_offset; |
| 157 | } |
| 158 | |
| 159 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 160 | size_t last, |
| 161 | CodeGenerator* codegen, |
| 162 | size_t stack_offset) { |
| 163 | DCHECK_LE(first, last); |
| 164 | if ((first == last) && (first == 0)) { |
| 165 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 166 | return stack_offset; |
| 167 | } |
| 168 | if (first % 2 == 1) { |
| 169 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 170 | } |
| 171 | |
| 172 | bool restore_last = false; |
| 173 | if (last % 2 == 0) { |
| 174 | restore_last = true; |
| 175 | --last; |
| 176 | } |
| 177 | |
| 178 | if (first < last) { |
| 179 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 180 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 181 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 182 | if (number_of_d_regs == 1) { |
| 183 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 184 | } else if (number_of_d_regs > 1) { |
| 185 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 186 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 187 | } |
| 188 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 189 | } |
| 190 | |
| 191 | if (restore_last) { |
| 192 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 193 | } |
| 194 | |
| 195 | return stack_offset; |
| 196 | } |
| 197 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 199 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 200 | size_t orig_offset = stack_offset; |
| 201 | |
| 202 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 203 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 204 | // If the register holds an object, update the stack mask. |
| 205 | if (locations->RegisterContainsObject(i)) { |
| 206 | locations->SetStackBit(stack_offset / kVRegSize); |
| 207 | } |
| 208 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 209 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 210 | saved_core_stack_offsets_[i] = stack_offset; |
| 211 | stack_offset += kArmWordSize; |
| 212 | } |
| 213 | |
| 214 | int reg_num = POPCOUNT(core_spills); |
| 215 | if (reg_num != 0) { |
| 216 | if (reg_num > kRegListThreshold) { |
| 217 | __ StoreList(RegList(core_spills), orig_offset); |
| 218 | } else { |
| 219 | stack_offset = orig_offset; |
| 220 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 221 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 226 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 227 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 228 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 229 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 230 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 231 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 232 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 233 | |
| 234 | stack_offset = orig_offset; |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 241 | } |
| 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 246 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 247 | size_t orig_offset = stack_offset; |
| 248 | |
| 249 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 250 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 251 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 252 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 253 | stack_offset += kArmWordSize; |
| 254 | } |
| 255 | |
| 256 | int reg_num = POPCOUNT(core_spills); |
| 257 | if (reg_num != 0) { |
| 258 | if (reg_num > kRegListThreshold) { |
| 259 | __ LoadList(RegList(core_spills), orig_offset); |
| 260 | } else { |
| 261 | stack_offset = orig_offset; |
| 262 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 263 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 268 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 269 | while (fp_spills != 0u) { |
| 270 | uint32_t begin = CTZ(fp_spills); |
| 271 | uint32_t tmp = fp_spills + (1u << begin); |
| 272 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 273 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 274 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 275 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 276 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 280 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 281 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 282 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 283 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 284 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 285 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 286 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 287 | // Live registers will be restored in the catch block if caught. |
| 288 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 289 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 290 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 291 | instruction_, |
| 292 | instruction_->GetDexPc(), |
| 293 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 294 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 297 | bool IsFatal() const OVERRIDE { return true; } |
| 298 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 299 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 300 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 301 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 302 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 303 | }; |
| 304 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 305 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 306 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 307 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 308 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 310 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 311 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 312 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 313 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 316 | bool IsFatal() const OVERRIDE { return true; } |
| 317 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 318 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 319 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 320 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 321 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 322 | }; |
| 323 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 324 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 325 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 327 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 328 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 330 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 331 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 332 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 333 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 334 | if (successor_ == nullptr) { |
| 335 | __ b(GetReturnLabel()); |
| 336 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 337 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 338 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 341 | Label* GetReturnLabel() { |
| 342 | DCHECK(successor_ == nullptr); |
| 343 | return &return_label_; |
| 344 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 346 | HBasicBlock* GetSuccessor() const { |
| 347 | return successor_; |
| 348 | } |
| 349 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 350 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 351 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 352 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 353 | // If not null, the block to branch to after the suspend check. |
| 354 | HBasicBlock* const successor_; |
| 355 | |
| 356 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 357 | Label return_label_; |
| 358 | |
| 359 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 360 | }; |
| 361 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 362 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 363 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 364 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 365 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 366 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 367 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 368 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 369 | LocationSummary* locations = instruction_->GetLocations(); |
| 370 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 371 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 372 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 373 | // Live registers will be restored in the catch block if caught. |
| 374 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 375 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 376 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 377 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 378 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 379 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 380 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 381 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 382 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 383 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 385 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 386 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 387 | ? kQuickThrowStringBounds |
| 388 | : kQuickThrowArrayBounds; |
| 389 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 390 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 391 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 394 | bool IsFatal() const OVERRIDE { return true; } |
| 395 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 396 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 397 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 398 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 400 | }; |
| 401 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 402 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 403 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 404 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 405 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 406 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 407 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 408 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 409 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 410 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 411 | Location out = locations->Out(); |
| 412 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 413 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 414 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 415 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 416 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 417 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 418 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 419 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 420 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 421 | bool is_load_class_bss_entry = |
| 422 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 423 | Register entry_address = kNoRegister; |
| 424 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 425 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 426 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 427 | // the kSaveEverything call. |
| 428 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 429 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 430 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 431 | if (temp_is_r0) { |
| 432 | __ mov(entry_address, ShifterOperand(temp)); |
| 433 | } |
| 434 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 435 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 436 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 437 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 438 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 439 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 440 | if (do_clinit_) { |
| 441 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 442 | } else { |
| 443 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 444 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 445 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 446 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 447 | if (is_load_class_bss_entry) { |
| 448 | if (call_saves_everything_except_r0) { |
| 449 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 450 | __ str(R0, Address(entry_address)); |
| 451 | } else { |
| 452 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 453 | Register temp = IP; |
| 454 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 455 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 456 | __ BindTrackedLabel(&labels->movw_label); |
| 457 | __ movw(temp, /* placeholder */ 0u); |
| 458 | __ BindTrackedLabel(&labels->movt_label); |
| 459 | __ movt(temp, /* placeholder */ 0u); |
| 460 | __ BindTrackedLabel(&labels->add_pc_label); |
| 461 | __ add(temp, temp, ShifterOperand(PC)); |
| 462 | __ str(R0, Address(temp)); |
| 463 | } |
| 464 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 465 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 466 | if (out.IsValid()) { |
| 467 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 468 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 469 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 470 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 471 | __ b(GetExitLabel()); |
| 472 | } |
| 473 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 474 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 475 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 476 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 477 | // The class this slow path will load. |
| 478 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 479 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 480 | // The dex PC of `at_`. |
| 481 | const uint32_t dex_pc_; |
| 482 | |
| 483 | // Whether to initialize the class. |
| 484 | const bool do_clinit_; |
| 485 | |
| 486 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 487 | }; |
| 488 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 489 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 490 | public: |
| 491 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 492 | |
| 493 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 494 | DCHECK(instruction_->IsLoadString()); |
| 495 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 496 | LocationSummary* locations = instruction_->GetLocations(); |
| 497 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 498 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 499 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 500 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 501 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 502 | |
| 503 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 504 | __ Bind(GetEntryLabel()); |
| 505 | SaveLiveRegisters(codegen, locations); |
| 506 | |
| 507 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 508 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 509 | // the kSaveEverything call. |
| 510 | Register entry_address = kNoRegister; |
| 511 | if (call_saves_everything_except_r0) { |
| 512 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 513 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 514 | entry_address = temp_is_r0 ? out : temp; |
| 515 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 516 | if (temp_is_r0) { |
| 517 | __ mov(entry_address, ShifterOperand(temp)); |
| 518 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 519 | } |
| 520 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 521 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 522 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 523 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 524 | |
| 525 | // Store the resolved String to the .bss entry. |
| 526 | if (call_saves_everything_except_r0) { |
| 527 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 528 | __ str(R0, Address(entry_address)); |
| 529 | } else { |
| 530 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 531 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 532 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 533 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 534 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 535 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 536 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 537 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 538 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 539 | __ add(temp, temp, ShifterOperand(PC)); |
| 540 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 543 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 544 | RestoreLiveRegisters(codegen, locations); |
| 545 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 546 | __ b(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 550 | |
| 551 | private: |
| 552 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 553 | }; |
| 554 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 555 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 556 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 557 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 558 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 559 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 560 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 561 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 562 | DCHECK(instruction_->IsCheckCast() |
| 563 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 564 | |
| 565 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 566 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 567 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 568 | if (!is_fatal_) { |
| 569 | SaveLiveRegisters(codegen, locations); |
| 570 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 571 | |
| 572 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 573 | // move resolver. |
| 574 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 575 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 576 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 577 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 578 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 579 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 580 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 581 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 582 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 583 | instruction_, |
| 584 | instruction_->GetDexPc(), |
| 585 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 586 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 587 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 588 | } else { |
| 589 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 590 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 591 | instruction_, |
| 592 | instruction_->GetDexPc(), |
| 593 | this); |
| 594 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 595 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 596 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 597 | if (!is_fatal_) { |
| 598 | RestoreLiveRegisters(codegen, locations); |
| 599 | __ b(GetExitLabel()); |
| 600 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 603 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 604 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 605 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 606 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 607 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 608 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 609 | |
| 610 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 611 | }; |
| 612 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 613 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 614 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 615 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 616 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 617 | |
| 618 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 619 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 620 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 621 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 622 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 625 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 626 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 627 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 628 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 629 | }; |
| 630 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 631 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 632 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 633 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 634 | |
| 635 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 636 | LocationSummary* locations = instruction_->GetLocations(); |
| 637 | __ Bind(GetEntryLabel()); |
| 638 | SaveLiveRegisters(codegen, locations); |
| 639 | |
| 640 | InvokeRuntimeCallingConvention calling_convention; |
| 641 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 642 | parallel_move.AddMove( |
| 643 | locations->InAt(0), |
| 644 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 645 | Primitive::kPrimNot, |
| 646 | nullptr); |
| 647 | parallel_move.AddMove( |
| 648 | locations->InAt(1), |
| 649 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 650 | Primitive::kPrimInt, |
| 651 | nullptr); |
| 652 | parallel_move.AddMove( |
| 653 | locations->InAt(2), |
| 654 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 655 | Primitive::kPrimNot, |
| 656 | nullptr); |
| 657 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 658 | |
| 659 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 660 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 661 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 662 | RestoreLiveRegisters(codegen, locations); |
| 663 | __ b(GetExitLabel()); |
| 664 | } |
| 665 | |
| 666 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 667 | |
| 668 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 669 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 670 | }; |
| 671 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 672 | // Abstract base class for read barrier slow paths marking a reference |
| 673 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 674 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 675 | // Argument `entrypoint` must be a register location holding the read |
| 676 | // barrier marking runtime entry point to be invoked. |
| 677 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 678 | protected: |
| 679 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 680 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 681 | DCHECK(kEmitCompilerReadBarrier); |
| 682 | } |
| 683 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 685 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 686 | // Generate assembly code calling the read barrier marking runtime |
| 687 | // entry point (ReadBarrierMarkRegX). |
| 688 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 689 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 690 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 691 | // No need to save live registers; it's taken care of by the |
| 692 | // entrypoint. Also, there is no need to update the stack mask, |
| 693 | // as this runtime call will not trigger a garbage collection. |
| 694 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 695 | DCHECK_NE(ref_reg, SP); |
| 696 | DCHECK_NE(ref_reg, LR); |
| 697 | DCHECK_NE(ref_reg, PC); |
| 698 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 699 | // as a temporary, it cannot be the entry point's input/output. |
| 700 | DCHECK_NE(ref_reg, IP); |
| 701 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 702 | // "Compact" slow path, saving two moves. |
| 703 | // |
| 704 | // Instead of using the standard runtime calling convention (input |
| 705 | // and output in R0): |
| 706 | // |
| 707 | // R0 <- ref |
| 708 | // R0 <- ReadBarrierMark(R0) |
| 709 | // ref <- R0 |
| 710 | // |
| 711 | // we just use rX (the register containing `ref`) as input and output |
| 712 | // of a dedicated entrypoint: |
| 713 | // |
| 714 | // rX <- ReadBarrierMarkRegX(rX) |
| 715 | // |
| 716 | if (entrypoint_.IsValid()) { |
| 717 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 718 | __ blx(entrypoint_.AsRegister<Register>()); |
| 719 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 720 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 721 | int32_t entry_point_offset = |
| 722 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 723 | // This runtime call does not require a stack map. |
| 724 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 725 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | // The location (register) of the marked object reference. |
| 729 | const Location ref_; |
| 730 | |
| 731 | // The location of the entrypoint if it is already loaded. |
| 732 | const Location entrypoint_; |
| 733 | |
| 734 | private: |
| 735 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 736 | }; |
| 737 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 738 | // Slow path marking an object reference `ref` during a read |
| 739 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 740 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 741 | // |
| 742 | // This means that after the execution of this slow path, `ref` will |
| 743 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 744 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 745 | // probably still be a from-space reference (unless it gets updated by |
| 746 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 747 | // reference (different from `ref`) in `obj.field`). |
| 748 | // |
| 749 | // If `entrypoint` is a valid location it is assumed to already be |
| 750 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 751 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 752 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 753 | public: |
| 754 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 755 | Location ref, |
| 756 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 757 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 758 | DCHECK(kEmitCompilerReadBarrier); |
| 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 762 | |
| 763 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 764 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 765 | DCHECK(locations->CanCall()); |
| 766 | if (kIsDebugBuild) { |
| 767 | Register ref_reg = ref_.AsRegister<Register>(); |
| 768 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 769 | } |
| 770 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 771 | << "Unexpected instruction in read barrier marking slow path: " |
| 772 | << instruction_->DebugName(); |
| 773 | |
| 774 | __ Bind(GetEntryLabel()); |
| 775 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 776 | __ b(GetExitLabel()); |
| 777 | } |
| 778 | |
| 779 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 780 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 781 | }; |
| 782 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 783 | // Slow path loading `obj`'s lock word, loading a reference from |
| 784 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 785 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 786 | // read barrier). The field `obj.field` in the object `obj` holding |
| 787 | // this reference does not get updated by this slow path after marking |
| 788 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 789 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 790 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 791 | // This means that after the execution of this slow path, `ref` will |
| 792 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 793 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 794 | // probably still be a from-space reference (unless it gets updated by |
| 795 | // another thread, or if another thread installed another object |
| 796 | // reference (different from `ref`) in `obj.field`). |
| 797 | // |
| 798 | // Argument `entrypoint` must be a register location holding the read |
| 799 | // barrier marking runtime entry point to be invoked. |
| 800 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 801 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 802 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 803 | Location ref, |
| 804 | Register obj, |
| 805 | uint32_t offset, |
| 806 | Location index, |
| 807 | ScaleFactor scale_factor, |
| 808 | bool needs_null_check, |
| 809 | Register temp, |
| 810 | Location entrypoint) |
| 811 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 812 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | offset_(offset), |
| 814 | index_(index), |
| 815 | scale_factor_(scale_factor), |
| 816 | needs_null_check_(needs_null_check), |
| 817 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 818 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 819 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 822 | const char* GetDescription() const OVERRIDE { |
| 823 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 824 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 825 | |
| 826 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 827 | LocationSummary* locations = instruction_->GetLocations(); |
| 828 | Register ref_reg = ref_.AsRegister<Register>(); |
| 829 | DCHECK(locations->CanCall()); |
| 830 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 831 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 832 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 833 | instruction_->IsStaticFieldGet() || |
| 834 | instruction_->IsArrayGet() || |
| 835 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 836 | instruction_->IsInstanceOf() || |
| 837 | instruction_->IsCheckCast() || |
| 838 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 839 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 840 | << "Unexpected instruction in read barrier marking slow path: " |
| 841 | << instruction_->DebugName(); |
| 842 | // The read barrier instrumentation of object ArrayGet |
| 843 | // instructions does not support the HIntermediateAddress |
| 844 | // instruction. |
| 845 | DCHECK(!(instruction_->IsArrayGet() && |
| 846 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 847 | |
| 848 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 849 | |
| 850 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 851 | // inserted after the original load. However, in fast path based |
| 852 | // Baker's read barriers, we need to perform the load of |
| 853 | // mirror::Object::monitor_ *before* the original reference load. |
| 854 | // This load-load ordering is required by the read barrier. |
| 855 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 856 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 857 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 858 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 859 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 860 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 861 | // if (is_gray) { |
| 862 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 863 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 864 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 865 | // Note: the original implementation in ReadBarrier::Barrier is |
| 866 | // slightly more complex as it performs additional checks that we do |
| 867 | // not do here for performance reasons. |
| 868 | |
| 869 | // /* int32_t */ monitor = obj->monitor_ |
| 870 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 871 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 872 | if (needs_null_check_) { |
| 873 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 874 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 875 | // /* LockWord */ lock_word = LockWord(monitor) |
| 876 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 877 | "art::LockWord and int32_t have different sizes."); |
| 878 | |
| 879 | // Introduce a dependency on the lock_word including the rb_state, |
| 880 | // which shall prevent load-load reordering without using |
| 881 | // a memory barrier (which would be more expensive). |
| 882 | // `obj` is unchanged by this operation, but its value now depends |
| 883 | // on `temp`. |
| 884 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 885 | |
| 886 | // The actual reference load. |
| 887 | // A possible implicit null check has already been handled above. |
| 888 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 889 | arm_codegen->GenerateRawReferenceLoad( |
| 890 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 891 | |
| 892 | // Mark the object `ref` when `obj` is gray. |
| 893 | // |
| 894 | // if (rb_state == ReadBarrier::GrayState()) |
| 895 | // ref = ReadBarrier::Mark(ref); |
| 896 | // |
| 897 | // Given the numeric representation, it's enough to check the low bit of the |
| 898 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 899 | // which can be a 16-bit instruction unlike the TST immediate. |
| 900 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 901 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 902 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 903 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 904 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 905 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 906 | __ b(GetExitLabel()); |
| 907 | } |
| 908 | |
| 909 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 910 | // The register containing the object holding the marked object reference field. |
| 911 | Register obj_; |
| 912 | // The offset, index and scale factor to access the reference in `obj_`. |
| 913 | uint32_t offset_; |
| 914 | Location index_; |
| 915 | ScaleFactor scale_factor_; |
| 916 | // Is a null check required? |
| 917 | bool needs_null_check_; |
| 918 | // A temporary register used to hold the lock word of `obj_`. |
| 919 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 920 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 921 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 922 | }; |
| 923 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 924 | // Slow path loading `obj`'s lock word, loading a reference from |
| 925 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 926 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 927 | // read barrier). If needed, this slow path also atomically updates |
| 928 | // the field `obj.field` in the object `obj` holding this reference |
| 929 | // after marking (contrary to |
| 930 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 931 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 932 | // |
| 933 | // This means that after the execution of this slow path, both `ref` |
| 934 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 935 | // hold the same to-space reference (unless another thread installed |
| 936 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 937 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 938 | // Argument `entrypoint` must be a register location holding the read |
| 939 | // barrier marking runtime entry point to be invoked. |
| 940 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 941 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 942 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 943 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 944 | Location ref, |
| 945 | Register obj, |
| 946 | uint32_t offset, |
| 947 | Location index, |
| 948 | ScaleFactor scale_factor, |
| 949 | bool needs_null_check, |
| 950 | Register temp1, |
| 951 | Register temp2, |
| 952 | Location entrypoint) |
| 953 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 954 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 955 | offset_(offset), |
| 956 | index_(index), |
| 957 | scale_factor_(scale_factor), |
| 958 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 959 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 960 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 961 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 962 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 965 | const char* GetDescription() const OVERRIDE { |
| 966 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 967 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 968 | |
| 969 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 970 | LocationSummary* locations = instruction_->GetLocations(); |
| 971 | Register ref_reg = ref_.AsRegister<Register>(); |
| 972 | DCHECK(locations->CanCall()); |
| 973 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | DCHECK_NE(ref_reg, temp1_); |
| 975 | |
| 976 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 977 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 978 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 979 | << instruction_->DebugName(); |
| 980 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 981 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | DCHECK_EQ(offset_, 0u); |
| 983 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 984 | // The location of the offset of the marked reference field within `obj_`. |
| 985 | Location field_offset = index_; |
| 986 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 987 | |
| 988 | __ Bind(GetEntryLabel()); |
| 989 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 990 | // /* int32_t */ monitor = obj->monitor_ |
| 991 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 992 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 993 | if (needs_null_check_) { |
| 994 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 995 | } |
| 996 | // /* LockWord */ lock_word = LockWord(monitor) |
| 997 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 998 | "art::LockWord and int32_t have different sizes."); |
| 999 | |
| 1000 | // Introduce a dependency on the lock_word including the rb_state, |
| 1001 | // which shall prevent load-load reordering without using |
| 1002 | // a memory barrier (which would be more expensive). |
| 1003 | // `obj` is unchanged by this operation, but its value now depends |
| 1004 | // on `temp1`. |
| 1005 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 1006 | |
| 1007 | // The actual reference load. |
| 1008 | // A possible implicit null check has already been handled above. |
| 1009 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1010 | arm_codegen->GenerateRawReferenceLoad( |
| 1011 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1012 | |
| 1013 | // Mark the object `ref` when `obj` is gray. |
| 1014 | // |
| 1015 | // if (rb_state == ReadBarrier::GrayState()) |
| 1016 | // ref = ReadBarrier::Mark(ref); |
| 1017 | // |
| 1018 | // Given the numeric representation, it's enough to check the low bit of the |
| 1019 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1020 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1021 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1022 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1023 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1024 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 1025 | |
| 1026 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1027 | // Note that we cannot use IP to save the old reference, as IP is |
| 1028 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1029 | // need the old reference after the call to that entry point. |
| 1030 | DCHECK_NE(temp1_, IP); |
| 1031 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1032 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1033 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1034 | |
| 1035 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1036 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1037 | // |
| 1038 | // Note that this field could also hold a different object, if |
| 1039 | // another thread had concurrently changed it. In that case, the |
| 1040 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1041 | // (CAS) operation below would abort the CAS, leaving the field |
| 1042 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1043 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1044 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1045 | |
| 1046 | // Update the the holder's field atomically. This may fail if |
| 1047 | // mutator updates before us, but it's OK. This is achieved |
| 1048 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1049 | // memory synchronization ordering, where the expected value is |
| 1050 | // the old reference and the desired value is the new reference. |
| 1051 | |
| 1052 | // Convenience aliases. |
| 1053 | Register base = obj_; |
| 1054 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1055 | // offset ("long offset"), of which only the low part contains |
| 1056 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1057 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1058 | Register expected = temp1_; |
| 1059 | Register value = ref_reg; |
| 1060 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1061 | Register tmp = temp2_; // Value in memory. |
| 1062 | |
| 1063 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1064 | |
| 1065 | if (kPoisonHeapReferences) { |
| 1066 | __ PoisonHeapReference(expected); |
| 1067 | if (value == expected) { |
| 1068 | // Do not poison `value`, as it is the same register as |
| 1069 | // `expected`, which has just been poisoned. |
| 1070 | } else { |
| 1071 | __ PoisonHeapReference(value); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | // do { |
| 1076 | // tmp = [r_ptr] - expected; |
| 1077 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1078 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1079 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1080 | __ Bind(&loop_head); |
| 1081 | |
| 1082 | __ ldrex(tmp, tmp_ptr); |
| 1083 | |
| 1084 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1085 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1086 | __ it(NE); |
| 1087 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1088 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1089 | __ b(&exit_loop, NE); |
| 1090 | |
| 1091 | __ strex(tmp, value, tmp_ptr); |
| 1092 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1093 | __ b(&loop_head, EQ); |
| 1094 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1095 | __ Bind(&exit_loop); |
| 1096 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1097 | if (kPoisonHeapReferences) { |
| 1098 | __ UnpoisonHeapReference(expected); |
| 1099 | if (value == expected) { |
| 1100 | // Do not unpoison `value`, as it is the same register as |
| 1101 | // `expected`, which has just been unpoisoned. |
| 1102 | } else { |
| 1103 | __ UnpoisonHeapReference(value); |
| 1104 | } |
| 1105 | } |
| 1106 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1107 | __ b(GetExitLabel()); |
| 1108 | } |
| 1109 | |
| 1110 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1111 | // The register containing the object holding the marked object reference field. |
| 1112 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1113 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1114 | uint32_t offset_; |
| 1115 | Location index_; |
| 1116 | ScaleFactor scale_factor_; |
| 1117 | // Is a null check required? |
| 1118 | bool needs_null_check_; |
| 1119 | // A temporary register used to hold the lock word of `obj_`; and |
| 1120 | // also to hold the original reference value, when the reference is |
| 1121 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1122 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1123 | // A temporary register used in the implementation of the CAS, to |
| 1124 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1125 | const Register temp2_; |
| 1126 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1127 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1128 | }; |
| 1129 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1130 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1131 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1132 | public: |
| 1133 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1134 | Location out, |
| 1135 | Location ref, |
| 1136 | Location obj, |
| 1137 | uint32_t offset, |
| 1138 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1139 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1140 | out_(out), |
| 1141 | ref_(ref), |
| 1142 | obj_(obj), |
| 1143 | offset_(offset), |
| 1144 | index_(index) { |
| 1145 | DCHECK(kEmitCompilerReadBarrier); |
| 1146 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1147 | // has been overwritten by (or after) the heap object reference load |
| 1148 | // to be instrumented, e.g.: |
| 1149 | // |
| 1150 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1151 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1152 | // |
| 1153 | // In that case, we have lost the information about the original |
| 1154 | // object, and the emitted read barrier cannot work properly. |
| 1155 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1156 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1157 | } |
| 1158 | |
| 1159 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1160 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1161 | LocationSummary* locations = instruction_->GetLocations(); |
| 1162 | Register reg_out = out_.AsRegister<Register>(); |
| 1163 | DCHECK(locations->CanCall()); |
| 1164 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1165 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1166 | instruction_->IsStaticFieldGet() || |
| 1167 | instruction_->IsArrayGet() || |
| 1168 | instruction_->IsInstanceOf() || |
| 1169 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1170 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1171 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1172 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1173 | // The read barrier instrumentation of object ArrayGet |
| 1174 | // instructions does not support the HIntermediateAddress |
| 1175 | // instruction. |
| 1176 | DCHECK(!(instruction_->IsArrayGet() && |
| 1177 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1178 | |
| 1179 | __ Bind(GetEntryLabel()); |
| 1180 | SaveLiveRegisters(codegen, locations); |
| 1181 | |
| 1182 | // We may have to change the index's value, but as `index_` is a |
| 1183 | // constant member (like other "inputs" of this slow path), |
| 1184 | // introduce a copy of it, `index`. |
| 1185 | Location index = index_; |
| 1186 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1187 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1188 | if (instruction_->IsArrayGet()) { |
| 1189 | // Compute the actual memory offset and store it in `index`. |
| 1190 | Register index_reg = index_.AsRegister<Register>(); |
| 1191 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1192 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1193 | // We are about to change the value of `index_reg` (see the |
| 1194 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1195 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1196 | // not been saved by the previous call to |
| 1197 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1198 | // callee-save register -- |
| 1199 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1200 | // callee-save registers, as it has been designed with the |
| 1201 | // assumption that callee-save registers are supposed to be |
| 1202 | // handled by the called function. So, as a callee-save |
| 1203 | // register, `index_reg` _would_ eventually be saved onto |
| 1204 | // the stack, but it would be too late: we would have |
| 1205 | // changed its value earlier. Therefore, we manually save |
| 1206 | // it here into another freely available register, |
| 1207 | // `free_reg`, chosen of course among the caller-save |
| 1208 | // registers (as a callee-save `free_reg` register would |
| 1209 | // exhibit the same problem). |
| 1210 | // |
| 1211 | // Note we could have requested a temporary register from |
| 1212 | // the register allocator instead; but we prefer not to, as |
| 1213 | // this is a slow path, and we know we can find a |
| 1214 | // caller-save register that is available. |
| 1215 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1216 | __ Mov(free_reg, index_reg); |
| 1217 | index_reg = free_reg; |
| 1218 | index = Location::RegisterLocation(index_reg); |
| 1219 | } else { |
| 1220 | // The initial register stored in `index_` has already been |
| 1221 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1222 | // (as it is not a callee-save register), so we can freely |
| 1223 | // use it. |
| 1224 | } |
| 1225 | // Shifting the index value contained in `index_reg` by the scale |
| 1226 | // factor (2) cannot overflow in practice, as the runtime is |
| 1227 | // unable to allocate object arrays with a size larger than |
| 1228 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1229 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1230 | static_assert( |
| 1231 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1232 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1233 | __ AddConstant(index_reg, index_reg, offset_); |
| 1234 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1235 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1236 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1237 | // (as in the case of ArrayGet), as it is actually an offset |
| 1238 | // to an object field within an object. |
| 1239 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1240 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1241 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1242 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1243 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1244 | DCHECK_EQ(offset_, 0U); |
| 1245 | DCHECK(index_.IsRegisterPair()); |
| 1246 | // UnsafeGet's offset location is a register pair, the low |
| 1247 | // part contains the correct offset. |
| 1248 | index = index_.ToLow(); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | // We're moving two or three locations to locations that could |
| 1253 | // overlap, so we need a parallel move resolver. |
| 1254 | InvokeRuntimeCallingConvention calling_convention; |
| 1255 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1256 | parallel_move.AddMove(ref_, |
| 1257 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1258 | Primitive::kPrimNot, |
| 1259 | nullptr); |
| 1260 | parallel_move.AddMove(obj_, |
| 1261 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1262 | Primitive::kPrimNot, |
| 1263 | nullptr); |
| 1264 | if (index.IsValid()) { |
| 1265 | parallel_move.AddMove(index, |
| 1266 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1267 | Primitive::kPrimInt, |
| 1268 | nullptr); |
| 1269 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1270 | } else { |
| 1271 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1272 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1273 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1274 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1275 | CheckEntrypointTypes< |
| 1276 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1277 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1278 | |
| 1279 | RestoreLiveRegisters(codegen, locations); |
| 1280 | __ b(GetExitLabel()); |
| 1281 | } |
| 1282 | |
| 1283 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1284 | |
| 1285 | private: |
| 1286 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1287 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1288 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1289 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1290 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1291 | return static_cast<Register>(i); |
| 1292 | } |
| 1293 | } |
| 1294 | // We shall never fail to find a free caller-save register, as |
| 1295 | // there are more than two core caller-save registers on ARM |
| 1296 | // (meaning it is possible to find one which is different from |
| 1297 | // `ref` and `obj`). |
| 1298 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1299 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1300 | UNREACHABLE(); |
| 1301 | } |
| 1302 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1303 | const Location out_; |
| 1304 | const Location ref_; |
| 1305 | const Location obj_; |
| 1306 | const uint32_t offset_; |
| 1307 | // An additional location containing an index to an array. |
| 1308 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1309 | // UnsafeGetObjectVolatile intrinsics. |
| 1310 | const Location index_; |
| 1311 | |
| 1312 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1313 | }; |
| 1314 | |
| 1315 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1316 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1317 | public: |
| 1318 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1319 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1320 | DCHECK(kEmitCompilerReadBarrier); |
| 1321 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1322 | |
| 1323 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1324 | LocationSummary* locations = instruction_->GetLocations(); |
| 1325 | Register reg_out = out_.AsRegister<Register>(); |
| 1326 | DCHECK(locations->CanCall()); |
| 1327 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1328 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1329 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1330 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1331 | |
| 1332 | __ Bind(GetEntryLabel()); |
| 1333 | SaveLiveRegisters(codegen, locations); |
| 1334 | |
| 1335 | InvokeRuntimeCallingConvention calling_convention; |
| 1336 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1337 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1338 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1339 | instruction_, |
| 1340 | instruction_->GetDexPc(), |
| 1341 | this); |
| 1342 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1343 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1344 | |
| 1345 | RestoreLiveRegisters(codegen, locations); |
| 1346 | __ b(GetExitLabel()); |
| 1347 | } |
| 1348 | |
| 1349 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1350 | |
| 1351 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1352 | const Location out_; |
| 1353 | const Location root_; |
| 1354 | |
| 1355 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1356 | }; |
| 1357 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1358 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1359 | switch (cond) { |
| 1360 | case kCondEQ: return EQ; |
| 1361 | case kCondNE: return NE; |
| 1362 | case kCondLT: return LT; |
| 1363 | case kCondLE: return LE; |
| 1364 | case kCondGT: return GT; |
| 1365 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1366 | case kCondB: return LO; |
| 1367 | case kCondBE: return LS; |
| 1368 | case kCondA: return HI; |
| 1369 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1370 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | LOG(FATAL) << "Unreachable"; |
| 1372 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1375 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1376 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1377 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1378 | case kCondEQ: return EQ; |
| 1379 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1380 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1381 | case kCondLT: return LO; |
| 1382 | case kCondLE: return LS; |
| 1383 | case kCondGT: return HI; |
| 1384 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1385 | // Unsigned remain unchanged. |
| 1386 | case kCondB: return LO; |
| 1387 | case kCondBE: return LS; |
| 1388 | case kCondA: return HI; |
| 1389 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1390 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1391 | LOG(FATAL) << "Unreachable"; |
| 1392 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1395 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1396 | // The ARM condition codes can express all the necessary branches, see the |
| 1397 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1398 | // There is no dex instruction or HIR that would need the missing conditions |
| 1399 | // "equal or unordered" or "not equal". |
| 1400 | switch (cond) { |
| 1401 | case kCondEQ: return EQ; |
| 1402 | case kCondNE: return NE /* unordered */; |
| 1403 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1404 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1405 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1406 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1407 | default: |
| 1408 | LOG(FATAL) << "UNREACHABLE"; |
| 1409 | UNREACHABLE(); |
| 1410 | } |
| 1411 | } |
| 1412 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1413 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1414 | switch (op_kind) { |
| 1415 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1416 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1417 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1418 | default: |
| 1419 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1420 | UNREACHABLE(); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1425 | Register out, |
| 1426 | Register first, |
| 1427 | const ShifterOperand& second, |
| 1428 | CodeGeneratorARM* codegen) { |
| 1429 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1430 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1431 | ? ShifterOperand(0) |
| 1432 | : ShifterOperand(first); |
| 1433 | |
| 1434 | __ mov(out, in); |
| 1435 | } else { |
| 1436 | switch (kind) { |
| 1437 | case HInstruction::kAdd: |
| 1438 | __ add(out, first, second); |
| 1439 | break; |
| 1440 | case HInstruction::kAnd: |
| 1441 | __ and_(out, first, second); |
| 1442 | break; |
| 1443 | case HInstruction::kOr: |
| 1444 | __ orr(out, first, second); |
| 1445 | break; |
| 1446 | case HInstruction::kSub: |
| 1447 | __ sub(out, first, second); |
| 1448 | break; |
| 1449 | case HInstruction::kXor: |
| 1450 | __ eor(out, first, second); |
| 1451 | break; |
| 1452 | default: |
| 1453 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1454 | UNREACHABLE(); |
| 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1460 | const Location& out, |
| 1461 | const Location& first, |
| 1462 | const ShifterOperand& second_lo, |
| 1463 | const ShifterOperand& second_hi, |
| 1464 | CodeGeneratorARM* codegen) { |
| 1465 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1466 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1467 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1468 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1469 | |
| 1470 | if (kind == HInstruction::kAdd) { |
| 1471 | __ adds(out_lo, first_lo, second_lo); |
| 1472 | __ adc(out_hi, first_hi, second_hi); |
| 1473 | } else if (kind == HInstruction::kSub) { |
| 1474 | __ subs(out_lo, first_lo, second_lo); |
| 1475 | __ sbc(out_hi, first_hi, second_hi); |
| 1476 | } else { |
| 1477 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1478 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1483 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1484 | } |
| 1485 | |
| 1486 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1487 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1488 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1489 | |
| 1490 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1491 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1492 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1493 | const Location first = locations->InAt(0); |
| 1494 | const Location second = locations->InAt(1); |
| 1495 | const Location out = locations->Out(); |
| 1496 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1497 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1498 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1499 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1500 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1501 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1502 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1503 | |
| 1504 | if (shift_value >= 32) { |
| 1505 | if (shift == LSL) { |
| 1506 | GenerateDataProcInstruction(kind, |
| 1507 | out_hi, |
| 1508 | first_hi, |
| 1509 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1510 | codegen); |
| 1511 | GenerateDataProcInstruction(kind, |
| 1512 | out_lo, |
| 1513 | first_lo, |
| 1514 | ShifterOperand(0), |
| 1515 | codegen); |
| 1516 | } else if (shift == ASR) { |
| 1517 | GenerateDataProc(kind, |
| 1518 | out, |
| 1519 | first, |
| 1520 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1521 | ShifterOperand(second_hi, ASR, 31), |
| 1522 | codegen); |
| 1523 | } else { |
| 1524 | DCHECK_EQ(shift, LSR); |
| 1525 | GenerateDataProc(kind, |
| 1526 | out, |
| 1527 | first, |
| 1528 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1529 | ShifterOperand(0), |
| 1530 | codegen); |
| 1531 | } |
| 1532 | } else { |
| 1533 | DCHECK_GT(shift_value, 1U); |
| 1534 | DCHECK_LT(shift_value, 32U); |
| 1535 | |
| 1536 | if (shift == LSL) { |
| 1537 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1538 | // Location::kOutputOverlap; not applicable to other cases. |
| 1539 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1540 | GenerateDataProcInstruction(kind, |
| 1541 | out_hi, |
| 1542 | first_hi, |
| 1543 | ShifterOperand(second_hi, LSL, shift_value), |
| 1544 | codegen); |
| 1545 | GenerateDataProcInstruction(kind, |
| 1546 | out_hi, |
| 1547 | out_hi, |
| 1548 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1549 | codegen); |
| 1550 | GenerateDataProcInstruction(kind, |
| 1551 | out_lo, |
| 1552 | first_lo, |
| 1553 | ShifterOperand(second_lo, LSL, shift_value), |
| 1554 | codegen); |
| 1555 | } else { |
| 1556 | __ Lsl(IP, second_hi, shift_value); |
| 1557 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1558 | GenerateDataProc(kind, |
| 1559 | out, |
| 1560 | first, |
| 1561 | ShifterOperand(second_lo, LSL, shift_value), |
| 1562 | ShifterOperand(IP), |
| 1563 | codegen); |
| 1564 | } |
| 1565 | } else { |
| 1566 | DCHECK(shift == ASR || shift == LSR); |
| 1567 | |
| 1568 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1569 | // Location::kOutputOverlap; not applicable to other cases. |
| 1570 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1571 | GenerateDataProcInstruction(kind, |
| 1572 | out_lo, |
| 1573 | first_lo, |
| 1574 | ShifterOperand(second_lo, LSR, shift_value), |
| 1575 | codegen); |
| 1576 | GenerateDataProcInstruction(kind, |
| 1577 | out_lo, |
| 1578 | out_lo, |
| 1579 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1580 | codegen); |
| 1581 | GenerateDataProcInstruction(kind, |
| 1582 | out_hi, |
| 1583 | first_hi, |
| 1584 | ShifterOperand(second_hi, shift, shift_value), |
| 1585 | codegen); |
| 1586 | } else { |
| 1587 | __ Lsr(IP, second_lo, shift_value); |
| 1588 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1589 | GenerateDataProc(kind, |
| 1590 | out, |
| 1591 | first, |
| 1592 | ShifterOperand(IP), |
| 1593 | ShifterOperand(second_hi, shift, shift_value), |
| 1594 | codegen); |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1600 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1601 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1602 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1603 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1604 | if (rhs_loc.IsConstant()) { |
| 1605 | // 0.0 is the only immediate that can be encoded directly in |
| 1606 | // a VCMP instruction. |
| 1607 | // |
| 1608 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1609 | // specify that in a floating-point comparison, positive zero |
| 1610 | // and negative zero are considered equal, so we can use the |
| 1611 | // literal 0.0 for both cases here. |
| 1612 | // |
| 1613 | // Note however that some methods (Float.equal, Float.compare, |
| 1614 | // Float.compareTo, Double.equal, Double.compare, |
| 1615 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1616 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1617 | // -0.0. So if we ever translate calls to these methods into a |
| 1618 | // HCompare instruction, we must handle the -0.0 case with |
| 1619 | // care here. |
| 1620 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1621 | if (type == Primitive::kPrimFloat) { |
| 1622 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1623 | } else { |
| 1624 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1625 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1626 | } |
| 1627 | } else { |
| 1628 | if (type == Primitive::kPrimFloat) { |
| 1629 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1630 | } else { |
| 1631 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1632 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1633 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1634 | } |
| 1635 | } |
| 1636 | } |
| 1637 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1638 | static std::pair<Condition, Condition> GenerateLongTestConstant(HCondition* condition, |
| 1639 | bool invert, |
| 1640 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1641 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1642 | |
| 1643 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1644 | IfCondition cond = condition->GetCondition(); |
| 1645 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1646 | |
| 1647 | if (invert) { |
| 1648 | std::swap(cond, opposite); |
| 1649 | } |
| 1650 | |
| 1651 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1652 | const Location left = locations->InAt(0); |
| 1653 | const Location right = locations->InAt(1); |
| 1654 | |
| 1655 | DCHECK(right.IsConstant()); |
| 1656 | |
| 1657 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1658 | const Register left_low = left.AsRegisterPairLow<Register>(); |
| 1659 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1660 | |
| 1661 | switch (cond) { |
| 1662 | case kCondEQ: |
| 1663 | case kCondNE: |
| 1664 | case kCondB: |
| 1665 | case kCondBE: |
| 1666 | case kCondA: |
| 1667 | case kCondAE: |
| 1668 | __ CmpConstant(left_high, High32Bits(value)); |
| 1669 | __ it(EQ); |
| 1670 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1671 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1672 | break; |
| 1673 | case kCondLE: |
| 1674 | case kCondGT: |
| 1675 | // Trivially true or false. |
| 1676 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1677 | __ cmp(left_low, ShifterOperand(left_low)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1678 | ret = cond == kCondLE ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1679 | break; |
| 1680 | } |
| 1681 | |
| 1682 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1683 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1684 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1685 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1686 | } else { |
| 1687 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1688 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1689 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1690 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | value++; |
| 1694 | FALLTHROUGH_INTENDED; |
| 1695 | case kCondGE: |
| 1696 | case kCondLT: |
| 1697 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1698 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1699 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1700 | break; |
| 1701 | default: |
| 1702 | LOG(FATAL) << "Unreachable"; |
| 1703 | UNREACHABLE(); |
| 1704 | } |
| 1705 | |
| 1706 | return ret; |
| 1707 | } |
| 1708 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1709 | static std::pair<Condition, Condition> GenerateLongTest(HCondition* condition, |
| 1710 | bool invert, |
| 1711 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1712 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1713 | |
| 1714 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1715 | IfCondition cond = condition->GetCondition(); |
| 1716 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1717 | |
| 1718 | if (invert) { |
| 1719 | std::swap(cond, opposite); |
| 1720 | } |
| 1721 | |
| 1722 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1723 | Location left = locations->InAt(0); |
| 1724 | Location right = locations->InAt(1); |
| 1725 | |
| 1726 | DCHECK(right.IsRegisterPair()); |
| 1727 | |
| 1728 | switch (cond) { |
| 1729 | case kCondEQ: |
| 1730 | case kCondNE: |
| 1731 | case kCondB: |
| 1732 | case kCondBE: |
| 1733 | case kCondA: |
| 1734 | case kCondAE: |
| 1735 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1736 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1737 | __ it(EQ); |
| 1738 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1739 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1740 | EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1741 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1742 | break; |
| 1743 | case kCondLE: |
| 1744 | case kCondGT: |
| 1745 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1746 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1747 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1748 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1749 | } else { |
| 1750 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1751 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1752 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1753 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | std::swap(left, right); |
| 1757 | FALLTHROUGH_INTENDED; |
| 1758 | case kCondGE: |
| 1759 | case kCondLT: |
| 1760 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1761 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1762 | __ sbcs(IP, |
| 1763 | left.AsRegisterPairHigh<Register>(), |
| 1764 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1765 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1766 | break; |
| 1767 | default: |
| 1768 | LOG(FATAL) << "Unreachable"; |
| 1769 | UNREACHABLE(); |
| 1770 | } |
| 1771 | |
| 1772 | return ret; |
| 1773 | } |
| 1774 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1775 | static std::pair<Condition, Condition> GenerateTest(HCondition* condition, |
| 1776 | bool invert, |
| 1777 | CodeGeneratorARM* codegen) { |
| 1778 | const LocationSummary* const locations = condition->GetLocations(); |
| 1779 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1780 | IfCondition cond = condition->GetCondition(); |
| 1781 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1782 | std::pair<Condition, Condition> ret; |
| 1783 | const Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1784 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1785 | if (invert) { |
| 1786 | std::swap(cond, opposite); |
| 1787 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1788 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1789 | if (type == Primitive::kPrimLong) { |
| 1790 | ret = locations->InAt(1).IsConstant() |
| 1791 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1792 | : GenerateLongTest(condition, invert, codegen); |
| 1793 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1794 | GenerateVcmp(condition, codegen); |
| 1795 | __ vmstat(); |
| 1796 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1797 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1798 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1799 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1800 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1801 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1802 | |
| 1803 | if (right.IsRegister()) { |
| 1804 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1805 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1806 | DCHECK(right.IsConstant()); |
| 1807 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1808 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1809 | |
| 1810 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | return ret; |
| 1814 | } |
| 1815 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1816 | static bool CanGenerateTest(HCondition* condition, ArmAssembler* assembler) { |
| 1817 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1818 | const LocationSummary* const locations = condition->GetLocations(); |
| 1819 | const IfCondition c = condition->GetCondition(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1820 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1821 | if (locations->InAt(1).IsConstant()) { |
| 1822 | const int64_t value = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 1823 | ShifterOperand so; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1824 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1825 | if (c < kCondLT || c > kCondGE) { |
| 1826 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1827 | // we check that the least significant half of the first input to be compared |
| 1828 | // is in a low register (the other half is read outside an IT block), and |
| 1829 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1830 | // encoding can be used. |
| 1831 | if (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1832 | !IsUint<8>(Low32Bits(value))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1833 | return false; |
| 1834 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1835 | } else if (c == kCondLE || c == kCondGT) { |
| 1836 | if (value < std::numeric_limits<int64_t>::max() && |
| 1837 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1838 | kNoRegister, |
| 1839 | SBC, |
| 1840 | High32Bits(value + 1), |
| 1841 | kCcSet, |
| 1842 | &so)) { |
| 1843 | return false; |
| 1844 | } |
| 1845 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1846 | kNoRegister, |
| 1847 | SBC, |
| 1848 | High32Bits(value), |
| 1849 | kCcSet, |
| 1850 | &so)) { |
| 1851 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | return true; |
| 1857 | } |
| 1858 | |
| 1859 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1860 | const Primitive::Type type = constant->GetType(); |
| 1861 | bool ret = false; |
| 1862 | |
| 1863 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1864 | |
| 1865 | if (type == Primitive::kPrimLong) { |
| 1866 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 1867 | |
| 1868 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1869 | } else { |
| 1870 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 1871 | } |
| 1872 | |
| 1873 | return ret; |
| 1874 | } |
| 1875 | |
| 1876 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1877 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1878 | |
| 1879 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1880 | return Location::ConstantLocation(constant->AsConstant()); |
| 1881 | } |
| 1882 | |
| 1883 | return Location::RequiresRegister(); |
| 1884 | } |
| 1885 | |
| 1886 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1887 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1888 | // we check that we are not dealing with floating-point output (there is no |
| 1889 | // 16-bit VMOV encoding). |
| 1890 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1891 | return false; |
| 1892 | } |
| 1893 | |
| 1894 | // For constants, we also check that the output is in one or two low registers, |
| 1895 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1896 | // MOV encoding can be used. |
| 1897 | if (src.IsConstant()) { |
| 1898 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1899 | return false; |
| 1900 | } |
| 1901 | |
| 1902 | if (out.IsRegister()) { |
| 1903 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 1904 | return false; |
| 1905 | } |
| 1906 | } else { |
| 1907 | DCHECK(out.IsRegisterPair()); |
| 1908 | |
| 1909 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 1910 | return false; |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1918 | #undef __ |
| 1919 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1920 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1921 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1922 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 1923 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1924 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1925 | |
| 1926 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1927 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1928 | HInstruction* const next = instruction->GetNext(); |
| 1929 | |
| 1930 | // Avoid a branch to a branch. |
| 1931 | if (next->IsGoto() && (info == nullptr || |
| 1932 | !info->IsBackEdge(*block) || |
| 1933 | !info->HasSuspendCheck())) { |
| 1934 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1935 | } |
| 1936 | |
| 1937 | return final_label; |
| 1938 | } |
| 1939 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1940 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1941 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1945 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1948 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1949 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1950 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1951 | } |
| 1952 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1953 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1954 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1955 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1956 | } |
| 1957 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1958 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1959 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1960 | return kArmWordSize; |
| 1961 | } |
| 1962 | |
| 1963 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1964 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1965 | return kArmWordSize; |
| 1966 | } |
| 1967 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1968 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1969 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1970 | const CompilerOptions& compiler_options, |
| 1971 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1972 | : CodeGenerator(graph, |
| 1973 | kNumberOfCoreRegisters, |
| 1974 | kNumberOfSRegisters, |
| 1975 | kNumberOfRegisterPairs, |
| 1976 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1977 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1978 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1979 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1980 | compiler_options, |
| 1981 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1982 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1983 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1984 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1985 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1986 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1987 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1988 | uint32_literals_(std::less<uint32_t>(), |
| 1989 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1990 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1991 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1992 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1993 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1994 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1995 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1996 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1997 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 1998 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1999 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 2000 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2001 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2002 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2003 | // Always save the LR register to mimic Quick. |
| 2004 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2007 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 2008 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 2009 | __ FinalizeCode(); |
| 2010 | |
| 2011 | // Adjust native pc offsets in stack maps. |
| 2012 | for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) { |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 2013 | uint32_t old_position = |
| 2014 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2015 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 2016 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 2017 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 2018 | // Adjust pc offsets for the disassembly information. |
| 2019 | if (disasm_info_ != nullptr) { |
| 2020 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 2021 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 2022 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 2023 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 2024 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 2025 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 2026 | } |
| 2027 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 2028 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 2029 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 2030 | } |
| 2031 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2032 | |
| 2033 | CodeGenerator::Finalize(allocator); |
| 2034 | } |
| 2035 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2036 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2037 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2038 | blocked_core_registers_[SP] = true; |
| 2039 | blocked_core_registers_[LR] = true; |
| 2040 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2041 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2042 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2043 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2044 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2045 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2046 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2047 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2048 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2049 | // Stubs do not save callee-save floating point registers. If the graph |
| 2050 | // is debuggable, we need to deal with these registers differently. For |
| 2051 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2052 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2053 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2054 | } |
| 2055 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2056 | } |
| 2057 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2058 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2059 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2060 | assembler_(codegen->GetAssembler()), |
| 2061 | codegen_(codegen) {} |
| 2062 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2063 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2064 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2065 | DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved"; |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2066 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2067 | // restore another arbitrary register. |
| 2068 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2069 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2070 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2071 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2072 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2073 | // but in the range. |
| 2074 | if (fpu_spill_mask_ != 0) { |
| 2075 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2076 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2077 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2078 | fpu_spill_mask_ |= (1 << i); |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2083 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2084 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2088 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2089 | } |
| 2090 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2091 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2092 | bool skip_overflow_check = |
| 2093 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2094 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2095 | __ Bind(&frame_entry_label_); |
| 2096 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2097 | if (HasEmptyFrame()) { |
| 2098 | return; |
| 2099 | } |
| 2100 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2101 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2102 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2103 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2104 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2107 | __ PushList(core_spill_mask_); |
| 2108 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2109 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2110 | if (fpu_spill_mask_ != 0) { |
| 2111 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2112 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2113 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2114 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2115 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2116 | |
| 2117 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2118 | // Initialize should_deoptimize flag to 0. |
| 2119 | __ mov(IP, ShifterOperand(0)); |
| 2120 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2121 | } |
| 2122 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2123 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2124 | __ AddConstant(SP, -adjust); |
| 2125 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2126 | |
| 2127 | // Save the current method if we need it. Note that we do not |
| 2128 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2129 | // in the SSA graph. |
| 2130 | if (RequiresCurrentMethod()) { |
| 2131 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2132 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2136 | if (HasEmptyFrame()) { |
| 2137 | __ bx(LR); |
| 2138 | return; |
| 2139 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2140 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2141 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2142 | __ AddConstant(SP, adjust); |
| 2143 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2144 | if (fpu_spill_mask_ != 0) { |
| 2145 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2146 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2147 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2148 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2149 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2150 | // Pop LR into PC to return. |
| 2151 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2152 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2153 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2154 | __ cfi().RestoreState(); |
| 2155 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2158 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2159 | Label* label = GetLabelOf(block); |
| 2160 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2163 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2164 | switch (type) { |
| 2165 | case Primitive::kPrimBoolean: |
| 2166 | case Primitive::kPrimByte: |
| 2167 | case Primitive::kPrimChar: |
| 2168 | case Primitive::kPrimShort: |
| 2169 | case Primitive::kPrimInt: |
| 2170 | case Primitive::kPrimNot: { |
| 2171 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2172 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2173 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2174 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2175 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2176 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2177 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2178 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2179 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2181 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2182 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2183 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2184 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2185 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2186 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2187 | // Skip R1, and use R2_R3 instead. |
| 2188 | gp_index_++; |
| 2189 | index++; |
| 2190 | } |
| 2191 | } |
| 2192 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2193 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2194 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2195 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2196 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2197 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2198 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2199 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | case Primitive::kPrimFloat: { |
| 2204 | uint32_t stack_index = stack_index_++; |
| 2205 | if (float_index_ % 2 == 0) { |
| 2206 | float_index_ = std::max(double_index_, float_index_); |
| 2207 | } |
| 2208 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2209 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2210 | } else { |
| 2211 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | case Primitive::kPrimDouble: { |
| 2216 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2217 | uint32_t stack_index = stack_index_; |
| 2218 | stack_index_ += 2; |
| 2219 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2220 | uint32_t index = double_index_; |
| 2221 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2222 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2223 | calling_convention.GetFpuRegisterAt(index), |
| 2224 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2225 | DCHECK(ExpectedPairLayout(result)); |
| 2226 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2227 | } else { |
| 2228 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2232 | case Primitive::kPrimVoid: |
| 2233 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2234 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2235 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2236 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2237 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2238 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2239 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2240 | switch (type) { |
| 2241 | case Primitive::kPrimBoolean: |
| 2242 | case Primitive::kPrimByte: |
| 2243 | case Primitive::kPrimChar: |
| 2244 | case Primitive::kPrimShort: |
| 2245 | case Primitive::kPrimInt: |
| 2246 | case Primitive::kPrimNot: { |
| 2247 | return Location::RegisterLocation(R0); |
| 2248 | } |
| 2249 | |
| 2250 | case Primitive::kPrimFloat: { |
| 2251 | return Location::FpuRegisterLocation(S0); |
| 2252 | } |
| 2253 | |
| 2254 | case Primitive::kPrimLong: { |
| 2255 | return Location::RegisterPairLocation(R0, R1); |
| 2256 | } |
| 2257 | |
| 2258 | case Primitive::kPrimDouble: { |
| 2259 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2260 | } |
| 2261 | |
| 2262 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2263 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2264 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2265 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2266 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2269 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2270 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2271 | } |
| 2272 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2273 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2274 | if (source.Equals(destination)) { |
| 2275 | return; |
| 2276 | } |
| 2277 | if (destination.IsRegister()) { |
| 2278 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2279 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2280 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2281 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2282 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2283 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2284 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2285 | } else if (destination.IsFpuRegister()) { |
| 2286 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2287 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2288 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2289 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2290 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2291 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2292 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2293 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2294 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2295 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2296 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2297 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2298 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2299 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2300 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2301 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2302 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2308 | if (source.Equals(destination)) { |
| 2309 | return; |
| 2310 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2311 | if (destination.IsRegisterPair()) { |
| 2312 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2313 | EmitParallelMoves( |
| 2314 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2315 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2316 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2317 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2318 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2319 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2320 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2321 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2322 | } else if (source.IsFpuRegisterPair()) { |
| 2323 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2324 | destination.AsRegisterPairHigh<Register>(), |
| 2325 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2326 | } else { |
| 2327 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2328 | DCHECK(ExpectedPairLayout(destination)); |
| 2329 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2330 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2331 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2332 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2333 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2334 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2335 | SP, |
| 2336 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2337 | } else if (source.IsRegisterPair()) { |
| 2338 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2339 | source.AsRegisterPairLow<Register>(), |
| 2340 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2341 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2342 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2343 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2344 | } else { |
| 2345 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2346 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2347 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2348 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2349 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2350 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2351 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2352 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2353 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2354 | SP, destination.GetStackIndex()); |
| 2355 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2356 | } else if (source.IsFpuRegisterPair()) { |
| 2357 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2358 | SP, |
| 2359 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2360 | } else { |
| 2361 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2362 | EmitParallelMoves( |
| 2363 | Location::StackSlot(source.GetStackIndex()), |
| 2364 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2365 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2366 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2367 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2368 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2369 | } |
| 2370 | } |
| 2371 | } |
| 2372 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2373 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2374 | DCHECK(location.IsRegister()); |
| 2375 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2376 | } |
| 2377 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2378 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2379 | HParallelMove move(GetGraph()->GetArena()); |
| 2380 | move.AddMove(src, dst, dst_type, nullptr); |
| 2381 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2385 | if (location.IsRegister()) { |
| 2386 | locations->AddTemp(location); |
| 2387 | } else if (location.IsRegisterPair()) { |
| 2388 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2389 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2390 | } else { |
| 2391 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2392 | } |
| 2393 | } |
| 2394 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2395 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2396 | HInstruction* instruction, |
| 2397 | uint32_t dex_pc, |
| 2398 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2399 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2400 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2401 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2402 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2403 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2406 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2407 | HInstruction* instruction, |
| 2408 | SlowPathCode* slow_path) { |
| 2409 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2410 | GenerateInvokeRuntime(entry_point_offset); |
| 2411 | } |
| 2412 | |
| 2413 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2414 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2415 | __ blx(LR); |
| 2416 | } |
| 2417 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2418 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2419 | DCHECK(!successor->IsExitBlock()); |
| 2420 | |
| 2421 | HBasicBlock* block = got->GetBlock(); |
| 2422 | HInstruction* previous = got->GetPrevious(); |
| 2423 | |
| 2424 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2425 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2426 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2427 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2428 | return; |
| 2429 | } |
| 2430 | |
| 2431 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2432 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2433 | } |
| 2434 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2435 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2439 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2440 | got->SetLocations(nullptr); |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2444 | HandleGoto(got, got->GetSuccessor()); |
| 2445 | } |
| 2446 | |
| 2447 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2448 | try_boundary->SetLocations(nullptr); |
| 2449 | } |
| 2450 | |
| 2451 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2452 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2453 | if (!successor->IsExitBlock()) { |
| 2454 | HandleGoto(try_boundary, successor); |
| 2455 | } |
| 2456 | } |
| 2457 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2458 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2459 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2462 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2463 | } |
| 2464 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2465 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2466 | Label* true_label, |
| 2467 | Label* false_label) { |
| 2468 | LocationSummary* locations = cond->GetLocations(); |
| 2469 | Location left = locations->InAt(0); |
| 2470 | Location right = locations->InAt(1); |
| 2471 | IfCondition if_cond = cond->GetCondition(); |
| 2472 | |
| 2473 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2474 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2475 | IfCondition true_high_cond = if_cond; |
| 2476 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2477 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2478 | |
| 2479 | // Set the conditions for the test, remembering that == needs to be |
| 2480 | // decided using the low words. |
| 2481 | switch (if_cond) { |
| 2482 | case kCondEQ: |
| 2483 | case kCondNE: |
| 2484 | // Nothing to do. |
| 2485 | break; |
| 2486 | case kCondLT: |
| 2487 | false_high_cond = kCondGT; |
| 2488 | break; |
| 2489 | case kCondLE: |
| 2490 | true_high_cond = kCondLT; |
| 2491 | break; |
| 2492 | case kCondGT: |
| 2493 | false_high_cond = kCondLT; |
| 2494 | break; |
| 2495 | case kCondGE: |
| 2496 | true_high_cond = kCondGT; |
| 2497 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2498 | case kCondB: |
| 2499 | false_high_cond = kCondA; |
| 2500 | break; |
| 2501 | case kCondBE: |
| 2502 | true_high_cond = kCondB; |
| 2503 | break; |
| 2504 | case kCondA: |
| 2505 | false_high_cond = kCondB; |
| 2506 | break; |
| 2507 | case kCondAE: |
| 2508 | true_high_cond = kCondA; |
| 2509 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2510 | } |
| 2511 | if (right.IsConstant()) { |
| 2512 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2513 | int32_t val_low = Low32Bits(value); |
| 2514 | int32_t val_high = High32Bits(value); |
| 2515 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2516 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2517 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2518 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2519 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2520 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2521 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2522 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2523 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2524 | } |
| 2525 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2526 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2527 | } else { |
| 2528 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2529 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2530 | |
| 2531 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2532 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2533 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2534 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2535 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2536 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2537 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2538 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2539 | } |
| 2540 | // Must be equal high, so compare the lows. |
| 2541 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2542 | } |
| 2543 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2544 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2545 | __ b(true_label, final_condition); |
| 2546 | } |
| 2547 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2548 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2549 | Label* true_target_in, |
| 2550 | Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2551 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2552 | Label* non_fallthrough_target; |
| 2553 | bool invert; |
| 2554 | |
| 2555 | if (true_target_in == nullptr) { |
| 2556 | DCHECK(false_target_in != nullptr); |
| 2557 | non_fallthrough_target = false_target_in; |
| 2558 | invert = true; |
| 2559 | } else { |
| 2560 | non_fallthrough_target = true_target_in; |
| 2561 | invert = false; |
| 2562 | } |
| 2563 | |
| 2564 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2565 | |
| 2566 | __ b(non_fallthrough_target, cond.first); |
| 2567 | |
| 2568 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2569 | __ b(false_target_in); |
| 2570 | } |
| 2571 | |
| 2572 | return; |
| 2573 | } |
| 2574 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2575 | // Generated branching requires both targets to be explicit. If either of the |
| 2576 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2577 | Label fallthrough_target; |
| 2578 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2579 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2580 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2581 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 2582 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2583 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2584 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2585 | __ b(false_target); |
| 2586 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2587 | |
| 2588 | if (fallthrough_target.IsLinked()) { |
| 2589 | __ Bind(&fallthrough_target); |
| 2590 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2591 | } |
| 2592 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2593 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2594 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2595 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2596 | Label* false_target) { |
| 2597 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2598 | |
| 2599 | if (true_target == nullptr && false_target == nullptr) { |
| 2600 | // Nothing to do. The code always falls through. |
| 2601 | return; |
| 2602 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2603 | // Constant condition, statically compared against "true" (integer value 1). |
| 2604 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2605 | if (true_target != nullptr) { |
| 2606 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2607 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2608 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2609 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2610 | if (false_target != nullptr) { |
| 2611 | __ b(false_target); |
| 2612 | } |
| 2613 | } |
| 2614 | return; |
| 2615 | } |
| 2616 | |
| 2617 | // The following code generates these patterns: |
| 2618 | // (1) true_target == nullptr && false_target != nullptr |
| 2619 | // - opposite condition true => branch to false_target |
| 2620 | // (2) true_target != nullptr && false_target == nullptr |
| 2621 | // - condition true => branch to true_target |
| 2622 | // (3) true_target != nullptr && false_target != nullptr |
| 2623 | // - condition true => branch to true_target |
| 2624 | // - branch to false_target |
| 2625 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2626 | // Condition has been materialized, compare the output to 0. |
| 2627 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2628 | DCHECK(cond_val.IsRegister()); |
| 2629 | if (true_target == nullptr) { |
| 2630 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2631 | } else { |
| 2632 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2633 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2634 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2635 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2636 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2637 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2638 | |
| 2639 | // If this is a long or FP comparison that has been folded into |
| 2640 | // the HCondition, generate the comparison directly. |
| 2641 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2642 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2643 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2644 | return; |
| 2645 | } |
| 2646 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2647 | Label* non_fallthrough_target; |
| 2648 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2649 | LocationSummary* locations = cond->GetLocations(); |
| 2650 | DCHECK(locations->InAt(0).IsRegister()); |
| 2651 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2652 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2653 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2654 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2655 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2656 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2657 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2658 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2659 | non_fallthrough_target = true_target; |
| 2660 | } |
| 2661 | |
| 2662 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2663 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2664 | if (arm_cond == EQ) { |
| 2665 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2666 | } else { |
| 2667 | DCHECK_EQ(arm_cond, NE); |
| 2668 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2669 | } |
| 2670 | } else { |
| 2671 | if (right.IsRegister()) { |
| 2672 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2673 | } else { |
| 2674 | DCHECK(right.IsConstant()); |
| 2675 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2676 | } |
| 2677 | |
| 2678 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2679 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2680 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2681 | |
| 2682 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2683 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2684 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2685 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2689 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2690 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2691 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2697 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2698 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2699 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2700 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2701 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2702 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2703 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2707 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2708 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2709 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2710 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2711 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2716 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2717 | GenerateTestAndBranch(deoptimize, |
| 2718 | /* condition_input_index */ 0, |
| 2719 | slow_path->GetEntryLabel(), |
| 2720 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2721 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2722 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2723 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2724 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2725 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2726 | locations->SetOut(Location::RequiresRegister()); |
| 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2730 | __ LoadFromOffset(kLoadWord, |
| 2731 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2732 | SP, |
| 2733 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2734 | } |
| 2735 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2736 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2737 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2738 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2739 | |
| 2740 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2741 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2742 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2743 | } else { |
| 2744 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2745 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2746 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2747 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2748 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2749 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2750 | // The code generator handles overlap with the values, but not with the condition. |
| 2751 | locations->SetOut(Location::SameAsFirstInput()); |
| 2752 | } else if (is_floating_point) { |
| 2753 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2754 | } else { |
| 2755 | if (!locations->InAt(1).IsConstant()) { |
| 2756 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2757 | } |
| 2758 | |
| 2759 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2760 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2764 | HInstruction* const condition = select->GetCondition(); |
| 2765 | const LocationSummary* const locations = select->GetLocations(); |
| 2766 | const Primitive::Type type = select->GetType(); |
| 2767 | const Location first = locations->InAt(0); |
| 2768 | const Location out = locations->Out(); |
| 2769 | const Location second = locations->InAt(1); |
| 2770 | Location src; |
| 2771 | |
| 2772 | if (condition->IsIntConstant()) { |
| 2773 | if (condition->AsIntConstant()->IsFalse()) { |
| 2774 | src = first; |
| 2775 | } else { |
| 2776 | src = second; |
| 2777 | } |
| 2778 | |
| 2779 | codegen_->MoveLocation(out, src, type); |
| 2780 | return; |
| 2781 | } |
| 2782 | |
| 2783 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2784 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 2785 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2786 | bool invert = false; |
| 2787 | |
| 2788 | if (out.Equals(second)) { |
| 2789 | src = first; |
| 2790 | invert = true; |
| 2791 | } else if (out.Equals(first)) { |
| 2792 | src = second; |
| 2793 | } else if (second.IsConstant()) { |
| 2794 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2795 | src = second; |
| 2796 | } else if (first.IsConstant()) { |
| 2797 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2798 | src = first; |
| 2799 | invert = true; |
| 2800 | } else { |
| 2801 | src = second; |
| 2802 | } |
| 2803 | |
| 2804 | if (CanGenerateConditionalMove(out, src)) { |
| 2805 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2806 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2807 | } |
| 2808 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2809 | std::pair<Condition, Condition> cond; |
| 2810 | |
| 2811 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2812 | __ CmpConstant(locations->InAt(2).AsRegister<Register>(), 0); |
| 2813 | cond = invert ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
| 2814 | } else { |
| 2815 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2816 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2817 | |
| 2818 | if (out.IsRegister()) { |
| 2819 | ShifterOperand operand; |
| 2820 | |
| 2821 | if (src.IsConstant()) { |
| 2822 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 2823 | } else { |
| 2824 | DCHECK(src.IsRegister()); |
| 2825 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 2826 | } |
| 2827 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2828 | __ it(cond.first); |
| 2829 | __ mov(out.AsRegister<Register>(), operand, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2830 | } else { |
| 2831 | DCHECK(out.IsRegisterPair()); |
| 2832 | |
| 2833 | ShifterOperand operand_high; |
| 2834 | ShifterOperand operand_low; |
| 2835 | |
| 2836 | if (src.IsConstant()) { |
| 2837 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 2838 | |
| 2839 | operand_high = ShifterOperand(High32Bits(value)); |
| 2840 | operand_low = ShifterOperand(Low32Bits(value)); |
| 2841 | } else { |
| 2842 | DCHECK(src.IsRegisterPair()); |
| 2843 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 2844 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 2845 | } |
| 2846 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2847 | __ it(cond.first); |
| 2848 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond.first); |
| 2849 | __ it(cond.first); |
| 2850 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | return; |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | Label* false_target = nullptr; |
| 2858 | Label* true_target = nullptr; |
| 2859 | Label select_end; |
| 2860 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 2861 | |
| 2862 | if (out.Equals(second)) { |
| 2863 | true_target = target; |
| 2864 | src = first; |
| 2865 | } else { |
| 2866 | false_target = target; |
| 2867 | src = second; |
| 2868 | |
| 2869 | if (!out.Equals(first)) { |
| 2870 | codegen_->MoveLocation(out, first, type); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 2875 | codegen_->MoveLocation(out, src, type); |
| 2876 | |
| 2877 | if (select_end.IsLinked()) { |
| 2878 | __ Bind(&select_end); |
| 2879 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2882 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2883 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2884 | } |
| 2885 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2886 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2887 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | void CodeGeneratorARM::GenerateNop() { |
| 2891 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2894 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2895 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2896 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2897 | // Handle the long/FP comparisons made in instruction simplification. |
| 2898 | switch (cond->InputAt(0)->GetType()) { |
| 2899 | case Primitive::kPrimLong: |
| 2900 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2901 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2902 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2903 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2904 | } |
| 2905 | break; |
| 2906 | |
| 2907 | case Primitive::kPrimFloat: |
| 2908 | case Primitive::kPrimDouble: |
| 2909 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2910 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2911 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2912 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2913 | } |
| 2914 | break; |
| 2915 | |
| 2916 | default: |
| 2917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2918 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2919 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2920 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2921 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2922 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2925 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2926 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2927 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2928 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2929 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2930 | const Register out = cond->GetLocations()->Out().AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2931 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2932 | if (ArmAssembler::IsLowRegister(out) && CanGenerateTest(cond, codegen_->GetAssembler())) { |
| 2933 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2934 | |
| 2935 | __ it(condition.first); |
| 2936 | __ mov(out, ShifterOperand(1), condition.first); |
| 2937 | __ it(condition.second); |
| 2938 | __ mov(out, ShifterOperand(0), condition.second); |
| 2939 | return; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | // Convert the jumps into the result. |
| 2943 | Label done_label; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2944 | Label* const final_label = codegen_->GetFinalLabel(cond, &done_label); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2945 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2946 | if (cond->InputAt(0)->GetType() == Primitive::kPrimLong) { |
| 2947 | Label true_label, false_label; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2948 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2949 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2950 | |
| 2951 | // False case: result = 0. |
| 2952 | __ Bind(&false_label); |
| 2953 | __ LoadImmediate(out, 0); |
| 2954 | __ b(final_label); |
| 2955 | |
| 2956 | // True case: result = 1. |
| 2957 | __ Bind(&true_label); |
| 2958 | __ LoadImmediate(out, 1); |
| 2959 | } else { |
| 2960 | DCHECK(CanGenerateTest(cond, codegen_->GetAssembler())); |
| 2961 | |
| 2962 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2963 | |
| 2964 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 2965 | __ b(final_label, condition.second); |
| 2966 | __ LoadImmediate(out, 1); |
| 2967 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (done_label.IsLinked()) { |
| 2970 | __ Bind(&done_label); |
| 2971 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2975 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2979 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2983 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2987 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2991 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2995 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2999 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3003 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3007 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3011 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3015 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3019 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3022 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3023 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3027 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3031 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3035 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3039 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3043 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3047 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3051 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3054 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3055 | LocationSummary* locations = |
| 3056 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3057 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3060 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3061 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3064 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 3065 | LocationSummary* locations = |
| 3066 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3067 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3068 | } |
| 3069 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3070 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3071 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3074 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3075 | LocationSummary* locations = |
| 3076 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3077 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3078 | } |
| 3079 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3080 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3081 | // Will be generated at use site. |
| 3082 | } |
| 3083 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3084 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3085 | LocationSummary* locations = |
| 3086 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3087 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3088 | } |
| 3089 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3090 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3091 | // Will be generated at use site. |
| 3092 | } |
| 3093 | |
| 3094 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3095 | LocationSummary* locations = |
| 3096 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3097 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3098 | } |
| 3099 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3100 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3101 | // Will be generated at use site. |
| 3102 | } |
| 3103 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3104 | void LocationsBuilderARM::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3105 | constructor_fence->SetLocations(nullptr); |
| 3106 | } |
| 3107 | |
| 3108 | void InstructionCodeGeneratorARM::VisitConstructorFence( |
| 3109 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3110 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3111 | } |
| 3112 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3113 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3114 | memory_barrier->SetLocations(nullptr); |
| 3115 | } |
| 3116 | |
| 3117 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3118 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3121 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3122 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3125 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3126 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3129 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3130 | LocationSummary* locations = |
| 3131 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3132 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3135 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3136 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3139 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3140 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3141 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3142 | // the method_idx. |
| 3143 | HandleInvoke(invoke); |
| 3144 | } |
| 3145 | |
| 3146 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3147 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3148 | } |
| 3149 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3150 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3151 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3152 | // art::PrepareForRegisterAllocation. |
| 3153 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3154 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3155 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3156 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3157 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3158 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3159 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3160 | return; |
| 3161 | } |
| 3162 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3163 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3164 | |
| 3165 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3166 | if (invoke->HasPcRelativeDexCache()) { |
| 3167 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3168 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3169 | } |
| 3170 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3171 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3172 | if (invoke->GetLocations()->Intrinsified()) { |
| 3173 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3174 | intrinsic.Dispatch(invoke); |
| 3175 | return true; |
| 3176 | } |
| 3177 | return false; |
| 3178 | } |
| 3179 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3180 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3181 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3182 | // art::PrepareForRegisterAllocation. |
| 3183 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3184 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3185 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3186 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3187 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3188 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3189 | LocationSummary* locations = invoke->GetLocations(); |
| 3190 | codegen_->GenerateStaticOrDirectCall( |
| 3191 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3192 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3193 | } |
| 3194 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3195 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3196 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3197 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3200 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3201 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3202 | if (intrinsic.TryDispatch(invoke)) { |
| 3203 | return; |
| 3204 | } |
| 3205 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3206 | HandleInvoke(invoke); |
| 3207 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3208 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3209 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3210 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3211 | return; |
| 3212 | } |
| 3213 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3214 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3215 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3216 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3219 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3220 | HandleInvoke(invoke); |
| 3221 | // Add the hidden argument. |
| 3222 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3223 | } |
| 3224 | |
| 3225 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3226 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3227 | LocationSummary* locations = invoke->GetLocations(); |
| 3228 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3229 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3230 | Location receiver = locations->InAt(0); |
| 3231 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3232 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3233 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3234 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3235 | DCHECK_EQ(R12, hidden_reg); |
| 3236 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3237 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3238 | if (receiver.IsStackSlot()) { |
| 3239 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3240 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3241 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3242 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3243 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3244 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3245 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3246 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3247 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3248 | // emit a read barrier for the previous class reference load. |
| 3249 | // However this is not required in practice, as this is an |
| 3250 | // intermediate/temporary reference and because the current |
| 3251 | // concurrent copying collector keeps the from-space memory |
| 3252 | // intact/accessible until the end of the marking phase (the |
| 3253 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3254 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3255 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3256 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3257 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3258 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3259 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3260 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3261 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3262 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3263 | // LR = temp->GetEntryPoint(); |
| 3264 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3265 | // LR(); |
| 3266 | __ blx(LR); |
| 3267 | DCHECK(!codegen_->IsLeafMethod()); |
| 3268 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3269 | } |
| 3270 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3271 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3272 | HandleInvoke(invoke); |
| 3273 | } |
| 3274 | |
| 3275 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3276 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3277 | } |
| 3278 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3279 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3280 | LocationSummary* locations = |
| 3281 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3282 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3283 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3284 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3285 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3286 | break; |
| 3287 | } |
| 3288 | case Primitive::kPrimLong: { |
| 3289 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3290 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3291 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3292 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3293 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3294 | case Primitive::kPrimFloat: |
| 3295 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3297 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3298 | break; |
| 3299 | |
| 3300 | default: |
| 3301 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3306 | LocationSummary* locations = neg->GetLocations(); |
| 3307 | Location out = locations->Out(); |
| 3308 | Location in = locations->InAt(0); |
| 3309 | switch (neg->GetResultType()) { |
| 3310 | case Primitive::kPrimInt: |
| 3311 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3312 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3313 | break; |
| 3314 | |
| 3315 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3316 | DCHECK(in.IsRegisterPair()); |
| 3317 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3318 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3319 | in.AsRegisterPairLow<Register>(), |
| 3320 | ShifterOperand(0)); |
| 3321 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3322 | // instruction here, as it does not exist in the Thumb-2 |
| 3323 | // instruction set. We use the following approach |
| 3324 | // using SBC and SUB instead. |
| 3325 | // |
| 3326 | // out.hi = -C |
| 3327 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3328 | out.AsRegisterPairHigh<Register>(), |
| 3329 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3330 | // out.hi = out.hi - in.hi |
| 3331 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3332 | out.AsRegisterPairHigh<Register>(), |
| 3333 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3334 | break; |
| 3335 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3336 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3337 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3338 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3339 | break; |
| 3340 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3341 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3342 | DCHECK(in.IsFpuRegisterPair()); |
| 3343 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3344 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3345 | break; |
| 3346 | |
| 3347 | default: |
| 3348 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3349 | } |
| 3350 | } |
| 3351 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3352 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3353 | Primitive::Type result_type = conversion->GetResultType(); |
| 3354 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3355 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3356 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3357 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3358 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3359 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3360 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3361 | && result_type == Primitive::kPrimLong) |
| 3362 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3363 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3364 | : LocationSummary::kNoCall; |
| 3365 | LocationSummary* locations = |
| 3366 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3367 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3368 | // The Java language does not allow treating boolean as an integral type but |
| 3369 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3370 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3371 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3372 | case Primitive::kPrimByte: |
| 3373 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3374 | case Primitive::kPrimLong: |
| 3375 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3376 | case Primitive::kPrimBoolean: |
| 3377 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3378 | case Primitive::kPrimShort: |
| 3379 | case Primitive::kPrimInt: |
| 3380 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3381 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3383 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3384 | break; |
| 3385 | |
| 3386 | default: |
| 3387 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3388 | << " to " << result_type; |
| 3389 | } |
| 3390 | break; |
| 3391 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3392 | case Primitive::kPrimShort: |
| 3393 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3394 | case Primitive::kPrimLong: |
| 3395 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3396 | case Primitive::kPrimBoolean: |
| 3397 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3398 | case Primitive::kPrimByte: |
| 3399 | case Primitive::kPrimInt: |
| 3400 | case Primitive::kPrimChar: |
| 3401 | // Processing a Dex `int-to-short' instruction. |
| 3402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3403 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3404 | break; |
| 3405 | |
| 3406 | default: |
| 3407 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3408 | << " to " << result_type; |
| 3409 | } |
| 3410 | break; |
| 3411 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3412 | case Primitive::kPrimInt: |
| 3413 | switch (input_type) { |
| 3414 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3415 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3416 | locations->SetInAt(0, Location::Any()); |
| 3417 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3418 | break; |
| 3419 | |
| 3420 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3421 | // Processing a Dex `float-to-int' instruction. |
| 3422 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3423 | locations->SetOut(Location::RequiresRegister()); |
| 3424 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3425 | break; |
| 3426 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3427 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3428 | // Processing a Dex `double-to-int' instruction. |
| 3429 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3430 | locations->SetOut(Location::RequiresRegister()); |
| 3431 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3432 | break; |
| 3433 | |
| 3434 | default: |
| 3435 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3436 | << " to " << result_type; |
| 3437 | } |
| 3438 | break; |
| 3439 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3440 | case Primitive::kPrimLong: |
| 3441 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3442 | case Primitive::kPrimBoolean: |
| 3443 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3444 | case Primitive::kPrimByte: |
| 3445 | case Primitive::kPrimShort: |
| 3446 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3447 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3448 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3449 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3450 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3451 | break; |
| 3452 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3453 | case Primitive::kPrimFloat: { |
| 3454 | // Processing a Dex `float-to-long' instruction. |
| 3455 | InvokeRuntimeCallingConvention calling_convention; |
| 3456 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3457 | calling_convention.GetFpuRegisterAt(0))); |
| 3458 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3459 | break; |
| 3460 | } |
| 3461 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3462 | case Primitive::kPrimDouble: { |
| 3463 | // Processing a Dex `double-to-long' instruction. |
| 3464 | InvokeRuntimeCallingConvention calling_convention; |
| 3465 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3466 | calling_convention.GetFpuRegisterAt(0), |
| 3467 | calling_convention.GetFpuRegisterAt(1))); |
| 3468 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3469 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3470 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3471 | |
| 3472 | default: |
| 3473 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3474 | << " to " << result_type; |
| 3475 | } |
| 3476 | break; |
| 3477 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3478 | case Primitive::kPrimChar: |
| 3479 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3480 | case Primitive::kPrimLong: |
| 3481 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3482 | case Primitive::kPrimBoolean: |
| 3483 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3484 | case Primitive::kPrimByte: |
| 3485 | case Primitive::kPrimShort: |
| 3486 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3487 | // Processing a Dex `int-to-char' instruction. |
| 3488 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3489 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3490 | break; |
| 3491 | |
| 3492 | default: |
| 3493 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3494 | << " to " << result_type; |
| 3495 | } |
| 3496 | break; |
| 3497 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3498 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3499 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3500 | case Primitive::kPrimBoolean: |
| 3501 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3502 | case Primitive::kPrimByte: |
| 3503 | case Primitive::kPrimShort: |
| 3504 | case Primitive::kPrimInt: |
| 3505 | case Primitive::kPrimChar: |
| 3506 | // Processing a Dex `int-to-float' instruction. |
| 3507 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3508 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3509 | break; |
| 3510 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3511 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3512 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3513 | InvokeRuntimeCallingConvention calling_convention; |
| 3514 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3515 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3516 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3517 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3518 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3519 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3520 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3521 | // Processing a Dex `double-to-float' instruction. |
| 3522 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3523 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3524 | break; |
| 3525 | |
| 3526 | default: |
| 3527 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3528 | << " to " << result_type; |
| 3529 | }; |
| 3530 | break; |
| 3531 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3532 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3533 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3534 | case Primitive::kPrimBoolean: |
| 3535 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3536 | case Primitive::kPrimByte: |
| 3537 | case Primitive::kPrimShort: |
| 3538 | case Primitive::kPrimInt: |
| 3539 | case Primitive::kPrimChar: |
| 3540 | // Processing a Dex `int-to-double' instruction. |
| 3541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3542 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3543 | break; |
| 3544 | |
| 3545 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3546 | // Processing a Dex `long-to-double' instruction. |
| 3547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3548 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3549 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3550 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3551 | break; |
| 3552 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3553 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3554 | // Processing a Dex `float-to-double' instruction. |
| 3555 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3556 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3557 | break; |
| 3558 | |
| 3559 | default: |
| 3560 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3561 | << " to " << result_type; |
| 3562 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3563 | break; |
| 3564 | |
| 3565 | default: |
| 3566 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3567 | << " to " << result_type; |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3572 | LocationSummary* locations = conversion->GetLocations(); |
| 3573 | Location out = locations->Out(); |
| 3574 | Location in = locations->InAt(0); |
| 3575 | Primitive::Type result_type = conversion->GetResultType(); |
| 3576 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3577 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3578 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3579 | case Primitive::kPrimByte: |
| 3580 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3581 | case Primitive::kPrimLong: |
| 3582 | // Type conversion from long to byte is a result of code transformations. |
| 3583 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3584 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3585 | case Primitive::kPrimBoolean: |
| 3586 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3587 | case Primitive::kPrimShort: |
| 3588 | case Primitive::kPrimInt: |
| 3589 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3590 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3591 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3592 | break; |
| 3593 | |
| 3594 | default: |
| 3595 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3596 | << " to " << result_type; |
| 3597 | } |
| 3598 | break; |
| 3599 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3600 | case Primitive::kPrimShort: |
| 3601 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3602 | case Primitive::kPrimLong: |
| 3603 | // Type conversion from long to short is a result of code transformations. |
| 3604 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3605 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3606 | case Primitive::kPrimBoolean: |
| 3607 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3608 | case Primitive::kPrimByte: |
| 3609 | case Primitive::kPrimInt: |
| 3610 | case Primitive::kPrimChar: |
| 3611 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3612 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3613 | break; |
| 3614 | |
| 3615 | default: |
| 3616 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3617 | << " to " << result_type; |
| 3618 | } |
| 3619 | break; |
| 3620 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3621 | case Primitive::kPrimInt: |
| 3622 | switch (input_type) { |
| 3623 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3624 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3625 | DCHECK(out.IsRegister()); |
| 3626 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3627 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3628 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3629 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3630 | } else { |
| 3631 | DCHECK(in.IsConstant()); |
| 3632 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3633 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3634 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3635 | } |
| 3636 | break; |
| 3637 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3638 | case Primitive::kPrimFloat: { |
| 3639 | // Processing a Dex `float-to-int' instruction. |
| 3640 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3641 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3642 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3643 | break; |
| 3644 | } |
| 3645 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3646 | case Primitive::kPrimDouble: { |
| 3647 | // Processing a Dex `double-to-int' instruction. |
| 3648 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3649 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3650 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3651 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3652 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3653 | |
| 3654 | default: |
| 3655 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3656 | << " to " << result_type; |
| 3657 | } |
| 3658 | break; |
| 3659 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3660 | case Primitive::kPrimLong: |
| 3661 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3662 | case Primitive::kPrimBoolean: |
| 3663 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3664 | case Primitive::kPrimByte: |
| 3665 | case Primitive::kPrimShort: |
| 3666 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3667 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3668 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3669 | DCHECK(out.IsRegisterPair()); |
| 3670 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3671 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3672 | // Sign extension. |
| 3673 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3674 | out.AsRegisterPairLow<Register>(), |
| 3675 | 31); |
| 3676 | break; |
| 3677 | |
| 3678 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3679 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3680 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3681 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3682 | break; |
| 3683 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3684 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3685 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3686 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3687 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | |
| 3690 | default: |
| 3691 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3692 | << " to " << result_type; |
| 3693 | } |
| 3694 | break; |
| 3695 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3696 | case Primitive::kPrimChar: |
| 3697 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3698 | case Primitive::kPrimLong: |
| 3699 | // Type conversion from long to char is a result of code transformations. |
| 3700 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3701 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3702 | case Primitive::kPrimBoolean: |
| 3703 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3704 | case Primitive::kPrimByte: |
| 3705 | case Primitive::kPrimShort: |
| 3706 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3707 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3708 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3709 | break; |
| 3710 | |
| 3711 | default: |
| 3712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3713 | << " to " << result_type; |
| 3714 | } |
| 3715 | break; |
| 3716 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3717 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3718 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3719 | case Primitive::kPrimBoolean: |
| 3720 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3721 | case Primitive::kPrimByte: |
| 3722 | case Primitive::kPrimShort: |
| 3723 | case Primitive::kPrimInt: |
| 3724 | case Primitive::kPrimChar: { |
| 3725 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3726 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3727 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3728 | break; |
| 3729 | } |
| 3730 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3731 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3732 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3733 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3734 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3735 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3736 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3737 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3738 | // Processing a Dex `double-to-float' instruction. |
| 3739 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3740 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3741 | break; |
| 3742 | |
| 3743 | default: |
| 3744 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3745 | << " to " << result_type; |
| 3746 | }; |
| 3747 | break; |
| 3748 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3749 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3750 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3751 | case Primitive::kPrimBoolean: |
| 3752 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimByte: |
| 3754 | case Primitive::kPrimShort: |
| 3755 | case Primitive::kPrimInt: |
| 3756 | case Primitive::kPrimChar: { |
| 3757 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3758 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3759 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3760 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3761 | break; |
| 3762 | } |
| 3763 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3764 | case Primitive::kPrimLong: { |
| 3765 | // Processing a Dex `long-to-double' instruction. |
| 3766 | Register low = in.AsRegisterPairLow<Register>(); |
| 3767 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3768 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3769 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3770 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3771 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3772 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3773 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3774 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3775 | // temp_d = int-to-double(high) |
| 3776 | __ vmovsr(temp_s, high); |
| 3777 | __ vcvtdi(temp_d, temp_s); |
| 3778 | // constant_d = k2Pow32EncodingForDouble |
| 3779 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3780 | // out_d = unsigned-to-double(low) |
| 3781 | __ vmovsr(out_s, low); |
| 3782 | __ vcvtdu(out_d, out_s); |
| 3783 | // out_d += temp_d * constant_d |
| 3784 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | } |
| 3787 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3788 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3789 | // Processing a Dex `float-to-double' instruction. |
| 3790 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3791 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | |
| 3794 | default: |
| 3795 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3796 | << " to " << result_type; |
| 3797 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3798 | break; |
| 3799 | |
| 3800 | default: |
| 3801 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3802 | << " to " << result_type; |
| 3803 | } |
| 3804 | } |
| 3805 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3806 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3807 | LocationSummary* locations = |
| 3808 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3809 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3810 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3811 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3812 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3813 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3814 | break; |
| 3815 | } |
| 3816 | |
| 3817 | case Primitive::kPrimLong: { |
| 3818 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3819 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3820 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3821 | break; |
| 3822 | } |
| 3823 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3824 | case Primitive::kPrimFloat: |
| 3825 | case Primitive::kPrimDouble: { |
| 3826 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3827 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3828 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3829 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3830 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3831 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3832 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3833 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3834 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3838 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3839 | Location out = locations->Out(); |
| 3840 | Location first = locations->InAt(0); |
| 3841 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3842 | switch (add->GetResultType()) { |
| 3843 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3844 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3845 | __ add(out.AsRegister<Register>(), |
| 3846 | first.AsRegister<Register>(), |
| 3847 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3848 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3849 | __ AddConstant(out.AsRegister<Register>(), |
| 3850 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3851 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3852 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3853 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3854 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3855 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3856 | if (second.IsConstant()) { |
| 3857 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3858 | GenerateAddLongConst(out, first, value); |
| 3859 | } else { |
| 3860 | DCHECK(second.IsRegisterPair()); |
| 3861 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3862 | first.AsRegisterPairLow<Register>(), |
| 3863 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3864 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3865 | first.AsRegisterPairHigh<Register>(), |
| 3866 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3867 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3868 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3869 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3870 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3871 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3872 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3873 | first.AsFpuRegister<SRegister>(), |
| 3874 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3875 | break; |
| 3876 | |
| 3877 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3878 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3879 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3880 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3881 | break; |
| 3882 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3883 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3884 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3888 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3889 | LocationSummary* locations = |
| 3890 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3891 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3892 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3893 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3894 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3895 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | case Primitive::kPrimLong: { |
| 3900 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3901 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3903 | break; |
| 3904 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3905 | case Primitive::kPrimFloat: |
| 3906 | case Primitive::kPrimDouble: { |
| 3907 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3908 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3909 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3910 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3911 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3912 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3913 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3914 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3918 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3919 | Location out = locations->Out(); |
| 3920 | Location first = locations->InAt(0); |
| 3921 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3922 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3923 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3924 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3925 | __ sub(out.AsRegister<Register>(), |
| 3926 | first.AsRegister<Register>(), |
| 3927 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3928 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3929 | __ AddConstant(out.AsRegister<Register>(), |
| 3930 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3931 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3932 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3933 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3934 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3935 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3936 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3937 | if (second.IsConstant()) { |
| 3938 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3939 | GenerateAddLongConst(out, first, -value); |
| 3940 | } else { |
| 3941 | DCHECK(second.IsRegisterPair()); |
| 3942 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3943 | first.AsRegisterPairLow<Register>(), |
| 3944 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3945 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3946 | first.AsRegisterPairHigh<Register>(), |
| 3947 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3948 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3949 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3950 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3951 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3952 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3953 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3954 | first.AsFpuRegister<SRegister>(), |
| 3955 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3956 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3960 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3961 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3962 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3963 | break; |
| 3964 | } |
| 3965 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3966 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3967 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3968 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3972 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3973 | LocationSummary* locations = |
| 3974 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3975 | switch (mul->GetResultType()) { |
| 3976 | case Primitive::kPrimInt: |
| 3977 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3978 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3979 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3980 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3981 | break; |
| 3982 | } |
| 3983 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3984 | case Primitive::kPrimFloat: |
| 3985 | case Primitive::kPrimDouble: { |
| 3986 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3987 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3988 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3989 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3990 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3991 | |
| 3992 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3993 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3998 | LocationSummary* locations = mul->GetLocations(); |
| 3999 | Location out = locations->Out(); |
| 4000 | Location first = locations->InAt(0); |
| 4001 | Location second = locations->InAt(1); |
| 4002 | switch (mul->GetResultType()) { |
| 4003 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4004 | __ mul(out.AsRegister<Register>(), |
| 4005 | first.AsRegister<Register>(), |
| 4006 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4007 | break; |
| 4008 | } |
| 4009 | case Primitive::kPrimLong: { |
| 4010 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 4011 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 4012 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 4013 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 4014 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 4015 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 4016 | |
| 4017 | // Extra checks to protect caused by the existence of R1_R2. |
| 4018 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4019 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 4020 | DCHECK_NE(out_hi, in1_lo); |
| 4021 | DCHECK_NE(out_hi, in2_lo); |
| 4022 | |
| 4023 | // input: in1 - 64 bits, in2 - 64 bits |
| 4024 | // output: out |
| 4025 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4026 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4027 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4028 | |
| 4029 | // IP <- in1.lo * in2.hi |
| 4030 | __ mul(IP, in1_lo, in2_hi); |
| 4031 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4032 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 4033 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4034 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 4035 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 4036 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 4037 | break; |
| 4038 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4039 | |
| 4040 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4041 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 4042 | first.AsFpuRegister<SRegister>(), |
| 4043 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4044 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4048 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4049 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4050 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4051 | break; |
| 4052 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4053 | |
| 4054 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4055 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4059 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4060 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4061 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4062 | |
| 4063 | LocationSummary* locations = instruction->GetLocations(); |
| 4064 | Location second = locations->InAt(1); |
| 4065 | DCHECK(second.IsConstant()); |
| 4066 | |
| 4067 | Register out = locations->Out().AsRegister<Register>(); |
| 4068 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4069 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4070 | DCHECK(imm == 1 || imm == -1); |
| 4071 | |
| 4072 | if (instruction->IsRem()) { |
| 4073 | __ LoadImmediate(out, 0); |
| 4074 | } else { |
| 4075 | if (imm == 1) { |
| 4076 | __ Mov(out, dividend); |
| 4077 | } else { |
| 4078 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4079 | } |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4084 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4085 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4086 | |
| 4087 | LocationSummary* locations = instruction->GetLocations(); |
| 4088 | Location second = locations->InAt(1); |
| 4089 | DCHECK(second.IsConstant()); |
| 4090 | |
| 4091 | Register out = locations->Out().AsRegister<Register>(); |
| 4092 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4093 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4094 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4095 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4096 | int ctz_imm = CTZ(abs_imm); |
| 4097 | |
| 4098 | if (ctz_imm == 1) { |
| 4099 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4100 | } else { |
| 4101 | __ Asr(temp, dividend, 31); |
| 4102 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4103 | } |
| 4104 | __ add(out, temp, ShifterOperand(dividend)); |
| 4105 | |
| 4106 | if (instruction->IsDiv()) { |
| 4107 | __ Asr(out, out, ctz_imm); |
| 4108 | if (imm < 0) { |
| 4109 | __ rsb(out, out, ShifterOperand(0)); |
| 4110 | } |
| 4111 | } else { |
| 4112 | __ ubfx(out, out, 0, ctz_imm); |
| 4113 | __ sub(out, out, ShifterOperand(temp)); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4118 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4119 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4120 | |
| 4121 | LocationSummary* locations = instruction->GetLocations(); |
| 4122 | Location second = locations->InAt(1); |
| 4123 | DCHECK(second.IsConstant()); |
| 4124 | |
| 4125 | Register out = locations->Out().AsRegister<Register>(); |
| 4126 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4127 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4128 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4129 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4130 | |
| 4131 | int64_t magic; |
| 4132 | int shift; |
| 4133 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4134 | |
| 4135 | __ LoadImmediate(temp1, magic); |
| 4136 | __ smull(temp2, temp1, dividend, temp1); |
| 4137 | |
| 4138 | if (imm > 0 && magic < 0) { |
| 4139 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4140 | } else if (imm < 0 && magic > 0) { |
| 4141 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4142 | } |
| 4143 | |
| 4144 | if (shift != 0) { |
| 4145 | __ Asr(temp1, temp1, shift); |
| 4146 | } |
| 4147 | |
| 4148 | if (instruction->IsDiv()) { |
| 4149 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4150 | } else { |
| 4151 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4152 | // TODO: Strength reduction for mls. |
| 4153 | __ LoadImmediate(temp2, imm); |
| 4154 | __ mls(out, temp1, temp2, dividend); |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4159 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4160 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4161 | |
| 4162 | LocationSummary* locations = instruction->GetLocations(); |
| 4163 | Location second = locations->InAt(1); |
| 4164 | DCHECK(second.IsConstant()); |
| 4165 | |
| 4166 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4167 | if (imm == 0) { |
| 4168 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4169 | } else if (imm == 1 || imm == -1) { |
| 4170 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4171 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4172 | DivRemByPowerOfTwo(instruction); |
| 4173 | } else { |
| 4174 | DCHECK(imm <= -2 || imm >= 2); |
| 4175 | GenerateDivRemWithAnyConstant(instruction); |
| 4176 | } |
| 4177 | } |
| 4178 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4179 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4180 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4181 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4182 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4183 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4184 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4185 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4186 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4187 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4188 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4189 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4192 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4193 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4194 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4195 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4196 | if (div->InputAt(1)->IsConstant()) { |
| 4197 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4198 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4200 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4201 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4202 | // No temp register required. |
| 4203 | } else { |
| 4204 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4205 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4206 | locations->AddTemp(Location::RequiresRegister()); |
| 4207 | } |
| 4208 | } |
| 4209 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4211 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4212 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4213 | } else { |
| 4214 | InvokeRuntimeCallingConvention calling_convention; |
| 4215 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4216 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4217 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4218 | // we only need the former. |
| 4219 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4220 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4221 | break; |
| 4222 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4223 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4224 | InvokeRuntimeCallingConvention calling_convention; |
| 4225 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4226 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4227 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4228 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4229 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | case Primitive::kPrimFloat: |
| 4233 | case Primitive::kPrimDouble: { |
| 4234 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4235 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4236 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4237 | break; |
| 4238 | } |
| 4239 | |
| 4240 | default: |
| 4241 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4246 | LocationSummary* locations = div->GetLocations(); |
| 4247 | Location out = locations->Out(); |
| 4248 | Location first = locations->InAt(0); |
| 4249 | Location second = locations->InAt(1); |
| 4250 | |
| 4251 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4252 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4253 | if (second.IsConstant()) { |
| 4254 | GenerateDivRemConstantIntegral(div); |
| 4255 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4256 | __ sdiv(out.AsRegister<Register>(), |
| 4257 | first.AsRegister<Register>(), |
| 4258 | second.AsRegister<Register>()); |
| 4259 | } else { |
| 4260 | InvokeRuntimeCallingConvention calling_convention; |
| 4261 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4262 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4263 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4264 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4265 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4266 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4267 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4268 | break; |
| 4269 | } |
| 4270 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4271 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4272 | InvokeRuntimeCallingConvention calling_convention; |
| 4273 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4274 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4275 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4276 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4277 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4278 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4279 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4280 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4281 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4282 | break; |
| 4283 | } |
| 4284 | |
| 4285 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4286 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4287 | first.AsFpuRegister<SRegister>(), |
| 4288 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4289 | break; |
| 4290 | } |
| 4291 | |
| 4292 | case Primitive::kPrimDouble: { |
| 4293 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4294 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4295 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4296 | break; |
| 4297 | } |
| 4298 | |
| 4299 | default: |
| 4300 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4301 | } |
| 4302 | } |
| 4303 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4304 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4305 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4306 | |
| 4307 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4308 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4309 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4310 | // sdiv will be replaced by other instruction sequence. |
| 4311 | call_kind = LocationSummary::kNoCall; |
| 4312 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4313 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4314 | // Have hardware divide instruction for int, do it with three instructions. |
| 4315 | call_kind = LocationSummary::kNoCall; |
| 4316 | } |
| 4317 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4318 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4319 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4320 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4321 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4322 | if (rem->InputAt(1)->IsConstant()) { |
| 4323 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4324 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4325 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4326 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4327 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4328 | // No temp register required. |
| 4329 | } else { |
| 4330 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4331 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4332 | locations->AddTemp(Location::RequiresRegister()); |
| 4333 | } |
| 4334 | } |
| 4335 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4337 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4338 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4339 | locations->AddTemp(Location::RequiresRegister()); |
| 4340 | } else { |
| 4341 | InvokeRuntimeCallingConvention calling_convention; |
| 4342 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4343 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4344 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4345 | // we only need the latter. |
| 4346 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4347 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4348 | break; |
| 4349 | } |
| 4350 | case Primitive::kPrimLong: { |
| 4351 | InvokeRuntimeCallingConvention calling_convention; |
| 4352 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4353 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4354 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4355 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4356 | // The runtime helper puts the output in R2,R3. |
| 4357 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4358 | break; |
| 4359 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4360 | case Primitive::kPrimFloat: { |
| 4361 | InvokeRuntimeCallingConvention calling_convention; |
| 4362 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4363 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4364 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4365 | break; |
| 4366 | } |
| 4367 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4368 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4369 | InvokeRuntimeCallingConvention calling_convention; |
| 4370 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4371 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4372 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4373 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4374 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4375 | break; |
| 4376 | } |
| 4377 | |
| 4378 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4379 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4384 | LocationSummary* locations = rem->GetLocations(); |
| 4385 | Location out = locations->Out(); |
| 4386 | Location first = locations->InAt(0); |
| 4387 | Location second = locations->InAt(1); |
| 4388 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4389 | Primitive::Type type = rem->GetResultType(); |
| 4390 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4391 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4392 | if (second.IsConstant()) { |
| 4393 | GenerateDivRemConstantIntegral(rem); |
| 4394 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4395 | Register reg1 = first.AsRegister<Register>(); |
| 4396 | Register reg2 = second.AsRegister<Register>(); |
| 4397 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4398 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4399 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4400 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4401 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4402 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4403 | } else { |
| 4404 | InvokeRuntimeCallingConvention calling_convention; |
| 4405 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4406 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4407 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4408 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4409 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4410 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4411 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4412 | break; |
| 4413 | } |
| 4414 | |
| 4415 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4416 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4417 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4418 | break; |
| 4419 | } |
| 4420 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4421 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4422 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4423 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4424 | break; |
| 4425 | } |
| 4426 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4427 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4428 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4429 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4430 | break; |
| 4431 | } |
| 4432 | |
| 4433 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4434 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4435 | } |
| 4436 | } |
| 4437 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4438 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4439 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4440 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4444 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4445 | codegen_->AddSlowPath(slow_path); |
| 4446 | |
| 4447 | LocationSummary* locations = instruction->GetLocations(); |
| 4448 | Location value = locations->InAt(0); |
| 4449 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4450 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4451 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4452 | case Primitive::kPrimByte: |
| 4453 | case Primitive::kPrimChar: |
| 4454 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4455 | case Primitive::kPrimInt: { |
| 4456 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4457 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4458 | } else { |
| 4459 | DCHECK(value.IsConstant()) << value; |
| 4460 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4461 | __ b(slow_path->GetEntryLabel()); |
| 4462 | } |
| 4463 | } |
| 4464 | break; |
| 4465 | } |
| 4466 | case Primitive::kPrimLong: { |
| 4467 | if (value.IsRegisterPair()) { |
| 4468 | __ orrs(IP, |
| 4469 | value.AsRegisterPairLow<Register>(), |
| 4470 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4471 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4472 | } else { |
| 4473 | DCHECK(value.IsConstant()) << value; |
| 4474 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4475 | __ b(slow_path->GetEntryLabel()); |
| 4476 | } |
| 4477 | } |
| 4478 | break; |
| 4479 | default: |
| 4480 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4481 | } |
| 4482 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4483 | } |
| 4484 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4485 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4486 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4487 | Location rhs = locations->InAt(1); |
| 4488 | Register out = locations->Out().AsRegister<Register>(); |
| 4489 | |
| 4490 | if (rhs.IsConstant()) { |
| 4491 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4492 | // so map all rotations to a +ve. equivalent in that range. |
| 4493 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4494 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4495 | if (rot) { |
| 4496 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4497 | // (e.g. left by 2 bits == right by 30.) |
| 4498 | __ Ror(out, in, rot); |
| 4499 | } else if (out != in) { |
| 4500 | __ Mov(out, in); |
| 4501 | } |
| 4502 | } else { |
| 4503 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4508 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4509 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4510 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4511 | void InstructionCodeGeneratorARM::HandleLongRotate(HRor* ror) { |
| 4512 | LocationSummary* locations = ror->GetLocations(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4513 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4514 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4515 | Location rhs = locations->InAt(1); |
| 4516 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4517 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4518 | |
| 4519 | if (rhs.IsConstant()) { |
| 4520 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4521 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4522 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4523 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4524 | // logic below to a simple pair of binary orr. |
| 4525 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4526 | if (rot >= kArmBitsPerWord) { |
| 4527 | rot -= kArmBitsPerWord; |
| 4528 | std::swap(in_reg_hi, in_reg_lo); |
| 4529 | } |
| 4530 | // Rotate, or mov to out for zero or word size rotations. |
| 4531 | if (rot != 0u) { |
| 4532 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4533 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4534 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4535 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4536 | } else { |
| 4537 | __ Mov(out_reg_lo, in_reg_lo); |
| 4538 | __ Mov(out_reg_hi, in_reg_hi); |
| 4539 | } |
| 4540 | } else { |
| 4541 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4542 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4543 | Label end; |
| 4544 | Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4545 | Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4546 | |
| 4547 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4548 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4549 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4550 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4551 | |
| 4552 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4553 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4554 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4555 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4556 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4557 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4558 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4559 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4560 | __ b(final_label); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4561 | |
| 4562 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4563 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4564 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4565 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4566 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4567 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4568 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4569 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4570 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4571 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4572 | if (end.IsLinked()) { |
| 4573 | __ Bind(&end); |
| 4574 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4575 | } |
| 4576 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4577 | |
| 4578 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4579 | LocationSummary* locations = |
| 4580 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4581 | switch (ror->GetResultType()) { |
| 4582 | case Primitive::kPrimInt: { |
| 4583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4584 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4585 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4586 | break; |
| 4587 | } |
| 4588 | case Primitive::kPrimLong: { |
| 4589 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4590 | if (ror->InputAt(1)->IsConstant()) { |
| 4591 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4592 | } else { |
| 4593 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4594 | locations->AddTemp(Location::RequiresRegister()); |
| 4595 | locations->AddTemp(Location::RequiresRegister()); |
| 4596 | } |
| 4597 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4598 | break; |
| 4599 | } |
| 4600 | default: |
| 4601 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4602 | } |
| 4603 | } |
| 4604 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4605 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4606 | LocationSummary* locations = ror->GetLocations(); |
| 4607 | Primitive::Type type = ror->GetResultType(); |
| 4608 | switch (type) { |
| 4609 | case Primitive::kPrimInt: { |
| 4610 | HandleIntegerRotate(locations); |
| 4611 | break; |
| 4612 | } |
| 4613 | case Primitive::kPrimLong: { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4614 | HandleLongRotate(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4615 | break; |
| 4616 | } |
| 4617 | default: |
| 4618 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4619 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4623 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4624 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4625 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4626 | LocationSummary* locations = |
| 4627 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4628 | |
| 4629 | switch (op->GetResultType()) { |
| 4630 | case Primitive::kPrimInt: { |
| 4631 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4632 | if (op->InputAt(1)->IsConstant()) { |
| 4633 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4634 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4635 | } else { |
| 4636 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4637 | // Make the output overlap, as it will be used to hold the masked |
| 4638 | // second input. |
| 4639 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4640 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4641 | break; |
| 4642 | } |
| 4643 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4644 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4645 | if (op->InputAt(1)->IsConstant()) { |
| 4646 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4647 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4648 | // don't clash with high registers which the register allocator currently guarantees. |
| 4649 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4650 | } else { |
| 4651 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4652 | locations->AddTemp(Location::RequiresRegister()); |
| 4653 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4654 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4655 | break; |
| 4656 | } |
| 4657 | default: |
| 4658 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4663 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4664 | |
| 4665 | LocationSummary* locations = op->GetLocations(); |
| 4666 | Location out = locations->Out(); |
| 4667 | Location first = locations->InAt(0); |
| 4668 | Location second = locations->InAt(1); |
| 4669 | |
| 4670 | Primitive::Type type = op->GetResultType(); |
| 4671 | switch (type) { |
| 4672 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4673 | Register out_reg = out.AsRegister<Register>(); |
| 4674 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4675 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4676 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4677 | // ARM doesn't mask the shift count so we need to do it ourselves. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4678 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4679 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4680 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4681 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4682 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4683 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4684 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4685 | } |
| 4686 | } else { |
| 4687 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4688 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4689 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4690 | __ Mov(out_reg, first_reg); |
| 4691 | } else if (op->IsShl()) { |
| 4692 | __ Lsl(out_reg, first_reg, shift_value); |
| 4693 | } else if (op->IsShr()) { |
| 4694 | __ Asr(out_reg, first_reg, shift_value); |
| 4695 | } else { |
| 4696 | __ Lsr(out_reg, first_reg, shift_value); |
| 4697 | } |
| 4698 | } |
| 4699 | break; |
| 4700 | } |
| 4701 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4702 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4703 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4704 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4705 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4706 | Register low = first.AsRegisterPairLow<Register>(); |
| 4707 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4708 | if (second.IsRegister()) { |
| 4709 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4710 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4711 | Register second_reg = second.AsRegister<Register>(); |
| 4712 | |
| 4713 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4714 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4715 | // Shift the high part |
| 4716 | __ Lsl(o_h, high, o_l); |
| 4717 | // Shift the low part and `or` what overflew on the high part |
| 4718 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4719 | __ Lsr(temp, low, temp); |
| 4720 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4721 | // If the shift is > 32 bits, override the high part |
| 4722 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4723 | __ it(PL); |
| 4724 | __ Lsl(o_h, low, temp, PL); |
| 4725 | // Shift the low part |
| 4726 | __ Lsl(o_l, low, o_l); |
| 4727 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4728 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4729 | // Shift the low part |
| 4730 | __ Lsr(o_l, low, o_h); |
| 4731 | // Shift the high part and `or` what underflew on the low part |
| 4732 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4733 | __ Lsl(temp, high, temp); |
| 4734 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4735 | // If the shift is > 32 bits, override the low part |
| 4736 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4737 | __ it(PL); |
| 4738 | __ Asr(o_l, high, temp, PL); |
| 4739 | // Shift the high part |
| 4740 | __ Asr(o_h, high, o_h); |
| 4741 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4742 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4743 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4744 | __ Lsr(o_l, low, o_h); |
| 4745 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4746 | __ Lsl(temp, high, temp); |
| 4747 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4748 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4749 | __ it(PL); |
| 4750 | __ Lsr(o_l, high, temp, PL); |
| 4751 | __ Lsr(o_h, high, o_h); |
| 4752 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4753 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4754 | // Register allocator doesn't create partial overlap. |
| 4755 | DCHECK_NE(o_l, high); |
| 4756 | DCHECK_NE(o_h, low); |
| 4757 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4758 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4759 | if (shift_value > 32) { |
| 4760 | if (op->IsShl()) { |
| 4761 | __ Lsl(o_h, low, shift_value - 32); |
| 4762 | __ LoadImmediate(o_l, 0); |
| 4763 | } else if (op->IsShr()) { |
| 4764 | __ Asr(o_l, high, shift_value - 32); |
| 4765 | __ Asr(o_h, high, 31); |
| 4766 | } else { |
| 4767 | __ Lsr(o_l, high, shift_value - 32); |
| 4768 | __ LoadImmediate(o_h, 0); |
| 4769 | } |
| 4770 | } else if (shift_value == 32) { |
| 4771 | if (op->IsShl()) { |
| 4772 | __ mov(o_h, ShifterOperand(low)); |
| 4773 | __ LoadImmediate(o_l, 0); |
| 4774 | } else if (op->IsShr()) { |
| 4775 | __ mov(o_l, ShifterOperand(high)); |
| 4776 | __ Asr(o_h, high, 31); |
| 4777 | } else { |
| 4778 | __ mov(o_l, ShifterOperand(high)); |
| 4779 | __ LoadImmediate(o_h, 0); |
| 4780 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4781 | } else if (shift_value == 1) { |
| 4782 | if (op->IsShl()) { |
| 4783 | __ Lsls(o_l, low, 1); |
| 4784 | __ adc(o_h, high, ShifterOperand(high)); |
| 4785 | } else if (op->IsShr()) { |
| 4786 | __ Asrs(o_h, high, 1); |
| 4787 | __ Rrx(o_l, low); |
| 4788 | } else { |
| 4789 | __ Lsrs(o_h, high, 1); |
| 4790 | __ Rrx(o_l, low); |
| 4791 | } |
| 4792 | } else { |
| 4793 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4794 | if (op->IsShl()) { |
| 4795 | __ Lsl(o_h, high, shift_value); |
| 4796 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4797 | __ Lsl(o_l, low, shift_value); |
| 4798 | } else if (op->IsShr()) { |
| 4799 | __ Lsr(o_l, low, shift_value); |
| 4800 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4801 | __ Asr(o_h, high, shift_value); |
| 4802 | } else { |
| 4803 | __ Lsr(o_l, low, shift_value); |
| 4804 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4805 | __ Lsr(o_h, high, shift_value); |
| 4806 | } |
| 4807 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4808 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | default: |
| 4812 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4813 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4818 | HandleShift(shl); |
| 4819 | } |
| 4820 | |
| 4821 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4822 | HandleShift(shl); |
| 4823 | } |
| 4824 | |
| 4825 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4826 | HandleShift(shr); |
| 4827 | } |
| 4828 | |
| 4829 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4830 | HandleShift(shr); |
| 4831 | } |
| 4832 | |
| 4833 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4834 | HandleShift(ushr); |
| 4835 | } |
| 4836 | |
| 4837 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4838 | HandleShift(ushr); |
| 4839 | } |
| 4840 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4841 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4842 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4843 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4844 | if (instruction->IsStringAlloc()) { |
| 4845 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4846 | } else { |
| 4847 | InvokeRuntimeCallingConvention calling_convention; |
| 4848 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4849 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4850 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4854 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4855 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4856 | if (instruction->IsStringAlloc()) { |
| 4857 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4858 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4859 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4860 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4861 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4862 | __ blx(LR); |
| 4863 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4864 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4865 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4866 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4867 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4868 | } |
| 4869 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4870 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4871 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4872 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4873 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4874 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4875 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4876 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4880 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4881 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4882 | QuickEntrypointEnum entrypoint = |
| 4883 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4884 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4885 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4886 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4887 | } |
| 4888 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4889 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4890 | LocationSummary* locations = |
| 4891 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4892 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4893 | if (location.IsStackSlot()) { |
| 4894 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4895 | } else if (location.IsDoubleStackSlot()) { |
| 4896 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4897 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4898 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4899 | } |
| 4900 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4901 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4902 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4903 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4907 | LocationSummary* locations = |
| 4908 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4909 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4910 | } |
| 4911 | |
| 4912 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4913 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4914 | } |
| 4915 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4916 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4917 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4918 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4920 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4921 | } |
| 4922 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4923 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4924 | LocationSummary* locations = not_->GetLocations(); |
| 4925 | Location out = locations->Out(); |
| 4926 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4927 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4928 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4929 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4930 | break; |
| 4931 | |
| 4932 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4933 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4934 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4935 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4936 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4937 | break; |
| 4938 | |
| 4939 | default: |
| 4940 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4941 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4942 | } |
| 4943 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4944 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4945 | LocationSummary* locations = |
| 4946 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4948 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4949 | } |
| 4950 | |
| 4951 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4952 | LocationSummary* locations = bool_not->GetLocations(); |
| 4953 | Location out = locations->Out(); |
| 4954 | Location in = locations->InAt(0); |
| 4955 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4956 | } |
| 4957 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4958 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4959 | LocationSummary* locations = |
| 4960 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4961 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4962 | case Primitive::kPrimBoolean: |
| 4963 | case Primitive::kPrimByte: |
| 4964 | case Primitive::kPrimShort: |
| 4965 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4966 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4967 | case Primitive::kPrimLong: { |
| 4968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4969 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4970 | // Output overlaps because it is written before doing the low comparison. |
| 4971 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4972 | break; |
| 4973 | } |
| 4974 | case Primitive::kPrimFloat: |
| 4975 | case Primitive::kPrimDouble: { |
| 4976 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4977 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4978 | locations->SetOut(Location::RequiresRegister()); |
| 4979 | break; |
| 4980 | } |
| 4981 | default: |
| 4982 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4983 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4987 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4988 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4989 | Location left = locations->InAt(0); |
| 4990 | Location right = locations->InAt(1); |
| 4991 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4992 | Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4993 | Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4994 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4995 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4996 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4997 | case Primitive::kPrimBoolean: |
| 4998 | case Primitive::kPrimByte: |
| 4999 | case Primitive::kPrimShort: |
| 5000 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5001 | case Primitive::kPrimInt: { |
| 5002 | __ LoadImmediate(out, 0); |
| 5003 | __ cmp(left.AsRegister<Register>(), |
| 5004 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 5005 | less_cond = LT; |
| 5006 | break; |
| 5007 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5008 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5009 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 5010 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5011 | __ b(&less, LT); |
| 5012 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5013 | // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags. |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5014 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5015 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 5016 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5017 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5018 | break; |
| 5019 | } |
| 5020 | case Primitive::kPrimFloat: |
| 5021 | case Primitive::kPrimDouble: { |
| 5022 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5023 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5024 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5025 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5026 | break; |
| 5027 | } |
| 5028 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5029 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5030 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5031 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5032 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5033 | __ b(final_label, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5034 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5035 | |
| 5036 | __ Bind(&greater); |
| 5037 | __ LoadImmediate(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5038 | __ b(final_label); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5039 | |
| 5040 | __ Bind(&less); |
| 5041 | __ LoadImmediate(out, -1); |
| 5042 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5043 | if (done.IsLinked()) { |
| 5044 | __ Bind(&done); |
| 5045 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5048 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5049 | LocationSummary* locations = |
| 5050 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5051 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5052 | locations->SetInAt(i, Location::Any()); |
| 5053 | } |
| 5054 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5057 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5058 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5059 | } |
| 5060 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5061 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5062 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5063 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5064 | switch (kind) { |
| 5065 | case MemBarrierKind::kAnyStore: |
| 5066 | case MemBarrierKind::kLoadAny: |
| 5067 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5068 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5069 | break; |
| 5070 | } |
| 5071 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5072 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5073 | break; |
| 5074 | } |
| 5075 | default: |
| 5076 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5077 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5078 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5082 | uint32_t offset, |
| 5083 | Register out_lo, |
| 5084 | Register out_hi) { |
| 5085 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5086 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5087 | // `offset` into `out_lo` does not clutter `addr`. |
| 5088 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5089 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5090 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5091 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5092 | } |
| 5093 | __ ldrexd(out_lo, out_hi, addr); |
| 5094 | } |
| 5095 | |
| 5096 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5097 | uint32_t offset, |
| 5098 | Register value_lo, |
| 5099 | Register value_hi, |
| 5100 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5101 | Register temp2, |
| 5102 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5103 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5104 | if (offset != 0) { |
| 5105 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5106 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5107 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5108 | } |
| 5109 | __ Bind(&fail); |
| 5110 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5111 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5112 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5113 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5114 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5115 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5119 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5120 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5121 | LocationSummary* locations = |
| 5122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5123 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5124 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5125 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5126 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5127 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5128 | } else { |
| 5129 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5130 | } |
| 5131 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5132 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5133 | bool generate_volatile = field_info.IsVolatile() |
| 5134 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5135 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5136 | bool needs_write_barrier = |
| 5137 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5138 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5139 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5140 | if (needs_write_barrier) { |
| 5141 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5142 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5143 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5144 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5145 | // - registers need to be consecutive |
| 5146 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5147 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5148 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5149 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5150 | |
| 5151 | locations->AddTemp(Location::RequiresRegister()); |
| 5152 | locations->AddTemp(Location::RequiresRegister()); |
| 5153 | if (field_type == Primitive::kPrimDouble) { |
| 5154 | // For doubles we need two more registers to copy the value. |
| 5155 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5156 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5157 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5158 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5159 | } |
| 5160 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5161 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5162 | const FieldInfo& field_info, |
| 5163 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5164 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5165 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5166 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5167 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5168 | Location value = locations->InAt(1); |
| 5169 | |
| 5170 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5171 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5172 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5173 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5174 | bool needs_write_barrier = |
| 5175 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | |
| 5177 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5178 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5179 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5180 | |
| 5181 | switch (field_type) { |
| 5182 | case Primitive::kPrimBoolean: |
| 5183 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5185 | break; |
| 5186 | } |
| 5187 | |
| 5188 | case Primitive::kPrimShort: |
| 5189 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5190 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5191 | break; |
| 5192 | } |
| 5193 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5194 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5195 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5196 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5197 | // Note that in the case where `value` is a null reference, |
| 5198 | // we do not enter this block, as a null reference does not |
| 5199 | // need poisoning. |
| 5200 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5201 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5202 | __ Mov(temp, value.AsRegister<Register>()); |
| 5203 | __ PoisonHeapReference(temp); |
| 5204 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5205 | } else { |
| 5206 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5207 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5208 | break; |
| 5209 | } |
| 5210 | |
| 5211 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5212 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5213 | GenerateWideAtomicStore(base, offset, |
| 5214 | value.AsRegisterPairLow<Register>(), |
| 5215 | value.AsRegisterPairHigh<Register>(), |
| 5216 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5217 | locations->GetTemp(1).AsRegister<Register>(), |
| 5218 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5219 | } else { |
| 5220 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5221 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5222 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5223 | break; |
| 5224 | } |
| 5225 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5226 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5227 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5228 | break; |
| 5229 | } |
| 5230 | |
| 5231 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5232 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5233 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5234 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5235 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5236 | |
| 5237 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5238 | |
| 5239 | GenerateWideAtomicStore(base, offset, |
| 5240 | value_reg_lo, |
| 5241 | value_reg_hi, |
| 5242 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5243 | locations->GetTemp(3).AsRegister<Register>(), |
| 5244 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5245 | } else { |
| 5246 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5247 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5248 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5249 | break; |
| 5250 | } |
| 5251 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5252 | case Primitive::kPrimVoid: |
| 5253 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5254 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5255 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5256 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5257 | // Longs and doubles are handled in the switch. |
| 5258 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5259 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5260 | } |
| 5261 | |
| 5262 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5263 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5264 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5265 | codegen_->MarkGCCard( |
| 5266 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5267 | } |
| 5268 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5269 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5270 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5271 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5272 | } |
| 5273 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5274 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5275 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5276 | |
| 5277 | bool object_field_get_with_read_barrier = |
| 5278 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5279 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5280 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5281 | object_field_get_with_read_barrier ? |
| 5282 | LocationSummary::kCallOnSlowPath : |
| 5283 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5284 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5285 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5286 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5287 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5288 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5289 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5290 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5291 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5292 | // The output overlaps in case of volatile long: we don't want the |
| 5293 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5294 | // object's location. Likewise, in the case of an object field get |
| 5295 | // with read barriers enabled, we do not want the load to overwrite |
| 5296 | // the object's location, as we need it to emit the read barrier. |
| 5297 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5298 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5299 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5300 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5301 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5302 | } else { |
| 5303 | locations->SetOut(Location::RequiresRegister(), |
| 5304 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5305 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5306 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5307 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5308 | // - registers need to be consecutive |
| 5309 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5310 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5311 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5312 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5313 | locations->AddTemp(Location::RequiresRegister()); |
| 5314 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5315 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5316 | // We need a temporary register for the read barrier marking slow |
| 5317 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 5318 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5319 | !Runtime::Current()->UseJitCompilation()) { |
| 5320 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5321 | // loads we need a temporary only if the offset is too big. |
| 5322 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5323 | locations->AddTemp(Location::RequiresRegister()); |
| 5324 | } |
| 5325 | // And we always need the reserved entrypoint register. |
| 5326 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5327 | } else { |
| 5328 | locations->AddTemp(Location::RequiresRegister()); |
| 5329 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5330 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5333 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5334 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5335 | << input->GetType(); |
| 5336 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5337 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5338 | return Location::ConstantLocation(input->AsConstant()); |
| 5339 | } else { |
| 5340 | return Location::RequiresFpuRegister(); |
| 5341 | } |
| 5342 | } |
| 5343 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5344 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5345 | Opcode opcode) { |
| 5346 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5347 | if (constant->IsConstant() && |
| 5348 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5349 | return Location::ConstantLocation(constant->AsConstant()); |
| 5350 | } |
| 5351 | return Location::RequiresRegister(); |
| 5352 | } |
| 5353 | |
| 5354 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5355 | Opcode opcode) { |
| 5356 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5357 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5358 | Opcode high_opcode = opcode; |
| 5359 | SetCc low_set_cc = kCcDontCare; |
| 5360 | switch (opcode) { |
| 5361 | case SUB: |
| 5362 | // Flip the operation to an ADD. |
| 5363 | value = -value; |
| 5364 | opcode = ADD; |
| 5365 | FALLTHROUGH_INTENDED; |
| 5366 | case ADD: |
| 5367 | if (Low32Bits(value) == 0u) { |
| 5368 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5369 | } |
| 5370 | high_opcode = ADC; |
| 5371 | low_set_cc = kCcSet; |
| 5372 | break; |
| 5373 | default: |
| 5374 | break; |
| 5375 | } |
| 5376 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5377 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5378 | } else { |
| 5379 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5380 | } |
| 5381 | } |
| 5382 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5383 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5384 | Opcode opcode, |
| 5385 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5386 | ShifterOperand so; |
| 5387 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5388 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5389 | return true; |
| 5390 | } |
| 5391 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5392 | uint32_t neg_value = 0; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5393 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5394 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5395 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5396 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5397 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5398 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5399 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5400 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5401 | default: |
| 5402 | return false; |
| 5403 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5404 | |
| 5405 | if (assembler->ShifterOperandCanHold(kNoRegister, |
| 5406 | kNoRegister, |
| 5407 | neg_opcode, |
| 5408 | neg_value, |
| 5409 | set_cc, |
| 5410 | &so)) { |
| 5411 | return true; |
| 5412 | } |
| 5413 | |
| 5414 | return opcode == AND && IsPowerOfTwo(value + 1); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5415 | } |
| 5416 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5417 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5418 | const FieldInfo& field_info) { |
| 5419 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5420 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5421 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5422 | Location base_loc = locations->InAt(0); |
| 5423 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5424 | Location out = locations->Out(); |
| 5425 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5426 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5427 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5428 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5429 | |
| 5430 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5431 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5432 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5433 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5434 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5435 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5436 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5437 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5438 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5439 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5440 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5441 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5442 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5443 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5444 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5445 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5446 | |
| 5447 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5448 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5449 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5450 | |
| 5451 | case Primitive::kPrimNot: { |
| 5452 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5453 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5454 | Location temp_loc = locations->GetTemp(0); |
| 5455 | // Note that a potential implicit null check is handled in this |
| 5456 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5457 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5458 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5459 | if (is_volatile) { |
| 5460 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5461 | } |
| 5462 | } else { |
| 5463 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5464 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5465 | if (is_volatile) { |
| 5466 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5467 | } |
| 5468 | // If read barriers are enabled, emit read barriers other than |
| 5469 | // Baker's using a slow path (and also unpoison the loaded |
| 5470 | // reference, if heap poisoning is enabled). |
| 5471 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5472 | } |
| 5473 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5474 | } |
| 5475 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5476 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5477 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5478 | GenerateWideAtomicLoad(base, offset, |
| 5479 | out.AsRegisterPairLow<Register>(), |
| 5480 | out.AsRegisterPairHigh<Register>()); |
| 5481 | } else { |
| 5482 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5483 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5484 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5485 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5486 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5487 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5488 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5489 | |
| 5490 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5491 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5492 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5493 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5494 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5495 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5496 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5497 | __ vmovdrr(out_reg, lo, hi); |
| 5498 | } else { |
| 5499 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5500 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5501 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5502 | break; |
| 5503 | } |
| 5504 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5505 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5506 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5507 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5508 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5509 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5510 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5511 | // Potential implicit null checks, in the case of reference or |
| 5512 | // double fields, are handled in the previous switch statement. |
| 5513 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5514 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5515 | } |
| 5516 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5517 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5518 | if (field_type == Primitive::kPrimNot) { |
| 5519 | // Memory barriers, in the case of references, are also handled |
| 5520 | // in the previous switch statement. |
| 5521 | } else { |
| 5522 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5523 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5524 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5528 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5529 | } |
| 5530 | |
| 5531 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5532 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5536 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5537 | } |
| 5538 | |
| 5539 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5540 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5541 | } |
| 5542 | |
| 5543 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5544 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5545 | } |
| 5546 | |
| 5547 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5548 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5549 | } |
| 5550 | |
| 5551 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5552 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5553 | } |
| 5554 | |
| 5555 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5556 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5557 | } |
| 5558 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5559 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5560 | HUnresolvedInstanceFieldGet* instruction) { |
| 5561 | FieldAccessCallingConventionARM calling_convention; |
| 5562 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5563 | instruction, instruction->GetFieldType(), calling_convention); |
| 5564 | } |
| 5565 | |
| 5566 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5567 | HUnresolvedInstanceFieldGet* instruction) { |
| 5568 | FieldAccessCallingConventionARM calling_convention; |
| 5569 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5570 | instruction->GetFieldType(), |
| 5571 | instruction->GetFieldIndex(), |
| 5572 | instruction->GetDexPc(), |
| 5573 | calling_convention); |
| 5574 | } |
| 5575 | |
| 5576 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5577 | HUnresolvedInstanceFieldSet* instruction) { |
| 5578 | FieldAccessCallingConventionARM calling_convention; |
| 5579 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5580 | instruction, instruction->GetFieldType(), calling_convention); |
| 5581 | } |
| 5582 | |
| 5583 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5584 | HUnresolvedInstanceFieldSet* instruction) { |
| 5585 | FieldAccessCallingConventionARM calling_convention; |
| 5586 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5587 | instruction->GetFieldType(), |
| 5588 | instruction->GetFieldIndex(), |
| 5589 | instruction->GetDexPc(), |
| 5590 | calling_convention); |
| 5591 | } |
| 5592 | |
| 5593 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5594 | HUnresolvedStaticFieldGet* instruction) { |
| 5595 | FieldAccessCallingConventionARM calling_convention; |
| 5596 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5597 | instruction, instruction->GetFieldType(), calling_convention); |
| 5598 | } |
| 5599 | |
| 5600 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5601 | HUnresolvedStaticFieldGet* instruction) { |
| 5602 | FieldAccessCallingConventionARM calling_convention; |
| 5603 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5604 | instruction->GetFieldType(), |
| 5605 | instruction->GetFieldIndex(), |
| 5606 | instruction->GetDexPc(), |
| 5607 | calling_convention); |
| 5608 | } |
| 5609 | |
| 5610 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5611 | HUnresolvedStaticFieldSet* instruction) { |
| 5612 | FieldAccessCallingConventionARM calling_convention; |
| 5613 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5614 | instruction, instruction->GetFieldType(), calling_convention); |
| 5615 | } |
| 5616 | |
| 5617 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5618 | HUnresolvedStaticFieldSet* instruction) { |
| 5619 | FieldAccessCallingConventionARM calling_convention; |
| 5620 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5621 | instruction->GetFieldType(), |
| 5622 | instruction->GetFieldIndex(), |
| 5623 | instruction->GetDexPc(), |
| 5624 | calling_convention); |
| 5625 | } |
| 5626 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5627 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5628 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5629 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5630 | } |
| 5631 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5632 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5633 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5634 | return; |
| 5635 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5636 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5637 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5638 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5639 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5642 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5643 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5644 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5645 | |
| 5646 | LocationSummary* locations = instruction->GetLocations(); |
| 5647 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5648 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5649 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5650 | } |
| 5651 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5652 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5653 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5654 | } |
| 5655 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5656 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5657 | switch (type) { |
| 5658 | case Primitive::kPrimNot: |
| 5659 | return kLoadWord; |
| 5660 | case Primitive::kPrimBoolean: |
| 5661 | return kLoadUnsignedByte; |
| 5662 | case Primitive::kPrimByte: |
| 5663 | return kLoadSignedByte; |
| 5664 | case Primitive::kPrimChar: |
| 5665 | return kLoadUnsignedHalfword; |
| 5666 | case Primitive::kPrimShort: |
| 5667 | return kLoadSignedHalfword; |
| 5668 | case Primitive::kPrimInt: |
| 5669 | return kLoadWord; |
| 5670 | case Primitive::kPrimLong: |
| 5671 | return kLoadWordPair; |
| 5672 | case Primitive::kPrimFloat: |
| 5673 | return kLoadSWord; |
| 5674 | case Primitive::kPrimDouble: |
| 5675 | return kLoadDWord; |
| 5676 | default: |
| 5677 | LOG(FATAL) << "Unreachable type " << type; |
| 5678 | UNREACHABLE(); |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5683 | switch (type) { |
| 5684 | case Primitive::kPrimNot: |
| 5685 | return kStoreWord; |
| 5686 | case Primitive::kPrimBoolean: |
| 5687 | case Primitive::kPrimByte: |
| 5688 | return kStoreByte; |
| 5689 | case Primitive::kPrimChar: |
| 5690 | case Primitive::kPrimShort: |
| 5691 | return kStoreHalfword; |
| 5692 | case Primitive::kPrimInt: |
| 5693 | return kStoreWord; |
| 5694 | case Primitive::kPrimLong: |
| 5695 | return kStoreWordPair; |
| 5696 | case Primitive::kPrimFloat: |
| 5697 | return kStoreSWord; |
| 5698 | case Primitive::kPrimDouble: |
| 5699 | return kStoreDWord; |
| 5700 | default: |
| 5701 | LOG(FATAL) << "Unreachable type " << type; |
| 5702 | UNREACHABLE(); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5707 | Location out_loc, |
| 5708 | Register base, |
| 5709 | Register reg_offset, |
| 5710 | Condition cond) { |
| 5711 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5712 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5713 | |
| 5714 | switch (type) { |
| 5715 | case Primitive::kPrimByte: |
| 5716 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5717 | break; |
| 5718 | case Primitive::kPrimBoolean: |
| 5719 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5720 | break; |
| 5721 | case Primitive::kPrimShort: |
| 5722 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5723 | break; |
| 5724 | case Primitive::kPrimChar: |
| 5725 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5726 | break; |
| 5727 | case Primitive::kPrimNot: |
| 5728 | case Primitive::kPrimInt: |
| 5729 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5730 | break; |
| 5731 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5732 | case Primitive::kPrimLong: |
| 5733 | case Primitive::kPrimFloat: |
| 5734 | case Primitive::kPrimDouble: |
| 5735 | default: |
| 5736 | LOG(FATAL) << "Unreachable type " << type; |
| 5737 | UNREACHABLE(); |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5742 | Location loc, |
| 5743 | Register base, |
| 5744 | Register reg_offset, |
| 5745 | Condition cond) { |
| 5746 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5747 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5748 | |
| 5749 | switch (type) { |
| 5750 | case Primitive::kPrimByte: |
| 5751 | case Primitive::kPrimBoolean: |
| 5752 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5753 | break; |
| 5754 | case Primitive::kPrimShort: |
| 5755 | case Primitive::kPrimChar: |
| 5756 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5757 | break; |
| 5758 | case Primitive::kPrimNot: |
| 5759 | case Primitive::kPrimInt: |
| 5760 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5761 | break; |
| 5762 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5763 | case Primitive::kPrimLong: |
| 5764 | case Primitive::kPrimFloat: |
| 5765 | case Primitive::kPrimDouble: |
| 5766 | default: |
| 5767 | LOG(FATAL) << "Unreachable type " << type; |
| 5768 | UNREACHABLE(); |
| 5769 | } |
| 5770 | } |
| 5771 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5772 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5773 | bool object_array_get_with_read_barrier = |
| 5774 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5775 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5776 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5777 | object_array_get_with_read_barrier ? |
| 5778 | LocationSummary::kCallOnSlowPath : |
| 5779 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5780 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5781 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5782 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5783 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5784 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5785 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5786 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5787 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5788 | // The output overlaps in the case of an object array get with |
| 5789 | // read barriers enabled: we do not want the move to overwrite the |
| 5790 | // array's location, as we need it to emit the read barrier. |
| 5791 | locations->SetOut( |
| 5792 | Location::RequiresRegister(), |
| 5793 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5794 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 5795 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5796 | // We need a temporary register for the read barrier marking slow |
| 5797 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 5798 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5799 | !Runtime::Current()->UseJitCompilation() && |
| 5800 | instruction->GetIndex()->IsConstant()) { |
| 5801 | // Array loads with constant index are treated as field loads. |
| 5802 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5803 | // constant index loads we need a temporary only if the offset is too big. |
| 5804 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5805 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 5806 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5807 | if (offset >= kReferenceLoadMinFarOffset) { |
| 5808 | locations->AddTemp(Location::RequiresRegister()); |
| 5809 | } |
| 5810 | // And we always need the reserved entrypoint register. |
| 5811 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5812 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 5813 | !Runtime::Current()->UseJitCompilation() && |
| 5814 | !instruction->GetIndex()->IsConstant()) { |
| 5815 | // We need a non-scratch temporary for the array data pointer. |
| 5816 | locations->AddTemp(Location::RequiresRegister()); |
| 5817 | // And we always need the reserved entrypoint register. |
| 5818 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5819 | } else { |
| 5820 | locations->AddTemp(Location::RequiresRegister()); |
| 5821 | } |
| 5822 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5823 | // Also need a temporary for String compression feature. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5824 | locations->AddTemp(Location::RequiresRegister()); |
| 5825 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5829 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5830 | Location obj_loc = locations->InAt(0); |
| 5831 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5832 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5833 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5834 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5835 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5836 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5837 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5838 | HInstruction* array_instr = instruction->GetArray(); |
| 5839 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5840 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5841 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5842 | case Primitive::kPrimBoolean: |
| 5843 | case Primitive::kPrimByte: |
| 5844 | case Primitive::kPrimShort: |
| 5845 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5846 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5847 | Register length; |
| 5848 | if (maybe_compressed_char_at) { |
| 5849 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5850 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5851 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5852 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5853 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5854 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5855 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5856 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5857 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5858 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5859 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5860 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5861 | "Expecting 0=compressed, 1=uncompressed"); |
| 5862 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5863 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5864 | out_loc.AsRegister<Register>(), |
| 5865 | obj, |
| 5866 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5867 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5868 | __ Bind(&uncompressed_load); |
| 5869 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5870 | out_loc.AsRegister<Register>(), |
| 5871 | obj, |
| 5872 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5873 | if (done.IsLinked()) { |
| 5874 | __ Bind(&done); |
| 5875 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5876 | } else { |
| 5877 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5878 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5879 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5880 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5881 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5882 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5883 | Register temp = IP; |
| 5884 | |
| 5885 | if (has_intermediate_address) { |
| 5886 | // We do not need to compute the intermediate address from the array: the |
| 5887 | // input instruction has done it already. See the comment in |
| 5888 | // `TryExtractArrayAccessAddress()`. |
| 5889 | if (kIsDebugBuild) { |
| 5890 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5891 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5892 | } |
| 5893 | temp = obj; |
| 5894 | } else { |
| 5895 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5896 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5897 | if (maybe_compressed_char_at) { |
| 5898 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5899 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5900 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5901 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5902 | "Expecting 0=compressed, 1=uncompressed"); |
| 5903 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5904 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5905 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5906 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5907 | __ Bind(&uncompressed_load); |
| 5908 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5909 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5910 | if (done.IsLinked()) { |
| 5911 | __ Bind(&done); |
| 5912 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5913 | } else { |
| 5914 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5915 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5916 | } |
| 5917 | break; |
| 5918 | } |
| 5919 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5920 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5921 | // The read barrier instrumentation of object ArrayGet |
| 5922 | // instructions does not support the HIntermediateAddress |
| 5923 | // instruction. |
| 5924 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5925 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5926 | static_assert( |
| 5927 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5928 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5929 | // /* HeapReference<Object> */ out = |
| 5930 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5931 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5932 | Location temp = locations->GetTemp(0); |
| 5933 | // Note that a potential implicit null check is handled in this |
| 5934 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 5935 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 5936 | if (index.IsConstant()) { |
| 5937 | // Array load with a constant index can be treated as a field load. |
| 5938 | data_offset += helpers::Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 5939 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5940 | out_loc, |
| 5941 | obj, |
| 5942 | data_offset, |
| 5943 | locations->GetTemp(0), |
| 5944 | /* needs_null_check */ false); |
| 5945 | } else { |
| 5946 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5947 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 5948 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5949 | } else { |
| 5950 | Register out = out_loc.AsRegister<Register>(); |
| 5951 | if (index.IsConstant()) { |
| 5952 | size_t offset = |
| 5953 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5954 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5955 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5956 | // If read barriers are enabled, emit read barriers other than |
| 5957 | // Baker's using a slow path (and also unpoison the loaded |
| 5958 | // reference, if heap poisoning is enabled). |
| 5959 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5960 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5961 | Register temp = IP; |
| 5962 | |
| 5963 | if (has_intermediate_address) { |
| 5964 | // We do not need to compute the intermediate address from the array: the |
| 5965 | // input instruction has done it already. See the comment in |
| 5966 | // `TryExtractArrayAccessAddress()`. |
| 5967 | if (kIsDebugBuild) { |
| 5968 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5969 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5970 | } |
| 5971 | temp = obj; |
| 5972 | } else { |
| 5973 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5974 | } |
| 5975 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5976 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5977 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5978 | // If read barriers are enabled, emit read barriers other than |
| 5979 | // Baker's using a slow path (and also unpoison the loaded |
| 5980 | // reference, if heap poisoning is enabled). |
| 5981 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5982 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5983 | } |
| 5984 | } |
| 5985 | break; |
| 5986 | } |
| 5987 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5988 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5989 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5990 | size_t offset = |
| 5991 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5992 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5993 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5994 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5995 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5996 | } |
| 5997 | break; |
| 5998 | } |
| 5999 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6000 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6001 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6002 | if (index.IsConstant()) { |
| 6003 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6004 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6005 | } else { |
| 6006 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6007 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6008 | } |
| 6009 | break; |
| 6010 | } |
| 6011 | |
| 6012 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6013 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6014 | if (index.IsConstant()) { |
| 6015 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6016 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6017 | } else { |
| 6018 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6019 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6020 | } |
| 6021 | break; |
| 6022 | } |
| 6023 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6024 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6025 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6026 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6027 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6028 | |
| 6029 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6030 | // Potential implicit null checks, in the case of reference |
| 6031 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6032 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6033 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6034 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6038 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6039 | |
| 6040 | bool needs_write_barrier = |
| 6041 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6042 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6043 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6044 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6045 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 6046 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6047 | LocationSummary::kCallOnSlowPath : |
| 6048 | LocationSummary::kNoCall); |
| 6049 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6051 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6052 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6053 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6054 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6055 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6056 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6057 | if (needs_write_barrier) { |
| 6058 | // Temporary registers for the write barrier. |
| 6059 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6060 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6061 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 6065 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6066 | Location array_loc = locations->InAt(0); |
| 6067 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6068 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6069 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6070 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6071 | bool needs_write_barrier = |
| 6072 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6073 | uint32_t data_offset = |
| 6074 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6075 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6076 | HInstruction* array_instr = instruction->GetArray(); |
| 6077 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6078 | |
| 6079 | switch (value_type) { |
| 6080 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6081 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6082 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6083 | case Primitive::kPrimChar: |
| 6084 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6085 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6086 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 6087 | uint32_t full_offset = |
| 6088 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6089 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6090 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6091 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6092 | Register temp = IP; |
| 6093 | |
| 6094 | if (has_intermediate_address) { |
| 6095 | // We do not need to compute the intermediate address from the array: the |
| 6096 | // input instruction has done it already. See the comment in |
| 6097 | // `TryExtractArrayAccessAddress()`. |
| 6098 | if (kIsDebugBuild) { |
| 6099 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6100 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 6101 | } |
| 6102 | temp = array; |
| 6103 | } else { |
| 6104 | __ add(temp, array, ShifterOperand(data_offset)); |
| 6105 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6106 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6107 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6108 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6109 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6110 | } |
| 6111 | break; |
| 6112 | } |
| 6113 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6114 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6115 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6116 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6117 | // See the comment in instruction_simplifier_shared.cc. |
| 6118 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6119 | |
| 6120 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6121 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6122 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6123 | size_t offset = |
| 6124 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6125 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6126 | } else { |
| 6127 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6128 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6129 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6130 | value_loc, |
| 6131 | IP, |
| 6132 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6133 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 6134 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6135 | DCHECK(!needs_write_barrier); |
| 6136 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6137 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6138 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6139 | |
| 6140 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6141 | Location temp1_loc = locations->GetTemp(0); |
| 6142 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6143 | Location temp2_loc = locations->GetTemp(1); |
| 6144 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6145 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6146 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6147 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6148 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6149 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6150 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6151 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6152 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6153 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6154 | codegen_->AddSlowPath(slow_path); |
| 6155 | if (instruction->GetValueCanBeNull()) { |
| 6156 | Label non_zero; |
| 6157 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6158 | if (index.IsConstant()) { |
| 6159 | size_t offset = |
| 6160 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6161 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6162 | } else { |
| 6163 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6164 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6165 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6166 | value_loc, |
| 6167 | IP, |
| 6168 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6169 | } |
| 6170 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6171 | __ b(final_label); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6172 | __ Bind(&non_zero); |
| 6173 | } |
| 6174 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6175 | // Note that when read barriers are enabled, the type checks |
| 6176 | // are performed without read barriers. This is fine, even in |
| 6177 | // the case where a class object is in the from-space after |
| 6178 | // the flip, as a comparison involving such a type would not |
| 6179 | // produce a false positive; it may of course produce a false |
| 6180 | // negative, in which case we would take the ArraySet slow |
| 6181 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6182 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6183 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6184 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6186 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6187 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6188 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6189 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6190 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6191 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6192 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6193 | // nor `temp2`, as we are comparing two poisoned references. |
| 6194 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6195 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6196 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6197 | Label do_put; |
| 6198 | __ b(&do_put, EQ); |
| 6199 | // If heap poisoning is enabled, the `temp1` reference has |
| 6200 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6201 | __ MaybeUnpoisonHeapReference(temp1); |
| 6202 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6203 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6204 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6205 | // If heap poisoning is enabled, no need to unpoison |
| 6206 | // `temp1`, as we are comparing against null below. |
| 6207 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6208 | __ Bind(&do_put); |
| 6209 | } else { |
| 6210 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6211 | } |
| 6212 | } |
| 6213 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6214 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6215 | if (kPoisonHeapReferences) { |
| 6216 | // Note that in the case where `value` is a null reference, |
| 6217 | // we do not enter this block, as a null reference does not |
| 6218 | // need poisoning. |
| 6219 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6220 | __ Mov(temp1, value); |
| 6221 | __ PoisonHeapReference(temp1); |
| 6222 | source = temp1; |
| 6223 | } |
| 6224 | |
| 6225 | if (index.IsConstant()) { |
| 6226 | size_t offset = |
| 6227 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6228 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6229 | } else { |
| 6230 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6231 | |
| 6232 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6233 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6234 | Location::RegisterLocation(source), |
| 6235 | IP, |
| 6236 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6237 | } |
| 6238 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6239 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6240 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6241 | } |
| 6242 | |
| 6243 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6244 | |
| 6245 | if (done.IsLinked()) { |
| 6246 | __ Bind(&done); |
| 6247 | } |
| 6248 | |
| 6249 | if (slow_path != nullptr) { |
| 6250 | __ Bind(slow_path->GetExitLabel()); |
| 6251 | } |
| 6252 | |
| 6253 | break; |
| 6254 | } |
| 6255 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6256 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6257 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6258 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6259 | size_t offset = |
| 6260 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6261 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6262 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6263 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6264 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6265 | } |
| 6266 | break; |
| 6267 | } |
| 6268 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6269 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6270 | Location value = locations->InAt(2); |
| 6271 | DCHECK(value.IsFpuRegister()); |
| 6272 | if (index.IsConstant()) { |
| 6273 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6274 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6275 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6276 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6277 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6278 | } |
| 6279 | break; |
| 6280 | } |
| 6281 | |
| 6282 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6283 | Location value = locations->InAt(2); |
| 6284 | DCHECK(value.IsFpuRegisterPair()); |
| 6285 | if (index.IsConstant()) { |
| 6286 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6287 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6288 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6289 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6290 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6291 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6292 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6293 | break; |
| 6294 | } |
| 6295 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6296 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6297 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6298 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6299 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6300 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6301 | // Objects are handled in the switch. |
| 6302 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6304 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6308 | LocationSummary* locations = |
| 6309 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6310 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6312 | } |
| 6313 | |
| 6314 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6315 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6316 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6317 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6318 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6319 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6320 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6321 | // Mask out compression flag from String's array length. |
| 6322 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6323 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6324 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6325 | } |
| 6326 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6327 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6328 | LocationSummary* locations = |
| 6329 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6330 | |
| 6331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6332 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6333 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6334 | } |
| 6335 | |
| 6336 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6337 | LocationSummary* locations = instruction->GetLocations(); |
| 6338 | Location out = locations->Out(); |
| 6339 | Location first = locations->InAt(0); |
| 6340 | Location second = locations->InAt(1); |
| 6341 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6342 | if (second.IsRegister()) { |
| 6343 | __ add(out.AsRegister<Register>(), |
| 6344 | first.AsRegister<Register>(), |
| 6345 | ShifterOperand(second.AsRegister<Register>())); |
| 6346 | } else { |
| 6347 | __ AddConstant(out.AsRegister<Register>(), |
| 6348 | first.AsRegister<Register>(), |
| 6349 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6350 | } |
| 6351 | } |
| 6352 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6353 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6354 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6355 | InvokeRuntimeCallingConvention calling_convention; |
| 6356 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6357 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6358 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6359 | |
| 6360 | HInstruction* index = instruction->InputAt(0); |
| 6361 | HInstruction* length = instruction->InputAt(1); |
| 6362 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6363 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6364 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6365 | // locations. |
| 6366 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6367 | locations->SetInAt(0, both_const |
| 6368 | ? Location::ConstantLocation(index->AsConstant()) |
| 6369 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6370 | locations->SetInAt(1, both_const |
| 6371 | ? Location::ConstantLocation(length->AsConstant()) |
| 6372 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6376 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6377 | Location index_loc = locations->InAt(0); |
| 6378 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6379 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6380 | if (length_loc.IsConstant()) { |
| 6381 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6382 | if (index_loc.IsConstant()) { |
| 6383 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6384 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6385 | if (index < 0 || index >= length) { |
| 6386 | SlowPathCodeARM* slow_path = |
| 6387 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6388 | codegen_->AddSlowPath(slow_path); |
| 6389 | __ b(slow_path->GetEntryLabel()); |
| 6390 | } else { |
| 6391 | // Some optimization after BCE may have generated this, and we should not |
| 6392 | // generate a bounds check if it is a valid range. |
| 6393 | } |
| 6394 | return; |
| 6395 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6396 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6397 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6398 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6399 | codegen_->AddSlowPath(slow_path); |
| 6400 | __ b(slow_path->GetEntryLabel(), HS); |
| 6401 | } else { |
| 6402 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6403 | if (index_loc.IsConstant()) { |
| 6404 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6405 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6406 | } else { |
| 6407 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6408 | } |
| 6409 | codegen_->AddSlowPath(slow_path); |
| 6410 | __ b(slow_path->GetEntryLabel(), LS); |
| 6411 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6412 | } |
| 6413 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6414 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6415 | Register card, |
| 6416 | Register object, |
| 6417 | Register value, |
| 6418 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6419 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6420 | if (can_be_null) { |
| 6421 | __ CompareAndBranchIfZero(value, &is_null); |
| 6422 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6423 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6424 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6425 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6426 | if (can_be_null) { |
| 6427 | __ Bind(&is_null); |
| 6428 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6429 | } |
| 6430 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6431 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6432 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6436 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6437 | } |
| 6438 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6439 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6440 | LocationSummary* locations = |
| 6441 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6442 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6446 | HBasicBlock* block = instruction->GetBlock(); |
| 6447 | if (block->GetLoopInformation() != nullptr) { |
| 6448 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6449 | // The back edge will generate the suspend check. |
| 6450 | return; |
| 6451 | } |
| 6452 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6453 | // The goto will generate the suspend check. |
| 6454 | return; |
| 6455 | } |
| 6456 | GenerateSuspendCheck(instruction, nullptr); |
| 6457 | } |
| 6458 | |
| 6459 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6460 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6461 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6462 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6463 | if (slow_path == nullptr) { |
| 6464 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6465 | instruction->SetSlowPath(slow_path); |
| 6466 | codegen_->AddSlowPath(slow_path); |
| 6467 | if (successor != nullptr) { |
| 6468 | DCHECK(successor->IsLoopHeader()); |
| 6469 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6470 | } |
| 6471 | } else { |
| 6472 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6473 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6474 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6475 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6476 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6477 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6478 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6479 | __ Bind(slow_path->GetReturnLabel()); |
| 6480 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6481 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6482 | __ b(slow_path->GetEntryLabel()); |
| 6483 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6484 | } |
| 6485 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6486 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6487 | return codegen_->GetAssembler(); |
| 6488 | } |
| 6489 | |
| 6490 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6491 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6492 | Location source = move->GetSource(); |
| 6493 | Location destination = move->GetDestination(); |
| 6494 | |
| 6495 | if (source.IsRegister()) { |
| 6496 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6497 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6498 | } else if (destination.IsFpuRegister()) { |
| 6499 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6500 | } else { |
| 6501 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6502 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6503 | SP, destination.GetStackIndex()); |
| 6504 | } |
| 6505 | } else if (source.IsStackSlot()) { |
| 6506 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6507 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6508 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6509 | } else if (destination.IsFpuRegister()) { |
| 6510 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6511 | } else { |
| 6512 | DCHECK(destination.IsStackSlot()); |
| 6513 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6514 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6515 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6516 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6517 | if (destination.IsRegister()) { |
| 6518 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6519 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6520 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6521 | } else { |
| 6522 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6523 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6524 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6525 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6526 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6527 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6528 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6529 | } else if (destination.IsRegisterPair()) { |
| 6530 | DCHECK(ExpectedPairLayout(destination)); |
| 6531 | __ LoadFromOffset( |
| 6532 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6533 | } else { |
| 6534 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6535 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6536 | SP, |
| 6537 | source.GetStackIndex()); |
| 6538 | } |
| 6539 | } else if (source.IsRegisterPair()) { |
| 6540 | if (destination.IsRegisterPair()) { |
| 6541 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6542 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6543 | } else if (destination.IsFpuRegisterPair()) { |
| 6544 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6545 | source.AsRegisterPairLow<Register>(), |
| 6546 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6547 | } else { |
| 6548 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6549 | DCHECK(ExpectedPairLayout(source)); |
| 6550 | __ StoreToOffset( |
| 6551 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6552 | } |
| 6553 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6554 | if (destination.IsRegisterPair()) { |
| 6555 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6556 | destination.AsRegisterPairHigh<Register>(), |
| 6557 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6558 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6559 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6560 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6561 | } else { |
| 6562 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6563 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6564 | SP, |
| 6565 | destination.GetStackIndex()); |
| 6566 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6567 | } else { |
| 6568 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6569 | HConstant* constant = source.GetConstant(); |
| 6570 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6571 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6572 | if (destination.IsRegister()) { |
| 6573 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6574 | } else { |
| 6575 | DCHECK(destination.IsStackSlot()); |
| 6576 | __ LoadImmediate(IP, value); |
| 6577 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6578 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6579 | } else if (constant->IsLongConstant()) { |
| 6580 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6581 | if (destination.IsRegisterPair()) { |
| 6582 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6583 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6584 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6585 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6586 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6587 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6588 | __ LoadImmediate(IP, High32Bits(value)); |
| 6589 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6590 | } |
| 6591 | } else if (constant->IsDoubleConstant()) { |
| 6592 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6593 | if (destination.IsFpuRegisterPair()) { |
| 6594 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6595 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6596 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6597 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6598 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6599 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6600 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6601 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6602 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6603 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6604 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6605 | float value = constant->AsFloatConstant()->GetValue(); |
| 6606 | if (destination.IsFpuRegister()) { |
| 6607 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6608 | } else { |
| 6609 | DCHECK(destination.IsStackSlot()); |
| 6610 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6611 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6612 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6613 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6618 | __ Mov(IP, reg); |
| 6619 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6620 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6621 | } |
| 6622 | |
| 6623 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6624 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6625 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6626 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6627 | SP, mem1 + stack_offset); |
| 6628 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6629 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6630 | SP, mem2 + stack_offset); |
| 6631 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6632 | } |
| 6633 | |
| 6634 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6635 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6636 | Location source = move->GetSource(); |
| 6637 | Location destination = move->GetDestination(); |
| 6638 | |
| 6639 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6640 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6641 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6642 | __ Mov(IP, source.AsRegister<Register>()); |
| 6643 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6644 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6645 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6646 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6647 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6648 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6649 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6650 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6651 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6652 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6653 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6654 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6655 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6656 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6657 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6658 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6659 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6660 | destination.AsRegisterPairHigh<Register>(), |
| 6661 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6662 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6663 | Register low_reg = source.IsRegisterPair() |
| 6664 | ? source.AsRegisterPairLow<Register>() |
| 6665 | : destination.AsRegisterPairLow<Register>(); |
| 6666 | int mem = source.IsRegisterPair() |
| 6667 | ? destination.GetStackIndex() |
| 6668 | : source.GetStackIndex(); |
| 6669 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6670 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6671 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6672 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6673 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6674 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6675 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6676 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6677 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6678 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6679 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6680 | DRegister reg = source.IsFpuRegisterPair() |
| 6681 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6682 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6683 | int mem = source.IsFpuRegisterPair() |
| 6684 | ? destination.GetStackIndex() |
| 6685 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6686 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6687 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6688 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6689 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6690 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6691 | : destination.AsFpuRegister<SRegister>(); |
| 6692 | int mem = source.IsFpuRegister() |
| 6693 | ? destination.GetStackIndex() |
| 6694 | : source.GetStackIndex(); |
| 6695 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6696 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6697 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6698 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6699 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6700 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6701 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6702 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6703 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6704 | } |
| 6705 | } |
| 6706 | |
| 6707 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6708 | __ Push(static_cast<Register>(reg)); |
| 6709 | } |
| 6710 | |
| 6711 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6712 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6713 | } |
| 6714 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6715 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6716 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6717 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6718 | case HLoadClass::LoadKind::kInvalid: |
| 6719 | LOG(FATAL) << "UNREACHABLE"; |
| 6720 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6721 | case HLoadClass::LoadKind::kReferrersClass: |
| 6722 | break; |
| 6723 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6724 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6725 | break; |
| 6726 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6727 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6728 | break; |
| 6729 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6730 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6731 | case HLoadClass::LoadKind::kBssEntry: |
| 6732 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6733 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6734 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6735 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6736 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6737 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6738 | break; |
| 6739 | } |
| 6740 | return desired_class_load_kind; |
| 6741 | } |
| 6742 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6743 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6744 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6745 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6746 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6747 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6748 | cls, |
| 6749 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6750 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6751 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6752 | return; |
| 6753 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6754 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6755 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6756 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6757 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6758 | ? LocationSummary::kCallOnSlowPath |
| 6759 | : LocationSummary::kNoCall; |
| 6760 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6761 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6762 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6763 | } |
| 6764 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6765 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6766 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6767 | } |
| 6768 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6769 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6770 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6771 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6772 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6773 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6774 | locations->AddTemp(Location::RequiresRegister()); |
| 6775 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6776 | InvokeRuntimeCallingConvention calling_convention; |
| 6777 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6778 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6779 | // that the the kPrimNot result register is the same as the first argument register. |
| 6780 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6781 | } else { |
| 6782 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6783 | } |
| 6784 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 6785 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6786 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 6787 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 6788 | !Runtime::Current()->UseJitCompilation())) { |
| 6789 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6790 | } |
| 6791 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6792 | } |
| 6793 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6794 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6795 | // move. |
| 6796 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6797 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6798 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6799 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6800 | return; |
| 6801 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6802 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6803 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6804 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6805 | Location out_loc = locations->Out(); |
| 6806 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6807 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6808 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6809 | ? kWithoutReadBarrier |
| 6810 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6811 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6812 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6813 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6814 | DCHECK(!cls->CanCallRuntime()); |
| 6815 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6816 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6817 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6818 | GenerateGcRootFieldLoad(cls, |
| 6819 | out_loc, |
| 6820 | current_method, |
| 6821 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6822 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6823 | break; |
| 6824 | } |
| 6825 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6826 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6827 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6828 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6829 | cls->GetTypeIndex())); |
| 6830 | break; |
| 6831 | } |
| 6832 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6833 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6834 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6835 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6836 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6837 | __ BindTrackedLabel(&labels->movw_label); |
| 6838 | __ movw(out, /* placeholder */ 0u); |
| 6839 | __ BindTrackedLabel(&labels->movt_label); |
| 6840 | __ movt(out, /* placeholder */ 0u); |
| 6841 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6842 | __ add(out, out, ShifterOperand(PC)); |
| 6843 | break; |
| 6844 | } |
| 6845 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6846 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6847 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6848 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6849 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6850 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6851 | break; |
| 6852 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6853 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6854 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6855 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6856 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6857 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6858 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6859 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6860 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6861 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6862 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6863 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6864 | __ add(temp, temp, ShifterOperand(PC)); |
| 6865 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6866 | generate_null_check = true; |
| 6867 | break; |
| 6868 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6869 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6870 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6871 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6872 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6873 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6874 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6875 | break; |
| 6876 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6877 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6878 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6879 | LOG(FATAL) << "UNREACHABLE"; |
| 6880 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6881 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6882 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6883 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6884 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6885 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6886 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6887 | codegen_->AddSlowPath(slow_path); |
| 6888 | if (generate_null_check) { |
| 6889 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6890 | } |
| 6891 | if (cls->MustGenerateClinitCheck()) { |
| 6892 | GenerateClassInitializationCheck(slow_path, out); |
| 6893 | } else { |
| 6894 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6895 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6900 | LocationSummary* locations = |
| 6901 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6902 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6903 | if (check->HasUses()) { |
| 6904 | locations->SetOut(Location::SameAsFirstInput()); |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6909 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6910 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6911 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6912 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6913 | GenerateClassInitializationCheck(slow_path, |
| 6914 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6915 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6916 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6917 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6918 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6919 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6920 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6921 | __ b(slow_path->GetEntryLabel(), LT); |
| 6922 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6923 | // properly. Therefore, we do a memory fence. |
| 6924 | __ dmb(ISH); |
| 6925 | __ Bind(slow_path->GetExitLabel()); |
| 6926 | } |
| 6927 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6928 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6929 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6930 | switch (desired_string_load_kind) { |
| 6931 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6932 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6933 | break; |
| 6934 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6935 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6936 | break; |
| 6937 | case HLoadString::LoadKind::kBootImageAddress: |
| 6938 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6939 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6940 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6941 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6942 | case HLoadString::LoadKind::kJitTableAddress: |
| 6943 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6944 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6945 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6946 | break; |
| 6947 | } |
| 6948 | return desired_string_load_kind; |
| 6949 | } |
| 6950 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6951 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6952 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6953 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6954 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6955 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6956 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6957 | } else { |
| 6958 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6959 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6960 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6961 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6962 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6963 | // to the custom calling convention) or by marking, so we request a different temp. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6964 | locations->AddTemp(Location::RequiresRegister()); |
| 6965 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6966 | InvokeRuntimeCallingConvention calling_convention; |
| 6967 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6968 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6969 | // that the the kPrimNot result register is the same as the first argument register. |
| 6970 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 6971 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6972 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6973 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6974 | } else { |
| 6975 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6976 | } |
| 6977 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6978 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6981 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6982 | // move. |
| 6983 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6984 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6985 | Location out_loc = locations->Out(); |
| 6986 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6987 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6988 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6989 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6990 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6991 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6992 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6993 | load->GetStringIndex())); |
| 6994 | return; // No dex cache slow path. |
| 6995 | } |
| 6996 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6997 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6998 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6999 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7000 | __ BindTrackedLabel(&labels->movw_label); |
| 7001 | __ movw(out, /* placeholder */ 0u); |
| 7002 | __ BindTrackedLabel(&labels->movt_label); |
| 7003 | __ movt(out, /* placeholder */ 0u); |
| 7004 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7005 | __ add(out, out, ShifterOperand(PC)); |
| 7006 | return; // No dex cache slow path. |
| 7007 | } |
| 7008 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7009 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7010 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7011 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7012 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7013 | return; // No dex cache slow path. |
| 7014 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7015 | case HLoadString::LoadKind::kBssEntry: { |
| 7016 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7017 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7018 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7019 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7020 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7021 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7022 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7023 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7024 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7025 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7026 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7027 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7028 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7029 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 7030 | codegen_->AddSlowPath(slow_path); |
| 7031 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7032 | __ Bind(slow_path->GetExitLabel()); |
| 7033 | return; |
| 7034 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7035 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7036 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7037 | load->GetStringIndex(), |
| 7038 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7039 | // /* GcRoot<mirror::String> */ out = *out |
| 7040 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7041 | return; |
| 7042 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7043 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7044 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7045 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7046 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7047 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 7048 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 7049 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7050 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7051 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7052 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7053 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7054 | } |
| 7055 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7056 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7057 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7058 | } |
| 7059 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7060 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 7061 | LocationSummary* locations = |
| 7062 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7063 | locations->SetOut(Location::RequiresRegister()); |
| 7064 | } |
| 7065 | |
| 7066 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7067 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7068 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7069 | } |
| 7070 | |
| 7071 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 7072 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7073 | } |
| 7074 | |
| 7075 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7076 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7077 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 7081 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7082 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7083 | InvokeRuntimeCallingConvention calling_convention; |
| 7084 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7085 | } |
| 7086 | |
| 7087 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7088 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7089 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7090 | } |
| 7091 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7092 | // Temp is used for read barrier. |
| 7093 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7094 | if (kEmitCompilerReadBarrier && |
| 7095 | (kUseBakerReadBarrier || |
| 7096 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7097 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7098 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7099 | return 1; |
| 7100 | } |
| 7101 | return 0; |
| 7102 | } |
| 7103 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7104 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7105 | // interface pointer, one for loading the current interface. |
| 7106 | // The other checks have one temp for loading the object's class. |
| 7107 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7108 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7109 | return 3; |
| 7110 | } |
| 7111 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7112 | } |
| 7113 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7114 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7115 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7116 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7117 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7118 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7119 | case TypeCheckKind::kExactCheck: |
| 7120 | case TypeCheckKind::kAbstractClassCheck: |
| 7121 | case TypeCheckKind::kClassHierarchyCheck: |
| 7122 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7123 | call_kind = |
| 7124 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7125 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7126 | break; |
| 7127 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7128 | case TypeCheckKind::kUnresolvedCheck: |
| 7129 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7130 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7131 | break; |
| 7132 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7133 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7134 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7135 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7136 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7137 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7139 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7140 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7141 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7142 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7143 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 7144 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7145 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7146 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7147 | } |
| 7148 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7149 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7150 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7151 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7152 | Location obj_loc = locations->InAt(0); |
| 7153 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7154 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7155 | Location out_loc = locations->Out(); |
| 7156 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7157 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7158 | DCHECK_LE(num_temps, 1u); |
| 7159 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7160 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7161 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7162 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7163 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7164 | Label done; |
| 7165 | Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7166 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7167 | |
| 7168 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7169 | // avoid null check if we know obj is not null. |
| 7170 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7171 | DCHECK_NE(out, obj); |
| 7172 | __ LoadImmediate(out, 0); |
| 7173 | __ CompareAndBranchIfZero(obj, final_label); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7174 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7175 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7176 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7177 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7178 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7179 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7180 | out_loc, |
| 7181 | obj_loc, |
| 7182 | class_offset, |
| 7183 | maybe_temp_loc, |
| 7184 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7185 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7186 | __ cmp(out, ShifterOperand(cls)); |
| 7187 | // We speculatively set the result to false without changing the condition |
| 7188 | // flags, which allows us to avoid some branching later. |
| 7189 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7190 | |
| 7191 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7192 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7193 | // encoding can be used. |
| 7194 | if (ArmAssembler::IsLowRegister(out)) { |
| 7195 | __ it(EQ); |
| 7196 | __ mov(out, ShifterOperand(1), EQ); |
| 7197 | } else { |
| 7198 | __ b(final_label, NE); |
| 7199 | __ LoadImmediate(out, 1); |
| 7200 | } |
| 7201 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7202 | break; |
| 7203 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7204 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7205 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7206 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7207 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7208 | out_loc, |
| 7209 | obj_loc, |
| 7210 | class_offset, |
| 7211 | maybe_temp_loc, |
| 7212 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7213 | // If the class is abstract, we eagerly fetch the super class of the |
| 7214 | // object to avoid doing a comparison we know will fail. |
| 7215 | Label loop; |
| 7216 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7217 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7218 | GenerateReferenceLoadOneRegister(instruction, |
| 7219 | out_loc, |
| 7220 | super_offset, |
| 7221 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7222 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7223 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7224 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7225 | __ cmp(out, ShifterOperand(cls)); |
| 7226 | __ b(&loop, NE); |
| 7227 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7228 | break; |
| 7229 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7230 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7231 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7232 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7233 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7234 | out_loc, |
| 7235 | obj_loc, |
| 7236 | class_offset, |
| 7237 | maybe_temp_loc, |
| 7238 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7239 | // Walk over the class hierarchy to find a match. |
| 7240 | Label loop, success; |
| 7241 | __ Bind(&loop); |
| 7242 | __ cmp(out, ShifterOperand(cls)); |
| 7243 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7244 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7245 | GenerateReferenceLoadOneRegister(instruction, |
| 7246 | out_loc, |
| 7247 | super_offset, |
| 7248 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7249 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7250 | // This is essentially a null check, but it sets the condition flags to the |
| 7251 | // proper value for the code that follows the loop, i.e. not `EQ`. |
| 7252 | __ cmp(out, ShifterOperand(1)); |
| 7253 | __ b(&loop, HS); |
| 7254 | |
| 7255 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7256 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7257 | // encoding can be used. |
| 7258 | if (ArmAssembler::IsLowRegister(out)) { |
| 7259 | // If `out` is null, we use it for the result, and the condition flags |
| 7260 | // have already been set to `NE`, so the IT block that comes afterwards |
| 7261 | // (and which handles the successful case) turns into a NOP (instead of |
| 7262 | // overwriting `out`). |
| 7263 | __ Bind(&success); |
| 7264 | // There is only one branch to the `success` label (which is bound to this |
| 7265 | // IT block), and it has the same condition, `EQ`, so in that case the MOV |
| 7266 | // is executed. |
| 7267 | __ it(EQ); |
| 7268 | __ mov(out, ShifterOperand(1), EQ); |
| 7269 | } else { |
| 7270 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7271 | __ b(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7272 | __ Bind(&success); |
| 7273 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7274 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7275 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7276 | break; |
| 7277 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7278 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7279 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7280 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7281 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7282 | out_loc, |
| 7283 | obj_loc, |
| 7284 | class_offset, |
| 7285 | maybe_temp_loc, |
| 7286 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7287 | // Do an exact check. |
| 7288 | Label exact_check; |
| 7289 | __ cmp(out, ShifterOperand(cls)); |
| 7290 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7291 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7292 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7293 | GenerateReferenceLoadOneRegister(instruction, |
| 7294 | out_loc, |
| 7295 | component_offset, |
| 7296 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7297 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7298 | // If `out` is null, we use it for the result, and jump to the final label. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7299 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7300 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7301 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7302 | __ cmp(out, ShifterOperand(0)); |
| 7303 | // We speculatively set the result to false without changing the condition |
| 7304 | // flags, which allows us to avoid some branching later. |
| 7305 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7306 | |
| 7307 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7308 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7309 | // encoding can be used. |
| 7310 | if (ArmAssembler::IsLowRegister(out)) { |
| 7311 | __ Bind(&exact_check); |
| 7312 | __ it(EQ); |
| 7313 | __ mov(out, ShifterOperand(1), EQ); |
| 7314 | } else { |
| 7315 | __ b(final_label, NE); |
| 7316 | __ Bind(&exact_check); |
| 7317 | __ LoadImmediate(out, 1); |
| 7318 | } |
| 7319 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7320 | break; |
| 7321 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7323 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7324 | // No read barrier since the slow path will retry upon failure. |
| 7325 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7326 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7327 | out_loc, |
| 7328 | obj_loc, |
| 7329 | class_offset, |
| 7330 | maybe_temp_loc, |
| 7331 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7332 | __ cmp(out, ShifterOperand(cls)); |
| 7333 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7334 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7335 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7336 | codegen_->AddSlowPath(slow_path); |
| 7337 | __ b(slow_path->GetEntryLabel(), NE); |
| 7338 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7339 | break; |
| 7340 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7341 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7342 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7343 | case TypeCheckKind::kInterfaceCheck: { |
| 7344 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7345 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7346 | // cases. |
| 7347 | // |
| 7348 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7349 | // entry point without resorting to a type checking slow path |
| 7350 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7351 | // require to assign fixed registers for the inputs of this |
| 7352 | // HInstanceOf instruction (following the runtime calling |
| 7353 | // convention), which might be cluttered by the potential first |
| 7354 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7355 | // |
| 7356 | // TODO: Introduce a new runtime entry point taking the object |
| 7357 | // to test (instead of its class) as argument, and let it deal |
| 7358 | // with the read barrier issues. This will let us refactor this |
| 7359 | // case of the `switch` code as it was previously (with a direct |
| 7360 | // call to the runtime not using a type checking slow path). |
| 7361 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7362 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7363 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7364 | /* is_fatal */ false); |
| 7365 | codegen_->AddSlowPath(slow_path); |
| 7366 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7367 | break; |
| 7368 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7369 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7370 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7371 | if (done.IsLinked()) { |
| 7372 | __ Bind(&done); |
| 7373 | } |
| 7374 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7375 | if (slow_path != nullptr) { |
| 7376 | __ Bind(slow_path->GetExitLabel()); |
| 7377 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7378 | } |
| 7379 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7380 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7381 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7382 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7383 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7384 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7385 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7386 | case TypeCheckKind::kExactCheck: |
| 7387 | case TypeCheckKind::kAbstractClassCheck: |
| 7388 | case TypeCheckKind::kClassHierarchyCheck: |
| 7389 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7390 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7391 | LocationSummary::kCallOnSlowPath : |
| 7392 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7393 | break; |
| 7394 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7395 | case TypeCheckKind::kUnresolvedCheck: |
| 7396 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7397 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7398 | break; |
| 7399 | } |
| 7400 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7401 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7403 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7404 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7405 | } |
| 7406 | |
| 7407 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7408 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7409 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7410 | Location obj_loc = locations->InAt(0); |
| 7411 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7412 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7413 | Location temp_loc = locations->GetTemp(0); |
| 7414 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7415 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7416 | DCHECK_LE(num_temps, 3u); |
| 7417 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7418 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7419 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7420 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7421 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7422 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7423 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7424 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7425 | const uint32_t object_array_data_offset = |
| 7426 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7427 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7428 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7429 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7430 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7431 | bool is_type_check_slow_path_fatal = false; |
| 7432 | if (!kEmitCompilerReadBarrier) { |
| 7433 | is_type_check_slow_path_fatal = |
| 7434 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7435 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7436 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7437 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7438 | !instruction->CanThrowIntoCatchBlock(); |
| 7439 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7440 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7441 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7442 | is_type_check_slow_path_fatal); |
| 7443 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7444 | |
| 7445 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7446 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7447 | // Avoid null check if we know obj is not null. |
| 7448 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7449 | __ CompareAndBranchIfZero(obj, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7450 | } |
| 7451 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7452 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7453 | case TypeCheckKind::kExactCheck: |
| 7454 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7455 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7456 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7457 | temp_loc, |
| 7458 | obj_loc, |
| 7459 | class_offset, |
| 7460 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7461 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7462 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7463 | __ cmp(temp, ShifterOperand(cls)); |
| 7464 | // Jump to slow path for throwing the exception or doing a |
| 7465 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7466 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7467 | break; |
| 7468 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7469 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7470 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7471 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7472 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7473 | temp_loc, |
| 7474 | obj_loc, |
| 7475 | class_offset, |
| 7476 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7477 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7478 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7479 | // If the class is abstract, we eagerly fetch the super class of the |
| 7480 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7481 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7482 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7483 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7484 | GenerateReferenceLoadOneRegister(instruction, |
| 7485 | temp_loc, |
| 7486 | super_offset, |
| 7487 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7488 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7489 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7490 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7491 | // exception. |
| 7492 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7493 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7494 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7495 | __ cmp(temp, ShifterOperand(cls)); |
| 7496 | __ b(&loop, NE); |
| 7497 | break; |
| 7498 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7499 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7500 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7501 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7502 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7503 | temp_loc, |
| 7504 | obj_loc, |
| 7505 | class_offset, |
| 7506 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7507 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7508 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7509 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7510 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7511 | __ Bind(&loop); |
| 7512 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7513 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7514 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7515 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7516 | GenerateReferenceLoadOneRegister(instruction, |
| 7517 | temp_loc, |
| 7518 | super_offset, |
| 7519 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7520 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7521 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7522 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7523 | // exception. |
| 7524 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7525 | // Otherwise, jump to the beginning of the loop. |
| 7526 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7527 | break; |
| 7528 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7529 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7530 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7531 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7532 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7533 | temp_loc, |
| 7534 | obj_loc, |
| 7535 | class_offset, |
| 7536 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7537 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7538 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7539 | // Do an exact check. |
| 7540 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7541 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7542 | |
| 7543 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7544 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7545 | GenerateReferenceLoadOneRegister(instruction, |
| 7546 | temp_loc, |
| 7547 | component_offset, |
| 7548 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7549 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7550 | // If the component type is null, jump to the slow path to throw the exception. |
| 7551 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7552 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7553 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7554 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7555 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7556 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7557 | break; |
| 7558 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7559 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7560 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7561 | // We always go into the type check slow path for the unresolved check case. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7562 | // We cannot directly call the CheckCast runtime entry point |
| 7563 | // without resorting to a type checking slow path here (i.e. by |
| 7564 | // calling InvokeRuntime directly), as it would require to |
| 7565 | // assign fixed registers for the inputs of this HInstanceOf |
| 7566 | // instruction (following the runtime calling convention), which |
| 7567 | // might be cluttered by the potential first read barrier |
| 7568 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7569 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7570 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7571 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7572 | |
| 7573 | case TypeCheckKind::kInterfaceCheck: { |
| 7574 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7575 | // positives by doing this. |
| 7576 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7577 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7578 | temp_loc, |
| 7579 | obj_loc, |
| 7580 | class_offset, |
| 7581 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7582 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7583 | |
| 7584 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7585 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7586 | temp_loc, |
| 7587 | temp_loc, |
| 7588 | iftable_offset, |
| 7589 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7590 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7591 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7592 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7593 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7594 | Label start_loop; |
| 7595 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7596 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7597 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7598 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7599 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7600 | // Go to next interface. |
| 7601 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7602 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7603 | maybe_temp2_loc.AsRegister<Register>(), |
| 7604 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7605 | // Compare the classes and continue the loop if they do not match. |
| 7606 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7607 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7608 | break; |
| 7609 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7610 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7611 | |
| 7612 | if (done.IsLinked()) { |
| 7613 | __ Bind(&done); |
| 7614 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7615 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7616 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7617 | } |
| 7618 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7619 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7620 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7621 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7622 | InvokeRuntimeCallingConvention calling_convention; |
| 7623 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7624 | } |
| 7625 | |
| 7626 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7627 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7628 | instruction, |
| 7629 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7630 | if (instruction->IsEnter()) { |
| 7631 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7632 | } else { |
| 7633 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7634 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7635 | } |
| 7636 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7637 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 7638 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 7639 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7640 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7641 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7642 | LocationSummary* locations = |
| 7643 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7644 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7645 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7646 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7647 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7648 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7649 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7653 | HandleBitwiseOperation(instruction); |
| 7654 | } |
| 7655 | |
| 7656 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7657 | HandleBitwiseOperation(instruction); |
| 7658 | } |
| 7659 | |
| 7660 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7661 | HandleBitwiseOperation(instruction); |
| 7662 | } |
| 7663 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7664 | |
| 7665 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7666 | LocationSummary* locations = |
| 7667 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7668 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7669 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7670 | |
| 7671 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7672 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7673 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7674 | } |
| 7675 | |
| 7676 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7677 | LocationSummary* locations = instruction->GetLocations(); |
| 7678 | Location first = locations->InAt(0); |
| 7679 | Location second = locations->InAt(1); |
| 7680 | Location out = locations->Out(); |
| 7681 | |
| 7682 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7683 | Register first_reg = first.AsRegister<Register>(); |
| 7684 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7685 | Register out_reg = out.AsRegister<Register>(); |
| 7686 | |
| 7687 | switch (instruction->GetOpKind()) { |
| 7688 | case HInstruction::kAnd: |
| 7689 | __ bic(out_reg, first_reg, second_reg); |
| 7690 | break; |
| 7691 | case HInstruction::kOr: |
| 7692 | __ orn(out_reg, first_reg, second_reg); |
| 7693 | break; |
| 7694 | // There is no EON on arm. |
| 7695 | case HInstruction::kXor: |
| 7696 | default: |
| 7697 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7698 | UNREACHABLE(); |
| 7699 | } |
| 7700 | return; |
| 7701 | |
| 7702 | } else { |
| 7703 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7704 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7705 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7706 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7707 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7708 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7709 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7710 | |
| 7711 | switch (instruction->GetOpKind()) { |
| 7712 | case HInstruction::kAnd: |
| 7713 | __ bic(out_low, first_low, second_low); |
| 7714 | __ bic(out_high, first_high, second_high); |
| 7715 | break; |
| 7716 | case HInstruction::kOr: |
| 7717 | __ orn(out_low, first_low, second_low); |
| 7718 | __ orn(out_high, first_high, second_high); |
| 7719 | break; |
| 7720 | // There is no EON on arm. |
| 7721 | case HInstruction::kXor: |
| 7722 | default: |
| 7723 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7724 | UNREACHABLE(); |
| 7725 | } |
| 7726 | } |
| 7727 | } |
| 7728 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7729 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7730 | HDataProcWithShifterOp* instruction) { |
| 7731 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7732 | instruction->GetType() == Primitive::kPrimLong); |
| 7733 | LocationSummary* locations = |
| 7734 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7735 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7736 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7737 | |
| 7738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7739 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7740 | locations->SetOut(Location::RequiresRegister(), |
| 7741 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7742 | } |
| 7743 | |
| 7744 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7745 | HDataProcWithShifterOp* instruction) { |
| 7746 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7747 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7748 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7749 | const Location left = locations->InAt(0); |
| 7750 | const Location right = locations->InAt(1); |
| 7751 | const Location out = locations->Out(); |
| 7752 | |
| 7753 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7754 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7755 | |
| 7756 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7757 | ? right.AsRegisterPairLow<Register>() |
| 7758 | : right.AsRegister<Register>(); |
| 7759 | |
| 7760 | GenerateDataProcInstruction(kind, |
| 7761 | out.AsRegister<Register>(), |
| 7762 | left.AsRegister<Register>(), |
| 7763 | ShifterOperand(second, |
| 7764 | ShiftFromOpKind(op_kind), |
| 7765 | instruction->GetShiftAmount()), |
| 7766 | codegen_); |
| 7767 | } else { |
| 7768 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7769 | |
| 7770 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7771 | const Register second = right.AsRegister<Register>(); |
| 7772 | |
| 7773 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7774 | GenerateDataProc(kind, |
| 7775 | out, |
| 7776 | left, |
| 7777 | ShifterOperand(second), |
| 7778 | ShifterOperand(second, ASR, 31), |
| 7779 | codegen_); |
| 7780 | } else { |
| 7781 | GenerateLongDataProc(instruction, codegen_); |
| 7782 | } |
| 7783 | } |
| 7784 | } |
| 7785 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7786 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7787 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7788 | if (value == 0xffffffffu) { |
| 7789 | if (out != first) { |
| 7790 | __ mov(out, ShifterOperand(first)); |
| 7791 | } |
| 7792 | return; |
| 7793 | } |
| 7794 | if (value == 0u) { |
| 7795 | __ mov(out, ShifterOperand(0)); |
| 7796 | return; |
| 7797 | } |
| 7798 | ShifterOperand so; |
| 7799 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7800 | __ and_(out, first, so); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7801 | } else if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7802 | __ bic(out, first, ShifterOperand(~value)); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7803 | } else { |
| 7804 | DCHECK(IsPowerOfTwo(value + 1)); |
| 7805 | __ ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7810 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7811 | if (value == 0u) { |
| 7812 | if (out != first) { |
| 7813 | __ mov(out, ShifterOperand(first)); |
| 7814 | } |
| 7815 | return; |
| 7816 | } |
| 7817 | if (value == 0xffffffffu) { |
| 7818 | __ mvn(out, ShifterOperand(0)); |
| 7819 | return; |
| 7820 | } |
| 7821 | ShifterOperand so; |
| 7822 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7823 | __ orr(out, first, so); |
| 7824 | } else { |
| 7825 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7826 | __ orn(out, first, ShifterOperand(~value)); |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7831 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7832 | if (value == 0u) { |
| 7833 | if (out != first) { |
| 7834 | __ mov(out, ShifterOperand(first)); |
| 7835 | } |
| 7836 | return; |
| 7837 | } |
| 7838 | __ eor(out, first, ShifterOperand(value)); |
| 7839 | } |
| 7840 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7841 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7842 | Location first, |
| 7843 | uint64_t value) { |
| 7844 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7845 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7846 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7847 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7848 | uint32_t value_low = Low32Bits(value); |
| 7849 | uint32_t value_high = High32Bits(value); |
| 7850 | if (value_low == 0u) { |
| 7851 | if (out_low != first_low) { |
| 7852 | __ mov(out_low, ShifterOperand(first_low)); |
| 7853 | } |
| 7854 | __ AddConstant(out_high, first_high, value_high); |
| 7855 | return; |
| 7856 | } |
| 7857 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7858 | ShifterOperand so; |
| 7859 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7860 | __ adc(out_high, first_high, so); |
| 7861 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7862 | __ sbc(out_high, first_high, so); |
| 7863 | } else { |
| 7864 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7865 | UNREACHABLE(); |
| 7866 | } |
| 7867 | } |
| 7868 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7869 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7870 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7871 | Location first = locations->InAt(0); |
| 7872 | Location second = locations->InAt(1); |
| 7873 | Location out = locations->Out(); |
| 7874 | |
| 7875 | if (second.IsConstant()) { |
| 7876 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7877 | uint32_t value_low = Low32Bits(value); |
| 7878 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7879 | Register first_reg = first.AsRegister<Register>(); |
| 7880 | Register out_reg = out.AsRegister<Register>(); |
| 7881 | if (instruction->IsAnd()) { |
| 7882 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7883 | } else if (instruction->IsOr()) { |
| 7884 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7885 | } else { |
| 7886 | DCHECK(instruction->IsXor()); |
| 7887 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7888 | } |
| 7889 | } else { |
| 7890 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7891 | uint32_t value_high = High32Bits(value); |
| 7892 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7893 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7894 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7895 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7896 | if (instruction->IsAnd()) { |
| 7897 | GenerateAndConst(out_low, first_low, value_low); |
| 7898 | GenerateAndConst(out_high, first_high, value_high); |
| 7899 | } else if (instruction->IsOr()) { |
| 7900 | GenerateOrrConst(out_low, first_low, value_low); |
| 7901 | GenerateOrrConst(out_high, first_high, value_high); |
| 7902 | } else { |
| 7903 | DCHECK(instruction->IsXor()); |
| 7904 | GenerateEorConst(out_low, first_low, value_low); |
| 7905 | GenerateEorConst(out_high, first_high, value_high); |
| 7906 | } |
| 7907 | } |
| 7908 | return; |
| 7909 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7910 | |
| 7911 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7912 | Register first_reg = first.AsRegister<Register>(); |
| 7913 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7914 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7915 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7916 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7917 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7918 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7919 | } else { |
| 7920 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7921 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7922 | } |
| 7923 | } else { |
| 7924 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7925 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7926 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7927 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7928 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7929 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7930 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7931 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7932 | __ and_(out_low, first_low, second_low); |
| 7933 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7934 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7935 | __ orr(out_low, first_low, second_low); |
| 7936 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7937 | } else { |
| 7938 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7939 | __ eor(out_low, first_low, second_low); |
| 7940 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7941 | } |
| 7942 | } |
| 7943 | } |
| 7944 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7945 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7946 | HInstruction* instruction, |
| 7947 | Location out, |
| 7948 | uint32_t offset, |
| 7949 | Location maybe_temp, |
| 7950 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7951 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7952 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7953 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7954 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7955 | if (kUseBakerReadBarrier) { |
| 7956 | // Load with fast path based Baker's read barrier. |
| 7957 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7958 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7959 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7960 | } else { |
| 7961 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7962 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7963 | // in the following move operation, as we will need it for the |
| 7964 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7965 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7966 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7967 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7968 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7969 | } |
| 7970 | } else { |
| 7971 | // Plain load with no read barrier. |
| 7972 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7973 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7974 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7975 | } |
| 7976 | } |
| 7977 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7978 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7979 | HInstruction* instruction, |
| 7980 | Location out, |
| 7981 | Location obj, |
| 7982 | uint32_t offset, |
| 7983 | Location maybe_temp, |
| 7984 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7985 | Register out_reg = out.AsRegister<Register>(); |
| 7986 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7987 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7988 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7989 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7990 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7991 | // Load with fast path based Baker's read barrier. |
| 7992 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7993 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7994 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7995 | } else { |
| 7996 | // Load with slow path based read barrier. |
| 7997 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7998 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7999 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8000 | } |
| 8001 | } else { |
| 8002 | // Plain load with no read barrier. |
| 8003 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8004 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8005 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8006 | } |
| 8007 | } |
| 8008 | |
| 8009 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 8010 | Location root, |
| 8011 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8012 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8013 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8014 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8015 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8016 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8017 | if (kUseBakerReadBarrier) { |
| 8018 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8019 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8020 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8021 | !Runtime::Current()->UseJitCompilation()) { |
| 8022 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8023 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8024 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8025 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8026 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8027 | // |
| 8028 | // We use link-time generated thunks for the slow path. That thunk |
| 8029 | // checks the reference and jumps to the entrypoint if needed. |
| 8030 | // |
| 8031 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8032 | // lr = &return_address; |
| 8033 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8034 | // if (temp != nullptr) { |
| 8035 | // goto gc_root_thunk<root_reg>(lr) |
| 8036 | // } |
| 8037 | // return_address: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8038 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8039 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8040 | uint32_t custom_data = |
| 8041 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg); |
| 8042 | Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8043 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8044 | // entrypoint_reg = |
| 8045 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8046 | DCHECK_EQ(IP, 12); |
| 8047 | const int32_t entry_point_offset = |
| 8048 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8049 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8050 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8051 | Label return_address; |
| 8052 | __ AdrCode(LR, &return_address); |
| 8053 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8054 | static_assert( |
| 8055 | BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 8056 | "GC root LDR must be 2 32-bit instructions (8B) before the return address label."); |
| 8057 | // Currently the offset is always within range. If that changes, |
| 8058 | // we shall have to split the load the same way as for fields. |
| 8059 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8060 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8061 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8062 | EmitPlaceholderBne(codegen_, bne_label); |
| 8063 | __ Bind(&return_address); |
| 8064 | } else { |
| 8065 | // Note that we do not actually check the value of |
| 8066 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8067 | // root or not. Instead, we load into `temp` the read barrier |
| 8068 | // mark entry point corresponding to register `root`. If `temp` |
| 8069 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8070 | // versa. |
| 8071 | // |
| 8072 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8073 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8074 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8075 | // // Slow path. |
| 8076 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8077 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8078 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8079 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8080 | Location temp = Location::RegisterLocation(LR); |
| 8081 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 8082 | instruction, root, /* entrypoint */ temp); |
| 8083 | codegen_->AddSlowPath(slow_path); |
| 8084 | |
| 8085 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8086 | const int32_t entry_point_offset = |
| 8087 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8088 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8089 | // threads are suspended or running a checkpoint. |
| 8090 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 8091 | |
| 8092 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8093 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8094 | static_assert( |
| 8095 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8096 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8097 | "have different sizes."); |
| 8098 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8099 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8100 | "have different sizes."); |
| 8101 | |
| 8102 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8103 | // checking GetIsGcMarking. |
| 8104 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8105 | __ Bind(slow_path->GetExitLabel()); |
| 8106 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8107 | } else { |
| 8108 | // GC root loaded through a slow path for read barriers other |
| 8109 | // than Baker's. |
| 8110 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8111 | __ AddConstant(root_reg, obj, offset); |
| 8112 | // /* mirror::Object* */ root = root->Read() |
| 8113 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8114 | } |
| 8115 | } else { |
| 8116 | // Plain GC root load with no read barrier. |
| 8117 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8118 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8119 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8120 | // do not have to unpoison `root_reg` here. |
| 8121 | } |
| 8122 | } |
| 8123 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8124 | void CodeGeneratorARM::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8125 | DCHECK(kEmitCompilerReadBarrier); |
| 8126 | DCHECK(kUseBakerReadBarrier); |
| 8127 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8128 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8129 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 8130 | } |
| 8131 | } |
| 8132 | } |
| 8133 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8134 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8135 | Location ref, |
| 8136 | Register obj, |
| 8137 | uint32_t offset, |
| 8138 | Location temp, |
| 8139 | bool needs_null_check) { |
| 8140 | DCHECK(kEmitCompilerReadBarrier); |
| 8141 | DCHECK(kUseBakerReadBarrier); |
| 8142 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8143 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8144 | !Runtime::Current()->UseJitCompilation()) { |
| 8145 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8146 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8147 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8148 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8149 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8150 | // |
| 8151 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8152 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8153 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8154 | // |
| 8155 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8156 | // lr = &gray_return_address; |
| 8157 | // if (temp != nullptr) { |
| 8158 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8159 | // } |
| 8160 | // not_gray_return_address: |
| 8161 | // // Original reference load. If the offset is too large to fit |
| 8162 | // // into LDR, we use an adjusted base register here. |
| 8163 | // GcRoot<mirror::Object> reference = *(obj+offset); |
| 8164 | // gray_return_address: |
| 8165 | |
| 8166 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8167 | Register base = obj; |
| 8168 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8169 | base = temp.AsRegister<Register>(); |
| 8170 | DCHECK_NE(base, kBakerCcEntrypointRegister); |
| 8171 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8172 | __ AddConstant(base, obj, offset & ~(kReferenceLoadMinFarOffset - 1u)); |
| 8173 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8174 | } |
| 8175 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8176 | uint32_t custom_data = |
| 8177 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData(base, obj); |
| 8178 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8179 | |
| 8180 | // entrypoint_reg = |
| 8181 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8182 | DCHECK_EQ(IP, 12); |
| 8183 | const int32_t entry_point_offset = |
| 8184 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8185 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8186 | |
| 8187 | Label return_address; |
| 8188 | __ AdrCode(LR, &return_address); |
| 8189 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8190 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8191 | EmitPlaceholderBne(this, bne_label); |
| 8192 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 8193 | "Field LDR must be 1 32-bit instruction (4B) before the return address label; " |
| 8194 | " 2 32-bit instructions (8B) for heap poisoning."); |
| 8195 | Register ref_reg = ref.AsRegister<Register>(); |
| 8196 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8197 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset); |
| 8198 | if (needs_null_check) { |
| 8199 | MaybeRecordImplicitNullCheck(instruction); |
| 8200 | } |
| 8201 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8202 | __ Bind(&return_address); |
| 8203 | return; |
| 8204 | } |
| 8205 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8206 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8207 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8208 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8209 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8210 | instruction, ref, obj, offset, no_index, no_scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8211 | } |
| 8212 | |
| 8213 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8214 | Location ref, |
| 8215 | Register obj, |
| 8216 | uint32_t data_offset, |
| 8217 | Location index, |
| 8218 | Location temp, |
| 8219 | bool needs_null_check) { |
| 8220 | DCHECK(kEmitCompilerReadBarrier); |
| 8221 | DCHECK(kUseBakerReadBarrier); |
| 8222 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8223 | static_assert( |
| 8224 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8225 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8226 | ScaleFactor scale_factor = TIMES_4; |
| 8227 | |
| 8228 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8229 | !Runtime::Current()->UseJitCompilation()) { |
| 8230 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8231 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8232 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8233 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8234 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8235 | // |
| 8236 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8237 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8238 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8239 | // |
| 8240 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8241 | // lr = &gray_return_address; |
| 8242 | // if (temp != nullptr) { |
| 8243 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8244 | // } |
| 8245 | // not_gray_return_address: |
| 8246 | // // Original reference load. If the offset is too large to fit |
| 8247 | // // into LDR, we use an adjusted base register here. |
| 8248 | // GcRoot<mirror::Object> reference = data[index]; |
| 8249 | // gray_return_address: |
| 8250 | |
| 8251 | DCHECK(index.IsValid()); |
| 8252 | Register index_reg = index.AsRegister<Register>(); |
| 8253 | Register ref_reg = ref.AsRegister<Register>(); |
| 8254 | Register data_reg = temp.AsRegister<Register>(); |
| 8255 | DCHECK_NE(data_reg, kBakerCcEntrypointRegister); |
| 8256 | |
| 8257 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8258 | uint32_t custom_data = |
| 8259 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg); |
| 8260 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8261 | |
| 8262 | // entrypoint_reg = |
| 8263 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8264 | DCHECK_EQ(IP, 12); |
| 8265 | const int32_t entry_point_offset = |
| 8266 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8267 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8268 | __ AddConstant(data_reg, obj, data_offset); |
| 8269 | |
| 8270 | Label return_address; |
| 8271 | __ AdrCode(LR, &return_address); |
| 8272 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8273 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8274 | EmitPlaceholderBne(this, bne_label); |
| 8275 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 8276 | "Array LDR must be 1 32-bit instruction (4B) before the return address label; " |
| 8277 | " 2 32-bit instructions (8B) for heap poisoning."); |
| 8278 | __ ldr(ref_reg, Address(data_reg, index_reg, LSL, scale_factor)); |
| 8279 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8280 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8281 | __ Bind(&return_address); |
| 8282 | return; |
| 8283 | } |
| 8284 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8285 | // /* HeapReference<Object> */ ref = |
| 8286 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8287 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8288 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8289 | } |
| 8290 | |
| 8291 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8292 | Location ref, |
| 8293 | Register obj, |
| 8294 | uint32_t offset, |
| 8295 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8296 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8297 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8298 | bool needs_null_check, |
| 8299 | bool always_update_field, |
| 8300 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8301 | DCHECK(kEmitCompilerReadBarrier); |
| 8302 | DCHECK(kUseBakerReadBarrier); |
| 8303 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8304 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8305 | // whether we need to enter the slow path to mark the reference. |
| 8306 | // Then, in the slow path, check the gray bit in the lock word of |
| 8307 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8308 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8309 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8310 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 8311 | // instead, we load into `temp3` the read barrier mark entry point |
| 8312 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8313 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8314 | // |
| 8315 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8316 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8317 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8318 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8319 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8320 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8321 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8322 | // if (is_gray) { |
| 8323 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8324 | // } |
| 8325 | // } else { |
| 8326 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8327 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8328 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8329 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 8330 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8331 | // Slow path marking the object `ref` when the GC is marking. The |
| 8332 | // entrypoint will already be loaded in `temp3`. |
| 8333 | Location temp3 = Location::RegisterLocation(LR); |
| 8334 | SlowPathCodeARM* slow_path; |
| 8335 | if (always_update_field) { |
| 8336 | DCHECK(temp2 != nullptr); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8337 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM only |
| 8338 | // supports address of the form `obj + field_offset`, where `obj` |
| 8339 | // is a register and `field_offset` is a register pair (of which |
| 8340 | // only the lower half is used). Thus `offset` and `scale_factor` |
| 8341 | // above are expected to be null in this code path. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8342 | DCHECK_EQ(offset, 0u); |
| 8343 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8344 | Location field_offset = index; |
| 8345 | slow_path = |
| 8346 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 8347 | instruction, |
| 8348 | ref, |
| 8349 | obj, |
| 8350 | offset, |
| 8351 | /* index */ field_offset, |
| 8352 | scale_factor, |
| 8353 | needs_null_check, |
| 8354 | temp_reg, |
| 8355 | *temp2, |
| 8356 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8357 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8358 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 8359 | instruction, |
| 8360 | ref, |
| 8361 | obj, |
| 8362 | offset, |
| 8363 | index, |
| 8364 | scale_factor, |
| 8365 | needs_null_check, |
| 8366 | temp_reg, |
| 8367 | /* entrypoint */ temp3); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8368 | } |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8369 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8370 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8371 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8372 | const int32_t entry_point_offset = |
| 8373 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8374 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8375 | // threads are suspended or running a checkpoint. |
| 8376 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8377 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8378 | // checking GetIsGcMarking. |
| 8379 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8380 | // Fast path: just load the reference. |
| 8381 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8382 | __ Bind(slow_path->GetExitLabel()); |
| 8383 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8384 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8385 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8386 | Location ref, |
| 8387 | Register obj, |
| 8388 | uint32_t offset, |
| 8389 | Location index, |
| 8390 | ScaleFactor scale_factor, |
| 8391 | bool needs_null_check) { |
| 8392 | Register ref_reg = ref.AsRegister<Register>(); |
| 8393 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8394 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8395 | // Load types involving an "index": ArrayGet, |
| 8396 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8397 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8398 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8399 | if (index.IsConstant()) { |
| 8400 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8401 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8402 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8403 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8404 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8405 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8406 | // intrinsics, which use a register pair as index ("long |
| 8407 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8408 | Register index_reg = index.IsRegisterPair() |
| 8409 | ? index.AsRegisterPairLow<Register>() |
| 8410 | : index.AsRegister<Register>(); |
| 8411 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8412 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8413 | } |
| 8414 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8415 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8416 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8417 | } |
| 8418 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8419 | if (needs_null_check) { |
| 8420 | MaybeRecordImplicitNullCheck(instruction); |
| 8421 | } |
| 8422 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8423 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8424 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8425 | } |
| 8426 | |
| 8427 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8428 | Location out, |
| 8429 | Location ref, |
| 8430 | Location obj, |
| 8431 | uint32_t offset, |
| 8432 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8433 | DCHECK(kEmitCompilerReadBarrier); |
| 8434 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8435 | // Insert a slow path based read barrier *after* the reference load. |
| 8436 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8437 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8438 | // reference will be carried out by the runtime within the slow |
| 8439 | // path. |
| 8440 | // |
| 8441 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8442 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8443 | // not used by the artReadBarrierSlow entry point. |
| 8444 | // |
| 8445 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8446 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8447 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8448 | AddSlowPath(slow_path); |
| 8449 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8450 | __ b(slow_path->GetEntryLabel()); |
| 8451 | __ Bind(slow_path->GetExitLabel()); |
| 8452 | } |
| 8453 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8454 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8455 | Location out, |
| 8456 | Location ref, |
| 8457 | Location obj, |
| 8458 | uint32_t offset, |
| 8459 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8460 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8461 | // Baker's read barriers shall be handled by the fast path |
| 8462 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8463 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8464 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8465 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8466 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8467 | } else if (kPoisonHeapReferences) { |
| 8468 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8469 | } |
| 8470 | } |
| 8471 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8472 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8473 | Location out, |
| 8474 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8475 | DCHECK(kEmitCompilerReadBarrier); |
| 8476 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8477 | // Insert a slow path based read barrier *after* the GC root load. |
| 8478 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8479 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8480 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8481 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8482 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8483 | AddSlowPath(slow_path); |
| 8484 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8485 | __ b(slow_path->GetEntryLabel()); |
| 8486 | __ Bind(slow_path->GetExitLabel()); |
| 8487 | } |
| 8488 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8489 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8490 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8491 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8492 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8493 | } |
| 8494 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8495 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8496 | Register temp) { |
| 8497 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8498 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8499 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8500 | return location.AsRegister<Register>(); |
| 8501 | } |
| 8502 | // For intrinsics we allow any location, so it may be on the stack. |
| 8503 | if (!location.IsRegister()) { |
| 8504 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8505 | return temp; |
| 8506 | } |
| 8507 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8508 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8509 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8510 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8511 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8512 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8513 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8514 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8515 | return temp; |
| 8516 | } |
| 8517 | return location.AsRegister<Register>(); |
| 8518 | } |
| 8519 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8520 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8521 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8522 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8523 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8524 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8525 | uint32_t offset = |
| 8526 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8527 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8528 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8529 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8530 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8531 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8532 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8533 | break; |
| 8534 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8535 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8536 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8537 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8538 | HArmDexCacheArraysBase* base = |
| 8539 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8540 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8541 | temp.AsRegister<Register>()); |
| 8542 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8543 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8544 | break; |
| 8545 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8546 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8547 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8548 | Register method_reg; |
| 8549 | Register reg = temp.AsRegister<Register>(); |
| 8550 | if (current_method.IsRegister()) { |
| 8551 | method_reg = current_method.AsRegister<Register>(); |
| 8552 | } else { |
| 8553 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8554 | DCHECK(!current_method.IsValid()); |
| 8555 | method_reg = reg; |
| 8556 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 8557 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8558 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8559 | __ LoadFromOffset(kLoadWord, |
| 8560 | reg, |
| 8561 | method_reg, |
| 8562 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 8563 | // temp = temp[index_in_cache]; |
| 8564 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8565 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8566 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 8567 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 8568 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8569 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8570 | return callee_method; |
| 8571 | } |
| 8572 | |
| 8573 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 8574 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8575 | |
| 8576 | switch (invoke->GetCodePtrLocation()) { |
| 8577 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8578 | __ bl(GetFrameEntryLabel()); |
| 8579 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8580 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8581 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8582 | __ LoadFromOffset( |
| 8583 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8584 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8585 | // LR() |
| 8586 | __ blx(LR); |
| 8587 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8588 | } |
| 8589 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8590 | DCHECK(!IsLeafMethod()); |
| 8591 | } |
| 8592 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8593 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8594 | Register temp = temp_location.AsRegister<Register>(); |
| 8595 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8596 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8597 | |
| 8598 | // Use the calling convention instead of the location of the receiver, as |
| 8599 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8600 | // slow path, the arguments have been moved to the right place, so here we are |
| 8601 | // guaranteed that the receiver is the first register of the calling convention. |
| 8602 | InvokeDexCallingConvention calling_convention; |
| 8603 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8604 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8605 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8606 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8607 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8608 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8609 | // emit a read barrier for the previous class reference load. |
| 8610 | // However this is not required in practice, as this is an |
| 8611 | // intermediate/temporary reference and because the current |
| 8612 | // concurrent copying collector keeps the from-space memory |
| 8613 | // intact/accessible until the end of the marking phase (the |
| 8614 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8615 | __ MaybeUnpoisonHeapReference(temp); |
| 8616 | // temp = temp->GetMethodAt(method_offset); |
| 8617 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8618 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8619 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8620 | // LR = temp->GetEntryPoint(); |
| 8621 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 8622 | // LR(); |
| 8623 | __ blx(LR); |
| 8624 | } |
| 8625 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8626 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8627 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8628 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8629 | } |
| 8630 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8631 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8632 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8633 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8634 | } |
| 8635 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8636 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 8637 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8638 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8639 | } |
| 8640 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8641 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 8642 | const DexFile& dex_file, uint32_t element_offset) { |
| 8643 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8644 | } |
| 8645 | |
| 8646 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 8647 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8648 | patches->emplace_back(dex_file, offset_or_index); |
| 8649 | return &patches->back(); |
| 8650 | } |
| 8651 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8652 | Label* CodeGeneratorARM::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 8653 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 8654 | return &baker_read_barrier_patches_.back().label; |
| 8655 | } |
| 8656 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8657 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8658 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8659 | return boot_image_string_patches_.GetOrCreate( |
| 8660 | StringReference(&dex_file, string_index), |
| 8661 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8662 | } |
| 8663 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8664 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8665 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8666 | return boot_image_type_patches_.GetOrCreate( |
| 8667 | TypeReference(&dex_file, type_index), |
| 8668 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8669 | } |
| 8670 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8671 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8672 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8673 | } |
| 8674 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8675 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8676 | dex::StringIndex string_index, |
| 8677 | Handle<mirror::String> handle) { |
| 8678 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8679 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8680 | return jit_string_patches_.GetOrCreate( |
| 8681 | StringReference(&dex_file, string_index), |
| 8682 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8683 | } |
| 8684 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8685 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8686 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8687 | Handle<mirror::Class> handle) { |
| 8688 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8689 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8690 | return jit_class_patches_.GetOrCreate( |
| 8691 | TypeReference(&dex_file, type_index), |
| 8692 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8693 | } |
| 8694 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8695 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8696 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 8697 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8698 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8699 | for (const PcRelativePatchInfo& info : infos) { |
| 8700 | const DexFile& dex_file = info.target_dex_file; |
| 8701 | size_t offset_or_index = info.offset_or_index; |
| 8702 | DCHECK(info.add_pc_label.IsBound()); |
| 8703 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 8704 | // Add MOVW patch. |
| 8705 | DCHECK(info.movw_label.IsBound()); |
| 8706 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 8707 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8708 | // Add MOVT patch. |
| 8709 | DCHECK(info.movt_label.IsBound()); |
| 8710 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 8711 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8712 | } |
| 8713 | } |
| 8714 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8715 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8716 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8717 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8718 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8719 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8720 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8721 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8722 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8723 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
| 8724 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8725 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8726 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8727 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8728 | for (const auto& entry : boot_image_string_patches_) { |
| 8729 | const StringReference& target_string = entry.first; |
| 8730 | Literal* literal = entry.second; |
| 8731 | DCHECK(literal->GetLabel()->IsBound()); |
| 8732 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8733 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8734 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8735 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8736 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8737 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8738 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8739 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8740 | linker_patches); |
| 8741 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8742 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8743 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8744 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8745 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8746 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8747 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8748 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8749 | for (const auto& entry : boot_image_type_patches_) { |
| 8750 | const TypeReference& target_type = entry.first; |
| 8751 | Literal* literal = entry.second; |
| 8752 | DCHECK(literal->GetLabel()->IsBound()); |
| 8753 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8754 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8755 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8756 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8757 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame^] | 8758 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 8759 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.Position(), |
| 8760 | info.custom_data)); |
| 8761 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8762 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 8766 | return map->GetOrCreate( |
| 8767 | value, |
| 8768 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8769 | } |
| 8770 | |
| 8771 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 8772 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8773 | return map->GetOrCreate( |
| 8774 | target_method, |
| 8775 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8776 | } |
| 8777 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8778 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8779 | LocationSummary* locations = |
| 8780 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8781 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8782 | Location::RequiresRegister()); |
| 8783 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8784 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8785 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8786 | } |
| 8787 | |
| 8788 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8789 | LocationSummary* locations = instr->GetLocations(); |
| 8790 | Register res = locations->Out().AsRegister<Register>(); |
| 8791 | Register accumulator = |
| 8792 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 8793 | Register mul_left = |
| 8794 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 8795 | Register mul_right = |
| 8796 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 8797 | |
| 8798 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8799 | __ mla(res, mul_left, mul_right, accumulator); |
| 8800 | } else { |
| 8801 | __ mls(res, mul_left, mul_right, accumulator); |
| 8802 | } |
| 8803 | } |
| 8804 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8805 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8806 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8807 | LOG(FATAL) << "Unreachable"; |
| 8808 | } |
| 8809 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8810 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8811 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8812 | LOG(FATAL) << "Unreachable"; |
| 8813 | } |
| 8814 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8815 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8816 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8817 | LocationSummary* locations = |
| 8818 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8819 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8820 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8821 | codegen_->GetAssembler()->IsThumb()) { |
| 8822 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8823 | if (switch_instr->GetStartValue() != 0) { |
| 8824 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8825 | } |
| 8826 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8827 | } |
| 8828 | |
| 8829 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8830 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8831 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8832 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8833 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8834 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8835 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8836 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8837 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8838 | Register temp_reg = IP; |
| 8839 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8840 | // the immediate, because IP is used as the destination register. For the other |
| 8841 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8842 | // and they can be encoded in the instruction without making use of IP register. |
| 8843 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8844 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8845 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8846 | // Jump to successors[0] if value == lower_bound. |
| 8847 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8848 | int32_t last_index = 0; |
| 8849 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8850 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8851 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8852 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8853 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8854 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8855 | } |
| 8856 | if (num_entries - last_index == 2) { |
| 8857 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8858 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8859 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8860 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8861 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8862 | // And the default for any other value. |
| 8863 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8864 | __ b(codegen_->GetLabelOf(default_block)); |
| 8865 | } |
| 8866 | } else { |
| 8867 | // Create a table lookup. |
| 8868 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8869 | |
| 8870 | // Materialize a pointer to the switch table |
| 8871 | std::vector<Label*> labels(num_entries); |
| 8872 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8873 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8874 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8875 | } |
| 8876 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8877 | |
| 8878 | // Remove the bias. |
| 8879 | Register key_reg; |
| 8880 | if (lower_bound != 0) { |
| 8881 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8882 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8883 | } else { |
| 8884 | key_reg = value_reg; |
| 8885 | } |
| 8886 | |
| 8887 | // Check whether the value is in the table, jump to default block if not. |
| 8888 | __ CmpConstant(key_reg, num_entries - 1); |
| 8889 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8890 | |
| 8891 | // Load the displacement from the table. |
| 8892 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8893 | |
| 8894 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8895 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8896 | } |
| 8897 | } |
| 8898 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8899 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8900 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8901 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8902 | } |
| 8903 | |
| 8904 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8905 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8906 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8907 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8908 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8909 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8910 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8911 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8912 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8913 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8914 | } |
| 8915 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8916 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8917 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8918 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8919 | return; |
| 8920 | } |
| 8921 | |
| 8922 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8923 | |
| 8924 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8925 | if (return_loc.Equals(trg)) { |
| 8926 | return; |
| 8927 | } |
| 8928 | |
| 8929 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8930 | // with the last branch. |
| 8931 | if (type == Primitive::kPrimLong) { |
| 8932 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8933 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8934 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8935 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8936 | } else if (type == Primitive::kPrimDouble) { |
| 8937 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8938 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8939 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8940 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8941 | } else { |
| 8942 | // Let the parallel move resolver take care of all of this. |
| 8943 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8944 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8945 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8946 | } |
| 8947 | } |
| 8948 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8949 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8950 | LocationSummary* locations = |
| 8951 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8953 | locations->SetOut(Location::RequiresRegister()); |
| 8954 | } |
| 8955 | |
| 8956 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8957 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8958 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8959 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8960 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8961 | __ LoadFromOffset(kLoadWord, |
| 8962 | locations->Out().AsRegister<Register>(), |
| 8963 | locations->InAt(0).AsRegister<Register>(), |
| 8964 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8965 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8966 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8967 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8968 | __ LoadFromOffset(kLoadWord, |
| 8969 | locations->Out().AsRegister<Register>(), |
| 8970 | locations->InAt(0).AsRegister<Register>(), |
| 8971 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8972 | __ LoadFromOffset(kLoadWord, |
| 8973 | locations->Out().AsRegister<Register>(), |
| 8974 | locations->Out().AsRegister<Register>(), |
| 8975 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8976 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8977 | } |
| 8978 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8979 | static void PatchJitRootUse(uint8_t* code, |
| 8980 | const uint8_t* roots_data, |
| 8981 | Literal* literal, |
| 8982 | uint64_t index_in_table) { |
| 8983 | DCHECK(literal->GetLabel()->IsBound()); |
| 8984 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8985 | uintptr_t address = |
| 8986 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8987 | uint8_t* data = code + literal_offset; |
| 8988 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8989 | } |
| 8990 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8991 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8992 | for (const auto& entry : jit_string_patches_) { |
| 8993 | const auto& it = jit_string_roots_.find(entry.first); |
| 8994 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8995 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8996 | } |
| 8997 | for (const auto& entry : jit_class_patches_) { |
| 8998 | const auto& it = jit_class_roots_.find(entry.first); |
| 8999 | DCHECK(it != jit_class_roots_.end()); |
| 9000 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9001 | } |
| 9002 | } |
| 9003 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9004 | #undef __ |
| 9005 | #undef QUICK_ENTRY_POINT |
| 9006 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9007 | } // namespace arm |
| 9008 | } // namespace art |