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 | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 50 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 51 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 52 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 54 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 55 | static constexpr SRegister kFpuCalleeSaves[] = |
| 56 | { 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] | 57 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 58 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 59 | // S registers. Therefore there is no need to block it. |
| 60 | static constexpr DRegister DTMP = D31; |
| 61 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 62 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 63 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 64 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 65 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 66 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 67 | // the offset explicitly. |
| 68 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 69 | |
| 70 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 71 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 72 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 73 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 74 | |
| 75 | // The reserved entrypoint register for link-time generated thunks. |
| 76 | const Register kBakerCcEntrypointRegister = R4; |
| 77 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 78 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 79 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 80 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 82 | static inline void CheckLastTempIsBakerCcEntrypointRegister(HInstruction* instruction) { |
| 83 | DCHECK_EQ(static_cast<uint32_t>(kBakerCcEntrypointRegister), |
| 84 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 85 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 86 | DCHECK_EQ(kBakerCcEntrypointRegister, |
| 87 | instruction->GetLocations()->GetTemp( |
| 88 | instruction->GetLocations()->GetTempCount() - 1u).AsRegister<Register>()); |
| 89 | } |
| 90 | |
| 91 | static inline void EmitPlaceholderBne(CodeGeneratorARM* codegen, Label* bne_label) { |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 92 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(codegen->GetAssembler())); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 93 | __ BindTrackedLabel(bne_label); |
| 94 | Label placeholder_label; |
| 95 | __ b(&placeholder_label, NE); // Placeholder, patched at link-time. |
| 96 | __ Bind(&placeholder_label); |
| 97 | } |
| 98 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 99 | static inline bool CanEmitNarrowLdr(Register rt, Register rn, uint32_t offset) { |
| 100 | return ArmAssembler::IsLowRegister(rt) && ArmAssembler::IsLowRegister(rn) && offset < 32u; |
| 101 | } |
| 102 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 103 | static constexpr int kRegListThreshold = 4; |
| 104 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 105 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 106 | // for each live D registers they treat two corresponding S registers as live ones. |
| 107 | // |
| 108 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 109 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 110 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 111 | // - decreasing code size |
| 112 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 113 | // restored and then used in regular non SlowPath code as D register. |
| 114 | // |
| 115 | // For the following example (v means the S register is live): |
| 116 | // D names: | D0 | D1 | D2 | D4 | ... |
| 117 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 118 | // Live? | | v | v | v | v | v | v | | ... |
| 119 | // |
| 120 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 121 | // as D registers. |
| 122 | static size_t SaveContiguousSRegisterList(size_t first, |
| 123 | size_t last, |
| 124 | CodeGenerator* codegen, |
| 125 | size_t stack_offset) { |
| 126 | DCHECK_LE(first, last); |
| 127 | if ((first == last) && (first == 0)) { |
| 128 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 129 | return stack_offset; |
| 130 | } |
| 131 | if (first % 2 == 1) { |
| 132 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 133 | } |
| 134 | |
| 135 | bool save_last = false; |
| 136 | if (last % 2 == 0) { |
| 137 | save_last = true; |
| 138 | --last; |
| 139 | } |
| 140 | |
| 141 | if (first < last) { |
| 142 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 143 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 144 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 145 | |
| 146 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 147 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 148 | } else if (number_of_d_regs > 1) { |
| 149 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 150 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 151 | } |
| 152 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 153 | } |
| 154 | |
| 155 | if (save_last) { |
| 156 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 157 | } |
| 158 | |
| 159 | return stack_offset; |
| 160 | } |
| 161 | |
| 162 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 163 | size_t last, |
| 164 | CodeGenerator* codegen, |
| 165 | size_t stack_offset) { |
| 166 | DCHECK_LE(first, last); |
| 167 | if ((first == last) && (first == 0)) { |
| 168 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 169 | return stack_offset; |
| 170 | } |
| 171 | if (first % 2 == 1) { |
| 172 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 173 | } |
| 174 | |
| 175 | bool restore_last = false; |
| 176 | if (last % 2 == 0) { |
| 177 | restore_last = true; |
| 178 | --last; |
| 179 | } |
| 180 | |
| 181 | if (first < last) { |
| 182 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 183 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 184 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 185 | if (number_of_d_regs == 1) { |
| 186 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 187 | } else if (number_of_d_regs > 1) { |
| 188 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 189 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 190 | } |
| 191 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 192 | } |
| 193 | |
| 194 | if (restore_last) { |
| 195 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 196 | } |
| 197 | |
| 198 | return stack_offset; |
| 199 | } |
| 200 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 201 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 202 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 203 | size_t orig_offset = stack_offset; |
| 204 | |
| 205 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 206 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 207 | // If the register holds an object, update the stack mask. |
| 208 | if (locations->RegisterContainsObject(i)) { |
| 209 | locations->SetStackBit(stack_offset / kVRegSize); |
| 210 | } |
| 211 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 212 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 213 | saved_core_stack_offsets_[i] = stack_offset; |
| 214 | stack_offset += kArmWordSize; |
| 215 | } |
| 216 | |
| 217 | int reg_num = POPCOUNT(core_spills); |
| 218 | if (reg_num != 0) { |
| 219 | if (reg_num > kRegListThreshold) { |
| 220 | __ StoreList(RegList(core_spills), orig_offset); |
| 221 | } else { |
| 222 | stack_offset = orig_offset; |
| 223 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 224 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 229 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 230 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 231 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 232 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 233 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 235 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 236 | |
| 237 | stack_offset = orig_offset; |
| 238 | while (fp_spills != 0u) { |
| 239 | uint32_t begin = CTZ(fp_spills); |
| 240 | uint32_t tmp = fp_spills + (1u << begin); |
| 241 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 242 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 243 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 244 | } |
| 245 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 249 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 250 | size_t orig_offset = stack_offset; |
| 251 | |
| 252 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 253 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 254 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 255 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 256 | stack_offset += kArmWordSize; |
| 257 | } |
| 258 | |
| 259 | int reg_num = POPCOUNT(core_spills); |
| 260 | if (reg_num != 0) { |
| 261 | if (reg_num > kRegListThreshold) { |
| 262 | __ LoadList(RegList(core_spills), orig_offset); |
| 263 | } else { |
| 264 | stack_offset = orig_offset; |
| 265 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 266 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 271 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 272 | while (fp_spills != 0u) { |
| 273 | uint32_t begin = CTZ(fp_spills); |
| 274 | uint32_t tmp = fp_spills + (1u << begin); |
| 275 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 276 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 277 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 278 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 279 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 283 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 284 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 285 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 287 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 288 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 289 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 290 | // Live registers will be restored in the catch block if caught. |
| 291 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 292 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 293 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 294 | instruction_, |
| 295 | instruction_->GetDexPc(), |
| 296 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 297 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 300 | bool IsFatal() const OVERRIDE { return true; } |
| 301 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 302 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 303 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 304 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 305 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 306 | }; |
| 307 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 308 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 309 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 310 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 311 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 312 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 313 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 314 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 315 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 316 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 319 | bool IsFatal() const OVERRIDE { return true; } |
| 320 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 321 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 322 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 323 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 324 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 325 | }; |
| 326 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 327 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 328 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 330 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 331 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 332 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 333 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 334 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 335 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 336 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 337 | if (successor_ == nullptr) { |
| 338 | __ b(GetReturnLabel()); |
| 339 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 340 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 341 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 344 | Label* GetReturnLabel() { |
| 345 | DCHECK(successor_ == nullptr); |
| 346 | return &return_label_; |
| 347 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 348 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 349 | HBasicBlock* GetSuccessor() const { |
| 350 | return successor_; |
| 351 | } |
| 352 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 353 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 354 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 355 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 356 | // If not null, the block to branch to after the suspend check. |
| 357 | HBasicBlock* const successor_; |
| 358 | |
| 359 | // 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] | 360 | Label return_label_; |
| 361 | |
| 362 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 363 | }; |
| 364 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 365 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 366 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 367 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 369 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 371 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 372 | LocationSummary* locations = instruction_->GetLocations(); |
| 373 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 374 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 375 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 376 | // Live registers will be restored in the catch block if caught. |
| 377 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 378 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 379 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 380 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 381 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 382 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 383 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 385 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 386 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 387 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 388 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 389 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 390 | ? kQuickThrowStringBounds |
| 391 | : kQuickThrowArrayBounds; |
| 392 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 393 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 397 | bool IsFatal() const OVERRIDE { return true; } |
| 398 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 399 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 400 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 401 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 402 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 403 | }; |
| 404 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 405 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 406 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 407 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 408 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 409 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 410 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 411 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 412 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 413 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 414 | Location out = locations->Out(); |
| 415 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 416 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 417 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 418 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 419 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 420 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 421 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 422 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 423 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 424 | bool is_load_class_bss_entry = |
| 425 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 426 | Register entry_address = kNoRegister; |
| 427 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 428 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 429 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 430 | // the kSaveEverything call. |
| 431 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 432 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 433 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 434 | if (temp_is_r0) { |
| 435 | __ mov(entry_address, ShifterOperand(temp)); |
| 436 | } |
| 437 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 438 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 439 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 440 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 441 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 442 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 443 | if (do_clinit_) { |
| 444 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 445 | } else { |
| 446 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 447 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 448 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 449 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 450 | if (is_load_class_bss_entry) { |
| 451 | if (call_saves_everything_except_r0) { |
| 452 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 453 | __ str(R0, Address(entry_address)); |
| 454 | } else { |
| 455 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 456 | Register temp = IP; |
| 457 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 458 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 459 | __ BindTrackedLabel(&labels->movw_label); |
| 460 | __ movw(temp, /* placeholder */ 0u); |
| 461 | __ BindTrackedLabel(&labels->movt_label); |
| 462 | __ movt(temp, /* placeholder */ 0u); |
| 463 | __ BindTrackedLabel(&labels->add_pc_label); |
| 464 | __ add(temp, temp, ShifterOperand(PC)); |
| 465 | __ str(R0, Address(temp)); |
| 466 | } |
| 467 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 468 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 469 | if (out.IsValid()) { |
| 470 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 471 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 472 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 473 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 474 | __ b(GetExitLabel()); |
| 475 | } |
| 476 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 477 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 478 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 479 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 480 | // The class this slow path will load. |
| 481 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 482 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 483 | // The dex PC of `at_`. |
| 484 | const uint32_t dex_pc_; |
| 485 | |
| 486 | // Whether to initialize the class. |
| 487 | const bool do_clinit_; |
| 488 | |
| 489 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 490 | }; |
| 491 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 492 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 493 | public: |
| 494 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 495 | |
| 496 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 497 | DCHECK(instruction_->IsLoadString()); |
| 498 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 499 | LocationSummary* locations = instruction_->GetLocations(); |
| 500 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 501 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 502 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 503 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 504 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 505 | |
| 506 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 507 | __ Bind(GetEntryLabel()); |
| 508 | SaveLiveRegisters(codegen, locations); |
| 509 | |
| 510 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 511 | // 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] | 512 | // the kSaveEverything call. |
| 513 | Register entry_address = kNoRegister; |
| 514 | if (call_saves_everything_except_r0) { |
| 515 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 516 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 517 | entry_address = temp_is_r0 ? out : temp; |
| 518 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 519 | if (temp_is_r0) { |
| 520 | __ mov(entry_address, ShifterOperand(temp)); |
| 521 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 524 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 525 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 526 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 527 | |
| 528 | // Store the resolved String to the .bss entry. |
| 529 | if (call_saves_everything_except_r0) { |
| 530 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 531 | __ str(R0, Address(entry_address)); |
| 532 | } else { |
| 533 | // 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] | 534 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 535 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 536 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 537 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 538 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 539 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 540 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 541 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 542 | __ add(temp, temp, ShifterOperand(PC)); |
| 543 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 546 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 547 | RestoreLiveRegisters(codegen, locations); |
| 548 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 549 | __ b(GetExitLabel()); |
| 550 | } |
| 551 | |
| 552 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 553 | |
| 554 | private: |
| 555 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 556 | }; |
| 557 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 558 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 559 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 560 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 561 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 562 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 563 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 564 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 565 | DCHECK(instruction_->IsCheckCast() |
| 566 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 567 | |
| 568 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 569 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 570 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 571 | if (!is_fatal_) { |
| 572 | SaveLiveRegisters(codegen, locations); |
| 573 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 574 | |
| 575 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 576 | // move resolver. |
| 577 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 578 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 579 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 580 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 581 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 582 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 583 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 584 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 585 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 586 | instruction_, |
| 587 | instruction_->GetDexPc(), |
| 588 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 589 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 590 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 591 | } else { |
| 592 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 593 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 594 | instruction_, |
| 595 | instruction_->GetDexPc(), |
| 596 | this); |
| 597 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 598 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 599 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 600 | if (!is_fatal_) { |
| 601 | RestoreLiveRegisters(codegen, locations); |
| 602 | __ b(GetExitLabel()); |
| 603 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 606 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 607 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 608 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 609 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 610 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 611 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 612 | |
| 613 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 614 | }; |
| 615 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 616 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 617 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 618 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 619 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 620 | |
| 621 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 622 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 623 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 624 | LocationSummary* locations = instruction_->GetLocations(); |
| 625 | SaveLiveRegisters(codegen, locations); |
| 626 | InvokeRuntimeCallingConvention calling_convention; |
| 627 | __ LoadImmediate(calling_convention.GetRegisterAt(0), |
| 628 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 629 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 630 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 633 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 634 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 635 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 636 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 637 | }; |
| 638 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 639 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 640 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 641 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 642 | |
| 643 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 644 | LocationSummary* locations = instruction_->GetLocations(); |
| 645 | __ Bind(GetEntryLabel()); |
| 646 | SaveLiveRegisters(codegen, locations); |
| 647 | |
| 648 | InvokeRuntimeCallingConvention calling_convention; |
| 649 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 650 | parallel_move.AddMove( |
| 651 | locations->InAt(0), |
| 652 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 653 | Primitive::kPrimNot, |
| 654 | nullptr); |
| 655 | parallel_move.AddMove( |
| 656 | locations->InAt(1), |
| 657 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 658 | Primitive::kPrimInt, |
| 659 | nullptr); |
| 660 | parallel_move.AddMove( |
| 661 | locations->InAt(2), |
| 662 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 663 | Primitive::kPrimNot, |
| 664 | nullptr); |
| 665 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 666 | |
| 667 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 668 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 669 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 670 | RestoreLiveRegisters(codegen, locations); |
| 671 | __ b(GetExitLabel()); |
| 672 | } |
| 673 | |
| 674 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 675 | |
| 676 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 677 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 678 | }; |
| 679 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 680 | // Abstract base class for read barrier slow paths marking a reference |
| 681 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 682 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 683 | // Argument `entrypoint` must be a register location holding the read |
| 684 | // barrier marking runtime entry point to be invoked. |
| 685 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 686 | protected: |
| 687 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 688 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 689 | DCHECK(kEmitCompilerReadBarrier); |
| 690 | } |
| 691 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 692 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 693 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 694 | // Generate assembly code calling the read barrier marking runtime |
| 695 | // entry point (ReadBarrierMarkRegX). |
| 696 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 697 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 698 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 699 | // No need to save live registers; it's taken care of by the |
| 700 | // entrypoint. Also, there is no need to update the stack mask, |
| 701 | // as this runtime call will not trigger a garbage collection. |
| 702 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 703 | DCHECK_NE(ref_reg, SP); |
| 704 | DCHECK_NE(ref_reg, LR); |
| 705 | DCHECK_NE(ref_reg, PC); |
| 706 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 707 | // as a temporary, it cannot be the entry point's input/output. |
| 708 | DCHECK_NE(ref_reg, IP); |
| 709 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 710 | // "Compact" slow path, saving two moves. |
| 711 | // |
| 712 | // Instead of using the standard runtime calling convention (input |
| 713 | // and output in R0): |
| 714 | // |
| 715 | // R0 <- ref |
| 716 | // R0 <- ReadBarrierMark(R0) |
| 717 | // ref <- R0 |
| 718 | // |
| 719 | // we just use rX (the register containing `ref`) as input and output |
| 720 | // of a dedicated entrypoint: |
| 721 | // |
| 722 | // rX <- ReadBarrierMarkRegX(rX) |
| 723 | // |
| 724 | if (entrypoint_.IsValid()) { |
| 725 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 726 | __ blx(entrypoint_.AsRegister<Register>()); |
| 727 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 728 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 729 | int32_t entry_point_offset = |
| 730 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 731 | // This runtime call does not require a stack map. |
| 732 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 733 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | // The location (register) of the marked object reference. |
| 737 | const Location ref_; |
| 738 | |
| 739 | // The location of the entrypoint if it is already loaded. |
| 740 | const Location entrypoint_; |
| 741 | |
| 742 | private: |
| 743 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 744 | }; |
| 745 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 746 | // Slow path marking an object reference `ref` during a read |
| 747 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 748 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 749 | // |
| 750 | // This means that after the execution of this slow path, `ref` will |
| 751 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 752 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 753 | // probably still be a from-space reference (unless it gets updated by |
| 754 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 755 | // reference (different from `ref`) in `obj.field`). |
| 756 | // |
| 757 | // If `entrypoint` is a valid location it is assumed to already be |
| 758 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 759 | // 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] | 760 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 761 | public: |
| 762 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 763 | Location ref, |
| 764 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 765 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 766 | DCHECK(kEmitCompilerReadBarrier); |
| 767 | } |
| 768 | |
| 769 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 770 | |
| 771 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 772 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 773 | DCHECK(locations->CanCall()); |
| 774 | if (kIsDebugBuild) { |
| 775 | Register ref_reg = ref_.AsRegister<Register>(); |
| 776 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 777 | } |
| 778 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 779 | << "Unexpected instruction in read barrier marking slow path: " |
| 780 | << instruction_->DebugName(); |
| 781 | |
| 782 | __ Bind(GetEntryLabel()); |
| 783 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 784 | __ b(GetExitLabel()); |
| 785 | } |
| 786 | |
| 787 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 788 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 789 | }; |
| 790 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 791 | // Slow path loading `obj`'s lock word, loading a reference from |
| 792 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 793 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 794 | // read barrier). The field `obj.field` in the object `obj` holding |
| 795 | // this reference does not get updated by this slow path after marking |
| 796 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 797 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 798 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 799 | // This means that after the execution of this slow path, `ref` will |
| 800 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 801 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 802 | // probably still be a from-space reference (unless it gets updated by |
| 803 | // another thread, or if another thread installed another object |
| 804 | // reference (different from `ref`) in `obj.field`). |
| 805 | // |
| 806 | // Argument `entrypoint` must be a register location holding the read |
| 807 | // barrier marking runtime entry point to be invoked. |
| 808 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 809 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 810 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 811 | Location ref, |
| 812 | Register obj, |
| 813 | uint32_t offset, |
| 814 | Location index, |
| 815 | ScaleFactor scale_factor, |
| 816 | bool needs_null_check, |
| 817 | Register temp, |
| 818 | Location entrypoint) |
| 819 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 820 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 821 | offset_(offset), |
| 822 | index_(index), |
| 823 | scale_factor_(scale_factor), |
| 824 | needs_null_check_(needs_null_check), |
| 825 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 826 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 827 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 830 | const char* GetDescription() const OVERRIDE { |
| 831 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 832 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 833 | |
| 834 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 835 | LocationSummary* locations = instruction_->GetLocations(); |
| 836 | Register ref_reg = ref_.AsRegister<Register>(); |
| 837 | DCHECK(locations->CanCall()); |
| 838 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 839 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 840 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 841 | instruction_->IsStaticFieldGet() || |
| 842 | instruction_->IsArrayGet() || |
| 843 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 844 | instruction_->IsInstanceOf() || |
| 845 | instruction_->IsCheckCast() || |
| 846 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 847 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 848 | << "Unexpected instruction in read barrier marking slow path: " |
| 849 | << instruction_->DebugName(); |
| 850 | // The read barrier instrumentation of object ArrayGet |
| 851 | // instructions does not support the HIntermediateAddress |
| 852 | // instruction. |
| 853 | DCHECK(!(instruction_->IsArrayGet() && |
| 854 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 855 | |
| 856 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 857 | |
| 858 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 859 | // inserted after the original load. However, in fast path based |
| 860 | // Baker's read barriers, we need to perform the load of |
| 861 | // mirror::Object::monitor_ *before* the original reference load. |
| 862 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 863 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 864 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 865 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 866 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 867 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 868 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 869 | // if (is_gray) { |
| 870 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 871 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 872 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 873 | // Note: the original implementation in ReadBarrier::Barrier is |
| 874 | // slightly more complex as it performs additional checks that we do |
| 875 | // not do here for performance reasons. |
| 876 | |
| 877 | // /* int32_t */ monitor = obj->monitor_ |
| 878 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 879 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 880 | if (needs_null_check_) { |
| 881 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 882 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 883 | // /* LockWord */ lock_word = LockWord(monitor) |
| 884 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 885 | "art::LockWord and int32_t have different sizes."); |
| 886 | |
| 887 | // Introduce a dependency on the lock_word including the rb_state, |
| 888 | // which shall prevent load-load reordering without using |
| 889 | // a memory barrier (which would be more expensive). |
| 890 | // `obj` is unchanged by this operation, but its value now depends |
| 891 | // on `temp`. |
| 892 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 893 | |
| 894 | // The actual reference load. |
| 895 | // A possible implicit null check has already been handled above. |
| 896 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 897 | arm_codegen->GenerateRawReferenceLoad( |
| 898 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 899 | |
| 900 | // Mark the object `ref` when `obj` is gray. |
| 901 | // |
| 902 | // if (rb_state == ReadBarrier::GrayState()) |
| 903 | // ref = ReadBarrier::Mark(ref); |
| 904 | // |
| 905 | // Given the numeric representation, it's enough to check the low bit of the |
| 906 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 907 | // which can be a 16-bit instruction unlike the TST immediate. |
| 908 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 909 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 910 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 911 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 912 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 913 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 914 | __ b(GetExitLabel()); |
| 915 | } |
| 916 | |
| 917 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 918 | // The register containing the object holding the marked object reference field. |
| 919 | Register obj_; |
| 920 | // The offset, index and scale factor to access the reference in `obj_`. |
| 921 | uint32_t offset_; |
| 922 | Location index_; |
| 923 | ScaleFactor scale_factor_; |
| 924 | // Is a null check required? |
| 925 | bool needs_null_check_; |
| 926 | // A temporary register used to hold the lock word of `obj_`. |
| 927 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 928 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 929 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 930 | }; |
| 931 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | // Slow path loading `obj`'s lock word, loading a reference from |
| 933 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 934 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 935 | // read barrier). If needed, this slow path also atomically updates |
| 936 | // the field `obj.field` in the object `obj` holding this reference |
| 937 | // after marking (contrary to |
| 938 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 939 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 940 | // |
| 941 | // This means that after the execution of this slow path, both `ref` |
| 942 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 943 | // hold the same to-space reference (unless another thread installed |
| 944 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 945 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 946 | // Argument `entrypoint` must be a register location holding the read |
| 947 | // barrier marking runtime entry point to be invoked. |
| 948 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 949 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 950 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 951 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 952 | Location ref, |
| 953 | Register obj, |
| 954 | uint32_t offset, |
| 955 | Location index, |
| 956 | ScaleFactor scale_factor, |
| 957 | bool needs_null_check, |
| 958 | Register temp1, |
| 959 | Register temp2, |
| 960 | Location entrypoint) |
| 961 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 962 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 963 | offset_(offset), |
| 964 | index_(index), |
| 965 | scale_factor_(scale_factor), |
| 966 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 967 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 968 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 969 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 970 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 973 | const char* GetDescription() const OVERRIDE { |
| 974 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 975 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 976 | |
| 977 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 978 | LocationSummary* locations = instruction_->GetLocations(); |
| 979 | Register ref_reg = ref_.AsRegister<Register>(); |
| 980 | DCHECK(locations->CanCall()); |
| 981 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | DCHECK_NE(ref_reg, temp1_); |
| 983 | |
| 984 | // 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] | 985 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 986 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 987 | << instruction_->DebugName(); |
| 988 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 989 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 990 | DCHECK_EQ(offset_, 0u); |
| 991 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 992 | // The location of the offset of the marked reference field within `obj_`. |
| 993 | Location field_offset = index_; |
| 994 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 995 | |
| 996 | __ Bind(GetEntryLabel()); |
| 997 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 998 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM's: |
| 999 | // |
| 1000 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1001 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1002 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1003 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1004 | // if (is_gray) { |
| 1005 | // old_ref = ref; |
| 1006 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1007 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1008 | // } |
| 1009 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1010 | // /* int32_t */ monitor = obj->monitor_ |
| 1011 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1012 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1013 | if (needs_null_check_) { |
| 1014 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1015 | } |
| 1016 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1017 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1018 | "art::LockWord and int32_t have different sizes."); |
| 1019 | |
| 1020 | // Introduce a dependency on the lock_word including the rb_state, |
| 1021 | // which shall prevent load-load reordering without using |
| 1022 | // a memory barrier (which would be more expensive). |
| 1023 | // `obj` is unchanged by this operation, but its value now depends |
| 1024 | // on `temp1`. |
| 1025 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 1026 | |
| 1027 | // The actual reference load. |
| 1028 | // A possible implicit null check has already been handled above. |
| 1029 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1030 | arm_codegen->GenerateRawReferenceLoad( |
| 1031 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1032 | |
| 1033 | // Mark the object `ref` when `obj` is gray. |
| 1034 | // |
| 1035 | // if (rb_state == ReadBarrier::GrayState()) |
| 1036 | // ref = ReadBarrier::Mark(ref); |
| 1037 | // |
| 1038 | // Given the numeric representation, it's enough to check the low bit of the |
| 1039 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1040 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1041 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1042 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1043 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1044 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 1045 | |
| 1046 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1047 | // Note that we cannot use IP to save the old reference, as IP is |
| 1048 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1049 | // need the old reference after the call to that entry point. |
| 1050 | DCHECK_NE(temp1_, IP); |
| 1051 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1052 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1053 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1054 | |
| 1055 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1056 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1057 | // |
| 1058 | // Note that this field could also hold a different object, if |
| 1059 | // another thread had concurrently changed it. In that case, the |
| 1060 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1061 | // (CAS) operation below would abort the CAS, leaving the field |
| 1062 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1063 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1064 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1065 | |
| 1066 | // Update the the holder's field atomically. This may fail if |
| 1067 | // mutator updates before us, but it's OK. This is achieved |
| 1068 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1069 | // memory synchronization ordering, where the expected value is |
| 1070 | // the old reference and the desired value is the new reference. |
| 1071 | |
| 1072 | // Convenience aliases. |
| 1073 | Register base = obj_; |
| 1074 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1075 | // offset ("long offset"), of which only the low part contains |
| 1076 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1077 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1078 | Register expected = temp1_; |
| 1079 | Register value = ref_reg; |
| 1080 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1081 | Register tmp = temp2_; // Value in memory. |
| 1082 | |
| 1083 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1084 | |
| 1085 | if (kPoisonHeapReferences) { |
| 1086 | __ PoisonHeapReference(expected); |
| 1087 | if (value == expected) { |
| 1088 | // Do not poison `value`, as it is the same register as |
| 1089 | // `expected`, which has just been poisoned. |
| 1090 | } else { |
| 1091 | __ PoisonHeapReference(value); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // do { |
| 1096 | // tmp = [r_ptr] - expected; |
| 1097 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1098 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1099 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1100 | __ Bind(&loop_head); |
| 1101 | |
| 1102 | __ ldrex(tmp, tmp_ptr); |
| 1103 | |
| 1104 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1105 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1106 | __ it(NE); |
| 1107 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1108 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1109 | __ b(&exit_loop, NE); |
| 1110 | |
| 1111 | __ strex(tmp, value, tmp_ptr); |
| 1112 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1113 | __ b(&loop_head, EQ); |
| 1114 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1115 | __ Bind(&exit_loop); |
| 1116 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1117 | if (kPoisonHeapReferences) { |
| 1118 | __ UnpoisonHeapReference(expected); |
| 1119 | if (value == expected) { |
| 1120 | // Do not unpoison `value`, as it is the same register as |
| 1121 | // `expected`, which has just been unpoisoned. |
| 1122 | } else { |
| 1123 | __ UnpoisonHeapReference(value); |
| 1124 | } |
| 1125 | } |
| 1126 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1127 | __ b(GetExitLabel()); |
| 1128 | } |
| 1129 | |
| 1130 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1131 | // The register containing the object holding the marked object reference field. |
| 1132 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1133 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1134 | uint32_t offset_; |
| 1135 | Location index_; |
| 1136 | ScaleFactor scale_factor_; |
| 1137 | // Is a null check required? |
| 1138 | bool needs_null_check_; |
| 1139 | // A temporary register used to hold the lock word of `obj_`; and |
| 1140 | // also to hold the original reference value, when the reference is |
| 1141 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1142 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1143 | // A temporary register used in the implementation of the CAS, to |
| 1144 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1145 | const Register temp2_; |
| 1146 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1147 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1148 | }; |
| 1149 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1150 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1151 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1152 | public: |
| 1153 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1154 | Location out, |
| 1155 | Location ref, |
| 1156 | Location obj, |
| 1157 | uint32_t offset, |
| 1158 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1159 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1160 | out_(out), |
| 1161 | ref_(ref), |
| 1162 | obj_(obj), |
| 1163 | offset_(offset), |
| 1164 | index_(index) { |
| 1165 | DCHECK(kEmitCompilerReadBarrier); |
| 1166 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1167 | // has been overwritten by (or after) the heap object reference load |
| 1168 | // to be instrumented, e.g.: |
| 1169 | // |
| 1170 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1171 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1172 | // |
| 1173 | // In that case, we have lost the information about the original |
| 1174 | // object, and the emitted read barrier cannot work properly. |
| 1175 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1176 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1177 | } |
| 1178 | |
| 1179 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1180 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1181 | LocationSummary* locations = instruction_->GetLocations(); |
| 1182 | Register reg_out = out_.AsRegister<Register>(); |
| 1183 | DCHECK(locations->CanCall()); |
| 1184 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1185 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1186 | instruction_->IsStaticFieldGet() || |
| 1187 | instruction_->IsArrayGet() || |
| 1188 | instruction_->IsInstanceOf() || |
| 1189 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1190 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1191 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1192 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1193 | // The read barrier instrumentation of object ArrayGet |
| 1194 | // instructions does not support the HIntermediateAddress |
| 1195 | // instruction. |
| 1196 | DCHECK(!(instruction_->IsArrayGet() && |
| 1197 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1198 | |
| 1199 | __ Bind(GetEntryLabel()); |
| 1200 | SaveLiveRegisters(codegen, locations); |
| 1201 | |
| 1202 | // We may have to change the index's value, but as `index_` is a |
| 1203 | // constant member (like other "inputs" of this slow path), |
| 1204 | // introduce a copy of it, `index`. |
| 1205 | Location index = index_; |
| 1206 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1207 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1208 | if (instruction_->IsArrayGet()) { |
| 1209 | // Compute the actual memory offset and store it in `index`. |
| 1210 | Register index_reg = index_.AsRegister<Register>(); |
| 1211 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1212 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1213 | // We are about to change the value of `index_reg` (see the |
| 1214 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1215 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1216 | // not been saved by the previous call to |
| 1217 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1218 | // callee-save register -- |
| 1219 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1220 | // callee-save registers, as it has been designed with the |
| 1221 | // assumption that callee-save registers are supposed to be |
| 1222 | // handled by the called function. So, as a callee-save |
| 1223 | // register, `index_reg` _would_ eventually be saved onto |
| 1224 | // the stack, but it would be too late: we would have |
| 1225 | // changed its value earlier. Therefore, we manually save |
| 1226 | // it here into another freely available register, |
| 1227 | // `free_reg`, chosen of course among the caller-save |
| 1228 | // registers (as a callee-save `free_reg` register would |
| 1229 | // exhibit the same problem). |
| 1230 | // |
| 1231 | // Note we could have requested a temporary register from |
| 1232 | // the register allocator instead; but we prefer not to, as |
| 1233 | // this is a slow path, and we know we can find a |
| 1234 | // caller-save register that is available. |
| 1235 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1236 | __ Mov(free_reg, index_reg); |
| 1237 | index_reg = free_reg; |
| 1238 | index = Location::RegisterLocation(index_reg); |
| 1239 | } else { |
| 1240 | // The initial register stored in `index_` has already been |
| 1241 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1242 | // (as it is not a callee-save register), so we can freely |
| 1243 | // use it. |
| 1244 | } |
| 1245 | // Shifting the index value contained in `index_reg` by the scale |
| 1246 | // factor (2) cannot overflow in practice, as the runtime is |
| 1247 | // unable to allocate object arrays with a size larger than |
| 1248 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1249 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1250 | static_assert( |
| 1251 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1252 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1253 | __ AddConstant(index_reg, index_reg, offset_); |
| 1254 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1255 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1256 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1257 | // (as in the case of ArrayGet), as it is actually an offset |
| 1258 | // to an object field within an object. |
| 1259 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1260 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1261 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1262 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1263 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1264 | DCHECK_EQ(offset_, 0U); |
| 1265 | DCHECK(index_.IsRegisterPair()); |
| 1266 | // UnsafeGet's offset location is a register pair, the low |
| 1267 | // part contains the correct offset. |
| 1268 | index = index_.ToLow(); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | // We're moving two or three locations to locations that could |
| 1273 | // overlap, so we need a parallel move resolver. |
| 1274 | InvokeRuntimeCallingConvention calling_convention; |
| 1275 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1276 | parallel_move.AddMove(ref_, |
| 1277 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1278 | Primitive::kPrimNot, |
| 1279 | nullptr); |
| 1280 | parallel_move.AddMove(obj_, |
| 1281 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1282 | Primitive::kPrimNot, |
| 1283 | nullptr); |
| 1284 | if (index.IsValid()) { |
| 1285 | parallel_move.AddMove(index, |
| 1286 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1287 | Primitive::kPrimInt, |
| 1288 | nullptr); |
| 1289 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1290 | } else { |
| 1291 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1292 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1293 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1294 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1295 | CheckEntrypointTypes< |
| 1296 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1297 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1298 | |
| 1299 | RestoreLiveRegisters(codegen, locations); |
| 1300 | __ b(GetExitLabel()); |
| 1301 | } |
| 1302 | |
| 1303 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1304 | |
| 1305 | private: |
| 1306 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1307 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1308 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1309 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1310 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1311 | return static_cast<Register>(i); |
| 1312 | } |
| 1313 | } |
| 1314 | // We shall never fail to find a free caller-save register, as |
| 1315 | // there are more than two core caller-save registers on ARM |
| 1316 | // (meaning it is possible to find one which is different from |
| 1317 | // `ref` and `obj`). |
| 1318 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1319 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1320 | UNREACHABLE(); |
| 1321 | } |
| 1322 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1323 | const Location out_; |
| 1324 | const Location ref_; |
| 1325 | const Location obj_; |
| 1326 | const uint32_t offset_; |
| 1327 | // An additional location containing an index to an array. |
| 1328 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1329 | // UnsafeGetObjectVolatile intrinsics. |
| 1330 | const Location index_; |
| 1331 | |
| 1332 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1333 | }; |
| 1334 | |
| 1335 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1336 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1337 | public: |
| 1338 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1339 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1340 | DCHECK(kEmitCompilerReadBarrier); |
| 1341 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1342 | |
| 1343 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1344 | LocationSummary* locations = instruction_->GetLocations(); |
| 1345 | Register reg_out = out_.AsRegister<Register>(); |
| 1346 | DCHECK(locations->CanCall()); |
| 1347 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1348 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1349 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1350 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1351 | |
| 1352 | __ Bind(GetEntryLabel()); |
| 1353 | SaveLiveRegisters(codegen, locations); |
| 1354 | |
| 1355 | InvokeRuntimeCallingConvention calling_convention; |
| 1356 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1357 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1358 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1359 | instruction_, |
| 1360 | instruction_->GetDexPc(), |
| 1361 | this); |
| 1362 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1363 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1364 | |
| 1365 | RestoreLiveRegisters(codegen, locations); |
| 1366 | __ b(GetExitLabel()); |
| 1367 | } |
| 1368 | |
| 1369 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1370 | |
| 1371 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1372 | const Location out_; |
| 1373 | const Location root_; |
| 1374 | |
| 1375 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1376 | }; |
| 1377 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1378 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1379 | switch (cond) { |
| 1380 | case kCondEQ: return EQ; |
| 1381 | case kCondNE: return NE; |
| 1382 | case kCondLT: return LT; |
| 1383 | case kCondLE: return LE; |
| 1384 | case kCondGT: return GT; |
| 1385 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1386 | case kCondB: return LO; |
| 1387 | case kCondBE: return LS; |
| 1388 | case kCondA: return HI; |
| 1389 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1390 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1391 | LOG(FATAL) << "Unreachable"; |
| 1392 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1395 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1396 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1397 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1398 | case kCondEQ: return EQ; |
| 1399 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1400 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1401 | case kCondLT: return LO; |
| 1402 | case kCondLE: return LS; |
| 1403 | case kCondGT: return HI; |
| 1404 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1405 | // Unsigned remain unchanged. |
| 1406 | case kCondB: return LO; |
| 1407 | case kCondBE: return LS; |
| 1408 | case kCondA: return HI; |
| 1409 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1410 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1411 | LOG(FATAL) << "Unreachable"; |
| 1412 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1415 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1416 | // The ARM condition codes can express all the necessary branches, see the |
| 1417 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1418 | // There is no dex instruction or HIR that would need the missing conditions |
| 1419 | // "equal or unordered" or "not equal". |
| 1420 | switch (cond) { |
| 1421 | case kCondEQ: return EQ; |
| 1422 | case kCondNE: return NE /* unordered */; |
| 1423 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1424 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1425 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1426 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1427 | default: |
| 1428 | LOG(FATAL) << "UNREACHABLE"; |
| 1429 | UNREACHABLE(); |
| 1430 | } |
| 1431 | } |
| 1432 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1433 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1434 | switch (op_kind) { |
| 1435 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1436 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1437 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1438 | default: |
| 1439 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1440 | UNREACHABLE(); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1445 | Register out, |
| 1446 | Register first, |
| 1447 | const ShifterOperand& second, |
| 1448 | CodeGeneratorARM* codegen) { |
| 1449 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1450 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1451 | ? ShifterOperand(0) |
| 1452 | : ShifterOperand(first); |
| 1453 | |
| 1454 | __ mov(out, in); |
| 1455 | } else { |
| 1456 | switch (kind) { |
| 1457 | case HInstruction::kAdd: |
| 1458 | __ add(out, first, second); |
| 1459 | break; |
| 1460 | case HInstruction::kAnd: |
| 1461 | __ and_(out, first, second); |
| 1462 | break; |
| 1463 | case HInstruction::kOr: |
| 1464 | __ orr(out, first, second); |
| 1465 | break; |
| 1466 | case HInstruction::kSub: |
| 1467 | __ sub(out, first, second); |
| 1468 | break; |
| 1469 | case HInstruction::kXor: |
| 1470 | __ eor(out, first, second); |
| 1471 | break; |
| 1472 | default: |
| 1473 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1474 | UNREACHABLE(); |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1480 | const Location& out, |
| 1481 | const Location& first, |
| 1482 | const ShifterOperand& second_lo, |
| 1483 | const ShifterOperand& second_hi, |
| 1484 | CodeGeneratorARM* codegen) { |
| 1485 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1486 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1487 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1488 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1489 | |
| 1490 | if (kind == HInstruction::kAdd) { |
| 1491 | __ adds(out_lo, first_lo, second_lo); |
| 1492 | __ adc(out_hi, first_hi, second_hi); |
| 1493 | } else if (kind == HInstruction::kSub) { |
| 1494 | __ subs(out_lo, first_lo, second_lo); |
| 1495 | __ sbc(out_hi, first_hi, second_hi); |
| 1496 | } else { |
| 1497 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1498 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1503 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1504 | } |
| 1505 | |
| 1506 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1507 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1508 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1509 | |
| 1510 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1511 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1512 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1513 | const Location first = locations->InAt(0); |
| 1514 | const Location second = locations->InAt(1); |
| 1515 | const Location out = locations->Out(); |
| 1516 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1517 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1518 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1519 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1520 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1521 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1522 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1523 | |
| 1524 | if (shift_value >= 32) { |
| 1525 | if (shift == LSL) { |
| 1526 | GenerateDataProcInstruction(kind, |
| 1527 | out_hi, |
| 1528 | first_hi, |
| 1529 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1530 | codegen); |
| 1531 | GenerateDataProcInstruction(kind, |
| 1532 | out_lo, |
| 1533 | first_lo, |
| 1534 | ShifterOperand(0), |
| 1535 | codegen); |
| 1536 | } else if (shift == ASR) { |
| 1537 | GenerateDataProc(kind, |
| 1538 | out, |
| 1539 | first, |
| 1540 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1541 | ShifterOperand(second_hi, ASR, 31), |
| 1542 | codegen); |
| 1543 | } else { |
| 1544 | DCHECK_EQ(shift, LSR); |
| 1545 | GenerateDataProc(kind, |
| 1546 | out, |
| 1547 | first, |
| 1548 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1549 | ShifterOperand(0), |
| 1550 | codegen); |
| 1551 | } |
| 1552 | } else { |
| 1553 | DCHECK_GT(shift_value, 1U); |
| 1554 | DCHECK_LT(shift_value, 32U); |
| 1555 | |
| 1556 | if (shift == LSL) { |
| 1557 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1558 | // Location::kOutputOverlap; not applicable to other cases. |
| 1559 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1560 | GenerateDataProcInstruction(kind, |
| 1561 | out_hi, |
| 1562 | first_hi, |
| 1563 | ShifterOperand(second_hi, LSL, shift_value), |
| 1564 | codegen); |
| 1565 | GenerateDataProcInstruction(kind, |
| 1566 | out_hi, |
| 1567 | out_hi, |
| 1568 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1569 | codegen); |
| 1570 | GenerateDataProcInstruction(kind, |
| 1571 | out_lo, |
| 1572 | first_lo, |
| 1573 | ShifterOperand(second_lo, LSL, shift_value), |
| 1574 | codegen); |
| 1575 | } else { |
| 1576 | __ Lsl(IP, second_hi, shift_value); |
| 1577 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1578 | GenerateDataProc(kind, |
| 1579 | out, |
| 1580 | first, |
| 1581 | ShifterOperand(second_lo, LSL, shift_value), |
| 1582 | ShifterOperand(IP), |
| 1583 | codegen); |
| 1584 | } |
| 1585 | } else { |
| 1586 | DCHECK(shift == ASR || shift == LSR); |
| 1587 | |
| 1588 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1589 | // Location::kOutputOverlap; not applicable to other cases. |
| 1590 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1591 | GenerateDataProcInstruction(kind, |
| 1592 | out_lo, |
| 1593 | first_lo, |
| 1594 | ShifterOperand(second_lo, LSR, shift_value), |
| 1595 | codegen); |
| 1596 | GenerateDataProcInstruction(kind, |
| 1597 | out_lo, |
| 1598 | out_lo, |
| 1599 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1600 | codegen); |
| 1601 | GenerateDataProcInstruction(kind, |
| 1602 | out_hi, |
| 1603 | first_hi, |
| 1604 | ShifterOperand(second_hi, shift, shift_value), |
| 1605 | codegen); |
| 1606 | } else { |
| 1607 | __ Lsr(IP, second_lo, shift_value); |
| 1608 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1609 | GenerateDataProc(kind, |
| 1610 | out, |
| 1611 | first, |
| 1612 | ShifterOperand(IP), |
| 1613 | ShifterOperand(second_hi, shift, shift_value), |
| 1614 | codegen); |
| 1615 | } |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1620 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1621 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1622 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1623 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1624 | if (rhs_loc.IsConstant()) { |
| 1625 | // 0.0 is the only immediate that can be encoded directly in |
| 1626 | // a VCMP instruction. |
| 1627 | // |
| 1628 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1629 | // specify that in a floating-point comparison, positive zero |
| 1630 | // and negative zero are considered equal, so we can use the |
| 1631 | // literal 0.0 for both cases here. |
| 1632 | // |
| 1633 | // Note however that some methods (Float.equal, Float.compare, |
| 1634 | // Float.compareTo, Double.equal, Double.compare, |
| 1635 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1636 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1637 | // -0.0. So if we ever translate calls to these methods into a |
| 1638 | // HCompare instruction, we must handle the -0.0 case with |
| 1639 | // care here. |
| 1640 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1641 | if (type == Primitive::kPrimFloat) { |
| 1642 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1643 | } else { |
| 1644 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1645 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1646 | } |
| 1647 | } else { |
| 1648 | if (type == Primitive::kPrimFloat) { |
| 1649 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1650 | } else { |
| 1651 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1652 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1653 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1658 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1659 | IfCondition* condition, |
| 1660 | IfCondition* opposite) { |
| 1661 | if (value == 1) { |
| 1662 | if (*condition == kCondB) { |
| 1663 | value = 0; |
| 1664 | *condition = kCondEQ; |
| 1665 | *opposite = kCondNE; |
| 1666 | } else if (*condition == kCondAE) { |
| 1667 | value = 0; |
| 1668 | *condition = kCondNE; |
| 1669 | *opposite = kCondEQ; |
| 1670 | } |
| 1671 | } else if (value == -1) { |
| 1672 | if (*condition == kCondGT) { |
| 1673 | value = 0; |
| 1674 | *condition = kCondGE; |
| 1675 | *opposite = kCondLT; |
| 1676 | } else if (*condition == kCondLE) { |
| 1677 | value = 0; |
| 1678 | *condition = kCondLT; |
| 1679 | *opposite = kCondGE; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | return value; |
| 1684 | } |
| 1685 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1686 | static std::pair<Condition, Condition> GenerateLongTestConstant(HCondition* condition, |
| 1687 | bool invert, |
| 1688 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1689 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1690 | |
| 1691 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1692 | IfCondition cond = condition->GetCondition(); |
| 1693 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1694 | |
| 1695 | if (invert) { |
| 1696 | std::swap(cond, opposite); |
| 1697 | } |
| 1698 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1699 | std::pair<Condition, Condition> ret(EQ, NE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1700 | const Location left = locations->InAt(0); |
| 1701 | const Location right = locations->InAt(1); |
| 1702 | |
| 1703 | DCHECK(right.IsConstant()); |
| 1704 | |
| 1705 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1706 | const Register left_low = left.AsRegisterPairLow<Register>(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1707 | int64_t value = AdjustConstantForCondition(right.GetConstant()->AsLongConstant()->GetValue(), |
| 1708 | &cond, |
| 1709 | &opposite); |
| 1710 | |
| 1711 | // Comparisons against 0 are common enough to deserve special attention. |
| 1712 | if (value == 0) { |
| 1713 | switch (cond) { |
| 1714 | case kCondNE: |
| 1715 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1716 | case kCondA: |
| 1717 | ret = std::make_pair(NE, EQ); |
| 1718 | FALLTHROUGH_INTENDED; |
| 1719 | case kCondEQ: |
| 1720 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1721 | case kCondBE: |
| 1722 | __ orrs(IP, left_low, ShifterOperand(left_high)); |
| 1723 | return ret; |
| 1724 | case kCondLT: |
| 1725 | case kCondGE: |
| 1726 | __ cmp(left_high, ShifterOperand(0)); |
| 1727 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1728 | // Trivially true or false. |
| 1729 | case kCondB: |
| 1730 | ret = std::make_pair(NE, EQ); |
| 1731 | FALLTHROUGH_INTENDED; |
| 1732 | case kCondAE: |
| 1733 | __ cmp(left_low, ShifterOperand(left_low)); |
| 1734 | return ret; |
| 1735 | default: |
| 1736 | break; |
| 1737 | } |
| 1738 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1739 | |
| 1740 | switch (cond) { |
| 1741 | case kCondEQ: |
| 1742 | case kCondNE: |
| 1743 | case kCondB: |
| 1744 | case kCondBE: |
| 1745 | case kCondA: |
| 1746 | case kCondAE: |
| 1747 | __ CmpConstant(left_high, High32Bits(value)); |
| 1748 | __ it(EQ); |
| 1749 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1750 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1751 | break; |
| 1752 | case kCondLE: |
| 1753 | case kCondGT: |
| 1754 | // Trivially true or false. |
| 1755 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1756 | __ cmp(left_low, ShifterOperand(left_low)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1757 | 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] | 1758 | break; |
| 1759 | } |
| 1760 | |
| 1761 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1762 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1763 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1764 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1765 | } else { |
| 1766 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1767 | DCHECK_EQ(opposite, kCondLE); |
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 | } |
| 1771 | |
| 1772 | value++; |
| 1773 | FALLTHROUGH_INTENDED; |
| 1774 | case kCondGE: |
| 1775 | case kCondLT: |
| 1776 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1777 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1778 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1779 | break; |
| 1780 | default: |
| 1781 | LOG(FATAL) << "Unreachable"; |
| 1782 | UNREACHABLE(); |
| 1783 | } |
| 1784 | |
| 1785 | return ret; |
| 1786 | } |
| 1787 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1788 | static std::pair<Condition, Condition> GenerateLongTest(HCondition* condition, |
| 1789 | bool invert, |
| 1790 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1791 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1792 | |
| 1793 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1794 | IfCondition cond = condition->GetCondition(); |
| 1795 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1796 | |
| 1797 | if (invert) { |
| 1798 | std::swap(cond, opposite); |
| 1799 | } |
| 1800 | |
| 1801 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1802 | Location left = locations->InAt(0); |
| 1803 | Location right = locations->InAt(1); |
| 1804 | |
| 1805 | DCHECK(right.IsRegisterPair()); |
| 1806 | |
| 1807 | switch (cond) { |
| 1808 | case kCondEQ: |
| 1809 | case kCondNE: |
| 1810 | case kCondB: |
| 1811 | case kCondBE: |
| 1812 | case kCondA: |
| 1813 | case kCondAE: |
| 1814 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1815 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1816 | __ it(EQ); |
| 1817 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1818 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1819 | EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1820 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1821 | break; |
| 1822 | case kCondLE: |
| 1823 | case kCondGT: |
| 1824 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1825 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1826 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1827 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1828 | } else { |
| 1829 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1830 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1831 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1832 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | std::swap(left, right); |
| 1836 | FALLTHROUGH_INTENDED; |
| 1837 | case kCondGE: |
| 1838 | case kCondLT: |
| 1839 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1840 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1841 | __ sbcs(IP, |
| 1842 | left.AsRegisterPairHigh<Register>(), |
| 1843 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1844 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1845 | break; |
| 1846 | default: |
| 1847 | LOG(FATAL) << "Unreachable"; |
| 1848 | UNREACHABLE(); |
| 1849 | } |
| 1850 | |
| 1851 | return ret; |
| 1852 | } |
| 1853 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1854 | static std::pair<Condition, Condition> GenerateTest(HCondition* condition, |
| 1855 | bool invert, |
| 1856 | CodeGeneratorARM* codegen) { |
| 1857 | const LocationSummary* const locations = condition->GetLocations(); |
| 1858 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1859 | IfCondition cond = condition->GetCondition(); |
| 1860 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1861 | std::pair<Condition, Condition> ret; |
| 1862 | const Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1863 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1864 | if (invert) { |
| 1865 | std::swap(cond, opposite); |
| 1866 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1867 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1868 | if (type == Primitive::kPrimLong) { |
| 1869 | ret = locations->InAt(1).IsConstant() |
| 1870 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1871 | : GenerateLongTest(condition, invert, codegen); |
| 1872 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1873 | GenerateVcmp(condition, codegen); |
| 1874 | __ vmstat(); |
| 1875 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1876 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1877 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1878 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1879 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1880 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1881 | |
| 1882 | if (right.IsRegister()) { |
| 1883 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1884 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1885 | DCHECK(right.IsConstant()); |
| 1886 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1887 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1888 | |
| 1889 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | return ret; |
| 1893 | } |
| 1894 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1895 | static bool CanGenerateTest(HCondition* condition, ArmAssembler* assembler) { |
| 1896 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1897 | const LocationSummary* const locations = condition->GetLocations(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1898 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1899 | if (locations->InAt(1).IsConstant()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1900 | IfCondition c = condition->GetCondition(); |
| 1901 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1902 | const int64_t value = AdjustConstantForCondition( |
| 1903 | Int64FromConstant(locations->InAt(1).GetConstant()), |
| 1904 | &c, |
| 1905 | &opposite); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1906 | ShifterOperand so; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1907 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1908 | if (c < kCondLT || c > kCondGE) { |
| 1909 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1910 | // we check that the least significant half of the first input to be compared |
| 1911 | // is in a low register (the other half is read outside an IT block), and |
| 1912 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1913 | // encoding can be used; 0 is always handled, no matter what registers are |
| 1914 | // used by the first input. |
| 1915 | if (value != 0 && |
| 1916 | (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1917 | !IsUint<8>(Low32Bits(value)))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1918 | return false; |
| 1919 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1920 | } else if (c == kCondLE || c == kCondGT) { |
| 1921 | if (value < std::numeric_limits<int64_t>::max() && |
| 1922 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1923 | kNoRegister, |
| 1924 | SBC, |
| 1925 | High32Bits(value + 1), |
| 1926 | kCcSet, |
| 1927 | &so)) { |
| 1928 | return false; |
| 1929 | } |
| 1930 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1931 | kNoRegister, |
| 1932 | SBC, |
| 1933 | High32Bits(value), |
| 1934 | kCcSet, |
| 1935 | &so)) { |
| 1936 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | return true; |
| 1942 | } |
| 1943 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1944 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARM* codegen) { |
| 1945 | DCHECK(CanGenerateTest(cond, codegen->GetAssembler())); |
| 1946 | |
| 1947 | const Register out = cond->GetLocations()->Out().AsRegister<Register>(); |
| 1948 | const auto condition = GenerateTest(cond, false, codegen); |
| 1949 | |
| 1950 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 1951 | |
| 1952 | if (ArmAssembler::IsLowRegister(out)) { |
| 1953 | __ it(condition.first); |
| 1954 | __ mov(out, ShifterOperand(1), condition.first); |
| 1955 | } else { |
| 1956 | Label done_label; |
| 1957 | Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1958 | |
| 1959 | __ b(final_label, condition.second); |
| 1960 | __ LoadImmediate(out, 1); |
| 1961 | |
| 1962 | if (done_label.IsLinked()) { |
| 1963 | __ Bind(&done_label); |
| 1964 | } |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARM* codegen) { |
| 1969 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1970 | |
| 1971 | const LocationSummary* const locations = cond->GetLocations(); |
| 1972 | IfCondition condition = cond->GetCondition(); |
| 1973 | const Register out = locations->Out().AsRegister<Register>(); |
| 1974 | const Location left = locations->InAt(0); |
| 1975 | const Location right = locations->InAt(1); |
| 1976 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1977 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1978 | |
| 1979 | if (right.IsConstant()) { |
| 1980 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1981 | const int64_t value = AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 1982 | &condition, |
| 1983 | &opposite); |
| 1984 | int32_t value_high = -High32Bits(value); |
| 1985 | int32_t value_low = -Low32Bits(value); |
| 1986 | |
| 1987 | // The output uses Location::kNoOutputOverlap. |
| 1988 | if (out == left_high) { |
| 1989 | std::swap(left_low, left_high); |
| 1990 | std::swap(value_low, value_high); |
| 1991 | } |
| 1992 | |
| 1993 | __ AddConstant(out, left_low, value_low); |
| 1994 | __ AddConstant(IP, left_high, value_high); |
| 1995 | } else { |
| 1996 | DCHECK(right.IsRegisterPair()); |
| 1997 | __ sub(IP, left_high, ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1998 | __ sub(out, left_low, ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1999 | } |
| 2000 | |
| 2001 | // Need to check after calling AdjustConstantForCondition(). |
| 2002 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2003 | |
| 2004 | if (condition == kCondNE && ArmAssembler::IsLowRegister(out)) { |
| 2005 | __ orrs(out, out, ShifterOperand(IP)); |
| 2006 | __ it(NE); |
| 2007 | __ mov(out, ShifterOperand(1), NE); |
| 2008 | } else { |
| 2009 | __ orr(out, out, ShifterOperand(IP)); |
| 2010 | codegen->GenerateConditionWithZero(condition, out, out, IP); |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | static void GenerateLongComparesAndJumps(HCondition* cond, |
| 2015 | Label* true_label, |
| 2016 | Label* false_label, |
| 2017 | CodeGeneratorARM* codegen) { |
| 2018 | LocationSummary* locations = cond->GetLocations(); |
| 2019 | Location left = locations->InAt(0); |
| 2020 | Location right = locations->InAt(1); |
| 2021 | IfCondition if_cond = cond->GetCondition(); |
| 2022 | |
| 2023 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2024 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2025 | IfCondition true_high_cond = if_cond; |
| 2026 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2027 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2028 | |
| 2029 | // Set the conditions for the test, remembering that == needs to be |
| 2030 | // decided using the low words. |
| 2031 | switch (if_cond) { |
| 2032 | case kCondEQ: |
| 2033 | case kCondNE: |
| 2034 | // Nothing to do. |
| 2035 | break; |
| 2036 | case kCondLT: |
| 2037 | false_high_cond = kCondGT; |
| 2038 | break; |
| 2039 | case kCondLE: |
| 2040 | true_high_cond = kCondLT; |
| 2041 | break; |
| 2042 | case kCondGT: |
| 2043 | false_high_cond = kCondLT; |
| 2044 | break; |
| 2045 | case kCondGE: |
| 2046 | true_high_cond = kCondGT; |
| 2047 | break; |
| 2048 | case kCondB: |
| 2049 | false_high_cond = kCondA; |
| 2050 | break; |
| 2051 | case kCondBE: |
| 2052 | true_high_cond = kCondB; |
| 2053 | break; |
| 2054 | case kCondA: |
| 2055 | false_high_cond = kCondB; |
| 2056 | break; |
| 2057 | case kCondAE: |
| 2058 | true_high_cond = kCondA; |
| 2059 | break; |
| 2060 | } |
| 2061 | if (right.IsConstant()) { |
| 2062 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2063 | int32_t val_low = Low32Bits(value); |
| 2064 | int32_t val_high = High32Bits(value); |
| 2065 | |
| 2066 | __ CmpConstant(left_high, val_high); |
| 2067 | if (if_cond == kCondNE) { |
| 2068 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2069 | } else if (if_cond == kCondEQ) { |
| 2070 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2071 | } else { |
| 2072 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2073 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2074 | } |
| 2075 | // Must be equal high, so compare the lows. |
| 2076 | __ CmpConstant(left_low, val_low); |
| 2077 | } else { |
| 2078 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2079 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2080 | |
| 2081 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2082 | if (if_cond == kCondNE) { |
| 2083 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2084 | } else if (if_cond == kCondEQ) { |
| 2085 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2086 | } else { |
| 2087 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2088 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2089 | } |
| 2090 | // Must be equal high, so compare the lows. |
| 2091 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2092 | } |
| 2093 | // The last comparison might be unsigned. |
| 2094 | // TODO: optimize cases where this is always true/false |
| 2095 | __ b(true_label, final_condition); |
| 2096 | } |
| 2097 | |
| 2098 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARM* codegen) { |
| 2099 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 2100 | |
| 2101 | const LocationSummary* const locations = cond->GetLocations(); |
| 2102 | IfCondition condition = cond->GetCondition(); |
| 2103 | const Register out = locations->Out().AsRegister<Register>(); |
| 2104 | const Location left = locations->InAt(0); |
| 2105 | const Location right = locations->InAt(1); |
| 2106 | |
| 2107 | if (right.IsConstant()) { |
| 2108 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2109 | |
| 2110 | // Comparisons against 0 are common enough to deserve special attention. |
| 2111 | if (AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 2112 | &condition, |
| 2113 | &opposite) == 0) { |
| 2114 | switch (condition) { |
| 2115 | case kCondNE: |
| 2116 | case kCondA: |
| 2117 | if (ArmAssembler::IsLowRegister(out)) { |
| 2118 | // We only care if both input registers are 0 or not. |
| 2119 | __ orrs(out, |
| 2120 | left.AsRegisterPairLow<Register>(), |
| 2121 | ShifterOperand(left.AsRegisterPairHigh<Register>())); |
| 2122 | __ it(NE); |
| 2123 | __ mov(out, ShifterOperand(1), NE); |
| 2124 | return; |
| 2125 | } |
| 2126 | |
| 2127 | FALLTHROUGH_INTENDED; |
| 2128 | case kCondEQ: |
| 2129 | case kCondBE: |
| 2130 | // We only care if both input registers are 0 or not. |
| 2131 | __ orr(out, |
| 2132 | left.AsRegisterPairLow<Register>(), |
| 2133 | ShifterOperand(left.AsRegisterPairHigh<Register>())); |
| 2134 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2135 | return; |
| 2136 | case kCondLT: |
| 2137 | case kCondGE: |
| 2138 | // We only care about the sign bit. |
| 2139 | FALLTHROUGH_INTENDED; |
| 2140 | case kCondAE: |
| 2141 | case kCondB: |
| 2142 | codegen->GenerateConditionWithZero(condition, out, left.AsRegisterPairHigh<Register>()); |
| 2143 | return; |
| 2144 | case kCondLE: |
| 2145 | case kCondGT: |
| 2146 | default: |
| 2147 | break; |
| 2148 | } |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | if ((condition == kCondEQ || condition == kCondNE) && |
| 2153 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2154 | // function generates a shorter code sequence that is still branchless. |
| 2155 | (!ArmAssembler::IsLowRegister(out) || !CanGenerateTest(cond, codegen->GetAssembler()))) { |
| 2156 | GenerateEqualLong(cond, codegen); |
| 2157 | return; |
| 2158 | } |
| 2159 | |
| 2160 | if (CanGenerateTest(cond, codegen->GetAssembler())) { |
| 2161 | GenerateConditionGeneric(cond, codegen); |
| 2162 | return; |
| 2163 | } |
| 2164 | |
| 2165 | // Convert the jumps into the result. |
| 2166 | Label done_label; |
| 2167 | Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2168 | Label true_label, false_label; |
| 2169 | |
| 2170 | GenerateLongComparesAndJumps(cond, &true_label, &false_label, codegen); |
| 2171 | |
| 2172 | // False case: result = 0. |
| 2173 | __ Bind(&false_label); |
| 2174 | __ mov(out, ShifterOperand(0)); |
| 2175 | __ b(final_label); |
| 2176 | |
| 2177 | // True case: result = 1. |
| 2178 | __ Bind(&true_label); |
| 2179 | __ mov(out, ShifterOperand(1)); |
| 2180 | |
| 2181 | if (done_label.IsLinked()) { |
| 2182 | __ Bind(&done_label); |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, CodeGeneratorARM* codegen) { |
| 2187 | const Primitive::Type type = cond->GetLeft()->GetType(); |
| 2188 | |
| 2189 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2190 | |
| 2191 | if (type == Primitive::kPrimLong) { |
| 2192 | GenerateConditionLong(cond, codegen); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
| 2196 | const LocationSummary* const locations = cond->GetLocations(); |
| 2197 | IfCondition condition = cond->GetCondition(); |
| 2198 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 2199 | const Register out = locations->Out().AsRegister<Register>(); |
| 2200 | const Location right = cond->GetLocations()->InAt(1); |
| 2201 | int64_t value; |
| 2202 | |
| 2203 | if (right.IsConstant()) { |
| 2204 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2205 | |
| 2206 | value = AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 2207 | &condition, |
| 2208 | &opposite); |
| 2209 | |
| 2210 | // Comparisons against 0 are common enough to deserve special attention. |
| 2211 | if (value == 0) { |
| 2212 | switch (condition) { |
| 2213 | case kCondNE: |
| 2214 | case kCondA: |
| 2215 | if (ArmAssembler::IsLowRegister(out) && out == in) { |
| 2216 | __ cmp(out, ShifterOperand(0)); |
| 2217 | __ it(NE); |
| 2218 | __ mov(out, ShifterOperand(1), NE); |
| 2219 | return; |
| 2220 | } |
| 2221 | |
| 2222 | FALLTHROUGH_INTENDED; |
| 2223 | case kCondEQ: |
| 2224 | case kCondBE: |
| 2225 | case kCondLT: |
| 2226 | case kCondGE: |
| 2227 | case kCondAE: |
| 2228 | case kCondB: |
| 2229 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2230 | return; |
| 2231 | case kCondLE: |
| 2232 | case kCondGT: |
| 2233 | default: |
| 2234 | break; |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | if (condition == kCondEQ || condition == kCondNE) { |
| 2240 | ShifterOperand operand; |
| 2241 | |
| 2242 | if (right.IsConstant()) { |
| 2243 | operand = ShifterOperand(value); |
| 2244 | } else if (out == right.AsRegister<Register>()) { |
| 2245 | // Avoid 32-bit instructions if possible. |
| 2246 | operand = ShifterOperand(in); |
| 2247 | in = right.AsRegister<Register>(); |
| 2248 | } else { |
| 2249 | operand = ShifterOperand(right.AsRegister<Register>()); |
| 2250 | } |
| 2251 | |
| 2252 | if (condition == kCondNE && ArmAssembler::IsLowRegister(out)) { |
| 2253 | __ subs(out, in, operand); |
| 2254 | __ it(NE); |
| 2255 | __ mov(out, ShifterOperand(1), NE); |
| 2256 | } else { |
| 2257 | __ sub(out, in, operand); |
| 2258 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2259 | } |
| 2260 | |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| 2264 | GenerateConditionGeneric(cond, codegen); |
| 2265 | } |
| 2266 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2267 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 2268 | const Primitive::Type type = constant->GetType(); |
| 2269 | bool ret = false; |
| 2270 | |
| 2271 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2272 | |
| 2273 | if (type == Primitive::kPrimLong) { |
| 2274 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 2275 | |
| 2276 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2277 | } else { |
| 2278 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 2279 | } |
| 2280 | |
| 2281 | return ret; |
| 2282 | } |
| 2283 | |
| 2284 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 2285 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 2286 | |
| 2287 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2288 | return Location::ConstantLocation(constant->AsConstant()); |
| 2289 | } |
| 2290 | |
| 2291 | return Location::RequiresRegister(); |
| 2292 | } |
| 2293 | |
| 2294 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2295 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2296 | // we check that we are not dealing with floating-point output (there is no |
| 2297 | // 16-bit VMOV encoding). |
| 2298 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2299 | return false; |
| 2300 | } |
| 2301 | |
| 2302 | // For constants, we also check that the output is in one or two low registers, |
| 2303 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2304 | // MOV encoding can be used. |
| 2305 | if (src.IsConstant()) { |
| 2306 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2307 | return false; |
| 2308 | } |
| 2309 | |
| 2310 | if (out.IsRegister()) { |
| 2311 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 2312 | return false; |
| 2313 | } |
| 2314 | } else { |
| 2315 | DCHECK(out.IsRegisterPair()); |
| 2316 | |
| 2317 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 2318 | return false; |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | return true; |
| 2324 | } |
| 2325 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2326 | #undef __ |
| 2327 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 2328 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 2329 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2330 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 2331 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2332 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2333 | |
| 2334 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2335 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2336 | HInstruction* const next = instruction->GetNext(); |
| 2337 | |
| 2338 | // Avoid a branch to a branch. |
| 2339 | if (next->IsGoto() && (info == nullptr || |
| 2340 | !info->IsBackEdge(*block) || |
| 2341 | !info->HasSuspendCheck())) { |
| 2342 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2343 | } |
| 2344 | |
| 2345 | return final_label; |
| 2346 | } |
| 2347 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2348 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 2349 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 2353 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2354 | } |
| 2355 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2356 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 2357 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 2358 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 2359 | } |
| 2360 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2361 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 2362 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 2363 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 2366 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 2367 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 2368 | return kArmWordSize; |
| 2369 | } |
| 2370 | |
| 2371 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 2372 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 2373 | return kArmWordSize; |
| 2374 | } |
| 2375 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2376 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2377 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 2378 | const CompilerOptions& compiler_options, |
| 2379 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2380 | : CodeGenerator(graph, |
| 2381 | kNumberOfCoreRegisters, |
| 2382 | kNumberOfSRegisters, |
| 2383 | kNumberOfRegisterPairs, |
| 2384 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 2385 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 2386 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 2387 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 2388 | compiler_options, |
| 2389 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 2390 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2391 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2392 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 2393 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 2394 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2395 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2396 | uint32_literals_(std::less<uint32_t>(), |
| 2397 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2398 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2399 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 2400 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2401 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2402 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2403 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 2404 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 2405 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2406 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2407 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2408 | // Always save the LR register to mimic Quick. |
| 2409 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 2410 | } |
| 2411 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2412 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 2413 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 2414 | __ FinalizeCode(); |
| 2415 | |
| 2416 | // Adjust native pc offsets in stack maps. |
| 2417 | 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] | 2418 | uint32_t old_position = |
| 2419 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2420 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 2421 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 2422 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 2423 | // Adjust pc offsets for the disassembly information. |
| 2424 | if (disasm_info_ != nullptr) { |
| 2425 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 2426 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 2427 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 2428 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 2429 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 2430 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 2431 | } |
| 2432 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 2433 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 2434 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 2435 | } |
| 2436 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2437 | |
| 2438 | CodeGenerator::Finalize(allocator); |
| 2439 | } |
| 2440 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2441 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2442 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2443 | blocked_core_registers_[SP] = true; |
| 2444 | blocked_core_registers_[LR] = true; |
| 2445 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2446 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2447 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2448 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2449 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2450 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2451 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2452 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2453 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2454 | // Stubs do not save callee-save floating point registers. If the graph |
| 2455 | // is debuggable, we need to deal with these registers differently. For |
| 2456 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2457 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2458 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2459 | } |
| 2460 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2461 | } |
| 2462 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2463 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2464 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2465 | assembler_(codegen->GetAssembler()), |
| 2466 | codegen_(codegen) {} |
| 2467 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2468 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2469 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2470 | 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] | 2471 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2472 | // restore another arbitrary register. |
| 2473 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2474 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2475 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2476 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2477 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2478 | // but in the range. |
| 2479 | if (fpu_spill_mask_ != 0) { |
| 2480 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2481 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2482 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2483 | fpu_spill_mask_ |= (1 << i); |
| 2484 | } |
| 2485 | } |
| 2486 | } |
| 2487 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2488 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2489 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2493 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2494 | } |
| 2495 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2496 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2497 | bool skip_overflow_check = |
| 2498 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2499 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2500 | __ Bind(&frame_entry_label_); |
| 2501 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2502 | if (HasEmptyFrame()) { |
| 2503 | return; |
| 2504 | } |
| 2505 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2506 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2507 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2508 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2509 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2512 | __ PushList(core_spill_mask_); |
| 2513 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2514 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2515 | if (fpu_spill_mask_ != 0) { |
| 2516 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2517 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2518 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2519 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2520 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2521 | |
| 2522 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2523 | // Initialize should_deoptimize flag to 0. |
| 2524 | __ mov(IP, ShifterOperand(0)); |
| 2525 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2526 | } |
| 2527 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2528 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2529 | __ AddConstant(SP, -adjust); |
| 2530 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2531 | |
| 2532 | // Save the current method if we need it. Note that we do not |
| 2533 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2534 | // in the SSA graph. |
| 2535 | if (RequiresCurrentMethod()) { |
| 2536 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2537 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2541 | if (HasEmptyFrame()) { |
| 2542 | __ bx(LR); |
| 2543 | return; |
| 2544 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2545 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2546 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2547 | __ AddConstant(SP, adjust); |
| 2548 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2549 | if (fpu_spill_mask_ != 0) { |
| 2550 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2551 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2552 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2553 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2554 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2555 | // Pop LR into PC to return. |
| 2556 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2557 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2558 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2559 | __ cfi().RestoreState(); |
| 2560 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2563 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2564 | Label* label = GetLabelOf(block); |
| 2565 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2568 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2569 | switch (type) { |
| 2570 | case Primitive::kPrimBoolean: |
| 2571 | case Primitive::kPrimByte: |
| 2572 | case Primitive::kPrimChar: |
| 2573 | case Primitive::kPrimShort: |
| 2574 | case Primitive::kPrimInt: |
| 2575 | case Primitive::kPrimNot: { |
| 2576 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2577 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2578 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2579 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2580 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2581 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2582 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2583 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2584 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2586 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2587 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2588 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2589 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2590 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2591 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2592 | // Skip R1, and use R2_R3 instead. |
| 2593 | gp_index_++; |
| 2594 | index++; |
| 2595 | } |
| 2596 | } |
| 2597 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2598 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2599 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2600 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2601 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2602 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2603 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2604 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2605 | } |
| 2606 | } |
| 2607 | |
| 2608 | case Primitive::kPrimFloat: { |
| 2609 | uint32_t stack_index = stack_index_++; |
| 2610 | if (float_index_ % 2 == 0) { |
| 2611 | float_index_ = std::max(double_index_, float_index_); |
| 2612 | } |
| 2613 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2614 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2615 | } else { |
| 2616 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2617 | } |
| 2618 | } |
| 2619 | |
| 2620 | case Primitive::kPrimDouble: { |
| 2621 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2622 | uint32_t stack_index = stack_index_; |
| 2623 | stack_index_ += 2; |
| 2624 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2625 | uint32_t index = double_index_; |
| 2626 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2627 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2628 | calling_convention.GetFpuRegisterAt(index), |
| 2629 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2630 | DCHECK(ExpectedPairLayout(result)); |
| 2631 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2632 | } else { |
| 2633 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2637 | case Primitive::kPrimVoid: |
| 2638 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2639 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2640 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2641 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2642 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2643 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2644 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2645 | switch (type) { |
| 2646 | case Primitive::kPrimBoolean: |
| 2647 | case Primitive::kPrimByte: |
| 2648 | case Primitive::kPrimChar: |
| 2649 | case Primitive::kPrimShort: |
| 2650 | case Primitive::kPrimInt: |
| 2651 | case Primitive::kPrimNot: { |
| 2652 | return Location::RegisterLocation(R0); |
| 2653 | } |
| 2654 | |
| 2655 | case Primitive::kPrimFloat: { |
| 2656 | return Location::FpuRegisterLocation(S0); |
| 2657 | } |
| 2658 | |
| 2659 | case Primitive::kPrimLong: { |
| 2660 | return Location::RegisterPairLocation(R0, R1); |
| 2661 | } |
| 2662 | |
| 2663 | case Primitive::kPrimDouble: { |
| 2664 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2665 | } |
| 2666 | |
| 2667 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2668 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2669 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2670 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2671 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2674 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2675 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2676 | } |
| 2677 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2678 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2679 | if (source.Equals(destination)) { |
| 2680 | return; |
| 2681 | } |
| 2682 | if (destination.IsRegister()) { |
| 2683 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2684 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2685 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2687 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2688 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2689 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2690 | } else if (destination.IsFpuRegister()) { |
| 2691 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2692 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2693 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2694 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2695 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2696 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2697 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2698 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2699 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2700 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2702 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2703 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2704 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2705 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2706 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2707 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2713 | if (source.Equals(destination)) { |
| 2714 | return; |
| 2715 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2716 | if (destination.IsRegisterPair()) { |
| 2717 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2718 | EmitParallelMoves( |
| 2719 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2720 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2721 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2722 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2723 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2724 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2725 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2726 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2727 | } else if (source.IsFpuRegisterPair()) { |
| 2728 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2729 | destination.AsRegisterPairHigh<Register>(), |
| 2730 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2731 | } else { |
| 2732 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2733 | DCHECK(ExpectedPairLayout(destination)); |
| 2734 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2735 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2736 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2737 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2738 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2739 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2740 | SP, |
| 2741 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2742 | } else if (source.IsRegisterPair()) { |
| 2743 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2744 | source.AsRegisterPairLow<Register>(), |
| 2745 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2746 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2747 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2748 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2749 | } else { |
| 2750 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2751 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2752 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2753 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2754 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2755 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2756 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2757 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2758 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2759 | SP, destination.GetStackIndex()); |
| 2760 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2761 | } else if (source.IsFpuRegisterPair()) { |
| 2762 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2763 | SP, |
| 2764 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2765 | } else { |
| 2766 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2767 | EmitParallelMoves( |
| 2768 | Location::StackSlot(source.GetStackIndex()), |
| 2769 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2770 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2771 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2772 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2773 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | } |
| 2777 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2778 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2779 | DCHECK(location.IsRegister()); |
| 2780 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2781 | } |
| 2782 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2783 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2784 | HParallelMove move(GetGraph()->GetArena()); |
| 2785 | move.AddMove(src, dst, dst_type, nullptr); |
| 2786 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2790 | if (location.IsRegister()) { |
| 2791 | locations->AddTemp(location); |
| 2792 | } else if (location.IsRegisterPair()) { |
| 2793 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2794 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2795 | } else { |
| 2796 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2797 | } |
| 2798 | } |
| 2799 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2800 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2801 | HInstruction* instruction, |
| 2802 | uint32_t dex_pc, |
| 2803 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2804 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2805 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2806 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2807 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2808 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2809 | } |
| 2810 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2811 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2812 | HInstruction* instruction, |
| 2813 | SlowPathCode* slow_path) { |
| 2814 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2815 | GenerateInvokeRuntime(entry_point_offset); |
| 2816 | } |
| 2817 | |
| 2818 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2819 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2820 | __ blx(LR); |
| 2821 | } |
| 2822 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2823 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2824 | DCHECK(!successor->IsExitBlock()); |
| 2825 | |
| 2826 | HBasicBlock* block = got->GetBlock(); |
| 2827 | HInstruction* previous = got->GetPrevious(); |
| 2828 | |
| 2829 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2830 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2831 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2832 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2833 | return; |
| 2834 | } |
| 2835 | |
| 2836 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2837 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2838 | } |
| 2839 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2840 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2844 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2845 | got->SetLocations(nullptr); |
| 2846 | } |
| 2847 | |
| 2848 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2849 | HandleGoto(got, got->GetSuccessor()); |
| 2850 | } |
| 2851 | |
| 2852 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2853 | try_boundary->SetLocations(nullptr); |
| 2854 | } |
| 2855 | |
| 2856 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2857 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2858 | if (!successor->IsExitBlock()) { |
| 2859 | HandleGoto(try_boundary, successor); |
| 2860 | } |
| 2861 | } |
| 2862 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2863 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2864 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2867 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2870 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2871 | Label* true_target_in, |
| 2872 | Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2873 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2874 | Label* non_fallthrough_target; |
| 2875 | bool invert; |
| 2876 | |
| 2877 | if (true_target_in == nullptr) { |
| 2878 | DCHECK(false_target_in != nullptr); |
| 2879 | non_fallthrough_target = false_target_in; |
| 2880 | invert = true; |
| 2881 | } else { |
| 2882 | non_fallthrough_target = true_target_in; |
| 2883 | invert = false; |
| 2884 | } |
| 2885 | |
| 2886 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2887 | |
| 2888 | __ b(non_fallthrough_target, cond.first); |
| 2889 | |
| 2890 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2891 | __ b(false_target_in); |
| 2892 | } |
| 2893 | |
| 2894 | return; |
| 2895 | } |
| 2896 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2897 | // Generated branching requires both targets to be explicit. If either of the |
| 2898 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2899 | Label fallthrough_target; |
| 2900 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2901 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2902 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2903 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2904 | GenerateLongComparesAndJumps(condition, true_target, false_target, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2905 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2906 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2907 | __ b(false_target); |
| 2908 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2909 | |
| 2910 | if (fallthrough_target.IsLinked()) { |
| 2911 | __ Bind(&fallthrough_target); |
| 2912 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2913 | } |
| 2914 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2915 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2916 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2917 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2918 | Label* false_target) { |
| 2919 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2920 | |
| 2921 | if (true_target == nullptr && false_target == nullptr) { |
| 2922 | // Nothing to do. The code always falls through. |
| 2923 | return; |
| 2924 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2925 | // Constant condition, statically compared against "true" (integer value 1). |
| 2926 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2927 | if (true_target != nullptr) { |
| 2928 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2929 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2930 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2931 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2932 | if (false_target != nullptr) { |
| 2933 | __ b(false_target); |
| 2934 | } |
| 2935 | } |
| 2936 | return; |
| 2937 | } |
| 2938 | |
| 2939 | // The following code generates these patterns: |
| 2940 | // (1) true_target == nullptr && false_target != nullptr |
| 2941 | // - opposite condition true => branch to false_target |
| 2942 | // (2) true_target != nullptr && false_target == nullptr |
| 2943 | // - condition true => branch to true_target |
| 2944 | // (3) true_target != nullptr && false_target != nullptr |
| 2945 | // - condition true => branch to true_target |
| 2946 | // - branch to false_target |
| 2947 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2948 | // Condition has been materialized, compare the output to 0. |
| 2949 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2950 | DCHECK(cond_val.IsRegister()); |
| 2951 | if (true_target == nullptr) { |
| 2952 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2953 | } else { |
| 2954 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2955 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2956 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2957 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2958 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2959 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2960 | |
| 2961 | // If this is a long or FP comparison that has been folded into |
| 2962 | // the HCondition, generate the comparison directly. |
| 2963 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2964 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2965 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2966 | return; |
| 2967 | } |
| 2968 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2969 | Label* non_fallthrough_target; |
| 2970 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2971 | LocationSummary* locations = cond->GetLocations(); |
| 2972 | DCHECK(locations->InAt(0).IsRegister()); |
| 2973 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2974 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2975 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2976 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2977 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2978 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2979 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2980 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2981 | non_fallthrough_target = true_target; |
| 2982 | } |
| 2983 | |
| 2984 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2985 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2986 | if (arm_cond == EQ) { |
| 2987 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2988 | } else { |
| 2989 | DCHECK_EQ(arm_cond, NE); |
| 2990 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2991 | } |
| 2992 | } else { |
| 2993 | if (right.IsRegister()) { |
| 2994 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2995 | } else { |
| 2996 | DCHECK(right.IsConstant()); |
| 2997 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2998 | } |
| 2999 | |
| 3000 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3001 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3002 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3003 | |
| 3004 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3005 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3006 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3007 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3011 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3012 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 3013 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3019 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3020 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 3021 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3022 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3023 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3024 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3025 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3029 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3030 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3031 | InvokeRuntimeCallingConvention calling_convention; |
| 3032 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3033 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3034 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3035 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3036 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3041 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3042 | GenerateTestAndBranch(deoptimize, |
| 3043 | /* condition_input_index */ 0, |
| 3044 | slow_path->GetEntryLabel(), |
| 3045 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3046 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3047 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3048 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3049 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3050 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3051 | locations->SetOut(Location::RequiresRegister()); |
| 3052 | } |
| 3053 | |
| 3054 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3055 | __ LoadFromOffset(kLoadWord, |
| 3056 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 3057 | SP, |
| 3058 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3059 | } |
| 3060 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3061 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 3062 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3063 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 3064 | |
| 3065 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3066 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3067 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3068 | } else { |
| 3069 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3070 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3071 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3072 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3073 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3074 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3075 | // The code generator handles overlap with the values, but not with the condition. |
| 3076 | locations->SetOut(Location::SameAsFirstInput()); |
| 3077 | } else if (is_floating_point) { |
| 3078 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3079 | } else { |
| 3080 | if (!locations->InAt(1).IsConstant()) { |
| 3081 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3082 | } |
| 3083 | |
| 3084 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3085 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3089 | HInstruction* const condition = select->GetCondition(); |
| 3090 | const LocationSummary* const locations = select->GetLocations(); |
| 3091 | const Primitive::Type type = select->GetType(); |
| 3092 | const Location first = locations->InAt(0); |
| 3093 | const Location out = locations->Out(); |
| 3094 | const Location second = locations->InAt(1); |
| 3095 | Location src; |
| 3096 | |
| 3097 | if (condition->IsIntConstant()) { |
| 3098 | if (condition->AsIntConstant()->IsFalse()) { |
| 3099 | src = first; |
| 3100 | } else { |
| 3101 | src = second; |
| 3102 | } |
| 3103 | |
| 3104 | codegen_->MoveLocation(out, src, type); |
| 3105 | return; |
| 3106 | } |
| 3107 | |
| 3108 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3109 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 3110 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3111 | bool invert = false; |
| 3112 | |
| 3113 | if (out.Equals(second)) { |
| 3114 | src = first; |
| 3115 | invert = true; |
| 3116 | } else if (out.Equals(first)) { |
| 3117 | src = second; |
| 3118 | } else if (second.IsConstant()) { |
| 3119 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3120 | src = second; |
| 3121 | } else if (first.IsConstant()) { |
| 3122 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3123 | src = first; |
| 3124 | invert = true; |
| 3125 | } else { |
| 3126 | src = second; |
| 3127 | } |
| 3128 | |
| 3129 | if (CanGenerateConditionalMove(out, src)) { |
| 3130 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3131 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3132 | } |
| 3133 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3134 | std::pair<Condition, Condition> cond; |
| 3135 | |
| 3136 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3137 | __ CmpConstant(locations->InAt(2).AsRegister<Register>(), 0); |
| 3138 | cond = invert ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
| 3139 | } else { |
| 3140 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3141 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3142 | |
| 3143 | if (out.IsRegister()) { |
| 3144 | ShifterOperand operand; |
| 3145 | |
| 3146 | if (src.IsConstant()) { |
| 3147 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 3148 | } else { |
| 3149 | DCHECK(src.IsRegister()); |
| 3150 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 3151 | } |
| 3152 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3153 | __ it(cond.first); |
| 3154 | __ mov(out.AsRegister<Register>(), operand, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3155 | } else { |
| 3156 | DCHECK(out.IsRegisterPair()); |
| 3157 | |
| 3158 | ShifterOperand operand_high; |
| 3159 | ShifterOperand operand_low; |
| 3160 | |
| 3161 | if (src.IsConstant()) { |
| 3162 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 3163 | |
| 3164 | operand_high = ShifterOperand(High32Bits(value)); |
| 3165 | operand_low = ShifterOperand(Low32Bits(value)); |
| 3166 | } else { |
| 3167 | DCHECK(src.IsRegisterPair()); |
| 3168 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 3169 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 3170 | } |
| 3171 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3172 | __ it(cond.first); |
| 3173 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond.first); |
| 3174 | __ it(cond.first); |
| 3175 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | return; |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | Label* false_target = nullptr; |
| 3183 | Label* true_target = nullptr; |
| 3184 | Label select_end; |
| 3185 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 3186 | |
| 3187 | if (out.Equals(second)) { |
| 3188 | true_target = target; |
| 3189 | src = first; |
| 3190 | } else { |
| 3191 | false_target = target; |
| 3192 | src = second; |
| 3193 | |
| 3194 | if (!out.Equals(first)) { |
| 3195 | codegen_->MoveLocation(out, first, type); |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 3200 | codegen_->MoveLocation(out, src, type); |
| 3201 | |
| 3202 | if (select_end.IsLinked()) { |
| 3203 | __ Bind(&select_end); |
| 3204 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3207 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3208 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3209 | } |
| 3210 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3211 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3212 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | void CodeGeneratorARM::GenerateNop() { |
| 3216 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3219 | // `temp` is an extra temporary register that is used for some conditions; |
| 3220 | // callers may not specify it, in which case the method will use a scratch |
| 3221 | // register instead. |
| 3222 | void CodeGeneratorARM::GenerateConditionWithZero(IfCondition condition, |
| 3223 | Register out, |
| 3224 | Register in, |
| 3225 | Register temp) { |
| 3226 | switch (condition) { |
| 3227 | case kCondEQ: |
| 3228 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3229 | case kCondBE: |
| 3230 | if (temp == kNoRegister || (ArmAssembler::IsLowRegister(out) && out != in)) { |
| 3231 | temp = out; |
| 3232 | } |
| 3233 | |
| 3234 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3235 | // different as well. |
| 3236 | if (ArmAssembler::IsLowRegister(in) && ArmAssembler::IsLowRegister(temp) && in != temp) { |
| 3237 | // temp = - in; only 0 sets the carry flag. |
| 3238 | __ rsbs(temp, in, ShifterOperand(0)); |
| 3239 | |
| 3240 | if (out == in) { |
| 3241 | std::swap(in, temp); |
| 3242 | } |
| 3243 | |
| 3244 | // out = - in + in + carry = carry |
| 3245 | __ adc(out, temp, ShifterOperand(in)); |
| 3246 | } else { |
| 3247 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3248 | __ clz(out, in); |
| 3249 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3250 | // the same operation on 32 yields 1. |
| 3251 | __ Lsr(out, out, 5); |
| 3252 | } |
| 3253 | |
| 3254 | break; |
| 3255 | case kCondNE: |
| 3256 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3257 | case kCondA: |
| 3258 | if (out == in) { |
| 3259 | if (temp == kNoRegister || in == temp) { |
| 3260 | temp = IP; |
| 3261 | } |
| 3262 | } else if (temp == kNoRegister || !ArmAssembler::IsLowRegister(temp)) { |
| 3263 | temp = out; |
| 3264 | } |
| 3265 | |
| 3266 | // temp = in - 1; only 0 does not set the carry flag. |
| 3267 | __ subs(temp, in, ShifterOperand(1)); |
| 3268 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3269 | __ sbc(out, in, ShifterOperand(temp)); |
| 3270 | break; |
| 3271 | case kCondGE: |
| 3272 | __ mvn(out, ShifterOperand(in)); |
| 3273 | in = out; |
| 3274 | FALLTHROUGH_INTENDED; |
| 3275 | case kCondLT: |
| 3276 | // We only care about the sign bit. |
| 3277 | __ Lsr(out, in, 31); |
| 3278 | break; |
| 3279 | case kCondAE: |
| 3280 | // Trivially true. |
| 3281 | __ mov(out, ShifterOperand(1)); |
| 3282 | break; |
| 3283 | case kCondB: |
| 3284 | // Trivially false. |
| 3285 | __ mov(out, ShifterOperand(0)); |
| 3286 | break; |
| 3287 | default: |
| 3288 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3289 | UNREACHABLE(); |
| 3290 | } |
| 3291 | } |
| 3292 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3293 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3294 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 3295 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3296 | // Handle the long/FP comparisons made in instruction simplification. |
| 3297 | switch (cond->InputAt(0)->GetType()) { |
| 3298 | case Primitive::kPrimLong: |
| 3299 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3300 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3301 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3303 | } |
| 3304 | break; |
| 3305 | |
| 3306 | case Primitive::kPrimFloat: |
| 3307 | case Primitive::kPrimDouble: |
| 3308 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3309 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3310 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3311 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3312 | } |
| 3313 | break; |
| 3314 | |
| 3315 | default: |
| 3316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3317 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3318 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3320 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3321 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3322 | } |
| 3323 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3324 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3325 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3326 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3327 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3328 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3329 | const Primitive::Type type = cond->GetLeft()->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3330 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3331 | if (Primitive::IsFloatingPointType(type)) { |
| 3332 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3333 | return; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3334 | } |
| 3335 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3336 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3337 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3338 | const IfCondition condition = cond->GetCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3339 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3340 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3341 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3342 | // as a regular condition with integral inputs. |
| 3343 | if (type == Primitive::kPrimBoolean && |
| 3344 | cond->GetRight()->GetType() == Primitive::kPrimBoolean && |
| 3345 | (condition == kCondEQ || condition == kCondNE)) { |
| 3346 | const LocationSummary* const locations = cond->GetLocations(); |
| 3347 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 3348 | const Register out = locations->Out().AsRegister<Register>(); |
| 3349 | const Location right_loc = locations->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3350 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3351 | // The constant case is handled by the instruction simplifier. |
| 3352 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3353 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3354 | Register right = right_loc.AsRegister<Register>(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3355 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3356 | // Avoid 32-bit instructions if possible. |
| 3357 | if (out == right) { |
| 3358 | std::swap(left, right); |
| 3359 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3360 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3361 | __ eor(out, left, ShifterOperand(right)); |
| 3362 | |
| 3363 | if (condition == kCondEQ) { |
| 3364 | __ eor(out, out, ShifterOperand(1)); |
| 3365 | } |
| 3366 | |
| 3367 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3368 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3369 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3370 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3374 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3378 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3382 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3386 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3390 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3394 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3398 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3402 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3406 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3410 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3414 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3418 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3419 | } |
| 3420 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3421 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3422 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3426 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3430 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3434 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3438 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3442 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3446 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3450 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3453 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3454 | LocationSummary* locations = |
| 3455 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3456 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3459 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3460 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3461 | } |
| 3462 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3463 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 3464 | LocationSummary* locations = |
| 3465 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3466 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3467 | } |
| 3468 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3469 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3470 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3473 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3474 | LocationSummary* locations = |
| 3475 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3476 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3479 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3480 | // Will be generated at use site. |
| 3481 | } |
| 3482 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3483 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3484 | LocationSummary* locations = |
| 3485 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3486 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3487 | } |
| 3488 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3489 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3490 | // Will be generated at use site. |
| 3491 | } |
| 3492 | |
| 3493 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3494 | LocationSummary* locations = |
| 3495 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3496 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3497 | } |
| 3498 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3499 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3500 | // Will be generated at use site. |
| 3501 | } |
| 3502 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3503 | void LocationsBuilderARM::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3504 | constructor_fence->SetLocations(nullptr); |
| 3505 | } |
| 3506 | |
| 3507 | void InstructionCodeGeneratorARM::VisitConstructorFence( |
| 3508 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3509 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3510 | } |
| 3511 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3512 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3513 | memory_barrier->SetLocations(nullptr); |
| 3514 | } |
| 3515 | |
| 3516 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3517 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3518 | } |
| 3519 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3520 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3521 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3524 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3525 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3528 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3529 | LocationSummary* locations = |
| 3530 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3531 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3534 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3535 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3538 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3539 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3540 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3541 | // the method_idx. |
| 3542 | HandleInvoke(invoke); |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3546 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3547 | } |
| 3548 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3549 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3550 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3551 | // art::PrepareForRegisterAllocation. |
| 3552 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3553 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3554 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3555 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3556 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3557 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3558 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3559 | return; |
| 3560 | } |
| 3561 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3562 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3563 | |
| 3564 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3565 | if (invoke->HasPcRelativeDexCache()) { |
| 3566 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3567 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3570 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3571 | if (invoke->GetLocations()->Intrinsified()) { |
| 3572 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3573 | intrinsic.Dispatch(invoke); |
| 3574 | return true; |
| 3575 | } |
| 3576 | return false; |
| 3577 | } |
| 3578 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3579 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3580 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3581 | // art::PrepareForRegisterAllocation. |
| 3582 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3583 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3584 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3585 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3586 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3587 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3588 | LocationSummary* locations = invoke->GetLocations(); |
| 3589 | codegen_->GenerateStaticOrDirectCall( |
| 3590 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3591 | } |
| 3592 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3593 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3594 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3595 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3596 | } |
| 3597 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3598 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3599 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3600 | if (intrinsic.TryDispatch(invoke)) { |
| 3601 | return; |
| 3602 | } |
| 3603 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3604 | HandleInvoke(invoke); |
| 3605 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3606 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3607 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3608 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3609 | return; |
| 3610 | } |
| 3611 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3612 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3613 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3614 | } |
| 3615 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3616 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3617 | HandleInvoke(invoke); |
| 3618 | // Add the hidden argument. |
| 3619 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3620 | } |
| 3621 | |
| 3622 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3623 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3624 | LocationSummary* locations = invoke->GetLocations(); |
| 3625 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3626 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3627 | Location receiver = locations->InAt(0); |
| 3628 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3629 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3630 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3631 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3632 | DCHECK_EQ(R12, hidden_reg); |
| 3633 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3634 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3635 | if (receiver.IsStackSlot()) { |
| 3636 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3637 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3638 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3639 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3640 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3641 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3642 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3643 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3644 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3645 | // emit a read barrier for the previous class reference load. |
| 3646 | // However this is not required in practice, as this is an |
| 3647 | // intermediate/temporary reference and because the current |
| 3648 | // concurrent copying collector keeps the from-space memory |
| 3649 | // intact/accessible until the end of the marking phase (the |
| 3650 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3651 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3652 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3653 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3654 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3655 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3656 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3657 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3658 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3659 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3660 | // LR = temp->GetEntryPoint(); |
| 3661 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3662 | // LR(); |
| 3663 | __ blx(LR); |
| 3664 | DCHECK(!codegen_->IsLeafMethod()); |
| 3665 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3666 | } |
| 3667 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3668 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3669 | HandleInvoke(invoke); |
| 3670 | } |
| 3671 | |
| 3672 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3673 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3674 | } |
| 3675 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3676 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3677 | LocationSummary* locations = |
| 3678 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3679 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3680 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3681 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3682 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3683 | break; |
| 3684 | } |
| 3685 | case Primitive::kPrimLong: { |
| 3686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3687 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3688 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3689 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3690 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3691 | case Primitive::kPrimFloat: |
| 3692 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3693 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3694 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3695 | break; |
| 3696 | |
| 3697 | default: |
| 3698 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3703 | LocationSummary* locations = neg->GetLocations(); |
| 3704 | Location out = locations->Out(); |
| 3705 | Location in = locations->InAt(0); |
| 3706 | switch (neg->GetResultType()) { |
| 3707 | case Primitive::kPrimInt: |
| 3708 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3709 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3710 | break; |
| 3711 | |
| 3712 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3713 | DCHECK(in.IsRegisterPair()); |
| 3714 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3715 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3716 | in.AsRegisterPairLow<Register>(), |
| 3717 | ShifterOperand(0)); |
| 3718 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3719 | // instruction here, as it does not exist in the Thumb-2 |
| 3720 | // instruction set. We use the following approach |
| 3721 | // using SBC and SUB instead. |
| 3722 | // |
| 3723 | // out.hi = -C |
| 3724 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3725 | out.AsRegisterPairHigh<Register>(), |
| 3726 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3727 | // out.hi = out.hi - in.hi |
| 3728 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3729 | out.AsRegisterPairHigh<Register>(), |
| 3730 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3731 | break; |
| 3732 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3733 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3734 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3735 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3736 | break; |
| 3737 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3738 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3739 | DCHECK(in.IsFpuRegisterPair()); |
| 3740 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3741 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3742 | break; |
| 3743 | |
| 3744 | default: |
| 3745 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3746 | } |
| 3747 | } |
| 3748 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3749 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3750 | Primitive::Type result_type = conversion->GetResultType(); |
| 3751 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3752 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3753 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3754 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3755 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3756 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3757 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3758 | && result_type == Primitive::kPrimLong) |
| 3759 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3760 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3761 | : LocationSummary::kNoCall; |
| 3762 | LocationSummary* locations = |
| 3763 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3764 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3765 | // The Java language does not allow treating boolean as an integral type but |
| 3766 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3767 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3768 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3769 | case Primitive::kPrimByte: |
| 3770 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3771 | case Primitive::kPrimLong: |
| 3772 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3773 | case Primitive::kPrimBoolean: |
| 3774 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3775 | case Primitive::kPrimShort: |
| 3776 | case Primitive::kPrimInt: |
| 3777 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3778 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3779 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3780 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3781 | break; |
| 3782 | |
| 3783 | default: |
| 3784 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3785 | << " to " << result_type; |
| 3786 | } |
| 3787 | break; |
| 3788 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3789 | case Primitive::kPrimShort: |
| 3790 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3791 | case Primitive::kPrimLong: |
| 3792 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3793 | case Primitive::kPrimBoolean: |
| 3794 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3795 | case Primitive::kPrimByte: |
| 3796 | case Primitive::kPrimInt: |
| 3797 | case Primitive::kPrimChar: |
| 3798 | // Processing a Dex `int-to-short' instruction. |
| 3799 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3800 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3801 | break; |
| 3802 | |
| 3803 | default: |
| 3804 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3805 | << " to " << result_type; |
| 3806 | } |
| 3807 | break; |
| 3808 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3809 | case Primitive::kPrimInt: |
| 3810 | switch (input_type) { |
| 3811 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3812 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3813 | locations->SetInAt(0, Location::Any()); |
| 3814 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3815 | break; |
| 3816 | |
| 3817 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3818 | // Processing a Dex `float-to-int' instruction. |
| 3819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3820 | locations->SetOut(Location::RequiresRegister()); |
| 3821 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3822 | break; |
| 3823 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3824 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3825 | // Processing a Dex `double-to-int' instruction. |
| 3826 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3827 | locations->SetOut(Location::RequiresRegister()); |
| 3828 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3829 | break; |
| 3830 | |
| 3831 | default: |
| 3832 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3833 | << " to " << result_type; |
| 3834 | } |
| 3835 | break; |
| 3836 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3837 | case Primitive::kPrimLong: |
| 3838 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3839 | case Primitive::kPrimBoolean: |
| 3840 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3841 | case Primitive::kPrimByte: |
| 3842 | case Primitive::kPrimShort: |
| 3843 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3844 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3845 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3847 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3848 | break; |
| 3849 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3850 | case Primitive::kPrimFloat: { |
| 3851 | // Processing a Dex `float-to-long' instruction. |
| 3852 | InvokeRuntimeCallingConvention calling_convention; |
| 3853 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3854 | calling_convention.GetFpuRegisterAt(0))); |
| 3855 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3856 | break; |
| 3857 | } |
| 3858 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3859 | case Primitive::kPrimDouble: { |
| 3860 | // Processing a Dex `double-to-long' instruction. |
| 3861 | InvokeRuntimeCallingConvention calling_convention; |
| 3862 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3863 | calling_convention.GetFpuRegisterAt(0), |
| 3864 | calling_convention.GetFpuRegisterAt(1))); |
| 3865 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3866 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3867 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3868 | |
| 3869 | default: |
| 3870 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3871 | << " to " << result_type; |
| 3872 | } |
| 3873 | break; |
| 3874 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3875 | case Primitive::kPrimChar: |
| 3876 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3877 | case Primitive::kPrimLong: |
| 3878 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3879 | case Primitive::kPrimBoolean: |
| 3880 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3881 | case Primitive::kPrimByte: |
| 3882 | case Primitive::kPrimShort: |
| 3883 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3884 | // Processing a Dex `int-to-char' instruction. |
| 3885 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3886 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3887 | break; |
| 3888 | |
| 3889 | default: |
| 3890 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3891 | << " to " << result_type; |
| 3892 | } |
| 3893 | break; |
| 3894 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3895 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3896 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3897 | case Primitive::kPrimBoolean: |
| 3898 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3899 | case Primitive::kPrimByte: |
| 3900 | case Primitive::kPrimShort: |
| 3901 | case Primitive::kPrimInt: |
| 3902 | case Primitive::kPrimChar: |
| 3903 | // Processing a Dex `int-to-float' instruction. |
| 3904 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3905 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3906 | break; |
| 3907 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3908 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3909 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3910 | InvokeRuntimeCallingConvention calling_convention; |
| 3911 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3912 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3913 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3914 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3915 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3916 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3917 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3918 | // Processing a Dex `double-to-float' instruction. |
| 3919 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3920 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3921 | break; |
| 3922 | |
| 3923 | default: |
| 3924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3925 | << " to " << result_type; |
| 3926 | }; |
| 3927 | break; |
| 3928 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3929 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3930 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3931 | case Primitive::kPrimBoolean: |
| 3932 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3933 | case Primitive::kPrimByte: |
| 3934 | case Primitive::kPrimShort: |
| 3935 | case Primitive::kPrimInt: |
| 3936 | case Primitive::kPrimChar: |
| 3937 | // Processing a Dex `int-to-double' instruction. |
| 3938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3939 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3940 | break; |
| 3941 | |
| 3942 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3943 | // Processing a Dex `long-to-double' instruction. |
| 3944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3945 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3946 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3947 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3948 | break; |
| 3949 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3950 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3951 | // Processing a Dex `float-to-double' instruction. |
| 3952 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3953 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3954 | break; |
| 3955 | |
| 3956 | default: |
| 3957 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3958 | << " to " << result_type; |
| 3959 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3960 | break; |
| 3961 | |
| 3962 | default: |
| 3963 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3964 | << " to " << result_type; |
| 3965 | } |
| 3966 | } |
| 3967 | |
| 3968 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3969 | LocationSummary* locations = conversion->GetLocations(); |
| 3970 | Location out = locations->Out(); |
| 3971 | Location in = locations->InAt(0); |
| 3972 | Primitive::Type result_type = conversion->GetResultType(); |
| 3973 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3974 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3975 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3976 | case Primitive::kPrimByte: |
| 3977 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3978 | case Primitive::kPrimLong: |
| 3979 | // Type conversion from long to byte is a result of code transformations. |
| 3980 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3981 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3982 | case Primitive::kPrimBoolean: |
| 3983 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3984 | case Primitive::kPrimShort: |
| 3985 | case Primitive::kPrimInt: |
| 3986 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3987 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3988 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3989 | break; |
| 3990 | |
| 3991 | default: |
| 3992 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3993 | << " to " << result_type; |
| 3994 | } |
| 3995 | break; |
| 3996 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3997 | case Primitive::kPrimShort: |
| 3998 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3999 | case Primitive::kPrimLong: |
| 4000 | // Type conversion from long to short is a result of code transformations. |
| 4001 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 4002 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4003 | case Primitive::kPrimBoolean: |
| 4004 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 4005 | case Primitive::kPrimByte: |
| 4006 | case Primitive::kPrimInt: |
| 4007 | case Primitive::kPrimChar: |
| 4008 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4009 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 4010 | break; |
| 4011 | |
| 4012 | default: |
| 4013 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4014 | << " to " << result_type; |
| 4015 | } |
| 4016 | break; |
| 4017 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4018 | case Primitive::kPrimInt: |
| 4019 | switch (input_type) { |
| 4020 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4021 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4022 | DCHECK(out.IsRegister()); |
| 4023 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4024 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4025 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4026 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4027 | } else { |
| 4028 | DCHECK(in.IsConstant()); |
| 4029 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 4030 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4031 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4032 | } |
| 4033 | break; |
| 4034 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 4035 | case Primitive::kPrimFloat: { |
| 4036 | // Processing a Dex `float-to-int' instruction. |
| 4037 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 4038 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 4039 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 4040 | break; |
| 4041 | } |
| 4042 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4043 | case Primitive::kPrimDouble: { |
| 4044 | // Processing a Dex `double-to-int' instruction. |
| 4045 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 4046 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4047 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4048 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4049 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4050 | |
| 4051 | default: |
| 4052 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4053 | << " to " << result_type; |
| 4054 | } |
| 4055 | break; |
| 4056 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4057 | case Primitive::kPrimLong: |
| 4058 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4059 | case Primitive::kPrimBoolean: |
| 4060 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4061 | case Primitive::kPrimByte: |
| 4062 | case Primitive::kPrimShort: |
| 4063 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 4064 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4065 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4066 | DCHECK(out.IsRegisterPair()); |
| 4067 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4068 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4069 | // Sign extension. |
| 4070 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 4071 | out.AsRegisterPairLow<Register>(), |
| 4072 | 31); |
| 4073 | break; |
| 4074 | |
| 4075 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4076 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4077 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4078 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4079 | break; |
| 4080 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4081 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4082 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4083 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4084 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4085 | break; |
| 4086 | |
| 4087 | default: |
| 4088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4089 | << " to " << result_type; |
| 4090 | } |
| 4091 | break; |
| 4092 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4093 | case Primitive::kPrimChar: |
| 4094 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 4095 | case Primitive::kPrimLong: |
| 4096 | // Type conversion from long to char is a result of code transformations. |
| 4097 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 4098 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4099 | case Primitive::kPrimBoolean: |
| 4100 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4101 | case Primitive::kPrimByte: |
| 4102 | case Primitive::kPrimShort: |
| 4103 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4104 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4105 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4106 | break; |
| 4107 | |
| 4108 | default: |
| 4109 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4110 | << " to " << result_type; |
| 4111 | } |
| 4112 | break; |
| 4113 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4114 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4115 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4116 | case Primitive::kPrimBoolean: |
| 4117 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4118 | case Primitive::kPrimByte: |
| 4119 | case Primitive::kPrimShort: |
| 4120 | case Primitive::kPrimInt: |
| 4121 | case Primitive::kPrimChar: { |
| 4122 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4123 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 4124 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4125 | break; |
| 4126 | } |
| 4127 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 4128 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4129 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4130 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4131 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4132 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4133 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4134 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 4135 | // Processing a Dex `double-to-float' instruction. |
| 4136 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 4137 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4138 | break; |
| 4139 | |
| 4140 | default: |
| 4141 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4142 | << " to " << result_type; |
| 4143 | }; |
| 4144 | break; |
| 4145 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4146 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4147 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4148 | case Primitive::kPrimBoolean: |
| 4149 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4150 | case Primitive::kPrimByte: |
| 4151 | case Primitive::kPrimShort: |
| 4152 | case Primitive::kPrimInt: |
| 4153 | case Primitive::kPrimChar: { |
| 4154 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4155 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4156 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4157 | out.AsFpuRegisterPairLow<SRegister>()); |
| 4158 | break; |
| 4159 | } |
| 4160 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4161 | case Primitive::kPrimLong: { |
| 4162 | // Processing a Dex `long-to-double' instruction. |
| 4163 | Register low = in.AsRegisterPairLow<Register>(); |
| 4164 | Register high = in.AsRegisterPairHigh<Register>(); |
| 4165 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 4166 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4167 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4168 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4169 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 4170 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4171 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4172 | // temp_d = int-to-double(high) |
| 4173 | __ vmovsr(temp_s, high); |
| 4174 | __ vcvtdi(temp_d, temp_s); |
| 4175 | // constant_d = k2Pow32EncodingForDouble |
| 4176 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 4177 | // out_d = unsigned-to-double(low) |
| 4178 | __ vmovsr(out_s, low); |
| 4179 | __ vcvtdu(out_d, out_s); |
| 4180 | // out_d += temp_d * constant_d |
| 4181 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4182 | break; |
| 4183 | } |
| 4184 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4185 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 4186 | // Processing a Dex `float-to-double' instruction. |
| 4187 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4188 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4189 | break; |
| 4190 | |
| 4191 | default: |
| 4192 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4193 | << " to " << result_type; |
| 4194 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4195 | break; |
| 4196 | |
| 4197 | default: |
| 4198 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4199 | << " to " << result_type; |
| 4200 | } |
| 4201 | } |
| 4202 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4203 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4204 | LocationSummary* locations = |
| 4205 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4206 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4207 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4209 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4210 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4211 | break; |
| 4212 | } |
| 4213 | |
| 4214 | case Primitive::kPrimLong: { |
| 4215 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4216 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4217 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4218 | break; |
| 4219 | } |
| 4220 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4221 | case Primitive::kPrimFloat: |
| 4222 | case Primitive::kPrimDouble: { |
| 4223 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4224 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4225 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4226 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4227 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4228 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4229 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4230 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4231 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 4235 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4236 | Location out = locations->Out(); |
| 4237 | Location first = locations->InAt(0); |
| 4238 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4239 | switch (add->GetResultType()) { |
| 4240 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4241 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4242 | __ add(out.AsRegister<Register>(), |
| 4243 | first.AsRegister<Register>(), |
| 4244 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4245 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4246 | __ AddConstant(out.AsRegister<Register>(), |
| 4247 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4248 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4249 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4250 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4251 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4252 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4253 | if (second.IsConstant()) { |
| 4254 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4255 | GenerateAddLongConst(out, first, value); |
| 4256 | } else { |
| 4257 | DCHECK(second.IsRegisterPair()); |
| 4258 | __ adds(out.AsRegisterPairLow<Register>(), |
| 4259 | first.AsRegisterPairLow<Register>(), |
| 4260 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4261 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 4262 | first.AsRegisterPairHigh<Register>(), |
| 4263 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4264 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4265 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4266 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4267 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4268 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4269 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 4270 | first.AsFpuRegister<SRegister>(), |
| 4271 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | |
| 4274 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4275 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4276 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4277 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4278 | break; |
| 4279 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4280 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4281 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4282 | } |
| 4283 | } |
| 4284 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4285 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4286 | LocationSummary* locations = |
| 4287 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4288 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4289 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4290 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4291 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4292 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimLong: { |
| 4297 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4298 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4300 | break; |
| 4301 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4302 | case Primitive::kPrimFloat: |
| 4303 | case Primitive::kPrimDouble: { |
| 4304 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4305 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4306 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4307 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4308 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4309 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4310 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4311 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 4315 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4316 | Location out = locations->Out(); |
| 4317 | Location first = locations->InAt(0); |
| 4318 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4319 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4320 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4321 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4322 | __ sub(out.AsRegister<Register>(), |
| 4323 | first.AsRegister<Register>(), |
| 4324 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4325 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4326 | __ AddConstant(out.AsRegister<Register>(), |
| 4327 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4328 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4329 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4330 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4331 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4332 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4333 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4334 | if (second.IsConstant()) { |
| 4335 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4336 | GenerateAddLongConst(out, first, -value); |
| 4337 | } else { |
| 4338 | DCHECK(second.IsRegisterPair()); |
| 4339 | __ subs(out.AsRegisterPairLow<Register>(), |
| 4340 | first.AsRegisterPairLow<Register>(), |
| 4341 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4342 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 4343 | first.AsRegisterPairHigh<Register>(), |
| 4344 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4345 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4346 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4347 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4348 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4349 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4350 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 4351 | first.AsFpuRegister<SRegister>(), |
| 4352 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4353 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4357 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4358 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4359 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4360 | break; |
| 4361 | } |
| 4362 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4363 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4364 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4365 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4369 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 4370 | LocationSummary* locations = |
| 4371 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4372 | switch (mul->GetResultType()) { |
| 4373 | case Primitive::kPrimInt: |
| 4374 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4375 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4376 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4378 | break; |
| 4379 | } |
| 4380 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4381 | case Primitive::kPrimFloat: |
| 4382 | case Primitive::kPrimDouble: { |
| 4383 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4384 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4385 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4386 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4387 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4388 | |
| 4389 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4390 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 4395 | LocationSummary* locations = mul->GetLocations(); |
| 4396 | Location out = locations->Out(); |
| 4397 | Location first = locations->InAt(0); |
| 4398 | Location second = locations->InAt(1); |
| 4399 | switch (mul->GetResultType()) { |
| 4400 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4401 | __ mul(out.AsRegister<Register>(), |
| 4402 | first.AsRegister<Register>(), |
| 4403 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4404 | break; |
| 4405 | } |
| 4406 | case Primitive::kPrimLong: { |
| 4407 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 4408 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 4409 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 4410 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 4411 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 4412 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 4413 | |
| 4414 | // Extra checks to protect caused by the existence of R1_R2. |
| 4415 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4416 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 4417 | DCHECK_NE(out_hi, in1_lo); |
| 4418 | DCHECK_NE(out_hi, in2_lo); |
| 4419 | |
| 4420 | // input: in1 - 64 bits, in2 - 64 bits |
| 4421 | // output: out |
| 4422 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4423 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4424 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4425 | |
| 4426 | // IP <- in1.lo * in2.hi |
| 4427 | __ mul(IP, in1_lo, in2_hi); |
| 4428 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4429 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 4430 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4431 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 4432 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 4433 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 4434 | break; |
| 4435 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4436 | |
| 4437 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4438 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 4439 | first.AsFpuRegister<SRegister>(), |
| 4440 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4441 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4445 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4446 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4447 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4448 | break; |
| 4449 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4450 | |
| 4451 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4452 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4456 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4457 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4458 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4459 | |
| 4460 | LocationSummary* locations = instruction->GetLocations(); |
| 4461 | Location second = locations->InAt(1); |
| 4462 | DCHECK(second.IsConstant()); |
| 4463 | |
| 4464 | Register out = locations->Out().AsRegister<Register>(); |
| 4465 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4466 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4467 | DCHECK(imm == 1 || imm == -1); |
| 4468 | |
| 4469 | if (instruction->IsRem()) { |
| 4470 | __ LoadImmediate(out, 0); |
| 4471 | } else { |
| 4472 | if (imm == 1) { |
| 4473 | __ Mov(out, dividend); |
| 4474 | } else { |
| 4475 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4481 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4482 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4483 | |
| 4484 | LocationSummary* locations = instruction->GetLocations(); |
| 4485 | Location second = locations->InAt(1); |
| 4486 | DCHECK(second.IsConstant()); |
| 4487 | |
| 4488 | Register out = locations->Out().AsRegister<Register>(); |
| 4489 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4490 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4491 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4492 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4493 | int ctz_imm = CTZ(abs_imm); |
| 4494 | |
| 4495 | if (ctz_imm == 1) { |
| 4496 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4497 | } else { |
| 4498 | __ Asr(temp, dividend, 31); |
| 4499 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4500 | } |
| 4501 | __ add(out, temp, ShifterOperand(dividend)); |
| 4502 | |
| 4503 | if (instruction->IsDiv()) { |
| 4504 | __ Asr(out, out, ctz_imm); |
| 4505 | if (imm < 0) { |
| 4506 | __ rsb(out, out, ShifterOperand(0)); |
| 4507 | } |
| 4508 | } else { |
| 4509 | __ ubfx(out, out, 0, ctz_imm); |
| 4510 | __ sub(out, out, ShifterOperand(temp)); |
| 4511 | } |
| 4512 | } |
| 4513 | |
| 4514 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4515 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4516 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4517 | |
| 4518 | LocationSummary* locations = instruction->GetLocations(); |
| 4519 | Location second = locations->InAt(1); |
| 4520 | DCHECK(second.IsConstant()); |
| 4521 | |
| 4522 | Register out = locations->Out().AsRegister<Register>(); |
| 4523 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4524 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4525 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4526 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4527 | |
| 4528 | int64_t magic; |
| 4529 | int shift; |
| 4530 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4531 | |
| 4532 | __ LoadImmediate(temp1, magic); |
| 4533 | __ smull(temp2, temp1, dividend, temp1); |
| 4534 | |
| 4535 | if (imm > 0 && magic < 0) { |
| 4536 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4537 | } else if (imm < 0 && magic > 0) { |
| 4538 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4539 | } |
| 4540 | |
| 4541 | if (shift != 0) { |
| 4542 | __ Asr(temp1, temp1, shift); |
| 4543 | } |
| 4544 | |
| 4545 | if (instruction->IsDiv()) { |
| 4546 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4547 | } else { |
| 4548 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4549 | // TODO: Strength reduction for mls. |
| 4550 | __ LoadImmediate(temp2, imm); |
| 4551 | __ mls(out, temp1, temp2, dividend); |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4556 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4557 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4558 | |
| 4559 | LocationSummary* locations = instruction->GetLocations(); |
| 4560 | Location second = locations->InAt(1); |
| 4561 | DCHECK(second.IsConstant()); |
| 4562 | |
| 4563 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4564 | if (imm == 0) { |
| 4565 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4566 | } else if (imm == 1 || imm == -1) { |
| 4567 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4568 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4569 | DivRemByPowerOfTwo(instruction); |
| 4570 | } else { |
| 4571 | DCHECK(imm <= -2 || imm >= 2); |
| 4572 | GenerateDivRemWithAnyConstant(instruction); |
| 4573 | } |
| 4574 | } |
| 4575 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4576 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4577 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4578 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4579 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4580 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4581 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4582 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4583 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4584 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4585 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4586 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4587 | } |
| 4588 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4589 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4590 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4591 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4592 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4593 | if (div->InputAt(1)->IsConstant()) { |
| 4594 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4595 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4596 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4597 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4598 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4599 | // No temp register required. |
| 4600 | } else { |
| 4601 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4602 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4603 | locations->AddTemp(Location::RequiresRegister()); |
| 4604 | } |
| 4605 | } |
| 4606 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4607 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4608 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4609 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4610 | } else { |
| 4611 | InvokeRuntimeCallingConvention calling_convention; |
| 4612 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4613 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4614 | // 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] | 4615 | // we only need the former. |
| 4616 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4617 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4618 | break; |
| 4619 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4620 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4621 | InvokeRuntimeCallingConvention calling_convention; |
| 4622 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4623 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4624 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4625 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4626 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4627 | break; |
| 4628 | } |
| 4629 | case Primitive::kPrimFloat: |
| 4630 | case Primitive::kPrimDouble: { |
| 4631 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4632 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4633 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4634 | break; |
| 4635 | } |
| 4636 | |
| 4637 | default: |
| 4638 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4643 | LocationSummary* locations = div->GetLocations(); |
| 4644 | Location out = locations->Out(); |
| 4645 | Location first = locations->InAt(0); |
| 4646 | Location second = locations->InAt(1); |
| 4647 | |
| 4648 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4649 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4650 | if (second.IsConstant()) { |
| 4651 | GenerateDivRemConstantIntegral(div); |
| 4652 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4653 | __ sdiv(out.AsRegister<Register>(), |
| 4654 | first.AsRegister<Register>(), |
| 4655 | second.AsRegister<Register>()); |
| 4656 | } else { |
| 4657 | InvokeRuntimeCallingConvention calling_convention; |
| 4658 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4659 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4660 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4661 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4662 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4663 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4664 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4665 | break; |
| 4666 | } |
| 4667 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4668 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4669 | InvokeRuntimeCallingConvention calling_convention; |
| 4670 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4671 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4672 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4673 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4674 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4675 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4676 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4677 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4678 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4679 | break; |
| 4680 | } |
| 4681 | |
| 4682 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4683 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4684 | first.AsFpuRegister<SRegister>(), |
| 4685 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4686 | break; |
| 4687 | } |
| 4688 | |
| 4689 | case Primitive::kPrimDouble: { |
| 4690 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4691 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4692 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4693 | break; |
| 4694 | } |
| 4695 | |
| 4696 | default: |
| 4697 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4698 | } |
| 4699 | } |
| 4700 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4701 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4702 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4703 | |
| 4704 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4705 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4706 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4707 | // sdiv will be replaced by other instruction sequence. |
| 4708 | call_kind = LocationSummary::kNoCall; |
| 4709 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4710 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4711 | // Have hardware divide instruction for int, do it with three instructions. |
| 4712 | call_kind = LocationSummary::kNoCall; |
| 4713 | } |
| 4714 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4715 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4716 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4717 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4718 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4719 | if (rem->InputAt(1)->IsConstant()) { |
| 4720 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4721 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4722 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4723 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4724 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4725 | // No temp register required. |
| 4726 | } else { |
| 4727 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4728 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4729 | locations->AddTemp(Location::RequiresRegister()); |
| 4730 | } |
| 4731 | } |
| 4732 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4734 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4735 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4736 | locations->AddTemp(Location::RequiresRegister()); |
| 4737 | } else { |
| 4738 | InvokeRuntimeCallingConvention calling_convention; |
| 4739 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4740 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4741 | // 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] | 4742 | // we only need the latter. |
| 4743 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4744 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| 4747 | case Primitive::kPrimLong: { |
| 4748 | InvokeRuntimeCallingConvention calling_convention; |
| 4749 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4750 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4751 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4752 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4753 | // The runtime helper puts the output in R2,R3. |
| 4754 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4755 | break; |
| 4756 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4757 | case Primitive::kPrimFloat: { |
| 4758 | InvokeRuntimeCallingConvention calling_convention; |
| 4759 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4760 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4761 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4762 | break; |
| 4763 | } |
| 4764 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4765 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4766 | InvokeRuntimeCallingConvention calling_convention; |
| 4767 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4768 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4769 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4770 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4771 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4772 | break; |
| 4773 | } |
| 4774 | |
| 4775 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4776 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4781 | LocationSummary* locations = rem->GetLocations(); |
| 4782 | Location out = locations->Out(); |
| 4783 | Location first = locations->InAt(0); |
| 4784 | Location second = locations->InAt(1); |
| 4785 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4786 | Primitive::Type type = rem->GetResultType(); |
| 4787 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4788 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4789 | if (second.IsConstant()) { |
| 4790 | GenerateDivRemConstantIntegral(rem); |
| 4791 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4792 | Register reg1 = first.AsRegister<Register>(); |
| 4793 | Register reg2 = second.AsRegister<Register>(); |
| 4794 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4795 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4796 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4797 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4798 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4799 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4800 | } else { |
| 4801 | InvokeRuntimeCallingConvention calling_convention; |
| 4802 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4803 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4804 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4805 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4806 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4807 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4808 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | |
| 4812 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4813 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4814 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4815 | break; |
| 4816 | } |
| 4817 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4818 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4819 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4820 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4821 | break; |
| 4822 | } |
| 4823 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4824 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4825 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4826 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | } |
| 4829 | |
| 4830 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4831 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4835 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4836 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4837 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4841 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4842 | codegen_->AddSlowPath(slow_path); |
| 4843 | |
| 4844 | LocationSummary* locations = instruction->GetLocations(); |
| 4845 | Location value = locations->InAt(0); |
| 4846 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4847 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4848 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4849 | case Primitive::kPrimByte: |
| 4850 | case Primitive::kPrimChar: |
| 4851 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4852 | case Primitive::kPrimInt: { |
| 4853 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4854 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4855 | } else { |
| 4856 | DCHECK(value.IsConstant()) << value; |
| 4857 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4858 | __ b(slow_path->GetEntryLabel()); |
| 4859 | } |
| 4860 | } |
| 4861 | break; |
| 4862 | } |
| 4863 | case Primitive::kPrimLong: { |
| 4864 | if (value.IsRegisterPair()) { |
| 4865 | __ orrs(IP, |
| 4866 | value.AsRegisterPairLow<Register>(), |
| 4867 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4868 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4869 | } else { |
| 4870 | DCHECK(value.IsConstant()) << value; |
| 4871 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4872 | __ b(slow_path->GetEntryLabel()); |
| 4873 | } |
| 4874 | } |
| 4875 | break; |
| 4876 | default: |
| 4877 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4878 | } |
| 4879 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4880 | } |
| 4881 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4882 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4883 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4884 | Location rhs = locations->InAt(1); |
| 4885 | Register out = locations->Out().AsRegister<Register>(); |
| 4886 | |
| 4887 | if (rhs.IsConstant()) { |
| 4888 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4889 | // so map all rotations to a +ve. equivalent in that range. |
| 4890 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4891 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4892 | if (rot) { |
| 4893 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4894 | // (e.g. left by 2 bits == right by 30.) |
| 4895 | __ Ror(out, in, rot); |
| 4896 | } else if (out != in) { |
| 4897 | __ Mov(out, in); |
| 4898 | } |
| 4899 | } else { |
| 4900 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4905 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4906 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4907 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4908 | void InstructionCodeGeneratorARM::HandleLongRotate(HRor* ror) { |
| 4909 | LocationSummary* locations = ror->GetLocations(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4910 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4911 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4912 | Location rhs = locations->InAt(1); |
| 4913 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4914 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4915 | |
| 4916 | if (rhs.IsConstant()) { |
| 4917 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4918 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4919 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4920 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4921 | // logic below to a simple pair of binary orr. |
| 4922 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4923 | if (rot >= kArmBitsPerWord) { |
| 4924 | rot -= kArmBitsPerWord; |
| 4925 | std::swap(in_reg_hi, in_reg_lo); |
| 4926 | } |
| 4927 | // Rotate, or mov to out for zero or word size rotations. |
| 4928 | if (rot != 0u) { |
| 4929 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4930 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4931 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4932 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4933 | } else { |
| 4934 | __ Mov(out_reg_lo, in_reg_lo); |
| 4935 | __ Mov(out_reg_hi, in_reg_hi); |
| 4936 | } |
| 4937 | } else { |
| 4938 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4939 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4940 | Label end; |
| 4941 | Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4942 | Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4943 | |
| 4944 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4945 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4946 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4947 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4948 | |
| 4949 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4950 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4951 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4952 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4953 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4954 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4955 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4956 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4957 | __ b(final_label); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4958 | |
| 4959 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4960 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4961 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4962 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4963 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4964 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4965 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4966 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4967 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4968 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4969 | if (end.IsLinked()) { |
| 4970 | __ Bind(&end); |
| 4971 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4972 | } |
| 4973 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4974 | |
| 4975 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4976 | LocationSummary* locations = |
| 4977 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4978 | switch (ror->GetResultType()) { |
| 4979 | case Primitive::kPrimInt: { |
| 4980 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4981 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4982 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4983 | break; |
| 4984 | } |
| 4985 | case Primitive::kPrimLong: { |
| 4986 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4987 | if (ror->InputAt(1)->IsConstant()) { |
| 4988 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4989 | } else { |
| 4990 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4991 | locations->AddTemp(Location::RequiresRegister()); |
| 4992 | locations->AddTemp(Location::RequiresRegister()); |
| 4993 | } |
| 4994 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4995 | break; |
| 4996 | } |
| 4997 | default: |
| 4998 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4999 | } |
| 5000 | } |
| 5001 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5002 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5003 | LocationSummary* locations = ror->GetLocations(); |
| 5004 | Primitive::Type type = ror->GetResultType(); |
| 5005 | switch (type) { |
| 5006 | case Primitive::kPrimInt: { |
| 5007 | HandleIntegerRotate(locations); |
| 5008 | break; |
| 5009 | } |
| 5010 | case Primitive::kPrimLong: { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5011 | HandleLongRotate(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5012 | break; |
| 5013 | } |
| 5014 | default: |
| 5015 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5016 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5017 | } |
| 5018 | } |
| 5019 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5020 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 5021 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5022 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5023 | LocationSummary* locations = |
| 5024 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5025 | |
| 5026 | switch (op->GetResultType()) { |
| 5027 | case Primitive::kPrimInt: { |
| 5028 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5029 | if (op->InputAt(1)->IsConstant()) { |
| 5030 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5031 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5032 | } else { |
| 5033 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5034 | // Make the output overlap, as it will be used to hold the masked |
| 5035 | // second input. |
| 5036 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5037 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5041 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5042 | if (op->InputAt(1)->IsConstant()) { |
| 5043 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5044 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5045 | // don't clash with high registers which the register allocator currently guarantees. |
| 5046 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5047 | } else { |
| 5048 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5049 | locations->AddTemp(Location::RequiresRegister()); |
| 5050 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5051 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5052 | break; |
| 5053 | } |
| 5054 | default: |
| 5055 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 5060 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5061 | |
| 5062 | LocationSummary* locations = op->GetLocations(); |
| 5063 | Location out = locations->Out(); |
| 5064 | Location first = locations->InAt(0); |
| 5065 | Location second = locations->InAt(1); |
| 5066 | |
| 5067 | Primitive::Type type = op->GetResultType(); |
| 5068 | switch (type) { |
| 5069 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5070 | Register out_reg = out.AsRegister<Register>(); |
| 5071 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5072 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5073 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5074 | // 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] | 5075 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5076 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5077 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5078 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5079 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5080 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5081 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5082 | } |
| 5083 | } else { |
| 5084 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5085 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5086 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5087 | __ Mov(out_reg, first_reg); |
| 5088 | } else if (op->IsShl()) { |
| 5089 | __ Lsl(out_reg, first_reg, shift_value); |
| 5090 | } else if (op->IsShr()) { |
| 5091 | __ Asr(out_reg, first_reg, shift_value); |
| 5092 | } else { |
| 5093 | __ Lsr(out_reg, first_reg, shift_value); |
| 5094 | } |
| 5095 | } |
| 5096 | break; |
| 5097 | } |
| 5098 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5099 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 5100 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5101 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5102 | Register high = first.AsRegisterPairHigh<Register>(); |
| 5103 | Register low = first.AsRegisterPairLow<Register>(); |
| 5104 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5105 | if (second.IsRegister()) { |
| 5106 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5107 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5108 | Register second_reg = second.AsRegister<Register>(); |
| 5109 | |
| 5110 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5111 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5112 | // Shift the high part |
| 5113 | __ Lsl(o_h, high, o_l); |
| 5114 | // Shift the low part and `or` what overflew on the high part |
| 5115 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 5116 | __ Lsr(temp, low, temp); |
| 5117 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 5118 | // If the shift is > 32 bits, override the high part |
| 5119 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 5120 | __ it(PL); |
| 5121 | __ Lsl(o_h, low, temp, PL); |
| 5122 | // Shift the low part |
| 5123 | __ Lsl(o_l, low, o_l); |
| 5124 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5125 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5126 | // Shift the low part |
| 5127 | __ Lsr(o_l, low, o_h); |
| 5128 | // Shift the high part and `or` what underflew on the low part |
| 5129 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5130 | __ Lsl(temp, high, temp); |
| 5131 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 5132 | // If the shift is > 32 bits, override the low part |
| 5133 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5134 | __ it(PL); |
| 5135 | __ Asr(o_l, high, temp, PL); |
| 5136 | // Shift the high part |
| 5137 | __ Asr(o_h, high, o_h); |
| 5138 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5139 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5140 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5141 | __ Lsr(o_l, low, o_h); |
| 5142 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5143 | __ Lsl(temp, high, temp); |
| 5144 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 5145 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5146 | __ it(PL); |
| 5147 | __ Lsr(o_l, high, temp, PL); |
| 5148 | __ Lsr(o_h, high, o_h); |
| 5149 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5150 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5151 | // Register allocator doesn't create partial overlap. |
| 5152 | DCHECK_NE(o_l, high); |
| 5153 | DCHECK_NE(o_h, low); |
| 5154 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5155 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5156 | if (shift_value > 32) { |
| 5157 | if (op->IsShl()) { |
| 5158 | __ Lsl(o_h, low, shift_value - 32); |
| 5159 | __ LoadImmediate(o_l, 0); |
| 5160 | } else if (op->IsShr()) { |
| 5161 | __ Asr(o_l, high, shift_value - 32); |
| 5162 | __ Asr(o_h, high, 31); |
| 5163 | } else { |
| 5164 | __ Lsr(o_l, high, shift_value - 32); |
| 5165 | __ LoadImmediate(o_h, 0); |
| 5166 | } |
| 5167 | } else if (shift_value == 32) { |
| 5168 | if (op->IsShl()) { |
| 5169 | __ mov(o_h, ShifterOperand(low)); |
| 5170 | __ LoadImmediate(o_l, 0); |
| 5171 | } else if (op->IsShr()) { |
| 5172 | __ mov(o_l, ShifterOperand(high)); |
| 5173 | __ Asr(o_h, high, 31); |
| 5174 | } else { |
| 5175 | __ mov(o_l, ShifterOperand(high)); |
| 5176 | __ LoadImmediate(o_h, 0); |
| 5177 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 5178 | } else if (shift_value == 1) { |
| 5179 | if (op->IsShl()) { |
| 5180 | __ Lsls(o_l, low, 1); |
| 5181 | __ adc(o_h, high, ShifterOperand(high)); |
| 5182 | } else if (op->IsShr()) { |
| 5183 | __ Asrs(o_h, high, 1); |
| 5184 | __ Rrx(o_l, low); |
| 5185 | } else { |
| 5186 | __ Lsrs(o_h, high, 1); |
| 5187 | __ Rrx(o_l, low); |
| 5188 | } |
| 5189 | } else { |
| 5190 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5191 | if (op->IsShl()) { |
| 5192 | __ Lsl(o_h, high, shift_value); |
| 5193 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 5194 | __ Lsl(o_l, low, shift_value); |
| 5195 | } else if (op->IsShr()) { |
| 5196 | __ Lsr(o_l, low, shift_value); |
| 5197 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 5198 | __ Asr(o_h, high, shift_value); |
| 5199 | } else { |
| 5200 | __ Lsr(o_l, low, shift_value); |
| 5201 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 5202 | __ Lsr(o_h, high, shift_value); |
| 5203 | } |
| 5204 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5205 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5206 | break; |
| 5207 | } |
| 5208 | default: |
| 5209 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5210 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 5215 | HandleShift(shl); |
| 5216 | } |
| 5217 | |
| 5218 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 5219 | HandleShift(shl); |
| 5220 | } |
| 5221 | |
| 5222 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 5223 | HandleShift(shr); |
| 5224 | } |
| 5225 | |
| 5226 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 5227 | HandleShift(shr); |
| 5228 | } |
| 5229 | |
| 5230 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 5231 | HandleShift(ushr); |
| 5232 | } |
| 5233 | |
| 5234 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 5235 | HandleShift(ushr); |
| 5236 | } |
| 5237 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5238 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5239 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5240 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5241 | if (instruction->IsStringAlloc()) { |
| 5242 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5243 | } else { |
| 5244 | InvokeRuntimeCallingConvention calling_convention; |
| 5245 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5246 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5247 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5251 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5252 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5253 | if (instruction->IsStringAlloc()) { |
| 5254 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5255 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5256 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5257 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5258 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 5259 | __ blx(LR); |
| 5260 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5261 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5262 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5263 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5264 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5265 | } |
| 5266 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5267 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 5268 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5269 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5270 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5271 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5272 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5273 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5277 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5278 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5279 | QuickEntrypointEnum entrypoint = |
| 5280 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5281 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5282 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5283 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5284 | } |
| 5285 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5286 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5287 | LocationSummary* locations = |
| 5288 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5289 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5290 | if (location.IsStackSlot()) { |
| 5291 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5292 | } else if (location.IsDoubleStackSlot()) { |
| 5293 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5294 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5295 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5296 | } |
| 5297 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5298 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 5299 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 5300 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5304 | LocationSummary* locations = |
| 5305 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5306 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5307 | } |
| 5308 | |
| 5309 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5310 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5311 | } |
| 5312 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5313 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5314 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5315 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5316 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5317 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5318 | } |
| 5319 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5320 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 5321 | LocationSummary* locations = not_->GetLocations(); |
| 5322 | Location out = locations->Out(); |
| 5323 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5324 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5325 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5326 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5327 | break; |
| 5328 | |
| 5329 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5330 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 5331 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 5332 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 5333 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5334 | break; |
| 5335 | |
| 5336 | default: |
| 5337 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5338 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5339 | } |
| 5340 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5341 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5342 | LocationSummary* locations = |
| 5343 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 5344 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5345 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5346 | } |
| 5347 | |
| 5348 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5349 | LocationSummary* locations = bool_not->GetLocations(); |
| 5350 | Location out = locations->Out(); |
| 5351 | Location in = locations->InAt(0); |
| 5352 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 5353 | } |
| 5354 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5355 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5356 | LocationSummary* locations = |
| 5357 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5358 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5359 | case Primitive::kPrimBoolean: |
| 5360 | case Primitive::kPrimByte: |
| 5361 | case Primitive::kPrimShort: |
| 5362 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5363 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5364 | case Primitive::kPrimLong: { |
| 5365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5366 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5367 | // Output overlaps because it is written before doing the low comparison. |
| 5368 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5369 | break; |
| 5370 | } |
| 5371 | case Primitive::kPrimFloat: |
| 5372 | case Primitive::kPrimDouble: { |
| 5373 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5374 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5375 | locations->SetOut(Location::RequiresRegister()); |
| 5376 | break; |
| 5377 | } |
| 5378 | default: |
| 5379 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5380 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5384 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5385 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5386 | Location left = locations->InAt(0); |
| 5387 | Location right = locations->InAt(1); |
| 5388 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5389 | Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5390 | Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5391 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5392 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5393 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5394 | case Primitive::kPrimBoolean: |
| 5395 | case Primitive::kPrimByte: |
| 5396 | case Primitive::kPrimShort: |
| 5397 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5398 | case Primitive::kPrimInt: { |
| 5399 | __ LoadImmediate(out, 0); |
| 5400 | __ cmp(left.AsRegister<Register>(), |
| 5401 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 5402 | less_cond = LT; |
| 5403 | break; |
| 5404 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5405 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5406 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 5407 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5408 | __ b(&less, LT); |
| 5409 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5410 | // 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] | 5411 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5412 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 5413 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5414 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5415 | break; |
| 5416 | } |
| 5417 | case Primitive::kPrimFloat: |
| 5418 | case Primitive::kPrimDouble: { |
| 5419 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5420 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5421 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5422 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5426 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5427 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5428 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5429 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5430 | __ b(final_label, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5431 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5432 | |
| 5433 | __ Bind(&greater); |
| 5434 | __ LoadImmediate(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5435 | __ b(final_label); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5436 | |
| 5437 | __ Bind(&less); |
| 5438 | __ LoadImmediate(out, -1); |
| 5439 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5440 | if (done.IsLinked()) { |
| 5441 | __ Bind(&done); |
| 5442 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5445 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5446 | LocationSummary* locations = |
| 5447 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5448 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5449 | locations->SetInAt(i, Location::Any()); |
| 5450 | } |
| 5451 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5452 | } |
| 5453 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5454 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5455 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5456 | } |
| 5457 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5458 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5459 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5460 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5461 | switch (kind) { |
| 5462 | case MemBarrierKind::kAnyStore: |
| 5463 | case MemBarrierKind::kLoadAny: |
| 5464 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5465 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5466 | break; |
| 5467 | } |
| 5468 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5469 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5470 | break; |
| 5471 | } |
| 5472 | default: |
| 5473 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5474 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5475 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5479 | uint32_t offset, |
| 5480 | Register out_lo, |
| 5481 | Register out_hi) { |
| 5482 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5483 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5484 | // `offset` into `out_lo` does not clutter `addr`. |
| 5485 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5486 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5487 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5488 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5489 | } |
| 5490 | __ ldrexd(out_lo, out_hi, addr); |
| 5491 | } |
| 5492 | |
| 5493 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5494 | uint32_t offset, |
| 5495 | Register value_lo, |
| 5496 | Register value_hi, |
| 5497 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5498 | Register temp2, |
| 5499 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5500 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5501 | if (offset != 0) { |
| 5502 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5503 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5504 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5505 | } |
| 5506 | __ Bind(&fail); |
| 5507 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5508 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5509 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5511 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5512 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5516 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5517 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5518 | LocationSummary* locations = |
| 5519 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5520 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5521 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5522 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5523 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5524 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5525 | } else { |
| 5526 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5527 | } |
| 5528 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5529 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5530 | bool generate_volatile = field_info.IsVolatile() |
| 5531 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5532 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5533 | bool needs_write_barrier = |
| 5534 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5535 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5536 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5537 | if (needs_write_barrier) { |
| 5538 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5539 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5540 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5541 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5542 | // - registers need to be consecutive |
| 5543 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5544 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5545 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5546 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5547 | |
| 5548 | locations->AddTemp(Location::RequiresRegister()); |
| 5549 | locations->AddTemp(Location::RequiresRegister()); |
| 5550 | if (field_type == Primitive::kPrimDouble) { |
| 5551 | // For doubles we need two more registers to copy the value. |
| 5552 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5553 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5554 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5555 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5558 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5559 | const FieldInfo& field_info, |
| 5560 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5561 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5562 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5563 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5564 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5565 | Location value = locations->InAt(1); |
| 5566 | |
| 5567 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5568 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5569 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5570 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5571 | bool needs_write_barrier = |
| 5572 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5573 | |
| 5574 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5575 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5576 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5577 | |
| 5578 | switch (field_type) { |
| 5579 | case Primitive::kPrimBoolean: |
| 5580 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5581 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5582 | break; |
| 5583 | } |
| 5584 | |
| 5585 | case Primitive::kPrimShort: |
| 5586 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5587 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5588 | break; |
| 5589 | } |
| 5590 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5591 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5592 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5593 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5594 | // Note that in the case where `value` is a null reference, |
| 5595 | // we do not enter this block, as a null reference does not |
| 5596 | // need poisoning. |
| 5597 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5598 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5599 | __ Mov(temp, value.AsRegister<Register>()); |
| 5600 | __ PoisonHeapReference(temp); |
| 5601 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5602 | } else { |
| 5603 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5604 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5605 | break; |
| 5606 | } |
| 5607 | |
| 5608 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5609 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5610 | GenerateWideAtomicStore(base, offset, |
| 5611 | value.AsRegisterPairLow<Register>(), |
| 5612 | value.AsRegisterPairHigh<Register>(), |
| 5613 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5614 | locations->GetTemp(1).AsRegister<Register>(), |
| 5615 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5616 | } else { |
| 5617 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5619 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5620 | break; |
| 5621 | } |
| 5622 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5623 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5624 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5625 | break; |
| 5626 | } |
| 5627 | |
| 5628 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5629 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5630 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5631 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5632 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5633 | |
| 5634 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5635 | |
| 5636 | GenerateWideAtomicStore(base, offset, |
| 5637 | value_reg_lo, |
| 5638 | value_reg_hi, |
| 5639 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5640 | locations->GetTemp(3).AsRegister<Register>(), |
| 5641 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5642 | } else { |
| 5643 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5645 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5646 | break; |
| 5647 | } |
| 5648 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5649 | case Primitive::kPrimVoid: |
| 5650 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5651 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5652 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5653 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5654 | // Longs and doubles are handled in the switch. |
| 5655 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5656 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5657 | } |
| 5658 | |
| 5659 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5660 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5661 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5662 | codegen_->MarkGCCard( |
| 5663 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5666 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5667 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5668 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5671 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5672 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5673 | |
| 5674 | bool object_field_get_with_read_barrier = |
| 5675 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5676 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5677 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5678 | object_field_get_with_read_barrier ? |
| 5679 | LocationSummary::kCallOnSlowPath : |
| 5680 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5681 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5682 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5683 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5684 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5685 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5686 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5687 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5688 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5689 | // The output overlaps in case of volatile long: we don't want the |
| 5690 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5691 | // object's location. Likewise, in the case of an object field get |
| 5692 | // with read barriers enabled, we do not want the load to overwrite |
| 5693 | // the object's location, as we need it to emit the read barrier. |
| 5694 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5695 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5696 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5697 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5698 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5699 | } else { |
| 5700 | locations->SetOut(Location::RequiresRegister(), |
| 5701 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5702 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5703 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5704 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5705 | // - registers need to be consecutive |
| 5706 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5707 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5708 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5709 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5710 | locations->AddTemp(Location::RequiresRegister()); |
| 5711 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5712 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5713 | // We need a temporary register for the read barrier marking slow |
| 5714 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5715 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5716 | !Runtime::Current()->UseJitCompilation()) { |
| 5717 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5718 | // loads we need a temporary only if the offset is too big. |
| 5719 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5720 | locations->AddTemp(Location::RequiresRegister()); |
| 5721 | } |
| 5722 | // And we always need the reserved entrypoint register. |
| 5723 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5724 | } else { |
| 5725 | locations->AddTemp(Location::RequiresRegister()); |
| 5726 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5727 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5728 | } |
| 5729 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5730 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5731 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5732 | << input->GetType(); |
| 5733 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5734 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5735 | return Location::ConstantLocation(input->AsConstant()); |
| 5736 | } else { |
| 5737 | return Location::RequiresFpuRegister(); |
| 5738 | } |
| 5739 | } |
| 5740 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5741 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5742 | Opcode opcode) { |
| 5743 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5744 | if (constant->IsConstant() && |
| 5745 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5746 | return Location::ConstantLocation(constant->AsConstant()); |
| 5747 | } |
| 5748 | return Location::RequiresRegister(); |
| 5749 | } |
| 5750 | |
| 5751 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5752 | Opcode opcode) { |
| 5753 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5754 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5755 | Opcode high_opcode = opcode; |
| 5756 | SetCc low_set_cc = kCcDontCare; |
| 5757 | switch (opcode) { |
| 5758 | case SUB: |
| 5759 | // Flip the operation to an ADD. |
| 5760 | value = -value; |
| 5761 | opcode = ADD; |
| 5762 | FALLTHROUGH_INTENDED; |
| 5763 | case ADD: |
| 5764 | if (Low32Bits(value) == 0u) { |
| 5765 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5766 | } |
| 5767 | high_opcode = ADC; |
| 5768 | low_set_cc = kCcSet; |
| 5769 | break; |
| 5770 | default: |
| 5771 | break; |
| 5772 | } |
| 5773 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5774 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5775 | } else { |
| 5776 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5777 | } |
| 5778 | } |
| 5779 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5780 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5781 | Opcode opcode, |
| 5782 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5783 | ShifterOperand so; |
| 5784 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5785 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5786 | return true; |
| 5787 | } |
| 5788 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5789 | uint32_t neg_value = 0; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5790 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5791 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5792 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5793 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5794 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5795 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5796 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5797 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5798 | default: |
| 5799 | return false; |
| 5800 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5801 | |
| 5802 | if (assembler->ShifterOperandCanHold(kNoRegister, |
| 5803 | kNoRegister, |
| 5804 | neg_opcode, |
| 5805 | neg_value, |
| 5806 | set_cc, |
| 5807 | &so)) { |
| 5808 | return true; |
| 5809 | } |
| 5810 | |
| 5811 | return opcode == AND && IsPowerOfTwo(value + 1); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5812 | } |
| 5813 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5814 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5815 | const FieldInfo& field_info) { |
| 5816 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5817 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5818 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5819 | Location base_loc = locations->InAt(0); |
| 5820 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5821 | Location out = locations->Out(); |
| 5822 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5823 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5824 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5825 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5826 | |
| 5827 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5828 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5829 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5830 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5831 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5832 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5833 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5834 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5835 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5836 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5837 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5838 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5839 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5840 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5841 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5842 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5843 | |
| 5844 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5845 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5846 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5847 | |
| 5848 | case Primitive::kPrimNot: { |
| 5849 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5850 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5851 | Location temp_loc = locations->GetTemp(0); |
| 5852 | // Note that a potential implicit null check is handled in this |
| 5853 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5854 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5855 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5856 | if (is_volatile) { |
| 5857 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5858 | } |
| 5859 | } else { |
| 5860 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5861 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5862 | if (is_volatile) { |
| 5863 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5864 | } |
| 5865 | // If read barriers are enabled, emit read barriers other than |
| 5866 | // Baker's using a slow path (and also unpoison the loaded |
| 5867 | // reference, if heap poisoning is enabled). |
| 5868 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5869 | } |
| 5870 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5871 | } |
| 5872 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5873 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5874 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5875 | GenerateWideAtomicLoad(base, offset, |
| 5876 | out.AsRegisterPairLow<Register>(), |
| 5877 | out.AsRegisterPairHigh<Register>()); |
| 5878 | } else { |
| 5879 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5880 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5881 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5882 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5883 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5884 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5885 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5886 | |
| 5887 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5888 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5889 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5890 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5891 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5892 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5893 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5894 | __ vmovdrr(out_reg, lo, hi); |
| 5895 | } else { |
| 5896 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5897 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5898 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5899 | break; |
| 5900 | } |
| 5901 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5902 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5903 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5904 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5905 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5906 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5907 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5908 | // Potential implicit null checks, in the case of reference or |
| 5909 | // double fields, are handled in the previous switch statement. |
| 5910 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5911 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5912 | } |
| 5913 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5914 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5915 | if (field_type == Primitive::kPrimNot) { |
| 5916 | // Memory barriers, in the case of references, are also handled |
| 5917 | // in the previous switch statement. |
| 5918 | } else { |
| 5919 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5920 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5921 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5925 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5926 | } |
| 5927 | |
| 5928 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5929 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5930 | } |
| 5931 | |
| 5932 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5933 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5934 | } |
| 5935 | |
| 5936 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5937 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5938 | } |
| 5939 | |
| 5940 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5941 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5942 | } |
| 5943 | |
| 5944 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5945 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5946 | } |
| 5947 | |
| 5948 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5949 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5950 | } |
| 5951 | |
| 5952 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5953 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5956 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5957 | HUnresolvedInstanceFieldGet* instruction) { |
| 5958 | FieldAccessCallingConventionARM calling_convention; |
| 5959 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5960 | instruction, instruction->GetFieldType(), calling_convention); |
| 5961 | } |
| 5962 | |
| 5963 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5964 | HUnresolvedInstanceFieldGet* instruction) { |
| 5965 | FieldAccessCallingConventionARM calling_convention; |
| 5966 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5967 | instruction->GetFieldType(), |
| 5968 | instruction->GetFieldIndex(), |
| 5969 | instruction->GetDexPc(), |
| 5970 | calling_convention); |
| 5971 | } |
| 5972 | |
| 5973 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5974 | HUnresolvedInstanceFieldSet* instruction) { |
| 5975 | FieldAccessCallingConventionARM calling_convention; |
| 5976 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5977 | instruction, instruction->GetFieldType(), calling_convention); |
| 5978 | } |
| 5979 | |
| 5980 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5981 | HUnresolvedInstanceFieldSet* instruction) { |
| 5982 | FieldAccessCallingConventionARM calling_convention; |
| 5983 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5984 | instruction->GetFieldType(), |
| 5985 | instruction->GetFieldIndex(), |
| 5986 | instruction->GetDexPc(), |
| 5987 | calling_convention); |
| 5988 | } |
| 5989 | |
| 5990 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5991 | HUnresolvedStaticFieldGet* instruction) { |
| 5992 | FieldAccessCallingConventionARM calling_convention; |
| 5993 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5994 | instruction, instruction->GetFieldType(), calling_convention); |
| 5995 | } |
| 5996 | |
| 5997 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5998 | HUnresolvedStaticFieldGet* instruction) { |
| 5999 | FieldAccessCallingConventionARM calling_convention; |
| 6000 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6001 | instruction->GetFieldType(), |
| 6002 | instruction->GetFieldIndex(), |
| 6003 | instruction->GetDexPc(), |
| 6004 | calling_convention); |
| 6005 | } |
| 6006 | |
| 6007 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 6008 | HUnresolvedStaticFieldSet* instruction) { |
| 6009 | FieldAccessCallingConventionARM calling_convention; |
| 6010 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6011 | instruction, instruction->GetFieldType(), calling_convention); |
| 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 6015 | HUnresolvedStaticFieldSet* instruction) { |
| 6016 | FieldAccessCallingConventionARM calling_convention; |
| 6017 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6018 | instruction->GetFieldType(), |
| 6019 | instruction->GetFieldIndex(), |
| 6020 | instruction->GetDexPc(), |
| 6021 | calling_convention); |
| 6022 | } |
| 6023 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6024 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6025 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6026 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6027 | } |
| 6028 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6029 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6030 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6031 | return; |
| 6032 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6033 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6034 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6035 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6036 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6039 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6040 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6041 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6042 | |
| 6043 | LocationSummary* locations = instruction->GetLocations(); |
| 6044 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6045 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6046 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6047 | } |
| 6048 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6049 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6050 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6053 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 6054 | switch (type) { |
| 6055 | case Primitive::kPrimNot: |
| 6056 | return kLoadWord; |
| 6057 | case Primitive::kPrimBoolean: |
| 6058 | return kLoadUnsignedByte; |
| 6059 | case Primitive::kPrimByte: |
| 6060 | return kLoadSignedByte; |
| 6061 | case Primitive::kPrimChar: |
| 6062 | return kLoadUnsignedHalfword; |
| 6063 | case Primitive::kPrimShort: |
| 6064 | return kLoadSignedHalfword; |
| 6065 | case Primitive::kPrimInt: |
| 6066 | return kLoadWord; |
| 6067 | case Primitive::kPrimLong: |
| 6068 | return kLoadWordPair; |
| 6069 | case Primitive::kPrimFloat: |
| 6070 | return kLoadSWord; |
| 6071 | case Primitive::kPrimDouble: |
| 6072 | return kLoadDWord; |
| 6073 | default: |
| 6074 | LOG(FATAL) << "Unreachable type " << type; |
| 6075 | UNREACHABLE(); |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 6080 | switch (type) { |
| 6081 | case Primitive::kPrimNot: |
| 6082 | return kStoreWord; |
| 6083 | case Primitive::kPrimBoolean: |
| 6084 | case Primitive::kPrimByte: |
| 6085 | return kStoreByte; |
| 6086 | case Primitive::kPrimChar: |
| 6087 | case Primitive::kPrimShort: |
| 6088 | return kStoreHalfword; |
| 6089 | case Primitive::kPrimInt: |
| 6090 | return kStoreWord; |
| 6091 | case Primitive::kPrimLong: |
| 6092 | return kStoreWordPair; |
| 6093 | case Primitive::kPrimFloat: |
| 6094 | return kStoreSWord; |
| 6095 | case Primitive::kPrimDouble: |
| 6096 | return kStoreDWord; |
| 6097 | default: |
| 6098 | LOG(FATAL) << "Unreachable type " << type; |
| 6099 | UNREACHABLE(); |
| 6100 | } |
| 6101 | } |
| 6102 | |
| 6103 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 6104 | Location out_loc, |
| 6105 | Register base, |
| 6106 | Register reg_offset, |
| 6107 | Condition cond) { |
| 6108 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6109 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 6110 | |
| 6111 | switch (type) { |
| 6112 | case Primitive::kPrimByte: |
| 6113 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6114 | break; |
| 6115 | case Primitive::kPrimBoolean: |
| 6116 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6117 | break; |
| 6118 | case Primitive::kPrimShort: |
| 6119 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6120 | break; |
| 6121 | case Primitive::kPrimChar: |
| 6122 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6123 | break; |
| 6124 | case Primitive::kPrimNot: |
| 6125 | case Primitive::kPrimInt: |
| 6126 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6127 | break; |
| 6128 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 6129 | case Primitive::kPrimLong: |
| 6130 | case Primitive::kPrimFloat: |
| 6131 | case Primitive::kPrimDouble: |
| 6132 | default: |
| 6133 | LOG(FATAL) << "Unreachable type " << type; |
| 6134 | UNREACHABLE(); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 6139 | Location loc, |
| 6140 | Register base, |
| 6141 | Register reg_offset, |
| 6142 | Condition cond) { |
| 6143 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6144 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 6145 | |
| 6146 | switch (type) { |
| 6147 | case Primitive::kPrimByte: |
| 6148 | case Primitive::kPrimBoolean: |
| 6149 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 6150 | break; |
| 6151 | case Primitive::kPrimShort: |
| 6152 | case Primitive::kPrimChar: |
| 6153 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 6154 | break; |
| 6155 | case Primitive::kPrimNot: |
| 6156 | case Primitive::kPrimInt: |
| 6157 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 6158 | break; |
| 6159 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 6160 | case Primitive::kPrimLong: |
| 6161 | case Primitive::kPrimFloat: |
| 6162 | case Primitive::kPrimDouble: |
| 6163 | default: |
| 6164 | LOG(FATAL) << "Unreachable type " << type; |
| 6165 | UNREACHABLE(); |
| 6166 | } |
| 6167 | } |
| 6168 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6169 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6170 | bool object_array_get_with_read_barrier = |
| 6171 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6172 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6173 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 6174 | object_array_get_with_read_barrier ? |
| 6175 | LocationSummary::kCallOnSlowPath : |
| 6176 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6177 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6178 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6179 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6180 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6181 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6182 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 6183 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6184 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6185 | // The output overlaps in the case of an object array get with |
| 6186 | // read barriers enabled: we do not want the move to overwrite the |
| 6187 | // array's location, as we need it to emit the read barrier. |
| 6188 | locations->SetOut( |
| 6189 | Location::RequiresRegister(), |
| 6190 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6191 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6192 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6193 | // We need a temporary register for the read barrier marking slow |
| 6194 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 6195 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6196 | !Runtime::Current()->UseJitCompilation() && |
| 6197 | instruction->GetIndex()->IsConstant()) { |
| 6198 | // Array loads with constant index are treated as field loads. |
| 6199 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6200 | // constant index loads we need a temporary only if the offset is too big. |
| 6201 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6202 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 6203 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6204 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6205 | locations->AddTemp(Location::RequiresRegister()); |
| 6206 | } |
| 6207 | // And we always need the reserved entrypoint register. |
| 6208 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6209 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6210 | !Runtime::Current()->UseJitCompilation() && |
| 6211 | !instruction->GetIndex()->IsConstant()) { |
| 6212 | // We need a non-scratch temporary for the array data pointer. |
| 6213 | locations->AddTemp(Location::RequiresRegister()); |
| 6214 | // And we always need the reserved entrypoint register. |
| 6215 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6216 | } else { |
| 6217 | locations->AddTemp(Location::RequiresRegister()); |
| 6218 | } |
| 6219 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6220 | // Also need a temporary for String compression feature. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6221 | locations->AddTemp(Location::RequiresRegister()); |
| 6222 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 6226 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6227 | Location obj_loc = locations->InAt(0); |
| 6228 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6229 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6230 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6231 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6232 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6233 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6234 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6235 | HInstruction* array_instr = instruction->GetArray(); |
| 6236 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6237 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6238 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6239 | case Primitive::kPrimBoolean: |
| 6240 | case Primitive::kPrimByte: |
| 6241 | case Primitive::kPrimShort: |
| 6242 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6243 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6244 | Register length; |
| 6245 | if (maybe_compressed_char_at) { |
| 6246 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 6247 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6248 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6249 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6250 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6251 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6252 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6253 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6254 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6255 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6256 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6257 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6258 | "Expecting 0=compressed, 1=uncompressed"); |
| 6259 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6260 | __ LoadFromOffset(kLoadUnsignedByte, |
| 6261 | out_loc.AsRegister<Register>(), |
| 6262 | obj, |
| 6263 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6264 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6265 | __ Bind(&uncompressed_load); |
| 6266 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 6267 | out_loc.AsRegister<Register>(), |
| 6268 | obj, |
| 6269 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6270 | if (done.IsLinked()) { |
| 6271 | __ Bind(&done); |
| 6272 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6273 | } else { |
| 6274 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6275 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6276 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6277 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 6278 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6279 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6280 | Register temp = IP; |
| 6281 | |
| 6282 | if (has_intermediate_address) { |
| 6283 | // We do not need to compute the intermediate address from the array: the |
| 6284 | // input instruction has done it already. See the comment in |
| 6285 | // `TryExtractArrayAccessAddress()`. |
| 6286 | if (kIsDebugBuild) { |
| 6287 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6288 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6289 | } |
| 6290 | temp = obj; |
| 6291 | } else { |
| 6292 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 6293 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6294 | if (maybe_compressed_char_at) { |
| 6295 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6296 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6297 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6298 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6299 | "Expecting 0=compressed, 1=uncompressed"); |
| 6300 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6301 | __ ldrb(out_loc.AsRegister<Register>(), |
| 6302 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6303 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6304 | __ Bind(&uncompressed_load); |
| 6305 | __ ldrh(out_loc.AsRegister<Register>(), |
| 6306 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6307 | if (done.IsLinked()) { |
| 6308 | __ Bind(&done); |
| 6309 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6310 | } else { |
| 6311 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 6312 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6313 | } |
| 6314 | break; |
| 6315 | } |
| 6316 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6317 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 6318 | // The read barrier instrumentation of object ArrayGet |
| 6319 | // instructions does not support the HIntermediateAddress |
| 6320 | // instruction. |
| 6321 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6322 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6323 | static_assert( |
| 6324 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6325 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6326 | // /* HeapReference<Object> */ out = |
| 6327 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6328 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 6329 | Location temp = locations->GetTemp(0); |
| 6330 | // Note that a potential implicit null check is handled in this |
| 6331 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6332 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6333 | if (index.IsConstant()) { |
| 6334 | // Array load with a constant index can be treated as a field load. |
| 6335 | data_offset += helpers::Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 6336 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6337 | out_loc, |
| 6338 | obj, |
| 6339 | data_offset, |
| 6340 | locations->GetTemp(0), |
| 6341 | /* needs_null_check */ false); |
| 6342 | } else { |
| 6343 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6344 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6345 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6346 | } else { |
| 6347 | Register out = out_loc.AsRegister<Register>(); |
| 6348 | if (index.IsConstant()) { |
| 6349 | size_t offset = |
| 6350 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6351 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 6352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6353 | // If read barriers are enabled, emit read barriers other than |
| 6354 | // Baker's using a slow path (and also unpoison the loaded |
| 6355 | // reference, if heap poisoning is enabled). |
| 6356 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6357 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6358 | Register temp = IP; |
| 6359 | |
| 6360 | if (has_intermediate_address) { |
| 6361 | // We do not need to compute the intermediate address from the array: the |
| 6362 | // input instruction has done it already. See the comment in |
| 6363 | // `TryExtractArrayAccessAddress()`. |
| 6364 | if (kIsDebugBuild) { |
| 6365 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6366 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6367 | } |
| 6368 | temp = obj; |
| 6369 | } else { |
| 6370 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 6371 | } |
| 6372 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6373 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6375 | // If read barriers are enabled, emit read barriers other than |
| 6376 | // Baker's using a slow path (and also unpoison the loaded |
| 6377 | // reference, if heap poisoning is enabled). |
| 6378 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6379 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6380 | } |
| 6381 | } |
| 6382 | break; |
| 6383 | } |
| 6384 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6385 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6386 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6387 | size_t offset = |
| 6388 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6389 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6390 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6391 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6392 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6393 | } |
| 6394 | break; |
| 6395 | } |
| 6396 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6397 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6398 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6399 | if (index.IsConstant()) { |
| 6400 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6401 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6402 | } else { |
| 6403 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6404 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6405 | } |
| 6406 | break; |
| 6407 | } |
| 6408 | |
| 6409 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6410 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6411 | if (index.IsConstant()) { |
| 6412 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6413 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6414 | } else { |
| 6415 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6416 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6417 | } |
| 6418 | break; |
| 6419 | } |
| 6420 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6421 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6422 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6423 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6424 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6425 | |
| 6426 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6427 | // Potential implicit null checks, in the case of reference |
| 6428 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6429 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6430 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6431 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6435 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6436 | |
| 6437 | bool needs_write_barrier = |
| 6438 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6439 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6440 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6441 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6442 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 6443 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6444 | LocationSummary::kCallOnSlowPath : |
| 6445 | LocationSummary::kNoCall); |
| 6446 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6447 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6448 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6449 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6450 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6451 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6452 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6453 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6454 | if (needs_write_barrier) { |
| 6455 | // Temporary registers for the write barrier. |
| 6456 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6457 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6458 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 6462 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6463 | Location array_loc = locations->InAt(0); |
| 6464 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6465 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6466 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6467 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6468 | bool needs_write_barrier = |
| 6469 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6470 | uint32_t data_offset = |
| 6471 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6472 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6473 | HInstruction* array_instr = instruction->GetArray(); |
| 6474 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6475 | |
| 6476 | switch (value_type) { |
| 6477 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6478 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6479 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6480 | case Primitive::kPrimChar: |
| 6481 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6482 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6483 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 6484 | uint32_t full_offset = |
| 6485 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6486 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6487 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6488 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6489 | Register temp = IP; |
| 6490 | |
| 6491 | if (has_intermediate_address) { |
| 6492 | // We do not need to compute the intermediate address from the array: the |
| 6493 | // input instruction has done it already. See the comment in |
| 6494 | // `TryExtractArrayAccessAddress()`. |
| 6495 | if (kIsDebugBuild) { |
| 6496 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6497 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 6498 | } |
| 6499 | temp = array; |
| 6500 | } else { |
| 6501 | __ add(temp, array, ShifterOperand(data_offset)); |
| 6502 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6503 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6504 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6505 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6506 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6507 | } |
| 6508 | break; |
| 6509 | } |
| 6510 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6511 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6512 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6513 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6514 | // See the comment in instruction_simplifier_shared.cc. |
| 6515 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6516 | |
| 6517 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6518 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6519 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6520 | size_t offset = |
| 6521 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6522 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6523 | } else { |
| 6524 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6525 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6526 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6527 | value_loc, |
| 6528 | IP, |
| 6529 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6530 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 6531 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6532 | DCHECK(!needs_write_barrier); |
| 6533 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6534 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6535 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6536 | |
| 6537 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6538 | Location temp1_loc = locations->GetTemp(0); |
| 6539 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6540 | Location temp2_loc = locations->GetTemp(1); |
| 6541 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6542 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6543 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6544 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6545 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6546 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6547 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6548 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6549 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6550 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6551 | codegen_->AddSlowPath(slow_path); |
| 6552 | if (instruction->GetValueCanBeNull()) { |
| 6553 | Label non_zero; |
| 6554 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6555 | if (index.IsConstant()) { |
| 6556 | size_t offset = |
| 6557 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6558 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6559 | } else { |
| 6560 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6561 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6562 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6563 | value_loc, |
| 6564 | IP, |
| 6565 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6566 | } |
| 6567 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6568 | __ b(final_label); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6569 | __ Bind(&non_zero); |
| 6570 | } |
| 6571 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6572 | // Note that when read barriers are enabled, the type checks |
| 6573 | // are performed without read barriers. This is fine, even in |
| 6574 | // the case where a class object is in the from-space after |
| 6575 | // the flip, as a comparison involving such a type would not |
| 6576 | // produce a false positive; it may of course produce a false |
| 6577 | // negative, in which case we would take the ArraySet slow |
| 6578 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6579 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6580 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6581 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6582 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6583 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6584 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6585 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6586 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6587 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6588 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6589 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6590 | // nor `temp2`, as we are comparing two poisoned references. |
| 6591 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6592 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6593 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6594 | Label do_put; |
| 6595 | __ b(&do_put, EQ); |
| 6596 | // If heap poisoning is enabled, the `temp1` reference has |
| 6597 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6598 | __ MaybeUnpoisonHeapReference(temp1); |
| 6599 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6600 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6601 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6602 | // If heap poisoning is enabled, no need to unpoison |
| 6603 | // `temp1`, as we are comparing against null below. |
| 6604 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6605 | __ Bind(&do_put); |
| 6606 | } else { |
| 6607 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6608 | } |
| 6609 | } |
| 6610 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6611 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6612 | if (kPoisonHeapReferences) { |
| 6613 | // Note that in the case where `value` is a null reference, |
| 6614 | // we do not enter this block, as a null reference does not |
| 6615 | // need poisoning. |
| 6616 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6617 | __ Mov(temp1, value); |
| 6618 | __ PoisonHeapReference(temp1); |
| 6619 | source = temp1; |
| 6620 | } |
| 6621 | |
| 6622 | if (index.IsConstant()) { |
| 6623 | size_t offset = |
| 6624 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6625 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6626 | } else { |
| 6627 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6628 | |
| 6629 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6630 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6631 | Location::RegisterLocation(source), |
| 6632 | IP, |
| 6633 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6634 | } |
| 6635 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6636 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6637 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6638 | } |
| 6639 | |
| 6640 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6641 | |
| 6642 | if (done.IsLinked()) { |
| 6643 | __ Bind(&done); |
| 6644 | } |
| 6645 | |
| 6646 | if (slow_path != nullptr) { |
| 6647 | __ Bind(slow_path->GetExitLabel()); |
| 6648 | } |
| 6649 | |
| 6650 | break; |
| 6651 | } |
| 6652 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6653 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6654 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6655 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6656 | size_t offset = |
| 6657 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6658 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6659 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6660 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6661 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6662 | } |
| 6663 | break; |
| 6664 | } |
| 6665 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6666 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6667 | Location value = locations->InAt(2); |
| 6668 | DCHECK(value.IsFpuRegister()); |
| 6669 | if (index.IsConstant()) { |
| 6670 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6671 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6672 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6673 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6674 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6675 | } |
| 6676 | break; |
| 6677 | } |
| 6678 | |
| 6679 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6680 | Location value = locations->InAt(2); |
| 6681 | DCHECK(value.IsFpuRegisterPair()); |
| 6682 | if (index.IsConstant()) { |
| 6683 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6684 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6685 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6686 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6687 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6688 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6689 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6690 | break; |
| 6691 | } |
| 6692 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6693 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6694 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6695 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6696 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6697 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6698 | // Objects are handled in the switch. |
| 6699 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6700 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6701 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6705 | LocationSummary* locations = |
| 6706 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6708 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6709 | } |
| 6710 | |
| 6711 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6712 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6713 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6714 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6715 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6716 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6717 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6718 | // Mask out compression flag from String's array length. |
| 6719 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6720 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6721 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6722 | } |
| 6723 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6724 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6725 | LocationSummary* locations = |
| 6726 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6727 | |
| 6728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6729 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6730 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6731 | } |
| 6732 | |
| 6733 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6734 | LocationSummary* locations = instruction->GetLocations(); |
| 6735 | Location out = locations->Out(); |
| 6736 | Location first = locations->InAt(0); |
| 6737 | Location second = locations->InAt(1); |
| 6738 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6739 | if (second.IsRegister()) { |
| 6740 | __ add(out.AsRegister<Register>(), |
| 6741 | first.AsRegister<Register>(), |
| 6742 | ShifterOperand(second.AsRegister<Register>())); |
| 6743 | } else { |
| 6744 | __ AddConstant(out.AsRegister<Register>(), |
| 6745 | first.AsRegister<Register>(), |
| 6746 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6747 | } |
| 6748 | } |
| 6749 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6750 | void LocationsBuilderARM::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 6751 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6752 | } |
| 6753 | |
| 6754 | void InstructionCodeGeneratorARM::VisitIntermediateAddressIndex( |
| 6755 | HIntermediateAddressIndex* instruction) { |
| 6756 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6757 | } |
| 6758 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6759 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6760 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6761 | InvokeRuntimeCallingConvention calling_convention; |
| 6762 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6763 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6764 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6765 | |
| 6766 | HInstruction* index = instruction->InputAt(0); |
| 6767 | HInstruction* length = instruction->InputAt(1); |
| 6768 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6769 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6770 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6771 | // locations. |
| 6772 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6773 | locations->SetInAt(0, both_const |
| 6774 | ? Location::ConstantLocation(index->AsConstant()) |
| 6775 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6776 | locations->SetInAt(1, both_const |
| 6777 | ? Location::ConstantLocation(length->AsConstant()) |
| 6778 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6782 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6783 | Location index_loc = locations->InAt(0); |
| 6784 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6785 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6786 | if (length_loc.IsConstant()) { |
| 6787 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6788 | if (index_loc.IsConstant()) { |
| 6789 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6790 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6791 | if (index < 0 || index >= length) { |
| 6792 | SlowPathCodeARM* slow_path = |
| 6793 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6794 | codegen_->AddSlowPath(slow_path); |
| 6795 | __ b(slow_path->GetEntryLabel()); |
| 6796 | } else { |
| 6797 | // Some optimization after BCE may have generated this, and we should not |
| 6798 | // generate a bounds check if it is a valid range. |
| 6799 | } |
| 6800 | return; |
| 6801 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6802 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6803 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6804 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6805 | codegen_->AddSlowPath(slow_path); |
| 6806 | __ b(slow_path->GetEntryLabel(), HS); |
| 6807 | } else { |
| 6808 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6809 | if (index_loc.IsConstant()) { |
| 6810 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6811 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6812 | } else { |
| 6813 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6814 | } |
| 6815 | codegen_->AddSlowPath(slow_path); |
| 6816 | __ b(slow_path->GetEntryLabel(), LS); |
| 6817 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6818 | } |
| 6819 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6820 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6821 | Register card, |
| 6822 | Register object, |
| 6823 | Register value, |
| 6824 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6825 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6826 | if (can_be_null) { |
| 6827 | __ CompareAndBranchIfZero(value, &is_null); |
| 6828 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6829 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6830 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6831 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6832 | if (can_be_null) { |
| 6833 | __ Bind(&is_null); |
| 6834 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6835 | } |
| 6836 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6837 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6838 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6842 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6843 | } |
| 6844 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6845 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6846 | LocationSummary* locations = |
| 6847 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6848 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6849 | } |
| 6850 | |
| 6851 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6852 | HBasicBlock* block = instruction->GetBlock(); |
| 6853 | if (block->GetLoopInformation() != nullptr) { |
| 6854 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6855 | // The back edge will generate the suspend check. |
| 6856 | return; |
| 6857 | } |
| 6858 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6859 | // The goto will generate the suspend check. |
| 6860 | return; |
| 6861 | } |
| 6862 | GenerateSuspendCheck(instruction, nullptr); |
| 6863 | } |
| 6864 | |
| 6865 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6866 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6867 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6868 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6869 | if (slow_path == nullptr) { |
| 6870 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6871 | instruction->SetSlowPath(slow_path); |
| 6872 | codegen_->AddSlowPath(slow_path); |
| 6873 | if (successor != nullptr) { |
| 6874 | DCHECK(successor->IsLoopHeader()); |
| 6875 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6876 | } |
| 6877 | } else { |
| 6878 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6879 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6880 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6881 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6882 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6883 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6884 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6885 | __ Bind(slow_path->GetReturnLabel()); |
| 6886 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6887 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6888 | __ b(slow_path->GetEntryLabel()); |
| 6889 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6890 | } |
| 6891 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6892 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6893 | return codegen_->GetAssembler(); |
| 6894 | } |
| 6895 | |
| 6896 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6897 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6898 | Location source = move->GetSource(); |
| 6899 | Location destination = move->GetDestination(); |
| 6900 | |
| 6901 | if (source.IsRegister()) { |
| 6902 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6903 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6904 | } else if (destination.IsFpuRegister()) { |
| 6905 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6906 | } else { |
| 6907 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6908 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6909 | SP, destination.GetStackIndex()); |
| 6910 | } |
| 6911 | } else if (source.IsStackSlot()) { |
| 6912 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6913 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6914 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6915 | } else if (destination.IsFpuRegister()) { |
| 6916 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6917 | } else { |
| 6918 | DCHECK(destination.IsStackSlot()); |
| 6919 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6920 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6921 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6922 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6923 | if (destination.IsRegister()) { |
| 6924 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6925 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6926 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6927 | } else { |
| 6928 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6929 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6930 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6931 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6932 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6933 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6934 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6935 | } else if (destination.IsRegisterPair()) { |
| 6936 | DCHECK(ExpectedPairLayout(destination)); |
| 6937 | __ LoadFromOffset( |
| 6938 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6939 | } else { |
| 6940 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6941 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6942 | SP, |
| 6943 | source.GetStackIndex()); |
| 6944 | } |
| 6945 | } else if (source.IsRegisterPair()) { |
| 6946 | if (destination.IsRegisterPair()) { |
| 6947 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6948 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6949 | } else if (destination.IsFpuRegisterPair()) { |
| 6950 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6951 | source.AsRegisterPairLow<Register>(), |
| 6952 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6953 | } else { |
| 6954 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6955 | DCHECK(ExpectedPairLayout(source)); |
| 6956 | __ StoreToOffset( |
| 6957 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6958 | } |
| 6959 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6960 | if (destination.IsRegisterPair()) { |
| 6961 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6962 | destination.AsRegisterPairHigh<Register>(), |
| 6963 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6964 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6965 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6966 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6967 | } else { |
| 6968 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6969 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6970 | SP, |
| 6971 | destination.GetStackIndex()); |
| 6972 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6973 | } else { |
| 6974 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6975 | HConstant* constant = source.GetConstant(); |
| 6976 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6977 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6978 | if (destination.IsRegister()) { |
| 6979 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6980 | } else { |
| 6981 | DCHECK(destination.IsStackSlot()); |
| 6982 | __ LoadImmediate(IP, value); |
| 6983 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6984 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6985 | } else if (constant->IsLongConstant()) { |
| 6986 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6987 | if (destination.IsRegisterPair()) { |
| 6988 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6989 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6990 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6991 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6992 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6993 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6994 | __ LoadImmediate(IP, High32Bits(value)); |
| 6995 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6996 | } |
| 6997 | } else if (constant->IsDoubleConstant()) { |
| 6998 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6999 | if (destination.IsFpuRegisterPair()) { |
| 7000 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7001 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7002 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7003 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7004 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 7005 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 7006 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 7007 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 7008 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7009 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7010 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7011 | float value = constant->AsFloatConstant()->GetValue(); |
| 7012 | if (destination.IsFpuRegister()) { |
| 7013 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 7014 | } else { |
| 7015 | DCHECK(destination.IsStackSlot()); |
| 7016 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 7017 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 7018 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 7019 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 7024 | __ Mov(IP, reg); |
| 7025 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 7026 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 7027 | } |
| 7028 | |
| 7029 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 7030 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 7031 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7032 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 7033 | SP, mem1 + stack_offset); |
| 7034 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 7035 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 7036 | SP, mem2 + stack_offset); |
| 7037 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 7038 | } |
| 7039 | |
| 7040 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7041 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7042 | Location source = move->GetSource(); |
| 7043 | Location destination = move->GetDestination(); |
| 7044 | |
| 7045 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7046 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 7047 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 7048 | __ Mov(IP, source.AsRegister<Register>()); |
| 7049 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 7050 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7051 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7052 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7053 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7054 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7055 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 7056 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7057 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7058 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7059 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7060 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7061 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7062 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7063 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7064 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7065 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 7066 | destination.AsRegisterPairHigh<Register>(), |
| 7067 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7068 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7069 | Register low_reg = source.IsRegisterPair() |
| 7070 | ? source.AsRegisterPairLow<Register>() |
| 7071 | : destination.AsRegisterPairLow<Register>(); |
| 7072 | int mem = source.IsRegisterPair() |
| 7073 | ? destination.GetStackIndex() |
| 7074 | : source.GetStackIndex(); |
| 7075 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7076 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7077 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7078 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7079 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7080 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 7081 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7082 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7083 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7084 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7085 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 7086 | DRegister reg = source.IsFpuRegisterPair() |
| 7087 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 7088 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 7089 | int mem = source.IsFpuRegisterPair() |
| 7090 | ? destination.GetStackIndex() |
| 7091 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7092 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7093 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7094 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7095 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 7096 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 7097 | : destination.AsFpuRegister<SRegister>(); |
| 7098 | int mem = source.IsFpuRegister() |
| 7099 | ? destination.GetStackIndex() |
| 7100 | : source.GetStackIndex(); |
| 7101 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7102 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7103 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7104 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7105 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7106 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 7107 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7108 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7109 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7110 | } |
| 7111 | } |
| 7112 | |
| 7113 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 7114 | __ Push(static_cast<Register>(reg)); |
| 7115 | } |
| 7116 | |
| 7117 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 7118 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7119 | } |
| 7120 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7121 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 7122 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7123 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7124 | case HLoadClass::LoadKind::kInvalid: |
| 7125 | LOG(FATAL) << "UNREACHABLE"; |
| 7126 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7127 | case HLoadClass::LoadKind::kReferrersClass: |
| 7128 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7129 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7130 | case HLoadClass::LoadKind::kBssEntry: |
| 7131 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7132 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7133 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7134 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7135 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7136 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7137 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7138 | break; |
| 7139 | } |
| 7140 | return desired_class_load_kind; |
| 7141 | } |
| 7142 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7143 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7144 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7145 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7146 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7147 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7148 | cls, |
| 7149 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7150 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7151 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7152 | return; |
| 7153 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7154 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7155 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7156 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7157 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7158 | ? LocationSummary::kCallOnSlowPath |
| 7159 | : LocationSummary::kNoCall; |
| 7160 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7161 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7162 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7163 | } |
| 7164 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7165 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7166 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7167 | } |
| 7168 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7169 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7170 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7171 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 7172 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7173 | // to the custom calling convention) or by marking, so we request a different temp. |
| 7174 | locations->AddTemp(Location::RequiresRegister()); |
| 7175 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7176 | InvokeRuntimeCallingConvention calling_convention; |
| 7177 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7178 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7179 | // that the the kPrimNot result register is the same as the first argument register. |
| 7180 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7181 | } else { |
| 7182 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7183 | } |
| 7184 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7185 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7186 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7187 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7188 | !Runtime::Current()->UseJitCompilation())) { |
| 7189 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 7190 | } |
| 7191 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7192 | } |
| 7193 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7194 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7195 | // move. |
| 7196 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7197 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7198 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7199 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7200 | return; |
| 7201 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7202 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7203 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7204 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7205 | Location out_loc = locations->Out(); |
| 7206 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7207 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7208 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7209 | ? kWithoutReadBarrier |
| 7210 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7211 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7212 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7213 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7214 | DCHECK(!cls->CanCallRuntime()); |
| 7215 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7216 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7217 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7218 | GenerateGcRootFieldLoad(cls, |
| 7219 | out_loc, |
| 7220 | current_method, |
| 7221 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7222 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7223 | break; |
| 7224 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7225 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7226 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7227 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7228 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7229 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7230 | __ BindTrackedLabel(&labels->movw_label); |
| 7231 | __ movw(out, /* placeholder */ 0u); |
| 7232 | __ BindTrackedLabel(&labels->movt_label); |
| 7233 | __ movt(out, /* placeholder */ 0u); |
| 7234 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7235 | __ add(out, out, ShifterOperand(PC)); |
| 7236 | break; |
| 7237 | } |
| 7238 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7239 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7240 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7241 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7242 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7243 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7244 | break; |
| 7245 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7246 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7247 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7248 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7249 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7250 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7251 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7252 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7253 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7254 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7255 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7256 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7257 | __ add(temp, temp, ShifterOperand(PC)); |
| 7258 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7259 | generate_null_check = true; |
| 7260 | break; |
| 7261 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7262 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 7263 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7264 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7265 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7266 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7267 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7268 | break; |
| 7269 | } |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7270 | case HLoadClass::LoadKind::kRuntimeCall: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7271 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7272 | LOG(FATAL) << "UNREACHABLE"; |
| 7273 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7274 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7275 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7276 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7277 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7278 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7279 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 7280 | codegen_->AddSlowPath(slow_path); |
| 7281 | if (generate_null_check) { |
| 7282 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7283 | } |
| 7284 | if (cls->MustGenerateClinitCheck()) { |
| 7285 | GenerateClassInitializationCheck(slow_path, out); |
| 7286 | } else { |
| 7287 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7288 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7289 | } |
| 7290 | } |
| 7291 | |
| 7292 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 7293 | LocationSummary* locations = |
| 7294 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 7295 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7296 | if (check->HasUses()) { |
| 7297 | locations->SetOut(Location::SameAsFirstInput()); |
| 7298 | } |
| 7299 | } |
| 7300 | |
| 7301 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7302 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7303 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7304 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7305 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7306 | GenerateClassInitializationCheck(slow_path, |
| 7307 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7308 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7309 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7310 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7311 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7312 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 7313 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 7314 | __ b(slow_path->GetEntryLabel(), LT); |
| 7315 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7316 | // properly. Therefore, we do a memory fence. |
| 7317 | __ dmb(ISH); |
| 7318 | __ Bind(slow_path->GetExitLabel()); |
| 7319 | } |
| 7320 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7321 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 7322 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7323 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7324 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7325 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 7326 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7327 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7328 | case HLoadString::LoadKind::kJitTableAddress: |
| 7329 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 7330 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7331 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7332 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7333 | break; |
| 7334 | } |
| 7335 | return desired_string_load_kind; |
| 7336 | } |
| 7337 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7338 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7339 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 7340 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7341 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7342 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7343 | locations->SetOut(Location::RegisterLocation(R0)); |
| 7344 | } else { |
| 7345 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7346 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7347 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7348 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 7349 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7350 | // 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] | 7351 | locations->AddTemp(Location::RequiresRegister()); |
| 7352 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7353 | InvokeRuntimeCallingConvention calling_convention; |
| 7354 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7355 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7356 | // that the the kPrimNot result register is the same as the first argument register. |
| 7357 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7358 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7359 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 7360 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7361 | } else { |
| 7362 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7363 | } |
| 7364 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7365 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7366 | } |
| 7367 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7368 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7369 | // move. |
| 7370 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7371 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7372 | Location out_loc = locations->Out(); |
| 7373 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7374 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7375 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7376 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7377 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7378 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7379 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7380 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7381 | __ BindTrackedLabel(&labels->movw_label); |
| 7382 | __ movw(out, /* placeholder */ 0u); |
| 7383 | __ BindTrackedLabel(&labels->movt_label); |
| 7384 | __ movt(out, /* placeholder */ 0u); |
| 7385 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7386 | __ add(out, out, ShifterOperand(PC)); |
| 7387 | return; // No dex cache slow path. |
| 7388 | } |
| 7389 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7390 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7391 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7392 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7393 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7394 | return; // No dex cache slow path. |
| 7395 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7396 | case HLoadString::LoadKind::kBssEntry: { |
| 7397 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7398 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7399 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7400 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7401 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7402 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7403 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7404 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7405 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7406 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7407 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7408 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7409 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7410 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 7411 | codegen_->AddSlowPath(slow_path); |
| 7412 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7413 | __ Bind(slow_path->GetExitLabel()); |
| 7414 | return; |
| 7415 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7416 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7417 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7418 | load->GetStringIndex(), |
| 7419 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7420 | // /* GcRoot<mirror::String> */ out = *out |
| 7421 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7422 | return; |
| 7423 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7424 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7425 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7426 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7427 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7428 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7429 | DCHECK(load_kind == HLoadString::LoadKind::kRuntimeCall); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7430 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7431 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7432 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7433 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7434 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7435 | } |
| 7436 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7437 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7438 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7439 | } |
| 7440 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7441 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 7442 | LocationSummary* locations = |
| 7443 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7444 | locations->SetOut(Location::RequiresRegister()); |
| 7445 | } |
| 7446 | |
| 7447 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7448 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7449 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7450 | } |
| 7451 | |
| 7452 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 7453 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7454 | } |
| 7455 | |
| 7456 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7457 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7458 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7459 | } |
| 7460 | |
| 7461 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 7462 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7463 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7464 | InvokeRuntimeCallingConvention calling_convention; |
| 7465 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7466 | } |
| 7467 | |
| 7468 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7469 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7470 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7471 | } |
| 7472 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7473 | // Temp is used for read barrier. |
| 7474 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7475 | if (kEmitCompilerReadBarrier && |
| 7476 | (kUseBakerReadBarrier || |
| 7477 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7478 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7479 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7480 | return 1; |
| 7481 | } |
| 7482 | return 0; |
| 7483 | } |
| 7484 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7485 | // 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] | 7486 | // interface pointer, one for loading the current interface. |
| 7487 | // The other checks have one temp for loading the object's class. |
| 7488 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7489 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7490 | return 3; |
| 7491 | } |
| 7492 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7493 | } |
| 7494 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7495 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7496 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7497 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7498 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7499 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7500 | case TypeCheckKind::kExactCheck: |
| 7501 | case TypeCheckKind::kAbstractClassCheck: |
| 7502 | case TypeCheckKind::kClassHierarchyCheck: |
| 7503 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7504 | call_kind = |
| 7505 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7506 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7507 | break; |
| 7508 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7509 | case TypeCheckKind::kUnresolvedCheck: |
| 7510 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7511 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7512 | break; |
| 7513 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7514 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7515 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7516 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7517 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7518 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7520 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7521 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7522 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7523 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7524 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7525 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7526 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7527 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7530 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7531 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7532 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7533 | Location obj_loc = locations->InAt(0); |
| 7534 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7535 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7536 | Location out_loc = locations->Out(); |
| 7537 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7538 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7539 | DCHECK_LE(num_temps, 1u); |
| 7540 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7541 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7542 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7543 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7544 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7545 | Label done; |
| 7546 | Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7547 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7548 | |
| 7549 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7550 | // avoid null check if we know obj is not null. |
| 7551 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7552 | DCHECK_NE(out, obj); |
| 7553 | __ LoadImmediate(out, 0); |
| 7554 | __ CompareAndBranchIfZero(obj, final_label); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7555 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7556 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7557 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7558 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7559 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7560 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7561 | out_loc, |
| 7562 | obj_loc, |
| 7563 | class_offset, |
| 7564 | maybe_temp_loc, |
| 7565 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7566 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7567 | __ cmp(out, ShifterOperand(cls)); |
| 7568 | // We speculatively set the result to false without changing the condition |
| 7569 | // flags, which allows us to avoid some branching later. |
| 7570 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7571 | |
| 7572 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7573 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7574 | // encoding can be used. |
| 7575 | if (ArmAssembler::IsLowRegister(out)) { |
| 7576 | __ it(EQ); |
| 7577 | __ mov(out, ShifterOperand(1), EQ); |
| 7578 | } else { |
| 7579 | __ b(final_label, NE); |
| 7580 | __ LoadImmediate(out, 1); |
| 7581 | } |
| 7582 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7583 | break; |
| 7584 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7585 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7586 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7587 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7588 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7589 | out_loc, |
| 7590 | obj_loc, |
| 7591 | class_offset, |
| 7592 | maybe_temp_loc, |
| 7593 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7594 | // If the class is abstract, we eagerly fetch the super class of the |
| 7595 | // object to avoid doing a comparison we know will fail. |
| 7596 | Label loop; |
| 7597 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7598 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7599 | GenerateReferenceLoadOneRegister(instruction, |
| 7600 | out_loc, |
| 7601 | super_offset, |
| 7602 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7603 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7604 | // 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] | 7605 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7606 | __ cmp(out, ShifterOperand(cls)); |
| 7607 | __ b(&loop, NE); |
| 7608 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7609 | break; |
| 7610 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7611 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7612 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7613 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7614 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7615 | out_loc, |
| 7616 | obj_loc, |
| 7617 | class_offset, |
| 7618 | maybe_temp_loc, |
| 7619 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7620 | // Walk over the class hierarchy to find a match. |
| 7621 | Label loop, success; |
| 7622 | __ Bind(&loop); |
| 7623 | __ cmp(out, ShifterOperand(cls)); |
| 7624 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7625 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7626 | GenerateReferenceLoadOneRegister(instruction, |
| 7627 | out_loc, |
| 7628 | super_offset, |
| 7629 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7630 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7631 | // This is essentially a null check, but it sets the condition flags to the |
| 7632 | // proper value for the code that follows the loop, i.e. not `EQ`. |
| 7633 | __ cmp(out, ShifterOperand(1)); |
| 7634 | __ b(&loop, HS); |
| 7635 | |
| 7636 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7637 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7638 | // encoding can be used. |
| 7639 | if (ArmAssembler::IsLowRegister(out)) { |
| 7640 | // If `out` is null, we use it for the result, and the condition flags |
| 7641 | // have already been set to `NE`, so the IT block that comes afterwards |
| 7642 | // (and which handles the successful case) turns into a NOP (instead of |
| 7643 | // overwriting `out`). |
| 7644 | __ Bind(&success); |
| 7645 | // There is only one branch to the `success` label (which is bound to this |
| 7646 | // IT block), and it has the same condition, `EQ`, so in that case the MOV |
| 7647 | // is executed. |
| 7648 | __ it(EQ); |
| 7649 | __ mov(out, ShifterOperand(1), EQ); |
| 7650 | } else { |
| 7651 | // 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] | 7652 | __ b(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7653 | __ Bind(&success); |
| 7654 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7655 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7656 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7657 | break; |
| 7658 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7659 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7660 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7661 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7662 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7663 | out_loc, |
| 7664 | obj_loc, |
| 7665 | class_offset, |
| 7666 | maybe_temp_loc, |
| 7667 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7668 | // Do an exact check. |
| 7669 | Label exact_check; |
| 7670 | __ cmp(out, ShifterOperand(cls)); |
| 7671 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7672 | // 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] | 7673 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7674 | GenerateReferenceLoadOneRegister(instruction, |
| 7675 | out_loc, |
| 7676 | component_offset, |
| 7677 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7678 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7679 | // 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] | 7680 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7681 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7682 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7683 | __ cmp(out, ShifterOperand(0)); |
| 7684 | // We speculatively set the result to false without changing the condition |
| 7685 | // flags, which allows us to avoid some branching later. |
| 7686 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7687 | |
| 7688 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7689 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7690 | // encoding can be used. |
| 7691 | if (ArmAssembler::IsLowRegister(out)) { |
| 7692 | __ Bind(&exact_check); |
| 7693 | __ it(EQ); |
| 7694 | __ mov(out, ShifterOperand(1), EQ); |
| 7695 | } else { |
| 7696 | __ b(final_label, NE); |
| 7697 | __ Bind(&exact_check); |
| 7698 | __ LoadImmediate(out, 1); |
| 7699 | } |
| 7700 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7701 | break; |
| 7702 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7703 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7704 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7705 | // No read barrier since the slow path will retry upon failure. |
| 7706 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7707 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7708 | out_loc, |
| 7709 | obj_loc, |
| 7710 | class_offset, |
| 7711 | maybe_temp_loc, |
| 7712 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7713 | __ cmp(out, ShifterOperand(cls)); |
| 7714 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7715 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7716 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7717 | codegen_->AddSlowPath(slow_path); |
| 7718 | __ b(slow_path->GetEntryLabel(), NE); |
| 7719 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7720 | break; |
| 7721 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7722 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7723 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7724 | case TypeCheckKind::kInterfaceCheck: { |
| 7725 | // 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] | 7726 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7727 | // cases. |
| 7728 | // |
| 7729 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7730 | // entry point without resorting to a type checking slow path |
| 7731 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7732 | // require to assign fixed registers for the inputs of this |
| 7733 | // HInstanceOf instruction (following the runtime calling |
| 7734 | // convention), which might be cluttered by the potential first |
| 7735 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7736 | // |
| 7737 | // TODO: Introduce a new runtime entry point taking the object |
| 7738 | // to test (instead of its class) as argument, and let it deal |
| 7739 | // with the read barrier issues. This will let us refactor this |
| 7740 | // case of the `switch` code as it was previously (with a direct |
| 7741 | // call to the runtime not using a type checking slow path). |
| 7742 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7743 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7744 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7745 | /* is_fatal */ false); |
| 7746 | codegen_->AddSlowPath(slow_path); |
| 7747 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7748 | break; |
| 7749 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7750 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7751 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7752 | if (done.IsLinked()) { |
| 7753 | __ Bind(&done); |
| 7754 | } |
| 7755 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7756 | if (slow_path != nullptr) { |
| 7757 | __ Bind(slow_path->GetExitLabel()); |
| 7758 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7759 | } |
| 7760 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7761 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7762 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7763 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7764 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7765 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7766 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7767 | case TypeCheckKind::kExactCheck: |
| 7768 | case TypeCheckKind::kAbstractClassCheck: |
| 7769 | case TypeCheckKind::kClassHierarchyCheck: |
| 7770 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7771 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7772 | LocationSummary::kCallOnSlowPath : |
| 7773 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7774 | break; |
| 7775 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7776 | case TypeCheckKind::kUnresolvedCheck: |
| 7777 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7778 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7779 | break; |
| 7780 | } |
| 7781 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7782 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7783 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7784 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7785 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
| 7788 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7789 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7790 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7791 | Location obj_loc = locations->InAt(0); |
| 7792 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7793 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7794 | Location temp_loc = locations->GetTemp(0); |
| 7795 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7796 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7797 | DCHECK_LE(num_temps, 3u); |
| 7798 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7799 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7800 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7801 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7802 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7803 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7804 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7805 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7806 | const uint32_t object_array_data_offset = |
| 7807 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7808 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7809 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7810 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7811 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7812 | bool is_type_check_slow_path_fatal = false; |
| 7813 | if (!kEmitCompilerReadBarrier) { |
| 7814 | is_type_check_slow_path_fatal = |
| 7815 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7816 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7817 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7818 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7819 | !instruction->CanThrowIntoCatchBlock(); |
| 7820 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7821 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7822 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7823 | is_type_check_slow_path_fatal); |
| 7824 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7825 | |
| 7826 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7827 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7828 | // Avoid null check if we know obj is not null. |
| 7829 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7830 | __ CompareAndBranchIfZero(obj, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7831 | } |
| 7832 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7833 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7834 | case TypeCheckKind::kExactCheck: |
| 7835 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7836 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7837 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7838 | temp_loc, |
| 7839 | obj_loc, |
| 7840 | class_offset, |
| 7841 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7842 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7843 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7844 | __ cmp(temp, ShifterOperand(cls)); |
| 7845 | // Jump to slow path for throwing the exception or doing a |
| 7846 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7847 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7848 | break; |
| 7849 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7850 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7851 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7852 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7853 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7854 | temp_loc, |
| 7855 | obj_loc, |
| 7856 | class_offset, |
| 7857 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7858 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7859 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7860 | // If the class is abstract, we eagerly fetch the super class of the |
| 7861 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7862 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7863 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7864 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7865 | GenerateReferenceLoadOneRegister(instruction, |
| 7866 | temp_loc, |
| 7867 | super_offset, |
| 7868 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7869 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7870 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7871 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7872 | // exception. |
| 7873 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7874 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7875 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7876 | __ cmp(temp, ShifterOperand(cls)); |
| 7877 | __ b(&loop, NE); |
| 7878 | break; |
| 7879 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7880 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7881 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7882 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7883 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7884 | temp_loc, |
| 7885 | obj_loc, |
| 7886 | class_offset, |
| 7887 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7888 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7889 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7890 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7891 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7892 | __ Bind(&loop); |
| 7893 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7894 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7895 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7896 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7897 | GenerateReferenceLoadOneRegister(instruction, |
| 7898 | temp_loc, |
| 7899 | super_offset, |
| 7900 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7901 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7902 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7903 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7904 | // exception. |
| 7905 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7906 | // Otherwise, jump to the beginning of the loop. |
| 7907 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7908 | break; |
| 7909 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7910 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7911 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7912 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7913 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7914 | temp_loc, |
| 7915 | obj_loc, |
| 7916 | class_offset, |
| 7917 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7918 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7919 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7920 | // Do an exact check. |
| 7921 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7922 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7923 | |
| 7924 | // 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] | 7925 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7926 | GenerateReferenceLoadOneRegister(instruction, |
| 7927 | temp_loc, |
| 7928 | component_offset, |
| 7929 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7930 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7931 | // If the component type is null, jump to the slow path to throw the exception. |
| 7932 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7933 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7934 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7935 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7936 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7937 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7938 | break; |
| 7939 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7940 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7941 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7942 | // 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] | 7943 | // We cannot directly call the CheckCast runtime entry point |
| 7944 | // without resorting to a type checking slow path here (i.e. by |
| 7945 | // calling InvokeRuntime directly), as it would require to |
| 7946 | // assign fixed registers for the inputs of this HInstanceOf |
| 7947 | // instruction (following the runtime calling convention), which |
| 7948 | // might be cluttered by the potential first read barrier |
| 7949 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7950 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7951 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7952 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7953 | |
| 7954 | case TypeCheckKind::kInterfaceCheck: { |
| 7955 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7956 | // positives by doing this. |
| 7957 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7958 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7959 | temp_loc, |
| 7960 | obj_loc, |
| 7961 | class_offset, |
| 7962 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7963 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7964 | |
| 7965 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7966 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7967 | temp_loc, |
| 7968 | temp_loc, |
| 7969 | iftable_offset, |
| 7970 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7971 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7972 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7973 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7974 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7975 | Label start_loop; |
| 7976 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7977 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7978 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7979 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7980 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7981 | // Go to next interface. |
| 7982 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7983 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7984 | maybe_temp2_loc.AsRegister<Register>(), |
| 7985 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7986 | // Compare the classes and continue the loop if they do not match. |
| 7987 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7988 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7989 | break; |
| 7990 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7991 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7992 | |
| 7993 | if (done.IsLinked()) { |
| 7994 | __ Bind(&done); |
| 7995 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7996 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7997 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7998 | } |
| 7999 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8000 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8001 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 8002 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8003 | InvokeRuntimeCallingConvention calling_convention; |
| 8004 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8005 | } |
| 8006 | |
| 8007 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 8008 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8009 | instruction, |
| 8010 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8011 | if (instruction->IsEnter()) { |
| 8012 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8013 | } else { |
| 8014 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8015 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8016 | } |
| 8017 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8018 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 8019 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 8020 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8021 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8022 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8023 | LocationSummary* locations = |
| 8024 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8025 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8026 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8027 | // 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] | 8028 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8029 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 8030 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 8034 | HandleBitwiseOperation(instruction); |
| 8035 | } |
| 8036 | |
| 8037 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 8038 | HandleBitwiseOperation(instruction); |
| 8039 | } |
| 8040 | |
| 8041 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 8042 | HandleBitwiseOperation(instruction); |
| 8043 | } |
| 8044 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 8045 | |
| 8046 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8047 | LocationSummary* locations = |
| 8048 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8049 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8050 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 8051 | |
| 8052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8053 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8054 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8055 | } |
| 8056 | |
| 8057 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8058 | LocationSummary* locations = instruction->GetLocations(); |
| 8059 | Location first = locations->InAt(0); |
| 8060 | Location second = locations->InAt(1); |
| 8061 | Location out = locations->Out(); |
| 8062 | |
| 8063 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8064 | Register first_reg = first.AsRegister<Register>(); |
| 8065 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 8066 | Register out_reg = out.AsRegister<Register>(); |
| 8067 | |
| 8068 | switch (instruction->GetOpKind()) { |
| 8069 | case HInstruction::kAnd: |
| 8070 | __ bic(out_reg, first_reg, second_reg); |
| 8071 | break; |
| 8072 | case HInstruction::kOr: |
| 8073 | __ orn(out_reg, first_reg, second_reg); |
| 8074 | break; |
| 8075 | // There is no EON on arm. |
| 8076 | case HInstruction::kXor: |
| 8077 | default: |
| 8078 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8079 | UNREACHABLE(); |
| 8080 | } |
| 8081 | return; |
| 8082 | |
| 8083 | } else { |
| 8084 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8085 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8086 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8087 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 8088 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 8089 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8090 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8091 | |
| 8092 | switch (instruction->GetOpKind()) { |
| 8093 | case HInstruction::kAnd: |
| 8094 | __ bic(out_low, first_low, second_low); |
| 8095 | __ bic(out_high, first_high, second_high); |
| 8096 | break; |
| 8097 | case HInstruction::kOr: |
| 8098 | __ orn(out_low, first_low, second_low); |
| 8099 | __ orn(out_high, first_high, second_high); |
| 8100 | break; |
| 8101 | // There is no EON on arm. |
| 8102 | case HInstruction::kXor: |
| 8103 | default: |
| 8104 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8105 | UNREACHABLE(); |
| 8106 | } |
| 8107 | } |
| 8108 | } |
| 8109 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8110 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 8111 | HDataProcWithShifterOp* instruction) { |
| 8112 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 8113 | instruction->GetType() == Primitive::kPrimLong); |
| 8114 | LocationSummary* locations = |
| 8115 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8116 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 8117 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8118 | |
| 8119 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8120 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8121 | locations->SetOut(Location::RequiresRegister(), |
| 8122 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8123 | } |
| 8124 | |
| 8125 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 8126 | HDataProcWithShifterOp* instruction) { |
| 8127 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8128 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8129 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8130 | const Location left = locations->InAt(0); |
| 8131 | const Location right = locations->InAt(1); |
| 8132 | const Location out = locations->Out(); |
| 8133 | |
| 8134 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 8135 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 8136 | |
| 8137 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 8138 | ? right.AsRegisterPairLow<Register>() |
| 8139 | : right.AsRegister<Register>(); |
| 8140 | |
| 8141 | GenerateDataProcInstruction(kind, |
| 8142 | out.AsRegister<Register>(), |
| 8143 | left.AsRegister<Register>(), |
| 8144 | ShifterOperand(second, |
| 8145 | ShiftFromOpKind(op_kind), |
| 8146 | instruction->GetShiftAmount()), |
| 8147 | codegen_); |
| 8148 | } else { |
| 8149 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 8150 | |
| 8151 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8152 | const Register second = right.AsRegister<Register>(); |
| 8153 | |
| 8154 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 8155 | GenerateDataProc(kind, |
| 8156 | out, |
| 8157 | left, |
| 8158 | ShifterOperand(second), |
| 8159 | ShifterOperand(second, ASR, 31), |
| 8160 | codegen_); |
| 8161 | } else { |
| 8162 | GenerateLongDataProc(instruction, codegen_); |
| 8163 | } |
| 8164 | } |
| 8165 | } |
| 8166 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8167 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 8168 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8169 | if (value == 0xffffffffu) { |
| 8170 | if (out != first) { |
| 8171 | __ mov(out, ShifterOperand(first)); |
| 8172 | } |
| 8173 | return; |
| 8174 | } |
| 8175 | if (value == 0u) { |
| 8176 | __ mov(out, ShifterOperand(0)); |
| 8177 | return; |
| 8178 | } |
| 8179 | ShifterOperand so; |
| 8180 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 8181 | __ and_(out, first, so); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8182 | } else if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8183 | __ bic(out, first, ShifterOperand(~value)); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8184 | } else { |
| 8185 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8186 | __ ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8187 | } |
| 8188 | } |
| 8189 | |
| 8190 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 8191 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8192 | if (value == 0u) { |
| 8193 | if (out != first) { |
| 8194 | __ mov(out, ShifterOperand(first)); |
| 8195 | } |
| 8196 | return; |
| 8197 | } |
| 8198 | if (value == 0xffffffffu) { |
| 8199 | __ mvn(out, ShifterOperand(0)); |
| 8200 | return; |
| 8201 | } |
| 8202 | ShifterOperand so; |
| 8203 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 8204 | __ orr(out, first, so); |
| 8205 | } else { |
| 8206 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 8207 | __ orn(out, first, ShifterOperand(~value)); |
| 8208 | } |
| 8209 | } |
| 8210 | |
| 8211 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 8212 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8213 | if (value == 0u) { |
| 8214 | if (out != first) { |
| 8215 | __ mov(out, ShifterOperand(first)); |
| 8216 | } |
| 8217 | return; |
| 8218 | } |
| 8219 | __ eor(out, first, ShifterOperand(value)); |
| 8220 | } |
| 8221 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 8222 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 8223 | Location first, |
| 8224 | uint64_t value) { |
| 8225 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8226 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8227 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8228 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8229 | uint32_t value_low = Low32Bits(value); |
| 8230 | uint32_t value_high = High32Bits(value); |
| 8231 | if (value_low == 0u) { |
| 8232 | if (out_low != first_low) { |
| 8233 | __ mov(out_low, ShifterOperand(first_low)); |
| 8234 | } |
| 8235 | __ AddConstant(out_high, first_high, value_high); |
| 8236 | return; |
| 8237 | } |
| 8238 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 8239 | ShifterOperand so; |
| 8240 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 8241 | __ adc(out_high, first_high, so); |
| 8242 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 8243 | __ sbc(out_high, first_high, so); |
| 8244 | } else { |
| 8245 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 8246 | UNREACHABLE(); |
| 8247 | } |
| 8248 | } |
| 8249 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8250 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8251 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8252 | Location first = locations->InAt(0); |
| 8253 | Location second = locations->InAt(1); |
| 8254 | Location out = locations->Out(); |
| 8255 | |
| 8256 | if (second.IsConstant()) { |
| 8257 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8258 | uint32_t value_low = Low32Bits(value); |
| 8259 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8260 | Register first_reg = first.AsRegister<Register>(); |
| 8261 | Register out_reg = out.AsRegister<Register>(); |
| 8262 | if (instruction->IsAnd()) { |
| 8263 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8264 | } else if (instruction->IsOr()) { |
| 8265 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8266 | } else { |
| 8267 | DCHECK(instruction->IsXor()); |
| 8268 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8269 | } |
| 8270 | } else { |
| 8271 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8272 | uint32_t value_high = High32Bits(value); |
| 8273 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8274 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8275 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8276 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8277 | if (instruction->IsAnd()) { |
| 8278 | GenerateAndConst(out_low, first_low, value_low); |
| 8279 | GenerateAndConst(out_high, first_high, value_high); |
| 8280 | } else if (instruction->IsOr()) { |
| 8281 | GenerateOrrConst(out_low, first_low, value_low); |
| 8282 | GenerateOrrConst(out_high, first_high, value_high); |
| 8283 | } else { |
| 8284 | DCHECK(instruction->IsXor()); |
| 8285 | GenerateEorConst(out_low, first_low, value_low); |
| 8286 | GenerateEorConst(out_high, first_high, value_high); |
| 8287 | } |
| 8288 | } |
| 8289 | return; |
| 8290 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8291 | |
| 8292 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8293 | Register first_reg = first.AsRegister<Register>(); |
| 8294 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 8295 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8296 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8297 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8298 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8299 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8300 | } else { |
| 8301 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8302 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8303 | } |
| 8304 | } else { |
| 8305 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8306 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8307 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8308 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 8309 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 8310 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8311 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8312 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8313 | __ and_(out_low, first_low, second_low); |
| 8314 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8315 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8316 | __ orr(out_low, first_low, second_low); |
| 8317 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8318 | } else { |
| 8319 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8320 | __ eor(out_low, first_low, second_low); |
| 8321 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8322 | } |
| 8323 | } |
| 8324 | } |
| 8325 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8326 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 8327 | HInstruction* instruction, |
| 8328 | Location out, |
| 8329 | uint32_t offset, |
| 8330 | Location maybe_temp, |
| 8331 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8332 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8333 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 8334 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8335 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8336 | if (kUseBakerReadBarrier) { |
| 8337 | // Load with fast path based Baker's read barrier. |
| 8338 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8339 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8340 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8341 | } else { |
| 8342 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8343 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8344 | // in the following move operation, as we will need it for the |
| 8345 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8346 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8347 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8348 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8349 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8350 | } |
| 8351 | } else { |
| 8352 | // Plain load with no read barrier. |
| 8353 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8354 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8355 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8356 | } |
| 8357 | } |
| 8358 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8359 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 8360 | HInstruction* instruction, |
| 8361 | Location out, |
| 8362 | Location obj, |
| 8363 | uint32_t offset, |
| 8364 | Location maybe_temp, |
| 8365 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8366 | Register out_reg = out.AsRegister<Register>(); |
| 8367 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8368 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 8369 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8370 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8371 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8372 | // Load with fast path based Baker's read barrier. |
| 8373 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8374 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8375 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8376 | } else { |
| 8377 | // Load with slow path based read barrier. |
| 8378 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8379 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8380 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8381 | } |
| 8382 | } else { |
| 8383 | // Plain load with no read barrier. |
| 8384 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8385 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8386 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8387 | } |
| 8388 | } |
| 8389 | |
| 8390 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 8391 | Location root, |
| 8392 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8393 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8394 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8395 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8396 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8397 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8398 | if (kUseBakerReadBarrier) { |
| 8399 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8400 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8401 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8402 | !Runtime::Current()->UseJitCompilation()) { |
| 8403 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8404 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8405 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8406 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8407 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8408 | // |
| 8409 | // We use link-time generated thunks for the slow path. That thunk |
| 8410 | // checks the reference and jumps to the entrypoint if needed. |
| 8411 | // |
| 8412 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8413 | // lr = &return_address; |
| 8414 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8415 | // if (temp != nullptr) { |
| 8416 | // goto gc_root_thunk<root_reg>(lr) |
| 8417 | // } |
| 8418 | // return_address: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8419 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8420 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8421 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8422 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8423 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8424 | Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8425 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8426 | // entrypoint_reg = |
| 8427 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8428 | DCHECK_EQ(IP, 12); |
| 8429 | const int32_t entry_point_offset = |
| 8430 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8431 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8432 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8433 | Label return_address; |
| 8434 | __ AdrCode(LR, &return_address); |
| 8435 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8436 | // Currently the offset is always within range. If that changes, |
| 8437 | // we shall have to split the load the same way as for fields. |
| 8438 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8439 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8440 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8441 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8442 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8443 | EmitPlaceholderBne(codegen_, bne_label); |
| 8444 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8445 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8446 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8447 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8448 | } else { |
| 8449 | // Note that we do not actually check the value of |
| 8450 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8451 | // root or not. Instead, we load into `temp` the read barrier |
| 8452 | // mark entry point corresponding to register `root`. If `temp` |
| 8453 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8454 | // versa. |
| 8455 | // |
| 8456 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8457 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8458 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8459 | // // Slow path. |
| 8460 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8461 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8462 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8463 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8464 | Location temp = Location::RegisterLocation(LR); |
| 8465 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 8466 | instruction, root, /* entrypoint */ temp); |
| 8467 | codegen_->AddSlowPath(slow_path); |
| 8468 | |
| 8469 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8470 | const int32_t entry_point_offset = |
| 8471 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8472 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8473 | // threads are suspended or running a checkpoint. |
| 8474 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 8475 | |
| 8476 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8477 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8478 | static_assert( |
| 8479 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8480 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8481 | "have different sizes."); |
| 8482 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8483 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8484 | "have different sizes."); |
| 8485 | |
| 8486 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8487 | // checking GetIsGcMarking. |
| 8488 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8489 | __ Bind(slow_path->GetExitLabel()); |
| 8490 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8491 | } else { |
| 8492 | // GC root loaded through a slow path for read barriers other |
| 8493 | // than Baker's. |
| 8494 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8495 | __ AddConstant(root_reg, obj, offset); |
| 8496 | // /* mirror::Object* */ root = root->Read() |
| 8497 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8498 | } |
| 8499 | } else { |
| 8500 | // Plain GC root load with no read barrier. |
| 8501 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8502 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8503 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8504 | // do not have to unpoison `root_reg` here. |
| 8505 | } |
| 8506 | } |
| 8507 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8508 | void CodeGeneratorARM::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8509 | DCHECK(kEmitCompilerReadBarrier); |
| 8510 | DCHECK(kUseBakerReadBarrier); |
| 8511 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8512 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8513 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 8514 | } |
| 8515 | } |
| 8516 | } |
| 8517 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8518 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8519 | Location ref, |
| 8520 | Register obj, |
| 8521 | uint32_t offset, |
| 8522 | Location temp, |
| 8523 | bool needs_null_check) { |
| 8524 | DCHECK(kEmitCompilerReadBarrier); |
| 8525 | DCHECK(kUseBakerReadBarrier); |
| 8526 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8527 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8528 | !Runtime::Current()->UseJitCompilation()) { |
| 8529 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8530 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8531 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8532 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8533 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8534 | // |
| 8535 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8536 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8537 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8538 | // |
| 8539 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8540 | // lr = &gray_return_address; |
| 8541 | // if (temp != nullptr) { |
| 8542 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8543 | // } |
| 8544 | // not_gray_return_address: |
| 8545 | // // Original reference load. If the offset is too large to fit |
| 8546 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8547 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8548 | // gray_return_address: |
| 8549 | |
| 8550 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8551 | Register ref_reg = ref.AsRegister<Register>(); |
| 8552 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8553 | Register base = obj; |
| 8554 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8555 | base = temp.AsRegister<Register>(); |
| 8556 | DCHECK_NE(base, kBakerCcEntrypointRegister); |
| 8557 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8558 | __ AddConstant(base, obj, offset & ~(kReferenceLoadMinFarOffset - 1u)); |
| 8559 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8560 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8561 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8562 | // increase the overall code size when taking the generated thunks into account. |
| 8563 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8564 | } |
| 8565 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8566 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8567 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData(base, obj, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8568 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8569 | |
| 8570 | // entrypoint_reg = |
| 8571 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8572 | DCHECK_EQ(IP, 12); |
| 8573 | const int32_t entry_point_offset = |
| 8574 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8575 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8576 | |
| 8577 | Label return_address; |
| 8578 | __ AdrCode(LR, &return_address); |
| 8579 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8580 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8581 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8582 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8583 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8584 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8585 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset); |
| 8586 | if (needs_null_check) { |
| 8587 | MaybeRecordImplicitNullCheck(instruction); |
| 8588 | } |
| 8589 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8590 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8591 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8592 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8593 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8594 | return; |
| 8595 | } |
| 8596 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8597 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8598 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8599 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8600 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8601 | 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] | 8602 | } |
| 8603 | |
| 8604 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8605 | Location ref, |
| 8606 | Register obj, |
| 8607 | uint32_t data_offset, |
| 8608 | Location index, |
| 8609 | Location temp, |
| 8610 | bool needs_null_check) { |
| 8611 | DCHECK(kEmitCompilerReadBarrier); |
| 8612 | DCHECK(kUseBakerReadBarrier); |
| 8613 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8614 | static_assert( |
| 8615 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8616 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8617 | ScaleFactor scale_factor = TIMES_4; |
| 8618 | |
| 8619 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8620 | !Runtime::Current()->UseJitCompilation()) { |
| 8621 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8622 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8623 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8624 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8625 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8626 | // |
| 8627 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8628 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8629 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8630 | // |
| 8631 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8632 | // lr = &gray_return_address; |
| 8633 | // if (temp != nullptr) { |
| 8634 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8635 | // } |
| 8636 | // not_gray_return_address: |
| 8637 | // // Original reference load. If the offset is too large to fit |
| 8638 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8639 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8640 | // gray_return_address: |
| 8641 | |
| 8642 | DCHECK(index.IsValid()); |
| 8643 | Register index_reg = index.AsRegister<Register>(); |
| 8644 | Register ref_reg = ref.AsRegister<Register>(); |
| 8645 | Register data_reg = temp.AsRegister<Register>(); |
| 8646 | DCHECK_NE(data_reg, kBakerCcEntrypointRegister); |
| 8647 | |
| 8648 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8649 | uint32_t custom_data = |
| 8650 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg); |
| 8651 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8652 | |
| 8653 | // entrypoint_reg = |
| 8654 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8655 | DCHECK_EQ(IP, 12); |
| 8656 | const int32_t entry_point_offset = |
| 8657 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8658 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8659 | __ AddConstant(data_reg, obj, data_offset); |
| 8660 | |
| 8661 | Label return_address; |
| 8662 | __ AdrCode(LR, &return_address); |
| 8663 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8664 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8665 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8666 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8667 | __ ldr(ref_reg, Address(data_reg, index_reg, LSL, scale_factor)); |
| 8668 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8669 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8670 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8671 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8672 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8673 | return; |
| 8674 | } |
| 8675 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8676 | // /* HeapReference<Object> */ ref = |
| 8677 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8678 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8679 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8680 | } |
| 8681 | |
| 8682 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8683 | Location ref, |
| 8684 | Register obj, |
| 8685 | uint32_t offset, |
| 8686 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8687 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8688 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8689 | bool needs_null_check) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8690 | DCHECK(kEmitCompilerReadBarrier); |
| 8691 | DCHECK(kUseBakerReadBarrier); |
| 8692 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8693 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8694 | // whether we need to enter the slow path to mark the reference. |
| 8695 | // Then, in the slow path, check the gray bit in the lock word of |
| 8696 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8697 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8698 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8699 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8700 | // instead, we load into `temp2` the read barrier mark entry point |
| 8701 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8702 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8703 | // |
| 8704 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8705 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8706 | // // Slow path. |
| 8707 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8708 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8709 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8710 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8711 | // if (is_gray) { |
| 8712 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8713 | // } |
| 8714 | // } else { |
| 8715 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8716 | // } |
| 8717 | |
| 8718 | Register temp_reg = temp.AsRegister<Register>(); |
| 8719 | |
| 8720 | // Slow path marking the object `ref` when the GC is marking. The |
| 8721 | // entrypoint will already be loaded in `temp2`. |
| 8722 | Location temp2 = Location::RegisterLocation(LR); |
| 8723 | SlowPathCodeARM* slow_path = |
| 8724 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 8725 | instruction, |
| 8726 | ref, |
| 8727 | obj, |
| 8728 | offset, |
| 8729 | index, |
| 8730 | scale_factor, |
| 8731 | needs_null_check, |
| 8732 | temp_reg, |
| 8733 | /* entrypoint */ temp2); |
| 8734 | AddSlowPath(slow_path); |
| 8735 | |
| 8736 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8737 | const int32_t entry_point_offset = |
| 8738 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8739 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8740 | // threads are suspended or running a checkpoint. |
| 8741 | __ LoadFromOffset(kLoadWord, temp2.AsRegister<Register>(), TR, entry_point_offset); |
| 8742 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8743 | // checking GetIsGcMarking. |
| 8744 | __ CompareAndBranchIfNonZero(temp2.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8745 | // Fast path: the GC is not marking: just load the reference. |
| 8746 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8747 | __ Bind(slow_path->GetExitLabel()); |
| 8748 | } |
| 8749 | |
| 8750 | void CodeGeneratorARM::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8751 | Location ref, |
| 8752 | Register obj, |
| 8753 | Location field_offset, |
| 8754 | Location temp, |
| 8755 | bool needs_null_check, |
| 8756 | Register temp2) { |
| 8757 | DCHECK(kEmitCompilerReadBarrier); |
| 8758 | DCHECK(kUseBakerReadBarrier); |
| 8759 | |
| 8760 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8761 | // whether we need to enter the slow path to update the reference |
| 8762 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8763 | // in the lock word of the reference's holder (`obj`) to decide |
| 8764 | // whether to mark `ref` and update the field or not. |
| 8765 | // |
| 8766 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8767 | // instead, we load into `temp3` the read barrier mark entry point |
| 8768 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8769 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8770 | // |
| 8771 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8772 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8773 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8774 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8775 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8776 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8777 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8778 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8779 | // old_ref = ref; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8780 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8781 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8782 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8783 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8784 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8785 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 8786 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8787 | // Slow path updating the object reference at address `obj + |
| 8788 | // field_offset` when the GC is marking. The entrypoint will already |
| 8789 | // be loaded in `temp3`. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8790 | Location temp3 = Location::RegisterLocation(LR); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8791 | SlowPathCodeARM* slow_path = |
| 8792 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 8793 | instruction, |
| 8794 | ref, |
| 8795 | obj, |
| 8796 | /* offset */ 0u, |
| 8797 | /* index */ field_offset, |
| 8798 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8799 | needs_null_check, |
| 8800 | temp_reg, |
| 8801 | temp2, |
| 8802 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8803 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8804 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8805 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8806 | const int32_t entry_point_offset = |
| 8807 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8808 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8809 | // threads are suspended or running a checkpoint. |
| 8810 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8811 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8812 | // checking GetIsGcMarking. |
| 8813 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8814 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8815 | // up-to-date, and we don't need to load the reference). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8816 | __ Bind(slow_path->GetExitLabel()); |
| 8817 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8818 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8819 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8820 | Location ref, |
| 8821 | Register obj, |
| 8822 | uint32_t offset, |
| 8823 | Location index, |
| 8824 | ScaleFactor scale_factor, |
| 8825 | bool needs_null_check) { |
| 8826 | Register ref_reg = ref.AsRegister<Register>(); |
| 8827 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8828 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8829 | // Load types involving an "index": ArrayGet, |
| 8830 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8831 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8832 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8833 | if (index.IsConstant()) { |
| 8834 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8835 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8836 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8837 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8838 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8839 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8840 | // intrinsics, which use a register pair as index ("long |
| 8841 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8842 | Register index_reg = index.IsRegisterPair() |
| 8843 | ? index.AsRegisterPairLow<Register>() |
| 8844 | : index.AsRegister<Register>(); |
| 8845 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8846 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8847 | } |
| 8848 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8849 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8850 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8851 | } |
| 8852 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8853 | if (needs_null_check) { |
| 8854 | MaybeRecordImplicitNullCheck(instruction); |
| 8855 | } |
| 8856 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8857 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8858 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8859 | } |
| 8860 | |
| 8861 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8862 | Location out, |
| 8863 | Location ref, |
| 8864 | Location obj, |
| 8865 | uint32_t offset, |
| 8866 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8867 | DCHECK(kEmitCompilerReadBarrier); |
| 8868 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8869 | // Insert a slow path based read barrier *after* the reference load. |
| 8870 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8871 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8872 | // reference will be carried out by the runtime within the slow |
| 8873 | // path. |
| 8874 | // |
| 8875 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8876 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8877 | // not used by the artReadBarrierSlow entry point. |
| 8878 | // |
| 8879 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8880 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8881 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8882 | AddSlowPath(slow_path); |
| 8883 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8884 | __ b(slow_path->GetEntryLabel()); |
| 8885 | __ Bind(slow_path->GetExitLabel()); |
| 8886 | } |
| 8887 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8888 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8889 | Location out, |
| 8890 | Location ref, |
| 8891 | Location obj, |
| 8892 | uint32_t offset, |
| 8893 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8894 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8895 | // Baker's read barriers shall be handled by the fast path |
| 8896 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8897 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8898 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8899 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8900 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8901 | } else if (kPoisonHeapReferences) { |
| 8902 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8903 | } |
| 8904 | } |
| 8905 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8906 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8907 | Location out, |
| 8908 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8909 | DCHECK(kEmitCompilerReadBarrier); |
| 8910 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8911 | // Insert a slow path based read barrier *after* the GC root load. |
| 8912 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8913 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8914 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8915 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8916 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8917 | AddSlowPath(slow_path); |
| 8918 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8919 | __ b(slow_path->GetEntryLabel()); |
| 8920 | __ Bind(slow_path->GetExitLabel()); |
| 8921 | } |
| 8922 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8923 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8924 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8925 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8926 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8927 | } |
| 8928 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8929 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8930 | Register temp) { |
| 8931 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8932 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8933 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8934 | return location.AsRegister<Register>(); |
| 8935 | } |
| 8936 | // For intrinsics we allow any location, so it may be on the stack. |
| 8937 | if (!location.IsRegister()) { |
| 8938 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8939 | return temp; |
| 8940 | } |
| 8941 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8942 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8943 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8944 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8945 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8946 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 8947 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8948 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8949 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8950 | return temp; |
| 8951 | } |
| 8952 | return location.AsRegister<Register>(); |
| 8953 | } |
| 8954 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8955 | void CodeGeneratorARM::GenerateStaticOrDirectCall( |
| 8956 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8957 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8958 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8959 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8960 | uint32_t offset = |
| 8961 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8962 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8963 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8964 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8965 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8966 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8967 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8968 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8969 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8970 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8971 | Register temp_reg = temp.AsRegister<Register>(); |
| 8972 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8973 | __ BindTrackedLabel(&labels->movw_label); |
| 8974 | __ movw(temp_reg, /* placeholder */ 0u); |
| 8975 | __ BindTrackedLabel(&labels->movt_label); |
| 8976 | __ movt(temp_reg, /* placeholder */ 0u); |
| 8977 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8978 | __ add(temp_reg, temp_reg, ShifterOperand(PC)); |
| 8979 | break; |
| 8980 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8981 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8982 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8983 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8984 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8985 | HArmDexCacheArraysBase* base = |
| 8986 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8987 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8988 | temp.AsRegister<Register>()); |
| 8989 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8990 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8991 | break; |
| 8992 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8993 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8994 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8995 | return; // No code pointer retrieval; the runtime performs the call directly. |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 8996 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8997 | } |
| 8998 | |
| 8999 | switch (invoke->GetCodePtrLocation()) { |
| 9000 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 9001 | __ bl(GetFrameEntryLabel()); |
| 9002 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9003 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 9004 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 9005 | __ LoadFromOffset( |
| 9006 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 9007 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9008 | // LR() |
| 9009 | __ blx(LR); |
| 9010 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 9011 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9012 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 9013 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 9014 | DCHECK(!IsLeafMethod()); |
| 9015 | } |
| 9016 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9017 | void CodeGeneratorARM::GenerateVirtualCall( |
| 9018 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9019 | Register temp = temp_location.AsRegister<Register>(); |
| 9020 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9021 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 9022 | |
| 9023 | // Use the calling convention instead of the location of the receiver, as |
| 9024 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9025 | // slow path, the arguments have been moved to the right place, so here we are |
| 9026 | // guaranteed that the receiver is the first register of the calling convention. |
| 9027 | InvokeDexCallingConvention calling_convention; |
| 9028 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9029 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 9030 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 9031 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9032 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 9033 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9034 | // emit a read barrier for the previous class reference load. |
| 9035 | // However this is not required in practice, as this is an |
| 9036 | // intermediate/temporary reference and because the current |
| 9037 | // concurrent copying collector keeps the from-space memory |
| 9038 | // intact/accessible until the end of the marking phase (the |
| 9039 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9040 | __ MaybeUnpoisonHeapReference(temp); |
| 9041 | // temp = temp->GetMethodAt(method_offset); |
| 9042 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 9043 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9044 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9045 | // LR = temp->GetEntryPoint(); |
| 9046 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 9047 | // LR(); |
| 9048 | __ blx(LR); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 9049 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9050 | } |
| 9051 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9052 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeMethodPatch( |
| 9053 | MethodReference target_method) { |
| 9054 | return NewPcRelativePatch(*target_method.dex_file, |
| 9055 | target_method.dex_method_index, |
| 9056 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9057 | } |
| 9058 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 9059 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 9060 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9061 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 9062 | } |
| 9063 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9064 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 9065 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9066 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9067 | } |
| 9068 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9069 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 9070 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9071 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9072 | } |
| 9073 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9074 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 9075 | const DexFile& dex_file, uint32_t element_offset) { |
| 9076 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 9077 | } |
| 9078 | |
| 9079 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 9080 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9081 | patches->emplace_back(dex_file, offset_or_index); |
| 9082 | return &patches->back(); |
| 9083 | } |
| 9084 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9085 | Label* CodeGeneratorARM::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9086 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9087 | return &baker_read_barrier_patches_.back().label; |
| 9088 | } |
| 9089 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9090 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9091 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9092 | } |
| 9093 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9094 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9095 | dex::StringIndex string_index, |
| 9096 | Handle<mirror::String> handle) { |
| 9097 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 9098 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9099 | return jit_string_patches_.GetOrCreate( |
| 9100 | StringReference(&dex_file, string_index), |
| 9101 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 9102 | } |
| 9103 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9104 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9105 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9106 | Handle<mirror::Class> handle) { |
| 9107 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 9108 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9109 | return jit_class_patches_.GetOrCreate( |
| 9110 | TypeReference(&dex_file, type_index), |
| 9111 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 9112 | } |
| 9113 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9114 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 9115 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 9116 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 9117 | ArenaVector<LinkerPatch>* linker_patches) { |
| 9118 | for (const PcRelativePatchInfo& info : infos) { |
| 9119 | const DexFile& dex_file = info.target_dex_file; |
| 9120 | size_t offset_or_index = info.offset_or_index; |
| 9121 | DCHECK(info.add_pc_label.IsBound()); |
| 9122 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 9123 | // Add MOVW patch. |
| 9124 | DCHECK(info.movw_label.IsBound()); |
| 9125 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 9126 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9127 | // Add MOVT patch. |
| 9128 | DCHECK(info.movt_label.IsBound()); |
| 9129 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 9130 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9131 | } |
| 9132 | } |
| 9133 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9134 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 9135 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9136 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9137 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9138 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9139 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9140 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9141 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9142 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9143 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9144 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 9145 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9146 | if (GetCompilerOptions().IsBootImage()) { |
| 9147 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9148 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 9149 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 9150 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9151 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 9152 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9153 | } else { |
| 9154 | DCHECK(pc_relative_method_patches_.empty()); |
| 9155 | DCHECK(pc_relative_type_patches_.empty()); |
| 9156 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 9157 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9158 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9159 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 9160 | linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9161 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 9162 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.Position(), |
| 9163 | info.custom_data)); |
| 9164 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9165 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9166 | } |
| 9167 | |
| 9168 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 9169 | return map->GetOrCreate( |
| 9170 | value, |
| 9171 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9172 | } |
| 9173 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 9174 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9175 | LocationSummary* locations = |
| 9176 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 9177 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9178 | Location::RequiresRegister()); |
| 9179 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9180 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9181 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9182 | } |
| 9183 | |
| 9184 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9185 | LocationSummary* locations = instr->GetLocations(); |
| 9186 | Register res = locations->Out().AsRegister<Register>(); |
| 9187 | Register accumulator = |
| 9188 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 9189 | Register mul_left = |
| 9190 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 9191 | Register mul_right = |
| 9192 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 9193 | |
| 9194 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9195 | __ mla(res, mul_left, mul_right, accumulator); |
| 9196 | } else { |
| 9197 | __ mls(res, mul_left, mul_right, accumulator); |
| 9198 | } |
| 9199 | } |
| 9200 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 9201 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9202 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9203 | LOG(FATAL) << "Unreachable"; |
| 9204 | } |
| 9205 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 9206 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9207 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9208 | LOG(FATAL) << "Unreachable"; |
| 9209 | } |
| 9210 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9211 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9212 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9213 | LocationSummary* locations = |
| 9214 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 9215 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9216 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9217 | codegen_->GetAssembler()->IsThumb()) { |
| 9218 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9219 | if (switch_instr->GetStartValue() != 0) { |
| 9220 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9221 | } |
| 9222 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9223 | } |
| 9224 | |
| 9225 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9226 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9227 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9228 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9229 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9230 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9231 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9232 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9233 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9234 | Register temp_reg = IP; |
| 9235 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9236 | // the immediate, because IP is used as the destination register. For the other |
| 9237 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9238 | // and they can be encoded in the instruction without making use of IP register. |
| 9239 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 9240 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9241 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9242 | // Jump to successors[0] if value == lower_bound. |
| 9243 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 9244 | int32_t last_index = 0; |
| 9245 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9246 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 9247 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9248 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 9249 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9250 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 9251 | } |
| 9252 | if (num_entries - last_index == 2) { |
| 9253 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 9254 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9255 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9256 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9257 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9258 | // And the default for any other value. |
| 9259 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9260 | __ b(codegen_->GetLabelOf(default_block)); |
| 9261 | } |
| 9262 | } else { |
| 9263 | // Create a table lookup. |
| 9264 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 9265 | |
| 9266 | // Materialize a pointer to the switch table |
| 9267 | std::vector<Label*> labels(num_entries); |
| 9268 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9269 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9270 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9271 | } |
| 9272 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 9273 | |
| 9274 | // Remove the bias. |
| 9275 | Register key_reg; |
| 9276 | if (lower_bound != 0) { |
| 9277 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 9278 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 9279 | } else { |
| 9280 | key_reg = value_reg; |
| 9281 | } |
| 9282 | |
| 9283 | // Check whether the value is in the table, jump to default block if not. |
| 9284 | __ CmpConstant(key_reg, num_entries - 1); |
| 9285 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 9286 | |
| 9287 | // Load the displacement from the table. |
| 9288 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 9289 | |
| 9290 | // Dispatch is a direct add to the PC (for Thumb2). |
| 9291 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9292 | } |
| 9293 | } |
| 9294 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9295 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 9296 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 9297 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9298 | } |
| 9299 | |
| 9300 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 9301 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9302 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 9303 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9304 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9305 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9306 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9307 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9308 | __ BindTrackedLabel(&labels->add_pc_label); |
| 9309 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 9310 | } |
| 9311 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 9312 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 9313 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 9314 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 9315 | return; |
| 9316 | } |
| 9317 | |
| 9318 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 9319 | |
| 9320 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 9321 | if (return_loc.Equals(trg)) { |
| 9322 | return; |
| 9323 | } |
| 9324 | |
| 9325 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9326 | // with the last branch. |
| 9327 | if (type == Primitive::kPrimLong) { |
| 9328 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9329 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 9330 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 9331 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9332 | } else if (type == Primitive::kPrimDouble) { |
| 9333 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9334 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 9335 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 9336 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9337 | } else { |
| 9338 | // Let the parallel move resolver take care of all of this. |
| 9339 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9340 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9341 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9342 | } |
| 9343 | } |
| 9344 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9345 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9346 | LocationSummary* locations = |
| 9347 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 9348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9349 | locations->SetOut(Location::RequiresRegister()); |
| 9350 | } |
| 9351 | |
| 9352 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9353 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9354 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9355 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9356 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9357 | __ LoadFromOffset(kLoadWord, |
| 9358 | locations->Out().AsRegister<Register>(), |
| 9359 | locations->InAt(0).AsRegister<Register>(), |
| 9360 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9361 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9362 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9363 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9364 | __ LoadFromOffset(kLoadWord, |
| 9365 | locations->Out().AsRegister<Register>(), |
| 9366 | locations->InAt(0).AsRegister<Register>(), |
| 9367 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9368 | __ LoadFromOffset(kLoadWord, |
| 9369 | locations->Out().AsRegister<Register>(), |
| 9370 | locations->Out().AsRegister<Register>(), |
| 9371 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9372 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9373 | } |
| 9374 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9375 | static void PatchJitRootUse(uint8_t* code, |
| 9376 | const uint8_t* roots_data, |
| 9377 | Literal* literal, |
| 9378 | uint64_t index_in_table) { |
| 9379 | DCHECK(literal->GetLabel()->IsBound()); |
| 9380 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 9381 | uintptr_t address = |
| 9382 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9383 | uint8_t* data = code + literal_offset; |
| 9384 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9385 | } |
| 9386 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9387 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9388 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9389 | const StringReference& string_reference = entry.first; |
| 9390 | Literal* table_entry_literal = entry.second; |
| 9391 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9392 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9393 | uint64_t index_in_table = it->second; |
| 9394 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9395 | } |
| 9396 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9397 | const TypeReference& type_reference = entry.first; |
| 9398 | Literal* table_entry_literal = entry.second; |
| 9399 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9400 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9401 | uint64_t index_in_table = it->second; |
| 9402 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9403 | } |
| 9404 | } |
| 9405 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9406 | #undef __ |
| 9407 | #undef QUICK_ENTRY_POINT |
| 9408 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9409 | } // namespace arm |
| 9410 | } // namespace art |