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) { |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 93 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(codegen->GetAssembler())); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 94 | __ BindTrackedLabel(bne_label); |
| 95 | Label placeholder_label; |
| 96 | __ b(&placeholder_label, NE); // Placeholder, patched at link-time. |
| 97 | __ Bind(&placeholder_label); |
| 98 | } |
| 99 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 100 | static inline bool CanEmitNarrowLdr(Register rt, Register rn, uint32_t offset) { |
| 101 | return ArmAssembler::IsLowRegister(rt) && ArmAssembler::IsLowRegister(rn) && offset < 32u; |
| 102 | } |
| 103 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 104 | static constexpr int kRegListThreshold = 4; |
| 105 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 106 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 107 | // for each live D registers they treat two corresponding S registers as live ones. |
| 108 | // |
| 109 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 110 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 111 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 112 | // - decreasing code size |
| 113 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 114 | // restored and then used in regular non SlowPath code as D register. |
| 115 | // |
| 116 | // For the following example (v means the S register is live): |
| 117 | // D names: | D0 | D1 | D2 | D4 | ... |
| 118 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 119 | // Live? | | v | v | v | v | v | v | | ... |
| 120 | // |
| 121 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 122 | // as D registers. |
| 123 | static size_t SaveContiguousSRegisterList(size_t first, |
| 124 | size_t last, |
| 125 | CodeGenerator* codegen, |
| 126 | size_t stack_offset) { |
| 127 | DCHECK_LE(first, last); |
| 128 | if ((first == last) && (first == 0)) { |
| 129 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 130 | return stack_offset; |
| 131 | } |
| 132 | if (first % 2 == 1) { |
| 133 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 134 | } |
| 135 | |
| 136 | bool save_last = false; |
| 137 | if (last % 2 == 0) { |
| 138 | save_last = true; |
| 139 | --last; |
| 140 | } |
| 141 | |
| 142 | if (first < last) { |
| 143 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 144 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 145 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 146 | |
| 147 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 148 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 149 | } else if (number_of_d_regs > 1) { |
| 150 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 151 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 152 | } |
| 153 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 154 | } |
| 155 | |
| 156 | if (save_last) { |
| 157 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 158 | } |
| 159 | |
| 160 | return stack_offset; |
| 161 | } |
| 162 | |
| 163 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 164 | size_t last, |
| 165 | CodeGenerator* codegen, |
| 166 | size_t stack_offset) { |
| 167 | DCHECK_LE(first, last); |
| 168 | if ((first == last) && (first == 0)) { |
| 169 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 170 | return stack_offset; |
| 171 | } |
| 172 | if (first % 2 == 1) { |
| 173 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 174 | } |
| 175 | |
| 176 | bool restore_last = false; |
| 177 | if (last % 2 == 0) { |
| 178 | restore_last = true; |
| 179 | --last; |
| 180 | } |
| 181 | |
| 182 | if (first < last) { |
| 183 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 184 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 185 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 186 | if (number_of_d_regs == 1) { |
| 187 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 188 | } else if (number_of_d_regs > 1) { |
| 189 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 190 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 191 | } |
| 192 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 193 | } |
| 194 | |
| 195 | if (restore_last) { |
| 196 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 197 | } |
| 198 | |
| 199 | return stack_offset; |
| 200 | } |
| 201 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 202 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 203 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 204 | size_t orig_offset = stack_offset; |
| 205 | |
| 206 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 207 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 208 | // If the register holds an object, update the stack mask. |
| 209 | if (locations->RegisterContainsObject(i)) { |
| 210 | locations->SetStackBit(stack_offset / kVRegSize); |
| 211 | } |
| 212 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 213 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 214 | saved_core_stack_offsets_[i] = stack_offset; |
| 215 | stack_offset += kArmWordSize; |
| 216 | } |
| 217 | |
| 218 | int reg_num = POPCOUNT(core_spills); |
| 219 | if (reg_num != 0) { |
| 220 | if (reg_num > kRegListThreshold) { |
| 221 | __ StoreList(RegList(core_spills), orig_offset); |
| 222 | } else { |
| 223 | stack_offset = orig_offset; |
| 224 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 225 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 230 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 231 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 232 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 233 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 234 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 235 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 236 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 237 | |
| 238 | stack_offset = orig_offset; |
| 239 | while (fp_spills != 0u) { |
| 240 | uint32_t begin = CTZ(fp_spills); |
| 241 | uint32_t tmp = fp_spills + (1u << begin); |
| 242 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 243 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 244 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 245 | } |
| 246 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 250 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 251 | size_t orig_offset = stack_offset; |
| 252 | |
| 253 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 254 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 255 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 256 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 257 | stack_offset += kArmWordSize; |
| 258 | } |
| 259 | |
| 260 | int reg_num = POPCOUNT(core_spills); |
| 261 | if (reg_num != 0) { |
| 262 | if (reg_num > kRegListThreshold) { |
| 263 | __ LoadList(RegList(core_spills), orig_offset); |
| 264 | } else { |
| 265 | stack_offset = orig_offset; |
| 266 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 267 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 272 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 273 | while (fp_spills != 0u) { |
| 274 | uint32_t begin = CTZ(fp_spills); |
| 275 | uint32_t tmp = fp_spills + (1u << begin); |
| 276 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 277 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 278 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 279 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 280 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 285 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 286 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 289 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 290 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 291 | // Live registers will be restored in the catch block if caught. |
| 292 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 293 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 294 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 295 | instruction_, |
| 296 | instruction_->GetDexPc(), |
| 297 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 298 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 301 | bool IsFatal() const OVERRIDE { return true; } |
| 302 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 303 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 304 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 305 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 306 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 307 | }; |
| 308 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 309 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 310 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 311 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 312 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 314 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 315 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 316 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 317 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 320 | bool IsFatal() const OVERRIDE { return true; } |
| 321 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 322 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 323 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 324 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 329 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 335 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 336 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 338 | if (successor_ == nullptr) { |
| 339 | __ b(GetReturnLabel()); |
| 340 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 341 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 342 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 345 | Label* GetReturnLabel() { |
| 346 | DCHECK(successor_ == nullptr); |
| 347 | return &return_label_; |
| 348 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 349 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 350 | HBasicBlock* GetSuccessor() const { |
| 351 | return successor_; |
| 352 | } |
| 353 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 354 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 355 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 356 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 357 | // If not null, the block to branch to after the suspend check. |
| 358 | HBasicBlock* const successor_; |
| 359 | |
| 360 | // 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] | 361 | Label return_label_; |
| 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 364 | }; |
| 365 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 366 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 367 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 368 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 369 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 370 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 372 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 373 | LocationSummary* locations = instruction_->GetLocations(); |
| 374 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 376 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 377 | // Live registers will be restored in the catch block if caught. |
| 378 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 379 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 380 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 381 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 382 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 383 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 384 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 385 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 386 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 387 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 388 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 389 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 390 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 391 | ? kQuickThrowStringBounds |
| 392 | : kQuickThrowArrayBounds; |
| 393 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 395 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 398 | bool IsFatal() const OVERRIDE { return true; } |
| 399 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 400 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 401 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 402 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 403 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 404 | }; |
| 405 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 406 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 407 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 408 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 409 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 410 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 411 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 412 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 413 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 414 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 415 | Location out = locations->Out(); |
| 416 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 417 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 418 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 419 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 420 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 421 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 422 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 423 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 424 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 425 | bool is_load_class_bss_entry = |
| 426 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 427 | Register entry_address = kNoRegister; |
| 428 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 429 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 430 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 431 | // the kSaveEverything call. |
| 432 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 433 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 434 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 435 | if (temp_is_r0) { |
| 436 | __ mov(entry_address, ShifterOperand(temp)); |
| 437 | } |
| 438 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 439 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 440 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 441 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 442 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 443 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | if (do_clinit_) { |
| 445 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 446 | } else { |
| 447 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 448 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 449 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 450 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 451 | if (is_load_class_bss_entry) { |
| 452 | if (call_saves_everything_except_r0) { |
| 453 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 454 | __ str(R0, Address(entry_address)); |
| 455 | } else { |
| 456 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 457 | Register temp = IP; |
| 458 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 459 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 460 | __ BindTrackedLabel(&labels->movw_label); |
| 461 | __ movw(temp, /* placeholder */ 0u); |
| 462 | __ BindTrackedLabel(&labels->movt_label); |
| 463 | __ movt(temp, /* placeholder */ 0u); |
| 464 | __ BindTrackedLabel(&labels->add_pc_label); |
| 465 | __ add(temp, temp, ShifterOperand(PC)); |
| 466 | __ str(R0, Address(temp)); |
| 467 | } |
| 468 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 469 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 470 | if (out.IsValid()) { |
| 471 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 472 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 473 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 474 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 475 | __ b(GetExitLabel()); |
| 476 | } |
| 477 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 478 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 479 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 480 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 481 | // The class this slow path will load. |
| 482 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 483 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 484 | // The dex PC of `at_`. |
| 485 | const uint32_t dex_pc_; |
| 486 | |
| 487 | // Whether to initialize the class. |
| 488 | const bool do_clinit_; |
| 489 | |
| 490 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 491 | }; |
| 492 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 493 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 494 | public: |
| 495 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 496 | |
| 497 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 498 | DCHECK(instruction_->IsLoadString()); |
| 499 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 500 | LocationSummary* locations = instruction_->GetLocations(); |
| 501 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 502 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 503 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 504 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 505 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 506 | |
| 507 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 508 | __ Bind(GetEntryLabel()); |
| 509 | SaveLiveRegisters(codegen, locations); |
| 510 | |
| 511 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 512 | // 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] | 513 | // the kSaveEverything call. |
| 514 | Register entry_address = kNoRegister; |
| 515 | if (call_saves_everything_except_r0) { |
| 516 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 517 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 518 | entry_address = temp_is_r0 ? out : temp; |
| 519 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 520 | if (temp_is_r0) { |
| 521 | __ mov(entry_address, ShifterOperand(temp)); |
| 522 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 525 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 526 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 527 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 528 | |
| 529 | // Store the resolved String to the .bss entry. |
| 530 | if (call_saves_everything_except_r0) { |
| 531 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 532 | __ str(R0, Address(entry_address)); |
| 533 | } else { |
| 534 | // 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] | 535 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 536 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 537 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 538 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 539 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 540 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 541 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 542 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 543 | __ add(temp, temp, ShifterOperand(PC)); |
| 544 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 547 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 548 | RestoreLiveRegisters(codegen, locations); |
| 549 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 550 | __ b(GetExitLabel()); |
| 551 | } |
| 552 | |
| 553 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 554 | |
| 555 | private: |
| 556 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 557 | }; |
| 558 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 559 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 560 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 561 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 562 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 563 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 564 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 565 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 566 | DCHECK(instruction_->IsCheckCast() |
| 567 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 568 | |
| 569 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 570 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 571 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 572 | if (!is_fatal_) { |
| 573 | SaveLiveRegisters(codegen, locations); |
| 574 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 575 | |
| 576 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 577 | // move resolver. |
| 578 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 579 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 580 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 581 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 582 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 583 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 584 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 585 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 586 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 587 | instruction_, |
| 588 | instruction_->GetDexPc(), |
| 589 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 590 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 591 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 592 | } else { |
| 593 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 594 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 595 | instruction_, |
| 596 | instruction_->GetDexPc(), |
| 597 | this); |
| 598 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 599 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 600 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 601 | if (!is_fatal_) { |
| 602 | RestoreLiveRegisters(codegen, locations); |
| 603 | __ b(GetExitLabel()); |
| 604 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 607 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 608 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 609 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 610 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 611 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 612 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 613 | |
| 614 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 615 | }; |
| 616 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 617 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 618 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 619 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 620 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 621 | |
| 622 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 623 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 624 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 625 | LocationSummary* locations = instruction_->GetLocations(); |
| 626 | SaveLiveRegisters(codegen, locations); |
| 627 | InvokeRuntimeCallingConvention calling_convention; |
| 628 | __ LoadImmediate(calling_convention.GetRegisterAt(0), |
| 629 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 630 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 631 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 634 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 635 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 636 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 637 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 638 | }; |
| 639 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 640 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 641 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 642 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 643 | |
| 644 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 645 | LocationSummary* locations = instruction_->GetLocations(); |
| 646 | __ Bind(GetEntryLabel()); |
| 647 | SaveLiveRegisters(codegen, locations); |
| 648 | |
| 649 | InvokeRuntimeCallingConvention calling_convention; |
| 650 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 651 | parallel_move.AddMove( |
| 652 | locations->InAt(0), |
| 653 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 654 | Primitive::kPrimNot, |
| 655 | nullptr); |
| 656 | parallel_move.AddMove( |
| 657 | locations->InAt(1), |
| 658 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 659 | Primitive::kPrimInt, |
| 660 | nullptr); |
| 661 | parallel_move.AddMove( |
| 662 | locations->InAt(2), |
| 663 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 664 | Primitive::kPrimNot, |
| 665 | nullptr); |
| 666 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 667 | |
| 668 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 669 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 670 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 671 | RestoreLiveRegisters(codegen, locations); |
| 672 | __ b(GetExitLabel()); |
| 673 | } |
| 674 | |
| 675 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 676 | |
| 677 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 678 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 679 | }; |
| 680 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 681 | // Abstract base class for read barrier slow paths marking a reference |
| 682 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 683 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | // Argument `entrypoint` must be a register location holding the read |
| 685 | // barrier marking runtime entry point to be invoked. |
| 686 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 687 | protected: |
| 688 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 689 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 690 | DCHECK(kEmitCompilerReadBarrier); |
| 691 | } |
| 692 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 693 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 694 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 695 | // Generate assembly code calling the read barrier marking runtime |
| 696 | // entry point (ReadBarrierMarkRegX). |
| 697 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 698 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 699 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 700 | // No need to save live registers; it's taken care of by the |
| 701 | // entrypoint. Also, there is no need to update the stack mask, |
| 702 | // as this runtime call will not trigger a garbage collection. |
| 703 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 704 | DCHECK_NE(ref_reg, SP); |
| 705 | DCHECK_NE(ref_reg, LR); |
| 706 | DCHECK_NE(ref_reg, PC); |
| 707 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 708 | // as a temporary, it cannot be the entry point's input/output. |
| 709 | DCHECK_NE(ref_reg, IP); |
| 710 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 711 | // "Compact" slow path, saving two moves. |
| 712 | // |
| 713 | // Instead of using the standard runtime calling convention (input |
| 714 | // and output in R0): |
| 715 | // |
| 716 | // R0 <- ref |
| 717 | // R0 <- ReadBarrierMark(R0) |
| 718 | // ref <- R0 |
| 719 | // |
| 720 | // we just use rX (the register containing `ref`) as input and output |
| 721 | // of a dedicated entrypoint: |
| 722 | // |
| 723 | // rX <- ReadBarrierMarkRegX(rX) |
| 724 | // |
| 725 | if (entrypoint_.IsValid()) { |
| 726 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 727 | __ blx(entrypoint_.AsRegister<Register>()); |
| 728 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 729 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 730 | int32_t entry_point_offset = |
| 731 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 732 | // This runtime call does not require a stack map. |
| 733 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 734 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // The location (register) of the marked object reference. |
| 738 | const Location ref_; |
| 739 | |
| 740 | // The location of the entrypoint if it is already loaded. |
| 741 | const Location entrypoint_; |
| 742 | |
| 743 | private: |
| 744 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 745 | }; |
| 746 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 747 | // Slow path marking an object reference `ref` during a read |
| 748 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 750 | // |
| 751 | // This means that after the execution of this slow path, `ref` will |
| 752 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 753 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 754 | // probably still be a from-space reference (unless it gets updated by |
| 755 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 756 | // reference (different from `ref`) in `obj.field`). |
| 757 | // |
| 758 | // If `entrypoint` is a valid location it is assumed to already be |
| 759 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 760 | // 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] | 761 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 762 | public: |
| 763 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 764 | Location ref, |
| 765 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 766 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 767 | DCHECK(kEmitCompilerReadBarrier); |
| 768 | } |
| 769 | |
| 770 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 771 | |
| 772 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 773 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 774 | DCHECK(locations->CanCall()); |
| 775 | if (kIsDebugBuild) { |
| 776 | Register ref_reg = ref_.AsRegister<Register>(); |
| 777 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 778 | } |
| 779 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 780 | << "Unexpected instruction in read barrier marking slow path: " |
| 781 | << instruction_->DebugName(); |
| 782 | |
| 783 | __ Bind(GetEntryLabel()); |
| 784 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 785 | __ b(GetExitLabel()); |
| 786 | } |
| 787 | |
| 788 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 789 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 790 | }; |
| 791 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 792 | // Slow path loading `obj`'s lock word, loading a reference from |
| 793 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 794 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 795 | // read barrier). The field `obj.field` in the object `obj` holding |
| 796 | // this reference does not get updated by this slow path after marking |
| 797 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 798 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 799 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 800 | // This means that after the execution of this slow path, `ref` will |
| 801 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 802 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 803 | // probably still be a from-space reference (unless it gets updated by |
| 804 | // another thread, or if another thread installed another object |
| 805 | // reference (different from `ref`) in `obj.field`). |
| 806 | // |
| 807 | // Argument `entrypoint` must be a register location holding the read |
| 808 | // barrier marking runtime entry point to be invoked. |
| 809 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 810 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 811 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 812 | Location ref, |
| 813 | Register obj, |
| 814 | uint32_t offset, |
| 815 | Location index, |
| 816 | ScaleFactor scale_factor, |
| 817 | bool needs_null_check, |
| 818 | Register temp, |
| 819 | Location entrypoint) |
| 820 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 821 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 822 | offset_(offset), |
| 823 | index_(index), |
| 824 | scale_factor_(scale_factor), |
| 825 | needs_null_check_(needs_null_check), |
| 826 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 827 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 828 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 831 | const char* GetDescription() const OVERRIDE { |
| 832 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 833 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 834 | |
| 835 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 836 | LocationSummary* locations = instruction_->GetLocations(); |
| 837 | Register ref_reg = ref_.AsRegister<Register>(); |
| 838 | DCHECK(locations->CanCall()); |
| 839 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 840 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 842 | instruction_->IsStaticFieldGet() || |
| 843 | instruction_->IsArrayGet() || |
| 844 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 845 | instruction_->IsInstanceOf() || |
| 846 | instruction_->IsCheckCast() || |
| 847 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 848 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 849 | << "Unexpected instruction in read barrier marking slow path: " |
| 850 | << instruction_->DebugName(); |
| 851 | // The read barrier instrumentation of object ArrayGet |
| 852 | // instructions does not support the HIntermediateAddress |
| 853 | // instruction. |
| 854 | DCHECK(!(instruction_->IsArrayGet() && |
| 855 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 856 | |
| 857 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 858 | |
| 859 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 860 | // inserted after the original load. However, in fast path based |
| 861 | // Baker's read barriers, we need to perform the load of |
| 862 | // mirror::Object::monitor_ *before* the original reference load. |
| 863 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 864 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 865 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 866 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 867 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 868 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 869 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 870 | // if (is_gray) { |
| 871 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 872 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 873 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 874 | // Note: the original implementation in ReadBarrier::Barrier is |
| 875 | // slightly more complex as it performs additional checks that we do |
| 876 | // not do here for performance reasons. |
| 877 | |
| 878 | // /* int32_t */ monitor = obj->monitor_ |
| 879 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 880 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 881 | if (needs_null_check_) { |
| 882 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 883 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 884 | // /* LockWord */ lock_word = LockWord(monitor) |
| 885 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 886 | "art::LockWord and int32_t have different sizes."); |
| 887 | |
| 888 | // Introduce a dependency on the lock_word including the rb_state, |
| 889 | // which shall prevent load-load reordering without using |
| 890 | // a memory barrier (which would be more expensive). |
| 891 | // `obj` is unchanged by this operation, but its value now depends |
| 892 | // on `temp`. |
| 893 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 894 | |
| 895 | // The actual reference load. |
| 896 | // A possible implicit null check has already been handled above. |
| 897 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 898 | arm_codegen->GenerateRawReferenceLoad( |
| 899 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 900 | |
| 901 | // Mark the object `ref` when `obj` is gray. |
| 902 | // |
| 903 | // if (rb_state == ReadBarrier::GrayState()) |
| 904 | // ref = ReadBarrier::Mark(ref); |
| 905 | // |
| 906 | // Given the numeric representation, it's enough to check the low bit of the |
| 907 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 908 | // which can be a 16-bit instruction unlike the TST immediate. |
| 909 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 910 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 911 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 912 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 913 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 914 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 915 | __ b(GetExitLabel()); |
| 916 | } |
| 917 | |
| 918 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | // The register containing the object holding the marked object reference field. |
| 920 | Register obj_; |
| 921 | // The offset, index and scale factor to access the reference in `obj_`. |
| 922 | uint32_t offset_; |
| 923 | Location index_; |
| 924 | ScaleFactor scale_factor_; |
| 925 | // Is a null check required? |
| 926 | bool needs_null_check_; |
| 927 | // A temporary register used to hold the lock word of `obj_`. |
| 928 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 929 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 930 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 931 | }; |
| 932 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 933 | // Slow path loading `obj`'s lock word, loading a reference from |
| 934 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 935 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 936 | // read barrier). If needed, this slow path also atomically updates |
| 937 | // the field `obj.field` in the object `obj` holding this reference |
| 938 | // after marking (contrary to |
| 939 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 940 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 941 | // |
| 942 | // This means that after the execution of this slow path, both `ref` |
| 943 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 944 | // hold the same to-space reference (unless another thread installed |
| 945 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 946 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 947 | // Argument `entrypoint` must be a register location holding the read |
| 948 | // barrier marking runtime entry point to be invoked. |
| 949 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 950 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 951 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 952 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 953 | Location ref, |
| 954 | Register obj, |
| 955 | uint32_t offset, |
| 956 | Location index, |
| 957 | ScaleFactor scale_factor, |
| 958 | bool needs_null_check, |
| 959 | Register temp1, |
| 960 | Register temp2, |
| 961 | Location entrypoint) |
| 962 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 963 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 964 | offset_(offset), |
| 965 | index_(index), |
| 966 | scale_factor_(scale_factor), |
| 967 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 968 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 970 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 971 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | const char* GetDescription() const OVERRIDE { |
| 975 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 976 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 977 | |
| 978 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 979 | LocationSummary* locations = instruction_->GetLocations(); |
| 980 | Register ref_reg = ref_.AsRegister<Register>(); |
| 981 | DCHECK(locations->CanCall()); |
| 982 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 983 | DCHECK_NE(ref_reg, temp1_); |
| 984 | |
| 985 | // 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] | 986 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 987 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 988 | << instruction_->DebugName(); |
| 989 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 990 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 991 | DCHECK_EQ(offset_, 0u); |
| 992 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 993 | // The location of the offset of the marked reference field within `obj_`. |
| 994 | Location field_offset = index_; |
| 995 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 996 | |
| 997 | __ Bind(GetEntryLabel()); |
| 998 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 999 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM's: |
| 1000 | // |
| 1001 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1002 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1003 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1004 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1005 | // if (is_gray) { |
| 1006 | // old_ref = ref; |
| 1007 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1008 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1009 | // } |
| 1010 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1011 | // /* int32_t */ monitor = obj->monitor_ |
| 1012 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1013 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1014 | if (needs_null_check_) { |
| 1015 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1016 | } |
| 1017 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1018 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1019 | "art::LockWord and int32_t have different sizes."); |
| 1020 | |
| 1021 | // Introduce a dependency on the lock_word including the rb_state, |
| 1022 | // which shall prevent load-load reordering without using |
| 1023 | // a memory barrier (which would be more expensive). |
| 1024 | // `obj` is unchanged by this operation, but its value now depends |
| 1025 | // on `temp1`. |
| 1026 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 1027 | |
| 1028 | // The actual reference load. |
| 1029 | // A possible implicit null check has already been handled above. |
| 1030 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1031 | arm_codegen->GenerateRawReferenceLoad( |
| 1032 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1033 | |
| 1034 | // Mark the object `ref` when `obj` is gray. |
| 1035 | // |
| 1036 | // if (rb_state == ReadBarrier::GrayState()) |
| 1037 | // ref = ReadBarrier::Mark(ref); |
| 1038 | // |
| 1039 | // Given the numeric representation, it's enough to check the low bit of the |
| 1040 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1041 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1042 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1043 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1044 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1045 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 1046 | |
| 1047 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1048 | // Note that we cannot use IP to save the old reference, as IP is |
| 1049 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1050 | // need the old reference after the call to that entry point. |
| 1051 | DCHECK_NE(temp1_, IP); |
| 1052 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1053 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1054 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1055 | |
| 1056 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1057 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1058 | // |
| 1059 | // Note that this field could also hold a different object, if |
| 1060 | // another thread had concurrently changed it. In that case, the |
| 1061 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1062 | // (CAS) operation below would abort the CAS, leaving the field |
| 1063 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1064 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1065 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1066 | |
| 1067 | // Update the the holder's field atomically. This may fail if |
| 1068 | // mutator updates before us, but it's OK. This is achieved |
| 1069 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1070 | // memory synchronization ordering, where the expected value is |
| 1071 | // the old reference and the desired value is the new reference. |
| 1072 | |
| 1073 | // Convenience aliases. |
| 1074 | Register base = obj_; |
| 1075 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1076 | // offset ("long offset"), of which only the low part contains |
| 1077 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1078 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1079 | Register expected = temp1_; |
| 1080 | Register value = ref_reg; |
| 1081 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1082 | Register tmp = temp2_; // Value in memory. |
| 1083 | |
| 1084 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1085 | |
| 1086 | if (kPoisonHeapReferences) { |
| 1087 | __ PoisonHeapReference(expected); |
| 1088 | if (value == expected) { |
| 1089 | // Do not poison `value`, as it is the same register as |
| 1090 | // `expected`, which has just been poisoned. |
| 1091 | } else { |
| 1092 | __ PoisonHeapReference(value); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | // do { |
| 1097 | // tmp = [r_ptr] - expected; |
| 1098 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1099 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1100 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1101 | __ Bind(&loop_head); |
| 1102 | |
| 1103 | __ ldrex(tmp, tmp_ptr); |
| 1104 | |
| 1105 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1106 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1107 | __ it(NE); |
| 1108 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1109 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1110 | __ b(&exit_loop, NE); |
| 1111 | |
| 1112 | __ strex(tmp, value, tmp_ptr); |
| 1113 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1114 | __ b(&loop_head, EQ); |
| 1115 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1116 | __ Bind(&exit_loop); |
| 1117 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1118 | if (kPoisonHeapReferences) { |
| 1119 | __ UnpoisonHeapReference(expected); |
| 1120 | if (value == expected) { |
| 1121 | // Do not unpoison `value`, as it is the same register as |
| 1122 | // `expected`, which has just been unpoisoned. |
| 1123 | } else { |
| 1124 | __ UnpoisonHeapReference(value); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1128 | __ b(GetExitLabel()); |
| 1129 | } |
| 1130 | |
| 1131 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1132 | // The register containing the object holding the marked object reference field. |
| 1133 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1134 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1135 | uint32_t offset_; |
| 1136 | Location index_; |
| 1137 | ScaleFactor scale_factor_; |
| 1138 | // Is a null check required? |
| 1139 | bool needs_null_check_; |
| 1140 | // A temporary register used to hold the lock word of `obj_`; and |
| 1141 | // also to hold the original reference value, when the reference is |
| 1142 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1143 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1144 | // A temporary register used in the implementation of the CAS, to |
| 1145 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1146 | const Register temp2_; |
| 1147 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1148 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1149 | }; |
| 1150 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1151 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1152 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1153 | public: |
| 1154 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1155 | Location out, |
| 1156 | Location ref, |
| 1157 | Location obj, |
| 1158 | uint32_t offset, |
| 1159 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1160 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1161 | out_(out), |
| 1162 | ref_(ref), |
| 1163 | obj_(obj), |
| 1164 | offset_(offset), |
| 1165 | index_(index) { |
| 1166 | DCHECK(kEmitCompilerReadBarrier); |
| 1167 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1168 | // has been overwritten by (or after) the heap object reference load |
| 1169 | // to be instrumented, e.g.: |
| 1170 | // |
| 1171 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1172 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1173 | // |
| 1174 | // In that case, we have lost the information about the original |
| 1175 | // object, and the emitted read barrier cannot work properly. |
| 1176 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1177 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1178 | } |
| 1179 | |
| 1180 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1181 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1182 | LocationSummary* locations = instruction_->GetLocations(); |
| 1183 | Register reg_out = out_.AsRegister<Register>(); |
| 1184 | DCHECK(locations->CanCall()); |
| 1185 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1186 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1187 | instruction_->IsStaticFieldGet() || |
| 1188 | instruction_->IsArrayGet() || |
| 1189 | instruction_->IsInstanceOf() || |
| 1190 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1191 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1192 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1193 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1194 | // The read barrier instrumentation of object ArrayGet |
| 1195 | // instructions does not support the HIntermediateAddress |
| 1196 | // instruction. |
| 1197 | DCHECK(!(instruction_->IsArrayGet() && |
| 1198 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1199 | |
| 1200 | __ Bind(GetEntryLabel()); |
| 1201 | SaveLiveRegisters(codegen, locations); |
| 1202 | |
| 1203 | // We may have to change the index's value, but as `index_` is a |
| 1204 | // constant member (like other "inputs" of this slow path), |
| 1205 | // introduce a copy of it, `index`. |
| 1206 | Location index = index_; |
| 1207 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1208 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1209 | if (instruction_->IsArrayGet()) { |
| 1210 | // Compute the actual memory offset and store it in `index`. |
| 1211 | Register index_reg = index_.AsRegister<Register>(); |
| 1212 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1213 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1214 | // We are about to change the value of `index_reg` (see the |
| 1215 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1216 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1217 | // not been saved by the previous call to |
| 1218 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1219 | // callee-save register -- |
| 1220 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1221 | // callee-save registers, as it has been designed with the |
| 1222 | // assumption that callee-save registers are supposed to be |
| 1223 | // handled by the called function. So, as a callee-save |
| 1224 | // register, `index_reg` _would_ eventually be saved onto |
| 1225 | // the stack, but it would be too late: we would have |
| 1226 | // changed its value earlier. Therefore, we manually save |
| 1227 | // it here into another freely available register, |
| 1228 | // `free_reg`, chosen of course among the caller-save |
| 1229 | // registers (as a callee-save `free_reg` register would |
| 1230 | // exhibit the same problem). |
| 1231 | // |
| 1232 | // Note we could have requested a temporary register from |
| 1233 | // the register allocator instead; but we prefer not to, as |
| 1234 | // this is a slow path, and we know we can find a |
| 1235 | // caller-save register that is available. |
| 1236 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1237 | __ Mov(free_reg, index_reg); |
| 1238 | index_reg = free_reg; |
| 1239 | index = Location::RegisterLocation(index_reg); |
| 1240 | } else { |
| 1241 | // The initial register stored in `index_` has already been |
| 1242 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1243 | // (as it is not a callee-save register), so we can freely |
| 1244 | // use it. |
| 1245 | } |
| 1246 | // Shifting the index value contained in `index_reg` by the scale |
| 1247 | // factor (2) cannot overflow in practice, as the runtime is |
| 1248 | // unable to allocate object arrays with a size larger than |
| 1249 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1250 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1251 | static_assert( |
| 1252 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1253 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1254 | __ AddConstant(index_reg, index_reg, offset_); |
| 1255 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1256 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1257 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1258 | // (as in the case of ArrayGet), as it is actually an offset |
| 1259 | // to an object field within an object. |
| 1260 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1261 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1262 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1263 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1264 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1265 | DCHECK_EQ(offset_, 0U); |
| 1266 | DCHECK(index_.IsRegisterPair()); |
| 1267 | // UnsafeGet's offset location is a register pair, the low |
| 1268 | // part contains the correct offset. |
| 1269 | index = index_.ToLow(); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | // We're moving two or three locations to locations that could |
| 1274 | // overlap, so we need a parallel move resolver. |
| 1275 | InvokeRuntimeCallingConvention calling_convention; |
| 1276 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1277 | parallel_move.AddMove(ref_, |
| 1278 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1279 | Primitive::kPrimNot, |
| 1280 | nullptr); |
| 1281 | parallel_move.AddMove(obj_, |
| 1282 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1283 | Primitive::kPrimNot, |
| 1284 | nullptr); |
| 1285 | if (index.IsValid()) { |
| 1286 | parallel_move.AddMove(index, |
| 1287 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1288 | Primitive::kPrimInt, |
| 1289 | nullptr); |
| 1290 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1291 | } else { |
| 1292 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1293 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1294 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1295 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1296 | CheckEntrypointTypes< |
| 1297 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1298 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1299 | |
| 1300 | RestoreLiveRegisters(codegen, locations); |
| 1301 | __ b(GetExitLabel()); |
| 1302 | } |
| 1303 | |
| 1304 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1305 | |
| 1306 | private: |
| 1307 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1308 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1309 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1310 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1311 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1312 | return static_cast<Register>(i); |
| 1313 | } |
| 1314 | } |
| 1315 | // We shall never fail to find a free caller-save register, as |
| 1316 | // there are more than two core caller-save registers on ARM |
| 1317 | // (meaning it is possible to find one which is different from |
| 1318 | // `ref` and `obj`). |
| 1319 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1320 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1321 | UNREACHABLE(); |
| 1322 | } |
| 1323 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1324 | const Location out_; |
| 1325 | const Location ref_; |
| 1326 | const Location obj_; |
| 1327 | const uint32_t offset_; |
| 1328 | // An additional location containing an index to an array. |
| 1329 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1330 | // UnsafeGetObjectVolatile intrinsics. |
| 1331 | const Location index_; |
| 1332 | |
| 1333 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1334 | }; |
| 1335 | |
| 1336 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1337 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1338 | public: |
| 1339 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1340 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1341 | DCHECK(kEmitCompilerReadBarrier); |
| 1342 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1343 | |
| 1344 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1345 | LocationSummary* locations = instruction_->GetLocations(); |
| 1346 | Register reg_out = out_.AsRegister<Register>(); |
| 1347 | DCHECK(locations->CanCall()); |
| 1348 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1349 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1350 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1351 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1352 | |
| 1353 | __ Bind(GetEntryLabel()); |
| 1354 | SaveLiveRegisters(codegen, locations); |
| 1355 | |
| 1356 | InvokeRuntimeCallingConvention calling_convention; |
| 1357 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1358 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1359 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1360 | instruction_, |
| 1361 | instruction_->GetDexPc(), |
| 1362 | this); |
| 1363 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1364 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1365 | |
| 1366 | RestoreLiveRegisters(codegen, locations); |
| 1367 | __ b(GetExitLabel()); |
| 1368 | } |
| 1369 | |
| 1370 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1371 | |
| 1372 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1373 | const Location out_; |
| 1374 | const Location root_; |
| 1375 | |
| 1376 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1377 | }; |
| 1378 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1379 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1380 | switch (cond) { |
| 1381 | case kCondEQ: return EQ; |
| 1382 | case kCondNE: return NE; |
| 1383 | case kCondLT: return LT; |
| 1384 | case kCondLE: return LE; |
| 1385 | case kCondGT: return GT; |
| 1386 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1387 | case kCondB: return LO; |
| 1388 | case kCondBE: return LS; |
| 1389 | case kCondA: return HI; |
| 1390 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1391 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1392 | LOG(FATAL) << "Unreachable"; |
| 1393 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1396 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1397 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1398 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1399 | case kCondEQ: return EQ; |
| 1400 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1401 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | case kCondLT: return LO; |
| 1403 | case kCondLE: return LS; |
| 1404 | case kCondGT: return HI; |
| 1405 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1406 | // Unsigned remain unchanged. |
| 1407 | case kCondB: return LO; |
| 1408 | case kCondBE: return LS; |
| 1409 | case kCondA: return HI; |
| 1410 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1411 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | LOG(FATAL) << "Unreachable"; |
| 1413 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1416 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1417 | // The ARM condition codes can express all the necessary branches, see the |
| 1418 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1419 | // There is no dex instruction or HIR that would need the missing conditions |
| 1420 | // "equal or unordered" or "not equal". |
| 1421 | switch (cond) { |
| 1422 | case kCondEQ: return EQ; |
| 1423 | case kCondNE: return NE /* unordered */; |
| 1424 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1425 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1426 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1427 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1428 | default: |
| 1429 | LOG(FATAL) << "UNREACHABLE"; |
| 1430 | UNREACHABLE(); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1434 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1435 | switch (op_kind) { |
| 1436 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1437 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1438 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1439 | default: |
| 1440 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1441 | UNREACHABLE(); |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1446 | Register out, |
| 1447 | Register first, |
| 1448 | const ShifterOperand& second, |
| 1449 | CodeGeneratorARM* codegen) { |
| 1450 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1451 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1452 | ? ShifterOperand(0) |
| 1453 | : ShifterOperand(first); |
| 1454 | |
| 1455 | __ mov(out, in); |
| 1456 | } else { |
| 1457 | switch (kind) { |
| 1458 | case HInstruction::kAdd: |
| 1459 | __ add(out, first, second); |
| 1460 | break; |
| 1461 | case HInstruction::kAnd: |
| 1462 | __ and_(out, first, second); |
| 1463 | break; |
| 1464 | case HInstruction::kOr: |
| 1465 | __ orr(out, first, second); |
| 1466 | break; |
| 1467 | case HInstruction::kSub: |
| 1468 | __ sub(out, first, second); |
| 1469 | break; |
| 1470 | case HInstruction::kXor: |
| 1471 | __ eor(out, first, second); |
| 1472 | break; |
| 1473 | default: |
| 1474 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1475 | UNREACHABLE(); |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1481 | const Location& out, |
| 1482 | const Location& first, |
| 1483 | const ShifterOperand& second_lo, |
| 1484 | const ShifterOperand& second_hi, |
| 1485 | CodeGeneratorARM* codegen) { |
| 1486 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1487 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1488 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1489 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1490 | |
| 1491 | if (kind == HInstruction::kAdd) { |
| 1492 | __ adds(out_lo, first_lo, second_lo); |
| 1493 | __ adc(out_hi, first_hi, second_hi); |
| 1494 | } else if (kind == HInstruction::kSub) { |
| 1495 | __ subs(out_lo, first_lo, second_lo); |
| 1496 | __ sbc(out_hi, first_hi, second_hi); |
| 1497 | } else { |
| 1498 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1499 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1504 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1505 | } |
| 1506 | |
| 1507 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1508 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1509 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1510 | |
| 1511 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1512 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1513 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1514 | const Location first = locations->InAt(0); |
| 1515 | const Location second = locations->InAt(1); |
| 1516 | const Location out = locations->Out(); |
| 1517 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1518 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1519 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1520 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1521 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1522 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1523 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1524 | |
| 1525 | if (shift_value >= 32) { |
| 1526 | if (shift == LSL) { |
| 1527 | GenerateDataProcInstruction(kind, |
| 1528 | out_hi, |
| 1529 | first_hi, |
| 1530 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1531 | codegen); |
| 1532 | GenerateDataProcInstruction(kind, |
| 1533 | out_lo, |
| 1534 | first_lo, |
| 1535 | ShifterOperand(0), |
| 1536 | codegen); |
| 1537 | } else if (shift == ASR) { |
| 1538 | GenerateDataProc(kind, |
| 1539 | out, |
| 1540 | first, |
| 1541 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1542 | ShifterOperand(second_hi, ASR, 31), |
| 1543 | codegen); |
| 1544 | } else { |
| 1545 | DCHECK_EQ(shift, LSR); |
| 1546 | GenerateDataProc(kind, |
| 1547 | out, |
| 1548 | first, |
| 1549 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1550 | ShifterOperand(0), |
| 1551 | codegen); |
| 1552 | } |
| 1553 | } else { |
| 1554 | DCHECK_GT(shift_value, 1U); |
| 1555 | DCHECK_LT(shift_value, 32U); |
| 1556 | |
| 1557 | if (shift == LSL) { |
| 1558 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1559 | // Location::kOutputOverlap; not applicable to other cases. |
| 1560 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1561 | GenerateDataProcInstruction(kind, |
| 1562 | out_hi, |
| 1563 | first_hi, |
| 1564 | ShifterOperand(second_hi, LSL, shift_value), |
| 1565 | codegen); |
| 1566 | GenerateDataProcInstruction(kind, |
| 1567 | out_hi, |
| 1568 | out_hi, |
| 1569 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1570 | codegen); |
| 1571 | GenerateDataProcInstruction(kind, |
| 1572 | out_lo, |
| 1573 | first_lo, |
| 1574 | ShifterOperand(second_lo, LSL, shift_value), |
| 1575 | codegen); |
| 1576 | } else { |
| 1577 | __ Lsl(IP, second_hi, shift_value); |
| 1578 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1579 | GenerateDataProc(kind, |
| 1580 | out, |
| 1581 | first, |
| 1582 | ShifterOperand(second_lo, LSL, shift_value), |
| 1583 | ShifterOperand(IP), |
| 1584 | codegen); |
| 1585 | } |
| 1586 | } else { |
| 1587 | DCHECK(shift == ASR || shift == LSR); |
| 1588 | |
| 1589 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1590 | // Location::kOutputOverlap; not applicable to other cases. |
| 1591 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1592 | GenerateDataProcInstruction(kind, |
| 1593 | out_lo, |
| 1594 | first_lo, |
| 1595 | ShifterOperand(second_lo, LSR, shift_value), |
| 1596 | codegen); |
| 1597 | GenerateDataProcInstruction(kind, |
| 1598 | out_lo, |
| 1599 | out_lo, |
| 1600 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1601 | codegen); |
| 1602 | GenerateDataProcInstruction(kind, |
| 1603 | out_hi, |
| 1604 | first_hi, |
| 1605 | ShifterOperand(second_hi, shift, shift_value), |
| 1606 | codegen); |
| 1607 | } else { |
| 1608 | __ Lsr(IP, second_lo, shift_value); |
| 1609 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1610 | GenerateDataProc(kind, |
| 1611 | out, |
| 1612 | first, |
| 1613 | ShifterOperand(IP), |
| 1614 | ShifterOperand(second_hi, shift, shift_value), |
| 1615 | codegen); |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1621 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1622 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1623 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1624 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1625 | if (rhs_loc.IsConstant()) { |
| 1626 | // 0.0 is the only immediate that can be encoded directly in |
| 1627 | // a VCMP instruction. |
| 1628 | // |
| 1629 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1630 | // specify that in a floating-point comparison, positive zero |
| 1631 | // and negative zero are considered equal, so we can use the |
| 1632 | // literal 0.0 for both cases here. |
| 1633 | // |
| 1634 | // Note however that some methods (Float.equal, Float.compare, |
| 1635 | // Float.compareTo, Double.equal, Double.compare, |
| 1636 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1637 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1638 | // -0.0. So if we ever translate calls to these methods into a |
| 1639 | // HCompare instruction, we must handle the -0.0 case with |
| 1640 | // care here. |
| 1641 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1642 | if (type == Primitive::kPrimFloat) { |
| 1643 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1644 | } else { |
| 1645 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1646 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1647 | } |
| 1648 | } else { |
| 1649 | if (type == Primitive::kPrimFloat) { |
| 1650 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1651 | } else { |
| 1652 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1653 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1654 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1659 | static std::pair<Condition, Condition> GenerateLongTestConstant(HCondition* condition, |
| 1660 | bool invert, |
| 1661 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1662 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1663 | |
| 1664 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1665 | IfCondition cond = condition->GetCondition(); |
| 1666 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1667 | |
| 1668 | if (invert) { |
| 1669 | std::swap(cond, opposite); |
| 1670 | } |
| 1671 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 1672 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1673 | const Location left = locations->InAt(0); |
| 1674 | const Location right = locations->InAt(1); |
| 1675 | |
| 1676 | DCHECK(right.IsConstant()); |
| 1677 | |
| 1678 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1679 | const Register left_low = left.AsRegisterPairLow<Register>(); |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 1680 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1681 | |
| 1682 | switch (cond) { |
| 1683 | case kCondEQ: |
| 1684 | case kCondNE: |
| 1685 | case kCondB: |
| 1686 | case kCondBE: |
| 1687 | case kCondA: |
| 1688 | case kCondAE: |
| 1689 | __ CmpConstant(left_high, High32Bits(value)); |
| 1690 | __ it(EQ); |
| 1691 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1692 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1693 | break; |
| 1694 | case kCondLE: |
| 1695 | case kCondGT: |
| 1696 | // Trivially true or false. |
| 1697 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1698 | __ cmp(left_low, ShifterOperand(left_low)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1699 | 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] | 1700 | break; |
| 1701 | } |
| 1702 | |
| 1703 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1704 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1705 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1706 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1707 | } else { |
| 1708 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1709 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1710 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1711 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | value++; |
| 1715 | FALLTHROUGH_INTENDED; |
| 1716 | case kCondGE: |
| 1717 | case kCondLT: |
| 1718 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1719 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1720 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1721 | break; |
| 1722 | default: |
| 1723 | LOG(FATAL) << "Unreachable"; |
| 1724 | UNREACHABLE(); |
| 1725 | } |
| 1726 | |
| 1727 | return ret; |
| 1728 | } |
| 1729 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1730 | static std::pair<Condition, Condition> GenerateLongTest(HCondition* condition, |
| 1731 | bool invert, |
| 1732 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1733 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1734 | |
| 1735 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1736 | IfCondition cond = condition->GetCondition(); |
| 1737 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1738 | |
| 1739 | if (invert) { |
| 1740 | std::swap(cond, opposite); |
| 1741 | } |
| 1742 | |
| 1743 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1744 | Location left = locations->InAt(0); |
| 1745 | Location right = locations->InAt(1); |
| 1746 | |
| 1747 | DCHECK(right.IsRegisterPair()); |
| 1748 | |
| 1749 | switch (cond) { |
| 1750 | case kCondEQ: |
| 1751 | case kCondNE: |
| 1752 | case kCondB: |
| 1753 | case kCondBE: |
| 1754 | case kCondA: |
| 1755 | case kCondAE: |
| 1756 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1757 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1758 | __ it(EQ); |
| 1759 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1760 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1761 | EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1762 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1763 | break; |
| 1764 | case kCondLE: |
| 1765 | case kCondGT: |
| 1766 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1767 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1768 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1769 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1770 | } else { |
| 1771 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1772 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1773 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1774 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | std::swap(left, right); |
| 1778 | FALLTHROUGH_INTENDED; |
| 1779 | case kCondGE: |
| 1780 | case kCondLT: |
| 1781 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1782 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1783 | __ sbcs(IP, |
| 1784 | left.AsRegisterPairHigh<Register>(), |
| 1785 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1786 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1787 | break; |
| 1788 | default: |
| 1789 | LOG(FATAL) << "Unreachable"; |
| 1790 | UNREACHABLE(); |
| 1791 | } |
| 1792 | |
| 1793 | return ret; |
| 1794 | } |
| 1795 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1796 | static std::pair<Condition, Condition> GenerateTest(HCondition* condition, |
| 1797 | bool invert, |
| 1798 | CodeGeneratorARM* codegen) { |
| 1799 | const LocationSummary* const locations = condition->GetLocations(); |
| 1800 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1801 | IfCondition cond = condition->GetCondition(); |
| 1802 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1803 | std::pair<Condition, Condition> ret; |
| 1804 | const Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1805 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1806 | if (invert) { |
| 1807 | std::swap(cond, opposite); |
| 1808 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1809 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1810 | if (type == Primitive::kPrimLong) { |
| 1811 | ret = locations->InAt(1).IsConstant() |
| 1812 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1813 | : GenerateLongTest(condition, invert, codegen); |
| 1814 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1815 | GenerateVcmp(condition, codegen); |
| 1816 | __ vmstat(); |
| 1817 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1818 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1819 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1820 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1821 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1822 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1823 | |
| 1824 | if (right.IsRegister()) { |
| 1825 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1826 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1827 | DCHECK(right.IsConstant()); |
| 1828 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1829 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1830 | |
| 1831 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | return ret; |
| 1835 | } |
| 1836 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1837 | static bool CanGenerateTest(HCondition* condition, ArmAssembler* assembler) { |
| 1838 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1839 | const LocationSummary* const locations = condition->GetLocations(); |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 1840 | const IfCondition c = condition->GetCondition(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1841 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1842 | if (locations->InAt(1).IsConstant()) { |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 1843 | const int64_t value = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1844 | ShifterOperand so; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1845 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1846 | if (c < kCondLT || c > kCondGE) { |
| 1847 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1848 | // we check that the least significant half of the first input to be compared |
| 1849 | // is in a low register (the other half is read outside an IT block), and |
| 1850 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 1851 | // encoding can be used. |
| 1852 | if (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1853 | !IsUint<8>(Low32Bits(value))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1856 | } else if (c == kCondLE || c == kCondGT) { |
| 1857 | if (value < std::numeric_limits<int64_t>::max() && |
| 1858 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1859 | kNoRegister, |
| 1860 | SBC, |
| 1861 | High32Bits(value + 1), |
| 1862 | kCcSet, |
| 1863 | &so)) { |
| 1864 | return false; |
| 1865 | } |
| 1866 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1867 | kNoRegister, |
| 1868 | SBC, |
| 1869 | High32Bits(value), |
| 1870 | kCcSet, |
| 1871 | &so)) { |
| 1872 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | return true; |
| 1878 | } |
| 1879 | |
| 1880 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1881 | const Primitive::Type type = constant->GetType(); |
| 1882 | bool ret = false; |
| 1883 | |
| 1884 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1885 | |
| 1886 | if (type == Primitive::kPrimLong) { |
| 1887 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 1888 | |
| 1889 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1890 | } else { |
| 1891 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 1892 | } |
| 1893 | |
| 1894 | return ret; |
| 1895 | } |
| 1896 | |
| 1897 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1898 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1899 | |
| 1900 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1901 | return Location::ConstantLocation(constant->AsConstant()); |
| 1902 | } |
| 1903 | |
| 1904 | return Location::RequiresRegister(); |
| 1905 | } |
| 1906 | |
| 1907 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1908 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1909 | // we check that we are not dealing with floating-point output (there is no |
| 1910 | // 16-bit VMOV encoding). |
| 1911 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1912 | return false; |
| 1913 | } |
| 1914 | |
| 1915 | // For constants, we also check that the output is in one or two low registers, |
| 1916 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1917 | // MOV encoding can be used. |
| 1918 | if (src.IsConstant()) { |
| 1919 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1920 | return false; |
| 1921 | } |
| 1922 | |
| 1923 | if (out.IsRegister()) { |
| 1924 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 1925 | return false; |
| 1926 | } |
| 1927 | } else { |
| 1928 | DCHECK(out.IsRegisterPair()); |
| 1929 | |
| 1930 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 1931 | return false; |
| 1932 | } |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | return true; |
| 1937 | } |
| 1938 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1939 | #undef __ |
| 1940 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1941 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1942 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1943 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 1944 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1945 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1946 | |
| 1947 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1948 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1949 | HInstruction* const next = instruction->GetNext(); |
| 1950 | |
| 1951 | // Avoid a branch to a branch. |
| 1952 | if (next->IsGoto() && (info == nullptr || |
| 1953 | !info->IsBackEdge(*block) || |
| 1954 | !info->HasSuspendCheck())) { |
| 1955 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1956 | } |
| 1957 | |
| 1958 | return final_label; |
| 1959 | } |
| 1960 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1961 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1962 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1966 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1969 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1970 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1971 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1972 | } |
| 1973 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1974 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1975 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1976 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1977 | } |
| 1978 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1979 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1980 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1981 | return kArmWordSize; |
| 1982 | } |
| 1983 | |
| 1984 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1985 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1986 | return kArmWordSize; |
| 1987 | } |
| 1988 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1989 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1990 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1991 | const CompilerOptions& compiler_options, |
| 1992 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1993 | : CodeGenerator(graph, |
| 1994 | kNumberOfCoreRegisters, |
| 1995 | kNumberOfSRegisters, |
| 1996 | kNumberOfRegisterPairs, |
| 1997 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1998 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1999 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 2000 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 2001 | compiler_options, |
| 2002 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 2003 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2004 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2005 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 2006 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 2007 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2008 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2009 | uint32_literals_(std::less<uint32_t>(), |
| 2010 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2011 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2012 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 2013 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2014 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2015 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 2016 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 2017 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2018 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2019 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2020 | // Always save the LR register to mimic Quick. |
| 2021 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 2022 | } |
| 2023 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2024 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 2025 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 2026 | __ FinalizeCode(); |
| 2027 | |
| 2028 | // Adjust native pc offsets in stack maps. |
| 2029 | 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] | 2030 | uint32_t old_position = |
| 2031 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2032 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 2033 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 2034 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 2035 | // Adjust pc offsets for the disassembly information. |
| 2036 | if (disasm_info_ != nullptr) { |
| 2037 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 2038 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 2039 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 2040 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 2041 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 2042 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 2043 | } |
| 2044 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 2045 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 2046 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 2047 | } |
| 2048 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2049 | |
| 2050 | CodeGenerator::Finalize(allocator); |
| 2051 | } |
| 2052 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2053 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2054 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2055 | blocked_core_registers_[SP] = true; |
| 2056 | blocked_core_registers_[LR] = true; |
| 2057 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2058 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2059 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2060 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2061 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2062 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2063 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2064 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2065 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2066 | // Stubs do not save callee-save floating point registers. If the graph |
| 2067 | // is debuggable, we need to deal with these registers differently. For |
| 2068 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2069 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2070 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2071 | } |
| 2072 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2073 | } |
| 2074 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2075 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2076 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2077 | assembler_(codegen->GetAssembler()), |
| 2078 | codegen_(codegen) {} |
| 2079 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2080 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2081 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2082 | 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] | 2083 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2084 | // restore another arbitrary register. |
| 2085 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2086 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2087 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2088 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2089 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2090 | // but in the range. |
| 2091 | if (fpu_spill_mask_ != 0) { |
| 2092 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2093 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2094 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2095 | fpu_spill_mask_ |= (1 << i); |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2100 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2101 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2105 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2108 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2109 | bool skip_overflow_check = |
| 2110 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2111 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2112 | __ Bind(&frame_entry_label_); |
| 2113 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2114 | if (HasEmptyFrame()) { |
| 2115 | return; |
| 2116 | } |
| 2117 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2118 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2119 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2120 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2121 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2122 | } |
| 2123 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2124 | __ PushList(core_spill_mask_); |
| 2125 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2126 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2127 | if (fpu_spill_mask_ != 0) { |
| 2128 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2129 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2130 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2131 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2132 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2133 | |
| 2134 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2135 | // Initialize should_deoptimize flag to 0. |
| 2136 | __ mov(IP, ShifterOperand(0)); |
| 2137 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2138 | } |
| 2139 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2140 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2141 | __ AddConstant(SP, -adjust); |
| 2142 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2143 | |
| 2144 | // Save the current method if we need it. Note that we do not |
| 2145 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2146 | // in the SSA graph. |
| 2147 | if (RequiresCurrentMethod()) { |
| 2148 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2149 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2153 | if (HasEmptyFrame()) { |
| 2154 | __ bx(LR); |
| 2155 | return; |
| 2156 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2157 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2158 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2159 | __ AddConstant(SP, adjust); |
| 2160 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2161 | if (fpu_spill_mask_ != 0) { |
| 2162 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2163 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2164 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2165 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2166 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2167 | // Pop LR into PC to return. |
| 2168 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2169 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2170 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2171 | __ cfi().RestoreState(); |
| 2172 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2175 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2176 | Label* label = GetLabelOf(block); |
| 2177 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2180 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2181 | switch (type) { |
| 2182 | case Primitive::kPrimBoolean: |
| 2183 | case Primitive::kPrimByte: |
| 2184 | case Primitive::kPrimChar: |
| 2185 | case Primitive::kPrimShort: |
| 2186 | case Primitive::kPrimInt: |
| 2187 | case Primitive::kPrimNot: { |
| 2188 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2189 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2190 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2191 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2192 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2193 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2194 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2195 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2196 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2197 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2198 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2199 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2200 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2201 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2202 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2203 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2204 | // Skip R1, and use R2_R3 instead. |
| 2205 | gp_index_++; |
| 2206 | index++; |
| 2207 | } |
| 2208 | } |
| 2209 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2210 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2211 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2212 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2213 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2214 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2215 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2216 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | case Primitive::kPrimFloat: { |
| 2221 | uint32_t stack_index = stack_index_++; |
| 2222 | if (float_index_ % 2 == 0) { |
| 2223 | float_index_ = std::max(double_index_, float_index_); |
| 2224 | } |
| 2225 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2226 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2227 | } else { |
| 2228 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | case Primitive::kPrimDouble: { |
| 2233 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2234 | uint32_t stack_index = stack_index_; |
| 2235 | stack_index_ += 2; |
| 2236 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2237 | uint32_t index = double_index_; |
| 2238 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2239 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2240 | calling_convention.GetFpuRegisterAt(index), |
| 2241 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2242 | DCHECK(ExpectedPairLayout(result)); |
| 2243 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2244 | } else { |
| 2245 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2246 | } |
| 2247 | } |
| 2248 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2249 | case Primitive::kPrimVoid: |
| 2250 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2251 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2252 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2253 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2254 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2255 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2256 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2257 | switch (type) { |
| 2258 | case Primitive::kPrimBoolean: |
| 2259 | case Primitive::kPrimByte: |
| 2260 | case Primitive::kPrimChar: |
| 2261 | case Primitive::kPrimShort: |
| 2262 | case Primitive::kPrimInt: |
| 2263 | case Primitive::kPrimNot: { |
| 2264 | return Location::RegisterLocation(R0); |
| 2265 | } |
| 2266 | |
| 2267 | case Primitive::kPrimFloat: { |
| 2268 | return Location::FpuRegisterLocation(S0); |
| 2269 | } |
| 2270 | |
| 2271 | case Primitive::kPrimLong: { |
| 2272 | return Location::RegisterPairLocation(R0, R1); |
| 2273 | } |
| 2274 | |
| 2275 | case Primitive::kPrimDouble: { |
| 2276 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2277 | } |
| 2278 | |
| 2279 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2280 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2281 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2282 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2283 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2286 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2287 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2288 | } |
| 2289 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2290 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2291 | if (source.Equals(destination)) { |
| 2292 | return; |
| 2293 | } |
| 2294 | if (destination.IsRegister()) { |
| 2295 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2296 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
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 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2299 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2300 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2301 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2302 | } else if (destination.IsFpuRegister()) { |
| 2303 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2304 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2305 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2306 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2307 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2308 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2310 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2311 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2312 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2313 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2314 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2315 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2316 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2317 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2318 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2319 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2325 | if (source.Equals(destination)) { |
| 2326 | return; |
| 2327 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2328 | if (destination.IsRegisterPair()) { |
| 2329 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2330 | EmitParallelMoves( |
| 2331 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2332 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2333 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2334 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2335 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2336 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2337 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2338 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2339 | } else if (source.IsFpuRegisterPair()) { |
| 2340 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2341 | destination.AsRegisterPairHigh<Register>(), |
| 2342 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2343 | } else { |
| 2344 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2345 | DCHECK(ExpectedPairLayout(destination)); |
| 2346 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2347 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2348 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2349 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2350 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2351 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2352 | SP, |
| 2353 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2354 | } else if (source.IsRegisterPair()) { |
| 2355 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2356 | source.AsRegisterPairLow<Register>(), |
| 2357 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2358 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2359 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2360 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2361 | } else { |
| 2362 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2363 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2364 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2365 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2366 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2367 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2368 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2369 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2370 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2371 | SP, destination.GetStackIndex()); |
| 2372 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2373 | } else if (source.IsFpuRegisterPair()) { |
| 2374 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2375 | SP, |
| 2376 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2377 | } else { |
| 2378 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2379 | EmitParallelMoves( |
| 2380 | Location::StackSlot(source.GetStackIndex()), |
| 2381 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2382 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2383 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2384 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2385 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2390 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2391 | DCHECK(location.IsRegister()); |
| 2392 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2393 | } |
| 2394 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2395 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2396 | HParallelMove move(GetGraph()->GetArena()); |
| 2397 | move.AddMove(src, dst, dst_type, nullptr); |
| 2398 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2402 | if (location.IsRegister()) { |
| 2403 | locations->AddTemp(location); |
| 2404 | } else if (location.IsRegisterPair()) { |
| 2405 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2406 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2407 | } else { |
| 2408 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2409 | } |
| 2410 | } |
| 2411 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2412 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2413 | HInstruction* instruction, |
| 2414 | uint32_t dex_pc, |
| 2415 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2416 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2417 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2418 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2419 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2420 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2423 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2424 | HInstruction* instruction, |
| 2425 | SlowPathCode* slow_path) { |
| 2426 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2427 | GenerateInvokeRuntime(entry_point_offset); |
| 2428 | } |
| 2429 | |
| 2430 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2431 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2432 | __ blx(LR); |
| 2433 | } |
| 2434 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2435 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2436 | DCHECK(!successor->IsExitBlock()); |
| 2437 | |
| 2438 | HBasicBlock* block = got->GetBlock(); |
| 2439 | HInstruction* previous = got->GetPrevious(); |
| 2440 | |
| 2441 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2442 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2443 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2444 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2445 | return; |
| 2446 | } |
| 2447 | |
| 2448 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2449 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2450 | } |
| 2451 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2452 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2456 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2457 | got->SetLocations(nullptr); |
| 2458 | } |
| 2459 | |
| 2460 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2461 | HandleGoto(got, got->GetSuccessor()); |
| 2462 | } |
| 2463 | |
| 2464 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2465 | try_boundary->SetLocations(nullptr); |
| 2466 | } |
| 2467 | |
| 2468 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2469 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2470 | if (!successor->IsExitBlock()) { |
| 2471 | HandleGoto(try_boundary, successor); |
| 2472 | } |
| 2473 | } |
| 2474 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2475 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2476 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2479 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2482 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2483 | Label* true_label, |
| 2484 | Label* false_label) { |
| 2485 | LocationSummary* locations = cond->GetLocations(); |
| 2486 | Location left = locations->InAt(0); |
| 2487 | Location right = locations->InAt(1); |
| 2488 | IfCondition if_cond = cond->GetCondition(); |
| 2489 | |
| 2490 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2491 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2492 | IfCondition true_high_cond = if_cond; |
| 2493 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2494 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2495 | |
| 2496 | // Set the conditions for the test, remembering that == needs to be |
| 2497 | // decided using the low words. |
| 2498 | switch (if_cond) { |
| 2499 | case kCondEQ: |
| 2500 | case kCondNE: |
| 2501 | // Nothing to do. |
| 2502 | break; |
| 2503 | case kCondLT: |
| 2504 | false_high_cond = kCondGT; |
| 2505 | break; |
| 2506 | case kCondLE: |
| 2507 | true_high_cond = kCondLT; |
| 2508 | break; |
| 2509 | case kCondGT: |
| 2510 | false_high_cond = kCondLT; |
| 2511 | break; |
| 2512 | case kCondGE: |
| 2513 | true_high_cond = kCondGT; |
| 2514 | break; |
| 2515 | case kCondB: |
| 2516 | false_high_cond = kCondA; |
| 2517 | break; |
| 2518 | case kCondBE: |
| 2519 | true_high_cond = kCondB; |
| 2520 | break; |
| 2521 | case kCondA: |
| 2522 | false_high_cond = kCondB; |
| 2523 | break; |
| 2524 | case kCondAE: |
| 2525 | true_high_cond = kCondA; |
| 2526 | break; |
| 2527 | } |
| 2528 | if (right.IsConstant()) { |
| 2529 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2530 | int32_t val_low = Low32Bits(value); |
| 2531 | int32_t val_high = High32Bits(value); |
| 2532 | |
| 2533 | __ CmpConstant(left_high, val_high); |
| 2534 | if (if_cond == kCondNE) { |
| 2535 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2536 | } else if (if_cond == kCondEQ) { |
| 2537 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2538 | } else { |
| 2539 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2540 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2541 | } |
| 2542 | // Must be equal high, so compare the lows. |
| 2543 | __ CmpConstant(left_low, val_low); |
| 2544 | } else { |
| 2545 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2546 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2547 | |
| 2548 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2549 | if (if_cond == kCondNE) { |
| 2550 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2551 | } else if (if_cond == kCondEQ) { |
| 2552 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2553 | } else { |
| 2554 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2555 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2556 | } |
| 2557 | // Must be equal high, so compare the lows. |
| 2558 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2559 | } |
| 2560 | // The last comparison might be unsigned. |
| 2561 | // TODO: optimize cases where this is always true/false |
| 2562 | __ b(true_label, final_condition); |
| 2563 | } |
| 2564 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2565 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2566 | Label* true_target_in, |
| 2567 | Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2568 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2569 | Label* non_fallthrough_target; |
| 2570 | bool invert; |
| 2571 | |
| 2572 | if (true_target_in == nullptr) { |
| 2573 | DCHECK(false_target_in != nullptr); |
| 2574 | non_fallthrough_target = false_target_in; |
| 2575 | invert = true; |
| 2576 | } else { |
| 2577 | non_fallthrough_target = true_target_in; |
| 2578 | invert = false; |
| 2579 | } |
| 2580 | |
| 2581 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2582 | |
| 2583 | __ b(non_fallthrough_target, cond.first); |
| 2584 | |
| 2585 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2586 | __ b(false_target_in); |
| 2587 | } |
| 2588 | |
| 2589 | return; |
| 2590 | } |
| 2591 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2592 | // Generated branching requires both targets to be explicit. If either of the |
| 2593 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2594 | Label fallthrough_target; |
| 2595 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2596 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2597 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2598 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2599 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2600 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2601 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2602 | __ b(false_target); |
| 2603 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2604 | |
| 2605 | if (fallthrough_target.IsLinked()) { |
| 2606 | __ Bind(&fallthrough_target); |
| 2607 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2608 | } |
| 2609 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2610 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2611 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2612 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2613 | Label* false_target) { |
| 2614 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2615 | |
| 2616 | if (true_target == nullptr && false_target == nullptr) { |
| 2617 | // Nothing to do. The code always falls through. |
| 2618 | return; |
| 2619 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2620 | // Constant condition, statically compared against "true" (integer value 1). |
| 2621 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2622 | if (true_target != nullptr) { |
| 2623 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2624 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2625 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2626 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2627 | if (false_target != nullptr) { |
| 2628 | __ b(false_target); |
| 2629 | } |
| 2630 | } |
| 2631 | return; |
| 2632 | } |
| 2633 | |
| 2634 | // The following code generates these patterns: |
| 2635 | // (1) true_target == nullptr && false_target != nullptr |
| 2636 | // - opposite condition true => branch to false_target |
| 2637 | // (2) true_target != nullptr && false_target == nullptr |
| 2638 | // - condition true => branch to true_target |
| 2639 | // (3) true_target != nullptr && false_target != nullptr |
| 2640 | // - condition true => branch to true_target |
| 2641 | // - branch to false_target |
| 2642 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2643 | // Condition has been materialized, compare the output to 0. |
| 2644 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2645 | DCHECK(cond_val.IsRegister()); |
| 2646 | if (true_target == nullptr) { |
| 2647 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2648 | } else { |
| 2649 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2650 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2651 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2652 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2653 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2654 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2655 | |
| 2656 | // If this is a long or FP comparison that has been folded into |
| 2657 | // the HCondition, generate the comparison directly. |
| 2658 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2659 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2660 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2661 | return; |
| 2662 | } |
| 2663 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2664 | Label* non_fallthrough_target; |
| 2665 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2666 | LocationSummary* locations = cond->GetLocations(); |
| 2667 | DCHECK(locations->InAt(0).IsRegister()); |
| 2668 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2669 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2670 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2671 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2672 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2673 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2674 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2675 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2676 | non_fallthrough_target = true_target; |
| 2677 | } |
| 2678 | |
| 2679 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2680 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2681 | if (arm_cond == EQ) { |
| 2682 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2683 | } else { |
| 2684 | DCHECK_EQ(arm_cond, NE); |
| 2685 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2686 | } |
| 2687 | } else { |
| 2688 | if (right.IsRegister()) { |
| 2689 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2690 | } else { |
| 2691 | DCHECK(right.IsConstant()); |
| 2692 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2693 | } |
| 2694 | |
| 2695 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2696 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2697 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2698 | |
| 2699 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2700 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2701 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2702 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2706 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2707 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2708 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2714 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2715 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2716 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2717 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2718 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2719 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2720 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2724 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2725 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2726 | InvokeRuntimeCallingConvention calling_convention; |
| 2727 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2728 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2729 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2730 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2736 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2737 | GenerateTestAndBranch(deoptimize, |
| 2738 | /* condition_input_index */ 0, |
| 2739 | slow_path->GetEntryLabel(), |
| 2740 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2741 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2742 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2743 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2744 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2745 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2746 | locations->SetOut(Location::RequiresRegister()); |
| 2747 | } |
| 2748 | |
| 2749 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2750 | __ LoadFromOffset(kLoadWord, |
| 2751 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2752 | SP, |
| 2753 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2754 | } |
| 2755 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2756 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2757 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2758 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2759 | |
| 2760 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2761 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2762 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2763 | } else { |
| 2764 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2765 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2766 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2767 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2768 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2769 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2770 | // The code generator handles overlap with the values, but not with the condition. |
| 2771 | locations->SetOut(Location::SameAsFirstInput()); |
| 2772 | } else if (is_floating_point) { |
| 2773 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2774 | } else { |
| 2775 | if (!locations->InAt(1).IsConstant()) { |
| 2776 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2777 | } |
| 2778 | |
| 2779 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2780 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2784 | HInstruction* const condition = select->GetCondition(); |
| 2785 | const LocationSummary* const locations = select->GetLocations(); |
| 2786 | const Primitive::Type type = select->GetType(); |
| 2787 | const Location first = locations->InAt(0); |
| 2788 | const Location out = locations->Out(); |
| 2789 | const Location second = locations->InAt(1); |
| 2790 | Location src; |
| 2791 | |
| 2792 | if (condition->IsIntConstant()) { |
| 2793 | if (condition->AsIntConstant()->IsFalse()) { |
| 2794 | src = first; |
| 2795 | } else { |
| 2796 | src = second; |
| 2797 | } |
| 2798 | |
| 2799 | codegen_->MoveLocation(out, src, type); |
| 2800 | return; |
| 2801 | } |
| 2802 | |
| 2803 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2804 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 2805 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2806 | bool invert = false; |
| 2807 | |
| 2808 | if (out.Equals(second)) { |
| 2809 | src = first; |
| 2810 | invert = true; |
| 2811 | } else if (out.Equals(first)) { |
| 2812 | src = second; |
| 2813 | } else if (second.IsConstant()) { |
| 2814 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2815 | src = second; |
| 2816 | } else if (first.IsConstant()) { |
| 2817 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2818 | src = first; |
| 2819 | invert = true; |
| 2820 | } else { |
| 2821 | src = second; |
| 2822 | } |
| 2823 | |
| 2824 | if (CanGenerateConditionalMove(out, src)) { |
| 2825 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2826 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2827 | } |
| 2828 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2829 | std::pair<Condition, Condition> cond; |
| 2830 | |
| 2831 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2832 | __ CmpConstant(locations->InAt(2).AsRegister<Register>(), 0); |
| 2833 | cond = invert ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
| 2834 | } else { |
| 2835 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2836 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2837 | |
| 2838 | if (out.IsRegister()) { |
| 2839 | ShifterOperand operand; |
| 2840 | |
| 2841 | if (src.IsConstant()) { |
| 2842 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 2843 | } else { |
| 2844 | DCHECK(src.IsRegister()); |
| 2845 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 2846 | } |
| 2847 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2848 | __ it(cond.first); |
| 2849 | __ mov(out.AsRegister<Register>(), operand, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2850 | } else { |
| 2851 | DCHECK(out.IsRegisterPair()); |
| 2852 | |
| 2853 | ShifterOperand operand_high; |
| 2854 | ShifterOperand operand_low; |
| 2855 | |
| 2856 | if (src.IsConstant()) { |
| 2857 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 2858 | |
| 2859 | operand_high = ShifterOperand(High32Bits(value)); |
| 2860 | operand_low = ShifterOperand(Low32Bits(value)); |
| 2861 | } else { |
| 2862 | DCHECK(src.IsRegisterPair()); |
| 2863 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 2864 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 2865 | } |
| 2866 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2867 | __ it(cond.first); |
| 2868 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond.first); |
| 2869 | __ it(cond.first); |
| 2870 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | return; |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | Label* false_target = nullptr; |
| 2878 | Label* true_target = nullptr; |
| 2879 | Label select_end; |
| 2880 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 2881 | |
| 2882 | if (out.Equals(second)) { |
| 2883 | true_target = target; |
| 2884 | src = first; |
| 2885 | } else { |
| 2886 | false_target = target; |
| 2887 | src = second; |
| 2888 | |
| 2889 | if (!out.Equals(first)) { |
| 2890 | codegen_->MoveLocation(out, first, type); |
| 2891 | } |
| 2892 | } |
| 2893 | |
| 2894 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 2895 | codegen_->MoveLocation(out, src, type); |
| 2896 | |
| 2897 | if (select_end.IsLinked()) { |
| 2898 | __ Bind(&select_end); |
| 2899 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2902 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2903 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2904 | } |
| 2905 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2906 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2907 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | void CodeGeneratorARM::GenerateNop() { |
| 2911 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2914 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2915 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2916 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2917 | // Handle the long/FP comparisons made in instruction simplification. |
| 2918 | switch (cond->InputAt(0)->GetType()) { |
| 2919 | case Primitive::kPrimLong: |
| 2920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2921 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2922 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2923 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2924 | } |
| 2925 | break; |
| 2926 | |
| 2927 | case Primitive::kPrimFloat: |
| 2928 | case Primitive::kPrimDouble: |
| 2929 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2930 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2931 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2932 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2933 | } |
| 2934 | break; |
| 2935 | |
| 2936 | default: |
| 2937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2938 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2939 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2940 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2941 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2942 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2943 | } |
| 2944 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2945 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2946 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2947 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2948 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2949 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2950 | const Register out = cond->GetLocations()->Out().AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2951 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2952 | if (ArmAssembler::IsLowRegister(out) && CanGenerateTest(cond, codegen_->GetAssembler())) { |
| 2953 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2954 | |
| 2955 | __ it(condition.first); |
| 2956 | __ mov(out, ShifterOperand(1), condition.first); |
| 2957 | __ it(condition.second); |
| 2958 | __ mov(out, ShifterOperand(0), condition.second); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2959 | return; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2960 | } |
| 2961 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2962 | // Convert the jumps into the result. |
| 2963 | Label done_label; |
| 2964 | Label* const final_label = codegen_->GetFinalLabel(cond, &done_label); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2965 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2966 | if (cond->InputAt(0)->GetType() == Primitive::kPrimLong) { |
| 2967 | Label true_label, false_label; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2968 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2969 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2970 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2971 | // False case: result = 0. |
| 2972 | __ Bind(&false_label); |
| 2973 | __ LoadImmediate(out, 0); |
| 2974 | __ b(final_label); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2975 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2976 | // True case: result = 1. |
| 2977 | __ Bind(&true_label); |
| 2978 | __ LoadImmediate(out, 1); |
| 2979 | } else { |
| 2980 | DCHECK(CanGenerateTest(cond, codegen_->GetAssembler())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2981 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2982 | const auto condition = GenerateTest(cond, false, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2983 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2984 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 2985 | __ b(final_label, condition.second); |
| 2986 | __ LoadImmediate(out, 1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2987 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2988 | |
Nicolas Geoffray | 3082661 | 2017-05-10 11:59:26 +0000 | [diff] [blame] | 2989 | if (done_label.IsLinked()) { |
| 2990 | __ Bind(&done_label); |
| 2991 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | void LocationsBuilderARM::VisitEqual(HEqual* 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 InstructionCodeGeneratorARM::VisitEqual(HEqual* 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 LocationsBuilderARM::VisitNotEqual(HNotEqual* 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 InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* 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 LocationsBuilderARM::VisitLessThan(HLessThan* 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 InstructionCodeGeneratorARM::VisitLessThan(HLessThan* 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 LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3019 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3023 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3027 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3031 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3035 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3039 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3042 | void LocationsBuilderARM::VisitBelow(HBelow* 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 InstructionCodeGeneratorARM::VisitBelow(HBelow* 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 LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* 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 | |
| 3054 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3055 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3059 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3063 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3067 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3071 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3074 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* 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 | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3080 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3081 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3084 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* 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::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3091 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3094 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3095 | LocationSummary* locations = |
| 3096 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3097 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3098 | } |
| 3099 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3100 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3101 | // Will be generated at use site. |
| 3102 | } |
| 3103 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3104 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3105 | LocationSummary* locations = |
| 3106 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3107 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3108 | } |
| 3109 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3110 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3111 | // Will be generated at use site. |
| 3112 | } |
| 3113 | |
| 3114 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3115 | LocationSummary* locations = |
| 3116 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3117 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3118 | } |
| 3119 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3120 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3121 | // Will be generated at use site. |
| 3122 | } |
| 3123 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3124 | void LocationsBuilderARM::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3125 | constructor_fence->SetLocations(nullptr); |
| 3126 | } |
| 3127 | |
| 3128 | void InstructionCodeGeneratorARM::VisitConstructorFence( |
| 3129 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3130 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3131 | } |
| 3132 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3133 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3134 | memory_barrier->SetLocations(nullptr); |
| 3135 | } |
| 3136 | |
| 3137 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3138 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3139 | } |
| 3140 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3141 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3142 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3145 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3146 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3149 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3150 | LocationSummary* locations = |
| 3151 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3152 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3155 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3156 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3159 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3160 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3161 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3162 | // the method_idx. |
| 3163 | HandleInvoke(invoke); |
| 3164 | } |
| 3165 | |
| 3166 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3167 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3168 | } |
| 3169 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3170 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3171 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3172 | // art::PrepareForRegisterAllocation. |
| 3173 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3174 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3175 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3176 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3177 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3178 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3179 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3180 | return; |
| 3181 | } |
| 3182 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3183 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3184 | |
| 3185 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3186 | if (invoke->HasPcRelativeDexCache()) { |
| 3187 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3188 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3191 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3192 | if (invoke->GetLocations()->Intrinsified()) { |
| 3193 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3194 | intrinsic.Dispatch(invoke); |
| 3195 | return true; |
| 3196 | } |
| 3197 | return false; |
| 3198 | } |
| 3199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3200 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3201 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3202 | // art::PrepareForRegisterAllocation. |
| 3203 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3204 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3205 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3206 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3207 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3208 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3209 | LocationSummary* locations = invoke->GetLocations(); |
| 3210 | codegen_->GenerateStaticOrDirectCall( |
| 3211 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3212 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3213 | } |
| 3214 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3215 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3216 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3217 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3220 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3221 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3222 | if (intrinsic.TryDispatch(invoke)) { |
| 3223 | return; |
| 3224 | } |
| 3225 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3226 | HandleInvoke(invoke); |
| 3227 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3228 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3229 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3230 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3231 | return; |
| 3232 | } |
| 3233 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3234 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3235 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3236 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3239 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3240 | HandleInvoke(invoke); |
| 3241 | // Add the hidden argument. |
| 3242 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3246 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3247 | LocationSummary* locations = invoke->GetLocations(); |
| 3248 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3249 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3250 | Location receiver = locations->InAt(0); |
| 3251 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3252 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3253 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3254 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3255 | DCHECK_EQ(R12, hidden_reg); |
| 3256 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3257 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3258 | if (receiver.IsStackSlot()) { |
| 3259 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3260 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3261 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3262 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3263 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3264 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3265 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3266 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3267 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3268 | // emit a read barrier for the previous class reference load. |
| 3269 | // However this is not required in practice, as this is an |
| 3270 | // intermediate/temporary reference and because the current |
| 3271 | // concurrent copying collector keeps the from-space memory |
| 3272 | // intact/accessible until the end of the marking phase (the |
| 3273 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3274 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3275 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3276 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3277 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3278 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3279 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3280 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3281 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3282 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3283 | // LR = temp->GetEntryPoint(); |
| 3284 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3285 | // LR(); |
| 3286 | __ blx(LR); |
| 3287 | DCHECK(!codegen_->IsLeafMethod()); |
| 3288 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3289 | } |
| 3290 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3291 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3292 | HandleInvoke(invoke); |
| 3293 | } |
| 3294 | |
| 3295 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3296 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3297 | } |
| 3298 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3299 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3300 | LocationSummary* locations = |
| 3301 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3302 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3303 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3304 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3305 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3306 | break; |
| 3307 | } |
| 3308 | case Primitive::kPrimLong: { |
| 3309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3310 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3311 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3312 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3313 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3314 | case Primitive::kPrimFloat: |
| 3315 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3316 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3317 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3318 | break; |
| 3319 | |
| 3320 | default: |
| 3321 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3326 | LocationSummary* locations = neg->GetLocations(); |
| 3327 | Location out = locations->Out(); |
| 3328 | Location in = locations->InAt(0); |
| 3329 | switch (neg->GetResultType()) { |
| 3330 | case Primitive::kPrimInt: |
| 3331 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3332 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3333 | break; |
| 3334 | |
| 3335 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3336 | DCHECK(in.IsRegisterPair()); |
| 3337 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3338 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3339 | in.AsRegisterPairLow<Register>(), |
| 3340 | ShifterOperand(0)); |
| 3341 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3342 | // instruction here, as it does not exist in the Thumb-2 |
| 3343 | // instruction set. We use the following approach |
| 3344 | // using SBC and SUB instead. |
| 3345 | // |
| 3346 | // out.hi = -C |
| 3347 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3348 | out.AsRegisterPairHigh<Register>(), |
| 3349 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3350 | // out.hi = out.hi - in.hi |
| 3351 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3352 | out.AsRegisterPairHigh<Register>(), |
| 3353 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3354 | break; |
| 3355 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3356 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3357 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3358 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3359 | break; |
| 3360 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3361 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3362 | DCHECK(in.IsFpuRegisterPair()); |
| 3363 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3364 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3365 | break; |
| 3366 | |
| 3367 | default: |
| 3368 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3369 | } |
| 3370 | } |
| 3371 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3372 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3373 | Primitive::Type result_type = conversion->GetResultType(); |
| 3374 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3375 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3376 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3377 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3378 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3379 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3380 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3381 | && result_type == Primitive::kPrimLong) |
| 3382 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3383 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3384 | : LocationSummary::kNoCall; |
| 3385 | LocationSummary* locations = |
| 3386 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3387 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3388 | // The Java language does not allow treating boolean as an integral type but |
| 3389 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3390 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3391 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3392 | case Primitive::kPrimByte: |
| 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 byte 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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3398 | case Primitive::kPrimShort: |
| 3399 | case Primitive::kPrimInt: |
| 3400 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3401 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 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 | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3412 | case Primitive::kPrimShort: |
| 3413 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3414 | case Primitive::kPrimLong: |
| 3415 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3416 | case Primitive::kPrimBoolean: |
| 3417 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3418 | case Primitive::kPrimByte: |
| 3419 | case Primitive::kPrimInt: |
| 3420 | case Primitive::kPrimChar: |
| 3421 | // Processing a Dex `int-to-short' instruction. |
| 3422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3423 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3424 | break; |
| 3425 | |
| 3426 | default: |
| 3427 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3428 | << " to " << result_type; |
| 3429 | } |
| 3430 | break; |
| 3431 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3432 | case Primitive::kPrimInt: |
| 3433 | switch (input_type) { |
| 3434 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3435 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3436 | locations->SetInAt(0, Location::Any()); |
| 3437 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3438 | break; |
| 3439 | |
| 3440 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3441 | // Processing a Dex `float-to-int' instruction. |
| 3442 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3443 | locations->SetOut(Location::RequiresRegister()); |
| 3444 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3445 | break; |
| 3446 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3447 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3448 | // Processing a Dex `double-to-int' instruction. |
| 3449 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3450 | locations->SetOut(Location::RequiresRegister()); |
| 3451 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | |
| 3454 | default: |
| 3455 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3456 | << " to " << result_type; |
| 3457 | } |
| 3458 | break; |
| 3459 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3460 | case Primitive::kPrimLong: |
| 3461 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3462 | case Primitive::kPrimBoolean: |
| 3463 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3464 | case Primitive::kPrimByte: |
| 3465 | case Primitive::kPrimShort: |
| 3466 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3467 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3468 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3470 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3471 | break; |
| 3472 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3473 | case Primitive::kPrimFloat: { |
| 3474 | // Processing a Dex `float-to-long' instruction. |
| 3475 | InvokeRuntimeCallingConvention calling_convention; |
| 3476 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3477 | calling_convention.GetFpuRegisterAt(0))); |
| 3478 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3479 | break; |
| 3480 | } |
| 3481 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3482 | case Primitive::kPrimDouble: { |
| 3483 | // Processing a Dex `double-to-long' instruction. |
| 3484 | InvokeRuntimeCallingConvention calling_convention; |
| 3485 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3486 | calling_convention.GetFpuRegisterAt(0), |
| 3487 | calling_convention.GetFpuRegisterAt(1))); |
| 3488 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3489 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3490 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3491 | |
| 3492 | default: |
| 3493 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3494 | << " to " << result_type; |
| 3495 | } |
| 3496 | break; |
| 3497 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3498 | case Primitive::kPrimChar: |
| 3499 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3500 | case Primitive::kPrimLong: |
| 3501 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3502 | case Primitive::kPrimBoolean: |
| 3503 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3504 | case Primitive::kPrimByte: |
| 3505 | case Primitive::kPrimShort: |
| 3506 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3507 | // Processing a Dex `int-to-char' instruction. |
| 3508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3509 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3510 | break; |
| 3511 | |
| 3512 | default: |
| 3513 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3514 | << " to " << result_type; |
| 3515 | } |
| 3516 | break; |
| 3517 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3518 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3519 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3520 | case Primitive::kPrimBoolean: |
| 3521 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3522 | case Primitive::kPrimByte: |
| 3523 | case Primitive::kPrimShort: |
| 3524 | case Primitive::kPrimInt: |
| 3525 | case Primitive::kPrimChar: |
| 3526 | // Processing a Dex `int-to-float' instruction. |
| 3527 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3528 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3529 | break; |
| 3530 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3531 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3532 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3533 | InvokeRuntimeCallingConvention calling_convention; |
| 3534 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3535 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3536 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3537 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3538 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3539 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3540 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3541 | // Processing a Dex `double-to-float' instruction. |
| 3542 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3543 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3544 | break; |
| 3545 | |
| 3546 | default: |
| 3547 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3548 | << " to " << result_type; |
| 3549 | }; |
| 3550 | break; |
| 3551 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3552 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3553 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3554 | case Primitive::kPrimBoolean: |
| 3555 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3556 | case Primitive::kPrimByte: |
| 3557 | case Primitive::kPrimShort: |
| 3558 | case Primitive::kPrimInt: |
| 3559 | case Primitive::kPrimChar: |
| 3560 | // Processing a Dex `int-to-double' instruction. |
| 3561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3562 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3563 | break; |
| 3564 | |
| 3565 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3566 | // Processing a Dex `long-to-double' instruction. |
| 3567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3568 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3569 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3570 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3571 | break; |
| 3572 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3573 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3574 | // Processing a Dex `float-to-double' instruction. |
| 3575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3576 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3577 | break; |
| 3578 | |
| 3579 | default: |
| 3580 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3581 | << " to " << result_type; |
| 3582 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3583 | break; |
| 3584 | |
| 3585 | default: |
| 3586 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3587 | << " to " << result_type; |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3592 | LocationSummary* locations = conversion->GetLocations(); |
| 3593 | Location out = locations->Out(); |
| 3594 | Location in = locations->InAt(0); |
| 3595 | Primitive::Type result_type = conversion->GetResultType(); |
| 3596 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3597 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3598 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3599 | case Primitive::kPrimByte: |
| 3600 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3601 | case Primitive::kPrimLong: |
| 3602 | // Type conversion from long to byte is a result of code transformations. |
| 3603 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3604 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3605 | case Primitive::kPrimBoolean: |
| 3606 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3607 | case Primitive::kPrimShort: |
| 3608 | case Primitive::kPrimInt: |
| 3609 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3610 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3611 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3612 | break; |
| 3613 | |
| 3614 | default: |
| 3615 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3616 | << " to " << result_type; |
| 3617 | } |
| 3618 | break; |
| 3619 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3620 | case Primitive::kPrimShort: |
| 3621 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3622 | case Primitive::kPrimLong: |
| 3623 | // Type conversion from long to short is a result of code transformations. |
| 3624 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3625 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3626 | case Primitive::kPrimBoolean: |
| 3627 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimByte: |
| 3629 | case Primitive::kPrimInt: |
| 3630 | case Primitive::kPrimChar: |
| 3631 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3632 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | |
| 3635 | default: |
| 3636 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3637 | << " to " << result_type; |
| 3638 | } |
| 3639 | break; |
| 3640 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3641 | case Primitive::kPrimInt: |
| 3642 | switch (input_type) { |
| 3643 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3644 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3645 | DCHECK(out.IsRegister()); |
| 3646 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3647 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3648 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3649 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3650 | } else { |
| 3651 | DCHECK(in.IsConstant()); |
| 3652 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3653 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3654 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3655 | } |
| 3656 | break; |
| 3657 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3658 | case Primitive::kPrimFloat: { |
| 3659 | // Processing a Dex `float-to-int' instruction. |
| 3660 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3661 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3662 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3663 | break; |
| 3664 | } |
| 3665 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3666 | case Primitive::kPrimDouble: { |
| 3667 | // Processing a Dex `double-to-int' instruction. |
| 3668 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3669 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3670 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3671 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3672 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3673 | |
| 3674 | default: |
| 3675 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3676 | << " to " << result_type; |
| 3677 | } |
| 3678 | break; |
| 3679 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3680 | case Primitive::kPrimLong: |
| 3681 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3682 | case Primitive::kPrimBoolean: |
| 3683 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3684 | case Primitive::kPrimByte: |
| 3685 | case Primitive::kPrimShort: |
| 3686 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3687 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3688 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3689 | DCHECK(out.IsRegisterPair()); |
| 3690 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3691 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3692 | // Sign extension. |
| 3693 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3694 | out.AsRegisterPairLow<Register>(), |
| 3695 | 31); |
| 3696 | break; |
| 3697 | |
| 3698 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3699 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3700 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3701 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3702 | break; |
| 3703 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3704 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3705 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3706 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3707 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3708 | break; |
| 3709 | |
| 3710 | default: |
| 3711 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3712 | << " to " << result_type; |
| 3713 | } |
| 3714 | break; |
| 3715 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3716 | case Primitive::kPrimChar: |
| 3717 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3718 | case Primitive::kPrimLong: |
| 3719 | // Type conversion from long to char is a result of code transformations. |
| 3720 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3721 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3722 | case Primitive::kPrimBoolean: |
| 3723 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3724 | case Primitive::kPrimByte: |
| 3725 | case Primitive::kPrimShort: |
| 3726 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3727 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3728 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3729 | break; |
| 3730 | |
| 3731 | default: |
| 3732 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3733 | << " to " << result_type; |
| 3734 | } |
| 3735 | break; |
| 3736 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3737 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3738 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3739 | case Primitive::kPrimBoolean: |
| 3740 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3741 | case Primitive::kPrimByte: |
| 3742 | case Primitive::kPrimShort: |
| 3743 | case Primitive::kPrimInt: |
| 3744 | case Primitive::kPrimChar: { |
| 3745 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3746 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3747 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3748 | break; |
| 3749 | } |
| 3750 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3751 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3752 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3753 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3754 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3755 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3756 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3757 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3758 | // Processing a Dex `double-to-float' instruction. |
| 3759 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3760 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | |
| 3763 | default: |
| 3764 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3765 | << " to " << result_type; |
| 3766 | }; |
| 3767 | break; |
| 3768 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3769 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3770 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3771 | case Primitive::kPrimBoolean: |
| 3772 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3773 | case Primitive::kPrimByte: |
| 3774 | case Primitive::kPrimShort: |
| 3775 | case Primitive::kPrimInt: |
| 3776 | case Primitive::kPrimChar: { |
| 3777 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3778 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3779 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3780 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3781 | break; |
| 3782 | } |
| 3783 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3784 | case Primitive::kPrimLong: { |
| 3785 | // Processing a Dex `long-to-double' instruction. |
| 3786 | Register low = in.AsRegisterPairLow<Register>(); |
| 3787 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3788 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3789 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3790 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3791 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3792 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3793 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3794 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3795 | // temp_d = int-to-double(high) |
| 3796 | __ vmovsr(temp_s, high); |
| 3797 | __ vcvtdi(temp_d, temp_s); |
| 3798 | // constant_d = k2Pow32EncodingForDouble |
| 3799 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3800 | // out_d = unsigned-to-double(low) |
| 3801 | __ vmovsr(out_s, low); |
| 3802 | __ vcvtdu(out_d, out_s); |
| 3803 | // out_d += temp_d * constant_d |
| 3804 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3805 | break; |
| 3806 | } |
| 3807 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3808 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3809 | // Processing a Dex `float-to-double' instruction. |
| 3810 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3811 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3812 | break; |
| 3813 | |
| 3814 | default: |
| 3815 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3816 | << " to " << result_type; |
| 3817 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3818 | break; |
| 3819 | |
| 3820 | default: |
| 3821 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3822 | << " to " << result_type; |
| 3823 | } |
| 3824 | } |
| 3825 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3826 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3827 | LocationSummary* locations = |
| 3828 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3829 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3830 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3832 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3833 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3834 | break; |
| 3835 | } |
| 3836 | |
| 3837 | case Primitive::kPrimLong: { |
| 3838 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3839 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3840 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3841 | break; |
| 3842 | } |
| 3843 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3844 | case Primitive::kPrimFloat: |
| 3845 | case Primitive::kPrimDouble: { |
| 3846 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3847 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3848 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3849 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3850 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3851 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3852 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3853 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3854 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3858 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3859 | Location out = locations->Out(); |
| 3860 | Location first = locations->InAt(0); |
| 3861 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3862 | switch (add->GetResultType()) { |
| 3863 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3864 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3865 | __ add(out.AsRegister<Register>(), |
| 3866 | first.AsRegister<Register>(), |
| 3867 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3868 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3869 | __ AddConstant(out.AsRegister<Register>(), |
| 3870 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3871 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3872 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3873 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3874 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3875 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3876 | if (second.IsConstant()) { |
| 3877 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3878 | GenerateAddLongConst(out, first, value); |
| 3879 | } else { |
| 3880 | DCHECK(second.IsRegisterPair()); |
| 3881 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3882 | first.AsRegisterPairLow<Register>(), |
| 3883 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3884 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3885 | first.AsRegisterPairHigh<Register>(), |
| 3886 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3887 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3888 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3889 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3890 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3891 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3892 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3893 | first.AsFpuRegister<SRegister>(), |
| 3894 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3895 | break; |
| 3896 | |
| 3897 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3898 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3899 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3900 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3901 | break; |
| 3902 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3903 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3904 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3908 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3909 | LocationSummary* locations = |
| 3910 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3911 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3912 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3914 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3915 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3916 | break; |
| 3917 | } |
| 3918 | |
| 3919 | case Primitive::kPrimLong: { |
| 3920 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3921 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3922 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3923 | break; |
| 3924 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3925 | case Primitive::kPrimFloat: |
| 3926 | case Primitive::kPrimDouble: { |
| 3927 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3928 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3929 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3930 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3931 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3932 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3933 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3934 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3938 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3939 | Location out = locations->Out(); |
| 3940 | Location first = locations->InAt(0); |
| 3941 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3942 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3943 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3944 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3945 | __ sub(out.AsRegister<Register>(), |
| 3946 | first.AsRegister<Register>(), |
| 3947 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3948 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3949 | __ AddConstant(out.AsRegister<Register>(), |
| 3950 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3951 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3952 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3953 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3954 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3955 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3956 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3957 | if (second.IsConstant()) { |
| 3958 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3959 | GenerateAddLongConst(out, first, -value); |
| 3960 | } else { |
| 3961 | DCHECK(second.IsRegisterPair()); |
| 3962 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3963 | first.AsRegisterPairLow<Register>(), |
| 3964 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3965 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3966 | first.AsRegisterPairHigh<Register>(), |
| 3967 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3968 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3969 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3970 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3971 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3972 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3973 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3974 | first.AsFpuRegister<SRegister>(), |
| 3975 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3976 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3980 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3981 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3982 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3983 | break; |
| 3984 | } |
| 3985 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3986 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3987 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3988 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3992 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3993 | LocationSummary* locations = |
| 3994 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3995 | switch (mul->GetResultType()) { |
| 3996 | case Primitive::kPrimInt: |
| 3997 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3998 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3999 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4000 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4001 | break; |
| 4002 | } |
| 4003 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4004 | case Primitive::kPrimFloat: |
| 4005 | case Primitive::kPrimDouble: { |
| 4006 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4007 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4008 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4009 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4010 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4011 | |
| 4012 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4013 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4014 | } |
| 4015 | } |
| 4016 | |
| 4017 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 4018 | LocationSummary* locations = mul->GetLocations(); |
| 4019 | Location out = locations->Out(); |
| 4020 | Location first = locations->InAt(0); |
| 4021 | Location second = locations->InAt(1); |
| 4022 | switch (mul->GetResultType()) { |
| 4023 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4024 | __ mul(out.AsRegister<Register>(), |
| 4025 | first.AsRegister<Register>(), |
| 4026 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4027 | break; |
| 4028 | } |
| 4029 | case Primitive::kPrimLong: { |
| 4030 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 4031 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 4032 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 4033 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 4034 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 4035 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 4036 | |
| 4037 | // Extra checks to protect caused by the existence of R1_R2. |
| 4038 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4039 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 4040 | DCHECK_NE(out_hi, in1_lo); |
| 4041 | DCHECK_NE(out_hi, in2_lo); |
| 4042 | |
| 4043 | // input: in1 - 64 bits, in2 - 64 bits |
| 4044 | // output: out |
| 4045 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4046 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4047 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4048 | |
| 4049 | // IP <- in1.lo * in2.hi |
| 4050 | __ mul(IP, in1_lo, in2_hi); |
| 4051 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4052 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 4053 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4054 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 4055 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 4056 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 4057 | break; |
| 4058 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4059 | |
| 4060 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4061 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 4062 | first.AsFpuRegister<SRegister>(), |
| 4063 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4064 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4068 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4069 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4070 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4071 | break; |
| 4072 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4073 | |
| 4074 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4075 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4076 | } |
| 4077 | } |
| 4078 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4079 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4080 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4081 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4082 | |
| 4083 | LocationSummary* locations = instruction->GetLocations(); |
| 4084 | Location second = locations->InAt(1); |
| 4085 | DCHECK(second.IsConstant()); |
| 4086 | |
| 4087 | Register out = locations->Out().AsRegister<Register>(); |
| 4088 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4089 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4090 | DCHECK(imm == 1 || imm == -1); |
| 4091 | |
| 4092 | if (instruction->IsRem()) { |
| 4093 | __ LoadImmediate(out, 0); |
| 4094 | } else { |
| 4095 | if (imm == 1) { |
| 4096 | __ Mov(out, dividend); |
| 4097 | } else { |
| 4098 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4099 | } |
| 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4104 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4105 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4106 | |
| 4107 | LocationSummary* locations = instruction->GetLocations(); |
| 4108 | Location second = locations->InAt(1); |
| 4109 | DCHECK(second.IsConstant()); |
| 4110 | |
| 4111 | Register out = locations->Out().AsRegister<Register>(); |
| 4112 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4113 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4114 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4115 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4116 | int ctz_imm = CTZ(abs_imm); |
| 4117 | |
| 4118 | if (ctz_imm == 1) { |
| 4119 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4120 | } else { |
| 4121 | __ Asr(temp, dividend, 31); |
| 4122 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4123 | } |
| 4124 | __ add(out, temp, ShifterOperand(dividend)); |
| 4125 | |
| 4126 | if (instruction->IsDiv()) { |
| 4127 | __ Asr(out, out, ctz_imm); |
| 4128 | if (imm < 0) { |
| 4129 | __ rsb(out, out, ShifterOperand(0)); |
| 4130 | } |
| 4131 | } else { |
| 4132 | __ ubfx(out, out, 0, ctz_imm); |
| 4133 | __ sub(out, out, ShifterOperand(temp)); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4138 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4139 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4140 | |
| 4141 | LocationSummary* locations = instruction->GetLocations(); |
| 4142 | Location second = locations->InAt(1); |
| 4143 | DCHECK(second.IsConstant()); |
| 4144 | |
| 4145 | Register out = locations->Out().AsRegister<Register>(); |
| 4146 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4147 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4148 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4149 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4150 | |
| 4151 | int64_t magic; |
| 4152 | int shift; |
| 4153 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4154 | |
| 4155 | __ LoadImmediate(temp1, magic); |
| 4156 | __ smull(temp2, temp1, dividend, temp1); |
| 4157 | |
| 4158 | if (imm > 0 && magic < 0) { |
| 4159 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4160 | } else if (imm < 0 && magic > 0) { |
| 4161 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4162 | } |
| 4163 | |
| 4164 | if (shift != 0) { |
| 4165 | __ Asr(temp1, temp1, shift); |
| 4166 | } |
| 4167 | |
| 4168 | if (instruction->IsDiv()) { |
| 4169 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4170 | } else { |
| 4171 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4172 | // TODO: Strength reduction for mls. |
| 4173 | __ LoadImmediate(temp2, imm); |
| 4174 | __ mls(out, temp1, temp2, dividend); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4179 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4180 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4181 | |
| 4182 | LocationSummary* locations = instruction->GetLocations(); |
| 4183 | Location second = locations->InAt(1); |
| 4184 | DCHECK(second.IsConstant()); |
| 4185 | |
| 4186 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4187 | if (imm == 0) { |
| 4188 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4189 | } else if (imm == 1 || imm == -1) { |
| 4190 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4191 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4192 | DivRemByPowerOfTwo(instruction); |
| 4193 | } else { |
| 4194 | DCHECK(imm <= -2 || imm >= 2); |
| 4195 | GenerateDivRemWithAnyConstant(instruction); |
| 4196 | } |
| 4197 | } |
| 4198 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4199 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4200 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4201 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4202 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4203 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4204 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4205 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4206 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4207 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4208 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4209 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4210 | } |
| 4211 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4212 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4213 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4214 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4215 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4216 | if (div->InputAt(1)->IsConstant()) { |
| 4217 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4218 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4219 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4220 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4221 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4222 | // No temp register required. |
| 4223 | } else { |
| 4224 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4225 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4226 | locations->AddTemp(Location::RequiresRegister()); |
| 4227 | } |
| 4228 | } |
| 4229 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4230 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4231 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4232 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4233 | } else { |
| 4234 | InvokeRuntimeCallingConvention calling_convention; |
| 4235 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4236 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4237 | // 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] | 4238 | // we only need the former. |
| 4239 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4240 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4241 | break; |
| 4242 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4243 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4244 | InvokeRuntimeCallingConvention calling_convention; |
| 4245 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4246 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4247 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4248 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4249 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4250 | break; |
| 4251 | } |
| 4252 | case Primitive::kPrimFloat: |
| 4253 | case Primitive::kPrimDouble: { |
| 4254 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4255 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4256 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4257 | break; |
| 4258 | } |
| 4259 | |
| 4260 | default: |
| 4261 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4266 | LocationSummary* locations = div->GetLocations(); |
| 4267 | Location out = locations->Out(); |
| 4268 | Location first = locations->InAt(0); |
| 4269 | Location second = locations->InAt(1); |
| 4270 | |
| 4271 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4272 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4273 | if (second.IsConstant()) { |
| 4274 | GenerateDivRemConstantIntegral(div); |
| 4275 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4276 | __ sdiv(out.AsRegister<Register>(), |
| 4277 | first.AsRegister<Register>(), |
| 4278 | second.AsRegister<Register>()); |
| 4279 | } else { |
| 4280 | InvokeRuntimeCallingConvention calling_convention; |
| 4281 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4282 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4283 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4284 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4285 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4286 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4287 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4288 | break; |
| 4289 | } |
| 4290 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4291 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4292 | InvokeRuntimeCallingConvention calling_convention; |
| 4293 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4294 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4295 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4296 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4297 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4298 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4299 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4300 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4301 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4302 | break; |
| 4303 | } |
| 4304 | |
| 4305 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4306 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4307 | first.AsFpuRegister<SRegister>(), |
| 4308 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4309 | break; |
| 4310 | } |
| 4311 | |
| 4312 | case Primitive::kPrimDouble: { |
| 4313 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4314 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4315 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4316 | break; |
| 4317 | } |
| 4318 | |
| 4319 | default: |
| 4320 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4321 | } |
| 4322 | } |
| 4323 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4324 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4325 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4326 | |
| 4327 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4328 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4329 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4330 | // sdiv will be replaced by other instruction sequence. |
| 4331 | call_kind = LocationSummary::kNoCall; |
| 4332 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4333 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4334 | // Have hardware divide instruction for int, do it with three instructions. |
| 4335 | call_kind = LocationSummary::kNoCall; |
| 4336 | } |
| 4337 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4338 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4339 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4340 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4341 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4342 | if (rem->InputAt(1)->IsConstant()) { |
| 4343 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4344 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4345 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4346 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4347 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4348 | // No temp register required. |
| 4349 | } else { |
| 4350 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4351 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4352 | locations->AddTemp(Location::RequiresRegister()); |
| 4353 | } |
| 4354 | } |
| 4355 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4356 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4357 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4358 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4359 | locations->AddTemp(Location::RequiresRegister()); |
| 4360 | } else { |
| 4361 | InvokeRuntimeCallingConvention calling_convention; |
| 4362 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4363 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4364 | // 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] | 4365 | // we only need the latter. |
| 4366 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4367 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4368 | break; |
| 4369 | } |
| 4370 | case Primitive::kPrimLong: { |
| 4371 | InvokeRuntimeCallingConvention calling_convention; |
| 4372 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4373 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4374 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4375 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4376 | // The runtime helper puts the output in R2,R3. |
| 4377 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4378 | break; |
| 4379 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4380 | case Primitive::kPrimFloat: { |
| 4381 | InvokeRuntimeCallingConvention calling_convention; |
| 4382 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4383 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4384 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4385 | break; |
| 4386 | } |
| 4387 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4388 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4389 | InvokeRuntimeCallingConvention calling_convention; |
| 4390 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4391 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4392 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4393 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4394 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4395 | break; |
| 4396 | } |
| 4397 | |
| 4398 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4399 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4404 | LocationSummary* locations = rem->GetLocations(); |
| 4405 | Location out = locations->Out(); |
| 4406 | Location first = locations->InAt(0); |
| 4407 | Location second = locations->InAt(1); |
| 4408 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4409 | Primitive::Type type = rem->GetResultType(); |
| 4410 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4411 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4412 | if (second.IsConstant()) { |
| 4413 | GenerateDivRemConstantIntegral(rem); |
| 4414 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4415 | Register reg1 = first.AsRegister<Register>(); |
| 4416 | Register reg2 = second.AsRegister<Register>(); |
| 4417 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4418 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4419 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4420 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4421 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4422 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4423 | } else { |
| 4424 | InvokeRuntimeCallingConvention calling_convention; |
| 4425 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4426 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4427 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4428 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4429 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4430 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4431 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4432 | break; |
| 4433 | } |
| 4434 | |
| 4435 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4436 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4437 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4438 | break; |
| 4439 | } |
| 4440 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4441 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4442 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4443 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4444 | break; |
| 4445 | } |
| 4446 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4447 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4448 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4449 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4450 | break; |
| 4451 | } |
| 4452 | |
| 4453 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4454 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4455 | } |
| 4456 | } |
| 4457 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4458 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4459 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4460 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4464 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4465 | codegen_->AddSlowPath(slow_path); |
| 4466 | |
| 4467 | LocationSummary* locations = instruction->GetLocations(); |
| 4468 | Location value = locations->InAt(0); |
| 4469 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4470 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4471 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4472 | case Primitive::kPrimByte: |
| 4473 | case Primitive::kPrimChar: |
| 4474 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4475 | case Primitive::kPrimInt: { |
| 4476 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4477 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4478 | } else { |
| 4479 | DCHECK(value.IsConstant()) << value; |
| 4480 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4481 | __ b(slow_path->GetEntryLabel()); |
| 4482 | } |
| 4483 | } |
| 4484 | break; |
| 4485 | } |
| 4486 | case Primitive::kPrimLong: { |
| 4487 | if (value.IsRegisterPair()) { |
| 4488 | __ orrs(IP, |
| 4489 | value.AsRegisterPairLow<Register>(), |
| 4490 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4491 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4492 | } else { |
| 4493 | DCHECK(value.IsConstant()) << value; |
| 4494 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4495 | __ b(slow_path->GetEntryLabel()); |
| 4496 | } |
| 4497 | } |
| 4498 | break; |
| 4499 | default: |
| 4500 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4501 | } |
| 4502 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4505 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4506 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4507 | Location rhs = locations->InAt(1); |
| 4508 | Register out = locations->Out().AsRegister<Register>(); |
| 4509 | |
| 4510 | if (rhs.IsConstant()) { |
| 4511 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4512 | // so map all rotations to a +ve. equivalent in that range. |
| 4513 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4514 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4515 | if (rot) { |
| 4516 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4517 | // (e.g. left by 2 bits == right by 30.) |
| 4518 | __ Ror(out, in, rot); |
| 4519 | } else if (out != in) { |
| 4520 | __ Mov(out, in); |
| 4521 | } |
| 4522 | } else { |
| 4523 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4528 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4529 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4530 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4531 | void InstructionCodeGeneratorARM::HandleLongRotate(HRor* ror) { |
| 4532 | LocationSummary* locations = ror->GetLocations(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4533 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4534 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4535 | Location rhs = locations->InAt(1); |
| 4536 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4537 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4538 | |
| 4539 | if (rhs.IsConstant()) { |
| 4540 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4541 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4542 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4543 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4544 | // logic below to a simple pair of binary orr. |
| 4545 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4546 | if (rot >= kArmBitsPerWord) { |
| 4547 | rot -= kArmBitsPerWord; |
| 4548 | std::swap(in_reg_hi, in_reg_lo); |
| 4549 | } |
| 4550 | // Rotate, or mov to out for zero or word size rotations. |
| 4551 | if (rot != 0u) { |
| 4552 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4553 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4554 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4555 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4556 | } else { |
| 4557 | __ Mov(out_reg_lo, in_reg_lo); |
| 4558 | __ Mov(out_reg_hi, in_reg_hi); |
| 4559 | } |
| 4560 | } else { |
| 4561 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4562 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4563 | Label end; |
| 4564 | Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4565 | Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4566 | |
| 4567 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4568 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4569 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4570 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4571 | |
| 4572 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4573 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4574 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4575 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4576 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4577 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4578 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4579 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4580 | __ b(final_label); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4581 | |
| 4582 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4583 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4584 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4585 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4586 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4587 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4588 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4589 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4590 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4591 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4592 | if (end.IsLinked()) { |
| 4593 | __ Bind(&end); |
| 4594 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4595 | } |
| 4596 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4597 | |
| 4598 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4599 | LocationSummary* locations = |
| 4600 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4601 | switch (ror->GetResultType()) { |
| 4602 | case Primitive::kPrimInt: { |
| 4603 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4604 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4606 | break; |
| 4607 | } |
| 4608 | case Primitive::kPrimLong: { |
| 4609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4610 | if (ror->InputAt(1)->IsConstant()) { |
| 4611 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4612 | } else { |
| 4613 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4614 | locations->AddTemp(Location::RequiresRegister()); |
| 4615 | locations->AddTemp(Location::RequiresRegister()); |
| 4616 | } |
| 4617 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4618 | break; |
| 4619 | } |
| 4620 | default: |
| 4621 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4622 | } |
| 4623 | } |
| 4624 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4625 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4626 | LocationSummary* locations = ror->GetLocations(); |
| 4627 | Primitive::Type type = ror->GetResultType(); |
| 4628 | switch (type) { |
| 4629 | case Primitive::kPrimInt: { |
| 4630 | HandleIntegerRotate(locations); |
| 4631 | break; |
| 4632 | } |
| 4633 | case Primitive::kPrimLong: { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4634 | HandleLongRotate(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4635 | break; |
| 4636 | } |
| 4637 | default: |
| 4638 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4639 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4643 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4644 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4645 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4646 | LocationSummary* locations = |
| 4647 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4648 | |
| 4649 | switch (op->GetResultType()) { |
| 4650 | case Primitive::kPrimInt: { |
| 4651 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4652 | if (op->InputAt(1)->IsConstant()) { |
| 4653 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4654 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4655 | } else { |
| 4656 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4657 | // Make the output overlap, as it will be used to hold the masked |
| 4658 | // second input. |
| 4659 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4660 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4661 | break; |
| 4662 | } |
| 4663 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4664 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4665 | if (op->InputAt(1)->IsConstant()) { |
| 4666 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4667 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4668 | // don't clash with high registers which the register allocator currently guarantees. |
| 4669 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4670 | } else { |
| 4671 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4672 | locations->AddTemp(Location::RequiresRegister()); |
| 4673 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4674 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4675 | break; |
| 4676 | } |
| 4677 | default: |
| 4678 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4683 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4684 | |
| 4685 | LocationSummary* locations = op->GetLocations(); |
| 4686 | Location out = locations->Out(); |
| 4687 | Location first = locations->InAt(0); |
| 4688 | Location second = locations->InAt(1); |
| 4689 | |
| 4690 | Primitive::Type type = op->GetResultType(); |
| 4691 | switch (type) { |
| 4692 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4693 | Register out_reg = out.AsRegister<Register>(); |
| 4694 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4695 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4696 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4697 | // 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] | 4698 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4699 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4700 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4701 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4702 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4703 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4704 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4705 | } |
| 4706 | } else { |
| 4707 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4708 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4709 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4710 | __ Mov(out_reg, first_reg); |
| 4711 | } else if (op->IsShl()) { |
| 4712 | __ Lsl(out_reg, first_reg, shift_value); |
| 4713 | } else if (op->IsShr()) { |
| 4714 | __ Asr(out_reg, first_reg, shift_value); |
| 4715 | } else { |
| 4716 | __ Lsr(out_reg, first_reg, shift_value); |
| 4717 | } |
| 4718 | } |
| 4719 | break; |
| 4720 | } |
| 4721 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4722 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4723 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4724 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4725 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4726 | Register low = first.AsRegisterPairLow<Register>(); |
| 4727 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4728 | if (second.IsRegister()) { |
| 4729 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4730 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4731 | Register second_reg = second.AsRegister<Register>(); |
| 4732 | |
| 4733 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4734 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4735 | // Shift the high part |
| 4736 | __ Lsl(o_h, high, o_l); |
| 4737 | // Shift the low part and `or` what overflew on the high part |
| 4738 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4739 | __ Lsr(temp, low, temp); |
| 4740 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4741 | // If the shift is > 32 bits, override the high part |
| 4742 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4743 | __ it(PL); |
| 4744 | __ Lsl(o_h, low, temp, PL); |
| 4745 | // Shift the low part |
| 4746 | __ Lsl(o_l, low, o_l); |
| 4747 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4748 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4749 | // Shift the low part |
| 4750 | __ Lsr(o_l, low, o_h); |
| 4751 | // Shift the high part and `or` what underflew on the low part |
| 4752 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4753 | __ Lsl(temp, high, temp); |
| 4754 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4755 | // If the shift is > 32 bits, override the low part |
| 4756 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4757 | __ it(PL); |
| 4758 | __ Asr(o_l, high, temp, PL); |
| 4759 | // Shift the high part |
| 4760 | __ Asr(o_h, high, o_h); |
| 4761 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4762 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4763 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4764 | __ Lsr(o_l, low, o_h); |
| 4765 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4766 | __ Lsl(temp, high, temp); |
| 4767 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4768 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4769 | __ it(PL); |
| 4770 | __ Lsr(o_l, high, temp, PL); |
| 4771 | __ Lsr(o_h, high, o_h); |
| 4772 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4773 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4774 | // Register allocator doesn't create partial overlap. |
| 4775 | DCHECK_NE(o_l, high); |
| 4776 | DCHECK_NE(o_h, low); |
| 4777 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4778 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4779 | if (shift_value > 32) { |
| 4780 | if (op->IsShl()) { |
| 4781 | __ Lsl(o_h, low, shift_value - 32); |
| 4782 | __ LoadImmediate(o_l, 0); |
| 4783 | } else if (op->IsShr()) { |
| 4784 | __ Asr(o_l, high, shift_value - 32); |
| 4785 | __ Asr(o_h, high, 31); |
| 4786 | } else { |
| 4787 | __ Lsr(o_l, high, shift_value - 32); |
| 4788 | __ LoadImmediate(o_h, 0); |
| 4789 | } |
| 4790 | } else if (shift_value == 32) { |
| 4791 | if (op->IsShl()) { |
| 4792 | __ mov(o_h, ShifterOperand(low)); |
| 4793 | __ LoadImmediate(o_l, 0); |
| 4794 | } else if (op->IsShr()) { |
| 4795 | __ mov(o_l, ShifterOperand(high)); |
| 4796 | __ Asr(o_h, high, 31); |
| 4797 | } else { |
| 4798 | __ mov(o_l, ShifterOperand(high)); |
| 4799 | __ LoadImmediate(o_h, 0); |
| 4800 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4801 | } else if (shift_value == 1) { |
| 4802 | if (op->IsShl()) { |
| 4803 | __ Lsls(o_l, low, 1); |
| 4804 | __ adc(o_h, high, ShifterOperand(high)); |
| 4805 | } else if (op->IsShr()) { |
| 4806 | __ Asrs(o_h, high, 1); |
| 4807 | __ Rrx(o_l, low); |
| 4808 | } else { |
| 4809 | __ Lsrs(o_h, high, 1); |
| 4810 | __ Rrx(o_l, low); |
| 4811 | } |
| 4812 | } else { |
| 4813 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4814 | if (op->IsShl()) { |
| 4815 | __ Lsl(o_h, high, shift_value); |
| 4816 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4817 | __ Lsl(o_l, low, shift_value); |
| 4818 | } else if (op->IsShr()) { |
| 4819 | __ Lsr(o_l, low, shift_value); |
| 4820 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4821 | __ Asr(o_h, high, shift_value); |
| 4822 | } else { |
| 4823 | __ Lsr(o_l, low, shift_value); |
| 4824 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4825 | __ Lsr(o_h, high, shift_value); |
| 4826 | } |
| 4827 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4828 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4829 | break; |
| 4830 | } |
| 4831 | default: |
| 4832 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4833 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4838 | HandleShift(shl); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4842 | HandleShift(shl); |
| 4843 | } |
| 4844 | |
| 4845 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4846 | HandleShift(shr); |
| 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4850 | HandleShift(shr); |
| 4851 | } |
| 4852 | |
| 4853 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4854 | HandleShift(ushr); |
| 4855 | } |
| 4856 | |
| 4857 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4858 | HandleShift(ushr); |
| 4859 | } |
| 4860 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4861 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4862 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4863 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4864 | if (instruction->IsStringAlloc()) { |
| 4865 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4866 | } else { |
| 4867 | InvokeRuntimeCallingConvention calling_convention; |
| 4868 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4869 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4870 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4874 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4875 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4876 | if (instruction->IsStringAlloc()) { |
| 4877 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4878 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4879 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4880 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4881 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4882 | __ blx(LR); |
| 4883 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4884 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4885 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4886 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4887 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4890 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4891 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4892 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4893 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4894 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4895 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4896 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4900 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4901 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4902 | QuickEntrypointEnum entrypoint = |
| 4903 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4904 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4905 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4906 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4907 | } |
| 4908 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4909 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4910 | LocationSummary* locations = |
| 4911 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4912 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4913 | if (location.IsStackSlot()) { |
| 4914 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4915 | } else if (location.IsDoubleStackSlot()) { |
| 4916 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4917 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4918 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4919 | } |
| 4920 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4921 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4922 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4923 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4927 | LocationSummary* locations = |
| 4928 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4929 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4930 | } |
| 4931 | |
| 4932 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4933 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4934 | } |
| 4935 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4936 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4937 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4938 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4939 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4940 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4941 | } |
| 4942 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4943 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4944 | LocationSummary* locations = not_->GetLocations(); |
| 4945 | Location out = locations->Out(); |
| 4946 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4947 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4948 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4949 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4950 | break; |
| 4951 | |
| 4952 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4953 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4954 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4955 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4956 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4957 | break; |
| 4958 | |
| 4959 | default: |
| 4960 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4961 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4962 | } |
| 4963 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4964 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4965 | LocationSummary* locations = |
| 4966 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4967 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4968 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4969 | } |
| 4970 | |
| 4971 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4972 | LocationSummary* locations = bool_not->GetLocations(); |
| 4973 | Location out = locations->Out(); |
| 4974 | Location in = locations->InAt(0); |
| 4975 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4976 | } |
| 4977 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4978 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4979 | LocationSummary* locations = |
| 4980 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4981 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4982 | case Primitive::kPrimBoolean: |
| 4983 | case Primitive::kPrimByte: |
| 4984 | case Primitive::kPrimShort: |
| 4985 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4986 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4987 | case Primitive::kPrimLong: { |
| 4988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4989 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4990 | // Output overlaps because it is written before doing the low comparison. |
| 4991 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4992 | break; |
| 4993 | } |
| 4994 | case Primitive::kPrimFloat: |
| 4995 | case Primitive::kPrimDouble: { |
| 4996 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4997 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4998 | locations->SetOut(Location::RequiresRegister()); |
| 4999 | break; |
| 5000 | } |
| 5001 | default: |
| 5002 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5003 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5007 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5008 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5009 | Location left = locations->InAt(0); |
| 5010 | Location right = locations->InAt(1); |
| 5011 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5012 | Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5013 | Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5014 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5015 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5016 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5017 | case Primitive::kPrimBoolean: |
| 5018 | case Primitive::kPrimByte: |
| 5019 | case Primitive::kPrimShort: |
| 5020 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5021 | case Primitive::kPrimInt: { |
| 5022 | __ LoadImmediate(out, 0); |
| 5023 | __ cmp(left.AsRegister<Register>(), |
| 5024 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 5025 | less_cond = LT; |
| 5026 | break; |
| 5027 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5028 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5029 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 5030 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5031 | __ b(&less, LT); |
| 5032 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5033 | // 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] | 5034 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5035 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 5036 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5037 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | case Primitive::kPrimFloat: |
| 5041 | case Primitive::kPrimDouble: { |
| 5042 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5043 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5044 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5045 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5046 | break; |
| 5047 | } |
| 5048 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5049 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5050 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5051 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5052 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5053 | __ b(final_label, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5054 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5055 | |
| 5056 | __ Bind(&greater); |
| 5057 | __ LoadImmediate(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5058 | __ b(final_label); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5059 | |
| 5060 | __ Bind(&less); |
| 5061 | __ LoadImmediate(out, -1); |
| 5062 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5063 | if (done.IsLinked()) { |
| 5064 | __ Bind(&done); |
| 5065 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5066 | } |
| 5067 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5068 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5069 | LocationSummary* locations = |
| 5070 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5071 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5072 | locations->SetInAt(i, Location::Any()); |
| 5073 | } |
| 5074 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5075 | } |
| 5076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5077 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5078 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5079 | } |
| 5080 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5081 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5082 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5083 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5084 | switch (kind) { |
| 5085 | case MemBarrierKind::kAnyStore: |
| 5086 | case MemBarrierKind::kLoadAny: |
| 5087 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5088 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5089 | break; |
| 5090 | } |
| 5091 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5092 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5093 | break; |
| 5094 | } |
| 5095 | default: |
| 5096 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5097 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5098 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5102 | uint32_t offset, |
| 5103 | Register out_lo, |
| 5104 | Register out_hi) { |
| 5105 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5106 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5107 | // `offset` into `out_lo` does not clutter `addr`. |
| 5108 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5109 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5110 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5111 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5112 | } |
| 5113 | __ ldrexd(out_lo, out_hi, addr); |
| 5114 | } |
| 5115 | |
| 5116 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5117 | uint32_t offset, |
| 5118 | Register value_lo, |
| 5119 | Register value_hi, |
| 5120 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5121 | Register temp2, |
| 5122 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5123 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5124 | if (offset != 0) { |
| 5125 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5126 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5127 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5128 | } |
| 5129 | __ Bind(&fail); |
| 5130 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5131 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5132 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5133 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5135 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5136 | } |
| 5137 | |
| 5138 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5139 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5140 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5141 | LocationSummary* locations = |
| 5142 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5143 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5144 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5145 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5146 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5147 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5148 | } else { |
| 5149 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5150 | } |
| 5151 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5152 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5153 | bool generate_volatile = field_info.IsVolatile() |
| 5154 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5155 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5156 | bool needs_write_barrier = |
| 5157 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5158 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5159 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5160 | if (needs_write_barrier) { |
| 5161 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5162 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5163 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5164 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5165 | // - registers need to be consecutive |
| 5166 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5167 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5168 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5169 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5170 | |
| 5171 | locations->AddTemp(Location::RequiresRegister()); |
| 5172 | locations->AddTemp(Location::RequiresRegister()); |
| 5173 | if (field_type == Primitive::kPrimDouble) { |
| 5174 | // For doubles we need two more registers to copy the value. |
| 5175 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5176 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5177 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5178 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5179 | } |
| 5180 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5181 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5182 | const FieldInfo& field_info, |
| 5183 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5185 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5186 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5187 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5188 | Location value = locations->InAt(1); |
| 5189 | |
| 5190 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5191 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5192 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5193 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5194 | bool needs_write_barrier = |
| 5195 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5196 | |
| 5197 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5198 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5199 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5200 | |
| 5201 | switch (field_type) { |
| 5202 | case Primitive::kPrimBoolean: |
| 5203 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5204 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5205 | break; |
| 5206 | } |
| 5207 | |
| 5208 | case Primitive::kPrimShort: |
| 5209 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5210 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5211 | break; |
| 5212 | } |
| 5213 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5214 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5215 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5216 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5217 | // Note that in the case where `value` is a null reference, |
| 5218 | // we do not enter this block, as a null reference does not |
| 5219 | // need poisoning. |
| 5220 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5221 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5222 | __ Mov(temp, value.AsRegister<Register>()); |
| 5223 | __ PoisonHeapReference(temp); |
| 5224 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5225 | } else { |
| 5226 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5227 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5228 | break; |
| 5229 | } |
| 5230 | |
| 5231 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5232 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5233 | GenerateWideAtomicStore(base, offset, |
| 5234 | value.AsRegisterPairLow<Register>(), |
| 5235 | value.AsRegisterPairHigh<Register>(), |
| 5236 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5237 | locations->GetTemp(1).AsRegister<Register>(), |
| 5238 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5239 | } else { |
| 5240 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5241 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5242 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5243 | break; |
| 5244 | } |
| 5245 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5246 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5247 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5248 | break; |
| 5249 | } |
| 5250 | |
| 5251 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5252 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5253 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5254 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5255 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5256 | |
| 5257 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5258 | |
| 5259 | GenerateWideAtomicStore(base, offset, |
| 5260 | value_reg_lo, |
| 5261 | value_reg_hi, |
| 5262 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5263 | locations->GetTemp(3).AsRegister<Register>(), |
| 5264 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5265 | } else { |
| 5266 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5267 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5268 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5269 | break; |
| 5270 | } |
| 5271 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5272 | case Primitive::kPrimVoid: |
| 5273 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5274 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5275 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5276 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5277 | // Longs and doubles are handled in the switch. |
| 5278 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5279 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5280 | } |
| 5281 | |
| 5282 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5283 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5284 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5285 | codegen_->MarkGCCard( |
| 5286 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5289 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5290 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5291 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5292 | } |
| 5293 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5294 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5295 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5296 | |
| 5297 | bool object_field_get_with_read_barrier = |
| 5298 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5299 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5300 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5301 | object_field_get_with_read_barrier ? |
| 5302 | LocationSummary::kCallOnSlowPath : |
| 5303 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5304 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5305 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5306 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5307 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5308 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5309 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5310 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5311 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5312 | // The output overlaps in case of volatile long: we don't want the |
| 5313 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5314 | // object's location. Likewise, in the case of an object field get |
| 5315 | // with read barriers enabled, we do not want the load to overwrite |
| 5316 | // the object's location, as we need it to emit the read barrier. |
| 5317 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5318 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5319 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5320 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5321 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5322 | } else { |
| 5323 | locations->SetOut(Location::RequiresRegister(), |
| 5324 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5325 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5326 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5327 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5328 | // - registers need to be consecutive |
| 5329 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5330 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5331 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5332 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5333 | locations->AddTemp(Location::RequiresRegister()); |
| 5334 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5335 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5336 | // We need a temporary register for the read barrier marking slow |
| 5337 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5338 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5339 | !Runtime::Current()->UseJitCompilation()) { |
| 5340 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5341 | // loads we need a temporary only if the offset is too big. |
| 5342 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5343 | locations->AddTemp(Location::RequiresRegister()); |
| 5344 | } |
| 5345 | // And we always need the reserved entrypoint register. |
| 5346 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5347 | } else { |
| 5348 | locations->AddTemp(Location::RequiresRegister()); |
| 5349 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5350 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5353 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5354 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5355 | << input->GetType(); |
| 5356 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5357 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5358 | return Location::ConstantLocation(input->AsConstant()); |
| 5359 | } else { |
| 5360 | return Location::RequiresFpuRegister(); |
| 5361 | } |
| 5362 | } |
| 5363 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5364 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5365 | Opcode opcode) { |
| 5366 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5367 | if (constant->IsConstant() && |
| 5368 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5369 | return Location::ConstantLocation(constant->AsConstant()); |
| 5370 | } |
| 5371 | return Location::RequiresRegister(); |
| 5372 | } |
| 5373 | |
| 5374 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5375 | Opcode opcode) { |
| 5376 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5377 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5378 | Opcode high_opcode = opcode; |
| 5379 | SetCc low_set_cc = kCcDontCare; |
| 5380 | switch (opcode) { |
| 5381 | case SUB: |
| 5382 | // Flip the operation to an ADD. |
| 5383 | value = -value; |
| 5384 | opcode = ADD; |
| 5385 | FALLTHROUGH_INTENDED; |
| 5386 | case ADD: |
| 5387 | if (Low32Bits(value) == 0u) { |
| 5388 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5389 | } |
| 5390 | high_opcode = ADC; |
| 5391 | low_set_cc = kCcSet; |
| 5392 | break; |
| 5393 | default: |
| 5394 | break; |
| 5395 | } |
| 5396 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5397 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5398 | } else { |
| 5399 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5400 | } |
| 5401 | } |
| 5402 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5403 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5404 | Opcode opcode, |
| 5405 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5406 | ShifterOperand so; |
| 5407 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5408 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5409 | return true; |
| 5410 | } |
| 5411 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5412 | uint32_t neg_value = 0; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5413 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5414 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5415 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5416 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5417 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5418 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5419 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5420 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5421 | default: |
| 5422 | return false; |
| 5423 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5424 | |
| 5425 | if (assembler->ShifterOperandCanHold(kNoRegister, |
| 5426 | kNoRegister, |
| 5427 | neg_opcode, |
| 5428 | neg_value, |
| 5429 | set_cc, |
| 5430 | &so)) { |
| 5431 | return true; |
| 5432 | } |
| 5433 | |
| 5434 | return opcode == AND && IsPowerOfTwo(value + 1); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5437 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5438 | const FieldInfo& field_info) { |
| 5439 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5440 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5441 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5442 | Location base_loc = locations->InAt(0); |
| 5443 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5444 | Location out = locations->Out(); |
| 5445 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5446 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5447 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5448 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5449 | |
| 5450 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5451 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5452 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5453 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5454 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5455 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5456 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5457 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5458 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5459 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5460 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5461 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5462 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5463 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5464 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5465 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5466 | |
| 5467 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5468 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5469 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5470 | |
| 5471 | case Primitive::kPrimNot: { |
| 5472 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5473 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5474 | Location temp_loc = locations->GetTemp(0); |
| 5475 | // Note that a potential implicit null check is handled in this |
| 5476 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5477 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5478 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5479 | if (is_volatile) { |
| 5480 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5481 | } |
| 5482 | } else { |
| 5483 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5484 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5485 | if (is_volatile) { |
| 5486 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5487 | } |
| 5488 | // If read barriers are enabled, emit read barriers other than |
| 5489 | // Baker's using a slow path (and also unpoison the loaded |
| 5490 | // reference, if heap poisoning is enabled). |
| 5491 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5492 | } |
| 5493 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5494 | } |
| 5495 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5496 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5497 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5498 | GenerateWideAtomicLoad(base, offset, |
| 5499 | out.AsRegisterPairLow<Register>(), |
| 5500 | out.AsRegisterPairHigh<Register>()); |
| 5501 | } else { |
| 5502 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5503 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5504 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5505 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5506 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5507 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5508 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5509 | |
| 5510 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5511 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5512 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5513 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5514 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5515 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5517 | __ vmovdrr(out_reg, lo, hi); |
| 5518 | } else { |
| 5519 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5521 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5522 | break; |
| 5523 | } |
| 5524 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5525 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5526 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5527 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5528 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5529 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5530 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5531 | // Potential implicit null checks, in the case of reference or |
| 5532 | // double fields, are handled in the previous switch statement. |
| 5533 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5534 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5535 | } |
| 5536 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5537 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5538 | if (field_type == Primitive::kPrimNot) { |
| 5539 | // Memory barriers, in the case of references, are also handled |
| 5540 | // in the previous switch statement. |
| 5541 | } else { |
| 5542 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5543 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5544 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5548 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5552 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5556 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5557 | } |
| 5558 | |
| 5559 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5560 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5561 | } |
| 5562 | |
| 5563 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5564 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5565 | } |
| 5566 | |
| 5567 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5568 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5569 | } |
| 5570 | |
| 5571 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5572 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5573 | } |
| 5574 | |
| 5575 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5576 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5577 | } |
| 5578 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5579 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5580 | HUnresolvedInstanceFieldGet* instruction) { |
| 5581 | FieldAccessCallingConventionARM calling_convention; |
| 5582 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5583 | instruction, instruction->GetFieldType(), calling_convention); |
| 5584 | } |
| 5585 | |
| 5586 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5587 | HUnresolvedInstanceFieldGet* instruction) { |
| 5588 | FieldAccessCallingConventionARM calling_convention; |
| 5589 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5590 | instruction->GetFieldType(), |
| 5591 | instruction->GetFieldIndex(), |
| 5592 | instruction->GetDexPc(), |
| 5593 | calling_convention); |
| 5594 | } |
| 5595 | |
| 5596 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5597 | HUnresolvedInstanceFieldSet* instruction) { |
| 5598 | FieldAccessCallingConventionARM calling_convention; |
| 5599 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5600 | instruction, instruction->GetFieldType(), calling_convention); |
| 5601 | } |
| 5602 | |
| 5603 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5604 | HUnresolvedInstanceFieldSet* instruction) { |
| 5605 | FieldAccessCallingConventionARM calling_convention; |
| 5606 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5607 | instruction->GetFieldType(), |
| 5608 | instruction->GetFieldIndex(), |
| 5609 | instruction->GetDexPc(), |
| 5610 | calling_convention); |
| 5611 | } |
| 5612 | |
| 5613 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5614 | HUnresolvedStaticFieldGet* instruction) { |
| 5615 | FieldAccessCallingConventionARM calling_convention; |
| 5616 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5617 | instruction, instruction->GetFieldType(), calling_convention); |
| 5618 | } |
| 5619 | |
| 5620 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5621 | HUnresolvedStaticFieldGet* instruction) { |
| 5622 | FieldAccessCallingConventionARM calling_convention; |
| 5623 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5624 | instruction->GetFieldType(), |
| 5625 | instruction->GetFieldIndex(), |
| 5626 | instruction->GetDexPc(), |
| 5627 | calling_convention); |
| 5628 | } |
| 5629 | |
| 5630 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5631 | HUnresolvedStaticFieldSet* instruction) { |
| 5632 | FieldAccessCallingConventionARM calling_convention; |
| 5633 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5634 | instruction, instruction->GetFieldType(), calling_convention); |
| 5635 | } |
| 5636 | |
| 5637 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5638 | HUnresolvedStaticFieldSet* instruction) { |
| 5639 | FieldAccessCallingConventionARM calling_convention; |
| 5640 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5641 | instruction->GetFieldType(), |
| 5642 | instruction->GetFieldIndex(), |
| 5643 | instruction->GetDexPc(), |
| 5644 | calling_convention); |
| 5645 | } |
| 5646 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5647 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5648 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5649 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5650 | } |
| 5651 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5652 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5653 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5654 | return; |
| 5655 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5656 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5657 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5658 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5659 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5662 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5663 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5664 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5665 | |
| 5666 | LocationSummary* locations = instruction->GetLocations(); |
| 5667 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5668 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5669 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5670 | } |
| 5671 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5672 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5673 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5674 | } |
| 5675 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5676 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5677 | switch (type) { |
| 5678 | case Primitive::kPrimNot: |
| 5679 | return kLoadWord; |
| 5680 | case Primitive::kPrimBoolean: |
| 5681 | return kLoadUnsignedByte; |
| 5682 | case Primitive::kPrimByte: |
| 5683 | return kLoadSignedByte; |
| 5684 | case Primitive::kPrimChar: |
| 5685 | return kLoadUnsignedHalfword; |
| 5686 | case Primitive::kPrimShort: |
| 5687 | return kLoadSignedHalfword; |
| 5688 | case Primitive::kPrimInt: |
| 5689 | return kLoadWord; |
| 5690 | case Primitive::kPrimLong: |
| 5691 | return kLoadWordPair; |
| 5692 | case Primitive::kPrimFloat: |
| 5693 | return kLoadSWord; |
| 5694 | case Primitive::kPrimDouble: |
| 5695 | return kLoadDWord; |
| 5696 | default: |
| 5697 | LOG(FATAL) << "Unreachable type " << type; |
| 5698 | UNREACHABLE(); |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5703 | switch (type) { |
| 5704 | case Primitive::kPrimNot: |
| 5705 | return kStoreWord; |
| 5706 | case Primitive::kPrimBoolean: |
| 5707 | case Primitive::kPrimByte: |
| 5708 | return kStoreByte; |
| 5709 | case Primitive::kPrimChar: |
| 5710 | case Primitive::kPrimShort: |
| 5711 | return kStoreHalfword; |
| 5712 | case Primitive::kPrimInt: |
| 5713 | return kStoreWord; |
| 5714 | case Primitive::kPrimLong: |
| 5715 | return kStoreWordPair; |
| 5716 | case Primitive::kPrimFloat: |
| 5717 | return kStoreSWord; |
| 5718 | case Primitive::kPrimDouble: |
| 5719 | return kStoreDWord; |
| 5720 | default: |
| 5721 | LOG(FATAL) << "Unreachable type " << type; |
| 5722 | UNREACHABLE(); |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5727 | Location out_loc, |
| 5728 | Register base, |
| 5729 | Register reg_offset, |
| 5730 | Condition cond) { |
| 5731 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5732 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5733 | |
| 5734 | switch (type) { |
| 5735 | case Primitive::kPrimByte: |
| 5736 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5737 | break; |
| 5738 | case Primitive::kPrimBoolean: |
| 5739 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5740 | break; |
| 5741 | case Primitive::kPrimShort: |
| 5742 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5743 | break; |
| 5744 | case Primitive::kPrimChar: |
| 5745 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5746 | break; |
| 5747 | case Primitive::kPrimNot: |
| 5748 | case Primitive::kPrimInt: |
| 5749 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5750 | break; |
| 5751 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5752 | case Primitive::kPrimLong: |
| 5753 | case Primitive::kPrimFloat: |
| 5754 | case Primitive::kPrimDouble: |
| 5755 | default: |
| 5756 | LOG(FATAL) << "Unreachable type " << type; |
| 5757 | UNREACHABLE(); |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5762 | Location loc, |
| 5763 | Register base, |
| 5764 | Register reg_offset, |
| 5765 | Condition cond) { |
| 5766 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5767 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5768 | |
| 5769 | switch (type) { |
| 5770 | case Primitive::kPrimByte: |
| 5771 | case Primitive::kPrimBoolean: |
| 5772 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5773 | break; |
| 5774 | case Primitive::kPrimShort: |
| 5775 | case Primitive::kPrimChar: |
| 5776 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5777 | break; |
| 5778 | case Primitive::kPrimNot: |
| 5779 | case Primitive::kPrimInt: |
| 5780 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5781 | break; |
| 5782 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5783 | case Primitive::kPrimLong: |
| 5784 | case Primitive::kPrimFloat: |
| 5785 | case Primitive::kPrimDouble: |
| 5786 | default: |
| 5787 | LOG(FATAL) << "Unreachable type " << type; |
| 5788 | UNREACHABLE(); |
| 5789 | } |
| 5790 | } |
| 5791 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5792 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5793 | bool object_array_get_with_read_barrier = |
| 5794 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5795 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5796 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5797 | object_array_get_with_read_barrier ? |
| 5798 | LocationSummary::kCallOnSlowPath : |
| 5799 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5800 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5801 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5802 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5803 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5804 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5805 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5806 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5807 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5808 | // The output overlaps in the case of an object array get with |
| 5809 | // read barriers enabled: we do not want the move to overwrite the |
| 5810 | // array's location, as we need it to emit the read barrier. |
| 5811 | locations->SetOut( |
| 5812 | Location::RequiresRegister(), |
| 5813 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5814 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5815 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5816 | // We need a temporary register for the read barrier marking slow |
| 5817 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 5818 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5819 | !Runtime::Current()->UseJitCompilation() && |
| 5820 | instruction->GetIndex()->IsConstant()) { |
| 5821 | // Array loads with constant index are treated as field loads. |
| 5822 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5823 | // constant index loads we need a temporary only if the offset is too big. |
| 5824 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5825 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 5826 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5827 | if (offset >= kReferenceLoadMinFarOffset) { |
| 5828 | locations->AddTemp(Location::RequiresRegister()); |
| 5829 | } |
| 5830 | // And we always need the reserved entrypoint register. |
| 5831 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5832 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 5833 | !Runtime::Current()->UseJitCompilation() && |
| 5834 | !instruction->GetIndex()->IsConstant()) { |
| 5835 | // We need a non-scratch temporary for the array data pointer. |
| 5836 | locations->AddTemp(Location::RequiresRegister()); |
| 5837 | // And we always need the reserved entrypoint register. |
| 5838 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5839 | } else { |
| 5840 | locations->AddTemp(Location::RequiresRegister()); |
| 5841 | } |
| 5842 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5843 | // Also need a temporary for String compression feature. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5844 | locations->AddTemp(Location::RequiresRegister()); |
| 5845 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5849 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5850 | Location obj_loc = locations->InAt(0); |
| 5851 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5852 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5853 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5854 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5855 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5856 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5857 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5858 | HInstruction* array_instr = instruction->GetArray(); |
| 5859 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5860 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5861 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5862 | case Primitive::kPrimBoolean: |
| 5863 | case Primitive::kPrimByte: |
| 5864 | case Primitive::kPrimShort: |
| 5865 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5866 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5867 | Register length; |
| 5868 | if (maybe_compressed_char_at) { |
| 5869 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5870 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5871 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5872 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5873 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5874 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5875 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5876 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5877 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5878 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5879 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5880 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5881 | "Expecting 0=compressed, 1=uncompressed"); |
| 5882 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5883 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5884 | out_loc.AsRegister<Register>(), |
| 5885 | obj, |
| 5886 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5887 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5888 | __ Bind(&uncompressed_load); |
| 5889 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5890 | out_loc.AsRegister<Register>(), |
| 5891 | obj, |
| 5892 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5893 | if (done.IsLinked()) { |
| 5894 | __ Bind(&done); |
| 5895 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5896 | } else { |
| 5897 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5898 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5899 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5900 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5901 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5902 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5903 | Register temp = IP; |
| 5904 | |
| 5905 | if (has_intermediate_address) { |
| 5906 | // We do not need to compute the intermediate address from the array: the |
| 5907 | // input instruction has done it already. See the comment in |
| 5908 | // `TryExtractArrayAccessAddress()`. |
| 5909 | if (kIsDebugBuild) { |
| 5910 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5911 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5912 | } |
| 5913 | temp = obj; |
| 5914 | } else { |
| 5915 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5916 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5917 | if (maybe_compressed_char_at) { |
| 5918 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5919 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5920 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5921 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5922 | "Expecting 0=compressed, 1=uncompressed"); |
| 5923 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5924 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5925 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5926 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5927 | __ Bind(&uncompressed_load); |
| 5928 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5929 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5930 | if (done.IsLinked()) { |
| 5931 | __ Bind(&done); |
| 5932 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5933 | } else { |
| 5934 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5935 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5936 | } |
| 5937 | break; |
| 5938 | } |
| 5939 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5940 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5941 | // The read barrier instrumentation of object ArrayGet |
| 5942 | // instructions does not support the HIntermediateAddress |
| 5943 | // instruction. |
| 5944 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5945 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5946 | static_assert( |
| 5947 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5948 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5949 | // /* HeapReference<Object> */ out = |
| 5950 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5951 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5952 | Location temp = locations->GetTemp(0); |
| 5953 | // Note that a potential implicit null check is handled in this |
| 5954 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5955 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 5956 | if (index.IsConstant()) { |
| 5957 | // Array load with a constant index can be treated as a field load. |
| 5958 | data_offset += helpers::Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 5959 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5960 | out_loc, |
| 5961 | obj, |
| 5962 | data_offset, |
| 5963 | locations->GetTemp(0), |
| 5964 | /* needs_null_check */ false); |
| 5965 | } else { |
| 5966 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5967 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 5968 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5969 | } else { |
| 5970 | Register out = out_loc.AsRegister<Register>(); |
| 5971 | if (index.IsConstant()) { |
| 5972 | size_t offset = |
| 5973 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5974 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5975 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5976 | // If read barriers are enabled, emit read barriers other than |
| 5977 | // Baker's using a slow path (and also unpoison the loaded |
| 5978 | // reference, if heap poisoning is enabled). |
| 5979 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5980 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5981 | Register temp = IP; |
| 5982 | |
| 5983 | if (has_intermediate_address) { |
| 5984 | // We do not need to compute the intermediate address from the array: the |
| 5985 | // input instruction has done it already. See the comment in |
| 5986 | // `TryExtractArrayAccessAddress()`. |
| 5987 | if (kIsDebugBuild) { |
| 5988 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5989 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5990 | } |
| 5991 | temp = obj; |
| 5992 | } else { |
| 5993 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5994 | } |
| 5995 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5996 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5998 | // If read barriers are enabled, emit read barriers other than |
| 5999 | // Baker's using a slow path (and also unpoison the loaded |
| 6000 | // reference, if heap poisoning is enabled). |
| 6001 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6002 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6003 | } |
| 6004 | } |
| 6005 | break; |
| 6006 | } |
| 6007 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6008 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6009 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6010 | size_t offset = |
| 6011 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6012 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6013 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6014 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6015 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6016 | } |
| 6017 | break; |
| 6018 | } |
| 6019 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6020 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6021 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6022 | if (index.IsConstant()) { |
| 6023 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6024 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6025 | } else { |
| 6026 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6027 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6028 | } |
| 6029 | break; |
| 6030 | } |
| 6031 | |
| 6032 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6033 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6034 | if (index.IsConstant()) { |
| 6035 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6036 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6037 | } else { |
| 6038 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6039 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6040 | } |
| 6041 | break; |
| 6042 | } |
| 6043 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6044 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6045 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6046 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6047 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6048 | |
| 6049 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6050 | // Potential implicit null checks, in the case of reference |
| 6051 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6052 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6053 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6054 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6058 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6059 | |
| 6060 | bool needs_write_barrier = |
| 6061 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6062 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6063 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6064 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6065 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 6066 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6067 | LocationSummary::kCallOnSlowPath : |
| 6068 | LocationSummary::kNoCall); |
| 6069 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6071 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6072 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6073 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6074 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6075 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6076 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6077 | if (needs_write_barrier) { |
| 6078 | // Temporary registers for the write barrier. |
| 6079 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6080 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6081 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 6085 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6086 | Location array_loc = locations->InAt(0); |
| 6087 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6088 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6089 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6090 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6091 | bool needs_write_barrier = |
| 6092 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6093 | uint32_t data_offset = |
| 6094 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6095 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6096 | HInstruction* array_instr = instruction->GetArray(); |
| 6097 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6098 | |
| 6099 | switch (value_type) { |
| 6100 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6101 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6102 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6103 | case Primitive::kPrimChar: |
| 6104 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6105 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6106 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 6107 | uint32_t full_offset = |
| 6108 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6109 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6110 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6111 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6112 | Register temp = IP; |
| 6113 | |
| 6114 | if (has_intermediate_address) { |
| 6115 | // We do not need to compute the intermediate address from the array: the |
| 6116 | // input instruction has done it already. See the comment in |
| 6117 | // `TryExtractArrayAccessAddress()`. |
| 6118 | if (kIsDebugBuild) { |
| 6119 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6120 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 6121 | } |
| 6122 | temp = array; |
| 6123 | } else { |
| 6124 | __ add(temp, array, ShifterOperand(data_offset)); |
| 6125 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6126 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6127 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6128 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6129 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6130 | } |
| 6131 | break; |
| 6132 | } |
| 6133 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6134 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6135 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6136 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6137 | // See the comment in instruction_simplifier_shared.cc. |
| 6138 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6139 | |
| 6140 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6141 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6142 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6143 | size_t offset = |
| 6144 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6145 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6146 | } else { |
| 6147 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6148 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6149 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6150 | value_loc, |
| 6151 | IP, |
| 6152 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6153 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 6154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6155 | DCHECK(!needs_write_barrier); |
| 6156 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6157 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6158 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6159 | |
| 6160 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6161 | Location temp1_loc = locations->GetTemp(0); |
| 6162 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6163 | Location temp2_loc = locations->GetTemp(1); |
| 6164 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6165 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6166 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6167 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6168 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6169 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6170 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6171 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6172 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6173 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6174 | codegen_->AddSlowPath(slow_path); |
| 6175 | if (instruction->GetValueCanBeNull()) { |
| 6176 | Label non_zero; |
| 6177 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6178 | if (index.IsConstant()) { |
| 6179 | size_t offset = |
| 6180 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6181 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6182 | } else { |
| 6183 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6184 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6185 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6186 | value_loc, |
| 6187 | IP, |
| 6188 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6189 | } |
| 6190 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6191 | __ b(final_label); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6192 | __ Bind(&non_zero); |
| 6193 | } |
| 6194 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6195 | // Note that when read barriers are enabled, the type checks |
| 6196 | // are performed without read barriers. This is fine, even in |
| 6197 | // the case where a class object is in the from-space after |
| 6198 | // the flip, as a comparison involving such a type would not |
| 6199 | // produce a false positive; it may of course produce a false |
| 6200 | // negative, in which case we would take the ArraySet slow |
| 6201 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6202 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6203 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6204 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6205 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6206 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6207 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6208 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6209 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6210 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6211 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6212 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6213 | // nor `temp2`, as we are comparing two poisoned references. |
| 6214 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6215 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6216 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6217 | Label do_put; |
| 6218 | __ b(&do_put, EQ); |
| 6219 | // If heap poisoning is enabled, the `temp1` reference has |
| 6220 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6221 | __ MaybeUnpoisonHeapReference(temp1); |
| 6222 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6223 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6224 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6225 | // If heap poisoning is enabled, no need to unpoison |
| 6226 | // `temp1`, as we are comparing against null below. |
| 6227 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6228 | __ Bind(&do_put); |
| 6229 | } else { |
| 6230 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6231 | } |
| 6232 | } |
| 6233 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6234 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6235 | if (kPoisonHeapReferences) { |
| 6236 | // Note that in the case where `value` is a null reference, |
| 6237 | // we do not enter this block, as a null reference does not |
| 6238 | // need poisoning. |
| 6239 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6240 | __ Mov(temp1, value); |
| 6241 | __ PoisonHeapReference(temp1); |
| 6242 | source = temp1; |
| 6243 | } |
| 6244 | |
| 6245 | if (index.IsConstant()) { |
| 6246 | size_t offset = |
| 6247 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6248 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6249 | } else { |
| 6250 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6251 | |
| 6252 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6253 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6254 | Location::RegisterLocation(source), |
| 6255 | IP, |
| 6256 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6257 | } |
| 6258 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6259 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6260 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6261 | } |
| 6262 | |
| 6263 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6264 | |
| 6265 | if (done.IsLinked()) { |
| 6266 | __ Bind(&done); |
| 6267 | } |
| 6268 | |
| 6269 | if (slow_path != nullptr) { |
| 6270 | __ Bind(slow_path->GetExitLabel()); |
| 6271 | } |
| 6272 | |
| 6273 | break; |
| 6274 | } |
| 6275 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6276 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6277 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6278 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6279 | size_t offset = |
| 6280 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6281 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6282 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6283 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6284 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6285 | } |
| 6286 | break; |
| 6287 | } |
| 6288 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6289 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6290 | Location value = locations->InAt(2); |
| 6291 | DCHECK(value.IsFpuRegister()); |
| 6292 | if (index.IsConstant()) { |
| 6293 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6294 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6295 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6296 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6297 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6298 | } |
| 6299 | break; |
| 6300 | } |
| 6301 | |
| 6302 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6303 | Location value = locations->InAt(2); |
| 6304 | DCHECK(value.IsFpuRegisterPair()); |
| 6305 | if (index.IsConstant()) { |
| 6306 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6307 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6308 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6309 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6310 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6311 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6312 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6313 | break; |
| 6314 | } |
| 6315 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6316 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6317 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6318 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6319 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6320 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6321 | // Objects are handled in the switch. |
| 6322 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6323 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6324 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6328 | LocationSummary* locations = |
| 6329 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6330 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6331 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6335 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6336 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6337 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6338 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6339 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6340 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6341 | // Mask out compression flag from String's array length. |
| 6342 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6343 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6344 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6345 | } |
| 6346 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6347 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6348 | LocationSummary* locations = |
| 6349 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6350 | |
| 6351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6352 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6354 | } |
| 6355 | |
| 6356 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6357 | LocationSummary* locations = instruction->GetLocations(); |
| 6358 | Location out = locations->Out(); |
| 6359 | Location first = locations->InAt(0); |
| 6360 | Location second = locations->InAt(1); |
| 6361 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6362 | if (second.IsRegister()) { |
| 6363 | __ add(out.AsRegister<Register>(), |
| 6364 | first.AsRegister<Register>(), |
| 6365 | ShifterOperand(second.AsRegister<Register>())); |
| 6366 | } else { |
| 6367 | __ AddConstant(out.AsRegister<Register>(), |
| 6368 | first.AsRegister<Register>(), |
| 6369 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6370 | } |
| 6371 | } |
| 6372 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6373 | void LocationsBuilderARM::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 6374 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6375 | } |
| 6376 | |
| 6377 | void InstructionCodeGeneratorARM::VisitIntermediateAddressIndex( |
| 6378 | HIntermediateAddressIndex* instruction) { |
| 6379 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6380 | } |
| 6381 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6382 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6383 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6384 | InvokeRuntimeCallingConvention calling_convention; |
| 6385 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6386 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6387 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6388 | |
| 6389 | HInstruction* index = instruction->InputAt(0); |
| 6390 | HInstruction* length = instruction->InputAt(1); |
| 6391 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6392 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6393 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6394 | // locations. |
| 6395 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6396 | locations->SetInAt(0, both_const |
| 6397 | ? Location::ConstantLocation(index->AsConstant()) |
| 6398 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6399 | locations->SetInAt(1, both_const |
| 6400 | ? Location::ConstantLocation(length->AsConstant()) |
| 6401 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6402 | } |
| 6403 | |
| 6404 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6405 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6406 | Location index_loc = locations->InAt(0); |
| 6407 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6408 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6409 | if (length_loc.IsConstant()) { |
| 6410 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6411 | if (index_loc.IsConstant()) { |
| 6412 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6413 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6414 | if (index < 0 || index >= length) { |
| 6415 | SlowPathCodeARM* slow_path = |
| 6416 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6417 | codegen_->AddSlowPath(slow_path); |
| 6418 | __ b(slow_path->GetEntryLabel()); |
| 6419 | } else { |
| 6420 | // Some optimization after BCE may have generated this, and we should not |
| 6421 | // generate a bounds check if it is a valid range. |
| 6422 | } |
| 6423 | return; |
| 6424 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6425 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6426 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6427 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6428 | codegen_->AddSlowPath(slow_path); |
| 6429 | __ b(slow_path->GetEntryLabel(), HS); |
| 6430 | } else { |
| 6431 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6432 | if (index_loc.IsConstant()) { |
| 6433 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6434 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6435 | } else { |
| 6436 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6437 | } |
| 6438 | codegen_->AddSlowPath(slow_path); |
| 6439 | __ b(slow_path->GetEntryLabel(), LS); |
| 6440 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6441 | } |
| 6442 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6443 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6444 | Register card, |
| 6445 | Register object, |
| 6446 | Register value, |
| 6447 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6448 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6449 | if (can_be_null) { |
| 6450 | __ CompareAndBranchIfZero(value, &is_null); |
| 6451 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6452 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6453 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6454 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6455 | if (can_be_null) { |
| 6456 | __ Bind(&is_null); |
| 6457 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6458 | } |
| 6459 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6460 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6461 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6465 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6466 | } |
| 6467 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6468 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6469 | LocationSummary* locations = |
| 6470 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6471 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6472 | } |
| 6473 | |
| 6474 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6475 | HBasicBlock* block = instruction->GetBlock(); |
| 6476 | if (block->GetLoopInformation() != nullptr) { |
| 6477 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6478 | // The back edge will generate the suspend check. |
| 6479 | return; |
| 6480 | } |
| 6481 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6482 | // The goto will generate the suspend check. |
| 6483 | return; |
| 6484 | } |
| 6485 | GenerateSuspendCheck(instruction, nullptr); |
| 6486 | } |
| 6487 | |
| 6488 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6489 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6490 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6491 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6492 | if (slow_path == nullptr) { |
| 6493 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6494 | instruction->SetSlowPath(slow_path); |
| 6495 | codegen_->AddSlowPath(slow_path); |
| 6496 | if (successor != nullptr) { |
| 6497 | DCHECK(successor->IsLoopHeader()); |
| 6498 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6499 | } |
| 6500 | } else { |
| 6501 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6502 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6503 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6504 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6505 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6506 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6507 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6508 | __ Bind(slow_path->GetReturnLabel()); |
| 6509 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6510 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6511 | __ b(slow_path->GetEntryLabel()); |
| 6512 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6515 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6516 | return codegen_->GetAssembler(); |
| 6517 | } |
| 6518 | |
| 6519 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6520 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6521 | Location source = move->GetSource(); |
| 6522 | Location destination = move->GetDestination(); |
| 6523 | |
| 6524 | if (source.IsRegister()) { |
| 6525 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6526 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6527 | } else if (destination.IsFpuRegister()) { |
| 6528 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6529 | } else { |
| 6530 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6531 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6532 | SP, destination.GetStackIndex()); |
| 6533 | } |
| 6534 | } else if (source.IsStackSlot()) { |
| 6535 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6536 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6537 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6538 | } else if (destination.IsFpuRegister()) { |
| 6539 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6540 | } else { |
| 6541 | DCHECK(destination.IsStackSlot()); |
| 6542 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6543 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6544 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6545 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6546 | if (destination.IsRegister()) { |
| 6547 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6548 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6549 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6550 | } else { |
| 6551 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6552 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6553 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6554 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6555 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6556 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6557 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6558 | } else if (destination.IsRegisterPair()) { |
| 6559 | DCHECK(ExpectedPairLayout(destination)); |
| 6560 | __ LoadFromOffset( |
| 6561 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6562 | } else { |
| 6563 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6564 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6565 | SP, |
| 6566 | source.GetStackIndex()); |
| 6567 | } |
| 6568 | } else if (source.IsRegisterPair()) { |
| 6569 | if (destination.IsRegisterPair()) { |
| 6570 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6571 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6572 | } else if (destination.IsFpuRegisterPair()) { |
| 6573 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6574 | source.AsRegisterPairLow<Register>(), |
| 6575 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6576 | } else { |
| 6577 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6578 | DCHECK(ExpectedPairLayout(source)); |
| 6579 | __ StoreToOffset( |
| 6580 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6581 | } |
| 6582 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6583 | if (destination.IsRegisterPair()) { |
| 6584 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6585 | destination.AsRegisterPairHigh<Register>(), |
| 6586 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6587 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6588 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6589 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6590 | } else { |
| 6591 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6592 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6593 | SP, |
| 6594 | destination.GetStackIndex()); |
| 6595 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6596 | } else { |
| 6597 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6598 | HConstant* constant = source.GetConstant(); |
| 6599 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6600 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6601 | if (destination.IsRegister()) { |
| 6602 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6603 | } else { |
| 6604 | DCHECK(destination.IsStackSlot()); |
| 6605 | __ LoadImmediate(IP, value); |
| 6606 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6607 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6608 | } else if (constant->IsLongConstant()) { |
| 6609 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6610 | if (destination.IsRegisterPair()) { |
| 6611 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6612 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6613 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6614 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6615 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6616 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6617 | __ LoadImmediate(IP, High32Bits(value)); |
| 6618 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6619 | } |
| 6620 | } else if (constant->IsDoubleConstant()) { |
| 6621 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6622 | if (destination.IsFpuRegisterPair()) { |
| 6623 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6624 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6625 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6626 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6627 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6628 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6629 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6630 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6631 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6632 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6633 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6634 | float value = constant->AsFloatConstant()->GetValue(); |
| 6635 | if (destination.IsFpuRegister()) { |
| 6636 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6637 | } else { |
| 6638 | DCHECK(destination.IsStackSlot()); |
| 6639 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6640 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6641 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6642 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6647 | __ Mov(IP, reg); |
| 6648 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6649 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6650 | } |
| 6651 | |
| 6652 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6653 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6654 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6655 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6656 | SP, mem1 + stack_offset); |
| 6657 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6658 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6659 | SP, mem2 + stack_offset); |
| 6660 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6661 | } |
| 6662 | |
| 6663 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6664 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6665 | Location source = move->GetSource(); |
| 6666 | Location destination = move->GetDestination(); |
| 6667 | |
| 6668 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6669 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6670 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6671 | __ Mov(IP, source.AsRegister<Register>()); |
| 6672 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6673 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6674 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6675 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6676 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6677 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6678 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6679 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6680 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6681 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6682 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6683 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6684 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6685 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6686 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6687 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6688 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6689 | destination.AsRegisterPairHigh<Register>(), |
| 6690 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6691 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6692 | Register low_reg = source.IsRegisterPair() |
| 6693 | ? source.AsRegisterPairLow<Register>() |
| 6694 | : destination.AsRegisterPairLow<Register>(); |
| 6695 | int mem = source.IsRegisterPair() |
| 6696 | ? destination.GetStackIndex() |
| 6697 | : source.GetStackIndex(); |
| 6698 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6699 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6700 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6701 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6702 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6703 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6704 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6705 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6706 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6707 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6708 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6709 | DRegister reg = source.IsFpuRegisterPair() |
| 6710 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6711 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6712 | int mem = source.IsFpuRegisterPair() |
| 6713 | ? destination.GetStackIndex() |
| 6714 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6715 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6716 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6717 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6718 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6719 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6720 | : destination.AsFpuRegister<SRegister>(); |
| 6721 | int mem = source.IsFpuRegister() |
| 6722 | ? destination.GetStackIndex() |
| 6723 | : source.GetStackIndex(); |
| 6724 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6725 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6726 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6727 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6728 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6729 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6730 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6731 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6732 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6737 | __ Push(static_cast<Register>(reg)); |
| 6738 | } |
| 6739 | |
| 6740 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6741 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6742 | } |
| 6743 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6744 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6745 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6746 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6747 | case HLoadClass::LoadKind::kInvalid: |
| 6748 | LOG(FATAL) << "UNREACHABLE"; |
| 6749 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6750 | case HLoadClass::LoadKind::kReferrersClass: |
| 6751 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6752 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6753 | case HLoadClass::LoadKind::kBssEntry: |
| 6754 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6755 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6756 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6757 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6758 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame^] | 6759 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6760 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6761 | break; |
| 6762 | } |
| 6763 | return desired_class_load_kind; |
| 6764 | } |
| 6765 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6767 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6768 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6769 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6770 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6771 | cls, |
| 6772 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6773 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6774 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6775 | return; |
| 6776 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6777 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6778 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6779 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6780 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6781 | ? LocationSummary::kCallOnSlowPath |
| 6782 | : LocationSummary::kNoCall; |
| 6783 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6784 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6785 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6786 | } |
| 6787 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6788 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6789 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6790 | } |
| 6791 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6792 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6793 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6794 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6795 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6796 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6797 | locations->AddTemp(Location::RequiresRegister()); |
| 6798 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6799 | InvokeRuntimeCallingConvention calling_convention; |
| 6800 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6801 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6802 | // that the the kPrimNot result register is the same as the first argument register. |
| 6803 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6804 | } else { |
| 6805 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6806 | } |
| 6807 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6808 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6809 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 6810 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 6811 | !Runtime::Current()->UseJitCompilation())) { |
| 6812 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6813 | } |
| 6814 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6815 | } |
| 6816 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6817 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6818 | // move. |
| 6819 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6820 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6821 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6822 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6823 | return; |
| 6824 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6825 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6826 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6827 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6828 | Location out_loc = locations->Out(); |
| 6829 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6830 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6831 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6832 | ? kWithoutReadBarrier |
| 6833 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6834 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6835 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6836 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6837 | DCHECK(!cls->CanCallRuntime()); |
| 6838 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6839 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6840 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6841 | GenerateGcRootFieldLoad(cls, |
| 6842 | out_loc, |
| 6843 | current_method, |
| 6844 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6845 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6846 | break; |
| 6847 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6848 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6849 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6850 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6851 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6852 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6853 | __ BindTrackedLabel(&labels->movw_label); |
| 6854 | __ movw(out, /* placeholder */ 0u); |
| 6855 | __ BindTrackedLabel(&labels->movt_label); |
| 6856 | __ movt(out, /* placeholder */ 0u); |
| 6857 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6858 | __ add(out, out, ShifterOperand(PC)); |
| 6859 | break; |
| 6860 | } |
| 6861 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6862 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6863 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6864 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6865 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6866 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6867 | break; |
| 6868 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6869 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6870 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6871 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6872 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6873 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6874 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6875 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6876 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6877 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6878 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6879 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6880 | __ add(temp, temp, ShifterOperand(PC)); |
| 6881 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6882 | generate_null_check = true; |
| 6883 | break; |
| 6884 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6885 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6886 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6887 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6888 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6889 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6890 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6891 | break; |
| 6892 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6893 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6894 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6895 | LOG(FATAL) << "UNREACHABLE"; |
| 6896 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6897 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6898 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6899 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6900 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6901 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6902 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6903 | codegen_->AddSlowPath(slow_path); |
| 6904 | if (generate_null_check) { |
| 6905 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6906 | } |
| 6907 | if (cls->MustGenerateClinitCheck()) { |
| 6908 | GenerateClassInitializationCheck(slow_path, out); |
| 6909 | } else { |
| 6910 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6911 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6912 | } |
| 6913 | } |
| 6914 | |
| 6915 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6916 | LocationSummary* locations = |
| 6917 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6918 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6919 | if (check->HasUses()) { |
| 6920 | locations->SetOut(Location::SameAsFirstInput()); |
| 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6925 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6926 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6927 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6928 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6929 | GenerateClassInitializationCheck(slow_path, |
| 6930 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6931 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6932 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6933 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6934 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6935 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6936 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6937 | __ b(slow_path->GetEntryLabel(), LT); |
| 6938 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6939 | // properly. Therefore, we do a memory fence. |
| 6940 | __ dmb(ISH); |
| 6941 | __ Bind(slow_path->GetExitLabel()); |
| 6942 | } |
| 6943 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6944 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6945 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6946 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6947 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6948 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6949 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6950 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6951 | case HLoadString::LoadKind::kJitTableAddress: |
| 6952 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6953 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame^] | 6954 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6955 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6956 | break; |
| 6957 | } |
| 6958 | return desired_string_load_kind; |
| 6959 | } |
| 6960 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6961 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6962 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6963 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6964 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6965 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6966 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6967 | } else { |
| 6968 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6969 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6970 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6971 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6972 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6973 | // 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] | 6974 | locations->AddTemp(Location::RequiresRegister()); |
| 6975 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6976 | InvokeRuntimeCallingConvention calling_convention; |
| 6977 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6978 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6979 | // that the the kPrimNot result register is the same as the first argument register. |
| 6980 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6981 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6982 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6983 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6984 | } else { |
| 6985 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6986 | } |
| 6987 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6988 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6991 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6992 | // move. |
| 6993 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6994 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6995 | Location out_loc = locations->Out(); |
| 6996 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6997 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6998 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6999 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7000 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7001 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7002 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7003 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7004 | __ BindTrackedLabel(&labels->movw_label); |
| 7005 | __ movw(out, /* placeholder */ 0u); |
| 7006 | __ BindTrackedLabel(&labels->movt_label); |
| 7007 | __ movt(out, /* placeholder */ 0u); |
| 7008 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7009 | __ add(out, out, ShifterOperand(PC)); |
| 7010 | return; // No dex cache slow path. |
| 7011 | } |
| 7012 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7013 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7014 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7015 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7016 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7017 | return; // No dex cache slow path. |
| 7018 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7019 | case HLoadString::LoadKind::kBssEntry: { |
| 7020 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7021 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7022 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7023 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7024 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7025 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7026 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7027 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7028 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7029 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7030 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7031 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7032 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7033 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 7034 | codegen_->AddSlowPath(slow_path); |
| 7035 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7036 | __ Bind(slow_path->GetExitLabel()); |
| 7037 | return; |
| 7038 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7039 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7040 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7041 | load->GetStringIndex(), |
| 7042 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7043 | // /* GcRoot<mirror::String> */ out = *out |
| 7044 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7045 | return; |
| 7046 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7047 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7048 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7049 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7050 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7051 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 7052 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 7053 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7054 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7055 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7056 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7057 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7058 | } |
| 7059 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7060 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7061 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7062 | } |
| 7063 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7064 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 7065 | LocationSummary* locations = |
| 7066 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7067 | locations->SetOut(Location::RequiresRegister()); |
| 7068 | } |
| 7069 | |
| 7070 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7071 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7072 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7073 | } |
| 7074 | |
| 7075 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 7076 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7077 | } |
| 7078 | |
| 7079 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7080 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7081 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7082 | } |
| 7083 | |
| 7084 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 7085 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7086 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7087 | InvokeRuntimeCallingConvention calling_convention; |
| 7088 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7089 | } |
| 7090 | |
| 7091 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7092 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7093 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7096 | // Temp is used for read barrier. |
| 7097 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7098 | if (kEmitCompilerReadBarrier && |
| 7099 | (kUseBakerReadBarrier || |
| 7100 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7101 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7102 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7103 | return 1; |
| 7104 | } |
| 7105 | return 0; |
| 7106 | } |
| 7107 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7108 | // 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] | 7109 | // interface pointer, one for loading the current interface. |
| 7110 | // The other checks have one temp for loading the object's class. |
| 7111 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7112 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7113 | return 3; |
| 7114 | } |
| 7115 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7116 | } |
| 7117 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7118 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7119 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7120 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7121 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7122 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7123 | case TypeCheckKind::kExactCheck: |
| 7124 | case TypeCheckKind::kAbstractClassCheck: |
| 7125 | case TypeCheckKind::kClassHierarchyCheck: |
| 7126 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7127 | call_kind = |
| 7128 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7129 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7130 | break; |
| 7131 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7132 | case TypeCheckKind::kUnresolvedCheck: |
| 7133 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7134 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7135 | break; |
| 7136 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7137 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7138 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7139 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7140 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7141 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7142 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7143 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7144 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7145 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7146 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7147 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7148 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7149 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7150 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7151 | } |
| 7152 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7153 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7154 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7155 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7156 | Location obj_loc = locations->InAt(0); |
| 7157 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7158 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7159 | Location out_loc = locations->Out(); |
| 7160 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7161 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7162 | DCHECK_LE(num_temps, 1u); |
| 7163 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7164 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7165 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7166 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7167 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7168 | Label done; |
| 7169 | Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7170 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7171 | |
| 7172 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7173 | // avoid null check if we know obj is not null. |
| 7174 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7175 | DCHECK_NE(out, obj); |
| 7176 | __ LoadImmediate(out, 0); |
| 7177 | __ CompareAndBranchIfZero(obj, final_label); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7178 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7179 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7180 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7181 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7182 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7183 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7184 | out_loc, |
| 7185 | obj_loc, |
| 7186 | class_offset, |
| 7187 | maybe_temp_loc, |
| 7188 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7189 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7190 | __ cmp(out, ShifterOperand(cls)); |
| 7191 | // We speculatively set the result to false without changing the condition |
| 7192 | // flags, which allows us to avoid some branching later. |
| 7193 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7194 | |
| 7195 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7196 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7197 | // encoding can be used. |
| 7198 | if (ArmAssembler::IsLowRegister(out)) { |
| 7199 | __ it(EQ); |
| 7200 | __ mov(out, ShifterOperand(1), EQ); |
| 7201 | } else { |
| 7202 | __ b(final_label, NE); |
| 7203 | __ LoadImmediate(out, 1); |
| 7204 | } |
| 7205 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7206 | break; |
| 7207 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7208 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7209 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7210 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7211 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7212 | out_loc, |
| 7213 | obj_loc, |
| 7214 | class_offset, |
| 7215 | maybe_temp_loc, |
| 7216 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7217 | // If the class is abstract, we eagerly fetch the super class of the |
| 7218 | // object to avoid doing a comparison we know will fail. |
| 7219 | Label loop; |
| 7220 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7221 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7222 | GenerateReferenceLoadOneRegister(instruction, |
| 7223 | out_loc, |
| 7224 | super_offset, |
| 7225 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7226 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7227 | // 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] | 7228 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7229 | __ cmp(out, ShifterOperand(cls)); |
| 7230 | __ b(&loop, NE); |
| 7231 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7232 | break; |
| 7233 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7234 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7235 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7236 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7237 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7238 | out_loc, |
| 7239 | obj_loc, |
| 7240 | class_offset, |
| 7241 | maybe_temp_loc, |
| 7242 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7243 | // Walk over the class hierarchy to find a match. |
| 7244 | Label loop, success; |
| 7245 | __ Bind(&loop); |
| 7246 | __ cmp(out, ShifterOperand(cls)); |
| 7247 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7248 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7249 | GenerateReferenceLoadOneRegister(instruction, |
| 7250 | out_loc, |
| 7251 | super_offset, |
| 7252 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7253 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7254 | // This is essentially a null check, but it sets the condition flags to the |
| 7255 | // proper value for the code that follows the loop, i.e. not `EQ`. |
| 7256 | __ cmp(out, ShifterOperand(1)); |
| 7257 | __ b(&loop, HS); |
| 7258 | |
| 7259 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7260 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7261 | // encoding can be used. |
| 7262 | if (ArmAssembler::IsLowRegister(out)) { |
| 7263 | // If `out` is null, we use it for the result, and the condition flags |
| 7264 | // have already been set to `NE`, so the IT block that comes afterwards |
| 7265 | // (and which handles the successful case) turns into a NOP (instead of |
| 7266 | // overwriting `out`). |
| 7267 | __ Bind(&success); |
| 7268 | // There is only one branch to the `success` label (which is bound to this |
| 7269 | // IT block), and it has the same condition, `EQ`, so in that case the MOV |
| 7270 | // is executed. |
| 7271 | __ it(EQ); |
| 7272 | __ mov(out, ShifterOperand(1), EQ); |
| 7273 | } else { |
| 7274 | // 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] | 7275 | __ b(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7276 | __ Bind(&success); |
| 7277 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7278 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7279 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7280 | break; |
| 7281 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7282 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7283 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7284 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7285 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7286 | out_loc, |
| 7287 | obj_loc, |
| 7288 | class_offset, |
| 7289 | maybe_temp_loc, |
| 7290 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7291 | // Do an exact check. |
| 7292 | Label exact_check; |
| 7293 | __ cmp(out, ShifterOperand(cls)); |
| 7294 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7295 | // 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] | 7296 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7297 | GenerateReferenceLoadOneRegister(instruction, |
| 7298 | out_loc, |
| 7299 | component_offset, |
| 7300 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7301 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7302 | // 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] | 7303 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7304 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7305 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7306 | __ cmp(out, ShifterOperand(0)); |
| 7307 | // We speculatively set the result to false without changing the condition |
| 7308 | // flags, which allows us to avoid some branching later. |
| 7309 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7310 | |
| 7311 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7312 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7313 | // encoding can be used. |
| 7314 | if (ArmAssembler::IsLowRegister(out)) { |
| 7315 | __ Bind(&exact_check); |
| 7316 | __ it(EQ); |
| 7317 | __ mov(out, ShifterOperand(1), EQ); |
| 7318 | } else { |
| 7319 | __ b(final_label, NE); |
| 7320 | __ Bind(&exact_check); |
| 7321 | __ LoadImmediate(out, 1); |
| 7322 | } |
| 7323 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7324 | break; |
| 7325 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7326 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7327 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7328 | // No read barrier since the slow path will retry upon failure. |
| 7329 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7330 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7331 | out_loc, |
| 7332 | obj_loc, |
| 7333 | class_offset, |
| 7334 | maybe_temp_loc, |
| 7335 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7336 | __ cmp(out, ShifterOperand(cls)); |
| 7337 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7338 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7339 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7340 | codegen_->AddSlowPath(slow_path); |
| 7341 | __ b(slow_path->GetEntryLabel(), NE); |
| 7342 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7343 | break; |
| 7344 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7345 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7346 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7347 | case TypeCheckKind::kInterfaceCheck: { |
| 7348 | // 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] | 7349 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7350 | // cases. |
| 7351 | // |
| 7352 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7353 | // entry point without resorting to a type checking slow path |
| 7354 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7355 | // require to assign fixed registers for the inputs of this |
| 7356 | // HInstanceOf instruction (following the runtime calling |
| 7357 | // convention), which might be cluttered by the potential first |
| 7358 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7359 | // |
| 7360 | // TODO: Introduce a new runtime entry point taking the object |
| 7361 | // to test (instead of its class) as argument, and let it deal |
| 7362 | // with the read barrier issues. This will let us refactor this |
| 7363 | // case of the `switch` code as it was previously (with a direct |
| 7364 | // call to the runtime not using a type checking slow path). |
| 7365 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7366 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7367 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7368 | /* is_fatal */ false); |
| 7369 | codegen_->AddSlowPath(slow_path); |
| 7370 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7371 | break; |
| 7372 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7373 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7374 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7375 | if (done.IsLinked()) { |
| 7376 | __ Bind(&done); |
| 7377 | } |
| 7378 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7379 | if (slow_path != nullptr) { |
| 7380 | __ Bind(slow_path->GetExitLabel()); |
| 7381 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7382 | } |
| 7383 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7384 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7385 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7386 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7387 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7388 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7389 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7390 | case TypeCheckKind::kExactCheck: |
| 7391 | case TypeCheckKind::kAbstractClassCheck: |
| 7392 | case TypeCheckKind::kClassHierarchyCheck: |
| 7393 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7394 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7395 | LocationSummary::kCallOnSlowPath : |
| 7396 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7397 | break; |
| 7398 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7399 | case TypeCheckKind::kUnresolvedCheck: |
| 7400 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7401 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7402 | break; |
| 7403 | } |
| 7404 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7405 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7407 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7408 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7409 | } |
| 7410 | |
| 7411 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7412 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7413 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7414 | Location obj_loc = locations->InAt(0); |
| 7415 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7416 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7417 | Location temp_loc = locations->GetTemp(0); |
| 7418 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7419 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7420 | DCHECK_LE(num_temps, 3u); |
| 7421 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7422 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7423 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7424 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7425 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7426 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7427 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7428 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7429 | const uint32_t object_array_data_offset = |
| 7430 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7431 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7432 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7433 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7434 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7435 | bool is_type_check_slow_path_fatal = false; |
| 7436 | if (!kEmitCompilerReadBarrier) { |
| 7437 | is_type_check_slow_path_fatal = |
| 7438 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7439 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7440 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7441 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7442 | !instruction->CanThrowIntoCatchBlock(); |
| 7443 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7444 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7445 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7446 | is_type_check_slow_path_fatal); |
| 7447 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7448 | |
| 7449 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7450 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7451 | // Avoid null check if we know obj is not null. |
| 7452 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7453 | __ CompareAndBranchIfZero(obj, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7456 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7457 | case TypeCheckKind::kExactCheck: |
| 7458 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7459 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7460 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7461 | temp_loc, |
| 7462 | obj_loc, |
| 7463 | class_offset, |
| 7464 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7465 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7466 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7467 | __ cmp(temp, ShifterOperand(cls)); |
| 7468 | // Jump to slow path for throwing the exception or doing a |
| 7469 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7470 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7471 | break; |
| 7472 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7473 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7474 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7475 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7476 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7477 | temp_loc, |
| 7478 | obj_loc, |
| 7479 | class_offset, |
| 7480 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7481 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7482 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7483 | // If the class is abstract, we eagerly fetch the super class of the |
| 7484 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7485 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7486 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7487 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7488 | GenerateReferenceLoadOneRegister(instruction, |
| 7489 | temp_loc, |
| 7490 | super_offset, |
| 7491 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7492 | kWithoutReadBarrier); |
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 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7495 | // exception. |
| 7496 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7497 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7498 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7499 | __ cmp(temp, ShifterOperand(cls)); |
| 7500 | __ b(&loop, NE); |
| 7501 | break; |
| 7502 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7503 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7504 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7505 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7506 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7507 | temp_loc, |
| 7508 | obj_loc, |
| 7509 | class_offset, |
| 7510 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7511 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7512 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7513 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7514 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7515 | __ Bind(&loop); |
| 7516 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7517 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7518 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7519 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7520 | GenerateReferenceLoadOneRegister(instruction, |
| 7521 | temp_loc, |
| 7522 | super_offset, |
| 7523 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7524 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7525 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7526 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7527 | // exception. |
| 7528 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7529 | // Otherwise, jump to the beginning of the loop. |
| 7530 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7531 | break; |
| 7532 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7533 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7534 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7535 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7536 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7537 | temp_loc, |
| 7538 | obj_loc, |
| 7539 | class_offset, |
| 7540 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7541 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7542 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7543 | // Do an exact check. |
| 7544 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7545 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7546 | |
| 7547 | // 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] | 7548 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7549 | GenerateReferenceLoadOneRegister(instruction, |
| 7550 | temp_loc, |
| 7551 | component_offset, |
| 7552 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7553 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7554 | // If the component type is null, jump to the slow path to throw the exception. |
| 7555 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7556 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7557 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7558 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7559 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7560 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7561 | break; |
| 7562 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7563 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7564 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7565 | // 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] | 7566 | // We cannot directly call the CheckCast runtime entry point |
| 7567 | // without resorting to a type checking slow path here (i.e. by |
| 7568 | // calling InvokeRuntime directly), as it would require to |
| 7569 | // assign fixed registers for the inputs of this HInstanceOf |
| 7570 | // instruction (following the runtime calling convention), which |
| 7571 | // might be cluttered by the potential first read barrier |
| 7572 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7573 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7574 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7575 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7576 | |
| 7577 | case TypeCheckKind::kInterfaceCheck: { |
| 7578 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7579 | // positives by doing this. |
| 7580 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7581 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7582 | temp_loc, |
| 7583 | obj_loc, |
| 7584 | class_offset, |
| 7585 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7586 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7587 | |
| 7588 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7590 | temp_loc, |
| 7591 | temp_loc, |
| 7592 | iftable_offset, |
| 7593 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7594 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7595 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7596 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7597 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7598 | Label start_loop; |
| 7599 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7600 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7601 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7602 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7603 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7604 | // Go to next interface. |
| 7605 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7606 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7607 | maybe_temp2_loc.AsRegister<Register>(), |
| 7608 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7609 | // Compare the classes and continue the loop if they do not match. |
| 7610 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7611 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7612 | break; |
| 7613 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7614 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7615 | |
| 7616 | if (done.IsLinked()) { |
| 7617 | __ Bind(&done); |
| 7618 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7619 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7620 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7621 | } |
| 7622 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7623 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7624 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7625 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7626 | InvokeRuntimeCallingConvention calling_convention; |
| 7627 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7628 | } |
| 7629 | |
| 7630 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7631 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7632 | instruction, |
| 7633 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7634 | if (instruction->IsEnter()) { |
| 7635 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7636 | } else { |
| 7637 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7638 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7639 | } |
| 7640 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7641 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 7642 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 7643 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7644 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7645 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7646 | LocationSummary* locations = |
| 7647 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7648 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7649 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7650 | // 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] | 7651 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7652 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7653 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7657 | HandleBitwiseOperation(instruction); |
| 7658 | } |
| 7659 | |
| 7660 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7661 | HandleBitwiseOperation(instruction); |
| 7662 | } |
| 7663 | |
| 7664 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7665 | HandleBitwiseOperation(instruction); |
| 7666 | } |
| 7667 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7668 | |
| 7669 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7670 | LocationSummary* locations = |
| 7671 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7672 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7673 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7674 | |
| 7675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7676 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7677 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7678 | } |
| 7679 | |
| 7680 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7681 | LocationSummary* locations = instruction->GetLocations(); |
| 7682 | Location first = locations->InAt(0); |
| 7683 | Location second = locations->InAt(1); |
| 7684 | Location out = locations->Out(); |
| 7685 | |
| 7686 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7687 | Register first_reg = first.AsRegister<Register>(); |
| 7688 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7689 | Register out_reg = out.AsRegister<Register>(); |
| 7690 | |
| 7691 | switch (instruction->GetOpKind()) { |
| 7692 | case HInstruction::kAnd: |
| 7693 | __ bic(out_reg, first_reg, second_reg); |
| 7694 | break; |
| 7695 | case HInstruction::kOr: |
| 7696 | __ orn(out_reg, first_reg, second_reg); |
| 7697 | break; |
| 7698 | // There is no EON on arm. |
| 7699 | case HInstruction::kXor: |
| 7700 | default: |
| 7701 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7702 | UNREACHABLE(); |
| 7703 | } |
| 7704 | return; |
| 7705 | |
| 7706 | } else { |
| 7707 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7708 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7709 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7710 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7711 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7712 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7713 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7714 | |
| 7715 | switch (instruction->GetOpKind()) { |
| 7716 | case HInstruction::kAnd: |
| 7717 | __ bic(out_low, first_low, second_low); |
| 7718 | __ bic(out_high, first_high, second_high); |
| 7719 | break; |
| 7720 | case HInstruction::kOr: |
| 7721 | __ orn(out_low, first_low, second_low); |
| 7722 | __ orn(out_high, first_high, second_high); |
| 7723 | break; |
| 7724 | // There is no EON on arm. |
| 7725 | case HInstruction::kXor: |
| 7726 | default: |
| 7727 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7728 | UNREACHABLE(); |
| 7729 | } |
| 7730 | } |
| 7731 | } |
| 7732 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7733 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7734 | HDataProcWithShifterOp* instruction) { |
| 7735 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7736 | instruction->GetType() == Primitive::kPrimLong); |
| 7737 | LocationSummary* locations = |
| 7738 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7739 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7740 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7741 | |
| 7742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7743 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7744 | locations->SetOut(Location::RequiresRegister(), |
| 7745 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7746 | } |
| 7747 | |
| 7748 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7749 | HDataProcWithShifterOp* instruction) { |
| 7750 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7751 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7752 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7753 | const Location left = locations->InAt(0); |
| 7754 | const Location right = locations->InAt(1); |
| 7755 | const Location out = locations->Out(); |
| 7756 | |
| 7757 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7758 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7759 | |
| 7760 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7761 | ? right.AsRegisterPairLow<Register>() |
| 7762 | : right.AsRegister<Register>(); |
| 7763 | |
| 7764 | GenerateDataProcInstruction(kind, |
| 7765 | out.AsRegister<Register>(), |
| 7766 | left.AsRegister<Register>(), |
| 7767 | ShifterOperand(second, |
| 7768 | ShiftFromOpKind(op_kind), |
| 7769 | instruction->GetShiftAmount()), |
| 7770 | codegen_); |
| 7771 | } else { |
| 7772 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7773 | |
| 7774 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7775 | const Register second = right.AsRegister<Register>(); |
| 7776 | |
| 7777 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7778 | GenerateDataProc(kind, |
| 7779 | out, |
| 7780 | left, |
| 7781 | ShifterOperand(second), |
| 7782 | ShifterOperand(second, ASR, 31), |
| 7783 | codegen_); |
| 7784 | } else { |
| 7785 | GenerateLongDataProc(instruction, codegen_); |
| 7786 | } |
| 7787 | } |
| 7788 | } |
| 7789 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7790 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7791 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7792 | if (value == 0xffffffffu) { |
| 7793 | if (out != first) { |
| 7794 | __ mov(out, ShifterOperand(first)); |
| 7795 | } |
| 7796 | return; |
| 7797 | } |
| 7798 | if (value == 0u) { |
| 7799 | __ mov(out, ShifterOperand(0)); |
| 7800 | return; |
| 7801 | } |
| 7802 | ShifterOperand so; |
| 7803 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7804 | __ and_(out, first, so); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7805 | } else if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7806 | __ bic(out, first, ShifterOperand(~value)); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7807 | } else { |
| 7808 | DCHECK(IsPowerOfTwo(value + 1)); |
| 7809 | __ ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7810 | } |
| 7811 | } |
| 7812 | |
| 7813 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7814 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7815 | if (value == 0u) { |
| 7816 | if (out != first) { |
| 7817 | __ mov(out, ShifterOperand(first)); |
| 7818 | } |
| 7819 | return; |
| 7820 | } |
| 7821 | if (value == 0xffffffffu) { |
| 7822 | __ mvn(out, ShifterOperand(0)); |
| 7823 | return; |
| 7824 | } |
| 7825 | ShifterOperand so; |
| 7826 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7827 | __ orr(out, first, so); |
| 7828 | } else { |
| 7829 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7830 | __ orn(out, first, ShifterOperand(~value)); |
| 7831 | } |
| 7832 | } |
| 7833 | |
| 7834 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7835 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7836 | if (value == 0u) { |
| 7837 | if (out != first) { |
| 7838 | __ mov(out, ShifterOperand(first)); |
| 7839 | } |
| 7840 | return; |
| 7841 | } |
| 7842 | __ eor(out, first, ShifterOperand(value)); |
| 7843 | } |
| 7844 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7845 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7846 | Location first, |
| 7847 | uint64_t value) { |
| 7848 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7849 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7850 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7851 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7852 | uint32_t value_low = Low32Bits(value); |
| 7853 | uint32_t value_high = High32Bits(value); |
| 7854 | if (value_low == 0u) { |
| 7855 | if (out_low != first_low) { |
| 7856 | __ mov(out_low, ShifterOperand(first_low)); |
| 7857 | } |
| 7858 | __ AddConstant(out_high, first_high, value_high); |
| 7859 | return; |
| 7860 | } |
| 7861 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7862 | ShifterOperand so; |
| 7863 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7864 | __ adc(out_high, first_high, so); |
| 7865 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7866 | __ sbc(out_high, first_high, so); |
| 7867 | } else { |
| 7868 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7869 | UNREACHABLE(); |
| 7870 | } |
| 7871 | } |
| 7872 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7873 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7874 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7875 | Location first = locations->InAt(0); |
| 7876 | Location second = locations->InAt(1); |
| 7877 | Location out = locations->Out(); |
| 7878 | |
| 7879 | if (second.IsConstant()) { |
| 7880 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7881 | uint32_t value_low = Low32Bits(value); |
| 7882 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7883 | Register first_reg = first.AsRegister<Register>(); |
| 7884 | Register out_reg = out.AsRegister<Register>(); |
| 7885 | if (instruction->IsAnd()) { |
| 7886 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7887 | } else if (instruction->IsOr()) { |
| 7888 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7889 | } else { |
| 7890 | DCHECK(instruction->IsXor()); |
| 7891 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7892 | } |
| 7893 | } else { |
| 7894 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7895 | uint32_t value_high = High32Bits(value); |
| 7896 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7897 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7898 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7899 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7900 | if (instruction->IsAnd()) { |
| 7901 | GenerateAndConst(out_low, first_low, value_low); |
| 7902 | GenerateAndConst(out_high, first_high, value_high); |
| 7903 | } else if (instruction->IsOr()) { |
| 7904 | GenerateOrrConst(out_low, first_low, value_low); |
| 7905 | GenerateOrrConst(out_high, first_high, value_high); |
| 7906 | } else { |
| 7907 | DCHECK(instruction->IsXor()); |
| 7908 | GenerateEorConst(out_low, first_low, value_low); |
| 7909 | GenerateEorConst(out_high, first_high, value_high); |
| 7910 | } |
| 7911 | } |
| 7912 | return; |
| 7913 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7914 | |
| 7915 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7916 | Register first_reg = first.AsRegister<Register>(); |
| 7917 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7918 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7919 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7920 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7921 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7922 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7923 | } else { |
| 7924 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7925 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7926 | } |
| 7927 | } else { |
| 7928 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7929 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7930 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7931 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7932 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7933 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7934 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7935 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7936 | __ and_(out_low, first_low, second_low); |
| 7937 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7938 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7939 | __ orr(out_low, first_low, second_low); |
| 7940 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7941 | } else { |
| 7942 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7943 | __ eor(out_low, first_low, second_low); |
| 7944 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7945 | } |
| 7946 | } |
| 7947 | } |
| 7948 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7949 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7950 | HInstruction* instruction, |
| 7951 | Location out, |
| 7952 | uint32_t offset, |
| 7953 | Location maybe_temp, |
| 7954 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7955 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7956 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7957 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7958 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7959 | if (kUseBakerReadBarrier) { |
| 7960 | // Load with fast path based Baker's read barrier. |
| 7961 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7962 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7963 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7964 | } else { |
| 7965 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7966 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7967 | // in the following move operation, as we will need it for the |
| 7968 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7969 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7970 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7971 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7972 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7973 | } |
| 7974 | } else { |
| 7975 | // Plain load with no read barrier. |
| 7976 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7977 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7978 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7979 | } |
| 7980 | } |
| 7981 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7982 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7983 | HInstruction* instruction, |
| 7984 | Location out, |
| 7985 | Location obj, |
| 7986 | uint32_t offset, |
| 7987 | Location maybe_temp, |
| 7988 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7989 | Register out_reg = out.AsRegister<Register>(); |
| 7990 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7991 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7992 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7993 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7994 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7995 | // Load with fast path based Baker's read barrier. |
| 7996 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7997 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7998 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7999 | } else { |
| 8000 | // Load with slow path based read barrier. |
| 8001 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8002 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8003 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8004 | } |
| 8005 | } else { |
| 8006 | // Plain load with no read barrier. |
| 8007 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8008 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8009 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8010 | } |
| 8011 | } |
| 8012 | |
| 8013 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 8014 | Location root, |
| 8015 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8016 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8017 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8018 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8019 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8020 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8021 | if (kUseBakerReadBarrier) { |
| 8022 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8023 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8024 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8025 | !Runtime::Current()->UseJitCompilation()) { |
| 8026 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8027 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8028 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8029 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8030 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8031 | // |
| 8032 | // We use link-time generated thunks for the slow path. That thunk |
| 8033 | // checks the reference and jumps to the entrypoint if needed. |
| 8034 | // |
| 8035 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8036 | // lr = &return_address; |
| 8037 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8038 | // if (temp != nullptr) { |
| 8039 | // goto gc_root_thunk<root_reg>(lr) |
| 8040 | // } |
| 8041 | // return_address: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8042 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8043 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8044 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8045 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8046 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8047 | Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8048 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8049 | // entrypoint_reg = |
| 8050 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8051 | DCHECK_EQ(IP, 12); |
| 8052 | const int32_t entry_point_offset = |
| 8053 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8054 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8055 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8056 | Label return_address; |
| 8057 | __ AdrCode(LR, &return_address); |
| 8058 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8059 | // Currently the offset is always within range. If that changes, |
| 8060 | // we shall have to split the load the same way as for fields. |
| 8061 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8062 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8063 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8064 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8065 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8066 | EmitPlaceholderBne(codegen_, bne_label); |
| 8067 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8068 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8069 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8070 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8071 | } else { |
| 8072 | // Note that we do not actually check the value of |
| 8073 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8074 | // root or not. Instead, we load into `temp` the read barrier |
| 8075 | // mark entry point corresponding to register `root`. If `temp` |
| 8076 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8077 | // versa. |
| 8078 | // |
| 8079 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8080 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8081 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8082 | // // Slow path. |
| 8083 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8084 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8085 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8086 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8087 | Location temp = Location::RegisterLocation(LR); |
| 8088 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 8089 | instruction, root, /* entrypoint */ temp); |
| 8090 | codegen_->AddSlowPath(slow_path); |
| 8091 | |
| 8092 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8093 | const int32_t entry_point_offset = |
| 8094 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8095 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8096 | // threads are suspended or running a checkpoint. |
| 8097 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 8098 | |
| 8099 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8100 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8101 | static_assert( |
| 8102 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8103 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8104 | "have different sizes."); |
| 8105 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8106 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8107 | "have different sizes."); |
| 8108 | |
| 8109 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8110 | // checking GetIsGcMarking. |
| 8111 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8112 | __ Bind(slow_path->GetExitLabel()); |
| 8113 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8114 | } else { |
| 8115 | // GC root loaded through a slow path for read barriers other |
| 8116 | // than Baker's. |
| 8117 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8118 | __ AddConstant(root_reg, obj, offset); |
| 8119 | // /* mirror::Object* */ root = root->Read() |
| 8120 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8121 | } |
| 8122 | } else { |
| 8123 | // Plain GC root load with no read barrier. |
| 8124 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8125 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8126 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8127 | // do not have to unpoison `root_reg` here. |
| 8128 | } |
| 8129 | } |
| 8130 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8131 | void CodeGeneratorARM::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8132 | DCHECK(kEmitCompilerReadBarrier); |
| 8133 | DCHECK(kUseBakerReadBarrier); |
| 8134 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8135 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8136 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 8137 | } |
| 8138 | } |
| 8139 | } |
| 8140 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8141 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8142 | Location ref, |
| 8143 | Register obj, |
| 8144 | uint32_t offset, |
| 8145 | Location temp, |
| 8146 | bool needs_null_check) { |
| 8147 | DCHECK(kEmitCompilerReadBarrier); |
| 8148 | DCHECK(kUseBakerReadBarrier); |
| 8149 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8150 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8151 | !Runtime::Current()->UseJitCompilation()) { |
| 8152 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8153 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8154 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8155 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8156 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8157 | // |
| 8158 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8159 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8160 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8161 | // |
| 8162 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8163 | // lr = &gray_return_address; |
| 8164 | // if (temp != nullptr) { |
| 8165 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8166 | // } |
| 8167 | // not_gray_return_address: |
| 8168 | // // Original reference load. If the offset is too large to fit |
| 8169 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8170 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8171 | // gray_return_address: |
| 8172 | |
| 8173 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8174 | Register ref_reg = ref.AsRegister<Register>(); |
| 8175 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8176 | Register base = obj; |
| 8177 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8178 | base = temp.AsRegister<Register>(); |
| 8179 | DCHECK_NE(base, kBakerCcEntrypointRegister); |
| 8180 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8181 | __ AddConstant(base, obj, offset & ~(kReferenceLoadMinFarOffset - 1u)); |
| 8182 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8183 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8184 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8185 | // increase the overall code size when taking the generated thunks into account. |
| 8186 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8187 | } |
| 8188 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8189 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8190 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData(base, obj, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8191 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8192 | |
| 8193 | // entrypoint_reg = |
| 8194 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8195 | DCHECK_EQ(IP, 12); |
| 8196 | const int32_t entry_point_offset = |
| 8197 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8198 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8199 | |
| 8200 | Label return_address; |
| 8201 | __ AdrCode(LR, &return_address); |
| 8202 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8203 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8204 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8205 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8206 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8207 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8208 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset); |
| 8209 | if (needs_null_check) { |
| 8210 | MaybeRecordImplicitNullCheck(instruction); |
| 8211 | } |
| 8212 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8213 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8214 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8215 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8216 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8217 | return; |
| 8218 | } |
| 8219 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8220 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8221 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8222 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8223 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8224 | 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] | 8225 | } |
| 8226 | |
| 8227 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8228 | Location ref, |
| 8229 | Register obj, |
| 8230 | uint32_t data_offset, |
| 8231 | Location index, |
| 8232 | Location temp, |
| 8233 | bool needs_null_check) { |
| 8234 | DCHECK(kEmitCompilerReadBarrier); |
| 8235 | DCHECK(kUseBakerReadBarrier); |
| 8236 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8237 | static_assert( |
| 8238 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8239 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8240 | ScaleFactor scale_factor = TIMES_4; |
| 8241 | |
| 8242 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8243 | !Runtime::Current()->UseJitCompilation()) { |
| 8244 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8245 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8246 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8247 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8248 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8249 | // |
| 8250 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8251 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8252 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8253 | // |
| 8254 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8255 | // lr = &gray_return_address; |
| 8256 | // if (temp != nullptr) { |
| 8257 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8258 | // } |
| 8259 | // not_gray_return_address: |
| 8260 | // // Original reference load. If the offset is too large to fit |
| 8261 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8262 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8263 | // gray_return_address: |
| 8264 | |
| 8265 | DCHECK(index.IsValid()); |
| 8266 | Register index_reg = index.AsRegister<Register>(); |
| 8267 | Register ref_reg = ref.AsRegister<Register>(); |
| 8268 | Register data_reg = temp.AsRegister<Register>(); |
| 8269 | DCHECK_NE(data_reg, kBakerCcEntrypointRegister); |
| 8270 | |
| 8271 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8272 | uint32_t custom_data = |
| 8273 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg); |
| 8274 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8275 | |
| 8276 | // entrypoint_reg = |
| 8277 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8278 | DCHECK_EQ(IP, 12); |
| 8279 | const int32_t entry_point_offset = |
| 8280 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8281 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8282 | __ AddConstant(data_reg, obj, data_offset); |
| 8283 | |
| 8284 | Label return_address; |
| 8285 | __ AdrCode(LR, &return_address); |
| 8286 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8287 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8288 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8289 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8290 | __ ldr(ref_reg, Address(data_reg, index_reg, LSL, scale_factor)); |
| 8291 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8292 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8293 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8294 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8295 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8296 | return; |
| 8297 | } |
| 8298 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8299 | // /* HeapReference<Object> */ ref = |
| 8300 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8301 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8302 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8303 | } |
| 8304 | |
| 8305 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8306 | Location ref, |
| 8307 | Register obj, |
| 8308 | uint32_t offset, |
| 8309 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8310 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8311 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8312 | bool needs_null_check) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8313 | DCHECK(kEmitCompilerReadBarrier); |
| 8314 | DCHECK(kUseBakerReadBarrier); |
| 8315 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8316 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8317 | // whether we need to enter the slow path to mark the reference. |
| 8318 | // Then, in the slow path, check the gray bit in the lock word of |
| 8319 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8320 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8321 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8322 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8323 | // instead, we load into `temp2` the read barrier mark entry point |
| 8324 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8325 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8326 | // |
| 8327 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8328 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8329 | // // Slow path. |
| 8330 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8331 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8332 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8333 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8334 | // if (is_gray) { |
| 8335 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8336 | // } |
| 8337 | // } else { |
| 8338 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8339 | // } |
| 8340 | |
| 8341 | Register temp_reg = temp.AsRegister<Register>(); |
| 8342 | |
| 8343 | // Slow path marking the object `ref` when the GC is marking. The |
| 8344 | // entrypoint will already be loaded in `temp2`. |
| 8345 | Location temp2 = Location::RegisterLocation(LR); |
| 8346 | SlowPathCodeARM* slow_path = |
| 8347 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 8348 | instruction, |
| 8349 | ref, |
| 8350 | obj, |
| 8351 | offset, |
| 8352 | index, |
| 8353 | scale_factor, |
| 8354 | needs_null_check, |
| 8355 | temp_reg, |
| 8356 | /* entrypoint */ temp2); |
| 8357 | AddSlowPath(slow_path); |
| 8358 | |
| 8359 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8360 | const int32_t entry_point_offset = |
| 8361 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8362 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8363 | // threads are suspended or running a checkpoint. |
| 8364 | __ LoadFromOffset(kLoadWord, temp2.AsRegister<Register>(), TR, entry_point_offset); |
| 8365 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8366 | // checking GetIsGcMarking. |
| 8367 | __ CompareAndBranchIfNonZero(temp2.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8368 | // Fast path: the GC is not marking: just load the reference. |
| 8369 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8370 | __ Bind(slow_path->GetExitLabel()); |
| 8371 | } |
| 8372 | |
| 8373 | void CodeGeneratorARM::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8374 | Location ref, |
| 8375 | Register obj, |
| 8376 | Location field_offset, |
| 8377 | Location temp, |
| 8378 | bool needs_null_check, |
| 8379 | Register temp2) { |
| 8380 | DCHECK(kEmitCompilerReadBarrier); |
| 8381 | DCHECK(kUseBakerReadBarrier); |
| 8382 | |
| 8383 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8384 | // whether we need to enter the slow path to update the reference |
| 8385 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8386 | // in the lock word of the reference's holder (`obj`) to decide |
| 8387 | // whether to mark `ref` and update the field or not. |
| 8388 | // |
| 8389 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8390 | // instead, we load into `temp3` the read barrier mark entry point |
| 8391 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8392 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8393 | // |
| 8394 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8395 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8396 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8397 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8398 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8399 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8400 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8401 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8402 | // old_ref = ref; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8403 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8404 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8405 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8406 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8407 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8408 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 8409 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8410 | // Slow path updating the object reference at address `obj + |
| 8411 | // field_offset` when the GC is marking. The entrypoint will already |
| 8412 | // be loaded in `temp3`. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8413 | Location temp3 = Location::RegisterLocation(LR); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8414 | SlowPathCodeARM* slow_path = |
| 8415 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 8416 | instruction, |
| 8417 | ref, |
| 8418 | obj, |
| 8419 | /* offset */ 0u, |
| 8420 | /* index */ field_offset, |
| 8421 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8422 | needs_null_check, |
| 8423 | temp_reg, |
| 8424 | temp2, |
| 8425 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8426 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8427 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8428 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8429 | const int32_t entry_point_offset = |
| 8430 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8431 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8432 | // threads are suspended or running a checkpoint. |
| 8433 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8434 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8435 | // checking GetIsGcMarking. |
| 8436 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8437 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8438 | // up-to-date, and we don't need to load the reference). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8439 | __ Bind(slow_path->GetExitLabel()); |
| 8440 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8441 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8442 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8443 | Location ref, |
| 8444 | Register obj, |
| 8445 | uint32_t offset, |
| 8446 | Location index, |
| 8447 | ScaleFactor scale_factor, |
| 8448 | bool needs_null_check) { |
| 8449 | Register ref_reg = ref.AsRegister<Register>(); |
| 8450 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8451 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8452 | // Load types involving an "index": ArrayGet, |
| 8453 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8454 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8455 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8456 | if (index.IsConstant()) { |
| 8457 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8458 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8459 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8460 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8461 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8462 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8463 | // intrinsics, which use a register pair as index ("long |
| 8464 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8465 | Register index_reg = index.IsRegisterPair() |
| 8466 | ? index.AsRegisterPairLow<Register>() |
| 8467 | : index.AsRegister<Register>(); |
| 8468 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8469 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8470 | } |
| 8471 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8472 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8473 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8474 | } |
| 8475 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8476 | if (needs_null_check) { |
| 8477 | MaybeRecordImplicitNullCheck(instruction); |
| 8478 | } |
| 8479 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8480 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8481 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8482 | } |
| 8483 | |
| 8484 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8485 | Location out, |
| 8486 | Location ref, |
| 8487 | Location obj, |
| 8488 | uint32_t offset, |
| 8489 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8490 | DCHECK(kEmitCompilerReadBarrier); |
| 8491 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8492 | // Insert a slow path based read barrier *after* the reference load. |
| 8493 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8494 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8495 | // reference will be carried out by the runtime within the slow |
| 8496 | // path. |
| 8497 | // |
| 8498 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8499 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8500 | // not used by the artReadBarrierSlow entry point. |
| 8501 | // |
| 8502 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8503 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8504 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8505 | AddSlowPath(slow_path); |
| 8506 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8507 | __ b(slow_path->GetEntryLabel()); |
| 8508 | __ Bind(slow_path->GetExitLabel()); |
| 8509 | } |
| 8510 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8511 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8512 | Location out, |
| 8513 | Location ref, |
| 8514 | Location obj, |
| 8515 | uint32_t offset, |
| 8516 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8517 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8518 | // Baker's read barriers shall be handled by the fast path |
| 8519 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8520 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8521 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8522 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8523 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8524 | } else if (kPoisonHeapReferences) { |
| 8525 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8526 | } |
| 8527 | } |
| 8528 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8529 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8530 | Location out, |
| 8531 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8532 | DCHECK(kEmitCompilerReadBarrier); |
| 8533 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8534 | // Insert a slow path based read barrier *after* the GC root load. |
| 8535 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8536 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8537 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8538 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8539 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8540 | AddSlowPath(slow_path); |
| 8541 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8542 | __ b(slow_path->GetEntryLabel()); |
| 8543 | __ Bind(slow_path->GetExitLabel()); |
| 8544 | } |
| 8545 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8546 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8547 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8548 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8549 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8550 | } |
| 8551 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8552 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8553 | Register temp) { |
| 8554 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8555 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8556 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8557 | return location.AsRegister<Register>(); |
| 8558 | } |
| 8559 | // For intrinsics we allow any location, so it may be on the stack. |
| 8560 | if (!location.IsRegister()) { |
| 8561 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8562 | return temp; |
| 8563 | } |
| 8564 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8565 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8566 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8567 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8568 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8569 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8570 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8571 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8572 | return temp; |
| 8573 | } |
| 8574 | return location.AsRegister<Register>(); |
| 8575 | } |
| 8576 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8577 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8578 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8579 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8580 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8581 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8582 | uint32_t offset = |
| 8583 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8584 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8585 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8586 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8587 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8588 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8589 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8590 | break; |
| 8591 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8592 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8593 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8594 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8595 | HArmDexCacheArraysBase* base = |
| 8596 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8597 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8598 | temp.AsRegister<Register>()); |
| 8599 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8600 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8601 | break; |
| 8602 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8603 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8604 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8605 | Register method_reg; |
| 8606 | Register reg = temp.AsRegister<Register>(); |
| 8607 | if (current_method.IsRegister()) { |
| 8608 | method_reg = current_method.AsRegister<Register>(); |
| 8609 | } else { |
| 8610 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8611 | DCHECK(!current_method.IsValid()); |
| 8612 | method_reg = reg; |
| 8613 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 8614 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8615 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8616 | __ LoadFromOffset(kLoadWord, |
| 8617 | reg, |
| 8618 | method_reg, |
| 8619 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 8620 | // temp = temp[index_in_cache]; |
| 8621 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8622 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8623 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 8624 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 8625 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8626 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8627 | return callee_method; |
| 8628 | } |
| 8629 | |
| 8630 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 8631 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8632 | |
| 8633 | switch (invoke->GetCodePtrLocation()) { |
| 8634 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8635 | __ bl(GetFrameEntryLabel()); |
| 8636 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8637 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8638 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8639 | __ LoadFromOffset( |
| 8640 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8641 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8642 | // LR() |
| 8643 | __ blx(LR); |
| 8644 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8645 | } |
| 8646 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8647 | DCHECK(!IsLeafMethod()); |
| 8648 | } |
| 8649 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8650 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8651 | Register temp = temp_location.AsRegister<Register>(); |
| 8652 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8653 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8654 | |
| 8655 | // Use the calling convention instead of the location of the receiver, as |
| 8656 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8657 | // slow path, the arguments have been moved to the right place, so here we are |
| 8658 | // guaranteed that the receiver is the first register of the calling convention. |
| 8659 | InvokeDexCallingConvention calling_convention; |
| 8660 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8661 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8662 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8663 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8664 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8665 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8666 | // emit a read barrier for the previous class reference load. |
| 8667 | // However this is not required in practice, as this is an |
| 8668 | // intermediate/temporary reference and because the current |
| 8669 | // concurrent copying collector keeps the from-space memory |
| 8670 | // intact/accessible until the end of the marking phase (the |
| 8671 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8672 | __ MaybeUnpoisonHeapReference(temp); |
| 8673 | // temp = temp->GetMethodAt(method_offset); |
| 8674 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8675 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8676 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8677 | // LR = temp->GetEntryPoint(); |
| 8678 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 8679 | // LR(); |
| 8680 | __ blx(LR); |
| 8681 | } |
| 8682 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8683 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8684 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8685 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8686 | } |
| 8687 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8688 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8689 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8690 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8691 | } |
| 8692 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8693 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 8694 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8695 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8696 | } |
| 8697 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8698 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 8699 | const DexFile& dex_file, uint32_t element_offset) { |
| 8700 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8701 | } |
| 8702 | |
| 8703 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 8704 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8705 | patches->emplace_back(dex_file, offset_or_index); |
| 8706 | return &patches->back(); |
| 8707 | } |
| 8708 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8709 | Label* CodeGeneratorARM::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 8710 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 8711 | return &baker_read_barrier_patches_.back().label; |
| 8712 | } |
| 8713 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8714 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8715 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8716 | } |
| 8717 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8718 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8719 | dex::StringIndex string_index, |
| 8720 | Handle<mirror::String> handle) { |
| 8721 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8722 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8723 | return jit_string_patches_.GetOrCreate( |
| 8724 | StringReference(&dex_file, string_index), |
| 8725 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8726 | } |
| 8727 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8728 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8729 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8730 | Handle<mirror::Class> handle) { |
| 8731 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8732 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8733 | return jit_class_patches_.GetOrCreate( |
| 8734 | TypeReference(&dex_file, type_index), |
| 8735 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8736 | } |
| 8737 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8738 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8739 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 8740 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8741 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8742 | for (const PcRelativePatchInfo& info : infos) { |
| 8743 | const DexFile& dex_file = info.target_dex_file; |
| 8744 | size_t offset_or_index = info.offset_or_index; |
| 8745 | DCHECK(info.add_pc_label.IsBound()); |
| 8746 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 8747 | // Add MOVW patch. |
| 8748 | DCHECK(info.movw_label.IsBound()); |
| 8749 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 8750 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8751 | // Add MOVT patch. |
| 8752 | DCHECK(info.movt_label.IsBound()); |
| 8753 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 8754 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8755 | } |
| 8756 | } |
| 8757 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8758 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8759 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8760 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8761 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8762 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8763 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8764 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
| 8765 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8766 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8767 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8768 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8769 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8770 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8771 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8772 | linker_patches); |
| 8773 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8774 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8775 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8776 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8777 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8778 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8779 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8780 | linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8781 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 8782 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.Position(), |
| 8783 | info.custom_data)); |
| 8784 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8785 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8786 | } |
| 8787 | |
| 8788 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 8789 | return map->GetOrCreate( |
| 8790 | value, |
| 8791 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8792 | } |
| 8793 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8794 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8795 | LocationSummary* locations = |
| 8796 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8797 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8798 | Location::RequiresRegister()); |
| 8799 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8800 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8801 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8802 | } |
| 8803 | |
| 8804 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8805 | LocationSummary* locations = instr->GetLocations(); |
| 8806 | Register res = locations->Out().AsRegister<Register>(); |
| 8807 | Register accumulator = |
| 8808 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 8809 | Register mul_left = |
| 8810 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 8811 | Register mul_right = |
| 8812 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 8813 | |
| 8814 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8815 | __ mla(res, mul_left, mul_right, accumulator); |
| 8816 | } else { |
| 8817 | __ mls(res, mul_left, mul_right, accumulator); |
| 8818 | } |
| 8819 | } |
| 8820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8821 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8822 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8823 | LOG(FATAL) << "Unreachable"; |
| 8824 | } |
| 8825 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8826 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8827 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8828 | LOG(FATAL) << "Unreachable"; |
| 8829 | } |
| 8830 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8831 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8832 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8833 | LocationSummary* locations = |
| 8834 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8835 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8836 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8837 | codegen_->GetAssembler()->IsThumb()) { |
| 8838 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8839 | if (switch_instr->GetStartValue() != 0) { |
| 8840 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8841 | } |
| 8842 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8843 | } |
| 8844 | |
| 8845 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8846 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8847 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8848 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8849 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8850 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8851 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8852 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8853 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8854 | Register temp_reg = IP; |
| 8855 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8856 | // the immediate, because IP is used as the destination register. For the other |
| 8857 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8858 | // and they can be encoded in the instruction without making use of IP register. |
| 8859 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8860 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8861 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8862 | // Jump to successors[0] if value == lower_bound. |
| 8863 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8864 | int32_t last_index = 0; |
| 8865 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8866 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8867 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8868 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8869 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8870 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8871 | } |
| 8872 | if (num_entries - last_index == 2) { |
| 8873 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8874 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8875 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8876 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8877 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8878 | // And the default for any other value. |
| 8879 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8880 | __ b(codegen_->GetLabelOf(default_block)); |
| 8881 | } |
| 8882 | } else { |
| 8883 | // Create a table lookup. |
| 8884 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8885 | |
| 8886 | // Materialize a pointer to the switch table |
| 8887 | std::vector<Label*> labels(num_entries); |
| 8888 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8889 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8890 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8891 | } |
| 8892 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8893 | |
| 8894 | // Remove the bias. |
| 8895 | Register key_reg; |
| 8896 | if (lower_bound != 0) { |
| 8897 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8898 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8899 | } else { |
| 8900 | key_reg = value_reg; |
| 8901 | } |
| 8902 | |
| 8903 | // Check whether the value is in the table, jump to default block if not. |
| 8904 | __ CmpConstant(key_reg, num_entries - 1); |
| 8905 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8906 | |
| 8907 | // Load the displacement from the table. |
| 8908 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8909 | |
| 8910 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8911 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8912 | } |
| 8913 | } |
| 8914 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8915 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8916 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8917 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8918 | } |
| 8919 | |
| 8920 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8921 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8922 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8923 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8924 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8925 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8926 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8927 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8928 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8929 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8930 | } |
| 8931 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8932 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8933 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8934 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8935 | return; |
| 8936 | } |
| 8937 | |
| 8938 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8939 | |
| 8940 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8941 | if (return_loc.Equals(trg)) { |
| 8942 | return; |
| 8943 | } |
| 8944 | |
| 8945 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8946 | // with the last branch. |
| 8947 | if (type == Primitive::kPrimLong) { |
| 8948 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8949 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8950 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8951 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8952 | } else if (type == Primitive::kPrimDouble) { |
| 8953 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8954 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8955 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8956 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8957 | } else { |
| 8958 | // Let the parallel move resolver take care of all of this. |
| 8959 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8960 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8961 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8962 | } |
| 8963 | } |
| 8964 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8965 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8966 | LocationSummary* locations = |
| 8967 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8969 | locations->SetOut(Location::RequiresRegister()); |
| 8970 | } |
| 8971 | |
| 8972 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8973 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8974 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8975 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8976 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8977 | __ LoadFromOffset(kLoadWord, |
| 8978 | locations->Out().AsRegister<Register>(), |
| 8979 | locations->InAt(0).AsRegister<Register>(), |
| 8980 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8981 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8982 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8983 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8984 | __ LoadFromOffset(kLoadWord, |
| 8985 | locations->Out().AsRegister<Register>(), |
| 8986 | locations->InAt(0).AsRegister<Register>(), |
| 8987 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8988 | __ LoadFromOffset(kLoadWord, |
| 8989 | locations->Out().AsRegister<Register>(), |
| 8990 | locations->Out().AsRegister<Register>(), |
| 8991 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8992 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8993 | } |
| 8994 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8995 | static void PatchJitRootUse(uint8_t* code, |
| 8996 | const uint8_t* roots_data, |
| 8997 | Literal* literal, |
| 8998 | uint64_t index_in_table) { |
| 8999 | DCHECK(literal->GetLabel()->IsBound()); |
| 9000 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 9001 | uintptr_t address = |
| 9002 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9003 | uint8_t* data = code + literal_offset; |
| 9004 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9005 | } |
| 9006 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9007 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9008 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9009 | const StringReference& string_reference = entry.first; |
| 9010 | Literal* table_entry_literal = entry.second; |
| 9011 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9012 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9013 | uint64_t index_in_table = it->second; |
| 9014 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9015 | } |
| 9016 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9017 | const TypeReference& type_reference = entry.first; |
| 9018 | Literal* table_entry_literal = entry.second; |
| 9019 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9020 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9021 | uint64_t index_in_table = it->second; |
| 9022 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9023 | } |
| 9024 | } |
| 9025 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9026 | #undef __ |
| 9027 | #undef QUICK_ENTRY_POINT |
| 9028 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9029 | } // namespace arm |
| 9030 | } // namespace art |