Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 19 | #include "arch/arm/asm_support_arm.h" |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 20 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 23 | #include "common_arm.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 24 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_arm.h" |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 29 | #include "linker/arm/relative_patcher_thumb2.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 32 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "utils/arm/assembler_arm.h" |
| 34 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 39 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 40 | template<class MirrorType> |
| 41 | class GcRoot; |
| 42 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 43 | namespace arm { |
| 44 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 45 | static bool ExpectedPairLayout(Location location) { |
| 46 | // We expected this for both core and fpu register pairs. |
| 47 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 48 | } |
| 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 51 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 53 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 55 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 56 | static constexpr SRegister kFpuCalleeSaves[] = |
| 57 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 58 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 59 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 60 | // S registers. Therefore there is no need to block it. |
| 61 | static constexpr DRegister DTMP = D31; |
| 62 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 63 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 64 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 65 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 66 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 67 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 68 | // the offset explicitly. |
| 69 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 70 | |
| 71 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 72 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 73 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 74 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 75 | |
| 76 | // The reserved entrypoint register for link-time generated thunks. |
| 77 | const Register kBakerCcEntrypointRegister = R4; |
| 78 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 79 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 80 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 81 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 83 | static inline void CheckLastTempIsBakerCcEntrypointRegister(HInstruction* instruction) { |
| 84 | DCHECK_EQ(static_cast<uint32_t>(kBakerCcEntrypointRegister), |
| 85 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 86 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 87 | DCHECK_EQ(kBakerCcEntrypointRegister, |
| 88 | instruction->GetLocations()->GetTemp( |
| 89 | instruction->GetLocations()->GetTempCount() - 1u).AsRegister<Register>()); |
| 90 | } |
| 91 | |
| 92 | static inline void EmitPlaceholderBne(CodeGeneratorARM* codegen, Label* bne_label) { |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 93 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(codegen->GetAssembler())); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 94 | __ BindTrackedLabel(bne_label); |
| 95 | Label placeholder_label; |
| 96 | __ b(&placeholder_label, NE); // Placeholder, patched at link-time. |
| 97 | __ Bind(&placeholder_label); |
| 98 | } |
| 99 | |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 100 | static inline bool CanEmitNarrowLdr(Register rt, Register rn, uint32_t offset) { |
| 101 | return ArmAssembler::IsLowRegister(rt) && ArmAssembler::IsLowRegister(rn) && offset < 32u; |
| 102 | } |
| 103 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 104 | static constexpr int kRegListThreshold = 4; |
| 105 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 106 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 107 | // for each live D registers they treat two corresponding S registers as live ones. |
| 108 | // |
| 109 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 110 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 111 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 112 | // - decreasing code size |
| 113 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 114 | // restored and then used in regular non SlowPath code as D register. |
| 115 | // |
| 116 | // For the following example (v means the S register is live): |
| 117 | // D names: | D0 | D1 | D2 | D4 | ... |
| 118 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 119 | // Live? | | v | v | v | v | v | v | | ... |
| 120 | // |
| 121 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 122 | // as D registers. |
| 123 | static size_t SaveContiguousSRegisterList(size_t first, |
| 124 | size_t last, |
| 125 | CodeGenerator* codegen, |
| 126 | size_t stack_offset) { |
| 127 | DCHECK_LE(first, last); |
| 128 | if ((first == last) && (first == 0)) { |
| 129 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 130 | return stack_offset; |
| 131 | } |
| 132 | if (first % 2 == 1) { |
| 133 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 134 | } |
| 135 | |
| 136 | bool save_last = false; |
| 137 | if (last % 2 == 0) { |
| 138 | save_last = true; |
| 139 | --last; |
| 140 | } |
| 141 | |
| 142 | if (first < last) { |
| 143 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 144 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 145 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 146 | |
| 147 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 148 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 149 | } else if (number_of_d_regs > 1) { |
| 150 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 151 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 152 | } |
| 153 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 154 | } |
| 155 | |
| 156 | if (save_last) { |
| 157 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 158 | } |
| 159 | |
| 160 | return stack_offset; |
| 161 | } |
| 162 | |
| 163 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 164 | size_t last, |
| 165 | CodeGenerator* codegen, |
| 166 | size_t stack_offset) { |
| 167 | DCHECK_LE(first, last); |
| 168 | if ((first == last) && (first == 0)) { |
| 169 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 170 | return stack_offset; |
| 171 | } |
| 172 | if (first % 2 == 1) { |
| 173 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 174 | } |
| 175 | |
| 176 | bool restore_last = false; |
| 177 | if (last % 2 == 0) { |
| 178 | restore_last = true; |
| 179 | --last; |
| 180 | } |
| 181 | |
| 182 | if (first < last) { |
| 183 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 184 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 185 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 186 | if (number_of_d_regs == 1) { |
| 187 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 188 | } else if (number_of_d_regs > 1) { |
| 189 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 190 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 191 | } |
| 192 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 193 | } |
| 194 | |
| 195 | if (restore_last) { |
| 196 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 197 | } |
| 198 | |
| 199 | return stack_offset; |
| 200 | } |
| 201 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 202 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 203 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 204 | size_t orig_offset = stack_offset; |
| 205 | |
| 206 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 207 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 208 | // If the register holds an object, update the stack mask. |
| 209 | if (locations->RegisterContainsObject(i)) { |
| 210 | locations->SetStackBit(stack_offset / kVRegSize); |
| 211 | } |
| 212 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 213 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 214 | saved_core_stack_offsets_[i] = stack_offset; |
| 215 | stack_offset += kArmWordSize; |
| 216 | } |
| 217 | |
| 218 | int reg_num = POPCOUNT(core_spills); |
| 219 | if (reg_num != 0) { |
| 220 | if (reg_num > kRegListThreshold) { |
| 221 | __ StoreList(RegList(core_spills), orig_offset); |
| 222 | } else { |
| 223 | stack_offset = orig_offset; |
| 224 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 225 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 230 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 231 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 232 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 233 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 234 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 235 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 236 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 237 | |
| 238 | stack_offset = orig_offset; |
| 239 | while (fp_spills != 0u) { |
| 240 | uint32_t begin = CTZ(fp_spills); |
| 241 | uint32_t tmp = fp_spills + (1u << begin); |
| 242 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 243 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 244 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 245 | } |
| 246 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 250 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 251 | size_t orig_offset = stack_offset; |
| 252 | |
| 253 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 254 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 255 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 256 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 257 | stack_offset += kArmWordSize; |
| 258 | } |
| 259 | |
| 260 | int reg_num = POPCOUNT(core_spills); |
| 261 | if (reg_num != 0) { |
| 262 | if (reg_num > kRegListThreshold) { |
| 263 | __ LoadList(RegList(core_spills), orig_offset); |
| 264 | } else { |
| 265 | stack_offset = orig_offset; |
| 266 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 267 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 272 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 273 | while (fp_spills != 0u) { |
| 274 | uint32_t begin = CTZ(fp_spills); |
| 275 | uint32_t tmp = fp_spills + (1u << begin); |
| 276 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 277 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 278 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 279 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 280 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 285 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 286 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 289 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 290 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 291 | // Live registers will be restored in the catch block if caught. |
| 292 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 293 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 294 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 295 | instruction_, |
| 296 | instruction_->GetDexPc(), |
| 297 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 298 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 301 | bool IsFatal() const OVERRIDE { return true; } |
| 302 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 303 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 304 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 305 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 306 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 307 | }; |
| 308 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 309 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 310 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 311 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 312 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 314 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 315 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 316 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 317 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 320 | bool IsFatal() const OVERRIDE { return true; } |
| 321 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 322 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 323 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 324 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 329 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 330 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 335 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 336 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 338 | if (successor_ == nullptr) { |
| 339 | __ b(GetReturnLabel()); |
| 340 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 341 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 342 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 345 | Label* GetReturnLabel() { |
| 346 | DCHECK(successor_ == nullptr); |
| 347 | return &return_label_; |
| 348 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 349 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 350 | HBasicBlock* GetSuccessor() const { |
| 351 | return successor_; |
| 352 | } |
| 353 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 354 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 355 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 356 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 357 | // If not null, the block to branch to after the suspend check. |
| 358 | HBasicBlock* const successor_; |
| 359 | |
| 360 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 361 | Label return_label_; |
| 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 364 | }; |
| 365 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 366 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 367 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 368 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 369 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 370 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 372 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 373 | LocationSummary* locations = instruction_->GetLocations(); |
| 374 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 376 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 377 | // Live registers will be restored in the catch block if caught. |
| 378 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 379 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 380 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 381 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 382 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 383 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 384 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 385 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 386 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 387 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 388 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 389 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 390 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 391 | ? kQuickThrowStringBounds |
| 392 | : kQuickThrowArrayBounds; |
| 393 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 395 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 398 | bool IsFatal() const OVERRIDE { return true; } |
| 399 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 400 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 401 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 402 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 403 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 404 | }; |
| 405 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 406 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 407 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 408 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 409 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 410 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 411 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 412 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 413 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 414 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 415 | Location out = locations->Out(); |
| 416 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 417 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 418 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 419 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 420 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 421 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 422 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 423 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 424 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 425 | bool is_load_class_bss_entry = |
| 426 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 427 | Register entry_address = kNoRegister; |
| 428 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 429 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 430 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 431 | // the kSaveEverything call. |
| 432 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 433 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 434 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 435 | if (temp_is_r0) { |
| 436 | __ mov(entry_address, ShifterOperand(temp)); |
| 437 | } |
| 438 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 439 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 440 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 441 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 442 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 443 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | if (do_clinit_) { |
| 445 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 446 | } else { |
| 447 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 448 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 449 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 450 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 451 | if (is_load_class_bss_entry) { |
| 452 | if (call_saves_everything_except_r0) { |
| 453 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 454 | __ str(R0, Address(entry_address)); |
| 455 | } else { |
| 456 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 457 | Register temp = IP; |
| 458 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 459 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 460 | __ BindTrackedLabel(&labels->movw_label); |
| 461 | __ movw(temp, /* placeholder */ 0u); |
| 462 | __ BindTrackedLabel(&labels->movt_label); |
| 463 | __ movt(temp, /* placeholder */ 0u); |
| 464 | __ BindTrackedLabel(&labels->add_pc_label); |
| 465 | __ add(temp, temp, ShifterOperand(PC)); |
| 466 | __ str(R0, Address(temp)); |
| 467 | } |
| 468 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 469 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 470 | if (out.IsValid()) { |
| 471 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 472 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 473 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 474 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 475 | __ b(GetExitLabel()); |
| 476 | } |
| 477 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 478 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 479 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 480 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 481 | // The class this slow path will load. |
| 482 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 483 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 484 | // The dex PC of `at_`. |
| 485 | const uint32_t dex_pc_; |
| 486 | |
| 487 | // Whether to initialize the class. |
| 488 | const bool do_clinit_; |
| 489 | |
| 490 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 491 | }; |
| 492 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 493 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 494 | public: |
| 495 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 496 | |
| 497 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 498 | DCHECK(instruction_->IsLoadString()); |
| 499 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 500 | LocationSummary* locations = instruction_->GetLocations(); |
| 501 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 502 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 503 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 504 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 505 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 506 | |
| 507 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 508 | __ Bind(GetEntryLabel()); |
| 509 | SaveLiveRegisters(codegen, locations); |
| 510 | |
| 511 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 512 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 513 | // the kSaveEverything call. |
| 514 | Register entry_address = kNoRegister; |
| 515 | if (call_saves_everything_except_r0) { |
| 516 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 517 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 518 | entry_address = temp_is_r0 ? out : temp; |
| 519 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 520 | if (temp_is_r0) { |
| 521 | __ mov(entry_address, ShifterOperand(temp)); |
| 522 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 525 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 526 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 527 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 528 | |
| 529 | // Store the resolved String to the .bss entry. |
| 530 | if (call_saves_everything_except_r0) { |
| 531 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 532 | __ str(R0, Address(entry_address)); |
| 533 | } else { |
| 534 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 535 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 536 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 537 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 538 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 539 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 540 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 541 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 542 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 543 | __ add(temp, temp, ShifterOperand(PC)); |
| 544 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 547 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 548 | RestoreLiveRegisters(codegen, locations); |
| 549 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 550 | __ b(GetExitLabel()); |
| 551 | } |
| 552 | |
| 553 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 554 | |
| 555 | private: |
| 556 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 557 | }; |
| 558 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 559 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 560 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 561 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 562 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 563 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 564 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 565 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 566 | DCHECK(instruction_->IsCheckCast() |
| 567 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 568 | |
| 569 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 570 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 571 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 572 | if (!is_fatal_) { |
| 573 | SaveLiveRegisters(codegen, locations); |
| 574 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 575 | |
| 576 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 577 | // move resolver. |
| 578 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 579 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 580 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 581 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 582 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 583 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 584 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 585 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 586 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 587 | instruction_, |
| 588 | instruction_->GetDexPc(), |
| 589 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 590 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 591 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 592 | } else { |
| 593 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 594 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 595 | instruction_, |
| 596 | instruction_->GetDexPc(), |
| 597 | this); |
| 598 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 599 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 600 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 601 | if (!is_fatal_) { |
| 602 | RestoreLiveRegisters(codegen, locations); |
| 603 | __ b(GetExitLabel()); |
| 604 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 607 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 608 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 609 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 610 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 611 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 612 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 613 | |
| 614 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 615 | }; |
| 616 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 617 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 618 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 619 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 620 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 621 | |
| 622 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 623 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 624 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 625 | LocationSummary* locations = instruction_->GetLocations(); |
| 626 | SaveLiveRegisters(codegen, locations); |
| 627 | InvokeRuntimeCallingConvention calling_convention; |
| 628 | __ LoadImmediate(calling_convention.GetRegisterAt(0), |
| 629 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 630 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 631 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 634 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 635 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 636 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 637 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 638 | }; |
| 639 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 640 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 641 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 642 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 643 | |
| 644 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 645 | LocationSummary* locations = instruction_->GetLocations(); |
| 646 | __ Bind(GetEntryLabel()); |
| 647 | SaveLiveRegisters(codegen, locations); |
| 648 | |
| 649 | InvokeRuntimeCallingConvention calling_convention; |
| 650 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 651 | parallel_move.AddMove( |
| 652 | locations->InAt(0), |
| 653 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 654 | Primitive::kPrimNot, |
| 655 | nullptr); |
| 656 | parallel_move.AddMove( |
| 657 | locations->InAt(1), |
| 658 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 659 | Primitive::kPrimInt, |
| 660 | nullptr); |
| 661 | parallel_move.AddMove( |
| 662 | locations->InAt(2), |
| 663 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 664 | Primitive::kPrimNot, |
| 665 | nullptr); |
| 666 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 667 | |
| 668 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 669 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 670 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 671 | RestoreLiveRegisters(codegen, locations); |
| 672 | __ b(GetExitLabel()); |
| 673 | } |
| 674 | |
| 675 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 676 | |
| 677 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 678 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 679 | }; |
| 680 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 681 | // Abstract base class for read barrier slow paths marking a reference |
| 682 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 683 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | // Argument `entrypoint` must be a register location holding the read |
| 685 | // barrier marking runtime entry point to be invoked. |
| 686 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 687 | protected: |
| 688 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 689 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 690 | DCHECK(kEmitCompilerReadBarrier); |
| 691 | } |
| 692 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 693 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 694 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 695 | // Generate assembly code calling the read barrier marking runtime |
| 696 | // entry point (ReadBarrierMarkRegX). |
| 697 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 698 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 699 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 700 | // No need to save live registers; it's taken care of by the |
| 701 | // entrypoint. Also, there is no need to update the stack mask, |
| 702 | // as this runtime call will not trigger a garbage collection. |
| 703 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 704 | DCHECK_NE(ref_reg, SP); |
| 705 | DCHECK_NE(ref_reg, LR); |
| 706 | DCHECK_NE(ref_reg, PC); |
| 707 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 708 | // as a temporary, it cannot be the entry point's input/output. |
| 709 | DCHECK_NE(ref_reg, IP); |
| 710 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 711 | // "Compact" slow path, saving two moves. |
| 712 | // |
| 713 | // Instead of using the standard runtime calling convention (input |
| 714 | // and output in R0): |
| 715 | // |
| 716 | // R0 <- ref |
| 717 | // R0 <- ReadBarrierMark(R0) |
| 718 | // ref <- R0 |
| 719 | // |
| 720 | // we just use rX (the register containing `ref`) as input and output |
| 721 | // of a dedicated entrypoint: |
| 722 | // |
| 723 | // rX <- ReadBarrierMarkRegX(rX) |
| 724 | // |
| 725 | if (entrypoint_.IsValid()) { |
| 726 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 727 | __ blx(entrypoint_.AsRegister<Register>()); |
| 728 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 729 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 730 | int32_t entry_point_offset = |
| 731 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 732 | // This runtime call does not require a stack map. |
| 733 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 734 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // The location (register) of the marked object reference. |
| 738 | const Location ref_; |
| 739 | |
| 740 | // The location of the entrypoint if it is already loaded. |
| 741 | const Location entrypoint_; |
| 742 | |
| 743 | private: |
| 744 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 745 | }; |
| 746 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 747 | // Slow path marking an object reference `ref` during a read |
| 748 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 749 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 750 | // |
| 751 | // This means that after the execution of this slow path, `ref` will |
| 752 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 753 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 754 | // probably still be a from-space reference (unless it gets updated by |
| 755 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 756 | // reference (different from `ref`) in `obj.field`). |
| 757 | // |
| 758 | // If `entrypoint` is a valid location it is assumed to already be |
| 759 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 760 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 761 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 762 | public: |
| 763 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 764 | Location ref, |
| 765 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 766 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 767 | DCHECK(kEmitCompilerReadBarrier); |
| 768 | } |
| 769 | |
| 770 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 771 | |
| 772 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 773 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 774 | DCHECK(locations->CanCall()); |
| 775 | if (kIsDebugBuild) { |
| 776 | Register ref_reg = ref_.AsRegister<Register>(); |
| 777 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 778 | } |
| 779 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 780 | << "Unexpected instruction in read barrier marking slow path: " |
| 781 | << instruction_->DebugName(); |
| 782 | |
| 783 | __ Bind(GetEntryLabel()); |
| 784 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 785 | __ b(GetExitLabel()); |
| 786 | } |
| 787 | |
| 788 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 789 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 790 | }; |
| 791 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 792 | // Slow path loading `obj`'s lock word, loading a reference from |
| 793 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 794 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 795 | // read barrier). The field `obj.field` in the object `obj` holding |
| 796 | // this reference does not get updated by this slow path after marking |
| 797 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 798 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 799 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 800 | // This means that after the execution of this slow path, `ref` will |
| 801 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 802 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 803 | // probably still be a from-space reference (unless it gets updated by |
| 804 | // another thread, or if another thread installed another object |
| 805 | // reference (different from `ref`) in `obj.field`). |
| 806 | // |
| 807 | // Argument `entrypoint` must be a register location holding the read |
| 808 | // barrier marking runtime entry point to be invoked. |
| 809 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 810 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 811 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 812 | Location ref, |
| 813 | Register obj, |
| 814 | uint32_t offset, |
| 815 | Location index, |
| 816 | ScaleFactor scale_factor, |
| 817 | bool needs_null_check, |
| 818 | Register temp, |
| 819 | Location entrypoint) |
| 820 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 821 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 822 | offset_(offset), |
| 823 | index_(index), |
| 824 | scale_factor_(scale_factor), |
| 825 | needs_null_check_(needs_null_check), |
| 826 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 827 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 828 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 831 | const char* GetDescription() const OVERRIDE { |
| 832 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 833 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 834 | |
| 835 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 836 | LocationSummary* locations = instruction_->GetLocations(); |
| 837 | Register ref_reg = ref_.AsRegister<Register>(); |
| 838 | DCHECK(locations->CanCall()); |
| 839 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 840 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 842 | instruction_->IsStaticFieldGet() || |
| 843 | instruction_->IsArrayGet() || |
| 844 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 845 | instruction_->IsInstanceOf() || |
| 846 | instruction_->IsCheckCast() || |
| 847 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 848 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 849 | << "Unexpected instruction in read barrier marking slow path: " |
| 850 | << instruction_->DebugName(); |
| 851 | // The read barrier instrumentation of object ArrayGet |
| 852 | // instructions does not support the HIntermediateAddress |
| 853 | // instruction. |
| 854 | DCHECK(!(instruction_->IsArrayGet() && |
| 855 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 856 | |
| 857 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 858 | |
| 859 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 860 | // inserted after the original load. However, in fast path based |
| 861 | // Baker's read barriers, we need to perform the load of |
| 862 | // mirror::Object::monitor_ *before* the original reference load. |
| 863 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 864 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 865 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 866 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 867 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 868 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 869 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 870 | // if (is_gray) { |
| 871 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 872 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 873 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 874 | // Note: the original implementation in ReadBarrier::Barrier is |
| 875 | // slightly more complex as it performs additional checks that we do |
| 876 | // not do here for performance reasons. |
| 877 | |
| 878 | // /* int32_t */ monitor = obj->monitor_ |
| 879 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 880 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 881 | if (needs_null_check_) { |
| 882 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 883 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 884 | // /* LockWord */ lock_word = LockWord(monitor) |
| 885 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 886 | "art::LockWord and int32_t have different sizes."); |
| 887 | |
| 888 | // Introduce a dependency on the lock_word including the rb_state, |
| 889 | // which shall prevent load-load reordering without using |
| 890 | // a memory barrier (which would be more expensive). |
| 891 | // `obj` is unchanged by this operation, but its value now depends |
| 892 | // on `temp`. |
| 893 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 894 | |
| 895 | // The actual reference load. |
| 896 | // A possible implicit null check has already been handled above. |
| 897 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 898 | arm_codegen->GenerateRawReferenceLoad( |
| 899 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 900 | |
| 901 | // Mark the object `ref` when `obj` is gray. |
| 902 | // |
| 903 | // if (rb_state == ReadBarrier::GrayState()) |
| 904 | // ref = ReadBarrier::Mark(ref); |
| 905 | // |
| 906 | // Given the numeric representation, it's enough to check the low bit of the |
| 907 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 908 | // which can be a 16-bit instruction unlike the TST immediate. |
| 909 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 910 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 911 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 912 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 913 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 914 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 915 | __ b(GetExitLabel()); |
| 916 | } |
| 917 | |
| 918 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 919 | // The register containing the object holding the marked object reference field. |
| 920 | Register obj_; |
| 921 | // The offset, index and scale factor to access the reference in `obj_`. |
| 922 | uint32_t offset_; |
| 923 | Location index_; |
| 924 | ScaleFactor scale_factor_; |
| 925 | // Is a null check required? |
| 926 | bool needs_null_check_; |
| 927 | // A temporary register used to hold the lock word of `obj_`. |
| 928 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 929 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 930 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 931 | }; |
| 932 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 933 | // Slow path loading `obj`'s lock word, loading a reference from |
| 934 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 935 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 936 | // read barrier). If needed, this slow path also atomically updates |
| 937 | // the field `obj.field` in the object `obj` holding this reference |
| 938 | // after marking (contrary to |
| 939 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 940 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 941 | // |
| 942 | // This means that after the execution of this slow path, both `ref` |
| 943 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 944 | // hold the same to-space reference (unless another thread installed |
| 945 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 946 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 947 | // Argument `entrypoint` must be a register location holding the read |
| 948 | // barrier marking runtime entry point to be invoked. |
| 949 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 950 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 951 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 952 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 953 | Location ref, |
| 954 | Register obj, |
| 955 | uint32_t offset, |
| 956 | Location index, |
| 957 | ScaleFactor scale_factor, |
| 958 | bool needs_null_check, |
| 959 | Register temp1, |
| 960 | Register temp2, |
| 961 | Location entrypoint) |
| 962 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 963 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 964 | offset_(offset), |
| 965 | index_(index), |
| 966 | scale_factor_(scale_factor), |
| 967 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 968 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 969 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 970 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 971 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | const char* GetDescription() const OVERRIDE { |
| 975 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 976 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 977 | |
| 978 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 979 | LocationSummary* locations = instruction_->GetLocations(); |
| 980 | Register ref_reg = ref_.AsRegister<Register>(); |
| 981 | DCHECK(locations->CanCall()); |
| 982 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 983 | DCHECK_NE(ref_reg, temp1_); |
| 984 | |
| 985 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 986 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 987 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 988 | << instruction_->DebugName(); |
| 989 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 990 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 991 | DCHECK_EQ(offset_, 0u); |
| 992 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 993 | // The location of the offset of the marked reference field within `obj_`. |
| 994 | Location field_offset = index_; |
| 995 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 996 | |
| 997 | __ Bind(GetEntryLabel()); |
| 998 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 999 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM's: |
| 1000 | // |
| 1001 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 1002 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 1003 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 1004 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 1005 | // if (is_gray) { |
| 1006 | // old_ref = ref; |
| 1007 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 1008 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1009 | // } |
| 1010 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1011 | // /* int32_t */ monitor = obj->monitor_ |
| 1012 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1013 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1014 | if (needs_null_check_) { |
| 1015 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1016 | } |
| 1017 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1018 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1019 | "art::LockWord and int32_t have different sizes."); |
| 1020 | |
| 1021 | // Introduce a dependency on the lock_word including the rb_state, |
| 1022 | // which shall prevent load-load reordering without using |
| 1023 | // a memory barrier (which would be more expensive). |
| 1024 | // `obj` is unchanged by this operation, but its value now depends |
| 1025 | // on `temp1`. |
| 1026 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 1027 | |
| 1028 | // The actual reference load. |
| 1029 | // A possible implicit null check has already been handled above. |
| 1030 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1031 | arm_codegen->GenerateRawReferenceLoad( |
| 1032 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1033 | |
| 1034 | // Mark the object `ref` when `obj` is gray. |
| 1035 | // |
| 1036 | // if (rb_state == ReadBarrier::GrayState()) |
| 1037 | // ref = ReadBarrier::Mark(ref); |
| 1038 | // |
| 1039 | // Given the numeric representation, it's enough to check the low bit of the |
| 1040 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1041 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1042 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1043 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1044 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1045 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 1046 | |
| 1047 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1048 | // Note that we cannot use IP to save the old reference, as IP is |
| 1049 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1050 | // need the old reference after the call to that entry point. |
| 1051 | DCHECK_NE(temp1_, IP); |
| 1052 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1053 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1054 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1055 | |
| 1056 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1057 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1058 | // |
| 1059 | // Note that this field could also hold a different object, if |
| 1060 | // another thread had concurrently changed it. In that case, the |
| 1061 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1062 | // (CAS) operation below would abort the CAS, leaving the field |
| 1063 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1064 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1065 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1066 | |
| 1067 | // Update the the holder's field atomically. This may fail if |
| 1068 | // mutator updates before us, but it's OK. This is achieved |
| 1069 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1070 | // memory synchronization ordering, where the expected value is |
| 1071 | // the old reference and the desired value is the new reference. |
| 1072 | |
| 1073 | // Convenience aliases. |
| 1074 | Register base = obj_; |
| 1075 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1076 | // offset ("long offset"), of which only the low part contains |
| 1077 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1078 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1079 | Register expected = temp1_; |
| 1080 | Register value = ref_reg; |
| 1081 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1082 | Register tmp = temp2_; // Value in memory. |
| 1083 | |
| 1084 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1085 | |
| 1086 | if (kPoisonHeapReferences) { |
| 1087 | __ PoisonHeapReference(expected); |
| 1088 | if (value == expected) { |
| 1089 | // Do not poison `value`, as it is the same register as |
| 1090 | // `expected`, which has just been poisoned. |
| 1091 | } else { |
| 1092 | __ PoisonHeapReference(value); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | // do { |
| 1097 | // tmp = [r_ptr] - expected; |
| 1098 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1099 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1100 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1101 | __ Bind(&loop_head); |
| 1102 | |
| 1103 | __ ldrex(tmp, tmp_ptr); |
| 1104 | |
| 1105 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1106 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1107 | __ it(NE); |
| 1108 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1109 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1110 | __ b(&exit_loop, NE); |
| 1111 | |
| 1112 | __ strex(tmp, value, tmp_ptr); |
| 1113 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1114 | __ b(&loop_head, EQ); |
| 1115 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1116 | __ Bind(&exit_loop); |
| 1117 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1118 | if (kPoisonHeapReferences) { |
| 1119 | __ UnpoisonHeapReference(expected); |
| 1120 | if (value == expected) { |
| 1121 | // Do not unpoison `value`, as it is the same register as |
| 1122 | // `expected`, which has just been unpoisoned. |
| 1123 | } else { |
| 1124 | __ UnpoisonHeapReference(value); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1128 | __ b(GetExitLabel()); |
| 1129 | } |
| 1130 | |
| 1131 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1132 | // The register containing the object holding the marked object reference field. |
| 1133 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1134 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1135 | uint32_t offset_; |
| 1136 | Location index_; |
| 1137 | ScaleFactor scale_factor_; |
| 1138 | // Is a null check required? |
| 1139 | bool needs_null_check_; |
| 1140 | // A temporary register used to hold the lock word of `obj_`; and |
| 1141 | // also to hold the original reference value, when the reference is |
| 1142 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1143 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1144 | // A temporary register used in the implementation of the CAS, to |
| 1145 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1146 | const Register temp2_; |
| 1147 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1148 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1149 | }; |
| 1150 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1151 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1152 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1153 | public: |
| 1154 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1155 | Location out, |
| 1156 | Location ref, |
| 1157 | Location obj, |
| 1158 | uint32_t offset, |
| 1159 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1160 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1161 | out_(out), |
| 1162 | ref_(ref), |
| 1163 | obj_(obj), |
| 1164 | offset_(offset), |
| 1165 | index_(index) { |
| 1166 | DCHECK(kEmitCompilerReadBarrier); |
| 1167 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1168 | // has been overwritten by (or after) the heap object reference load |
| 1169 | // to be instrumented, e.g.: |
| 1170 | // |
| 1171 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1172 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1173 | // |
| 1174 | // In that case, we have lost the information about the original |
| 1175 | // object, and the emitted read barrier cannot work properly. |
| 1176 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1177 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1178 | } |
| 1179 | |
| 1180 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1181 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1182 | LocationSummary* locations = instruction_->GetLocations(); |
| 1183 | Register reg_out = out_.AsRegister<Register>(); |
| 1184 | DCHECK(locations->CanCall()); |
| 1185 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1186 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1187 | instruction_->IsStaticFieldGet() || |
| 1188 | instruction_->IsArrayGet() || |
| 1189 | instruction_->IsInstanceOf() || |
| 1190 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1191 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1192 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1193 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1194 | // The read barrier instrumentation of object ArrayGet |
| 1195 | // instructions does not support the HIntermediateAddress |
| 1196 | // instruction. |
| 1197 | DCHECK(!(instruction_->IsArrayGet() && |
| 1198 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1199 | |
| 1200 | __ Bind(GetEntryLabel()); |
| 1201 | SaveLiveRegisters(codegen, locations); |
| 1202 | |
| 1203 | // We may have to change the index's value, but as `index_` is a |
| 1204 | // constant member (like other "inputs" of this slow path), |
| 1205 | // introduce a copy of it, `index`. |
| 1206 | Location index = index_; |
| 1207 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1208 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1209 | if (instruction_->IsArrayGet()) { |
| 1210 | // Compute the actual memory offset and store it in `index`. |
| 1211 | Register index_reg = index_.AsRegister<Register>(); |
| 1212 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1213 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1214 | // We are about to change the value of `index_reg` (see the |
| 1215 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1216 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1217 | // not been saved by the previous call to |
| 1218 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1219 | // callee-save register -- |
| 1220 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1221 | // callee-save registers, as it has been designed with the |
| 1222 | // assumption that callee-save registers are supposed to be |
| 1223 | // handled by the called function. So, as a callee-save |
| 1224 | // register, `index_reg` _would_ eventually be saved onto |
| 1225 | // the stack, but it would be too late: we would have |
| 1226 | // changed its value earlier. Therefore, we manually save |
| 1227 | // it here into another freely available register, |
| 1228 | // `free_reg`, chosen of course among the caller-save |
| 1229 | // registers (as a callee-save `free_reg` register would |
| 1230 | // exhibit the same problem). |
| 1231 | // |
| 1232 | // Note we could have requested a temporary register from |
| 1233 | // the register allocator instead; but we prefer not to, as |
| 1234 | // this is a slow path, and we know we can find a |
| 1235 | // caller-save register that is available. |
| 1236 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1237 | __ Mov(free_reg, index_reg); |
| 1238 | index_reg = free_reg; |
| 1239 | index = Location::RegisterLocation(index_reg); |
| 1240 | } else { |
| 1241 | // The initial register stored in `index_` has already been |
| 1242 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1243 | // (as it is not a callee-save register), so we can freely |
| 1244 | // use it. |
| 1245 | } |
| 1246 | // Shifting the index value contained in `index_reg` by the scale |
| 1247 | // factor (2) cannot overflow in practice, as the runtime is |
| 1248 | // unable to allocate object arrays with a size larger than |
| 1249 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1250 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1251 | static_assert( |
| 1252 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1253 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1254 | __ AddConstant(index_reg, index_reg, offset_); |
| 1255 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1256 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1257 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1258 | // (as in the case of ArrayGet), as it is actually an offset |
| 1259 | // to an object field within an object. |
| 1260 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1261 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1262 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1263 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1264 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1265 | DCHECK_EQ(offset_, 0U); |
| 1266 | DCHECK(index_.IsRegisterPair()); |
| 1267 | // UnsafeGet's offset location is a register pair, the low |
| 1268 | // part contains the correct offset. |
| 1269 | index = index_.ToLow(); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | // We're moving two or three locations to locations that could |
| 1274 | // overlap, so we need a parallel move resolver. |
| 1275 | InvokeRuntimeCallingConvention calling_convention; |
| 1276 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1277 | parallel_move.AddMove(ref_, |
| 1278 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1279 | Primitive::kPrimNot, |
| 1280 | nullptr); |
| 1281 | parallel_move.AddMove(obj_, |
| 1282 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1283 | Primitive::kPrimNot, |
| 1284 | nullptr); |
| 1285 | if (index.IsValid()) { |
| 1286 | parallel_move.AddMove(index, |
| 1287 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1288 | Primitive::kPrimInt, |
| 1289 | nullptr); |
| 1290 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1291 | } else { |
| 1292 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1293 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1294 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1295 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1296 | CheckEntrypointTypes< |
| 1297 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1298 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1299 | |
| 1300 | RestoreLiveRegisters(codegen, locations); |
| 1301 | __ b(GetExitLabel()); |
| 1302 | } |
| 1303 | |
| 1304 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1305 | |
| 1306 | private: |
| 1307 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1308 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1309 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1310 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1311 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1312 | return static_cast<Register>(i); |
| 1313 | } |
| 1314 | } |
| 1315 | // We shall never fail to find a free caller-save register, as |
| 1316 | // there are more than two core caller-save registers on ARM |
| 1317 | // (meaning it is possible to find one which is different from |
| 1318 | // `ref` and `obj`). |
| 1319 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1320 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1321 | UNREACHABLE(); |
| 1322 | } |
| 1323 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1324 | const Location out_; |
| 1325 | const Location ref_; |
| 1326 | const Location obj_; |
| 1327 | const uint32_t offset_; |
| 1328 | // An additional location containing an index to an array. |
| 1329 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1330 | // UnsafeGetObjectVolatile intrinsics. |
| 1331 | const Location index_; |
| 1332 | |
| 1333 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1334 | }; |
| 1335 | |
| 1336 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1337 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1338 | public: |
| 1339 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1340 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1341 | DCHECK(kEmitCompilerReadBarrier); |
| 1342 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1343 | |
| 1344 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1345 | LocationSummary* locations = instruction_->GetLocations(); |
| 1346 | Register reg_out = out_.AsRegister<Register>(); |
| 1347 | DCHECK(locations->CanCall()); |
| 1348 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1349 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1350 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1351 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1352 | |
| 1353 | __ Bind(GetEntryLabel()); |
| 1354 | SaveLiveRegisters(codegen, locations); |
| 1355 | |
| 1356 | InvokeRuntimeCallingConvention calling_convention; |
| 1357 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1358 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1359 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1360 | instruction_, |
| 1361 | instruction_->GetDexPc(), |
| 1362 | this); |
| 1363 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1364 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1365 | |
| 1366 | RestoreLiveRegisters(codegen, locations); |
| 1367 | __ b(GetExitLabel()); |
| 1368 | } |
| 1369 | |
| 1370 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1371 | |
| 1372 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1373 | const Location out_; |
| 1374 | const Location root_; |
| 1375 | |
| 1376 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1377 | }; |
| 1378 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1379 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1380 | switch (cond) { |
| 1381 | case kCondEQ: return EQ; |
| 1382 | case kCondNE: return NE; |
| 1383 | case kCondLT: return LT; |
| 1384 | case kCondLE: return LE; |
| 1385 | case kCondGT: return GT; |
| 1386 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1387 | case kCondB: return LO; |
| 1388 | case kCondBE: return LS; |
| 1389 | case kCondA: return HI; |
| 1390 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1391 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1392 | LOG(FATAL) << "Unreachable"; |
| 1393 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1396 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1397 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1398 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1399 | case kCondEQ: return EQ; |
| 1400 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1401 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1402 | case kCondLT: return LO; |
| 1403 | case kCondLE: return LS; |
| 1404 | case kCondGT: return HI; |
| 1405 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1406 | // Unsigned remain unchanged. |
| 1407 | case kCondB: return LO; |
| 1408 | case kCondBE: return LS; |
| 1409 | case kCondA: return HI; |
| 1410 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1411 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | LOG(FATAL) << "Unreachable"; |
| 1413 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1416 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1417 | // The ARM condition codes can express all the necessary branches, see the |
| 1418 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1419 | // There is no dex instruction or HIR that would need the missing conditions |
| 1420 | // "equal or unordered" or "not equal". |
| 1421 | switch (cond) { |
| 1422 | case kCondEQ: return EQ; |
| 1423 | case kCondNE: return NE /* unordered */; |
| 1424 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1425 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1426 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1427 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1428 | default: |
| 1429 | LOG(FATAL) << "UNREACHABLE"; |
| 1430 | UNREACHABLE(); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1434 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1435 | switch (op_kind) { |
| 1436 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1437 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1438 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1439 | default: |
| 1440 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1441 | UNREACHABLE(); |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1446 | Register out, |
| 1447 | Register first, |
| 1448 | const ShifterOperand& second, |
| 1449 | CodeGeneratorARM* codegen) { |
| 1450 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1451 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1452 | ? ShifterOperand(0) |
| 1453 | : ShifterOperand(first); |
| 1454 | |
| 1455 | __ mov(out, in); |
| 1456 | } else { |
| 1457 | switch (kind) { |
| 1458 | case HInstruction::kAdd: |
| 1459 | __ add(out, first, second); |
| 1460 | break; |
| 1461 | case HInstruction::kAnd: |
| 1462 | __ and_(out, first, second); |
| 1463 | break; |
| 1464 | case HInstruction::kOr: |
| 1465 | __ orr(out, first, second); |
| 1466 | break; |
| 1467 | case HInstruction::kSub: |
| 1468 | __ sub(out, first, second); |
| 1469 | break; |
| 1470 | case HInstruction::kXor: |
| 1471 | __ eor(out, first, second); |
| 1472 | break; |
| 1473 | default: |
| 1474 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1475 | UNREACHABLE(); |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1481 | const Location& out, |
| 1482 | const Location& first, |
| 1483 | const ShifterOperand& second_lo, |
| 1484 | const ShifterOperand& second_hi, |
| 1485 | CodeGeneratorARM* codegen) { |
| 1486 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1487 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1488 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1489 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1490 | |
| 1491 | if (kind == HInstruction::kAdd) { |
| 1492 | __ adds(out_lo, first_lo, second_lo); |
| 1493 | __ adc(out_hi, first_hi, second_hi); |
| 1494 | } else if (kind == HInstruction::kSub) { |
| 1495 | __ subs(out_lo, first_lo, second_lo); |
| 1496 | __ sbc(out_hi, first_hi, second_hi); |
| 1497 | } else { |
| 1498 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1499 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1504 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1505 | } |
| 1506 | |
| 1507 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1508 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1509 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1510 | |
| 1511 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1512 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1513 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1514 | const Location first = locations->InAt(0); |
| 1515 | const Location second = locations->InAt(1); |
| 1516 | const Location out = locations->Out(); |
| 1517 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1518 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1519 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1520 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1521 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1522 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1523 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1524 | |
| 1525 | if (shift_value >= 32) { |
| 1526 | if (shift == LSL) { |
| 1527 | GenerateDataProcInstruction(kind, |
| 1528 | out_hi, |
| 1529 | first_hi, |
| 1530 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1531 | codegen); |
| 1532 | GenerateDataProcInstruction(kind, |
| 1533 | out_lo, |
| 1534 | first_lo, |
| 1535 | ShifterOperand(0), |
| 1536 | codegen); |
| 1537 | } else if (shift == ASR) { |
| 1538 | GenerateDataProc(kind, |
| 1539 | out, |
| 1540 | first, |
| 1541 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1542 | ShifterOperand(second_hi, ASR, 31), |
| 1543 | codegen); |
| 1544 | } else { |
| 1545 | DCHECK_EQ(shift, LSR); |
| 1546 | GenerateDataProc(kind, |
| 1547 | out, |
| 1548 | first, |
| 1549 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1550 | ShifterOperand(0), |
| 1551 | codegen); |
| 1552 | } |
| 1553 | } else { |
| 1554 | DCHECK_GT(shift_value, 1U); |
| 1555 | DCHECK_LT(shift_value, 32U); |
| 1556 | |
| 1557 | if (shift == LSL) { |
| 1558 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1559 | // Location::kOutputOverlap; not applicable to other cases. |
| 1560 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1561 | GenerateDataProcInstruction(kind, |
| 1562 | out_hi, |
| 1563 | first_hi, |
| 1564 | ShifterOperand(second_hi, LSL, shift_value), |
| 1565 | codegen); |
| 1566 | GenerateDataProcInstruction(kind, |
| 1567 | out_hi, |
| 1568 | out_hi, |
| 1569 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1570 | codegen); |
| 1571 | GenerateDataProcInstruction(kind, |
| 1572 | out_lo, |
| 1573 | first_lo, |
| 1574 | ShifterOperand(second_lo, LSL, shift_value), |
| 1575 | codegen); |
| 1576 | } else { |
| 1577 | __ Lsl(IP, second_hi, shift_value); |
| 1578 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1579 | GenerateDataProc(kind, |
| 1580 | out, |
| 1581 | first, |
| 1582 | ShifterOperand(second_lo, LSL, shift_value), |
| 1583 | ShifterOperand(IP), |
| 1584 | codegen); |
| 1585 | } |
| 1586 | } else { |
| 1587 | DCHECK(shift == ASR || shift == LSR); |
| 1588 | |
| 1589 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1590 | // Location::kOutputOverlap; not applicable to other cases. |
| 1591 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1592 | GenerateDataProcInstruction(kind, |
| 1593 | out_lo, |
| 1594 | first_lo, |
| 1595 | ShifterOperand(second_lo, LSR, shift_value), |
| 1596 | codegen); |
| 1597 | GenerateDataProcInstruction(kind, |
| 1598 | out_lo, |
| 1599 | out_lo, |
| 1600 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1601 | codegen); |
| 1602 | GenerateDataProcInstruction(kind, |
| 1603 | out_hi, |
| 1604 | first_hi, |
| 1605 | ShifterOperand(second_hi, shift, shift_value), |
| 1606 | codegen); |
| 1607 | } else { |
| 1608 | __ Lsr(IP, second_lo, shift_value); |
| 1609 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1610 | GenerateDataProc(kind, |
| 1611 | out, |
| 1612 | first, |
| 1613 | ShifterOperand(IP), |
| 1614 | ShifterOperand(second_hi, shift, shift_value), |
| 1615 | codegen); |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1621 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1622 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1623 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1624 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1625 | if (rhs_loc.IsConstant()) { |
| 1626 | // 0.0 is the only immediate that can be encoded directly in |
| 1627 | // a VCMP instruction. |
| 1628 | // |
| 1629 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1630 | // specify that in a floating-point comparison, positive zero |
| 1631 | // and negative zero are considered equal, so we can use the |
| 1632 | // literal 0.0 for both cases here. |
| 1633 | // |
| 1634 | // Note however that some methods (Float.equal, Float.compare, |
| 1635 | // Float.compareTo, Double.equal, Double.compare, |
| 1636 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1637 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1638 | // -0.0. So if we ever translate calls to these methods into a |
| 1639 | // HCompare instruction, we must handle the -0.0 case with |
| 1640 | // care here. |
| 1641 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1642 | if (type == Primitive::kPrimFloat) { |
| 1643 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1644 | } else { |
| 1645 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1646 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1647 | } |
| 1648 | } else { |
| 1649 | if (type == Primitive::kPrimFloat) { |
| 1650 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1651 | } else { |
| 1652 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1653 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1654 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1659 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1660 | IfCondition* condition, |
| 1661 | IfCondition* opposite) { |
| 1662 | if (value == 1) { |
| 1663 | if (*condition == kCondB) { |
| 1664 | value = 0; |
| 1665 | *condition = kCondEQ; |
| 1666 | *opposite = kCondNE; |
| 1667 | } else if (*condition == kCondAE) { |
| 1668 | value = 0; |
| 1669 | *condition = kCondNE; |
| 1670 | *opposite = kCondEQ; |
| 1671 | } |
| 1672 | } else if (value == -1) { |
| 1673 | if (*condition == kCondGT) { |
| 1674 | value = 0; |
| 1675 | *condition = kCondGE; |
| 1676 | *opposite = kCondLT; |
| 1677 | } else if (*condition == kCondLE) { |
| 1678 | value = 0; |
| 1679 | *condition = kCondLT; |
| 1680 | *opposite = kCondGE; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | return value; |
| 1685 | } |
| 1686 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1687 | static std::pair<Condition, Condition> GenerateLongTestConstant(HCondition* condition, |
| 1688 | bool invert, |
| 1689 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1690 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1691 | |
| 1692 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1693 | IfCondition cond = condition->GetCondition(); |
| 1694 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1695 | |
| 1696 | if (invert) { |
| 1697 | std::swap(cond, opposite); |
| 1698 | } |
| 1699 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1700 | std::pair<Condition, Condition> ret(EQ, NE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1701 | const Location left = locations->InAt(0); |
| 1702 | const Location right = locations->InAt(1); |
| 1703 | |
| 1704 | DCHECK(right.IsConstant()); |
| 1705 | |
| 1706 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1707 | const Register left_low = left.AsRegisterPairLow<Register>(); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1708 | int64_t value = AdjustConstantForCondition(right.GetConstant()->AsLongConstant()->GetValue(), |
| 1709 | &cond, |
| 1710 | &opposite); |
| 1711 | |
| 1712 | // Comparisons against 0 are common enough to deserve special attention. |
| 1713 | if (value == 0) { |
| 1714 | switch (cond) { |
| 1715 | case kCondNE: |
| 1716 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1717 | case kCondA: |
| 1718 | ret = std::make_pair(NE, EQ); |
| 1719 | FALLTHROUGH_INTENDED; |
| 1720 | case kCondEQ: |
| 1721 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1722 | case kCondBE: |
| 1723 | __ orrs(IP, left_low, ShifterOperand(left_high)); |
| 1724 | return ret; |
| 1725 | case kCondLT: |
| 1726 | case kCondGE: |
| 1727 | __ cmp(left_high, ShifterOperand(0)); |
| 1728 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1729 | // Trivially true or false. |
| 1730 | case kCondB: |
| 1731 | ret = std::make_pair(NE, EQ); |
| 1732 | FALLTHROUGH_INTENDED; |
| 1733 | case kCondAE: |
| 1734 | __ cmp(left_low, ShifterOperand(left_low)); |
| 1735 | return ret; |
| 1736 | default: |
| 1737 | break; |
| 1738 | } |
| 1739 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1740 | |
| 1741 | switch (cond) { |
| 1742 | case kCondEQ: |
| 1743 | case kCondNE: |
| 1744 | case kCondB: |
| 1745 | case kCondBE: |
| 1746 | case kCondA: |
| 1747 | case kCondAE: |
| 1748 | __ CmpConstant(left_high, High32Bits(value)); |
| 1749 | __ it(EQ); |
| 1750 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1751 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1752 | break; |
| 1753 | case kCondLE: |
| 1754 | case kCondGT: |
| 1755 | // Trivially true or false. |
| 1756 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1757 | __ cmp(left_low, ShifterOperand(left_low)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1758 | 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] | 1759 | break; |
| 1760 | } |
| 1761 | |
| 1762 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1763 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1764 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1765 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1766 | } else { |
| 1767 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1768 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1769 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1770 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | value++; |
| 1774 | FALLTHROUGH_INTENDED; |
| 1775 | case kCondGE: |
| 1776 | case kCondLT: |
| 1777 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1778 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1779 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1780 | break; |
| 1781 | default: |
| 1782 | LOG(FATAL) << "Unreachable"; |
| 1783 | UNREACHABLE(); |
| 1784 | } |
| 1785 | |
| 1786 | return ret; |
| 1787 | } |
| 1788 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1789 | static std::pair<Condition, Condition> GenerateLongTest(HCondition* condition, |
| 1790 | bool invert, |
| 1791 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1792 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1793 | |
| 1794 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1795 | IfCondition cond = condition->GetCondition(); |
| 1796 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1797 | |
| 1798 | if (invert) { |
| 1799 | std::swap(cond, opposite); |
| 1800 | } |
| 1801 | |
| 1802 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1803 | Location left = locations->InAt(0); |
| 1804 | Location right = locations->InAt(1); |
| 1805 | |
| 1806 | DCHECK(right.IsRegisterPair()); |
| 1807 | |
| 1808 | switch (cond) { |
| 1809 | case kCondEQ: |
| 1810 | case kCondNE: |
| 1811 | case kCondB: |
| 1812 | case kCondBE: |
| 1813 | case kCondA: |
| 1814 | case kCondAE: |
| 1815 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1816 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1817 | __ it(EQ); |
| 1818 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1819 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1820 | EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1821 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1822 | break; |
| 1823 | case kCondLE: |
| 1824 | case kCondGT: |
| 1825 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1826 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1827 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1828 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1829 | } else { |
| 1830 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1831 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1833 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | std::swap(left, right); |
| 1837 | FALLTHROUGH_INTENDED; |
| 1838 | case kCondGE: |
| 1839 | case kCondLT: |
| 1840 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1841 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1842 | __ sbcs(IP, |
| 1843 | left.AsRegisterPairHigh<Register>(), |
| 1844 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1845 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1846 | break; |
| 1847 | default: |
| 1848 | LOG(FATAL) << "Unreachable"; |
| 1849 | UNREACHABLE(); |
| 1850 | } |
| 1851 | |
| 1852 | return ret; |
| 1853 | } |
| 1854 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1855 | static std::pair<Condition, Condition> GenerateTest(HCondition* condition, |
| 1856 | bool invert, |
| 1857 | CodeGeneratorARM* codegen) { |
| 1858 | const LocationSummary* const locations = condition->GetLocations(); |
| 1859 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1860 | IfCondition cond = condition->GetCondition(); |
| 1861 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1862 | std::pair<Condition, Condition> ret; |
| 1863 | const Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1864 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1865 | if (invert) { |
| 1866 | std::swap(cond, opposite); |
| 1867 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1868 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1869 | if (type == Primitive::kPrimLong) { |
| 1870 | ret = locations->InAt(1).IsConstant() |
| 1871 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1872 | : GenerateLongTest(condition, invert, codegen); |
| 1873 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1874 | GenerateVcmp(condition, codegen); |
| 1875 | __ vmstat(); |
| 1876 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1877 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1878 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1879 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1880 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1881 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1882 | |
| 1883 | if (right.IsRegister()) { |
| 1884 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1885 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1886 | DCHECK(right.IsConstant()); |
| 1887 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1888 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1889 | |
| 1890 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | return ret; |
| 1894 | } |
| 1895 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1896 | static bool CanGenerateTest(HCondition* condition, ArmAssembler* assembler) { |
| 1897 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1898 | const LocationSummary* const locations = condition->GetLocations(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1899 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1900 | if (locations->InAt(1).IsConstant()) { |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1901 | IfCondition c = condition->GetCondition(); |
| 1902 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1903 | const int64_t value = AdjustConstantForCondition( |
| 1904 | Int64FromConstant(locations->InAt(1).GetConstant()), |
| 1905 | &c, |
| 1906 | &opposite); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1907 | ShifterOperand so; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1908 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1909 | if (c < kCondLT || c > kCondGE) { |
| 1910 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1911 | // we check that the least significant half of the first input to be compared |
| 1912 | // is in a low register (the other half is read outside an IT block), and |
| 1913 | // 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] | 1914 | // encoding can be used; 0 is always handled, no matter what registers are |
| 1915 | // used by the first input. |
| 1916 | if (value != 0 && |
| 1917 | (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1918 | !IsUint<8>(Low32Bits(value)))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1921 | } else if (c == kCondLE || c == kCondGT) { |
| 1922 | if (value < std::numeric_limits<int64_t>::max() && |
| 1923 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1924 | kNoRegister, |
| 1925 | SBC, |
| 1926 | High32Bits(value + 1), |
| 1927 | kCcSet, |
| 1928 | &so)) { |
| 1929 | return false; |
| 1930 | } |
| 1931 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1932 | kNoRegister, |
| 1933 | SBC, |
| 1934 | High32Bits(value), |
| 1935 | kCcSet, |
| 1936 | &so)) { |
| 1937 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | return true; |
| 1943 | } |
| 1944 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1945 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARM* codegen) { |
| 1946 | DCHECK(CanGenerateTest(cond, codegen->GetAssembler())); |
| 1947 | |
| 1948 | const Register out = cond->GetLocations()->Out().AsRegister<Register>(); |
| 1949 | const auto condition = GenerateTest(cond, false, codegen); |
| 1950 | |
| 1951 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 1952 | |
| 1953 | if (ArmAssembler::IsLowRegister(out)) { |
| 1954 | __ it(condition.first); |
| 1955 | __ mov(out, ShifterOperand(1), condition.first); |
| 1956 | } else { |
| 1957 | Label done_label; |
| 1958 | Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1959 | |
| 1960 | __ b(final_label, condition.second); |
| 1961 | __ LoadImmediate(out, 1); |
| 1962 | |
| 1963 | if (done_label.IsLinked()) { |
| 1964 | __ Bind(&done_label); |
| 1965 | } |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARM* codegen) { |
| 1970 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1971 | |
| 1972 | const LocationSummary* const locations = cond->GetLocations(); |
| 1973 | IfCondition condition = cond->GetCondition(); |
| 1974 | const Register out = locations->Out().AsRegister<Register>(); |
| 1975 | const Location left = locations->InAt(0); |
| 1976 | const Location right = locations->InAt(1); |
| 1977 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1978 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1979 | |
| 1980 | if (right.IsConstant()) { |
| 1981 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1982 | const int64_t value = AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 1983 | &condition, |
| 1984 | &opposite); |
| 1985 | int32_t value_high = -High32Bits(value); |
| 1986 | int32_t value_low = -Low32Bits(value); |
| 1987 | |
| 1988 | // The output uses Location::kNoOutputOverlap. |
| 1989 | if (out == left_high) { |
| 1990 | std::swap(left_low, left_high); |
| 1991 | std::swap(value_low, value_high); |
| 1992 | } |
| 1993 | |
| 1994 | __ AddConstant(out, left_low, value_low); |
| 1995 | __ AddConstant(IP, left_high, value_high); |
| 1996 | } else { |
| 1997 | DCHECK(right.IsRegisterPair()); |
| 1998 | __ sub(IP, left_high, ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1999 | __ sub(out, left_low, ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 2000 | } |
| 2001 | |
| 2002 | // Need to check after calling AdjustConstantForCondition(). |
| 2003 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 2004 | |
| 2005 | if (condition == kCondNE && ArmAssembler::IsLowRegister(out)) { |
| 2006 | __ orrs(out, out, ShifterOperand(IP)); |
| 2007 | __ it(NE); |
| 2008 | __ mov(out, ShifterOperand(1), NE); |
| 2009 | } else { |
| 2010 | __ orr(out, out, ShifterOperand(IP)); |
| 2011 | codegen->GenerateConditionWithZero(condition, out, out, IP); |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | static void GenerateLongComparesAndJumps(HCondition* cond, |
| 2016 | Label* true_label, |
| 2017 | Label* false_label, |
| 2018 | CodeGeneratorARM* codegen) { |
| 2019 | LocationSummary* locations = cond->GetLocations(); |
| 2020 | Location left = locations->InAt(0); |
| 2021 | Location right = locations->InAt(1); |
| 2022 | IfCondition if_cond = cond->GetCondition(); |
| 2023 | |
| 2024 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2025 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2026 | IfCondition true_high_cond = if_cond; |
| 2027 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
| 2028 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
| 2029 | |
| 2030 | // Set the conditions for the test, remembering that == needs to be |
| 2031 | // decided using the low words. |
| 2032 | switch (if_cond) { |
| 2033 | case kCondEQ: |
| 2034 | case kCondNE: |
| 2035 | // Nothing to do. |
| 2036 | break; |
| 2037 | case kCondLT: |
| 2038 | false_high_cond = kCondGT; |
| 2039 | break; |
| 2040 | case kCondLE: |
| 2041 | true_high_cond = kCondLT; |
| 2042 | break; |
| 2043 | case kCondGT: |
| 2044 | false_high_cond = kCondLT; |
| 2045 | break; |
| 2046 | case kCondGE: |
| 2047 | true_high_cond = kCondGT; |
| 2048 | break; |
| 2049 | case kCondB: |
| 2050 | false_high_cond = kCondA; |
| 2051 | break; |
| 2052 | case kCondBE: |
| 2053 | true_high_cond = kCondB; |
| 2054 | break; |
| 2055 | case kCondA: |
| 2056 | false_high_cond = kCondB; |
| 2057 | break; |
| 2058 | case kCondAE: |
| 2059 | true_high_cond = kCondA; |
| 2060 | break; |
| 2061 | } |
| 2062 | if (right.IsConstant()) { |
| 2063 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2064 | int32_t val_low = Low32Bits(value); |
| 2065 | int32_t val_high = High32Bits(value); |
| 2066 | |
| 2067 | __ CmpConstant(left_high, val_high); |
| 2068 | if (if_cond == kCondNE) { |
| 2069 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2070 | } else if (if_cond == kCondEQ) { |
| 2071 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2072 | } else { |
| 2073 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2074 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2075 | } |
| 2076 | // Must be equal high, so compare the lows. |
| 2077 | __ CmpConstant(left_low, val_low); |
| 2078 | } else { |
| 2079 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2080 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2081 | |
| 2082 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2083 | if (if_cond == kCondNE) { |
| 2084 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2085 | } else if (if_cond == kCondEQ) { |
| 2086 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2087 | } else { |
| 2088 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2089 | __ b(false_label, ARMCondition(false_high_cond)); |
| 2090 | } |
| 2091 | // Must be equal high, so compare the lows. |
| 2092 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2093 | } |
| 2094 | // The last comparison might be unsigned. |
| 2095 | // TODO: optimize cases where this is always true/false |
| 2096 | __ b(true_label, final_condition); |
| 2097 | } |
| 2098 | |
| 2099 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARM* codegen) { |
| 2100 | DCHECK_EQ(cond->GetLeft()->GetType(), Primitive::kPrimLong); |
| 2101 | |
| 2102 | const LocationSummary* const locations = cond->GetLocations(); |
| 2103 | IfCondition condition = cond->GetCondition(); |
| 2104 | const Register out = locations->Out().AsRegister<Register>(); |
| 2105 | const Location left = locations->InAt(0); |
| 2106 | const Location right = locations->InAt(1); |
| 2107 | |
| 2108 | if (right.IsConstant()) { |
| 2109 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2110 | |
| 2111 | // Comparisons against 0 are common enough to deserve special attention. |
| 2112 | if (AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 2113 | &condition, |
| 2114 | &opposite) == 0) { |
| 2115 | switch (condition) { |
| 2116 | case kCondNE: |
| 2117 | case kCondA: |
| 2118 | if (ArmAssembler::IsLowRegister(out)) { |
| 2119 | // We only care if both input registers are 0 or not. |
| 2120 | __ orrs(out, |
| 2121 | left.AsRegisterPairLow<Register>(), |
| 2122 | ShifterOperand(left.AsRegisterPairHigh<Register>())); |
| 2123 | __ it(NE); |
| 2124 | __ mov(out, ShifterOperand(1), NE); |
| 2125 | return; |
| 2126 | } |
| 2127 | |
| 2128 | FALLTHROUGH_INTENDED; |
| 2129 | case kCondEQ: |
| 2130 | case kCondBE: |
| 2131 | // We only care if both input registers are 0 or not. |
| 2132 | __ orr(out, |
| 2133 | left.AsRegisterPairLow<Register>(), |
| 2134 | ShifterOperand(left.AsRegisterPairHigh<Register>())); |
| 2135 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2136 | return; |
| 2137 | case kCondLT: |
| 2138 | case kCondGE: |
| 2139 | // We only care about the sign bit. |
| 2140 | FALLTHROUGH_INTENDED; |
| 2141 | case kCondAE: |
| 2142 | case kCondB: |
| 2143 | codegen->GenerateConditionWithZero(condition, out, left.AsRegisterPairHigh<Register>()); |
| 2144 | return; |
| 2145 | case kCondLE: |
| 2146 | case kCondGT: |
| 2147 | default: |
| 2148 | break; |
| 2149 | } |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | if ((condition == kCondEQ || condition == kCondNE) && |
| 2154 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 2155 | // function generates a shorter code sequence that is still branchless. |
| 2156 | (!ArmAssembler::IsLowRegister(out) || !CanGenerateTest(cond, codegen->GetAssembler()))) { |
| 2157 | GenerateEqualLong(cond, codegen); |
| 2158 | return; |
| 2159 | } |
| 2160 | |
| 2161 | if (CanGenerateTest(cond, codegen->GetAssembler())) { |
| 2162 | GenerateConditionGeneric(cond, codegen); |
| 2163 | return; |
| 2164 | } |
| 2165 | |
| 2166 | // Convert the jumps into the result. |
| 2167 | Label done_label; |
| 2168 | Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 2169 | Label true_label, false_label; |
| 2170 | |
| 2171 | GenerateLongComparesAndJumps(cond, &true_label, &false_label, codegen); |
| 2172 | |
| 2173 | // False case: result = 0. |
| 2174 | __ Bind(&false_label); |
| 2175 | __ mov(out, ShifterOperand(0)); |
| 2176 | __ b(final_label); |
| 2177 | |
| 2178 | // True case: result = 1. |
| 2179 | __ Bind(&true_label); |
| 2180 | __ mov(out, ShifterOperand(1)); |
| 2181 | |
| 2182 | if (done_label.IsLinked()) { |
| 2183 | __ Bind(&done_label); |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, CodeGeneratorARM* codegen) { |
| 2188 | const Primitive::Type type = cond->GetLeft()->GetType(); |
| 2189 | |
| 2190 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2191 | |
| 2192 | if (type == Primitive::kPrimLong) { |
| 2193 | GenerateConditionLong(cond, codegen); |
| 2194 | return; |
| 2195 | } |
| 2196 | |
| 2197 | const LocationSummary* const locations = cond->GetLocations(); |
| 2198 | IfCondition condition = cond->GetCondition(); |
| 2199 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 2200 | const Register out = locations->Out().AsRegister<Register>(); |
| 2201 | const Location right = cond->GetLocations()->InAt(1); |
| 2202 | int64_t value; |
| 2203 | |
| 2204 | if (right.IsConstant()) { |
| 2205 | IfCondition opposite = cond->GetOppositeCondition(); |
| 2206 | |
| 2207 | value = AdjustConstantForCondition(Int64FromConstant(right.GetConstant()), |
| 2208 | &condition, |
| 2209 | &opposite); |
| 2210 | |
| 2211 | // Comparisons against 0 are common enough to deserve special attention. |
| 2212 | if (value == 0) { |
| 2213 | switch (condition) { |
| 2214 | case kCondNE: |
| 2215 | case kCondA: |
| 2216 | if (ArmAssembler::IsLowRegister(out) && out == in) { |
| 2217 | __ cmp(out, ShifterOperand(0)); |
| 2218 | __ it(NE); |
| 2219 | __ mov(out, ShifterOperand(1), NE); |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | FALLTHROUGH_INTENDED; |
| 2224 | case kCondEQ: |
| 2225 | case kCondBE: |
| 2226 | case kCondLT: |
| 2227 | case kCondGE: |
| 2228 | case kCondAE: |
| 2229 | case kCondB: |
| 2230 | codegen->GenerateConditionWithZero(condition, out, in); |
| 2231 | return; |
| 2232 | case kCondLE: |
| 2233 | case kCondGT: |
| 2234 | default: |
| 2235 | break; |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | if (condition == kCondEQ || condition == kCondNE) { |
| 2241 | ShifterOperand operand; |
| 2242 | |
| 2243 | if (right.IsConstant()) { |
| 2244 | operand = ShifterOperand(value); |
| 2245 | } else if (out == right.AsRegister<Register>()) { |
| 2246 | // Avoid 32-bit instructions if possible. |
| 2247 | operand = ShifterOperand(in); |
| 2248 | in = right.AsRegister<Register>(); |
| 2249 | } else { |
| 2250 | operand = ShifterOperand(right.AsRegister<Register>()); |
| 2251 | } |
| 2252 | |
| 2253 | if (condition == kCondNE && ArmAssembler::IsLowRegister(out)) { |
| 2254 | __ subs(out, in, operand); |
| 2255 | __ it(NE); |
| 2256 | __ mov(out, ShifterOperand(1), NE); |
| 2257 | } else { |
| 2258 | __ sub(out, in, operand); |
| 2259 | codegen->GenerateConditionWithZero(condition, out, out); |
| 2260 | } |
| 2261 | |
| 2262 | return; |
| 2263 | } |
| 2264 | |
| 2265 | GenerateConditionGeneric(cond, codegen); |
| 2266 | } |
| 2267 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2268 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 2269 | const Primitive::Type type = constant->GetType(); |
| 2270 | bool ret = false; |
| 2271 | |
| 2272 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 2273 | |
| 2274 | if (type == Primitive::kPrimLong) { |
| 2275 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 2276 | |
| 2277 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 2278 | } else { |
| 2279 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 2280 | } |
| 2281 | |
| 2282 | return ret; |
| 2283 | } |
| 2284 | |
| 2285 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 2286 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 2287 | |
| 2288 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 2289 | return Location::ConstantLocation(constant->AsConstant()); |
| 2290 | } |
| 2291 | |
| 2292 | return Location::RequiresRegister(); |
| 2293 | } |
| 2294 | |
| 2295 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 2296 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 2297 | // we check that we are not dealing with floating-point output (there is no |
| 2298 | // 16-bit VMOV encoding). |
| 2299 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 2300 | return false; |
| 2301 | } |
| 2302 | |
| 2303 | // For constants, we also check that the output is in one or two low registers, |
| 2304 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 2305 | // MOV encoding can be used. |
| 2306 | if (src.IsConstant()) { |
| 2307 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 2308 | return false; |
| 2309 | } |
| 2310 | |
| 2311 | if (out.IsRegister()) { |
| 2312 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 2313 | return false; |
| 2314 | } |
| 2315 | } else { |
| 2316 | DCHECK(out.IsRegisterPair()); |
| 2317 | |
| 2318 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 2319 | return false; |
| 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | return true; |
| 2325 | } |
| 2326 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 2327 | #undef __ |
| 2328 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 2329 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 2330 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2331 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 2332 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2333 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2334 | |
| 2335 | const HBasicBlock* const block = instruction->GetBlock(); |
| 2336 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 2337 | HInstruction* const next = instruction->GetNext(); |
| 2338 | |
| 2339 | // Avoid a branch to a branch. |
| 2340 | if (next->IsGoto() && (info == nullptr || |
| 2341 | !info->IsBackEdge(*block) || |
| 2342 | !info->HasSuspendCheck())) { |
| 2343 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 2344 | } |
| 2345 | |
| 2346 | return final_label; |
| 2347 | } |
| 2348 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2349 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 2350 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 2354 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2357 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 2358 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 2359 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 2360 | } |
| 2361 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2362 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 2363 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 2364 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 2365 | } |
| 2366 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 2367 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 2368 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 2369 | return kArmWordSize; |
| 2370 | } |
| 2371 | |
| 2372 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 2373 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 2374 | return kArmWordSize; |
| 2375 | } |
| 2376 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 2377 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2378 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 2379 | const CompilerOptions& compiler_options, |
| 2380 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2381 | : CodeGenerator(graph, |
| 2382 | kNumberOfCoreRegisters, |
| 2383 | kNumberOfSRegisters, |
| 2384 | kNumberOfRegisterPairs, |
| 2385 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 2386 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 2387 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 2388 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 2389 | compiler_options, |
| 2390 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 2391 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2392 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2393 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 2394 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 2395 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 2396 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2397 | uint32_literals_(std::less<uint32_t>(), |
| 2398 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2399 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2400 | pc_relative_method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 2401 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2402 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2403 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2404 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 2405 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 2406 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2407 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2408 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2409 | // Always save the LR register to mimic Quick. |
| 2410 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 2411 | } |
| 2412 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2413 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 2414 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 2415 | __ FinalizeCode(); |
| 2416 | |
| 2417 | // Adjust native pc offsets in stack maps. |
| 2418 | 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] | 2419 | uint32_t old_position = |
| 2420 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2421 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 2422 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 2423 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 2424 | // Adjust pc offsets for the disassembly information. |
| 2425 | if (disasm_info_ != nullptr) { |
| 2426 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 2427 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 2428 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 2429 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 2430 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 2431 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 2432 | } |
| 2433 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 2434 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 2435 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 2436 | } |
| 2437 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2438 | |
| 2439 | CodeGenerator::Finalize(allocator); |
| 2440 | } |
| 2441 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2442 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2443 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2444 | blocked_core_registers_[SP] = true; |
| 2445 | blocked_core_registers_[LR] = true; |
| 2446 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2447 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2448 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2449 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2450 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2451 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2452 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2453 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2454 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2455 | // Stubs do not save callee-save floating point registers. If the graph |
| 2456 | // is debuggable, we need to deal with these registers differently. For |
| 2457 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2458 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2459 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2460 | } |
| 2461 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2462 | } |
| 2463 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2464 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2465 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2466 | assembler_(codegen->GetAssembler()), |
| 2467 | codegen_(codegen) {} |
| 2468 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2469 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2470 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2471 | 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] | 2472 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2473 | // restore another arbitrary register. |
| 2474 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2475 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2476 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2477 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2478 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2479 | // but in the range. |
| 2480 | if (fpu_spill_mask_ != 0) { |
| 2481 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2482 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2483 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2484 | fpu_spill_mask_ |= (1 << i); |
| 2485 | } |
| 2486 | } |
| 2487 | } |
| 2488 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2489 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2490 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2494 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2495 | } |
| 2496 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2497 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2498 | bool skip_overflow_check = |
| 2499 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2500 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2501 | __ Bind(&frame_entry_label_); |
| 2502 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2503 | if (HasEmptyFrame()) { |
| 2504 | return; |
| 2505 | } |
| 2506 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2507 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2508 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2509 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2510 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2513 | __ PushList(core_spill_mask_); |
| 2514 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2515 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2516 | if (fpu_spill_mask_ != 0) { |
| 2517 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2518 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2519 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2520 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2521 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2522 | |
| 2523 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2524 | // Initialize should_deoptimize flag to 0. |
| 2525 | __ mov(IP, ShifterOperand(0)); |
| 2526 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2527 | } |
| 2528 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2529 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2530 | __ AddConstant(SP, -adjust); |
| 2531 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2532 | |
| 2533 | // Save the current method if we need it. Note that we do not |
| 2534 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2535 | // in the SSA graph. |
| 2536 | if (RequiresCurrentMethod()) { |
| 2537 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2538 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2542 | if (HasEmptyFrame()) { |
| 2543 | __ bx(LR); |
| 2544 | return; |
| 2545 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2546 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2547 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2548 | __ AddConstant(SP, adjust); |
| 2549 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2550 | if (fpu_spill_mask_ != 0) { |
| 2551 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2552 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2553 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2554 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2555 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2556 | // Pop LR into PC to return. |
| 2557 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2558 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2559 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2560 | __ cfi().RestoreState(); |
| 2561 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2564 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2565 | Label* label = GetLabelOf(block); |
| 2566 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2569 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2570 | switch (type) { |
| 2571 | case Primitive::kPrimBoolean: |
| 2572 | case Primitive::kPrimByte: |
| 2573 | case Primitive::kPrimChar: |
| 2574 | case Primitive::kPrimShort: |
| 2575 | case Primitive::kPrimInt: |
| 2576 | case Primitive::kPrimNot: { |
| 2577 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2578 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2579 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2580 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2581 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2582 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2583 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2584 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2585 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2587 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2588 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2589 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2590 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2591 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2592 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2593 | // Skip R1, and use R2_R3 instead. |
| 2594 | gp_index_++; |
| 2595 | index++; |
| 2596 | } |
| 2597 | } |
| 2598 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2599 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2600 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2601 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2602 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2603 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2604 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2605 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | case Primitive::kPrimFloat: { |
| 2610 | uint32_t stack_index = stack_index_++; |
| 2611 | if (float_index_ % 2 == 0) { |
| 2612 | float_index_ = std::max(double_index_, float_index_); |
| 2613 | } |
| 2614 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2615 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2616 | } else { |
| 2617 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | case Primitive::kPrimDouble: { |
| 2622 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2623 | uint32_t stack_index = stack_index_; |
| 2624 | stack_index_ += 2; |
| 2625 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2626 | uint32_t index = double_index_; |
| 2627 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2628 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2629 | calling_convention.GetFpuRegisterAt(index), |
| 2630 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2631 | DCHECK(ExpectedPairLayout(result)); |
| 2632 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2633 | } else { |
| 2634 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2638 | case Primitive::kPrimVoid: |
| 2639 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2640 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2641 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2642 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2643 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2644 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2645 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2646 | switch (type) { |
| 2647 | case Primitive::kPrimBoolean: |
| 2648 | case Primitive::kPrimByte: |
| 2649 | case Primitive::kPrimChar: |
| 2650 | case Primitive::kPrimShort: |
| 2651 | case Primitive::kPrimInt: |
| 2652 | case Primitive::kPrimNot: { |
| 2653 | return Location::RegisterLocation(R0); |
| 2654 | } |
| 2655 | |
| 2656 | case Primitive::kPrimFloat: { |
| 2657 | return Location::FpuRegisterLocation(S0); |
| 2658 | } |
| 2659 | |
| 2660 | case Primitive::kPrimLong: { |
| 2661 | return Location::RegisterPairLocation(R0, R1); |
| 2662 | } |
| 2663 | |
| 2664 | case Primitive::kPrimDouble: { |
| 2665 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2666 | } |
| 2667 | |
| 2668 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2669 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2670 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2671 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2672 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2675 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2676 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2677 | } |
| 2678 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2679 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2680 | if (source.Equals(destination)) { |
| 2681 | return; |
| 2682 | } |
| 2683 | if (destination.IsRegister()) { |
| 2684 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2685 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2686 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2687 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2688 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2689 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2690 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2691 | } else if (destination.IsFpuRegister()) { |
| 2692 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2693 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2694 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2695 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2696 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2697 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2698 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2699 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2700 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2701 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2702 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2703 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2704 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2705 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2706 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2707 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2708 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2714 | if (source.Equals(destination)) { |
| 2715 | return; |
| 2716 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2717 | if (destination.IsRegisterPair()) { |
| 2718 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2719 | EmitParallelMoves( |
| 2720 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2721 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2722 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2723 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2724 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2725 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2726 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2727 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2728 | } else if (source.IsFpuRegisterPair()) { |
| 2729 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2730 | destination.AsRegisterPairHigh<Register>(), |
| 2731 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2732 | } else { |
| 2733 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2734 | DCHECK(ExpectedPairLayout(destination)); |
| 2735 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2736 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2737 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2738 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2739 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2740 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2741 | SP, |
| 2742 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2743 | } else if (source.IsRegisterPair()) { |
| 2744 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2745 | source.AsRegisterPairLow<Register>(), |
| 2746 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2747 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2748 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2749 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2750 | } else { |
| 2751 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2752 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2753 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2754 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2755 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2756 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2757 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2758 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2759 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2760 | SP, destination.GetStackIndex()); |
| 2761 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2762 | } else if (source.IsFpuRegisterPair()) { |
| 2763 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2764 | SP, |
| 2765 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2766 | } else { |
| 2767 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2768 | EmitParallelMoves( |
| 2769 | Location::StackSlot(source.GetStackIndex()), |
| 2770 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2771 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2772 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2773 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2774 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2775 | } |
| 2776 | } |
| 2777 | } |
| 2778 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2779 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2780 | DCHECK(location.IsRegister()); |
| 2781 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2782 | } |
| 2783 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2784 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2785 | HParallelMove move(GetGraph()->GetArena()); |
| 2786 | move.AddMove(src, dst, dst_type, nullptr); |
| 2787 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2791 | if (location.IsRegister()) { |
| 2792 | locations->AddTemp(location); |
| 2793 | } else if (location.IsRegisterPair()) { |
| 2794 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2795 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2796 | } else { |
| 2797 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2798 | } |
| 2799 | } |
| 2800 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2801 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2802 | HInstruction* instruction, |
| 2803 | uint32_t dex_pc, |
| 2804 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2805 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2806 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2807 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2808 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2809 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2810 | } |
| 2811 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2812 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2813 | HInstruction* instruction, |
| 2814 | SlowPathCode* slow_path) { |
| 2815 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2816 | GenerateInvokeRuntime(entry_point_offset); |
| 2817 | } |
| 2818 | |
| 2819 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2820 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2821 | __ blx(LR); |
| 2822 | } |
| 2823 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2824 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2825 | DCHECK(!successor->IsExitBlock()); |
| 2826 | |
| 2827 | HBasicBlock* block = got->GetBlock(); |
| 2828 | HInstruction* previous = got->GetPrevious(); |
| 2829 | |
| 2830 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2831 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2832 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2833 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2834 | return; |
| 2835 | } |
| 2836 | |
| 2837 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2838 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2839 | } |
| 2840 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2841 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2845 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2846 | got->SetLocations(nullptr); |
| 2847 | } |
| 2848 | |
| 2849 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2850 | HandleGoto(got, got->GetSuccessor()); |
| 2851 | } |
| 2852 | |
| 2853 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2854 | try_boundary->SetLocations(nullptr); |
| 2855 | } |
| 2856 | |
| 2857 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2858 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2859 | if (!successor->IsExitBlock()) { |
| 2860 | HandleGoto(try_boundary, successor); |
| 2861 | } |
| 2862 | } |
| 2863 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2864 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2865 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2868 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2869 | } |
| 2870 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2871 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2872 | Label* true_target_in, |
| 2873 | Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2874 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2875 | Label* non_fallthrough_target; |
| 2876 | bool invert; |
| 2877 | |
| 2878 | if (true_target_in == nullptr) { |
| 2879 | DCHECK(false_target_in != nullptr); |
| 2880 | non_fallthrough_target = false_target_in; |
| 2881 | invert = true; |
| 2882 | } else { |
| 2883 | non_fallthrough_target = true_target_in; |
| 2884 | invert = false; |
| 2885 | } |
| 2886 | |
| 2887 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2888 | |
| 2889 | __ b(non_fallthrough_target, cond.first); |
| 2890 | |
| 2891 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2892 | __ b(false_target_in); |
| 2893 | } |
| 2894 | |
| 2895 | return; |
| 2896 | } |
| 2897 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2898 | // Generated branching requires both targets to be explicit. If either of the |
| 2899 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2900 | Label fallthrough_target; |
| 2901 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2902 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2903 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2904 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2905 | GenerateLongComparesAndJumps(condition, true_target, false_target, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2906 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2907 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2908 | __ b(false_target); |
| 2909 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2910 | |
| 2911 | if (fallthrough_target.IsLinked()) { |
| 2912 | __ Bind(&fallthrough_target); |
| 2913 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2914 | } |
| 2915 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2916 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2917 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2918 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2919 | Label* false_target) { |
| 2920 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2921 | |
| 2922 | if (true_target == nullptr && false_target == nullptr) { |
| 2923 | // Nothing to do. The code always falls through. |
| 2924 | return; |
| 2925 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2926 | // Constant condition, statically compared against "true" (integer value 1). |
| 2927 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2928 | if (true_target != nullptr) { |
| 2929 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2930 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2931 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2932 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2933 | if (false_target != nullptr) { |
| 2934 | __ b(false_target); |
| 2935 | } |
| 2936 | } |
| 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | // The following code generates these patterns: |
| 2941 | // (1) true_target == nullptr && false_target != nullptr |
| 2942 | // - opposite condition true => branch to false_target |
| 2943 | // (2) true_target != nullptr && false_target == nullptr |
| 2944 | // - condition true => branch to true_target |
| 2945 | // (3) true_target != nullptr && false_target != nullptr |
| 2946 | // - condition true => branch to true_target |
| 2947 | // - branch to false_target |
| 2948 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2949 | // Condition has been materialized, compare the output to 0. |
| 2950 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2951 | DCHECK(cond_val.IsRegister()); |
| 2952 | if (true_target == nullptr) { |
| 2953 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2954 | } else { |
| 2955 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2956 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2957 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2958 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2959 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2960 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2961 | |
| 2962 | // If this is a long or FP comparison that has been folded into |
| 2963 | // the HCondition, generate the comparison directly. |
| 2964 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2965 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2966 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2967 | return; |
| 2968 | } |
| 2969 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2970 | Label* non_fallthrough_target; |
| 2971 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2972 | LocationSummary* locations = cond->GetLocations(); |
| 2973 | DCHECK(locations->InAt(0).IsRegister()); |
| 2974 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2975 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2976 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2977 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2978 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2979 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2980 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2981 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2982 | non_fallthrough_target = true_target; |
| 2983 | } |
| 2984 | |
| 2985 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2986 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2987 | if (arm_cond == EQ) { |
| 2988 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2989 | } else { |
| 2990 | DCHECK_EQ(arm_cond, NE); |
| 2991 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2992 | } |
| 2993 | } else { |
| 2994 | if (right.IsRegister()) { |
| 2995 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2996 | } else { |
| 2997 | DCHECK(right.IsConstant()); |
| 2998 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2999 | } |
| 3000 | |
| 3001 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3002 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3003 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3004 | |
| 3005 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 3006 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 3007 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3008 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3009 | } |
| 3010 | } |
| 3011 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3012 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3013 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 3014 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3020 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 3021 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 3022 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 3023 | nullptr : codegen_->GetLabelOf(true_successor); |
| 3024 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 3025 | nullptr : codegen_->GetLabelOf(false_successor); |
| 3026 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 3030 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3031 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3032 | InvokeRuntimeCallingConvention calling_convention; |
| 3033 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 3034 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3035 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3036 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3042 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 3043 | GenerateTestAndBranch(deoptimize, |
| 3044 | /* condition_input_index */ 0, |
| 3045 | slow_path->GetEntryLabel(), |
| 3046 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3047 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3048 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3049 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3050 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 3051 | LocationSummary(flag, LocationSummary::kNoCall); |
| 3052 | locations->SetOut(Location::RequiresRegister()); |
| 3053 | } |
| 3054 | |
| 3055 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 3056 | __ LoadFromOffset(kLoadWord, |
| 3057 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 3058 | SP, |
| 3059 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 3060 | } |
| 3061 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3062 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 3063 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3064 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 3065 | |
| 3066 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3067 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3068 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3069 | } else { |
| 3070 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3071 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3072 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3073 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3074 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3075 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 3076 | // The code generator handles overlap with the values, but not with the condition. |
| 3077 | locations->SetOut(Location::SameAsFirstInput()); |
| 3078 | } else if (is_floating_point) { |
| 3079 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3080 | } else { |
| 3081 | if (!locations->InAt(1).IsConstant()) { |
| 3082 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 3083 | } |
| 3084 | |
| 3085 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3086 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3090 | HInstruction* const condition = select->GetCondition(); |
| 3091 | const LocationSummary* const locations = select->GetLocations(); |
| 3092 | const Primitive::Type type = select->GetType(); |
| 3093 | const Location first = locations->InAt(0); |
| 3094 | const Location out = locations->Out(); |
| 3095 | const Location second = locations->InAt(1); |
| 3096 | Location src; |
| 3097 | |
| 3098 | if (condition->IsIntConstant()) { |
| 3099 | if (condition->AsIntConstant()->IsFalse()) { |
| 3100 | src = first; |
| 3101 | } else { |
| 3102 | src = second; |
| 3103 | } |
| 3104 | |
| 3105 | codegen_->MoveLocation(out, src, type); |
| 3106 | return; |
| 3107 | } |
| 3108 | |
| 3109 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3110 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 3111 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3112 | bool invert = false; |
| 3113 | |
| 3114 | if (out.Equals(second)) { |
| 3115 | src = first; |
| 3116 | invert = true; |
| 3117 | } else if (out.Equals(first)) { |
| 3118 | src = second; |
| 3119 | } else if (second.IsConstant()) { |
| 3120 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 3121 | src = second; |
| 3122 | } else if (first.IsConstant()) { |
| 3123 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 3124 | src = first; |
| 3125 | invert = true; |
| 3126 | } else { |
| 3127 | src = second; |
| 3128 | } |
| 3129 | |
| 3130 | if (CanGenerateConditionalMove(out, src)) { |
| 3131 | if (!out.Equals(first) && !out.Equals(second)) { |
| 3132 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 3133 | } |
| 3134 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3135 | std::pair<Condition, Condition> cond; |
| 3136 | |
| 3137 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 3138 | __ CmpConstant(locations->InAt(2).AsRegister<Register>(), 0); |
| 3139 | cond = invert ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
| 3140 | } else { |
| 3141 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 3142 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3143 | |
| 3144 | if (out.IsRegister()) { |
| 3145 | ShifterOperand operand; |
| 3146 | |
| 3147 | if (src.IsConstant()) { |
| 3148 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 3149 | } else { |
| 3150 | DCHECK(src.IsRegister()); |
| 3151 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 3152 | } |
| 3153 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3154 | __ it(cond.first); |
| 3155 | __ mov(out.AsRegister<Register>(), operand, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3156 | } else { |
| 3157 | DCHECK(out.IsRegisterPair()); |
| 3158 | |
| 3159 | ShifterOperand operand_high; |
| 3160 | ShifterOperand operand_low; |
| 3161 | |
| 3162 | if (src.IsConstant()) { |
| 3163 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 3164 | |
| 3165 | operand_high = ShifterOperand(High32Bits(value)); |
| 3166 | operand_low = ShifterOperand(Low32Bits(value)); |
| 3167 | } else { |
| 3168 | DCHECK(src.IsRegisterPair()); |
| 3169 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 3170 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 3171 | } |
| 3172 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3173 | __ it(cond.first); |
| 3174 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond.first); |
| 3175 | __ it(cond.first); |
| 3176 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | return; |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | Label* false_target = nullptr; |
| 3184 | Label* true_target = nullptr; |
| 3185 | Label select_end; |
| 3186 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 3187 | |
| 3188 | if (out.Equals(second)) { |
| 3189 | true_target = target; |
| 3190 | src = first; |
| 3191 | } else { |
| 3192 | false_target = target; |
| 3193 | src = second; |
| 3194 | |
| 3195 | if (!out.Equals(first)) { |
| 3196 | codegen_->MoveLocation(out, first, type); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 3201 | codegen_->MoveLocation(out, src, type); |
| 3202 | |
| 3203 | if (select_end.IsLinked()) { |
| 3204 | __ Bind(&select_end); |
| 3205 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3208 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 3209 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 3210 | } |
| 3211 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 3212 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 3213 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | void CodeGeneratorARM::GenerateNop() { |
| 3217 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3220 | // `temp` is an extra temporary register that is used for some conditions; |
| 3221 | // callers may not specify it, in which case the method will use a scratch |
| 3222 | // register instead. |
| 3223 | void CodeGeneratorARM::GenerateConditionWithZero(IfCondition condition, |
| 3224 | Register out, |
| 3225 | Register in, |
| 3226 | Register temp) { |
| 3227 | switch (condition) { |
| 3228 | case kCondEQ: |
| 3229 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 3230 | case kCondBE: |
| 3231 | if (temp == kNoRegister || (ArmAssembler::IsLowRegister(out) && out != in)) { |
| 3232 | temp = out; |
| 3233 | } |
| 3234 | |
| 3235 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 3236 | // different as well. |
| 3237 | if (ArmAssembler::IsLowRegister(in) && ArmAssembler::IsLowRegister(temp) && in != temp) { |
| 3238 | // temp = - in; only 0 sets the carry flag. |
| 3239 | __ rsbs(temp, in, ShifterOperand(0)); |
| 3240 | |
| 3241 | if (out == in) { |
| 3242 | std::swap(in, temp); |
| 3243 | } |
| 3244 | |
| 3245 | // out = - in + in + carry = carry |
| 3246 | __ adc(out, temp, ShifterOperand(in)); |
| 3247 | } else { |
| 3248 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3249 | __ clz(out, in); |
| 3250 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3251 | // the same operation on 32 yields 1. |
| 3252 | __ Lsr(out, out, 5); |
| 3253 | } |
| 3254 | |
| 3255 | break; |
| 3256 | case kCondNE: |
| 3257 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 3258 | case kCondA: |
| 3259 | if (out == in) { |
| 3260 | if (temp == kNoRegister || in == temp) { |
| 3261 | temp = IP; |
| 3262 | } |
| 3263 | } else if (temp == kNoRegister || !ArmAssembler::IsLowRegister(temp)) { |
| 3264 | temp = out; |
| 3265 | } |
| 3266 | |
| 3267 | // temp = in - 1; only 0 does not set the carry flag. |
| 3268 | __ subs(temp, in, ShifterOperand(1)); |
| 3269 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 3270 | __ sbc(out, in, ShifterOperand(temp)); |
| 3271 | break; |
| 3272 | case kCondGE: |
| 3273 | __ mvn(out, ShifterOperand(in)); |
| 3274 | in = out; |
| 3275 | FALLTHROUGH_INTENDED; |
| 3276 | case kCondLT: |
| 3277 | // We only care about the sign bit. |
| 3278 | __ Lsr(out, in, 31); |
| 3279 | break; |
| 3280 | case kCondAE: |
| 3281 | // Trivially true. |
| 3282 | __ mov(out, ShifterOperand(1)); |
| 3283 | break; |
| 3284 | case kCondB: |
| 3285 | // Trivially false. |
| 3286 | __ mov(out, ShifterOperand(0)); |
| 3287 | break; |
| 3288 | default: |
| 3289 | LOG(FATAL) << "Unexpected condition " << condition; |
| 3290 | UNREACHABLE(); |
| 3291 | } |
| 3292 | } |
| 3293 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3294 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3295 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 3296 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3297 | // Handle the long/FP comparisons made in instruction simplification. |
| 3298 | switch (cond->InputAt(0)->GetType()) { |
| 3299 | case Primitive::kPrimLong: |
| 3300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3301 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3302 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3304 | } |
| 3305 | break; |
| 3306 | |
| 3307 | case Primitive::kPrimFloat: |
| 3308 | case Primitive::kPrimDouble: |
| 3309 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 3310 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3311 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3313 | } |
| 3314 | break; |
| 3315 | |
| 3316 | default: |
| 3317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3318 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3319 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3320 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3321 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3322 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3325 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3326 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3327 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3328 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3329 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3330 | const Primitive::Type type = cond->GetLeft()->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3331 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3332 | if (Primitive::IsFloatingPointType(type)) { |
| 3333 | GenerateConditionGeneric(cond, codegen_); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3334 | return; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3335 | } |
| 3336 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3337 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3338 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3339 | const IfCondition condition = cond->GetCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3340 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3341 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3342 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3343 | // as a regular condition with integral inputs. |
| 3344 | if (type == Primitive::kPrimBoolean && |
| 3345 | cond->GetRight()->GetType() == Primitive::kPrimBoolean && |
| 3346 | (condition == kCondEQ || condition == kCondNE)) { |
| 3347 | const LocationSummary* const locations = cond->GetLocations(); |
| 3348 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 3349 | const Register out = locations->Out().AsRegister<Register>(); |
| 3350 | const Location right_loc = locations->InAt(1); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3351 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3352 | // The constant case is handled by the instruction simplifier. |
| 3353 | DCHECK(!right_loc.IsConstant()); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3354 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3355 | Register right = right_loc.AsRegister<Register>(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3356 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3357 | // Avoid 32-bit instructions if possible. |
| 3358 | if (out == right) { |
| 3359 | std::swap(left, right); |
| 3360 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3361 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3362 | __ eor(out, left, ShifterOperand(right)); |
| 3363 | |
| 3364 | if (condition == kCondEQ) { |
| 3365 | __ eor(out, out, ShifterOperand(1)); |
| 3366 | } |
| 3367 | |
| 3368 | return; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3369 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3370 | |
Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3371 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3375 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3379 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3383 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3387 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3391 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3395 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3399 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3403 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3407 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3411 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3415 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3419 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3420 | } |
| 3421 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3422 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3423 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3427 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3431 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3435 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3439 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3443 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3447 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3451 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3454 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3455 | LocationSummary* locations = |
| 3456 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3457 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3458 | } |
| 3459 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3460 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3461 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3464 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 3465 | LocationSummary* locations = |
| 3466 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3467 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3468 | } |
| 3469 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3470 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3471 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3474 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3475 | LocationSummary* locations = |
| 3476 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3477 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3480 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3481 | // Will be generated at use site. |
| 3482 | } |
| 3483 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3484 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3485 | LocationSummary* locations = |
| 3486 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3487 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3488 | } |
| 3489 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3490 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3491 | // Will be generated at use site. |
| 3492 | } |
| 3493 | |
| 3494 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3495 | LocationSummary* locations = |
| 3496 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3497 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3498 | } |
| 3499 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3500 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3501 | // Will be generated at use site. |
| 3502 | } |
| 3503 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3504 | void LocationsBuilderARM::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3505 | constructor_fence->SetLocations(nullptr); |
| 3506 | } |
| 3507 | |
| 3508 | void InstructionCodeGeneratorARM::VisitConstructorFence( |
| 3509 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3510 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3511 | } |
| 3512 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3513 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3514 | memory_barrier->SetLocations(nullptr); |
| 3515 | } |
| 3516 | |
| 3517 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3518 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3521 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3522 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3525 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3526 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3529 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3530 | LocationSummary* locations = |
| 3531 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3532 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3535 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3536 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3537 | } |
| 3538 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3539 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3540 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3541 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3542 | // the method_idx. |
| 3543 | HandleInvoke(invoke); |
| 3544 | } |
| 3545 | |
| 3546 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3547 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3548 | } |
| 3549 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3550 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3551 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3552 | // art::PrepareForRegisterAllocation. |
| 3553 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3554 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3555 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3556 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3557 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3558 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3559 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3560 | return; |
| 3561 | } |
| 3562 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3563 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3564 | |
| 3565 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3566 | if (invoke->HasPcRelativeDexCache()) { |
| 3567 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3568 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3569 | } |
| 3570 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3571 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3572 | if (invoke->GetLocations()->Intrinsified()) { |
| 3573 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3574 | intrinsic.Dispatch(invoke); |
| 3575 | return true; |
| 3576 | } |
| 3577 | return false; |
| 3578 | } |
| 3579 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3580 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3581 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3582 | // art::PrepareForRegisterAllocation. |
| 3583 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3584 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3585 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3586 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3587 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3588 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3589 | LocationSummary* locations = invoke->GetLocations(); |
| 3590 | codegen_->GenerateStaticOrDirectCall( |
| 3591 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3592 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3593 | } |
| 3594 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3595 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3596 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3597 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3600 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3601 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3602 | if (intrinsic.TryDispatch(invoke)) { |
| 3603 | return; |
| 3604 | } |
| 3605 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3606 | HandleInvoke(invoke); |
| 3607 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3608 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3609 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3610 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3611 | return; |
| 3612 | } |
| 3613 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3614 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3615 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3616 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3619 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3620 | HandleInvoke(invoke); |
| 3621 | // Add the hidden argument. |
| 3622 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3623 | } |
| 3624 | |
| 3625 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3626 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3627 | LocationSummary* locations = invoke->GetLocations(); |
| 3628 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3629 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3630 | Location receiver = locations->InAt(0); |
| 3631 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3632 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3633 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3634 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3635 | DCHECK_EQ(R12, hidden_reg); |
| 3636 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3637 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3638 | if (receiver.IsStackSlot()) { |
| 3639 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3640 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3641 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3642 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3643 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3644 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3645 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3646 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3647 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3648 | // emit a read barrier for the previous class reference load. |
| 3649 | // However this is not required in practice, as this is an |
| 3650 | // intermediate/temporary reference and because the current |
| 3651 | // concurrent copying collector keeps the from-space memory |
| 3652 | // intact/accessible until the end of the marking phase (the |
| 3653 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3654 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3655 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3656 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3657 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3658 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3659 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3660 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3661 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3662 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3663 | // LR = temp->GetEntryPoint(); |
| 3664 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3665 | // LR(); |
| 3666 | __ blx(LR); |
| 3667 | DCHECK(!codegen_->IsLeafMethod()); |
| 3668 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3669 | } |
| 3670 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3671 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3672 | HandleInvoke(invoke); |
| 3673 | } |
| 3674 | |
| 3675 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3676 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3677 | } |
| 3678 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3679 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3680 | LocationSummary* locations = |
| 3681 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3682 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3683 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3684 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3685 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3686 | break; |
| 3687 | } |
| 3688 | case Primitive::kPrimLong: { |
| 3689 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3690 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3691 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3692 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3693 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3694 | case Primitive::kPrimFloat: |
| 3695 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3696 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3697 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3698 | break; |
| 3699 | |
| 3700 | default: |
| 3701 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3706 | LocationSummary* locations = neg->GetLocations(); |
| 3707 | Location out = locations->Out(); |
| 3708 | Location in = locations->InAt(0); |
| 3709 | switch (neg->GetResultType()) { |
| 3710 | case Primitive::kPrimInt: |
| 3711 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3712 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3713 | break; |
| 3714 | |
| 3715 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3716 | DCHECK(in.IsRegisterPair()); |
| 3717 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3718 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3719 | in.AsRegisterPairLow<Register>(), |
| 3720 | ShifterOperand(0)); |
| 3721 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3722 | // instruction here, as it does not exist in the Thumb-2 |
| 3723 | // instruction set. We use the following approach |
| 3724 | // using SBC and SUB instead. |
| 3725 | // |
| 3726 | // out.hi = -C |
| 3727 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3728 | out.AsRegisterPairHigh<Register>(), |
| 3729 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3730 | // out.hi = out.hi - in.hi |
| 3731 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3732 | out.AsRegisterPairHigh<Register>(), |
| 3733 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3734 | break; |
| 3735 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3736 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3737 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3738 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3739 | break; |
| 3740 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3741 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3742 | DCHECK(in.IsFpuRegisterPair()); |
| 3743 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3744 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3745 | break; |
| 3746 | |
| 3747 | default: |
| 3748 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3749 | } |
| 3750 | } |
| 3751 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3752 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3753 | Primitive::Type result_type = conversion->GetResultType(); |
| 3754 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3755 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3756 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3757 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3758 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3759 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3760 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3761 | && result_type == Primitive::kPrimLong) |
| 3762 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3763 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3764 | : LocationSummary::kNoCall; |
| 3765 | LocationSummary* locations = |
| 3766 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3767 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3768 | // The Java language does not allow treating boolean as an integral type but |
| 3769 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3770 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3771 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3772 | case Primitive::kPrimByte: |
| 3773 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3774 | case Primitive::kPrimLong: |
| 3775 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3776 | case Primitive::kPrimBoolean: |
| 3777 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3778 | case Primitive::kPrimShort: |
| 3779 | case Primitive::kPrimInt: |
| 3780 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3781 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3784 | break; |
| 3785 | |
| 3786 | default: |
| 3787 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3788 | << " to " << result_type; |
| 3789 | } |
| 3790 | break; |
| 3791 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3792 | case Primitive::kPrimShort: |
| 3793 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3794 | case Primitive::kPrimLong: |
| 3795 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3796 | case Primitive::kPrimBoolean: |
| 3797 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3798 | case Primitive::kPrimByte: |
| 3799 | case Primitive::kPrimInt: |
| 3800 | case Primitive::kPrimChar: |
| 3801 | // Processing a Dex `int-to-short' instruction. |
| 3802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3803 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3804 | break; |
| 3805 | |
| 3806 | default: |
| 3807 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3808 | << " to " << result_type; |
| 3809 | } |
| 3810 | break; |
| 3811 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3812 | case Primitive::kPrimInt: |
| 3813 | switch (input_type) { |
| 3814 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3815 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3816 | locations->SetInAt(0, Location::Any()); |
| 3817 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3818 | break; |
| 3819 | |
| 3820 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3821 | // Processing a Dex `float-to-int' instruction. |
| 3822 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3823 | locations->SetOut(Location::RequiresRegister()); |
| 3824 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3825 | break; |
| 3826 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3827 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3828 | // Processing a Dex `double-to-int' instruction. |
| 3829 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3830 | locations->SetOut(Location::RequiresRegister()); |
| 3831 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3832 | break; |
| 3833 | |
| 3834 | default: |
| 3835 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3836 | << " to " << result_type; |
| 3837 | } |
| 3838 | break; |
| 3839 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3840 | case Primitive::kPrimLong: |
| 3841 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3842 | case Primitive::kPrimBoolean: |
| 3843 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3844 | case Primitive::kPrimByte: |
| 3845 | case Primitive::kPrimShort: |
| 3846 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3847 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3848 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3849 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3850 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3851 | break; |
| 3852 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3853 | case Primitive::kPrimFloat: { |
| 3854 | // Processing a Dex `float-to-long' instruction. |
| 3855 | InvokeRuntimeCallingConvention calling_convention; |
| 3856 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3857 | calling_convention.GetFpuRegisterAt(0))); |
| 3858 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3859 | break; |
| 3860 | } |
| 3861 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3862 | case Primitive::kPrimDouble: { |
| 3863 | // Processing a Dex `double-to-long' instruction. |
| 3864 | InvokeRuntimeCallingConvention calling_convention; |
| 3865 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3866 | calling_convention.GetFpuRegisterAt(0), |
| 3867 | calling_convention.GetFpuRegisterAt(1))); |
| 3868 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3869 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3870 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3871 | |
| 3872 | default: |
| 3873 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3874 | << " to " << result_type; |
| 3875 | } |
| 3876 | break; |
| 3877 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3878 | case Primitive::kPrimChar: |
| 3879 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3880 | case Primitive::kPrimLong: |
| 3881 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3882 | case Primitive::kPrimBoolean: |
| 3883 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3884 | case Primitive::kPrimByte: |
| 3885 | case Primitive::kPrimShort: |
| 3886 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3887 | // Processing a Dex `int-to-char' instruction. |
| 3888 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3889 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3890 | break; |
| 3891 | |
| 3892 | default: |
| 3893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3894 | << " to " << result_type; |
| 3895 | } |
| 3896 | break; |
| 3897 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3898 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3899 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3900 | case Primitive::kPrimBoolean: |
| 3901 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3902 | case Primitive::kPrimByte: |
| 3903 | case Primitive::kPrimShort: |
| 3904 | case Primitive::kPrimInt: |
| 3905 | case Primitive::kPrimChar: |
| 3906 | // Processing a Dex `int-to-float' instruction. |
| 3907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3908 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3909 | break; |
| 3910 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3911 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3912 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3913 | InvokeRuntimeCallingConvention calling_convention; |
| 3914 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3915 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3916 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3917 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3918 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3919 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3920 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3921 | // Processing a Dex `double-to-float' instruction. |
| 3922 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3923 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3924 | break; |
| 3925 | |
| 3926 | default: |
| 3927 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3928 | << " to " << result_type; |
| 3929 | }; |
| 3930 | break; |
| 3931 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3932 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3933 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3934 | case Primitive::kPrimBoolean: |
| 3935 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3936 | case Primitive::kPrimByte: |
| 3937 | case Primitive::kPrimShort: |
| 3938 | case Primitive::kPrimInt: |
| 3939 | case Primitive::kPrimChar: |
| 3940 | // Processing a Dex `int-to-double' instruction. |
| 3941 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3942 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3943 | break; |
| 3944 | |
| 3945 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3946 | // Processing a Dex `long-to-double' instruction. |
| 3947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3948 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3949 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3950 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3951 | break; |
| 3952 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3953 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3954 | // Processing a Dex `float-to-double' instruction. |
| 3955 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3956 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3957 | break; |
| 3958 | |
| 3959 | default: |
| 3960 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3961 | << " to " << result_type; |
| 3962 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3963 | break; |
| 3964 | |
| 3965 | default: |
| 3966 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3967 | << " to " << result_type; |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3972 | LocationSummary* locations = conversion->GetLocations(); |
| 3973 | Location out = locations->Out(); |
| 3974 | Location in = locations->InAt(0); |
| 3975 | Primitive::Type result_type = conversion->GetResultType(); |
| 3976 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3977 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3978 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3979 | case Primitive::kPrimByte: |
| 3980 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3981 | case Primitive::kPrimLong: |
| 3982 | // Type conversion from long to byte is a result of code transformations. |
| 3983 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3984 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3985 | case Primitive::kPrimBoolean: |
| 3986 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3987 | case Primitive::kPrimShort: |
| 3988 | case Primitive::kPrimInt: |
| 3989 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3990 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3991 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3992 | break; |
| 3993 | |
| 3994 | default: |
| 3995 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3996 | << " to " << result_type; |
| 3997 | } |
| 3998 | break; |
| 3999 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 4000 | case Primitive::kPrimShort: |
| 4001 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 4002 | case Primitive::kPrimLong: |
| 4003 | // Type conversion from long to short is a result of code transformations. |
| 4004 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 4005 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4006 | case Primitive::kPrimBoolean: |
| 4007 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 4008 | case Primitive::kPrimByte: |
| 4009 | case Primitive::kPrimInt: |
| 4010 | case Primitive::kPrimChar: |
| 4011 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4012 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 4013 | break; |
| 4014 | |
| 4015 | default: |
| 4016 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4017 | << " to " << result_type; |
| 4018 | } |
| 4019 | break; |
| 4020 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4021 | case Primitive::kPrimInt: |
| 4022 | switch (input_type) { |
| 4023 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4024 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4025 | DCHECK(out.IsRegister()); |
| 4026 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4027 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4028 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4029 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4030 | } else { |
| 4031 | DCHECK(in.IsConstant()); |
| 4032 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 4033 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4034 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4035 | } |
| 4036 | break; |
| 4037 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 4038 | case Primitive::kPrimFloat: { |
| 4039 | // Processing a Dex `float-to-int' instruction. |
| 4040 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 4041 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 4042 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 4043 | break; |
| 4044 | } |
| 4045 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4046 | case Primitive::kPrimDouble: { |
| 4047 | // Processing a Dex `double-to-int' instruction. |
| 4048 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 4049 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4050 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4051 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4052 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 4053 | |
| 4054 | default: |
| 4055 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4056 | << " to " << result_type; |
| 4057 | } |
| 4058 | break; |
| 4059 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4060 | case Primitive::kPrimLong: |
| 4061 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4062 | case Primitive::kPrimBoolean: |
| 4063 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4064 | case Primitive::kPrimByte: |
| 4065 | case Primitive::kPrimShort: |
| 4066 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 4067 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4068 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4069 | DCHECK(out.IsRegisterPair()); |
| 4070 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4071 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4072 | // Sign extension. |
| 4073 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 4074 | out.AsRegisterPairLow<Register>(), |
| 4075 | 31); |
| 4076 | break; |
| 4077 | |
| 4078 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4079 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4080 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4081 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4082 | break; |
| 4083 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4084 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 4085 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4086 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4087 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4088 | break; |
| 4089 | |
| 4090 | default: |
| 4091 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4092 | << " to " << result_type; |
| 4093 | } |
| 4094 | break; |
| 4095 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4096 | case Primitive::kPrimChar: |
| 4097 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 4098 | case Primitive::kPrimLong: |
| 4099 | // Type conversion from long to char is a result of code transformations. |
| 4100 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 4101 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4102 | case Primitive::kPrimBoolean: |
| 4103 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4104 | case Primitive::kPrimByte: |
| 4105 | case Primitive::kPrimShort: |
| 4106 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4107 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4108 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 4109 | break; |
| 4110 | |
| 4111 | default: |
| 4112 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4113 | << " to " << result_type; |
| 4114 | } |
| 4115 | break; |
| 4116 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4117 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4118 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4119 | case Primitive::kPrimBoolean: |
| 4120 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4121 | case Primitive::kPrimByte: |
| 4122 | case Primitive::kPrimShort: |
| 4123 | case Primitive::kPrimInt: |
| 4124 | case Primitive::kPrimChar: { |
| 4125 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4126 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 4127 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 4131 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4132 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4133 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4134 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4135 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 4136 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4137 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 4138 | // Processing a Dex `double-to-float' instruction. |
| 4139 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 4140 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4141 | break; |
| 4142 | |
| 4143 | default: |
| 4144 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4145 | << " to " << result_type; |
| 4146 | }; |
| 4147 | break; |
| 4148 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4149 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4150 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 4151 | case Primitive::kPrimBoolean: |
| 4152 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4153 | case Primitive::kPrimByte: |
| 4154 | case Primitive::kPrimShort: |
| 4155 | case Primitive::kPrimInt: |
| 4156 | case Primitive::kPrimChar: { |
| 4157 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4158 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4159 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4160 | out.AsFpuRegisterPairLow<SRegister>()); |
| 4161 | break; |
| 4162 | } |
| 4163 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4164 | case Primitive::kPrimLong: { |
| 4165 | // Processing a Dex `long-to-double' instruction. |
| 4166 | Register low = in.AsRegisterPairLow<Register>(); |
| 4167 | Register high = in.AsRegisterPairHigh<Register>(); |
| 4168 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 4169 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4170 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4171 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4172 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 4173 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4174 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 4175 | // temp_d = int-to-double(high) |
| 4176 | __ vmovsr(temp_s, high); |
| 4177 | __ vcvtdi(temp_d, temp_s); |
| 4178 | // constant_d = k2Pow32EncodingForDouble |
| 4179 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 4180 | // out_d = unsigned-to-double(low) |
| 4181 | __ vmovsr(out_s, low); |
| 4182 | __ vcvtdu(out_d, out_s); |
| 4183 | // out_d += temp_d * constant_d |
| 4184 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 4185 | break; |
| 4186 | } |
| 4187 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4188 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 4189 | // Processing a Dex `float-to-double' instruction. |
| 4190 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4191 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 4192 | break; |
| 4193 | |
| 4194 | default: |
| 4195 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4196 | << " to " << result_type; |
| 4197 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4198 | break; |
| 4199 | |
| 4200 | default: |
| 4201 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 4202 | << " to " << result_type; |
| 4203 | } |
| 4204 | } |
| 4205 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4206 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4207 | LocationSummary* locations = |
| 4208 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4209 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4210 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4212 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4213 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4214 | break; |
| 4215 | } |
| 4216 | |
| 4217 | case Primitive::kPrimLong: { |
| 4218 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4219 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4220 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4221 | break; |
| 4222 | } |
| 4223 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4224 | case Primitive::kPrimFloat: |
| 4225 | case Primitive::kPrimDouble: { |
| 4226 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4227 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4228 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4229 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4230 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4231 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4232 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4233 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4234 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 4238 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4239 | Location out = locations->Out(); |
| 4240 | Location first = locations->InAt(0); |
| 4241 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4242 | switch (add->GetResultType()) { |
| 4243 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4244 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4245 | __ add(out.AsRegister<Register>(), |
| 4246 | first.AsRegister<Register>(), |
| 4247 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4248 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4249 | __ AddConstant(out.AsRegister<Register>(), |
| 4250 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4251 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4252 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4253 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4254 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4255 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4256 | if (second.IsConstant()) { |
| 4257 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4258 | GenerateAddLongConst(out, first, value); |
| 4259 | } else { |
| 4260 | DCHECK(second.IsRegisterPair()); |
| 4261 | __ adds(out.AsRegisterPairLow<Register>(), |
| 4262 | first.AsRegisterPairLow<Register>(), |
| 4263 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4264 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 4265 | first.AsRegisterPairHigh<Register>(), |
| 4266 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4267 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4268 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4269 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4270 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4271 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4272 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 4273 | first.AsFpuRegister<SRegister>(), |
| 4274 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4275 | break; |
| 4276 | |
| 4277 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4278 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4279 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4280 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4281 | break; |
| 4282 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4283 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 4284 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4285 | } |
| 4286 | } |
| 4287 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4288 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4289 | LocationSummary* locations = |
| 4290 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4291 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4292 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4294 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4295 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4296 | break; |
| 4297 | } |
| 4298 | |
| 4299 | case Primitive::kPrimLong: { |
| 4300 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4301 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4303 | break; |
| 4304 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4305 | case Primitive::kPrimFloat: |
| 4306 | case Primitive::kPrimDouble: { |
| 4307 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4308 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4309 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4310 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4311 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4312 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4313 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4314 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 4318 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4319 | Location out = locations->Out(); |
| 4320 | Location first = locations->InAt(0); |
| 4321 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4322 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4323 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4324 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4325 | __ sub(out.AsRegister<Register>(), |
| 4326 | first.AsRegister<Register>(), |
| 4327 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4328 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4329 | __ AddConstant(out.AsRegister<Register>(), |
| 4330 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4331 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4332 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4333 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4334 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4335 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4336 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4337 | if (second.IsConstant()) { |
| 4338 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 4339 | GenerateAddLongConst(out, first, -value); |
| 4340 | } else { |
| 4341 | DCHECK(second.IsRegisterPair()); |
| 4342 | __ subs(out.AsRegisterPairLow<Register>(), |
| 4343 | first.AsRegisterPairLow<Register>(), |
| 4344 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 4345 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 4346 | first.AsRegisterPairHigh<Register>(), |
| 4347 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 4348 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4349 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4350 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4351 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4352 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4353 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 4354 | first.AsFpuRegister<SRegister>(), |
| 4355 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4356 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4360 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4361 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4362 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4366 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4367 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 4368 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4372 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 4373 | LocationSummary* locations = |
| 4374 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 4375 | switch (mul->GetResultType()) { |
| 4376 | case Primitive::kPrimInt: |
| 4377 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4379 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4380 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4381 | break; |
| 4382 | } |
| 4383 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4384 | case Primitive::kPrimFloat: |
| 4385 | case Primitive::kPrimDouble: { |
| 4386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4387 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4388 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4389 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4390 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4391 | |
| 4392 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4393 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 4398 | LocationSummary* locations = mul->GetLocations(); |
| 4399 | Location out = locations->Out(); |
| 4400 | Location first = locations->InAt(0); |
| 4401 | Location second = locations->InAt(1); |
| 4402 | switch (mul->GetResultType()) { |
| 4403 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4404 | __ mul(out.AsRegister<Register>(), |
| 4405 | first.AsRegister<Register>(), |
| 4406 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4407 | break; |
| 4408 | } |
| 4409 | case Primitive::kPrimLong: { |
| 4410 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 4411 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 4412 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 4413 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 4414 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 4415 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 4416 | |
| 4417 | // Extra checks to protect caused by the existence of R1_R2. |
| 4418 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4419 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 4420 | DCHECK_NE(out_hi, in1_lo); |
| 4421 | DCHECK_NE(out_hi, in2_lo); |
| 4422 | |
| 4423 | // input: in1 - 64 bits, in2 - 64 bits |
| 4424 | // output: out |
| 4425 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4426 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4427 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4428 | |
| 4429 | // IP <- in1.lo * in2.hi |
| 4430 | __ mul(IP, in1_lo, in2_hi); |
| 4431 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4432 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 4433 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4434 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 4435 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 4436 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 4437 | break; |
| 4438 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4439 | |
| 4440 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4441 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 4442 | first.AsFpuRegister<SRegister>(), |
| 4443 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4444 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4448 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4449 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4450 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4451 | break; |
| 4452 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4453 | |
| 4454 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4455 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4456 | } |
| 4457 | } |
| 4458 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4459 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4460 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4461 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4462 | |
| 4463 | LocationSummary* locations = instruction->GetLocations(); |
| 4464 | Location second = locations->InAt(1); |
| 4465 | DCHECK(second.IsConstant()); |
| 4466 | |
| 4467 | Register out = locations->Out().AsRegister<Register>(); |
| 4468 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4469 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4470 | DCHECK(imm == 1 || imm == -1); |
| 4471 | |
| 4472 | if (instruction->IsRem()) { |
| 4473 | __ LoadImmediate(out, 0); |
| 4474 | } else { |
| 4475 | if (imm == 1) { |
| 4476 | __ Mov(out, dividend); |
| 4477 | } else { |
| 4478 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4479 | } |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4484 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4485 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4486 | |
| 4487 | LocationSummary* locations = instruction->GetLocations(); |
| 4488 | Location second = locations->InAt(1); |
| 4489 | DCHECK(second.IsConstant()); |
| 4490 | |
| 4491 | Register out = locations->Out().AsRegister<Register>(); |
| 4492 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4493 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4494 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4495 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4496 | int ctz_imm = CTZ(abs_imm); |
| 4497 | |
| 4498 | if (ctz_imm == 1) { |
| 4499 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4500 | } else { |
| 4501 | __ Asr(temp, dividend, 31); |
| 4502 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4503 | } |
| 4504 | __ add(out, temp, ShifterOperand(dividend)); |
| 4505 | |
| 4506 | if (instruction->IsDiv()) { |
| 4507 | __ Asr(out, out, ctz_imm); |
| 4508 | if (imm < 0) { |
| 4509 | __ rsb(out, out, ShifterOperand(0)); |
| 4510 | } |
| 4511 | } else { |
| 4512 | __ ubfx(out, out, 0, ctz_imm); |
| 4513 | __ sub(out, out, ShifterOperand(temp)); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4518 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4519 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4520 | |
| 4521 | LocationSummary* locations = instruction->GetLocations(); |
| 4522 | Location second = locations->InAt(1); |
| 4523 | DCHECK(second.IsConstant()); |
| 4524 | |
| 4525 | Register out = locations->Out().AsRegister<Register>(); |
| 4526 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4527 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4528 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4529 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4530 | |
| 4531 | int64_t magic; |
| 4532 | int shift; |
| 4533 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4534 | |
| 4535 | __ LoadImmediate(temp1, magic); |
| 4536 | __ smull(temp2, temp1, dividend, temp1); |
| 4537 | |
| 4538 | if (imm > 0 && magic < 0) { |
| 4539 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4540 | } else if (imm < 0 && magic > 0) { |
| 4541 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4542 | } |
| 4543 | |
| 4544 | if (shift != 0) { |
| 4545 | __ Asr(temp1, temp1, shift); |
| 4546 | } |
| 4547 | |
| 4548 | if (instruction->IsDiv()) { |
| 4549 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4550 | } else { |
| 4551 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4552 | // TODO: Strength reduction for mls. |
| 4553 | __ LoadImmediate(temp2, imm); |
| 4554 | __ mls(out, temp1, temp2, dividend); |
| 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4559 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4560 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4561 | |
| 4562 | LocationSummary* locations = instruction->GetLocations(); |
| 4563 | Location second = locations->InAt(1); |
| 4564 | DCHECK(second.IsConstant()); |
| 4565 | |
| 4566 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4567 | if (imm == 0) { |
| 4568 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4569 | } else if (imm == 1 || imm == -1) { |
| 4570 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4571 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4572 | DivRemByPowerOfTwo(instruction); |
| 4573 | } else { |
| 4574 | DCHECK(imm <= -2 || imm >= 2); |
| 4575 | GenerateDivRemWithAnyConstant(instruction); |
| 4576 | } |
| 4577 | } |
| 4578 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4579 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4580 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4581 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4582 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4583 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4584 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4585 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4586 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4587 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4588 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4589 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4590 | } |
| 4591 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4592 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4593 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4594 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4595 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4596 | if (div->InputAt(1)->IsConstant()) { |
| 4597 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4598 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4599 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4600 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4601 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4602 | // No temp register required. |
| 4603 | } else { |
| 4604 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4605 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4606 | locations->AddTemp(Location::RequiresRegister()); |
| 4607 | } |
| 4608 | } |
| 4609 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4611 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4613 | } else { |
| 4614 | InvokeRuntimeCallingConvention calling_convention; |
| 4615 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4616 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4617 | // 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] | 4618 | // we only need the former. |
| 4619 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4620 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4623 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4624 | InvokeRuntimeCallingConvention calling_convention; |
| 4625 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4626 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4627 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4628 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4629 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4630 | break; |
| 4631 | } |
| 4632 | case Primitive::kPrimFloat: |
| 4633 | case Primitive::kPrimDouble: { |
| 4634 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4635 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4636 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4637 | break; |
| 4638 | } |
| 4639 | |
| 4640 | default: |
| 4641 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4646 | LocationSummary* locations = div->GetLocations(); |
| 4647 | Location out = locations->Out(); |
| 4648 | Location first = locations->InAt(0); |
| 4649 | Location second = locations->InAt(1); |
| 4650 | |
| 4651 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4652 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4653 | if (second.IsConstant()) { |
| 4654 | GenerateDivRemConstantIntegral(div); |
| 4655 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4656 | __ sdiv(out.AsRegister<Register>(), |
| 4657 | first.AsRegister<Register>(), |
| 4658 | second.AsRegister<Register>()); |
| 4659 | } else { |
| 4660 | InvokeRuntimeCallingConvention calling_convention; |
| 4661 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4662 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4663 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4664 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4665 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4666 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4667 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4668 | break; |
| 4669 | } |
| 4670 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4671 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4672 | InvokeRuntimeCallingConvention calling_convention; |
| 4673 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4674 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4675 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4676 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4677 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4678 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4679 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4680 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4681 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4682 | break; |
| 4683 | } |
| 4684 | |
| 4685 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4686 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4687 | first.AsFpuRegister<SRegister>(), |
| 4688 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4689 | break; |
| 4690 | } |
| 4691 | |
| 4692 | case Primitive::kPrimDouble: { |
| 4693 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4694 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4695 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4696 | break; |
| 4697 | } |
| 4698 | |
| 4699 | default: |
| 4700 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4701 | } |
| 4702 | } |
| 4703 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4704 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4705 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4706 | |
| 4707 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4708 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4709 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4710 | // sdiv will be replaced by other instruction sequence. |
| 4711 | call_kind = LocationSummary::kNoCall; |
| 4712 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4713 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4714 | // Have hardware divide instruction for int, do it with three instructions. |
| 4715 | call_kind = LocationSummary::kNoCall; |
| 4716 | } |
| 4717 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4719 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4720 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4721 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4722 | if (rem->InputAt(1)->IsConstant()) { |
| 4723 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4724 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4725 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4726 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4727 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4728 | // No temp register required. |
| 4729 | } else { |
| 4730 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4731 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4732 | locations->AddTemp(Location::RequiresRegister()); |
| 4733 | } |
| 4734 | } |
| 4735 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4736 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4737 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4738 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4739 | locations->AddTemp(Location::RequiresRegister()); |
| 4740 | } else { |
| 4741 | InvokeRuntimeCallingConvention calling_convention; |
| 4742 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4743 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4744 | // 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] | 4745 | // we only need the latter. |
| 4746 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4747 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4748 | break; |
| 4749 | } |
| 4750 | case Primitive::kPrimLong: { |
| 4751 | InvokeRuntimeCallingConvention calling_convention; |
| 4752 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4753 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4754 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4755 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4756 | // The runtime helper puts the output in R2,R3. |
| 4757 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4758 | break; |
| 4759 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4760 | case Primitive::kPrimFloat: { |
| 4761 | InvokeRuntimeCallingConvention calling_convention; |
| 4762 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4763 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4764 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4765 | break; |
| 4766 | } |
| 4767 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4768 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4769 | InvokeRuntimeCallingConvention calling_convention; |
| 4770 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4771 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4772 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4773 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4774 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4775 | break; |
| 4776 | } |
| 4777 | |
| 4778 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4779 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4784 | LocationSummary* locations = rem->GetLocations(); |
| 4785 | Location out = locations->Out(); |
| 4786 | Location first = locations->InAt(0); |
| 4787 | Location second = locations->InAt(1); |
| 4788 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4789 | Primitive::Type type = rem->GetResultType(); |
| 4790 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4791 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4792 | if (second.IsConstant()) { |
| 4793 | GenerateDivRemConstantIntegral(rem); |
| 4794 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4795 | Register reg1 = first.AsRegister<Register>(); |
| 4796 | Register reg2 = second.AsRegister<Register>(); |
| 4797 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4798 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4799 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4800 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4801 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4802 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4803 | } else { |
| 4804 | InvokeRuntimeCallingConvention calling_convention; |
| 4805 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4806 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4807 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4808 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4809 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4810 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4811 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4812 | break; |
| 4813 | } |
| 4814 | |
| 4815 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4816 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4817 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4818 | break; |
| 4819 | } |
| 4820 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4821 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4822 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4823 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4824 | break; |
| 4825 | } |
| 4826 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4827 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4828 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4829 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4830 | break; |
| 4831 | } |
| 4832 | |
| 4833 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4834 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4835 | } |
| 4836 | } |
| 4837 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4838 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4839 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4840 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4844 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4845 | codegen_->AddSlowPath(slow_path); |
| 4846 | |
| 4847 | LocationSummary* locations = instruction->GetLocations(); |
| 4848 | Location value = locations->InAt(0); |
| 4849 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4850 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4851 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4852 | case Primitive::kPrimByte: |
| 4853 | case Primitive::kPrimChar: |
| 4854 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4855 | case Primitive::kPrimInt: { |
| 4856 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4857 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4858 | } else { |
| 4859 | DCHECK(value.IsConstant()) << value; |
| 4860 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4861 | __ b(slow_path->GetEntryLabel()); |
| 4862 | } |
| 4863 | } |
| 4864 | break; |
| 4865 | } |
| 4866 | case Primitive::kPrimLong: { |
| 4867 | if (value.IsRegisterPair()) { |
| 4868 | __ orrs(IP, |
| 4869 | value.AsRegisterPairLow<Register>(), |
| 4870 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4871 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4872 | } else { |
| 4873 | DCHECK(value.IsConstant()) << value; |
| 4874 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4875 | __ b(slow_path->GetEntryLabel()); |
| 4876 | } |
| 4877 | } |
| 4878 | break; |
| 4879 | default: |
| 4880 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4881 | } |
| 4882 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4885 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4886 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4887 | Location rhs = locations->InAt(1); |
| 4888 | Register out = locations->Out().AsRegister<Register>(); |
| 4889 | |
| 4890 | if (rhs.IsConstant()) { |
| 4891 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4892 | // so map all rotations to a +ve. equivalent in that range. |
| 4893 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4894 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4895 | if (rot) { |
| 4896 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4897 | // (e.g. left by 2 bits == right by 30.) |
| 4898 | __ Ror(out, in, rot); |
| 4899 | } else if (out != in) { |
| 4900 | __ Mov(out, in); |
| 4901 | } |
| 4902 | } else { |
| 4903 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4904 | } |
| 4905 | } |
| 4906 | |
| 4907 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4908 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4909 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4910 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4911 | void InstructionCodeGeneratorARM::HandleLongRotate(HRor* ror) { |
| 4912 | LocationSummary* locations = ror->GetLocations(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4913 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4914 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4915 | Location rhs = locations->InAt(1); |
| 4916 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4917 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4918 | |
| 4919 | if (rhs.IsConstant()) { |
| 4920 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4921 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4922 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4923 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4924 | // logic below to a simple pair of binary orr. |
| 4925 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4926 | if (rot >= kArmBitsPerWord) { |
| 4927 | rot -= kArmBitsPerWord; |
| 4928 | std::swap(in_reg_hi, in_reg_lo); |
| 4929 | } |
| 4930 | // Rotate, or mov to out for zero or word size rotations. |
| 4931 | if (rot != 0u) { |
| 4932 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4933 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4934 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4935 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4936 | } else { |
| 4937 | __ Mov(out_reg_lo, in_reg_lo); |
| 4938 | __ Mov(out_reg_hi, in_reg_hi); |
| 4939 | } |
| 4940 | } else { |
| 4941 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4942 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4943 | Label end; |
| 4944 | Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4945 | Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4946 | |
| 4947 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4948 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4949 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4950 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4951 | |
| 4952 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4953 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4954 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4955 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4956 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4957 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4958 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4959 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4960 | __ b(final_label); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4961 | |
| 4962 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4963 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4964 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4965 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4966 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4967 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4968 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4969 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4970 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4971 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4972 | if (end.IsLinked()) { |
| 4973 | __ Bind(&end); |
| 4974 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4975 | } |
| 4976 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4977 | |
| 4978 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4979 | LocationSummary* locations = |
| 4980 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4981 | switch (ror->GetResultType()) { |
| 4982 | case Primitive::kPrimInt: { |
| 4983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4984 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4985 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4986 | break; |
| 4987 | } |
| 4988 | case Primitive::kPrimLong: { |
| 4989 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4990 | if (ror->InputAt(1)->IsConstant()) { |
| 4991 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4992 | } else { |
| 4993 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4994 | locations->AddTemp(Location::RequiresRegister()); |
| 4995 | locations->AddTemp(Location::RequiresRegister()); |
| 4996 | } |
| 4997 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4998 | break; |
| 4999 | } |
| 5000 | default: |
| 5001 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 5002 | } |
| 5003 | } |
| 5004 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5005 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5006 | LocationSummary* locations = ror->GetLocations(); |
| 5007 | Primitive::Type type = ror->GetResultType(); |
| 5008 | switch (type) { |
| 5009 | case Primitive::kPrimInt: { |
| 5010 | HandleIntegerRotate(locations); |
| 5011 | break; |
| 5012 | } |
| 5013 | case Primitive::kPrimLong: { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5014 | HandleLongRotate(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5015 | break; |
| 5016 | } |
| 5017 | default: |
| 5018 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 5019 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5023 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 5024 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5025 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5026 | LocationSummary* locations = |
| 5027 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5028 | |
| 5029 | switch (op->GetResultType()) { |
| 5030 | case Primitive::kPrimInt: { |
| 5031 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5032 | if (op->InputAt(1)->IsConstant()) { |
| 5033 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5034 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5035 | } else { |
| 5036 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5037 | // Make the output overlap, as it will be used to hold the masked |
| 5038 | // second input. |
| 5039 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5040 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5041 | break; |
| 5042 | } |
| 5043 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5044 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5045 | if (op->InputAt(1)->IsConstant()) { |
| 5046 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 5047 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 5048 | // don't clash with high registers which the register allocator currently guarantees. |
| 5049 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5050 | } else { |
| 5051 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5052 | locations->AddTemp(Location::RequiresRegister()); |
| 5053 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5054 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5055 | break; |
| 5056 | } |
| 5057 | default: |
| 5058 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 5063 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 5064 | |
| 5065 | LocationSummary* locations = op->GetLocations(); |
| 5066 | Location out = locations->Out(); |
| 5067 | Location first = locations->InAt(0); |
| 5068 | Location second = locations->InAt(1); |
| 5069 | |
| 5070 | Primitive::Type type = op->GetResultType(); |
| 5071 | switch (type) { |
| 5072 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5073 | Register out_reg = out.AsRegister<Register>(); |
| 5074 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5075 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5076 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5077 | // 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] | 5078 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5079 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5080 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5081 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5082 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5083 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 5084 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5085 | } |
| 5086 | } else { |
| 5087 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5088 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5089 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5090 | __ Mov(out_reg, first_reg); |
| 5091 | } else if (op->IsShl()) { |
| 5092 | __ Lsl(out_reg, first_reg, shift_value); |
| 5093 | } else if (op->IsShr()) { |
| 5094 | __ Asr(out_reg, first_reg, shift_value); |
| 5095 | } else { |
| 5096 | __ Lsr(out_reg, first_reg, shift_value); |
| 5097 | } |
| 5098 | } |
| 5099 | break; |
| 5100 | } |
| 5101 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5102 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 5103 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5104 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5105 | Register high = first.AsRegisterPairHigh<Register>(); |
| 5106 | Register low = first.AsRegisterPairLow<Register>(); |
| 5107 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5108 | if (second.IsRegister()) { |
| 5109 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 5110 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5111 | Register second_reg = second.AsRegister<Register>(); |
| 5112 | |
| 5113 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5114 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5115 | // Shift the high part |
| 5116 | __ Lsl(o_h, high, o_l); |
| 5117 | // Shift the low part and `or` what overflew on the high part |
| 5118 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 5119 | __ Lsr(temp, low, temp); |
| 5120 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 5121 | // If the shift is > 32 bits, override the high part |
| 5122 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 5123 | __ it(PL); |
| 5124 | __ Lsl(o_h, low, temp, PL); |
| 5125 | // Shift the low part |
| 5126 | __ Lsl(o_l, low, o_l); |
| 5127 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5128 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5129 | // Shift the low part |
| 5130 | __ Lsr(o_l, low, o_h); |
| 5131 | // Shift the high part and `or` what underflew on the low part |
| 5132 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5133 | __ Lsl(temp, high, temp); |
| 5134 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 5135 | // If the shift is > 32 bits, override the low part |
| 5136 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5137 | __ it(PL); |
| 5138 | __ Asr(o_l, high, temp, PL); |
| 5139 | // Shift the high part |
| 5140 | __ Asr(o_h, high, o_h); |
| 5141 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5142 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5143 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5144 | __ Lsr(o_l, low, o_h); |
| 5145 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5146 | __ Lsl(temp, high, temp); |
| 5147 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 5148 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 5149 | __ it(PL); |
| 5150 | __ Lsr(o_l, high, temp, PL); |
| 5151 | __ Lsr(o_h, high, o_h); |
| 5152 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5153 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5154 | // Register allocator doesn't create partial overlap. |
| 5155 | DCHECK_NE(o_l, high); |
| 5156 | DCHECK_NE(o_h, low); |
| 5157 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5158 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5159 | if (shift_value > 32) { |
| 5160 | if (op->IsShl()) { |
| 5161 | __ Lsl(o_h, low, shift_value - 32); |
| 5162 | __ LoadImmediate(o_l, 0); |
| 5163 | } else if (op->IsShr()) { |
| 5164 | __ Asr(o_l, high, shift_value - 32); |
| 5165 | __ Asr(o_h, high, 31); |
| 5166 | } else { |
| 5167 | __ Lsr(o_l, high, shift_value - 32); |
| 5168 | __ LoadImmediate(o_h, 0); |
| 5169 | } |
| 5170 | } else if (shift_value == 32) { |
| 5171 | if (op->IsShl()) { |
| 5172 | __ mov(o_h, ShifterOperand(low)); |
| 5173 | __ LoadImmediate(o_l, 0); |
| 5174 | } else if (op->IsShr()) { |
| 5175 | __ mov(o_l, ShifterOperand(high)); |
| 5176 | __ Asr(o_h, high, 31); |
| 5177 | } else { |
| 5178 | __ mov(o_l, ShifterOperand(high)); |
| 5179 | __ LoadImmediate(o_h, 0); |
| 5180 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 5181 | } else if (shift_value == 1) { |
| 5182 | if (op->IsShl()) { |
| 5183 | __ Lsls(o_l, low, 1); |
| 5184 | __ adc(o_h, high, ShifterOperand(high)); |
| 5185 | } else if (op->IsShr()) { |
| 5186 | __ Asrs(o_h, high, 1); |
| 5187 | __ Rrx(o_l, low); |
| 5188 | } else { |
| 5189 | __ Lsrs(o_h, high, 1); |
| 5190 | __ Rrx(o_l, low); |
| 5191 | } |
| 5192 | } else { |
| 5193 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5194 | if (op->IsShl()) { |
| 5195 | __ Lsl(o_h, high, shift_value); |
| 5196 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 5197 | __ Lsl(o_l, low, shift_value); |
| 5198 | } else if (op->IsShr()) { |
| 5199 | __ Lsr(o_l, low, shift_value); |
| 5200 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 5201 | __ Asr(o_h, high, shift_value); |
| 5202 | } else { |
| 5203 | __ Lsr(o_l, low, shift_value); |
| 5204 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 5205 | __ Lsr(o_h, high, shift_value); |
| 5206 | } |
| 5207 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5208 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5209 | break; |
| 5210 | } |
| 5211 | default: |
| 5212 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 5213 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 5218 | HandleShift(shl); |
| 5219 | } |
| 5220 | |
| 5221 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 5222 | HandleShift(shl); |
| 5223 | } |
| 5224 | |
| 5225 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 5226 | HandleShift(shr); |
| 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 5230 | HandleShift(shr); |
| 5231 | } |
| 5232 | |
| 5233 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 5234 | HandleShift(ushr); |
| 5235 | } |
| 5236 | |
| 5237 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 5238 | HandleShift(ushr); |
| 5239 | } |
| 5240 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5241 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5242 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5243 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5244 | if (instruction->IsStringAlloc()) { |
| 5245 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5246 | } else { |
| 5247 | InvokeRuntimeCallingConvention calling_convention; |
| 5248 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5249 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5250 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5254 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5255 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5256 | if (instruction->IsStringAlloc()) { |
| 5257 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 5258 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5259 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5260 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 5261 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 5262 | __ blx(LR); |
| 5263 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5264 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 5265 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 5266 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 5267 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 5268 | } |
| 5269 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5270 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 5271 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5272 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5273 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5274 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5275 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5276 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5280 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 5281 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5282 | QuickEntrypointEnum entrypoint = |
| 5283 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 5284 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5285 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 5286 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 5287 | } |
| 5288 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5289 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5290 | LocationSummary* locations = |
| 5291 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5292 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5293 | if (location.IsStackSlot()) { |
| 5294 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5295 | } else if (location.IsDoubleStackSlot()) { |
| 5296 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5297 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 5298 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5299 | } |
| 5300 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5301 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 5302 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 5303 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5307 | LocationSummary* locations = |
| 5308 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5309 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 5310 | } |
| 5311 | |
| 5312 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5313 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5314 | } |
| 5315 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5316 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5317 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5318 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5320 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5321 | } |
| 5322 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5323 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 5324 | LocationSummary* locations = not_->GetLocations(); |
| 5325 | Location out = locations->Out(); |
| 5326 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 5327 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5328 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5329 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5330 | break; |
| 5331 | |
| 5332 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 5333 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 5334 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 5335 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 5336 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5337 | break; |
| 5338 | |
| 5339 | default: |
| 5340 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5341 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5342 | } |
| 5343 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5344 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5345 | LocationSummary* locations = |
| 5346 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 5347 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5348 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5349 | } |
| 5350 | |
| 5351 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5352 | LocationSummary* locations = bool_not->GetLocations(); |
| 5353 | Location out = locations->Out(); |
| 5354 | Location in = locations->InAt(0); |
| 5355 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 5356 | } |
| 5357 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5358 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5359 | LocationSummary* locations = |
| 5360 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5361 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5362 | case Primitive::kPrimBoolean: |
| 5363 | case Primitive::kPrimByte: |
| 5364 | case Primitive::kPrimShort: |
| 5365 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5366 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5367 | case Primitive::kPrimLong: { |
| 5368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5369 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5370 | // Output overlaps because it is written before doing the low comparison. |
| 5371 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5372 | break; |
| 5373 | } |
| 5374 | case Primitive::kPrimFloat: |
| 5375 | case Primitive::kPrimDouble: { |
| 5376 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5377 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5378 | locations->SetOut(Location::RequiresRegister()); |
| 5379 | break; |
| 5380 | } |
| 5381 | default: |
| 5382 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5383 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5387 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5388 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5389 | Location left = locations->InAt(0); |
| 5390 | Location right = locations->InAt(1); |
| 5391 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5392 | Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5393 | Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5394 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5395 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5396 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5397 | case Primitive::kPrimBoolean: |
| 5398 | case Primitive::kPrimByte: |
| 5399 | case Primitive::kPrimShort: |
| 5400 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5401 | case Primitive::kPrimInt: { |
| 5402 | __ LoadImmediate(out, 0); |
| 5403 | __ cmp(left.AsRegister<Register>(), |
| 5404 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 5405 | less_cond = LT; |
| 5406 | break; |
| 5407 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5408 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5409 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 5410 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5411 | __ b(&less, LT); |
| 5412 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5413 | // 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] | 5414 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5415 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 5416 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5417 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5418 | break; |
| 5419 | } |
| 5420 | case Primitive::kPrimFloat: |
| 5421 | case Primitive::kPrimDouble: { |
| 5422 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5423 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5424 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5425 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5426 | break; |
| 5427 | } |
| 5428 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5429 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5430 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5431 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5432 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5433 | __ b(final_label, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5434 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5435 | |
| 5436 | __ Bind(&greater); |
| 5437 | __ LoadImmediate(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5438 | __ b(final_label); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5439 | |
| 5440 | __ Bind(&less); |
| 5441 | __ LoadImmediate(out, -1); |
| 5442 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5443 | if (done.IsLinked()) { |
| 5444 | __ Bind(&done); |
| 5445 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5448 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5449 | LocationSummary* locations = |
| 5450 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5451 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5452 | locations->SetInAt(i, Location::Any()); |
| 5453 | } |
| 5454 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5455 | } |
| 5456 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5457 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5458 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5461 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5462 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5463 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5464 | switch (kind) { |
| 5465 | case MemBarrierKind::kAnyStore: |
| 5466 | case MemBarrierKind::kLoadAny: |
| 5467 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5468 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5469 | break; |
| 5470 | } |
| 5471 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5472 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5473 | break; |
| 5474 | } |
| 5475 | default: |
| 5476 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5477 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5478 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5482 | uint32_t offset, |
| 5483 | Register out_lo, |
| 5484 | Register out_hi) { |
| 5485 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5486 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5487 | // `offset` into `out_lo` does not clutter `addr`. |
| 5488 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5489 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5490 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5491 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5492 | } |
| 5493 | __ ldrexd(out_lo, out_hi, addr); |
| 5494 | } |
| 5495 | |
| 5496 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5497 | uint32_t offset, |
| 5498 | Register value_lo, |
| 5499 | Register value_hi, |
| 5500 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5501 | Register temp2, |
| 5502 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5503 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5504 | if (offset != 0) { |
| 5505 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5506 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5507 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5508 | } |
| 5509 | __ Bind(&fail); |
| 5510 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5511 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5512 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5513 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5514 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5515 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5519 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5520 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5521 | LocationSummary* locations = |
| 5522 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5523 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5524 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5525 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5526 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5527 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5528 | } else { |
| 5529 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5530 | } |
| 5531 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5532 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5533 | bool generate_volatile = field_info.IsVolatile() |
| 5534 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5535 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5536 | bool needs_write_barrier = |
| 5537 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5538 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5539 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5540 | if (needs_write_barrier) { |
| 5541 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5542 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5543 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5544 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5545 | // - registers need to be consecutive |
| 5546 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5547 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5548 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5549 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5550 | |
| 5551 | locations->AddTemp(Location::RequiresRegister()); |
| 5552 | locations->AddTemp(Location::RequiresRegister()); |
| 5553 | if (field_type == Primitive::kPrimDouble) { |
| 5554 | // For doubles we need two more registers to copy the value. |
| 5555 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5556 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5557 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5558 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5559 | } |
| 5560 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5561 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5562 | const FieldInfo& field_info, |
| 5563 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5564 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5565 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5566 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5567 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5568 | Location value = locations->InAt(1); |
| 5569 | |
| 5570 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5571 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5572 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5573 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5574 | bool needs_write_barrier = |
| 5575 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5576 | |
| 5577 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5578 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5579 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5580 | |
| 5581 | switch (field_type) { |
| 5582 | case Primitive::kPrimBoolean: |
| 5583 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5584 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5585 | break; |
| 5586 | } |
| 5587 | |
| 5588 | case Primitive::kPrimShort: |
| 5589 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5590 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5591 | break; |
| 5592 | } |
| 5593 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5594 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5595 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5596 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5597 | // Note that in the case where `value` is a null reference, |
| 5598 | // we do not enter this block, as a null reference does not |
| 5599 | // need poisoning. |
| 5600 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5601 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5602 | __ Mov(temp, value.AsRegister<Register>()); |
| 5603 | __ PoisonHeapReference(temp); |
| 5604 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5605 | } else { |
| 5606 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5607 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5608 | break; |
| 5609 | } |
| 5610 | |
| 5611 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5612 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5613 | GenerateWideAtomicStore(base, offset, |
| 5614 | value.AsRegisterPairLow<Register>(), |
| 5615 | value.AsRegisterPairHigh<Register>(), |
| 5616 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5617 | locations->GetTemp(1).AsRegister<Register>(), |
| 5618 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5619 | } else { |
| 5620 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5621 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5622 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5623 | break; |
| 5624 | } |
| 5625 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5626 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5627 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5628 | break; |
| 5629 | } |
| 5630 | |
| 5631 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5632 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5633 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5634 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5635 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5636 | |
| 5637 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5638 | |
| 5639 | GenerateWideAtomicStore(base, offset, |
| 5640 | value_reg_lo, |
| 5641 | value_reg_hi, |
| 5642 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5643 | locations->GetTemp(3).AsRegister<Register>(), |
| 5644 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5645 | } else { |
| 5646 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5647 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5648 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5649 | break; |
| 5650 | } |
| 5651 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5652 | case Primitive::kPrimVoid: |
| 5653 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5654 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5655 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5656 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5657 | // Longs and doubles are handled in the switch. |
| 5658 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5659 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5660 | } |
| 5661 | |
| 5662 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5663 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5664 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5665 | codegen_->MarkGCCard( |
| 5666 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5669 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5670 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5671 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5672 | } |
| 5673 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5674 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5675 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5676 | |
| 5677 | bool object_field_get_with_read_barrier = |
| 5678 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5679 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5680 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5681 | object_field_get_with_read_barrier ? |
| 5682 | LocationSummary::kCallOnSlowPath : |
| 5683 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5684 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5685 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5686 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5687 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5688 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5689 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5690 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5691 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5692 | // The output overlaps in case of volatile long: we don't want the |
| 5693 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5694 | // object's location. Likewise, in the case of an object field get |
| 5695 | // with read barriers enabled, we do not want the load to overwrite |
| 5696 | // the object's location, as we need it to emit the read barrier. |
| 5697 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5698 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5699 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5700 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5701 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5702 | } else { |
| 5703 | locations->SetOut(Location::RequiresRegister(), |
| 5704 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5705 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5706 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5707 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5708 | // - registers need to be consecutive |
| 5709 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5710 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5711 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5712 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5713 | locations->AddTemp(Location::RequiresRegister()); |
| 5714 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5715 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5716 | // We need a temporary register for the read barrier marking slow |
| 5717 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5718 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5719 | !Runtime::Current()->UseJitCompilation()) { |
| 5720 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5721 | // loads we need a temporary only if the offset is too big. |
| 5722 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5723 | locations->AddTemp(Location::RequiresRegister()); |
| 5724 | } |
| 5725 | // And we always need the reserved entrypoint register. |
| 5726 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5727 | } else { |
| 5728 | locations->AddTemp(Location::RequiresRegister()); |
| 5729 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5730 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5731 | } |
| 5732 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5733 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5734 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5735 | << input->GetType(); |
| 5736 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5737 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5738 | return Location::ConstantLocation(input->AsConstant()); |
| 5739 | } else { |
| 5740 | return Location::RequiresFpuRegister(); |
| 5741 | } |
| 5742 | } |
| 5743 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5744 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5745 | Opcode opcode) { |
| 5746 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5747 | if (constant->IsConstant() && |
| 5748 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5749 | return Location::ConstantLocation(constant->AsConstant()); |
| 5750 | } |
| 5751 | return Location::RequiresRegister(); |
| 5752 | } |
| 5753 | |
| 5754 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5755 | Opcode opcode) { |
| 5756 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5757 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5758 | Opcode high_opcode = opcode; |
| 5759 | SetCc low_set_cc = kCcDontCare; |
| 5760 | switch (opcode) { |
| 5761 | case SUB: |
| 5762 | // Flip the operation to an ADD. |
| 5763 | value = -value; |
| 5764 | opcode = ADD; |
| 5765 | FALLTHROUGH_INTENDED; |
| 5766 | case ADD: |
| 5767 | if (Low32Bits(value) == 0u) { |
| 5768 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5769 | } |
| 5770 | high_opcode = ADC; |
| 5771 | low_set_cc = kCcSet; |
| 5772 | break; |
| 5773 | default: |
| 5774 | break; |
| 5775 | } |
| 5776 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5777 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5778 | } else { |
| 5779 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5780 | } |
| 5781 | } |
| 5782 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5783 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5784 | Opcode opcode, |
| 5785 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5786 | ShifterOperand so; |
| 5787 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5788 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5789 | return true; |
| 5790 | } |
| 5791 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5792 | uint32_t neg_value = 0; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5793 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5794 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5795 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5796 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5797 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5798 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5799 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5800 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5801 | default: |
| 5802 | return false; |
| 5803 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5804 | |
| 5805 | if (assembler->ShifterOperandCanHold(kNoRegister, |
| 5806 | kNoRegister, |
| 5807 | neg_opcode, |
| 5808 | neg_value, |
| 5809 | set_cc, |
| 5810 | &so)) { |
| 5811 | return true; |
| 5812 | } |
| 5813 | |
| 5814 | return opcode == AND && IsPowerOfTwo(value + 1); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5815 | } |
| 5816 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5817 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5818 | const FieldInfo& field_info) { |
| 5819 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5820 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5821 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5822 | Location base_loc = locations->InAt(0); |
| 5823 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5824 | Location out = locations->Out(); |
| 5825 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5826 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5827 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5828 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5829 | |
| 5830 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5831 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5832 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5833 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5834 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5835 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5836 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5837 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5838 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5839 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5840 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5841 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5842 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5843 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5844 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5845 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5846 | |
| 5847 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5848 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5849 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5850 | |
| 5851 | case Primitive::kPrimNot: { |
| 5852 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5853 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5854 | Location temp_loc = locations->GetTemp(0); |
| 5855 | // Note that a potential implicit null check is handled in this |
| 5856 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5857 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5858 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5859 | if (is_volatile) { |
| 5860 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5861 | } |
| 5862 | } else { |
| 5863 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5864 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5865 | if (is_volatile) { |
| 5866 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5867 | } |
| 5868 | // If read barriers are enabled, emit read barriers other than |
| 5869 | // Baker's using a slow path (and also unpoison the loaded |
| 5870 | // reference, if heap poisoning is enabled). |
| 5871 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5872 | } |
| 5873 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5874 | } |
| 5875 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5876 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5877 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5878 | GenerateWideAtomicLoad(base, offset, |
| 5879 | out.AsRegisterPairLow<Register>(), |
| 5880 | out.AsRegisterPairHigh<Register>()); |
| 5881 | } else { |
| 5882 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5883 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5884 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5885 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5886 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5887 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5888 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5889 | |
| 5890 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5891 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5892 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5893 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5894 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5895 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5896 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5897 | __ vmovdrr(out_reg, lo, hi); |
| 5898 | } else { |
| 5899 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5900 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5901 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5902 | break; |
| 5903 | } |
| 5904 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5905 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5906 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5907 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5908 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5909 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5910 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5911 | // Potential implicit null checks, in the case of reference or |
| 5912 | // double fields, are handled in the previous switch statement. |
| 5913 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5914 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5915 | } |
| 5916 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5917 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5918 | if (field_type == Primitive::kPrimNot) { |
| 5919 | // Memory barriers, in the case of references, are also handled |
| 5920 | // in the previous switch statement. |
| 5921 | } else { |
| 5922 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5923 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5924 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5928 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5929 | } |
| 5930 | |
| 5931 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5932 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5936 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5937 | } |
| 5938 | |
| 5939 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5940 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5941 | } |
| 5942 | |
| 5943 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5944 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5945 | } |
| 5946 | |
| 5947 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5948 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5949 | } |
| 5950 | |
| 5951 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5952 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5953 | } |
| 5954 | |
| 5955 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5956 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5957 | } |
| 5958 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5959 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5960 | HUnresolvedInstanceFieldGet* instruction) { |
| 5961 | FieldAccessCallingConventionARM calling_convention; |
| 5962 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5963 | instruction, instruction->GetFieldType(), calling_convention); |
| 5964 | } |
| 5965 | |
| 5966 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5967 | HUnresolvedInstanceFieldGet* instruction) { |
| 5968 | FieldAccessCallingConventionARM calling_convention; |
| 5969 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5970 | instruction->GetFieldType(), |
| 5971 | instruction->GetFieldIndex(), |
| 5972 | instruction->GetDexPc(), |
| 5973 | calling_convention); |
| 5974 | } |
| 5975 | |
| 5976 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5977 | HUnresolvedInstanceFieldSet* instruction) { |
| 5978 | FieldAccessCallingConventionARM calling_convention; |
| 5979 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5980 | instruction, instruction->GetFieldType(), calling_convention); |
| 5981 | } |
| 5982 | |
| 5983 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5984 | HUnresolvedInstanceFieldSet* instruction) { |
| 5985 | FieldAccessCallingConventionARM calling_convention; |
| 5986 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5987 | instruction->GetFieldType(), |
| 5988 | instruction->GetFieldIndex(), |
| 5989 | instruction->GetDexPc(), |
| 5990 | calling_convention); |
| 5991 | } |
| 5992 | |
| 5993 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5994 | HUnresolvedStaticFieldGet* instruction) { |
| 5995 | FieldAccessCallingConventionARM calling_convention; |
| 5996 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5997 | instruction, instruction->GetFieldType(), calling_convention); |
| 5998 | } |
| 5999 | |
| 6000 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 6001 | HUnresolvedStaticFieldGet* instruction) { |
| 6002 | FieldAccessCallingConventionARM calling_convention; |
| 6003 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6004 | instruction->GetFieldType(), |
| 6005 | instruction->GetFieldIndex(), |
| 6006 | instruction->GetDexPc(), |
| 6007 | calling_convention); |
| 6008 | } |
| 6009 | |
| 6010 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 6011 | HUnresolvedStaticFieldSet* instruction) { |
| 6012 | FieldAccessCallingConventionARM calling_convention; |
| 6013 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 6014 | instruction, instruction->GetFieldType(), calling_convention); |
| 6015 | } |
| 6016 | |
| 6017 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 6018 | HUnresolvedStaticFieldSet* instruction) { |
| 6019 | FieldAccessCallingConventionARM calling_convention; |
| 6020 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 6021 | instruction->GetFieldType(), |
| 6022 | instruction->GetFieldIndex(), |
| 6023 | instruction->GetDexPc(), |
| 6024 | calling_convention); |
| 6025 | } |
| 6026 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6027 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6028 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 6029 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6030 | } |
| 6031 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6032 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 6033 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6034 | return; |
| 6035 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6036 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6037 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6038 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6039 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6040 | } |
| 6041 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6042 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6043 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6044 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6045 | |
| 6046 | LocationSummary* locations = instruction->GetLocations(); |
| 6047 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6048 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6049 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 6050 | } |
| 6051 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6052 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 6053 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 6054 | } |
| 6055 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6056 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 6057 | switch (type) { |
| 6058 | case Primitive::kPrimNot: |
| 6059 | return kLoadWord; |
| 6060 | case Primitive::kPrimBoolean: |
| 6061 | return kLoadUnsignedByte; |
| 6062 | case Primitive::kPrimByte: |
| 6063 | return kLoadSignedByte; |
| 6064 | case Primitive::kPrimChar: |
| 6065 | return kLoadUnsignedHalfword; |
| 6066 | case Primitive::kPrimShort: |
| 6067 | return kLoadSignedHalfword; |
| 6068 | case Primitive::kPrimInt: |
| 6069 | return kLoadWord; |
| 6070 | case Primitive::kPrimLong: |
| 6071 | return kLoadWordPair; |
| 6072 | case Primitive::kPrimFloat: |
| 6073 | return kLoadSWord; |
| 6074 | case Primitive::kPrimDouble: |
| 6075 | return kLoadDWord; |
| 6076 | default: |
| 6077 | LOG(FATAL) << "Unreachable type " << type; |
| 6078 | UNREACHABLE(); |
| 6079 | } |
| 6080 | } |
| 6081 | |
| 6082 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 6083 | switch (type) { |
| 6084 | case Primitive::kPrimNot: |
| 6085 | return kStoreWord; |
| 6086 | case Primitive::kPrimBoolean: |
| 6087 | case Primitive::kPrimByte: |
| 6088 | return kStoreByte; |
| 6089 | case Primitive::kPrimChar: |
| 6090 | case Primitive::kPrimShort: |
| 6091 | return kStoreHalfword; |
| 6092 | case Primitive::kPrimInt: |
| 6093 | return kStoreWord; |
| 6094 | case Primitive::kPrimLong: |
| 6095 | return kStoreWordPair; |
| 6096 | case Primitive::kPrimFloat: |
| 6097 | return kStoreSWord; |
| 6098 | case Primitive::kPrimDouble: |
| 6099 | return kStoreDWord; |
| 6100 | default: |
| 6101 | LOG(FATAL) << "Unreachable type " << type; |
| 6102 | UNREACHABLE(); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 6107 | Location out_loc, |
| 6108 | Register base, |
| 6109 | Register reg_offset, |
| 6110 | Condition cond) { |
| 6111 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6112 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 6113 | |
| 6114 | switch (type) { |
| 6115 | case Primitive::kPrimByte: |
| 6116 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6117 | break; |
| 6118 | case Primitive::kPrimBoolean: |
| 6119 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6120 | break; |
| 6121 | case Primitive::kPrimShort: |
| 6122 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6123 | break; |
| 6124 | case Primitive::kPrimChar: |
| 6125 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6126 | break; |
| 6127 | case Primitive::kPrimNot: |
| 6128 | case Primitive::kPrimInt: |
| 6129 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 6130 | break; |
| 6131 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 6132 | case Primitive::kPrimLong: |
| 6133 | case Primitive::kPrimFloat: |
| 6134 | case Primitive::kPrimDouble: |
| 6135 | default: |
| 6136 | LOG(FATAL) << "Unreachable type " << type; |
| 6137 | UNREACHABLE(); |
| 6138 | } |
| 6139 | } |
| 6140 | |
| 6141 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 6142 | Location loc, |
| 6143 | Register base, |
| 6144 | Register reg_offset, |
| 6145 | Condition cond) { |
| 6146 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 6147 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 6148 | |
| 6149 | switch (type) { |
| 6150 | case Primitive::kPrimByte: |
| 6151 | case Primitive::kPrimBoolean: |
| 6152 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 6153 | break; |
| 6154 | case Primitive::kPrimShort: |
| 6155 | case Primitive::kPrimChar: |
| 6156 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 6157 | break; |
| 6158 | case Primitive::kPrimNot: |
| 6159 | case Primitive::kPrimInt: |
| 6160 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 6161 | break; |
| 6162 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 6163 | case Primitive::kPrimLong: |
| 6164 | case Primitive::kPrimFloat: |
| 6165 | case Primitive::kPrimDouble: |
| 6166 | default: |
| 6167 | LOG(FATAL) << "Unreachable type " << type; |
| 6168 | UNREACHABLE(); |
| 6169 | } |
| 6170 | } |
| 6171 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6172 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6173 | bool object_array_get_with_read_barrier = |
| 6174 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6175 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6176 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 6177 | object_array_get_with_read_barrier ? |
| 6178 | LocationSummary::kCallOnSlowPath : |
| 6179 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6180 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6181 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6182 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6183 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6184 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6185 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 6186 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6187 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6188 | // The output overlaps in the case of an object array get with |
| 6189 | // read barriers enabled: we do not want the move to overwrite the |
| 6190 | // array's location, as we need it to emit the read barrier. |
| 6191 | locations->SetOut( |
| 6192 | Location::RequiresRegister(), |
| 6193 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 6194 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6195 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 6196 | // We need a temporary register for the read barrier marking slow |
| 6197 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 6198 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 6199 | !Runtime::Current()->UseJitCompilation() && |
| 6200 | instruction->GetIndex()->IsConstant()) { |
| 6201 | // Array loads with constant index are treated as field loads. |
| 6202 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 6203 | // constant index loads we need a temporary only if the offset is too big. |
| 6204 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6205 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 6206 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 6207 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6208 | locations->AddTemp(Location::RequiresRegister()); |
| 6209 | } |
| 6210 | // And we always need the reserved entrypoint register. |
| 6211 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6212 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 6213 | !Runtime::Current()->UseJitCompilation() && |
| 6214 | !instruction->GetIndex()->IsConstant()) { |
| 6215 | // We need a non-scratch temporary for the array data pointer. |
| 6216 | locations->AddTemp(Location::RequiresRegister()); |
| 6217 | // And we always need the reserved entrypoint register. |
| 6218 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6219 | } else { |
| 6220 | locations->AddTemp(Location::RequiresRegister()); |
| 6221 | } |
| 6222 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6223 | // Also need a temporary for String compression feature. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6224 | locations->AddTemp(Location::RequiresRegister()); |
| 6225 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 6229 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6230 | Location obj_loc = locations->InAt(0); |
| 6231 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6232 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6233 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6234 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6235 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6236 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6237 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6238 | HInstruction* array_instr = instruction->GetArray(); |
| 6239 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6240 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6241 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6242 | case Primitive::kPrimBoolean: |
| 6243 | case Primitive::kPrimByte: |
| 6244 | case Primitive::kPrimShort: |
| 6245 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6246 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6247 | Register length; |
| 6248 | if (maybe_compressed_char_at) { |
| 6249 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 6250 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 6251 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6252 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6253 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6254 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6255 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6256 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6257 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6258 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6259 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6260 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6261 | "Expecting 0=compressed, 1=uncompressed"); |
| 6262 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6263 | __ LoadFromOffset(kLoadUnsignedByte, |
| 6264 | out_loc.AsRegister<Register>(), |
| 6265 | obj, |
| 6266 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6267 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6268 | __ Bind(&uncompressed_load); |
| 6269 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 6270 | out_loc.AsRegister<Register>(), |
| 6271 | obj, |
| 6272 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6273 | if (done.IsLinked()) { |
| 6274 | __ Bind(&done); |
| 6275 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6276 | } else { |
| 6277 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6278 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6279 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6280 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 6281 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6282 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6283 | Register temp = IP; |
| 6284 | |
| 6285 | if (has_intermediate_address) { |
| 6286 | // We do not need to compute the intermediate address from the array: the |
| 6287 | // input instruction has done it already. See the comment in |
| 6288 | // `TryExtractArrayAccessAddress()`. |
| 6289 | if (kIsDebugBuild) { |
| 6290 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6291 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6292 | } |
| 6293 | temp = obj; |
| 6294 | } else { |
| 6295 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 6296 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6297 | if (maybe_compressed_char_at) { |
| 6298 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6299 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6300 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6301 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6302 | "Expecting 0=compressed, 1=uncompressed"); |
| 6303 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6304 | __ ldrb(out_loc.AsRegister<Register>(), |
| 6305 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6306 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6307 | __ Bind(&uncompressed_load); |
| 6308 | __ ldrh(out_loc.AsRegister<Register>(), |
| 6309 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6310 | if (done.IsLinked()) { |
| 6311 | __ Bind(&done); |
| 6312 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6313 | } else { |
| 6314 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 6315 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6316 | } |
| 6317 | break; |
| 6318 | } |
| 6319 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6320 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 6321 | // The read barrier instrumentation of object ArrayGet |
| 6322 | // instructions does not support the HIntermediateAddress |
| 6323 | // instruction. |
| 6324 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6325 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6326 | static_assert( |
| 6327 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6328 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6329 | // /* HeapReference<Object> */ out = |
| 6330 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6331 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 6332 | Location temp = locations->GetTemp(0); |
| 6333 | // Note that a potential implicit null check is handled in this |
| 6334 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6335 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6336 | if (index.IsConstant()) { |
| 6337 | // Array load with a constant index can be treated as a field load. |
| 6338 | data_offset += helpers::Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 6339 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6340 | out_loc, |
| 6341 | obj, |
| 6342 | data_offset, |
| 6343 | locations->GetTemp(0), |
| 6344 | /* needs_null_check */ false); |
| 6345 | } else { |
| 6346 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 6347 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 6348 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6349 | } else { |
| 6350 | Register out = out_loc.AsRegister<Register>(); |
| 6351 | if (index.IsConstant()) { |
| 6352 | size_t offset = |
| 6353 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6354 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 6355 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6356 | // If read barriers are enabled, emit read barriers other than |
| 6357 | // Baker's using a slow path (and also unpoison the loaded |
| 6358 | // reference, if heap poisoning is enabled). |
| 6359 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6360 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6361 | Register temp = IP; |
| 6362 | |
| 6363 | if (has_intermediate_address) { |
| 6364 | // We do not need to compute the intermediate address from the array: the |
| 6365 | // input instruction has done it already. See the comment in |
| 6366 | // `TryExtractArrayAccessAddress()`. |
| 6367 | if (kIsDebugBuild) { |
| 6368 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6369 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 6370 | } |
| 6371 | temp = obj; |
| 6372 | } else { |
| 6373 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 6374 | } |
| 6375 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6376 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6377 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6378 | // If read barriers are enabled, emit read barriers other than |
| 6379 | // Baker's using a slow path (and also unpoison the loaded |
| 6380 | // reference, if heap poisoning is enabled). |
| 6381 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6382 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6383 | } |
| 6384 | } |
| 6385 | break; |
| 6386 | } |
| 6387 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6388 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6389 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6390 | size_t offset = |
| 6391 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6392 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6393 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6394 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6395 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6396 | } |
| 6397 | break; |
| 6398 | } |
| 6399 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6400 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6401 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6402 | if (index.IsConstant()) { |
| 6403 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6404 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6405 | } else { |
| 6406 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6407 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6408 | } |
| 6409 | break; |
| 6410 | } |
| 6411 | |
| 6412 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6413 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6414 | if (index.IsConstant()) { |
| 6415 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6416 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6417 | } else { |
| 6418 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6419 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6420 | } |
| 6421 | break; |
| 6422 | } |
| 6423 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6424 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6425 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6426 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6427 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6428 | |
| 6429 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6430 | // Potential implicit null checks, in the case of reference |
| 6431 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6432 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6433 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6434 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6438 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6439 | |
| 6440 | bool needs_write_barrier = |
| 6441 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6442 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6443 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6444 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6445 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 6446 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6447 | LocationSummary::kCallOnSlowPath : |
| 6448 | LocationSummary::kNoCall); |
| 6449 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6450 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6451 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6452 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6453 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6454 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6455 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6456 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6457 | if (needs_write_barrier) { |
| 6458 | // Temporary registers for the write barrier. |
| 6459 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6460 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6461 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6462 | } |
| 6463 | |
| 6464 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 6465 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6466 | Location array_loc = locations->InAt(0); |
| 6467 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6468 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6469 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6470 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6471 | bool needs_write_barrier = |
| 6472 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6473 | uint32_t data_offset = |
| 6474 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6475 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6476 | HInstruction* array_instr = instruction->GetArray(); |
| 6477 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6478 | |
| 6479 | switch (value_type) { |
| 6480 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6481 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6482 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6483 | case Primitive::kPrimChar: |
| 6484 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6485 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6486 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 6487 | uint32_t full_offset = |
| 6488 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6489 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6490 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6491 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6492 | Register temp = IP; |
| 6493 | |
| 6494 | if (has_intermediate_address) { |
| 6495 | // We do not need to compute the intermediate address from the array: the |
| 6496 | // input instruction has done it already. See the comment in |
| 6497 | // `TryExtractArrayAccessAddress()`. |
| 6498 | if (kIsDebugBuild) { |
| 6499 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6500 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 6501 | } |
| 6502 | temp = array; |
| 6503 | } else { |
| 6504 | __ add(temp, array, ShifterOperand(data_offset)); |
| 6505 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6506 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6507 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6508 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6509 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6510 | } |
| 6511 | break; |
| 6512 | } |
| 6513 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6514 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6515 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6516 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6517 | // See the comment in instruction_simplifier_shared.cc. |
| 6518 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6519 | |
| 6520 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6521 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6522 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6523 | size_t offset = |
| 6524 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6525 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6526 | } else { |
| 6527 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6528 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6529 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6530 | value_loc, |
| 6531 | IP, |
| 6532 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6533 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 6534 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6535 | DCHECK(!needs_write_barrier); |
| 6536 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6537 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6538 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6539 | |
| 6540 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6541 | Location temp1_loc = locations->GetTemp(0); |
| 6542 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6543 | Location temp2_loc = locations->GetTemp(1); |
| 6544 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6545 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6546 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6547 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6548 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6549 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6550 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6551 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6552 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6553 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6554 | codegen_->AddSlowPath(slow_path); |
| 6555 | if (instruction->GetValueCanBeNull()) { |
| 6556 | Label non_zero; |
| 6557 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6558 | if (index.IsConstant()) { |
| 6559 | size_t offset = |
| 6560 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6561 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6562 | } else { |
| 6563 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6564 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6565 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6566 | value_loc, |
| 6567 | IP, |
| 6568 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6569 | } |
| 6570 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6571 | __ b(final_label); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6572 | __ Bind(&non_zero); |
| 6573 | } |
| 6574 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6575 | // Note that when read barriers are enabled, the type checks |
| 6576 | // are performed without read barriers. This is fine, even in |
| 6577 | // the case where a class object is in the from-space after |
| 6578 | // the flip, as a comparison involving such a type would not |
| 6579 | // produce a false positive; it may of course produce a false |
| 6580 | // negative, in which case we would take the ArraySet slow |
| 6581 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6582 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6583 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6584 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6586 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6587 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6588 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6589 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6590 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6591 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6592 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6593 | // nor `temp2`, as we are comparing two poisoned references. |
| 6594 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6595 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6596 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6597 | Label do_put; |
| 6598 | __ b(&do_put, EQ); |
| 6599 | // If heap poisoning is enabled, the `temp1` reference has |
| 6600 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6601 | __ MaybeUnpoisonHeapReference(temp1); |
| 6602 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6603 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6604 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6605 | // If heap poisoning is enabled, no need to unpoison |
| 6606 | // `temp1`, as we are comparing against null below. |
| 6607 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6608 | __ Bind(&do_put); |
| 6609 | } else { |
| 6610 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6611 | } |
| 6612 | } |
| 6613 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6614 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6615 | if (kPoisonHeapReferences) { |
| 6616 | // Note that in the case where `value` is a null reference, |
| 6617 | // we do not enter this block, as a null reference does not |
| 6618 | // need poisoning. |
| 6619 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6620 | __ Mov(temp1, value); |
| 6621 | __ PoisonHeapReference(temp1); |
| 6622 | source = temp1; |
| 6623 | } |
| 6624 | |
| 6625 | if (index.IsConstant()) { |
| 6626 | size_t offset = |
| 6627 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6628 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6629 | } else { |
| 6630 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6631 | |
| 6632 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6633 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6634 | Location::RegisterLocation(source), |
| 6635 | IP, |
| 6636 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6637 | } |
| 6638 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6639 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6640 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6641 | } |
| 6642 | |
| 6643 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6644 | |
| 6645 | if (done.IsLinked()) { |
| 6646 | __ Bind(&done); |
| 6647 | } |
| 6648 | |
| 6649 | if (slow_path != nullptr) { |
| 6650 | __ Bind(slow_path->GetExitLabel()); |
| 6651 | } |
| 6652 | |
| 6653 | break; |
| 6654 | } |
| 6655 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6656 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6657 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6658 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6659 | size_t offset = |
| 6660 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6661 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6662 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6663 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6664 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6665 | } |
| 6666 | break; |
| 6667 | } |
| 6668 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6669 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6670 | Location value = locations->InAt(2); |
| 6671 | DCHECK(value.IsFpuRegister()); |
| 6672 | if (index.IsConstant()) { |
| 6673 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6674 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6675 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6676 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6677 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6678 | } |
| 6679 | break; |
| 6680 | } |
| 6681 | |
| 6682 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6683 | Location value = locations->InAt(2); |
| 6684 | DCHECK(value.IsFpuRegisterPair()); |
| 6685 | if (index.IsConstant()) { |
| 6686 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6687 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6688 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6689 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6690 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6691 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6692 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6693 | break; |
| 6694 | } |
| 6695 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6696 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6697 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6698 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6699 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6700 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6701 | // Objects are handled in the switch. |
| 6702 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6703 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6704 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6708 | LocationSummary* locations = |
| 6709 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6710 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6711 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6712 | } |
| 6713 | |
| 6714 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6715 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6716 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6717 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6718 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6719 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6720 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6721 | // Mask out compression flag from String's array length. |
| 6722 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6723 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6724 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6725 | } |
| 6726 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6727 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6728 | LocationSummary* locations = |
| 6729 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6730 | |
| 6731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6732 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6733 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6734 | } |
| 6735 | |
| 6736 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6737 | LocationSummary* locations = instruction->GetLocations(); |
| 6738 | Location out = locations->Out(); |
| 6739 | Location first = locations->InAt(0); |
| 6740 | Location second = locations->InAt(1); |
| 6741 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6742 | if (second.IsRegister()) { |
| 6743 | __ add(out.AsRegister<Register>(), |
| 6744 | first.AsRegister<Register>(), |
| 6745 | ShifterOperand(second.AsRegister<Register>())); |
| 6746 | } else { |
| 6747 | __ AddConstant(out.AsRegister<Register>(), |
| 6748 | first.AsRegister<Register>(), |
| 6749 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6750 | } |
| 6751 | } |
| 6752 | |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6753 | void LocationsBuilderARM::VisitIntermediateAddressIndex(HIntermediateAddressIndex* instruction) { |
| 6754 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6755 | } |
| 6756 | |
| 6757 | void InstructionCodeGeneratorARM::VisitIntermediateAddressIndex( |
| 6758 | HIntermediateAddressIndex* instruction) { |
| 6759 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6760 | } |
| 6761 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6762 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6763 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6764 | InvokeRuntimeCallingConvention calling_convention; |
| 6765 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6766 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6767 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6768 | |
| 6769 | HInstruction* index = instruction->InputAt(0); |
| 6770 | HInstruction* length = instruction->InputAt(1); |
| 6771 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6772 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6773 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6774 | // locations. |
| 6775 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6776 | locations->SetInAt(0, both_const |
| 6777 | ? Location::ConstantLocation(index->AsConstant()) |
| 6778 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6779 | locations->SetInAt(1, both_const |
| 6780 | ? Location::ConstantLocation(length->AsConstant()) |
| 6781 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6785 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6786 | Location index_loc = locations->InAt(0); |
| 6787 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6788 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6789 | if (length_loc.IsConstant()) { |
| 6790 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6791 | if (index_loc.IsConstant()) { |
| 6792 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6793 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6794 | if (index < 0 || index >= length) { |
| 6795 | SlowPathCodeARM* slow_path = |
| 6796 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6797 | codegen_->AddSlowPath(slow_path); |
| 6798 | __ b(slow_path->GetEntryLabel()); |
| 6799 | } else { |
| 6800 | // Some optimization after BCE may have generated this, and we should not |
| 6801 | // generate a bounds check if it is a valid range. |
| 6802 | } |
| 6803 | return; |
| 6804 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6805 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6806 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6807 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6808 | codegen_->AddSlowPath(slow_path); |
| 6809 | __ b(slow_path->GetEntryLabel(), HS); |
| 6810 | } else { |
| 6811 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6812 | if (index_loc.IsConstant()) { |
| 6813 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6814 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6815 | } else { |
| 6816 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6817 | } |
| 6818 | codegen_->AddSlowPath(slow_path); |
| 6819 | __ b(slow_path->GetEntryLabel(), LS); |
| 6820 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6821 | } |
| 6822 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6823 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6824 | Register card, |
| 6825 | Register object, |
| 6826 | Register value, |
| 6827 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6828 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6829 | if (can_be_null) { |
| 6830 | __ CompareAndBranchIfZero(value, &is_null); |
| 6831 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6832 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6833 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6834 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6835 | if (can_be_null) { |
| 6836 | __ Bind(&is_null); |
| 6837 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6838 | } |
| 6839 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6840 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6841 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6845 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6846 | } |
| 6847 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6848 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6849 | LocationSummary* locations = |
| 6850 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6851 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6855 | HBasicBlock* block = instruction->GetBlock(); |
| 6856 | if (block->GetLoopInformation() != nullptr) { |
| 6857 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6858 | // The back edge will generate the suspend check. |
| 6859 | return; |
| 6860 | } |
| 6861 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6862 | // The goto will generate the suspend check. |
| 6863 | return; |
| 6864 | } |
| 6865 | GenerateSuspendCheck(instruction, nullptr); |
| 6866 | } |
| 6867 | |
| 6868 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6869 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6870 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6871 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6872 | if (slow_path == nullptr) { |
| 6873 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6874 | instruction->SetSlowPath(slow_path); |
| 6875 | codegen_->AddSlowPath(slow_path); |
| 6876 | if (successor != nullptr) { |
| 6877 | DCHECK(successor->IsLoopHeader()); |
| 6878 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6879 | } |
| 6880 | } else { |
| 6881 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6882 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6883 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6884 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6885 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6886 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6887 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6888 | __ Bind(slow_path->GetReturnLabel()); |
| 6889 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6890 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6891 | __ b(slow_path->GetEntryLabel()); |
| 6892 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6893 | } |
| 6894 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6895 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6896 | return codegen_->GetAssembler(); |
| 6897 | } |
| 6898 | |
| 6899 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6900 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6901 | Location source = move->GetSource(); |
| 6902 | Location destination = move->GetDestination(); |
| 6903 | |
| 6904 | if (source.IsRegister()) { |
| 6905 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6906 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6907 | } else if (destination.IsFpuRegister()) { |
| 6908 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6909 | } else { |
| 6910 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6911 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6912 | SP, destination.GetStackIndex()); |
| 6913 | } |
| 6914 | } else if (source.IsStackSlot()) { |
| 6915 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6916 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6917 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6918 | } else if (destination.IsFpuRegister()) { |
| 6919 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6920 | } else { |
| 6921 | DCHECK(destination.IsStackSlot()); |
| 6922 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6923 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6924 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6925 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6926 | if (destination.IsRegister()) { |
| 6927 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6928 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6929 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6930 | } else { |
| 6931 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6932 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6933 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6934 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6935 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6936 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6937 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6938 | } else if (destination.IsRegisterPair()) { |
| 6939 | DCHECK(ExpectedPairLayout(destination)); |
| 6940 | __ LoadFromOffset( |
| 6941 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6942 | } else { |
| 6943 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6944 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6945 | SP, |
| 6946 | source.GetStackIndex()); |
| 6947 | } |
| 6948 | } else if (source.IsRegisterPair()) { |
| 6949 | if (destination.IsRegisterPair()) { |
| 6950 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6951 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6952 | } else if (destination.IsFpuRegisterPair()) { |
| 6953 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6954 | source.AsRegisterPairLow<Register>(), |
| 6955 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6956 | } else { |
| 6957 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6958 | DCHECK(ExpectedPairLayout(source)); |
| 6959 | __ StoreToOffset( |
| 6960 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6961 | } |
| 6962 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6963 | if (destination.IsRegisterPair()) { |
| 6964 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6965 | destination.AsRegisterPairHigh<Register>(), |
| 6966 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6967 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6968 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6969 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6970 | } else { |
| 6971 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6972 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6973 | SP, |
| 6974 | destination.GetStackIndex()); |
| 6975 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6976 | } else { |
| 6977 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6978 | HConstant* constant = source.GetConstant(); |
| 6979 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6980 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6981 | if (destination.IsRegister()) { |
| 6982 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6983 | } else { |
| 6984 | DCHECK(destination.IsStackSlot()); |
| 6985 | __ LoadImmediate(IP, value); |
| 6986 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6987 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6988 | } else if (constant->IsLongConstant()) { |
| 6989 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6990 | if (destination.IsRegisterPair()) { |
| 6991 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6992 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6993 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6994 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6995 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6996 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6997 | __ LoadImmediate(IP, High32Bits(value)); |
| 6998 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6999 | } |
| 7000 | } else if (constant->IsDoubleConstant()) { |
| 7001 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7002 | if (destination.IsFpuRegisterPair()) { |
| 7003 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7004 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7005 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 7006 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7007 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 7008 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 7009 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 7010 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 7011 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7012 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 7013 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7014 | float value = constant->AsFloatConstant()->GetValue(); |
| 7015 | if (destination.IsFpuRegister()) { |
| 7016 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 7017 | } else { |
| 7018 | DCHECK(destination.IsStackSlot()); |
| 7019 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 7020 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 7021 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 7022 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 7027 | __ Mov(IP, reg); |
| 7028 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 7029 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 7030 | } |
| 7031 | |
| 7032 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 7033 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 7034 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 7035 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 7036 | SP, mem1 + stack_offset); |
| 7037 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 7038 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 7039 | SP, mem2 + stack_offset); |
| 7040 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 7041 | } |
| 7042 | |
| 7043 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7044 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7045 | Location source = move->GetSource(); |
| 7046 | Location destination = move->GetDestination(); |
| 7047 | |
| 7048 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7049 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 7050 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 7051 | __ Mov(IP, source.AsRegister<Register>()); |
| 7052 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 7053 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7054 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7055 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7056 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7057 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7058 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 7059 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7060 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7061 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7062 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7063 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7064 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7065 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7066 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7067 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7068 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 7069 | destination.AsRegisterPairHigh<Register>(), |
| 7070 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7071 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7072 | Register low_reg = source.IsRegisterPair() |
| 7073 | ? source.AsRegisterPairLow<Register>() |
| 7074 | : destination.AsRegisterPairLow<Register>(); |
| 7075 | int mem = source.IsRegisterPair() |
| 7076 | ? destination.GetStackIndex() |
| 7077 | : source.GetStackIndex(); |
| 7078 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7079 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7080 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7081 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7082 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7083 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 7084 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7085 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7086 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7087 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7088 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 7089 | DRegister reg = source.IsFpuRegisterPair() |
| 7090 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 7091 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 7092 | int mem = source.IsFpuRegisterPair() |
| 7093 | ? destination.GetStackIndex() |
| 7094 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7095 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7096 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 7097 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 7098 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 7099 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 7100 | : destination.AsFpuRegister<SRegister>(); |
| 7101 | int mem = source.IsFpuRegister() |
| 7102 | ? destination.GetStackIndex() |
| 7103 | : source.GetStackIndex(); |
| 7104 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7105 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7106 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 7107 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7108 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7109 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 7110 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7111 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 7112 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 7113 | } |
| 7114 | } |
| 7115 | |
| 7116 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 7117 | __ Push(static_cast<Register>(reg)); |
| 7118 | } |
| 7119 | |
| 7120 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 7121 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7122 | } |
| 7123 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7124 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 7125 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7126 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7127 | case HLoadClass::LoadKind::kInvalid: |
| 7128 | LOG(FATAL) << "UNREACHABLE"; |
| 7129 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7130 | case HLoadClass::LoadKind::kReferrersClass: |
| 7131 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7132 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7133 | case HLoadClass::LoadKind::kBssEntry: |
| 7134 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7135 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7136 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7137 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7138 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7139 | case HLoadClass::LoadKind::kBootImageAddress: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7140 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 7141 | break; |
| 7142 | } |
| 7143 | return desired_class_load_kind; |
| 7144 | } |
| 7145 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7146 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7147 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 7148 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7149 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7150 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7151 | cls, |
| 7152 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7153 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7154 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7155 | return; |
| 7156 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7157 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7158 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7159 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7160 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7161 | ? LocationSummary::kCallOnSlowPath |
| 7162 | : LocationSummary::kNoCall; |
| 7163 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7164 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7165 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7166 | } |
| 7167 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7168 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7170 | } |
| 7171 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7172 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7173 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7174 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 7175 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7176 | // to the custom calling convention) or by marking, so we request a different temp. |
| 7177 | locations->AddTemp(Location::RequiresRegister()); |
| 7178 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7179 | InvokeRuntimeCallingConvention calling_convention; |
| 7180 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7181 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7182 | // that the the kPrimNot result register is the same as the first argument register. |
| 7183 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 7184 | } else { |
| 7185 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7186 | } |
| 7187 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7188 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7189 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 7190 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 7191 | !Runtime::Current()->UseJitCompilation())) { |
| 7192 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 7193 | } |
| 7194 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7195 | } |
| 7196 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7197 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7198 | // move. |
| 7199 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7200 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 7201 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 7202 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7203 | return; |
| 7204 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7205 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 7206 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7207 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7208 | Location out_loc = locations->Out(); |
| 7209 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7210 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7211 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7212 | ? kWithoutReadBarrier |
| 7213 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7214 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7215 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7216 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7217 | DCHECK(!cls->CanCallRuntime()); |
| 7218 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7219 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7220 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7221 | GenerateGcRootFieldLoad(cls, |
| 7222 | out_loc, |
| 7223 | current_method, |
| 7224 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7225 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7226 | break; |
| 7227 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7228 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7229 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7230 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7231 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7232 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 7233 | __ BindTrackedLabel(&labels->movw_label); |
| 7234 | __ movw(out, /* placeholder */ 0u); |
| 7235 | __ BindTrackedLabel(&labels->movt_label); |
| 7236 | __ movt(out, /* placeholder */ 0u); |
| 7237 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7238 | __ add(out, out, ShifterOperand(PC)); |
| 7239 | break; |
| 7240 | } |
| 7241 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7242 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7243 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7244 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 7245 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7246 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7247 | break; |
| 7248 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7249 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7250 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7251 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7252 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7253 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7254 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7255 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7256 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7257 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7258 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7259 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7260 | __ add(temp, temp, ShifterOperand(PC)); |
| 7261 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7262 | generate_null_check = true; |
| 7263 | break; |
| 7264 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7265 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 7266 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7267 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7268 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7269 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7270 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7271 | break; |
| 7272 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7273 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7274 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7275 | LOG(FATAL) << "UNREACHABLE"; |
| 7276 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7277 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7278 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7279 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7280 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7281 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7282 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 7283 | codegen_->AddSlowPath(slow_path); |
| 7284 | if (generate_null_check) { |
| 7285 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7286 | } |
| 7287 | if (cls->MustGenerateClinitCheck()) { |
| 7288 | GenerateClassInitializationCheck(slow_path, out); |
| 7289 | } else { |
| 7290 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7291 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 7296 | LocationSummary* locations = |
| 7297 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 7298 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7299 | if (check->HasUses()) { |
| 7300 | locations->SetOut(Location::SameAsFirstInput()); |
| 7301 | } |
| 7302 | } |
| 7303 | |
| 7304 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7305 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7306 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7307 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7308 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7309 | GenerateClassInitializationCheck(slow_path, |
| 7310 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7311 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7312 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 7313 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7314 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 7315 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 7316 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 7317 | __ b(slow_path->GetEntryLabel(), LT); |
| 7318 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 7319 | // properly. Therefore, we do a memory fence. |
| 7320 | __ dmb(ISH); |
| 7321 | __ Bind(slow_path->GetExitLabel()); |
| 7322 | } |
| 7323 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7324 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 7325 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7326 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7327 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7328 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 7329 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7330 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7331 | case HLoadString::LoadKind::kJitTableAddress: |
| 7332 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 7333 | break; |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 7334 | case HLoadString::LoadKind::kBootImageAddress: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7335 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 7336 | break; |
| 7337 | } |
| 7338 | return desired_string_load_kind; |
| 7339 | } |
| 7340 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7341 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7342 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 7343 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7344 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7345 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7346 | locations->SetOut(Location::RegisterLocation(R0)); |
| 7347 | } else { |
| 7348 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7349 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7350 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7351 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 7352 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 7353 | // 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] | 7354 | locations->AddTemp(Location::RequiresRegister()); |
| 7355 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 7356 | InvokeRuntimeCallingConvention calling_convention; |
| 7357 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7358 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 7359 | // that the the kPrimNot result register is the same as the first argument register. |
| 7360 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7361 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 7362 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 7363 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7364 | } else { |
| 7365 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7366 | } |
| 7367 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7368 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7369 | } |
| 7370 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7371 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7372 | // move. |
| 7373 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 7374 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7375 | Location out_loc = locations->Out(); |
| 7376 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7377 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7378 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7379 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7380 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7381 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7382 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7383 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7384 | __ BindTrackedLabel(&labels->movw_label); |
| 7385 | __ movw(out, /* placeholder */ 0u); |
| 7386 | __ BindTrackedLabel(&labels->movt_label); |
| 7387 | __ movt(out, /* placeholder */ 0u); |
| 7388 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7389 | __ add(out, out, ShifterOperand(PC)); |
| 7390 | return; // No dex cache slow path. |
| 7391 | } |
| 7392 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7393 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7394 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7395 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7396 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7397 | return; // No dex cache slow path. |
| 7398 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7399 | case HLoadString::LoadKind::kBssEntry: { |
| 7400 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7401 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7402 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7403 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7404 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7405 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7406 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7407 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7408 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7409 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7410 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7411 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7412 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7413 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 7414 | codegen_->AddSlowPath(slow_path); |
| 7415 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7416 | __ Bind(slow_path->GetExitLabel()); |
| 7417 | return; |
| 7418 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7419 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7420 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7421 | load->GetStringIndex(), |
| 7422 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7423 | // /* GcRoot<mirror::String> */ out = *out |
| 7424 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7425 | return; |
| 7426 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7427 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7428 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7429 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7430 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7431 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 7432 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 7433 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7434 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7435 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7436 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7437 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7438 | } |
| 7439 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7440 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7441 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7442 | } |
| 7443 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7444 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 7445 | LocationSummary* locations = |
| 7446 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7447 | locations->SetOut(Location::RequiresRegister()); |
| 7448 | } |
| 7449 | |
| 7450 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7451 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7452 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7453 | } |
| 7454 | |
| 7455 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 7456 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7457 | } |
| 7458 | |
| 7459 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7460 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7461 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7462 | } |
| 7463 | |
| 7464 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 7465 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7466 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7467 | InvokeRuntimeCallingConvention calling_convention; |
| 7468 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7469 | } |
| 7470 | |
| 7471 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7472 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7473 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7474 | } |
| 7475 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7476 | // Temp is used for read barrier. |
| 7477 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7478 | if (kEmitCompilerReadBarrier && |
| 7479 | (kUseBakerReadBarrier || |
| 7480 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7481 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7482 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7483 | return 1; |
| 7484 | } |
| 7485 | return 0; |
| 7486 | } |
| 7487 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7488 | // 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] | 7489 | // interface pointer, one for loading the current interface. |
| 7490 | // The other checks have one temp for loading the object's class. |
| 7491 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7492 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7493 | return 3; |
| 7494 | } |
| 7495 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7496 | } |
| 7497 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7498 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7499 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7500 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7501 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7502 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7503 | case TypeCheckKind::kExactCheck: |
| 7504 | case TypeCheckKind::kAbstractClassCheck: |
| 7505 | case TypeCheckKind::kClassHierarchyCheck: |
| 7506 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7507 | call_kind = |
| 7508 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7509 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7510 | break; |
| 7511 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7512 | case TypeCheckKind::kUnresolvedCheck: |
| 7513 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7514 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7515 | break; |
| 7516 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7517 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7518 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7519 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7520 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7521 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7522 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7523 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7524 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7525 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7526 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7527 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7528 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7529 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7530 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7531 | } |
| 7532 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7533 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7534 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7535 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7536 | Location obj_loc = locations->InAt(0); |
| 7537 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7538 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7539 | Location out_loc = locations->Out(); |
| 7540 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7541 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7542 | DCHECK_LE(num_temps, 1u); |
| 7543 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7544 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7545 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7546 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7547 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7548 | Label done; |
| 7549 | Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7550 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7551 | |
| 7552 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7553 | // avoid null check if we know obj is not null. |
| 7554 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7555 | DCHECK_NE(out, obj); |
| 7556 | __ LoadImmediate(out, 0); |
| 7557 | __ CompareAndBranchIfZero(obj, final_label); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7558 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7559 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7560 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7561 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7562 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7563 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7564 | out_loc, |
| 7565 | obj_loc, |
| 7566 | class_offset, |
| 7567 | maybe_temp_loc, |
| 7568 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7569 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7570 | __ cmp(out, ShifterOperand(cls)); |
| 7571 | // We speculatively set the result to false without changing the condition |
| 7572 | // flags, which allows us to avoid some branching later. |
| 7573 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7574 | |
| 7575 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7576 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7577 | // encoding can be used. |
| 7578 | if (ArmAssembler::IsLowRegister(out)) { |
| 7579 | __ it(EQ); |
| 7580 | __ mov(out, ShifterOperand(1), EQ); |
| 7581 | } else { |
| 7582 | __ b(final_label, NE); |
| 7583 | __ LoadImmediate(out, 1); |
| 7584 | } |
| 7585 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7586 | break; |
| 7587 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7588 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7589 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7590 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7591 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7592 | out_loc, |
| 7593 | obj_loc, |
| 7594 | class_offset, |
| 7595 | maybe_temp_loc, |
| 7596 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7597 | // If the class is abstract, we eagerly fetch the super class of the |
| 7598 | // object to avoid doing a comparison we know will fail. |
| 7599 | Label loop; |
| 7600 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7601 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7602 | GenerateReferenceLoadOneRegister(instruction, |
| 7603 | out_loc, |
| 7604 | super_offset, |
| 7605 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7606 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7607 | // 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] | 7608 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7609 | __ cmp(out, ShifterOperand(cls)); |
| 7610 | __ b(&loop, NE); |
| 7611 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7612 | break; |
| 7613 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7614 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7615 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7616 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7617 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7618 | out_loc, |
| 7619 | obj_loc, |
| 7620 | class_offset, |
| 7621 | maybe_temp_loc, |
| 7622 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7623 | // Walk over the class hierarchy to find a match. |
| 7624 | Label loop, success; |
| 7625 | __ Bind(&loop); |
| 7626 | __ cmp(out, ShifterOperand(cls)); |
| 7627 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7628 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7629 | GenerateReferenceLoadOneRegister(instruction, |
| 7630 | out_loc, |
| 7631 | super_offset, |
| 7632 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7633 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7634 | // This is essentially a null check, but it sets the condition flags to the |
| 7635 | // proper value for the code that follows the loop, i.e. not `EQ`. |
| 7636 | __ cmp(out, ShifterOperand(1)); |
| 7637 | __ b(&loop, HS); |
| 7638 | |
| 7639 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7640 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7641 | // encoding can be used. |
| 7642 | if (ArmAssembler::IsLowRegister(out)) { |
| 7643 | // If `out` is null, we use it for the result, and the condition flags |
| 7644 | // have already been set to `NE`, so the IT block that comes afterwards |
| 7645 | // (and which handles the successful case) turns into a NOP (instead of |
| 7646 | // overwriting `out`). |
| 7647 | __ Bind(&success); |
| 7648 | // There is only one branch to the `success` label (which is bound to this |
| 7649 | // IT block), and it has the same condition, `EQ`, so in that case the MOV |
| 7650 | // is executed. |
| 7651 | __ it(EQ); |
| 7652 | __ mov(out, ShifterOperand(1), EQ); |
| 7653 | } else { |
| 7654 | // 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] | 7655 | __ b(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7656 | __ Bind(&success); |
| 7657 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7658 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7659 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7660 | break; |
| 7661 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7662 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7663 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7664 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7665 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7666 | out_loc, |
| 7667 | obj_loc, |
| 7668 | class_offset, |
| 7669 | maybe_temp_loc, |
| 7670 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7671 | // Do an exact check. |
| 7672 | Label exact_check; |
| 7673 | __ cmp(out, ShifterOperand(cls)); |
| 7674 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7675 | // 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] | 7676 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7677 | GenerateReferenceLoadOneRegister(instruction, |
| 7678 | out_loc, |
| 7679 | component_offset, |
| 7680 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7681 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7682 | // 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] | 7683 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7684 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7685 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7686 | __ cmp(out, ShifterOperand(0)); |
| 7687 | // We speculatively set the result to false without changing the condition |
| 7688 | // flags, which allows us to avoid some branching later. |
| 7689 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7690 | |
| 7691 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7692 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7693 | // encoding can be used. |
| 7694 | if (ArmAssembler::IsLowRegister(out)) { |
| 7695 | __ Bind(&exact_check); |
| 7696 | __ it(EQ); |
| 7697 | __ mov(out, ShifterOperand(1), EQ); |
| 7698 | } else { |
| 7699 | __ b(final_label, NE); |
| 7700 | __ Bind(&exact_check); |
| 7701 | __ LoadImmediate(out, 1); |
| 7702 | } |
| 7703 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7704 | break; |
| 7705 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7706 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7707 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7708 | // No read barrier since the slow path will retry upon failure. |
| 7709 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7710 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7711 | out_loc, |
| 7712 | obj_loc, |
| 7713 | class_offset, |
| 7714 | maybe_temp_loc, |
| 7715 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7716 | __ cmp(out, ShifterOperand(cls)); |
| 7717 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7718 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7719 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7720 | codegen_->AddSlowPath(slow_path); |
| 7721 | __ b(slow_path->GetEntryLabel(), NE); |
| 7722 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7723 | break; |
| 7724 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7725 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7726 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7727 | case TypeCheckKind::kInterfaceCheck: { |
| 7728 | // 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] | 7729 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7730 | // cases. |
| 7731 | // |
| 7732 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7733 | // entry point without resorting to a type checking slow path |
| 7734 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7735 | // require to assign fixed registers for the inputs of this |
| 7736 | // HInstanceOf instruction (following the runtime calling |
| 7737 | // convention), which might be cluttered by the potential first |
| 7738 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7739 | // |
| 7740 | // TODO: Introduce a new runtime entry point taking the object |
| 7741 | // to test (instead of its class) as argument, and let it deal |
| 7742 | // with the read barrier issues. This will let us refactor this |
| 7743 | // case of the `switch` code as it was previously (with a direct |
| 7744 | // call to the runtime not using a type checking slow path). |
| 7745 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7746 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7747 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7748 | /* is_fatal */ false); |
| 7749 | codegen_->AddSlowPath(slow_path); |
| 7750 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7751 | break; |
| 7752 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7753 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7754 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7755 | if (done.IsLinked()) { |
| 7756 | __ Bind(&done); |
| 7757 | } |
| 7758 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7759 | if (slow_path != nullptr) { |
| 7760 | __ Bind(slow_path->GetExitLabel()); |
| 7761 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7762 | } |
| 7763 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7764 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7765 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7766 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7767 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7768 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7769 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7770 | case TypeCheckKind::kExactCheck: |
| 7771 | case TypeCheckKind::kAbstractClassCheck: |
| 7772 | case TypeCheckKind::kClassHierarchyCheck: |
| 7773 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7774 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7775 | LocationSummary::kCallOnSlowPath : |
| 7776 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7777 | break; |
| 7778 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7779 | case TypeCheckKind::kUnresolvedCheck: |
| 7780 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7781 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7782 | break; |
| 7783 | } |
| 7784 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7785 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7786 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7787 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7788 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7789 | } |
| 7790 | |
| 7791 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7792 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7793 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7794 | Location obj_loc = locations->InAt(0); |
| 7795 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7796 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7797 | Location temp_loc = locations->GetTemp(0); |
| 7798 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7799 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7800 | DCHECK_LE(num_temps, 3u); |
| 7801 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7802 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7803 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7804 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7805 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7806 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7807 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7808 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7809 | const uint32_t object_array_data_offset = |
| 7810 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7811 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7812 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7813 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7814 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7815 | bool is_type_check_slow_path_fatal = false; |
| 7816 | if (!kEmitCompilerReadBarrier) { |
| 7817 | is_type_check_slow_path_fatal = |
| 7818 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7819 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7820 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7821 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7822 | !instruction->CanThrowIntoCatchBlock(); |
| 7823 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7824 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7825 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7826 | is_type_check_slow_path_fatal); |
| 7827 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7828 | |
| 7829 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7830 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7831 | // Avoid null check if we know obj is not null. |
| 7832 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7833 | __ CompareAndBranchIfZero(obj, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7834 | } |
| 7835 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7836 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7837 | case TypeCheckKind::kExactCheck: |
| 7838 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7839 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7840 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7841 | temp_loc, |
| 7842 | obj_loc, |
| 7843 | class_offset, |
| 7844 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7845 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7846 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7847 | __ cmp(temp, ShifterOperand(cls)); |
| 7848 | // Jump to slow path for throwing the exception or doing a |
| 7849 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7850 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7851 | break; |
| 7852 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7853 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7854 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7855 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7856 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7857 | temp_loc, |
| 7858 | obj_loc, |
| 7859 | class_offset, |
| 7860 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7861 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7862 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7863 | // If the class is abstract, we eagerly fetch the super class of the |
| 7864 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7865 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7866 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7867 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7868 | GenerateReferenceLoadOneRegister(instruction, |
| 7869 | temp_loc, |
| 7870 | super_offset, |
| 7871 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7872 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7873 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7874 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7875 | // exception. |
| 7876 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7877 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7878 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7879 | __ cmp(temp, ShifterOperand(cls)); |
| 7880 | __ b(&loop, NE); |
| 7881 | break; |
| 7882 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7883 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7884 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7885 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7886 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7887 | temp_loc, |
| 7888 | obj_loc, |
| 7889 | class_offset, |
| 7890 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7891 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7892 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7893 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7894 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7895 | __ Bind(&loop); |
| 7896 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7897 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7898 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7899 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7900 | GenerateReferenceLoadOneRegister(instruction, |
| 7901 | temp_loc, |
| 7902 | super_offset, |
| 7903 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7904 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7905 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7906 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7907 | // exception. |
| 7908 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7909 | // Otherwise, jump to the beginning of the loop. |
| 7910 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7911 | break; |
| 7912 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7913 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7914 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7915 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7916 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7917 | temp_loc, |
| 7918 | obj_loc, |
| 7919 | class_offset, |
| 7920 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7921 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7922 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7923 | // Do an exact check. |
| 7924 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7925 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7926 | |
| 7927 | // 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] | 7928 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7929 | GenerateReferenceLoadOneRegister(instruction, |
| 7930 | temp_loc, |
| 7931 | component_offset, |
| 7932 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7933 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7934 | // If the component type is null, jump to the slow path to throw the exception. |
| 7935 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7936 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7937 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7938 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7939 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7940 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7941 | break; |
| 7942 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7943 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7944 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7945 | // 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] | 7946 | // We cannot directly call the CheckCast runtime entry point |
| 7947 | // without resorting to a type checking slow path here (i.e. by |
| 7948 | // calling InvokeRuntime directly), as it would require to |
| 7949 | // assign fixed registers for the inputs of this HInstanceOf |
| 7950 | // instruction (following the runtime calling convention), which |
| 7951 | // might be cluttered by the potential first read barrier |
| 7952 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7953 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7954 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7955 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7956 | |
| 7957 | case TypeCheckKind::kInterfaceCheck: { |
| 7958 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7959 | // positives by doing this. |
| 7960 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7961 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7962 | temp_loc, |
| 7963 | obj_loc, |
| 7964 | class_offset, |
| 7965 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7966 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7967 | |
| 7968 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7969 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7970 | temp_loc, |
| 7971 | temp_loc, |
| 7972 | iftable_offset, |
| 7973 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7974 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7975 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7976 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7977 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7978 | Label start_loop; |
| 7979 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7980 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7981 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7982 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7983 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7984 | // Go to next interface. |
| 7985 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7986 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7987 | maybe_temp2_loc.AsRegister<Register>(), |
| 7988 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7989 | // Compare the classes and continue the loop if they do not match. |
| 7990 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7991 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7992 | break; |
| 7993 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7994 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7995 | |
| 7996 | if (done.IsLinked()) { |
| 7997 | __ Bind(&done); |
| 7998 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7999 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8000 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 8001 | } |
| 8002 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8003 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8004 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 8005 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8006 | InvokeRuntimeCallingConvention calling_convention; |
| 8007 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 8008 | } |
| 8009 | |
| 8010 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 8011 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8012 | instruction, |
| 8013 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 8014 | if (instruction->IsEnter()) { |
| 8015 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8016 | } else { |
| 8017 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8018 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 8019 | } |
| 8020 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8021 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 8022 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 8023 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8024 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8025 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8026 | LocationSummary* locations = |
| 8027 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8028 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8029 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8030 | // 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] | 8031 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8032 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 8033 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 8037 | HandleBitwiseOperation(instruction); |
| 8038 | } |
| 8039 | |
| 8040 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 8041 | HandleBitwiseOperation(instruction); |
| 8042 | } |
| 8043 | |
| 8044 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 8045 | HandleBitwiseOperation(instruction); |
| 8046 | } |
| 8047 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 8048 | |
| 8049 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8050 | LocationSummary* locations = |
| 8051 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8052 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 8053 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 8054 | |
| 8055 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8056 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8057 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8058 | } |
| 8059 | |
| 8060 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8061 | LocationSummary* locations = instruction->GetLocations(); |
| 8062 | Location first = locations->InAt(0); |
| 8063 | Location second = locations->InAt(1); |
| 8064 | Location out = locations->Out(); |
| 8065 | |
| 8066 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8067 | Register first_reg = first.AsRegister<Register>(); |
| 8068 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 8069 | Register out_reg = out.AsRegister<Register>(); |
| 8070 | |
| 8071 | switch (instruction->GetOpKind()) { |
| 8072 | case HInstruction::kAnd: |
| 8073 | __ bic(out_reg, first_reg, second_reg); |
| 8074 | break; |
| 8075 | case HInstruction::kOr: |
| 8076 | __ orn(out_reg, first_reg, second_reg); |
| 8077 | break; |
| 8078 | // There is no EON on arm. |
| 8079 | case HInstruction::kXor: |
| 8080 | default: |
| 8081 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8082 | UNREACHABLE(); |
| 8083 | } |
| 8084 | return; |
| 8085 | |
| 8086 | } else { |
| 8087 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8088 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8089 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8090 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 8091 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 8092 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8093 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8094 | |
| 8095 | switch (instruction->GetOpKind()) { |
| 8096 | case HInstruction::kAnd: |
| 8097 | __ bic(out_low, first_low, second_low); |
| 8098 | __ bic(out_high, first_high, second_high); |
| 8099 | break; |
| 8100 | case HInstruction::kOr: |
| 8101 | __ orn(out_low, first_low, second_low); |
| 8102 | __ orn(out_high, first_high, second_high); |
| 8103 | break; |
| 8104 | // There is no EON on arm. |
| 8105 | case HInstruction::kXor: |
| 8106 | default: |
| 8107 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8108 | UNREACHABLE(); |
| 8109 | } |
| 8110 | } |
| 8111 | } |
| 8112 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8113 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 8114 | HDataProcWithShifterOp* instruction) { |
| 8115 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 8116 | instruction->GetType() == Primitive::kPrimLong); |
| 8117 | LocationSummary* locations = |
| 8118 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8119 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 8120 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8121 | |
| 8122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8123 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8124 | locations->SetOut(Location::RequiresRegister(), |
| 8125 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8126 | } |
| 8127 | |
| 8128 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 8129 | HDataProcWithShifterOp* instruction) { |
| 8130 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8131 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8132 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8133 | const Location left = locations->InAt(0); |
| 8134 | const Location right = locations->InAt(1); |
| 8135 | const Location out = locations->Out(); |
| 8136 | |
| 8137 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 8138 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 8139 | |
| 8140 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 8141 | ? right.AsRegisterPairLow<Register>() |
| 8142 | : right.AsRegister<Register>(); |
| 8143 | |
| 8144 | GenerateDataProcInstruction(kind, |
| 8145 | out.AsRegister<Register>(), |
| 8146 | left.AsRegister<Register>(), |
| 8147 | ShifterOperand(second, |
| 8148 | ShiftFromOpKind(op_kind), |
| 8149 | instruction->GetShiftAmount()), |
| 8150 | codegen_); |
| 8151 | } else { |
| 8152 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 8153 | |
| 8154 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8155 | const Register second = right.AsRegister<Register>(); |
| 8156 | |
| 8157 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 8158 | GenerateDataProc(kind, |
| 8159 | out, |
| 8160 | left, |
| 8161 | ShifterOperand(second), |
| 8162 | ShifterOperand(second, ASR, 31), |
| 8163 | codegen_); |
| 8164 | } else { |
| 8165 | GenerateLongDataProc(instruction, codegen_); |
| 8166 | } |
| 8167 | } |
| 8168 | } |
| 8169 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8170 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 8171 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8172 | if (value == 0xffffffffu) { |
| 8173 | if (out != first) { |
| 8174 | __ mov(out, ShifterOperand(first)); |
| 8175 | } |
| 8176 | return; |
| 8177 | } |
| 8178 | if (value == 0u) { |
| 8179 | __ mov(out, ShifterOperand(0)); |
| 8180 | return; |
| 8181 | } |
| 8182 | ShifterOperand so; |
| 8183 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 8184 | __ and_(out, first, so); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8185 | } else if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8186 | __ bic(out, first, ShifterOperand(~value)); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8187 | } else { |
| 8188 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8189 | __ ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8190 | } |
| 8191 | } |
| 8192 | |
| 8193 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 8194 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8195 | if (value == 0u) { |
| 8196 | if (out != first) { |
| 8197 | __ mov(out, ShifterOperand(first)); |
| 8198 | } |
| 8199 | return; |
| 8200 | } |
| 8201 | if (value == 0xffffffffu) { |
| 8202 | __ mvn(out, ShifterOperand(0)); |
| 8203 | return; |
| 8204 | } |
| 8205 | ShifterOperand so; |
| 8206 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 8207 | __ orr(out, first, so); |
| 8208 | } else { |
| 8209 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 8210 | __ orn(out, first, ShifterOperand(~value)); |
| 8211 | } |
| 8212 | } |
| 8213 | |
| 8214 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 8215 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8216 | if (value == 0u) { |
| 8217 | if (out != first) { |
| 8218 | __ mov(out, ShifterOperand(first)); |
| 8219 | } |
| 8220 | return; |
| 8221 | } |
| 8222 | __ eor(out, first, ShifterOperand(value)); |
| 8223 | } |
| 8224 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 8225 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 8226 | Location first, |
| 8227 | uint64_t value) { |
| 8228 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8229 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8230 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8231 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8232 | uint32_t value_low = Low32Bits(value); |
| 8233 | uint32_t value_high = High32Bits(value); |
| 8234 | if (value_low == 0u) { |
| 8235 | if (out_low != first_low) { |
| 8236 | __ mov(out_low, ShifterOperand(first_low)); |
| 8237 | } |
| 8238 | __ AddConstant(out_high, first_high, value_high); |
| 8239 | return; |
| 8240 | } |
| 8241 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 8242 | ShifterOperand so; |
| 8243 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 8244 | __ adc(out_high, first_high, so); |
| 8245 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 8246 | __ sbc(out_high, first_high, so); |
| 8247 | } else { |
| 8248 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 8249 | UNREACHABLE(); |
| 8250 | } |
| 8251 | } |
| 8252 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8253 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8254 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8255 | Location first = locations->InAt(0); |
| 8256 | Location second = locations->InAt(1); |
| 8257 | Location out = locations->Out(); |
| 8258 | |
| 8259 | if (second.IsConstant()) { |
| 8260 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8261 | uint32_t value_low = Low32Bits(value); |
| 8262 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 8263 | Register first_reg = first.AsRegister<Register>(); |
| 8264 | Register out_reg = out.AsRegister<Register>(); |
| 8265 | if (instruction->IsAnd()) { |
| 8266 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8267 | } else if (instruction->IsOr()) { |
| 8268 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8269 | } else { |
| 8270 | DCHECK(instruction->IsXor()); |
| 8271 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8272 | } |
| 8273 | } else { |
| 8274 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 8275 | uint32_t value_high = High32Bits(value); |
| 8276 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8277 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8278 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8279 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 8280 | if (instruction->IsAnd()) { |
| 8281 | GenerateAndConst(out_low, first_low, value_low); |
| 8282 | GenerateAndConst(out_high, first_high, value_high); |
| 8283 | } else if (instruction->IsOr()) { |
| 8284 | GenerateOrrConst(out_low, first_low, value_low); |
| 8285 | GenerateOrrConst(out_high, first_high, value_high); |
| 8286 | } else { |
| 8287 | DCHECK(instruction->IsXor()); |
| 8288 | GenerateEorConst(out_low, first_low, value_low); |
| 8289 | GenerateEorConst(out_high, first_high, value_high); |
| 8290 | } |
| 8291 | } |
| 8292 | return; |
| 8293 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8294 | |
| 8295 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8296 | Register first_reg = first.AsRegister<Register>(); |
| 8297 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 8298 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8299 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8300 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8301 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8302 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8303 | } else { |
| 8304 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8305 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8306 | } |
| 8307 | } else { |
| 8308 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8309 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 8310 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 8311 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 8312 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 8313 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 8314 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8315 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8316 | __ and_(out_low, first_low, second_low); |
| 8317 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8318 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8319 | __ orr(out_low, first_low, second_low); |
| 8320 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8321 | } else { |
| 8322 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 8323 | __ eor(out_low, first_low, second_low); |
| 8324 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 8325 | } |
| 8326 | } |
| 8327 | } |
| 8328 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8329 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 8330 | HInstruction* instruction, |
| 8331 | Location out, |
| 8332 | uint32_t offset, |
| 8333 | Location maybe_temp, |
| 8334 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8335 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8336 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 8337 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8338 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8339 | if (kUseBakerReadBarrier) { |
| 8340 | // Load with fast path based Baker's read barrier. |
| 8341 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8342 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8343 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8344 | } else { |
| 8345 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8346 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8347 | // in the following move operation, as we will need it for the |
| 8348 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8349 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8350 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8351 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8352 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8353 | } |
| 8354 | } else { |
| 8355 | // Plain load with no read barrier. |
| 8356 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8357 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8358 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8359 | } |
| 8360 | } |
| 8361 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8362 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 8363 | HInstruction* instruction, |
| 8364 | Location out, |
| 8365 | Location obj, |
| 8366 | uint32_t offset, |
| 8367 | Location maybe_temp, |
| 8368 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8369 | Register out_reg = out.AsRegister<Register>(); |
| 8370 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8371 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 8372 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8373 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8374 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8375 | // Load with fast path based Baker's read barrier. |
| 8376 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8377 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8378 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8379 | } else { |
| 8380 | // Load with slow path based read barrier. |
| 8381 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8382 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8383 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8384 | } |
| 8385 | } else { |
| 8386 | // Plain load with no read barrier. |
| 8387 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8388 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8389 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8390 | } |
| 8391 | } |
| 8392 | |
| 8393 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 8394 | Location root, |
| 8395 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8396 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8397 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8398 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8399 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8400 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8401 | if (kUseBakerReadBarrier) { |
| 8402 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8403 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8404 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8405 | !Runtime::Current()->UseJitCompilation()) { |
| 8406 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8407 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8408 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8409 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8410 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8411 | // |
| 8412 | // We use link-time generated thunks for the slow path. That thunk |
| 8413 | // checks the reference and jumps to the entrypoint if needed. |
| 8414 | // |
| 8415 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8416 | // lr = &return_address; |
| 8417 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8418 | // if (temp != nullptr) { |
| 8419 | // goto gc_root_thunk<root_reg>(lr) |
| 8420 | // } |
| 8421 | // return_address: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8422 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8423 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8424 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8425 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8426 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8427 | Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8428 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8429 | // entrypoint_reg = |
| 8430 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8431 | DCHECK_EQ(IP, 12); |
| 8432 | const int32_t entry_point_offset = |
| 8433 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8434 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8435 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8436 | Label return_address; |
| 8437 | __ AdrCode(LR, &return_address); |
| 8438 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8439 | // Currently the offset is always within range. If that changes, |
| 8440 | // we shall have to split the load the same way as for fields. |
| 8441 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8442 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8443 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8444 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8445 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8446 | EmitPlaceholderBne(codegen_, bne_label); |
| 8447 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8448 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8449 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8450 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8451 | } else { |
| 8452 | // Note that we do not actually check the value of |
| 8453 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8454 | // root or not. Instead, we load into `temp` the read barrier |
| 8455 | // mark entry point corresponding to register `root`. If `temp` |
| 8456 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8457 | // versa. |
| 8458 | // |
| 8459 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8460 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8461 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8462 | // // Slow path. |
| 8463 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8464 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8465 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8466 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8467 | Location temp = Location::RegisterLocation(LR); |
| 8468 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 8469 | instruction, root, /* entrypoint */ temp); |
| 8470 | codegen_->AddSlowPath(slow_path); |
| 8471 | |
| 8472 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8473 | const int32_t entry_point_offset = |
| 8474 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8475 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8476 | // threads are suspended or running a checkpoint. |
| 8477 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 8478 | |
| 8479 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8480 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8481 | static_assert( |
| 8482 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8483 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8484 | "have different sizes."); |
| 8485 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8486 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8487 | "have different sizes."); |
| 8488 | |
| 8489 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8490 | // checking GetIsGcMarking. |
| 8491 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8492 | __ Bind(slow_path->GetExitLabel()); |
| 8493 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8494 | } else { |
| 8495 | // GC root loaded through a slow path for read barriers other |
| 8496 | // than Baker's. |
| 8497 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8498 | __ AddConstant(root_reg, obj, offset); |
| 8499 | // /* mirror::Object* */ root = root->Read() |
| 8500 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8501 | } |
| 8502 | } else { |
| 8503 | // Plain GC root load with no read barrier. |
| 8504 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8505 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8506 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8507 | // do not have to unpoison `root_reg` here. |
| 8508 | } |
| 8509 | } |
| 8510 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8511 | void CodeGeneratorARM::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8512 | DCHECK(kEmitCompilerReadBarrier); |
| 8513 | DCHECK(kUseBakerReadBarrier); |
| 8514 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8515 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8516 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 8517 | } |
| 8518 | } |
| 8519 | } |
| 8520 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8521 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8522 | Location ref, |
| 8523 | Register obj, |
| 8524 | uint32_t offset, |
| 8525 | Location temp, |
| 8526 | bool needs_null_check) { |
| 8527 | DCHECK(kEmitCompilerReadBarrier); |
| 8528 | DCHECK(kUseBakerReadBarrier); |
| 8529 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8530 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8531 | !Runtime::Current()->UseJitCompilation()) { |
| 8532 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8533 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8534 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8535 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8536 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8537 | // |
| 8538 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8539 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8540 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8541 | // |
| 8542 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8543 | // lr = &gray_return_address; |
| 8544 | // if (temp != nullptr) { |
| 8545 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8546 | // } |
| 8547 | // not_gray_return_address: |
| 8548 | // // Original reference load. If the offset is too large to fit |
| 8549 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8550 | // HeapReference<mirror::Object> reference = *(obj+offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8551 | // gray_return_address: |
| 8552 | |
| 8553 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8554 | Register ref_reg = ref.AsRegister<Register>(); |
| 8555 | bool narrow = CanEmitNarrowLdr(ref_reg, obj, offset); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8556 | Register base = obj; |
| 8557 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8558 | base = temp.AsRegister<Register>(); |
| 8559 | DCHECK_NE(base, kBakerCcEntrypointRegister); |
| 8560 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8561 | __ AddConstant(base, obj, offset & ~(kReferenceLoadMinFarOffset - 1u)); |
| 8562 | offset &= (kReferenceLoadMinFarOffset - 1u); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8563 | // Use narrow LDR only for small offsets. Generating narrow encoding LDR for the large |
| 8564 | // offsets with `(offset & (kReferenceLoadMinFarOffset - 1u)) < 32u` would most likely |
| 8565 | // increase the overall code size when taking the generated thunks into account. |
| 8566 | DCHECK(!narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8567 | } |
| 8568 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8569 | uint32_t custom_data = |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8570 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData(base, obj, narrow); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8571 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8572 | |
| 8573 | // entrypoint_reg = |
| 8574 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8575 | DCHECK_EQ(IP, 12); |
| 8576 | const int32_t entry_point_offset = |
| 8577 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8578 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8579 | |
| 8580 | Label return_address; |
| 8581 | __ AdrCode(LR, &return_address); |
| 8582 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8583 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8584 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8585 | DCHECK(!down_cast<Thumb2Assembler*>(GetAssembler())->IsForced32Bit()); |
| 8586 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler()), !narrow); |
| 8587 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8588 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset); |
| 8589 | if (needs_null_check) { |
| 8590 | MaybeRecordImplicitNullCheck(instruction); |
| 8591 | } |
| 8592 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8593 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8594 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8595 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8596 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8597 | return; |
| 8598 | } |
| 8599 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8600 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8601 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8602 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8603 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8604 | 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] | 8605 | } |
| 8606 | |
| 8607 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8608 | Location ref, |
| 8609 | Register obj, |
| 8610 | uint32_t data_offset, |
| 8611 | Location index, |
| 8612 | Location temp, |
| 8613 | bool needs_null_check) { |
| 8614 | DCHECK(kEmitCompilerReadBarrier); |
| 8615 | DCHECK(kUseBakerReadBarrier); |
| 8616 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8617 | static_assert( |
| 8618 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8619 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8620 | ScaleFactor scale_factor = TIMES_4; |
| 8621 | |
| 8622 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8623 | !Runtime::Current()->UseJitCompilation()) { |
| 8624 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8625 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8626 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8627 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8628 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8629 | // |
| 8630 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8631 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8632 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8633 | // |
| 8634 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8635 | // lr = &gray_return_address; |
| 8636 | // if (temp != nullptr) { |
| 8637 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8638 | // } |
| 8639 | // not_gray_return_address: |
| 8640 | // // Original reference load. If the offset is too large to fit |
| 8641 | // // into LDR, we use an adjusted base register here. |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8642 | // HeapReference<mirror::Object> reference = data[index]; |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8643 | // gray_return_address: |
| 8644 | |
| 8645 | DCHECK(index.IsValid()); |
| 8646 | Register index_reg = index.AsRegister<Register>(); |
| 8647 | Register ref_reg = ref.AsRegister<Register>(); |
| 8648 | Register data_reg = temp.AsRegister<Register>(); |
| 8649 | DCHECK_NE(data_reg, kBakerCcEntrypointRegister); |
| 8650 | |
| 8651 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8652 | uint32_t custom_data = |
| 8653 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg); |
| 8654 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8655 | |
| 8656 | // entrypoint_reg = |
| 8657 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8658 | DCHECK_EQ(IP, 12); |
| 8659 | const int32_t entry_point_offset = |
| 8660 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8661 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8662 | __ AddConstant(data_reg, obj, data_offset); |
| 8663 | |
| 8664 | Label return_address; |
| 8665 | __ AdrCode(LR, &return_address); |
| 8666 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8667 | EmitPlaceholderBne(this, bne_label); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8668 | ScopedForce32Bit maybe_force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8669 | int old_position = GetAssembler()->GetBuffer()->GetPosition(); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8670 | __ ldr(ref_reg, Address(data_reg, index_reg, LSL, scale_factor)); |
| 8671 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8672 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8673 | __ Bind(&return_address); |
Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 8674 | DCHECK_EQ(old_position - GetAssembler()->GetBuffer()->GetPosition(), |
| 8675 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8676 | return; |
| 8677 | } |
| 8678 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8679 | // /* HeapReference<Object> */ ref = |
| 8680 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8681 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8682 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8683 | } |
| 8684 | |
| 8685 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8686 | Location ref, |
| 8687 | Register obj, |
| 8688 | uint32_t offset, |
| 8689 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8690 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8691 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8692 | bool needs_null_check) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8693 | DCHECK(kEmitCompilerReadBarrier); |
| 8694 | DCHECK(kUseBakerReadBarrier); |
| 8695 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8696 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8697 | // whether we need to enter the slow path to mark the reference. |
| 8698 | // Then, in the slow path, check the gray bit in the lock word of |
| 8699 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8700 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8701 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8702 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8703 | // instead, we load into `temp2` the read barrier mark entry point |
| 8704 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8705 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8706 | // |
| 8707 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8708 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8709 | // // Slow path. |
| 8710 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8711 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8712 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8713 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8714 | // if (is_gray) { |
| 8715 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8716 | // } |
| 8717 | // } else { |
| 8718 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8719 | // } |
| 8720 | |
| 8721 | Register temp_reg = temp.AsRegister<Register>(); |
| 8722 | |
| 8723 | // Slow path marking the object `ref` when the GC is marking. The |
| 8724 | // entrypoint will already be loaded in `temp2`. |
| 8725 | Location temp2 = Location::RegisterLocation(LR); |
| 8726 | SlowPathCodeARM* slow_path = |
| 8727 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 8728 | instruction, |
| 8729 | ref, |
| 8730 | obj, |
| 8731 | offset, |
| 8732 | index, |
| 8733 | scale_factor, |
| 8734 | needs_null_check, |
| 8735 | temp_reg, |
| 8736 | /* entrypoint */ temp2); |
| 8737 | AddSlowPath(slow_path); |
| 8738 | |
| 8739 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8740 | const int32_t entry_point_offset = |
| 8741 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8742 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8743 | // threads are suspended or running a checkpoint. |
| 8744 | __ LoadFromOffset(kLoadWord, temp2.AsRegister<Register>(), TR, entry_point_offset); |
| 8745 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8746 | // checking GetIsGcMarking. |
| 8747 | __ CompareAndBranchIfNonZero(temp2.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8748 | // Fast path: the GC is not marking: just load the reference. |
| 8749 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8750 | __ Bind(slow_path->GetExitLabel()); |
| 8751 | } |
| 8752 | |
| 8753 | void CodeGeneratorARM::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8754 | Location ref, |
| 8755 | Register obj, |
| 8756 | Location field_offset, |
| 8757 | Location temp, |
| 8758 | bool needs_null_check, |
| 8759 | Register temp2) { |
| 8760 | DCHECK(kEmitCompilerReadBarrier); |
| 8761 | DCHECK(kUseBakerReadBarrier); |
| 8762 | |
| 8763 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8764 | // whether we need to enter the slow path to update the reference |
| 8765 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8766 | // in the lock word of the reference's holder (`obj`) to decide |
| 8767 | // whether to mark `ref` and update the field or not. |
| 8768 | // |
| 8769 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8770 | // instead, we load into `temp3` the read barrier mark entry point |
| 8771 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8772 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8773 | // |
| 8774 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8775 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8776 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8777 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8778 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8779 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8780 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8781 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8782 | // old_ref = ref; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8783 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8784 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8785 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8786 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8787 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8788 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 8789 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8790 | // Slow path updating the object reference at address `obj + |
| 8791 | // field_offset` when the GC is marking. The entrypoint will already |
| 8792 | // be loaded in `temp3`. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8793 | Location temp3 = Location::RegisterLocation(LR); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8794 | SlowPathCodeARM* slow_path = |
| 8795 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 8796 | instruction, |
| 8797 | ref, |
| 8798 | obj, |
| 8799 | /* offset */ 0u, |
| 8800 | /* index */ field_offset, |
| 8801 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8802 | needs_null_check, |
| 8803 | temp_reg, |
| 8804 | temp2, |
| 8805 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8806 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8807 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8808 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8809 | const int32_t entry_point_offset = |
| 8810 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8811 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8812 | // threads are suspended or running a checkpoint. |
| 8813 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8814 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8815 | // checking GetIsGcMarking. |
| 8816 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8817 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8818 | // up-to-date, and we don't need to load the reference). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8819 | __ Bind(slow_path->GetExitLabel()); |
| 8820 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8821 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8822 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8823 | Location ref, |
| 8824 | Register obj, |
| 8825 | uint32_t offset, |
| 8826 | Location index, |
| 8827 | ScaleFactor scale_factor, |
| 8828 | bool needs_null_check) { |
| 8829 | Register ref_reg = ref.AsRegister<Register>(); |
| 8830 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8831 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8832 | // Load types involving an "index": ArrayGet, |
| 8833 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8834 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8835 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8836 | if (index.IsConstant()) { |
| 8837 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8838 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8839 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8840 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8841 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8842 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8843 | // intrinsics, which use a register pair as index ("long |
| 8844 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8845 | Register index_reg = index.IsRegisterPair() |
| 8846 | ? index.AsRegisterPairLow<Register>() |
| 8847 | : index.AsRegister<Register>(); |
| 8848 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8849 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8850 | } |
| 8851 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8852 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8853 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8854 | } |
| 8855 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8856 | if (needs_null_check) { |
| 8857 | MaybeRecordImplicitNullCheck(instruction); |
| 8858 | } |
| 8859 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8860 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8861 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8862 | } |
| 8863 | |
| 8864 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8865 | Location out, |
| 8866 | Location ref, |
| 8867 | Location obj, |
| 8868 | uint32_t offset, |
| 8869 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8870 | DCHECK(kEmitCompilerReadBarrier); |
| 8871 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8872 | // Insert a slow path based read barrier *after* the reference load. |
| 8873 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8874 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8875 | // reference will be carried out by the runtime within the slow |
| 8876 | // path. |
| 8877 | // |
| 8878 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8879 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8880 | // not used by the artReadBarrierSlow entry point. |
| 8881 | // |
| 8882 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8883 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8884 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8885 | AddSlowPath(slow_path); |
| 8886 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8887 | __ b(slow_path->GetEntryLabel()); |
| 8888 | __ Bind(slow_path->GetExitLabel()); |
| 8889 | } |
| 8890 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8891 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8892 | Location out, |
| 8893 | Location ref, |
| 8894 | Location obj, |
| 8895 | uint32_t offset, |
| 8896 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8897 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8898 | // Baker's read barriers shall be handled by the fast path |
| 8899 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8900 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8901 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8902 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8903 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8904 | } else if (kPoisonHeapReferences) { |
| 8905 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8906 | } |
| 8907 | } |
| 8908 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8909 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8910 | Location out, |
| 8911 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8912 | DCHECK(kEmitCompilerReadBarrier); |
| 8913 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8914 | // Insert a slow path based read barrier *after* the GC root load. |
| 8915 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8916 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8917 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8918 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8919 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8920 | AddSlowPath(slow_path); |
| 8921 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8922 | __ b(slow_path->GetEntryLabel()); |
| 8923 | __ Bind(slow_path->GetExitLabel()); |
| 8924 | } |
| 8925 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8926 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8927 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8928 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8929 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8930 | } |
| 8931 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8932 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8933 | Register temp) { |
| 8934 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8935 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8936 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8937 | return location.AsRegister<Register>(); |
| 8938 | } |
| 8939 | // For intrinsics we allow any location, so it may be on the stack. |
| 8940 | if (!location.IsRegister()) { |
| 8941 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8942 | return temp; |
| 8943 | } |
| 8944 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8945 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8946 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8947 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8948 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8949 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 8950 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8951 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8952 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8953 | return temp; |
| 8954 | } |
| 8955 | return location.AsRegister<Register>(); |
| 8956 | } |
| 8957 | |
Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8958 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8959 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8960 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8961 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8962 | uint32_t offset = |
| 8963 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8964 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8965 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8966 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8967 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8968 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8969 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8970 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8971 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| 8972 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 8973 | Register temp_reg = temp.AsRegister<Register>(); |
| 8974 | PcRelativePatchInfo* labels = NewPcRelativeMethodPatch(invoke->GetTargetMethod()); |
| 8975 | __ BindTrackedLabel(&labels->movw_label); |
| 8976 | __ movw(temp_reg, /* placeholder */ 0u); |
| 8977 | __ BindTrackedLabel(&labels->movt_label); |
| 8978 | __ movt(temp_reg, /* placeholder */ 0u); |
| 8979 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8980 | __ add(temp_reg, temp_reg, ShifterOperand(PC)); |
| 8981 | break; |
| 8982 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8983 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8984 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8985 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8986 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8987 | HArmDexCacheArraysBase* base = |
| 8988 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8989 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8990 | temp.AsRegister<Register>()); |
| 8991 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8992 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8993 | break; |
| 8994 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8995 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8996 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8997 | Register method_reg; |
| 8998 | Register reg = temp.AsRegister<Register>(); |
| 8999 | if (current_method.IsRegister()) { |
| 9000 | method_reg = current_method.AsRegister<Register>(); |
| 9001 | } else { |
| 9002 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 9003 | DCHECK(!current_method.IsValid()); |
| 9004 | method_reg = reg; |
| 9005 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 9006 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 9007 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 9008 | __ LoadFromOffset(kLoadWord, |
| 9009 | reg, |
| 9010 | method_reg, |
| 9011 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 9012 | // temp = temp[index_in_cache]; |
| 9013 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 9014 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9015 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 9016 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 9017 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9018 | } |
| 9019 | |
| 9020 | switch (invoke->GetCodePtrLocation()) { |
| 9021 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 9022 | __ bl(GetFrameEntryLabel()); |
| 9023 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9024 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 9025 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 9026 | __ LoadFromOffset( |
| 9027 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 9028 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9029 | // LR() |
| 9030 | __ blx(LR); |
| 9031 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 9032 | } |
| 9033 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 9034 | DCHECK(!IsLeafMethod()); |
| 9035 | } |
| 9036 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9037 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 9038 | Register temp = temp_location.AsRegister<Register>(); |
| 9039 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9040 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 9041 | |
| 9042 | // Use the calling convention instead of the location of the receiver, as |
| 9043 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 9044 | // slow path, the arguments have been moved to the right place, so here we are |
| 9045 | // guaranteed that the receiver is the first register of the calling convention. |
| 9046 | InvokeDexCallingConvention calling_convention; |
| 9047 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9048 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 9049 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 9050 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9051 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 9052 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 9053 | // emit a read barrier for the previous class reference load. |
| 9054 | // However this is not required in practice, as this is an |
| 9055 | // intermediate/temporary reference and because the current |
| 9056 | // concurrent copying collector keeps the from-space memory |
| 9057 | // intact/accessible until the end of the marking phase (the |
| 9058 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9059 | __ MaybeUnpoisonHeapReference(temp); |
| 9060 | // temp = temp->GetMethodAt(method_offset); |
| 9061 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 9062 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 9063 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 9064 | // LR = temp->GetEntryPoint(); |
| 9065 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 9066 | // LR(); |
| 9067 | __ blx(LR); |
| 9068 | } |
| 9069 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9070 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeMethodPatch( |
| 9071 | MethodReference target_method) { |
| 9072 | return NewPcRelativePatch(*target_method.dex_file, |
| 9073 | target_method.dex_method_index, |
| 9074 | &pc_relative_method_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9075 | } |
| 9076 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 9077 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 9078 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9079 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 9080 | } |
| 9081 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9082 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 9083 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 9084 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 9085 | } |
| 9086 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9087 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
| 9088 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 9089 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
| 9090 | } |
| 9091 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9092 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 9093 | const DexFile& dex_file, uint32_t element_offset) { |
| 9094 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 9095 | } |
| 9096 | |
| 9097 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 9098 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 9099 | patches->emplace_back(dex_file, offset_or_index); |
| 9100 | return &patches->back(); |
| 9101 | } |
| 9102 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9103 | Label* CodeGeneratorARM::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 9104 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9105 | return &baker_read_barrier_patches_.back().label; |
| 9106 | } |
| 9107 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9108 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 9109 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9110 | } |
| 9111 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9112 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9113 | dex::StringIndex string_index, |
| 9114 | Handle<mirror::String> handle) { |
| 9115 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 9116 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9117 | return jit_string_patches_.GetOrCreate( |
| 9118 | StringReference(&dex_file, string_index), |
| 9119 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 9120 | } |
| 9121 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9122 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9123 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9124 | Handle<mirror::Class> handle) { |
| 9125 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 9126 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9127 | return jit_class_patches_.GetOrCreate( |
| 9128 | TypeReference(&dex_file, type_index), |
| 9129 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 9130 | } |
| 9131 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9132 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 9133 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 9134 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 9135 | ArenaVector<LinkerPatch>* linker_patches) { |
| 9136 | for (const PcRelativePatchInfo& info : infos) { |
| 9137 | const DexFile& dex_file = info.target_dex_file; |
| 9138 | size_t offset_or_index = info.offset_or_index; |
| 9139 | DCHECK(info.add_pc_label.IsBound()); |
| 9140 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 9141 | // Add MOVW patch. |
| 9142 | DCHECK(info.movw_label.IsBound()); |
| 9143 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 9144 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9145 | // Add MOVT patch. |
| 9146 | DCHECK(info.movt_label.IsBound()); |
| 9147 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 9148 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 9149 | } |
| 9150 | } |
| 9151 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9152 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 9153 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9154 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9155 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9156 | /* MOVW+MOVT for each entry */ 2u * pc_relative_method_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9157 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9158 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9159 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9160 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9161 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9162 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 9163 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9164 | if (GetCompilerOptions().IsBootImage()) { |
| 9165 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeMethodPatch>(pc_relative_method_patches_, |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9166 | linker_patches); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 9167 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 9168 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 9169 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 9170 | linker_patches); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9171 | } else { |
| 9172 | DCHECK(pc_relative_method_patches_.empty()); |
| 9173 | DCHECK(pc_relative_type_patches_.empty()); |
| 9174 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 9175 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9176 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9177 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 9178 | linker_patches); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9179 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 9180 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.Position(), |
| 9181 | info.custom_data)); |
| 9182 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9183 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9184 | } |
| 9185 | |
| 9186 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 9187 | return map->GetOrCreate( |
| 9188 | value, |
| 9189 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 9190 | } |
| 9191 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 9192 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9193 | LocationSummary* locations = |
| 9194 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 9195 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9196 | Location::RequiresRegister()); |
| 9197 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9198 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9199 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9200 | } |
| 9201 | |
| 9202 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9203 | LocationSummary* locations = instr->GetLocations(); |
| 9204 | Register res = locations->Out().AsRegister<Register>(); |
| 9205 | Register accumulator = |
| 9206 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 9207 | Register mul_left = |
| 9208 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 9209 | Register mul_right = |
| 9210 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 9211 | |
| 9212 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9213 | __ mla(res, mul_left, mul_right, accumulator); |
| 9214 | } else { |
| 9215 | __ mls(res, mul_left, mul_right, accumulator); |
| 9216 | } |
| 9217 | } |
| 9218 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 9219 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9220 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9221 | LOG(FATAL) << "Unreachable"; |
| 9222 | } |
| 9223 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 9224 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9225 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 9226 | LOG(FATAL) << "Unreachable"; |
| 9227 | } |
| 9228 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9229 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9230 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9231 | LocationSummary* locations = |
| 9232 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 9233 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9234 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9235 | codegen_->GetAssembler()->IsThumb()) { |
| 9236 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9237 | if (switch_instr->GetStartValue() != 0) { |
| 9238 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9239 | } |
| 9240 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9241 | } |
| 9242 | |
| 9243 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9244 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9245 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9246 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9247 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 9248 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9249 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9250 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9251 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9252 | Register temp_reg = IP; |
| 9253 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9254 | // the immediate, because IP is used as the destination register. For the other |
| 9255 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9256 | // and they can be encoded in the instruction without making use of IP register. |
| 9257 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 9258 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9259 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9260 | // Jump to successors[0] if value == lower_bound. |
| 9261 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 9262 | int32_t last_index = 0; |
| 9263 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9264 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 9265 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9266 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 9267 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9268 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 9269 | } |
| 9270 | if (num_entries - last_index == 2) { |
| 9271 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 9272 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 9273 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9274 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9275 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 9276 | // And the default for any other value. |
| 9277 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9278 | __ b(codegen_->GetLabelOf(default_block)); |
| 9279 | } |
| 9280 | } else { |
| 9281 | // Create a table lookup. |
| 9282 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 9283 | |
| 9284 | // Materialize a pointer to the switch table |
| 9285 | std::vector<Label*> labels(num_entries); |
| 9286 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9287 | for (uint32_t i = 0; i < num_entries; i++) { |
| 9288 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 9289 | } |
| 9290 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 9291 | |
| 9292 | // Remove the bias. |
| 9293 | Register key_reg; |
| 9294 | if (lower_bound != 0) { |
| 9295 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 9296 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 9297 | } else { |
| 9298 | key_reg = value_reg; |
| 9299 | } |
| 9300 | |
| 9301 | // Check whether the value is in the table, jump to default block if not. |
| 9302 | __ CmpConstant(key_reg, num_entries - 1); |
| 9303 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 9304 | |
| 9305 | // Load the displacement from the table. |
| 9306 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 9307 | |
| 9308 | // Dispatch is a direct add to the PC (for Thumb2). |
| 9309 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 9310 | } |
| 9311 | } |
| 9312 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9313 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 9314 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 9315 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9316 | } |
| 9317 | |
| 9318 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 9319 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9320 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 9321 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9322 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9323 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9324 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 9325 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 9326 | __ BindTrackedLabel(&labels->add_pc_label); |
| 9327 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 9328 | } |
| 9329 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 9330 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 9331 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 9332 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 9333 | return; |
| 9334 | } |
| 9335 | |
| 9336 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 9337 | |
| 9338 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 9339 | if (return_loc.Equals(trg)) { |
| 9340 | return; |
| 9341 | } |
| 9342 | |
| 9343 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9344 | // with the last branch. |
| 9345 | if (type == Primitive::kPrimLong) { |
| 9346 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9347 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 9348 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 9349 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9350 | } else if (type == Primitive::kPrimDouble) { |
| 9351 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9352 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 9353 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 9354 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9355 | } else { |
| 9356 | // Let the parallel move resolver take care of all of this. |
| 9357 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 9358 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9359 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9360 | } |
| 9361 | } |
| 9362 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9363 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9364 | LocationSummary* locations = |
| 9365 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 9366 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9367 | locations->SetOut(Location::RequiresRegister()); |
| 9368 | } |
| 9369 | |
| 9370 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9371 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9372 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9373 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9374 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9375 | __ LoadFromOffset(kLoadWord, |
| 9376 | locations->Out().AsRegister<Register>(), |
| 9377 | locations->InAt(0).AsRegister<Register>(), |
| 9378 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9379 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9380 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9381 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9382 | __ LoadFromOffset(kLoadWord, |
| 9383 | locations->Out().AsRegister<Register>(), |
| 9384 | locations->InAt(0).AsRegister<Register>(), |
| 9385 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9386 | __ LoadFromOffset(kLoadWord, |
| 9387 | locations->Out().AsRegister<Register>(), |
| 9388 | locations->Out().AsRegister<Register>(), |
| 9389 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9390 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9391 | } |
| 9392 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9393 | static void PatchJitRootUse(uint8_t* code, |
| 9394 | const uint8_t* roots_data, |
| 9395 | Literal* literal, |
| 9396 | uint64_t index_in_table) { |
| 9397 | DCHECK(literal->GetLabel()->IsBound()); |
| 9398 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 9399 | uintptr_t address = |
| 9400 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9401 | uint8_t* data = code + literal_offset; |
| 9402 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9403 | } |
| 9404 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9405 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9406 | for (const auto& entry : jit_string_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9407 | const StringReference& string_reference = entry.first; |
| 9408 | Literal* table_entry_literal = entry.second; |
| 9409 | const auto it = jit_string_roots_.find(string_reference); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9410 | DCHECK(it != jit_string_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9411 | uint64_t index_in_table = it->second; |
| 9412 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9413 | } |
| 9414 | for (const auto& entry : jit_class_patches_) { |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9415 | const TypeReference& type_reference = entry.first; |
| 9416 | Literal* table_entry_literal = entry.second; |
| 9417 | const auto it = jit_class_roots_.find(type_reference); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9418 | DCHECK(it != jit_class_roots_.end()); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9419 | uint64_t index_in_table = it->second; |
| 9420 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9421 | } |
| 9422 | } |
| 9423 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9424 | #undef __ |
| 9425 | #undef QUICK_ENTRY_POINT |
| 9426 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9427 | } // namespace arm |
| 9428 | } // namespace art |