Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 18 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 19 | #include "arch/arm/asm_support_arm.h" |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 20 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 23 | #include "common_arm.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 24 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 25 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 26 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_arm.h" |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 29 | #include "linker/arm/relative_patcher_thumb2.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 32 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "utils/arm/assembler_arm.h" |
| 34 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 39 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 40 | template<class MirrorType> |
| 41 | class GcRoot; |
| 42 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 43 | namespace arm { |
| 44 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 45 | static bool ExpectedPairLayout(Location location) { |
| 46 | // We expected this for both core and fpu register pairs. |
| 47 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 48 | } |
| 49 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 51 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 52 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 53 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 55 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 56 | static constexpr SRegister kFpuCalleeSaves[] = |
| 57 | { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 58 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 59 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 60 | // S registers. Therefore there is no need to block it. |
| 61 | static constexpr DRegister DTMP = D31; |
| 62 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 63 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 64 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 65 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 66 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| 67 | // For the Baker read barrier implementation using link-generated thunks we need to split |
| 68 | // the offset explicitly. |
| 69 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 70 | |
| 71 | // Flags controlling the use of link-time generated thunks for Baker read barriers. |
| 72 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForFields = true; |
| 73 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForArrays = true; |
| 74 | constexpr bool kBakerReadBarrierLinkTimeThunksEnableForGcRoots = true; |
| 75 | |
| 76 | // The reserved entrypoint register for link-time generated thunks. |
| 77 | const Register kBakerCcEntrypointRegister = R4; |
| 78 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 79 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 80 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 81 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 83 | static inline void CheckLastTempIsBakerCcEntrypointRegister(HInstruction* instruction) { |
| 84 | DCHECK_EQ(static_cast<uint32_t>(kBakerCcEntrypointRegister), |
| 85 | linker::Thumb2RelativePatcher::kBakerCcEntrypointRegister); |
| 86 | DCHECK_NE(instruction->GetLocations()->GetTempCount(), 0u); |
| 87 | DCHECK_EQ(kBakerCcEntrypointRegister, |
| 88 | instruction->GetLocations()->GetTemp( |
| 89 | instruction->GetLocations()->GetTempCount() - 1u).AsRegister<Register>()); |
| 90 | } |
| 91 | |
| 92 | static inline void EmitPlaceholderBne(CodeGeneratorARM* codegen, Label* bne_label) { |
| 93 | DCHECK(down_cast<Thumb2Assembler*>(codegen->GetAssembler())->IsForced32Bit()); |
| 94 | __ BindTrackedLabel(bne_label); |
| 95 | Label placeholder_label; |
| 96 | __ b(&placeholder_label, NE); // Placeholder, patched at link-time. |
| 97 | __ Bind(&placeholder_label); |
| 98 | } |
| 99 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 100 | static constexpr int kRegListThreshold = 4; |
| 101 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 102 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 103 | // for each live D registers they treat two corresponding S registers as live ones. |
| 104 | // |
| 105 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 106 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 107 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 108 | // - decreasing code size |
| 109 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 110 | // restored and then used in regular non SlowPath code as D register. |
| 111 | // |
| 112 | // For the following example (v means the S register is live): |
| 113 | // D names: | D0 | D1 | D2 | D4 | ... |
| 114 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 115 | // Live? | | v | v | v | v | v | v | | ... |
| 116 | // |
| 117 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 118 | // as D registers. |
| 119 | static size_t SaveContiguousSRegisterList(size_t first, |
| 120 | size_t last, |
| 121 | CodeGenerator* codegen, |
| 122 | size_t stack_offset) { |
| 123 | DCHECK_LE(first, last); |
| 124 | if ((first == last) && (first == 0)) { |
| 125 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 126 | return stack_offset; |
| 127 | } |
| 128 | if (first % 2 == 1) { |
| 129 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 130 | } |
| 131 | |
| 132 | bool save_last = false; |
| 133 | if (last % 2 == 0) { |
| 134 | save_last = true; |
| 135 | --last; |
| 136 | } |
| 137 | |
| 138 | if (first < last) { |
| 139 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 140 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 141 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 142 | |
| 143 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 144 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 145 | } else if (number_of_d_regs > 1) { |
| 146 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 147 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 148 | } |
| 149 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 150 | } |
| 151 | |
| 152 | if (save_last) { |
| 153 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 154 | } |
| 155 | |
| 156 | return stack_offset; |
| 157 | } |
| 158 | |
| 159 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 160 | size_t last, |
| 161 | CodeGenerator* codegen, |
| 162 | size_t stack_offset) { |
| 163 | DCHECK_LE(first, last); |
| 164 | if ((first == last) && (first == 0)) { |
| 165 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 166 | return stack_offset; |
| 167 | } |
| 168 | if (first % 2 == 1) { |
| 169 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 170 | } |
| 171 | |
| 172 | bool restore_last = false; |
| 173 | if (last % 2 == 0) { |
| 174 | restore_last = true; |
| 175 | --last; |
| 176 | } |
| 177 | |
| 178 | if (first < last) { |
| 179 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 180 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 181 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 182 | if (number_of_d_regs == 1) { |
| 183 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 184 | } else if (number_of_d_regs > 1) { |
| 185 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 186 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 187 | } |
| 188 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 189 | } |
| 190 | |
| 191 | if (restore_last) { |
| 192 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 193 | } |
| 194 | |
| 195 | return stack_offset; |
| 196 | } |
| 197 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 199 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 200 | size_t orig_offset = stack_offset; |
| 201 | |
| 202 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 203 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 204 | // If the register holds an object, update the stack mask. |
| 205 | if (locations->RegisterContainsObject(i)) { |
| 206 | locations->SetStackBit(stack_offset / kVRegSize); |
| 207 | } |
| 208 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 209 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 210 | saved_core_stack_offsets_[i] = stack_offset; |
| 211 | stack_offset += kArmWordSize; |
| 212 | } |
| 213 | |
| 214 | int reg_num = POPCOUNT(core_spills); |
| 215 | if (reg_num != 0) { |
| 216 | if (reg_num > kRegListThreshold) { |
| 217 | __ StoreList(RegList(core_spills), orig_offset); |
| 218 | } else { |
| 219 | stack_offset = orig_offset; |
| 220 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 221 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 226 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 227 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 228 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 229 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 230 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 231 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 232 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 233 | |
| 234 | stack_offset = orig_offset; |
| 235 | while (fp_spills != 0u) { |
| 236 | uint32_t begin = CTZ(fp_spills); |
| 237 | uint32_t tmp = fp_spills + (1u << begin); |
| 238 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 239 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 240 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 241 | } |
| 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 246 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 247 | size_t orig_offset = stack_offset; |
| 248 | |
| 249 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 250 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 251 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 252 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 253 | stack_offset += kArmWordSize; |
| 254 | } |
| 255 | |
| 256 | int reg_num = POPCOUNT(core_spills); |
| 257 | if (reg_num != 0) { |
| 258 | if (reg_num > kRegListThreshold) { |
| 259 | __ LoadList(RegList(core_spills), orig_offset); |
| 260 | } else { |
| 261 | stack_offset = orig_offset; |
| 262 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 263 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 268 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 269 | while (fp_spills != 0u) { |
| 270 | uint32_t begin = CTZ(fp_spills); |
| 271 | uint32_t tmp = fp_spills + (1u << begin); |
| 272 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 273 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 274 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 275 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 276 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 280 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 281 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 282 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 283 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 284 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 285 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 286 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 287 | // Live registers will be restored in the catch block if caught. |
| 288 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 289 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 290 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 291 | instruction_, |
| 292 | instruction_->GetDexPc(), |
| 293 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 294 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 297 | bool IsFatal() const OVERRIDE { return true; } |
| 298 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 299 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 300 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 301 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 302 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 303 | }; |
| 304 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 305 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 306 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 307 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 308 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 309 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 310 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 311 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 312 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 313 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 316 | bool IsFatal() const OVERRIDE { return true; } |
| 317 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 318 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 319 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 320 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 321 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 322 | }; |
| 323 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 324 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 325 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 326 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 327 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 328 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 329 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 330 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 331 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 332 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 333 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 334 | if (successor_ == nullptr) { |
| 335 | __ b(GetReturnLabel()); |
| 336 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 337 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 338 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 341 | Label* GetReturnLabel() { |
| 342 | DCHECK(successor_ == nullptr); |
| 343 | return &return_label_; |
| 344 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 346 | HBasicBlock* GetSuccessor() const { |
| 347 | return successor_; |
| 348 | } |
| 349 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 350 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 351 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 352 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 353 | // If not null, the block to branch to after the suspend check. |
| 354 | HBasicBlock* const successor_; |
| 355 | |
| 356 | // If `successor_` is null, the label to branch to after the suspend check. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 357 | Label return_label_; |
| 358 | |
| 359 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 360 | }; |
| 361 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 362 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 363 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 364 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 365 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 366 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 367 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 368 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 369 | LocationSummary* locations = instruction_->GetLocations(); |
| 370 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 371 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 372 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 373 | // Live registers will be restored in the catch block if caught. |
| 374 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 375 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 376 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 377 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 378 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 379 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 380 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 381 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 382 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 383 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 385 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 386 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 387 | ? kQuickThrowStringBounds |
| 388 | : kQuickThrowArrayBounds; |
| 389 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 390 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 391 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 394 | bool IsFatal() const OVERRIDE { return true; } |
| 395 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 396 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 397 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 398 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 400 | }; |
| 401 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 402 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 403 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 404 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 405 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 406 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 407 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 408 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 409 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 410 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 411 | Location out = locations->Out(); |
| 412 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 413 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 414 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 415 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 416 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 417 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 418 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 419 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 420 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 421 | bool is_load_class_bss_entry = |
| 422 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 423 | Register entry_address = kNoRegister; |
| 424 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 425 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 426 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 427 | // the kSaveEverything call. |
| 428 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 429 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 430 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 431 | if (temp_is_r0) { |
| 432 | __ mov(entry_address, ShifterOperand(temp)); |
| 433 | } |
| 434 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 435 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 436 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 437 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 438 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 439 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 440 | if (do_clinit_) { |
| 441 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 442 | } else { |
| 443 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 444 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 445 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 446 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 447 | if (is_load_class_bss_entry) { |
| 448 | if (call_saves_everything_except_r0) { |
| 449 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 450 | __ str(R0, Address(entry_address)); |
| 451 | } else { |
| 452 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 453 | Register temp = IP; |
| 454 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 455 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 456 | __ BindTrackedLabel(&labels->movw_label); |
| 457 | __ movw(temp, /* placeholder */ 0u); |
| 458 | __ BindTrackedLabel(&labels->movt_label); |
| 459 | __ movt(temp, /* placeholder */ 0u); |
| 460 | __ BindTrackedLabel(&labels->add_pc_label); |
| 461 | __ add(temp, temp, ShifterOperand(PC)); |
| 462 | __ str(R0, Address(temp)); |
| 463 | } |
| 464 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 465 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 466 | if (out.IsValid()) { |
| 467 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 468 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 469 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 470 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 471 | __ b(GetExitLabel()); |
| 472 | } |
| 473 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 474 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 475 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 476 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 477 | // The class this slow path will load. |
| 478 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 479 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 480 | // The dex PC of `at_`. |
| 481 | const uint32_t dex_pc_; |
| 482 | |
| 483 | // Whether to initialize the class. |
| 484 | const bool do_clinit_; |
| 485 | |
| 486 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 487 | }; |
| 488 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 489 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 490 | public: |
| 491 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 492 | |
| 493 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 494 | DCHECK(instruction_->IsLoadString()); |
| 495 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 496 | LocationSummary* locations = instruction_->GetLocations(); |
| 497 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 498 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 499 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 500 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 501 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 502 | |
| 503 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 504 | __ Bind(GetEntryLabel()); |
| 505 | SaveLiveRegisters(codegen, locations); |
| 506 | |
| 507 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 508 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 509 | // the kSaveEverything call. |
| 510 | Register entry_address = kNoRegister; |
| 511 | if (call_saves_everything_except_r0) { |
| 512 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 513 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 514 | entry_address = temp_is_r0 ? out : temp; |
| 515 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 516 | if (temp_is_r0) { |
| 517 | __ mov(entry_address, ShifterOperand(temp)); |
| 518 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 519 | } |
| 520 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 521 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 522 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 523 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 524 | |
| 525 | // Store the resolved String to the .bss entry. |
| 526 | if (call_saves_everything_except_r0) { |
| 527 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 528 | __ str(R0, Address(entry_address)); |
| 529 | } else { |
| 530 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 531 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 532 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 533 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 534 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 535 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 536 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 537 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 538 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 539 | __ add(temp, temp, ShifterOperand(PC)); |
| 540 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 543 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 544 | RestoreLiveRegisters(codegen, locations); |
| 545 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 546 | __ b(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 550 | |
| 551 | private: |
| 552 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 553 | }; |
| 554 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 555 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 556 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 557 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 558 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 559 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 560 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 561 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 562 | DCHECK(instruction_->IsCheckCast() |
| 563 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 564 | |
| 565 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 566 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 567 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 568 | if (!is_fatal_) { |
| 569 | SaveLiveRegisters(codegen, locations); |
| 570 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 571 | |
| 572 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 573 | // move resolver. |
| 574 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 575 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 576 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 577 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 578 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 579 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 580 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 581 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 582 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 583 | instruction_, |
| 584 | instruction_->GetDexPc(), |
| 585 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 586 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 587 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 588 | } else { |
| 589 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 590 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 591 | instruction_, |
| 592 | instruction_->GetDexPc(), |
| 593 | this); |
| 594 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 595 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 596 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 597 | if (!is_fatal_) { |
| 598 | RestoreLiveRegisters(codegen, locations); |
| 599 | __ b(GetExitLabel()); |
| 600 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 603 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 604 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 605 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 606 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 607 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 608 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 609 | |
| 610 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 611 | }; |
| 612 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 613 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 614 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 615 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 616 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 617 | |
| 618 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 619 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 620 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 621 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 622 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 625 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 626 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 627 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 628 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 629 | }; |
| 630 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 631 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 632 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 633 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 634 | |
| 635 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 636 | LocationSummary* locations = instruction_->GetLocations(); |
| 637 | __ Bind(GetEntryLabel()); |
| 638 | SaveLiveRegisters(codegen, locations); |
| 639 | |
| 640 | InvokeRuntimeCallingConvention calling_convention; |
| 641 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 642 | parallel_move.AddMove( |
| 643 | locations->InAt(0), |
| 644 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 645 | Primitive::kPrimNot, |
| 646 | nullptr); |
| 647 | parallel_move.AddMove( |
| 648 | locations->InAt(1), |
| 649 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 650 | Primitive::kPrimInt, |
| 651 | nullptr); |
| 652 | parallel_move.AddMove( |
| 653 | locations->InAt(2), |
| 654 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 655 | Primitive::kPrimNot, |
| 656 | nullptr); |
| 657 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 658 | |
| 659 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 660 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 661 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 662 | RestoreLiveRegisters(codegen, locations); |
| 663 | __ b(GetExitLabel()); |
| 664 | } |
| 665 | |
| 666 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 667 | |
| 668 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 669 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 670 | }; |
| 671 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 672 | // Abstract base class for read barrier slow paths marking a reference |
| 673 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 674 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 675 | // Argument `entrypoint` must be a register location holding the read |
| 676 | // barrier marking runtime entry point to be invoked. |
| 677 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 678 | protected: |
| 679 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 680 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 681 | DCHECK(kEmitCompilerReadBarrier); |
| 682 | } |
| 683 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 684 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 685 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 686 | // Generate assembly code calling the read barrier marking runtime |
| 687 | // entry point (ReadBarrierMarkRegX). |
| 688 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 689 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 690 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 691 | // No need to save live registers; it's taken care of by the |
| 692 | // entrypoint. Also, there is no need to update the stack mask, |
| 693 | // as this runtime call will not trigger a garbage collection. |
| 694 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 695 | DCHECK_NE(ref_reg, SP); |
| 696 | DCHECK_NE(ref_reg, LR); |
| 697 | DCHECK_NE(ref_reg, PC); |
| 698 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 699 | // as a temporary, it cannot be the entry point's input/output. |
| 700 | DCHECK_NE(ref_reg, IP); |
| 701 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 702 | // "Compact" slow path, saving two moves. |
| 703 | // |
| 704 | // Instead of using the standard runtime calling convention (input |
| 705 | // and output in R0): |
| 706 | // |
| 707 | // R0 <- ref |
| 708 | // R0 <- ReadBarrierMark(R0) |
| 709 | // ref <- R0 |
| 710 | // |
| 711 | // we just use rX (the register containing `ref`) as input and output |
| 712 | // of a dedicated entrypoint: |
| 713 | // |
| 714 | // rX <- ReadBarrierMarkRegX(rX) |
| 715 | // |
| 716 | if (entrypoint_.IsValid()) { |
| 717 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 718 | __ blx(entrypoint_.AsRegister<Register>()); |
| 719 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 720 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 721 | int32_t entry_point_offset = |
| 722 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 723 | // This runtime call does not require a stack map. |
| 724 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 725 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | // The location (register) of the marked object reference. |
| 729 | const Location ref_; |
| 730 | |
| 731 | // The location of the entrypoint if it is already loaded. |
| 732 | const Location entrypoint_; |
| 733 | |
| 734 | private: |
| 735 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 736 | }; |
| 737 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 738 | // Slow path marking an object reference `ref` during a read |
| 739 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 740 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 741 | // |
| 742 | // This means that after the execution of this slow path, `ref` will |
| 743 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 744 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 745 | // probably still be a from-space reference (unless it gets updated by |
| 746 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 747 | // reference (different from `ref`) in `obj.field`). |
| 748 | // |
| 749 | // If `entrypoint` is a valid location it is assumed to already be |
| 750 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 751 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 752 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 753 | public: |
| 754 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 755 | Location ref, |
| 756 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 757 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 758 | DCHECK(kEmitCompilerReadBarrier); |
| 759 | } |
| 760 | |
| 761 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 762 | |
| 763 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 764 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 765 | DCHECK(locations->CanCall()); |
| 766 | if (kIsDebugBuild) { |
| 767 | Register ref_reg = ref_.AsRegister<Register>(); |
| 768 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 769 | } |
| 770 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 771 | << "Unexpected instruction in read barrier marking slow path: " |
| 772 | << instruction_->DebugName(); |
| 773 | |
| 774 | __ Bind(GetEntryLabel()); |
| 775 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 776 | __ b(GetExitLabel()); |
| 777 | } |
| 778 | |
| 779 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 780 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 781 | }; |
| 782 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 783 | // Slow path loading `obj`'s lock word, loading a reference from |
| 784 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 785 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 786 | // read barrier). The field `obj.field` in the object `obj` holding |
| 787 | // this reference does not get updated by this slow path after marking |
| 788 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 789 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 790 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 791 | // This means that after the execution of this slow path, `ref` will |
| 792 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 793 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 794 | // probably still be a from-space reference (unless it gets updated by |
| 795 | // another thread, or if another thread installed another object |
| 796 | // reference (different from `ref`) in `obj.field`). |
| 797 | // |
| 798 | // Argument `entrypoint` must be a register location holding the read |
| 799 | // barrier marking runtime entry point to be invoked. |
| 800 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 801 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 802 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 803 | Location ref, |
| 804 | Register obj, |
| 805 | uint32_t offset, |
| 806 | Location index, |
| 807 | ScaleFactor scale_factor, |
| 808 | bool needs_null_check, |
| 809 | Register temp, |
| 810 | Location entrypoint) |
| 811 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 812 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 813 | offset_(offset), |
| 814 | index_(index), |
| 815 | scale_factor_(scale_factor), |
| 816 | needs_null_check_(needs_null_check), |
| 817 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 818 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 819 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 822 | const char* GetDescription() const OVERRIDE { |
| 823 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 824 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 825 | |
| 826 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 827 | LocationSummary* locations = instruction_->GetLocations(); |
| 828 | Register ref_reg = ref_.AsRegister<Register>(); |
| 829 | DCHECK(locations->CanCall()); |
| 830 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 831 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 832 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 833 | instruction_->IsStaticFieldGet() || |
| 834 | instruction_->IsArrayGet() || |
| 835 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 836 | instruction_->IsInstanceOf() || |
| 837 | instruction_->IsCheckCast() || |
| 838 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 839 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 840 | << "Unexpected instruction in read barrier marking slow path: " |
| 841 | << instruction_->DebugName(); |
| 842 | // The read barrier instrumentation of object ArrayGet |
| 843 | // instructions does not support the HIntermediateAddress |
| 844 | // instruction. |
| 845 | DCHECK(!(instruction_->IsArrayGet() && |
| 846 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 847 | |
| 848 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 849 | |
| 850 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 851 | // inserted after the original load. However, in fast path based |
| 852 | // Baker's read barriers, we need to perform the load of |
| 853 | // mirror::Object::monitor_ *before* the original reference load. |
| 854 | // This load-load ordering is required by the read barrier. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 855 | // The slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 856 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 857 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 858 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 859 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 860 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 861 | // if (is_gray) { |
| 862 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 863 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 864 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 865 | // Note: the original implementation in ReadBarrier::Barrier is |
| 866 | // slightly more complex as it performs additional checks that we do |
| 867 | // not do here for performance reasons. |
| 868 | |
| 869 | // /* int32_t */ monitor = obj->monitor_ |
| 870 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 871 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 872 | if (needs_null_check_) { |
| 873 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 874 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 875 | // /* LockWord */ lock_word = LockWord(monitor) |
| 876 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 877 | "art::LockWord and int32_t have different sizes."); |
| 878 | |
| 879 | // Introduce a dependency on the lock_word including the rb_state, |
| 880 | // which shall prevent load-load reordering without using |
| 881 | // a memory barrier (which would be more expensive). |
| 882 | // `obj` is unchanged by this operation, but its value now depends |
| 883 | // on `temp`. |
| 884 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 885 | |
| 886 | // The actual reference load. |
| 887 | // A possible implicit null check has already been handled above. |
| 888 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 889 | arm_codegen->GenerateRawReferenceLoad( |
| 890 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 891 | |
| 892 | // Mark the object `ref` when `obj` is gray. |
| 893 | // |
| 894 | // if (rb_state == ReadBarrier::GrayState()) |
| 895 | // ref = ReadBarrier::Mark(ref); |
| 896 | // |
| 897 | // Given the numeric representation, it's enough to check the low bit of the |
| 898 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 899 | // which can be a 16-bit instruction unlike the TST immediate. |
| 900 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 901 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 902 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 903 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 904 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 905 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 906 | __ b(GetExitLabel()); |
| 907 | } |
| 908 | |
| 909 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 910 | // The register containing the object holding the marked object reference field. |
| 911 | Register obj_; |
| 912 | // The offset, index and scale factor to access the reference in `obj_`. |
| 913 | uint32_t offset_; |
| 914 | Location index_; |
| 915 | ScaleFactor scale_factor_; |
| 916 | // Is a null check required? |
| 917 | bool needs_null_check_; |
| 918 | // A temporary register used to hold the lock word of `obj_`. |
| 919 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 920 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 921 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 922 | }; |
| 923 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 924 | // Slow path loading `obj`'s lock word, loading a reference from |
| 925 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 926 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 927 | // read barrier). If needed, this slow path also atomically updates |
| 928 | // the field `obj.field` in the object `obj` holding this reference |
| 929 | // after marking (contrary to |
| 930 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 931 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 932 | // |
| 933 | // This means that after the execution of this slow path, both `ref` |
| 934 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 935 | // hold the same to-space reference (unless another thread installed |
| 936 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 937 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 938 | // Argument `entrypoint` must be a register location holding the read |
| 939 | // barrier marking runtime entry point to be invoked. |
| 940 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 941 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 942 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 943 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 944 | Location ref, |
| 945 | Register obj, |
| 946 | uint32_t offset, |
| 947 | Location index, |
| 948 | ScaleFactor scale_factor, |
| 949 | bool needs_null_check, |
| 950 | Register temp1, |
| 951 | Register temp2, |
| 952 | Location entrypoint) |
| 953 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 954 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 955 | offset_(offset), |
| 956 | index_(index), |
| 957 | scale_factor_(scale_factor), |
| 958 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 959 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 960 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 961 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 962 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 965 | const char* GetDescription() const OVERRIDE { |
| 966 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 967 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 968 | |
| 969 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 970 | LocationSummary* locations = instruction_->GetLocations(); |
| 971 | Register ref_reg = ref_.AsRegister<Register>(); |
| 972 | DCHECK(locations->CanCall()); |
| 973 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 974 | DCHECK_NE(ref_reg, temp1_); |
| 975 | |
| 976 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 977 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 978 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 979 | << instruction_->DebugName(); |
| 980 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 981 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 982 | DCHECK_EQ(offset_, 0u); |
| 983 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 984 | // The location of the offset of the marked reference field within `obj_`. |
| 985 | Location field_offset = index_; |
| 986 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 987 | |
| 988 | __ Bind(GetEntryLabel()); |
| 989 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 990 | // The implementation is similar to LoadReferenceWithBakerReadBarrierSlowPathARM's: |
| 991 | // |
| 992 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 993 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 994 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 995 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 996 | // if (is_gray) { |
| 997 | // old_ref = ref; |
| 998 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 999 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
| 1000 | // } |
| 1001 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1002 | // /* int32_t */ monitor = obj->monitor_ |
| 1003 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 1004 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 1005 | if (needs_null_check_) { |
| 1006 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 1007 | } |
| 1008 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1009 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1010 | "art::LockWord and int32_t have different sizes."); |
| 1011 | |
| 1012 | // Introduce a dependency on the lock_word including the rb_state, |
| 1013 | // which shall prevent load-load reordering without using |
| 1014 | // a memory barrier (which would be more expensive). |
| 1015 | // `obj` is unchanged by this operation, but its value now depends |
| 1016 | // on `temp1`. |
| 1017 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 1018 | |
| 1019 | // The actual reference load. |
| 1020 | // A possible implicit null check has already been handled above. |
| 1021 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1022 | arm_codegen->GenerateRawReferenceLoad( |
| 1023 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 1024 | |
| 1025 | // Mark the object `ref` when `obj` is gray. |
| 1026 | // |
| 1027 | // if (rb_state == ReadBarrier::GrayState()) |
| 1028 | // ref = ReadBarrier::Mark(ref); |
| 1029 | // |
| 1030 | // Given the numeric representation, it's enough to check the low bit of the |
| 1031 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1032 | // which can be a 16-bit instruction unlike the TST immediate. |
| 1033 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 1034 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 1035 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 1036 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 1037 | |
| 1038 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 1039 | // Note that we cannot use IP to save the old reference, as IP is |
| 1040 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 1041 | // need the old reference after the call to that entry point. |
| 1042 | DCHECK_NE(temp1_, IP); |
| 1043 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 1044 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1045 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1046 | |
| 1047 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1048 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1049 | // |
| 1050 | // Note that this field could also hold a different object, if |
| 1051 | // another thread had concurrently changed it. In that case, the |
| 1052 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1053 | // (CAS) operation below would abort the CAS, leaving the field |
| 1054 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1055 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1056 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1057 | |
| 1058 | // Update the the holder's field atomically. This may fail if |
| 1059 | // mutator updates before us, but it's OK. This is achieved |
| 1060 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1061 | // memory synchronization ordering, where the expected value is |
| 1062 | // the old reference and the desired value is the new reference. |
| 1063 | |
| 1064 | // Convenience aliases. |
| 1065 | Register base = obj_; |
| 1066 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1067 | // offset ("long offset"), of which only the low part contains |
| 1068 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1069 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1070 | Register expected = temp1_; |
| 1071 | Register value = ref_reg; |
| 1072 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1073 | Register tmp = temp2_; // Value in memory. |
| 1074 | |
| 1075 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1076 | |
| 1077 | if (kPoisonHeapReferences) { |
| 1078 | __ PoisonHeapReference(expected); |
| 1079 | if (value == expected) { |
| 1080 | // Do not poison `value`, as it is the same register as |
| 1081 | // `expected`, which has just been poisoned. |
| 1082 | } else { |
| 1083 | __ PoisonHeapReference(value); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | // do { |
| 1088 | // tmp = [r_ptr] - expected; |
| 1089 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1090 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1091 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1092 | __ Bind(&loop_head); |
| 1093 | |
| 1094 | __ ldrex(tmp, tmp_ptr); |
| 1095 | |
| 1096 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1097 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1098 | __ it(NE); |
| 1099 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1100 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1101 | __ b(&exit_loop, NE); |
| 1102 | |
| 1103 | __ strex(tmp, value, tmp_ptr); |
| 1104 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1105 | __ b(&loop_head, EQ); |
| 1106 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1107 | __ Bind(&exit_loop); |
| 1108 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1109 | if (kPoisonHeapReferences) { |
| 1110 | __ UnpoisonHeapReference(expected); |
| 1111 | if (value == expected) { |
| 1112 | // Do not unpoison `value`, as it is the same register as |
| 1113 | // `expected`, which has just been unpoisoned. |
| 1114 | } else { |
| 1115 | __ UnpoisonHeapReference(value); |
| 1116 | } |
| 1117 | } |
| 1118 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1119 | __ b(GetExitLabel()); |
| 1120 | } |
| 1121 | |
| 1122 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1123 | // The register containing the object holding the marked object reference field. |
| 1124 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1125 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1126 | uint32_t offset_; |
| 1127 | Location index_; |
| 1128 | ScaleFactor scale_factor_; |
| 1129 | // Is a null check required? |
| 1130 | bool needs_null_check_; |
| 1131 | // A temporary register used to hold the lock word of `obj_`; and |
| 1132 | // also to hold the original reference value, when the reference is |
| 1133 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1134 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1135 | // A temporary register used in the implementation of the CAS, to |
| 1136 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1137 | const Register temp2_; |
| 1138 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1139 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1140 | }; |
| 1141 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1142 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1143 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1144 | public: |
| 1145 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1146 | Location out, |
| 1147 | Location ref, |
| 1148 | Location obj, |
| 1149 | uint32_t offset, |
| 1150 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1151 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1152 | out_(out), |
| 1153 | ref_(ref), |
| 1154 | obj_(obj), |
| 1155 | offset_(offset), |
| 1156 | index_(index) { |
| 1157 | DCHECK(kEmitCompilerReadBarrier); |
| 1158 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1159 | // has been overwritten by (or after) the heap object reference load |
| 1160 | // to be instrumented, e.g.: |
| 1161 | // |
| 1162 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1163 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1164 | // |
| 1165 | // In that case, we have lost the information about the original |
| 1166 | // object, and the emitted read barrier cannot work properly. |
| 1167 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1168 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1169 | } |
| 1170 | |
| 1171 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1172 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1173 | LocationSummary* locations = instruction_->GetLocations(); |
| 1174 | Register reg_out = out_.AsRegister<Register>(); |
| 1175 | DCHECK(locations->CanCall()); |
| 1176 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1177 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1178 | instruction_->IsStaticFieldGet() || |
| 1179 | instruction_->IsArrayGet() || |
| 1180 | instruction_->IsInstanceOf() || |
| 1181 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 1182 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1183 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1184 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1185 | // The read barrier instrumentation of object ArrayGet |
| 1186 | // instructions does not support the HIntermediateAddress |
| 1187 | // instruction. |
| 1188 | DCHECK(!(instruction_->IsArrayGet() && |
| 1189 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1190 | |
| 1191 | __ Bind(GetEntryLabel()); |
| 1192 | SaveLiveRegisters(codegen, locations); |
| 1193 | |
| 1194 | // We may have to change the index's value, but as `index_` is a |
| 1195 | // constant member (like other "inputs" of this slow path), |
| 1196 | // introduce a copy of it, `index`. |
| 1197 | Location index = index_; |
| 1198 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1199 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1200 | if (instruction_->IsArrayGet()) { |
| 1201 | // Compute the actual memory offset and store it in `index`. |
| 1202 | Register index_reg = index_.AsRegister<Register>(); |
| 1203 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1204 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1205 | // We are about to change the value of `index_reg` (see the |
| 1206 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1207 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1208 | // not been saved by the previous call to |
| 1209 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1210 | // callee-save register -- |
| 1211 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1212 | // callee-save registers, as it has been designed with the |
| 1213 | // assumption that callee-save registers are supposed to be |
| 1214 | // handled by the called function. So, as a callee-save |
| 1215 | // register, `index_reg` _would_ eventually be saved onto |
| 1216 | // the stack, but it would be too late: we would have |
| 1217 | // changed its value earlier. Therefore, we manually save |
| 1218 | // it here into another freely available register, |
| 1219 | // `free_reg`, chosen of course among the caller-save |
| 1220 | // registers (as a callee-save `free_reg` register would |
| 1221 | // exhibit the same problem). |
| 1222 | // |
| 1223 | // Note we could have requested a temporary register from |
| 1224 | // the register allocator instead; but we prefer not to, as |
| 1225 | // this is a slow path, and we know we can find a |
| 1226 | // caller-save register that is available. |
| 1227 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1228 | __ Mov(free_reg, index_reg); |
| 1229 | index_reg = free_reg; |
| 1230 | index = Location::RegisterLocation(index_reg); |
| 1231 | } else { |
| 1232 | // The initial register stored in `index_` has already been |
| 1233 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1234 | // (as it is not a callee-save register), so we can freely |
| 1235 | // use it. |
| 1236 | } |
| 1237 | // Shifting the index value contained in `index_reg` by the scale |
| 1238 | // factor (2) cannot overflow in practice, as the runtime is |
| 1239 | // unable to allocate object arrays with a size larger than |
| 1240 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1241 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1242 | static_assert( |
| 1243 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1244 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1245 | __ AddConstant(index_reg, index_reg, offset_); |
| 1246 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1247 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1248 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1249 | // (as in the case of ArrayGet), as it is actually an offset |
| 1250 | // to an object field within an object. |
| 1251 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1252 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1253 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1254 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1255 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1256 | DCHECK_EQ(offset_, 0U); |
| 1257 | DCHECK(index_.IsRegisterPair()); |
| 1258 | // UnsafeGet's offset location is a register pair, the low |
| 1259 | // part contains the correct offset. |
| 1260 | index = index_.ToLow(); |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | // We're moving two or three locations to locations that could |
| 1265 | // overlap, so we need a parallel move resolver. |
| 1266 | InvokeRuntimeCallingConvention calling_convention; |
| 1267 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1268 | parallel_move.AddMove(ref_, |
| 1269 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1270 | Primitive::kPrimNot, |
| 1271 | nullptr); |
| 1272 | parallel_move.AddMove(obj_, |
| 1273 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1274 | Primitive::kPrimNot, |
| 1275 | nullptr); |
| 1276 | if (index.IsValid()) { |
| 1277 | parallel_move.AddMove(index, |
| 1278 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1279 | Primitive::kPrimInt, |
| 1280 | nullptr); |
| 1281 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1282 | } else { |
| 1283 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1284 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1285 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1286 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1287 | CheckEntrypointTypes< |
| 1288 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1289 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1290 | |
| 1291 | RestoreLiveRegisters(codegen, locations); |
| 1292 | __ b(GetExitLabel()); |
| 1293 | } |
| 1294 | |
| 1295 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1296 | |
| 1297 | private: |
| 1298 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1299 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1300 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1301 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1302 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1303 | return static_cast<Register>(i); |
| 1304 | } |
| 1305 | } |
| 1306 | // We shall never fail to find a free caller-save register, as |
| 1307 | // there are more than two core caller-save registers on ARM |
| 1308 | // (meaning it is possible to find one which is different from |
| 1309 | // `ref` and `obj`). |
| 1310 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1311 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1312 | UNREACHABLE(); |
| 1313 | } |
| 1314 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1315 | const Location out_; |
| 1316 | const Location ref_; |
| 1317 | const Location obj_; |
| 1318 | const uint32_t offset_; |
| 1319 | // An additional location containing an index to an array. |
| 1320 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1321 | // UnsafeGetObjectVolatile intrinsics. |
| 1322 | const Location index_; |
| 1323 | |
| 1324 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1325 | }; |
| 1326 | |
| 1327 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1328 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1329 | public: |
| 1330 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1331 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1332 | DCHECK(kEmitCompilerReadBarrier); |
| 1333 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1334 | |
| 1335 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1336 | LocationSummary* locations = instruction_->GetLocations(); |
| 1337 | Register reg_out = out_.AsRegister<Register>(); |
| 1338 | DCHECK(locations->CanCall()); |
| 1339 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1340 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1341 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1342 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1343 | |
| 1344 | __ Bind(GetEntryLabel()); |
| 1345 | SaveLiveRegisters(codegen, locations); |
| 1346 | |
| 1347 | InvokeRuntimeCallingConvention calling_convention; |
| 1348 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1349 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1350 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1351 | instruction_, |
| 1352 | instruction_->GetDexPc(), |
| 1353 | this); |
| 1354 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1355 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1356 | |
| 1357 | RestoreLiveRegisters(codegen, locations); |
| 1358 | __ b(GetExitLabel()); |
| 1359 | } |
| 1360 | |
| 1361 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1362 | |
| 1363 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1364 | const Location out_; |
| 1365 | const Location root_; |
| 1366 | |
| 1367 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1368 | }; |
| 1369 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1370 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1371 | switch (cond) { |
| 1372 | case kCondEQ: return EQ; |
| 1373 | case kCondNE: return NE; |
| 1374 | case kCondLT: return LT; |
| 1375 | case kCondLE: return LE; |
| 1376 | case kCondGT: return GT; |
| 1377 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1378 | case kCondB: return LO; |
| 1379 | case kCondBE: return LS; |
| 1380 | case kCondA: return HI; |
| 1381 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1382 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1383 | LOG(FATAL) << "Unreachable"; |
| 1384 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1387 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1388 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1389 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1390 | case kCondEQ: return EQ; |
| 1391 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1392 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1393 | case kCondLT: return LO; |
| 1394 | case kCondLE: return LS; |
| 1395 | case kCondGT: return HI; |
| 1396 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1397 | // Unsigned remain unchanged. |
| 1398 | case kCondB: return LO; |
| 1399 | case kCondBE: return LS; |
| 1400 | case kCondA: return HI; |
| 1401 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1402 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1403 | LOG(FATAL) << "Unreachable"; |
| 1404 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1407 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1408 | // The ARM condition codes can express all the necessary branches, see the |
| 1409 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1410 | // There is no dex instruction or HIR that would need the missing conditions |
| 1411 | // "equal or unordered" or "not equal". |
| 1412 | switch (cond) { |
| 1413 | case kCondEQ: return EQ; |
| 1414 | case kCondNE: return NE /* unordered */; |
| 1415 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1416 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1417 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1418 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1419 | default: |
| 1420 | LOG(FATAL) << "UNREACHABLE"; |
| 1421 | UNREACHABLE(); |
| 1422 | } |
| 1423 | } |
| 1424 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1425 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1426 | switch (op_kind) { |
| 1427 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1428 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1429 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1430 | default: |
| 1431 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1432 | UNREACHABLE(); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1437 | Register out, |
| 1438 | Register first, |
| 1439 | const ShifterOperand& second, |
| 1440 | CodeGeneratorARM* codegen) { |
| 1441 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1442 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1443 | ? ShifterOperand(0) |
| 1444 | : ShifterOperand(first); |
| 1445 | |
| 1446 | __ mov(out, in); |
| 1447 | } else { |
| 1448 | switch (kind) { |
| 1449 | case HInstruction::kAdd: |
| 1450 | __ add(out, first, second); |
| 1451 | break; |
| 1452 | case HInstruction::kAnd: |
| 1453 | __ and_(out, first, second); |
| 1454 | break; |
| 1455 | case HInstruction::kOr: |
| 1456 | __ orr(out, first, second); |
| 1457 | break; |
| 1458 | case HInstruction::kSub: |
| 1459 | __ sub(out, first, second); |
| 1460 | break; |
| 1461 | case HInstruction::kXor: |
| 1462 | __ eor(out, first, second); |
| 1463 | break; |
| 1464 | default: |
| 1465 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1466 | UNREACHABLE(); |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1472 | const Location& out, |
| 1473 | const Location& first, |
| 1474 | const ShifterOperand& second_lo, |
| 1475 | const ShifterOperand& second_hi, |
| 1476 | CodeGeneratorARM* codegen) { |
| 1477 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1478 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1479 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1480 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1481 | |
| 1482 | if (kind == HInstruction::kAdd) { |
| 1483 | __ adds(out_lo, first_lo, second_lo); |
| 1484 | __ adc(out_hi, first_hi, second_hi); |
| 1485 | } else if (kind == HInstruction::kSub) { |
| 1486 | __ subs(out_lo, first_lo, second_lo); |
| 1487 | __ sbc(out_hi, first_hi, second_hi); |
| 1488 | } else { |
| 1489 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1490 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1495 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1496 | } |
| 1497 | |
| 1498 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1499 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1500 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1501 | |
| 1502 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1503 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1504 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1505 | const Location first = locations->InAt(0); |
| 1506 | const Location second = locations->InAt(1); |
| 1507 | const Location out = locations->Out(); |
| 1508 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1509 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1510 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1511 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1512 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1513 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1514 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1515 | |
| 1516 | if (shift_value >= 32) { |
| 1517 | if (shift == LSL) { |
| 1518 | GenerateDataProcInstruction(kind, |
| 1519 | out_hi, |
| 1520 | first_hi, |
| 1521 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1522 | codegen); |
| 1523 | GenerateDataProcInstruction(kind, |
| 1524 | out_lo, |
| 1525 | first_lo, |
| 1526 | ShifterOperand(0), |
| 1527 | codegen); |
| 1528 | } else if (shift == ASR) { |
| 1529 | GenerateDataProc(kind, |
| 1530 | out, |
| 1531 | first, |
| 1532 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1533 | ShifterOperand(second_hi, ASR, 31), |
| 1534 | codegen); |
| 1535 | } else { |
| 1536 | DCHECK_EQ(shift, LSR); |
| 1537 | GenerateDataProc(kind, |
| 1538 | out, |
| 1539 | first, |
| 1540 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1541 | ShifterOperand(0), |
| 1542 | codegen); |
| 1543 | } |
| 1544 | } else { |
| 1545 | DCHECK_GT(shift_value, 1U); |
| 1546 | DCHECK_LT(shift_value, 32U); |
| 1547 | |
| 1548 | if (shift == LSL) { |
| 1549 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1550 | // Location::kOutputOverlap; not applicable to other cases. |
| 1551 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1552 | GenerateDataProcInstruction(kind, |
| 1553 | out_hi, |
| 1554 | first_hi, |
| 1555 | ShifterOperand(second_hi, LSL, shift_value), |
| 1556 | codegen); |
| 1557 | GenerateDataProcInstruction(kind, |
| 1558 | out_hi, |
| 1559 | out_hi, |
| 1560 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1561 | codegen); |
| 1562 | GenerateDataProcInstruction(kind, |
| 1563 | out_lo, |
| 1564 | first_lo, |
| 1565 | ShifterOperand(second_lo, LSL, shift_value), |
| 1566 | codegen); |
| 1567 | } else { |
| 1568 | __ Lsl(IP, second_hi, shift_value); |
| 1569 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1570 | GenerateDataProc(kind, |
| 1571 | out, |
| 1572 | first, |
| 1573 | ShifterOperand(second_lo, LSL, shift_value), |
| 1574 | ShifterOperand(IP), |
| 1575 | codegen); |
| 1576 | } |
| 1577 | } else { |
| 1578 | DCHECK(shift == ASR || shift == LSR); |
| 1579 | |
| 1580 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1581 | // Location::kOutputOverlap; not applicable to other cases. |
| 1582 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1583 | GenerateDataProcInstruction(kind, |
| 1584 | out_lo, |
| 1585 | first_lo, |
| 1586 | ShifterOperand(second_lo, LSR, shift_value), |
| 1587 | codegen); |
| 1588 | GenerateDataProcInstruction(kind, |
| 1589 | out_lo, |
| 1590 | out_lo, |
| 1591 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1592 | codegen); |
| 1593 | GenerateDataProcInstruction(kind, |
| 1594 | out_hi, |
| 1595 | first_hi, |
| 1596 | ShifterOperand(second_hi, shift, shift_value), |
| 1597 | codegen); |
| 1598 | } else { |
| 1599 | __ Lsr(IP, second_lo, shift_value); |
| 1600 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1601 | GenerateDataProc(kind, |
| 1602 | out, |
| 1603 | first, |
| 1604 | ShifterOperand(IP), |
| 1605 | ShifterOperand(second_hi, shift, shift_value), |
| 1606 | codegen); |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1612 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1613 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1614 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1615 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1616 | if (rhs_loc.IsConstant()) { |
| 1617 | // 0.0 is the only immediate that can be encoded directly in |
| 1618 | // a VCMP instruction. |
| 1619 | // |
| 1620 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1621 | // specify that in a floating-point comparison, positive zero |
| 1622 | // and negative zero are considered equal, so we can use the |
| 1623 | // literal 0.0 for both cases here. |
| 1624 | // |
| 1625 | // Note however that some methods (Float.equal, Float.compare, |
| 1626 | // Float.compareTo, Double.equal, Double.compare, |
| 1627 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1628 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1629 | // -0.0. So if we ever translate calls to these methods into a |
| 1630 | // HCompare instruction, we must handle the -0.0 case with |
| 1631 | // care here. |
| 1632 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1633 | if (type == Primitive::kPrimFloat) { |
| 1634 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1635 | } else { |
| 1636 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1637 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1638 | } |
| 1639 | } else { |
| 1640 | if (type == Primitive::kPrimFloat) { |
| 1641 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1642 | } else { |
| 1643 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1644 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1645 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1650 | static std::pair<Condition, Condition> GenerateLongTestConstant(HCondition* condition, |
| 1651 | bool invert, |
| 1652 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1653 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1654 | |
| 1655 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1656 | IfCondition cond = condition->GetCondition(); |
| 1657 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1658 | |
| 1659 | if (invert) { |
| 1660 | std::swap(cond, opposite); |
| 1661 | } |
| 1662 | |
| 1663 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1664 | const Location left = locations->InAt(0); |
| 1665 | const Location right = locations->InAt(1); |
| 1666 | |
| 1667 | DCHECK(right.IsConstant()); |
| 1668 | |
| 1669 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1670 | const Register left_low = left.AsRegisterPairLow<Register>(); |
| 1671 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1672 | |
| 1673 | switch (cond) { |
| 1674 | case kCondEQ: |
| 1675 | case kCondNE: |
| 1676 | case kCondB: |
| 1677 | case kCondBE: |
| 1678 | case kCondA: |
| 1679 | case kCondAE: |
| 1680 | __ CmpConstant(left_high, High32Bits(value)); |
| 1681 | __ it(EQ); |
| 1682 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1683 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1684 | break; |
| 1685 | case kCondLE: |
| 1686 | case kCondGT: |
| 1687 | // Trivially true or false. |
| 1688 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1689 | __ cmp(left_low, ShifterOperand(left_low)); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1690 | 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] | 1691 | break; |
| 1692 | } |
| 1693 | |
| 1694 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1695 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1696 | cond = kCondLT; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1697 | opposite = kCondGE; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1698 | } else { |
| 1699 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1700 | DCHECK_EQ(opposite, kCondLE); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1701 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1702 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | value++; |
| 1706 | FALLTHROUGH_INTENDED; |
| 1707 | case kCondGE: |
| 1708 | case kCondLT: |
| 1709 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1710 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1711 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1712 | break; |
| 1713 | default: |
| 1714 | LOG(FATAL) << "Unreachable"; |
| 1715 | UNREACHABLE(); |
| 1716 | } |
| 1717 | |
| 1718 | return ret; |
| 1719 | } |
| 1720 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1721 | static std::pair<Condition, Condition> GenerateLongTest(HCondition* condition, |
| 1722 | bool invert, |
| 1723 | CodeGeneratorARM* codegen) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1724 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1725 | |
| 1726 | const LocationSummary* const locations = condition->GetLocations(); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1727 | IfCondition cond = condition->GetCondition(); |
| 1728 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1729 | |
| 1730 | if (invert) { |
| 1731 | std::swap(cond, opposite); |
| 1732 | } |
| 1733 | |
| 1734 | std::pair<Condition, Condition> ret; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1735 | Location left = locations->InAt(0); |
| 1736 | Location right = locations->InAt(1); |
| 1737 | |
| 1738 | DCHECK(right.IsRegisterPair()); |
| 1739 | |
| 1740 | switch (cond) { |
| 1741 | case kCondEQ: |
| 1742 | case kCondNE: |
| 1743 | case kCondB: |
| 1744 | case kCondBE: |
| 1745 | case kCondA: |
| 1746 | case kCondAE: |
| 1747 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1748 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1749 | __ it(EQ); |
| 1750 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1751 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1752 | EQ); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1753 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1754 | break; |
| 1755 | case kCondLE: |
| 1756 | case kCondGT: |
| 1757 | if (cond == kCondLE) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1758 | DCHECK_EQ(opposite, kCondGT); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1759 | cond = kCondGE; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1760 | opposite = kCondLT; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1761 | } else { |
| 1762 | DCHECK_EQ(cond, kCondGT); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1763 | DCHECK_EQ(opposite, kCondLE); |
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 | } |
| 1767 | |
| 1768 | std::swap(left, right); |
| 1769 | FALLTHROUGH_INTENDED; |
| 1770 | case kCondGE: |
| 1771 | case kCondLT: |
| 1772 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1773 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1774 | __ sbcs(IP, |
| 1775 | left.AsRegisterPairHigh<Register>(), |
| 1776 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1777 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1778 | break; |
| 1779 | default: |
| 1780 | LOG(FATAL) << "Unreachable"; |
| 1781 | UNREACHABLE(); |
| 1782 | } |
| 1783 | |
| 1784 | return ret; |
| 1785 | } |
| 1786 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1787 | static std::pair<Condition, Condition> GenerateTest(HCondition* condition, |
| 1788 | bool invert, |
| 1789 | CodeGeneratorARM* codegen) { |
| 1790 | const LocationSummary* const locations = condition->GetLocations(); |
| 1791 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1792 | IfCondition cond = condition->GetCondition(); |
| 1793 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1794 | std::pair<Condition, Condition> ret; |
| 1795 | const Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1796 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1797 | if (invert) { |
| 1798 | std::swap(cond, opposite); |
| 1799 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1800 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1801 | if (type == Primitive::kPrimLong) { |
| 1802 | ret = locations->InAt(1).IsConstant() |
| 1803 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1804 | : GenerateLongTest(condition, invert, codegen); |
| 1805 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1806 | GenerateVcmp(condition, codegen); |
| 1807 | __ vmstat(); |
| 1808 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1809 | ARMFPCondition(opposite, condition->IsGtBias())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1810 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1811 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1812 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1813 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1814 | |
| 1815 | if (right.IsRegister()) { |
| 1816 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1817 | } else { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1818 | DCHECK(right.IsConstant()); |
| 1819 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1820 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1821 | |
| 1822 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | return ret; |
| 1826 | } |
| 1827 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1828 | static bool CanGenerateTest(HCondition* condition, ArmAssembler* assembler) { |
| 1829 | if (condition->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1830 | const LocationSummary* const locations = condition->GetLocations(); |
| 1831 | const IfCondition c = condition->GetCondition(); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1832 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1833 | if (locations->InAt(1).IsConstant()) { |
| 1834 | const int64_t value = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 1835 | ShifterOperand so; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1836 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1837 | if (c < kCondLT || c > kCondGE) { |
| 1838 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1839 | // we check that the least significant half of the first input to be compared |
| 1840 | // is in a low register (the other half is read outside an IT block), and |
| 1841 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1842 | // encoding can be used. |
| 1843 | if (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1844 | !IsUint<8>(Low32Bits(value))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1845 | return false; |
| 1846 | } |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1847 | } else if (c == kCondLE || c == kCondGT) { |
| 1848 | if (value < std::numeric_limits<int64_t>::max() && |
| 1849 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1850 | kNoRegister, |
| 1851 | SBC, |
| 1852 | High32Bits(value + 1), |
| 1853 | kCcSet, |
| 1854 | &so)) { |
| 1855 | return false; |
| 1856 | } |
| 1857 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1858 | kNoRegister, |
| 1859 | SBC, |
| 1860 | High32Bits(value), |
| 1861 | kCcSet, |
| 1862 | &so)) { |
| 1863 | return false; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | return true; |
| 1869 | } |
| 1870 | |
| 1871 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1872 | const Primitive::Type type = constant->GetType(); |
| 1873 | bool ret = false; |
| 1874 | |
| 1875 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1876 | |
| 1877 | if (type == Primitive::kPrimLong) { |
| 1878 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 1879 | |
| 1880 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1881 | } else { |
| 1882 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 1883 | } |
| 1884 | |
| 1885 | return ret; |
| 1886 | } |
| 1887 | |
| 1888 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1889 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1890 | |
| 1891 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1892 | return Location::ConstantLocation(constant->AsConstant()); |
| 1893 | } |
| 1894 | |
| 1895 | return Location::RequiresRegister(); |
| 1896 | } |
| 1897 | |
| 1898 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1899 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1900 | // we check that we are not dealing with floating-point output (there is no |
| 1901 | // 16-bit VMOV encoding). |
| 1902 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1903 | return false; |
| 1904 | } |
| 1905 | |
| 1906 | // For constants, we also check that the output is in one or two low registers, |
| 1907 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1908 | // MOV encoding can be used. |
| 1909 | if (src.IsConstant()) { |
| 1910 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1911 | return false; |
| 1912 | } |
| 1913 | |
| 1914 | if (out.IsRegister()) { |
| 1915 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 1916 | return false; |
| 1917 | } |
| 1918 | } else { |
| 1919 | DCHECK(out.IsRegisterPair()); |
| 1920 | |
| 1921 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 1922 | return false; |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | return true; |
| 1928 | } |
| 1929 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1930 | #undef __ |
| 1931 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1932 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1933 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1934 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 1935 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1936 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1937 | |
| 1938 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1939 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1940 | HInstruction* const next = instruction->GetNext(); |
| 1941 | |
| 1942 | // Avoid a branch to a branch. |
| 1943 | if (next->IsGoto() && (info == nullptr || |
| 1944 | !info->IsBackEdge(*block) || |
| 1945 | !info->HasSuspendCheck())) { |
| 1946 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1947 | } |
| 1948 | |
| 1949 | return final_label; |
| 1950 | } |
| 1951 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1952 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1953 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1957 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1960 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1961 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1962 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1963 | } |
| 1964 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1965 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1966 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1967 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1970 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1971 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1972 | return kArmWordSize; |
| 1973 | } |
| 1974 | |
| 1975 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1976 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1977 | return kArmWordSize; |
| 1978 | } |
| 1979 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1980 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1981 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1982 | const CompilerOptions& compiler_options, |
| 1983 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1984 | : CodeGenerator(graph, |
| 1985 | kNumberOfCoreRegisters, |
| 1986 | kNumberOfSRegisters, |
| 1987 | kNumberOfRegisterPairs, |
| 1988 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1989 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1990 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1991 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1992 | compiler_options, |
| 1993 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1994 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1995 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1996 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1997 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1998 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1999 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2000 | uint32_literals_(std::less<uint32_t>(), |
| 2001 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2002 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2003 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 2004 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2005 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 2006 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 2007 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2008 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 2009 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 2010 | baker_read_barrier_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 2011 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 2012 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 2013 | jit_class_patches_(TypeReferenceValueComparator(), |
| 2014 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2015 | // Always save the LR register to mimic Quick. |
| 2016 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 2017 | } |
| 2018 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2019 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 2020 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 2021 | __ FinalizeCode(); |
| 2022 | |
| 2023 | // Adjust native pc offsets in stack maps. |
| 2024 | 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] | 2025 | uint32_t old_position = |
| 2026 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2027 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 2028 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 2029 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 2030 | // Adjust pc offsets for the disassembly information. |
| 2031 | if (disasm_info_ != nullptr) { |
| 2032 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 2033 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 2034 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 2035 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 2036 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 2037 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 2038 | } |
| 2039 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 2040 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 2041 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 2042 | } |
| 2043 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 2044 | |
| 2045 | CodeGenerator::Finalize(allocator); |
| 2046 | } |
| 2047 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2048 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2049 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2050 | blocked_core_registers_[SP] = true; |
| 2051 | blocked_core_registers_[LR] = true; |
| 2052 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2053 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2054 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2055 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2056 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2057 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 2058 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2059 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2060 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2061 | // Stubs do not save callee-save floating point registers. If the graph |
| 2062 | // is debuggable, we need to deal with these registers differently. For |
| 2063 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2064 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2065 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2066 | } |
| 2067 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2068 | } |
| 2069 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2070 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2071 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2072 | assembler_(codegen->GetAssembler()), |
| 2073 | codegen_(codegen) {} |
| 2074 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2075 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2076 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2077 | 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] | 2078 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2079 | // restore another arbitrary register. |
| 2080 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2081 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2082 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2083 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2084 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2085 | // but in the range. |
| 2086 | if (fpu_spill_mask_ != 0) { |
| 2087 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2088 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2089 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2090 | fpu_spill_mask_ |= (1 << i); |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2095 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2096 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2100 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2101 | } |
| 2102 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2103 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2104 | bool skip_overflow_check = |
| 2105 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2106 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2107 | __ Bind(&frame_entry_label_); |
| 2108 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2109 | if (HasEmptyFrame()) { |
| 2110 | return; |
| 2111 | } |
| 2112 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2113 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2114 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2115 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2116 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2119 | __ PushList(core_spill_mask_); |
| 2120 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2121 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2122 | if (fpu_spill_mask_ != 0) { |
| 2123 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2124 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2125 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2126 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2127 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2128 | |
| 2129 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2130 | // Initialize should_deoptimize flag to 0. |
| 2131 | __ mov(IP, ShifterOperand(0)); |
| 2132 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2133 | } |
| 2134 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2135 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2136 | __ AddConstant(SP, -adjust); |
| 2137 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2138 | |
| 2139 | // Save the current method if we need it. Note that we do not |
| 2140 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2141 | // in the SSA graph. |
| 2142 | if (RequiresCurrentMethod()) { |
| 2143 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2144 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2148 | if (HasEmptyFrame()) { |
| 2149 | __ bx(LR); |
| 2150 | return; |
| 2151 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2152 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2153 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2154 | __ AddConstant(SP, adjust); |
| 2155 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2156 | if (fpu_spill_mask_ != 0) { |
| 2157 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2158 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2159 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2160 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2161 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2162 | // Pop LR into PC to return. |
| 2163 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2164 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2165 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2166 | __ cfi().RestoreState(); |
| 2167 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2170 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2171 | Label* label = GetLabelOf(block); |
| 2172 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2175 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2176 | switch (type) { |
| 2177 | case Primitive::kPrimBoolean: |
| 2178 | case Primitive::kPrimByte: |
| 2179 | case Primitive::kPrimChar: |
| 2180 | case Primitive::kPrimShort: |
| 2181 | case Primitive::kPrimInt: |
| 2182 | case Primitive::kPrimNot: { |
| 2183 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2184 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2185 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2186 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2187 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2188 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2189 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2190 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2191 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2193 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2194 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2195 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2196 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2197 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2198 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2199 | // Skip R1, and use R2_R3 instead. |
| 2200 | gp_index_++; |
| 2201 | index++; |
| 2202 | } |
| 2203 | } |
| 2204 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2205 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2206 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2207 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2208 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2209 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2210 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2211 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | case Primitive::kPrimFloat: { |
| 2216 | uint32_t stack_index = stack_index_++; |
| 2217 | if (float_index_ % 2 == 0) { |
| 2218 | float_index_ = std::max(double_index_, float_index_); |
| 2219 | } |
| 2220 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2221 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2222 | } else { |
| 2223 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | case Primitive::kPrimDouble: { |
| 2228 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2229 | uint32_t stack_index = stack_index_; |
| 2230 | stack_index_ += 2; |
| 2231 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2232 | uint32_t index = double_index_; |
| 2233 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2234 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2235 | calling_convention.GetFpuRegisterAt(index), |
| 2236 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2237 | DCHECK(ExpectedPairLayout(result)); |
| 2238 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2239 | } else { |
| 2240 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2241 | } |
| 2242 | } |
| 2243 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2244 | case Primitive::kPrimVoid: |
| 2245 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2246 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2247 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2248 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2249 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2250 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2251 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2252 | switch (type) { |
| 2253 | case Primitive::kPrimBoolean: |
| 2254 | case Primitive::kPrimByte: |
| 2255 | case Primitive::kPrimChar: |
| 2256 | case Primitive::kPrimShort: |
| 2257 | case Primitive::kPrimInt: |
| 2258 | case Primitive::kPrimNot: { |
| 2259 | return Location::RegisterLocation(R0); |
| 2260 | } |
| 2261 | |
| 2262 | case Primitive::kPrimFloat: { |
| 2263 | return Location::FpuRegisterLocation(S0); |
| 2264 | } |
| 2265 | |
| 2266 | case Primitive::kPrimLong: { |
| 2267 | return Location::RegisterPairLocation(R0, R1); |
| 2268 | } |
| 2269 | |
| 2270 | case Primitive::kPrimDouble: { |
| 2271 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2272 | } |
| 2273 | |
| 2274 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2275 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2276 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2277 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2278 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2281 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2282 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2283 | } |
| 2284 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2285 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2286 | if (source.Equals(destination)) { |
| 2287 | return; |
| 2288 | } |
| 2289 | if (destination.IsRegister()) { |
| 2290 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2291 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2292 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2293 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2294 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2295 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2296 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2297 | } else if (destination.IsFpuRegister()) { |
| 2298 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2299 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2300 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2301 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2302 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2303 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2305 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2306 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2307 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2308 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2310 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2311 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2312 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2313 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2314 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2320 | if (source.Equals(destination)) { |
| 2321 | return; |
| 2322 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2323 | if (destination.IsRegisterPair()) { |
| 2324 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2325 | EmitParallelMoves( |
| 2326 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2327 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2328 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2329 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2330 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2331 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2332 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2333 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2334 | } else if (source.IsFpuRegisterPair()) { |
| 2335 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2336 | destination.AsRegisterPairHigh<Register>(), |
| 2337 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2338 | } else { |
| 2339 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2340 | DCHECK(ExpectedPairLayout(destination)); |
| 2341 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2342 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2343 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2344 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2345 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2346 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2347 | SP, |
| 2348 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2349 | } else if (source.IsRegisterPair()) { |
| 2350 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2351 | source.AsRegisterPairLow<Register>(), |
| 2352 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2353 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2354 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2355 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2356 | } else { |
| 2357 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2358 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2359 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2360 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2361 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2362 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2363 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2364 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2365 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2366 | SP, destination.GetStackIndex()); |
| 2367 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2368 | } else if (source.IsFpuRegisterPair()) { |
| 2369 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2370 | SP, |
| 2371 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2372 | } else { |
| 2373 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2374 | EmitParallelMoves( |
| 2375 | Location::StackSlot(source.GetStackIndex()), |
| 2376 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2377 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2378 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2379 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2380 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | } |
| 2384 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2385 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2386 | DCHECK(location.IsRegister()); |
| 2387 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2388 | } |
| 2389 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2390 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2391 | HParallelMove move(GetGraph()->GetArena()); |
| 2392 | move.AddMove(src, dst, dst_type, nullptr); |
| 2393 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2397 | if (location.IsRegister()) { |
| 2398 | locations->AddTemp(location); |
| 2399 | } else if (location.IsRegisterPair()) { |
| 2400 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2401 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2402 | } else { |
| 2403 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2404 | } |
| 2405 | } |
| 2406 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2407 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2408 | HInstruction* instruction, |
| 2409 | uint32_t dex_pc, |
| 2410 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2411 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2412 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2413 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2414 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2415 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2416 | } |
| 2417 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2418 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2419 | HInstruction* instruction, |
| 2420 | SlowPathCode* slow_path) { |
| 2421 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2422 | GenerateInvokeRuntime(entry_point_offset); |
| 2423 | } |
| 2424 | |
| 2425 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2426 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2427 | __ blx(LR); |
| 2428 | } |
| 2429 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2430 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2431 | DCHECK(!successor->IsExitBlock()); |
| 2432 | |
| 2433 | HBasicBlock* block = got->GetBlock(); |
| 2434 | HInstruction* previous = got->GetPrevious(); |
| 2435 | |
| 2436 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2437 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2438 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2439 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2440 | return; |
| 2441 | } |
| 2442 | |
| 2443 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2444 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2445 | } |
| 2446 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2447 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2451 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2452 | got->SetLocations(nullptr); |
| 2453 | } |
| 2454 | |
| 2455 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2456 | HandleGoto(got, got->GetSuccessor()); |
| 2457 | } |
| 2458 | |
| 2459 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2460 | try_boundary->SetLocations(nullptr); |
| 2461 | } |
| 2462 | |
| 2463 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2464 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2465 | if (!successor->IsExitBlock()) { |
| 2466 | HandleGoto(try_boundary, successor); |
| 2467 | } |
| 2468 | } |
| 2469 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2470 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2471 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2474 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2477 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2478 | Label* true_label, |
| 2479 | Label* false_label) { |
| 2480 | LocationSummary* locations = cond->GetLocations(); |
| 2481 | Location left = locations->InAt(0); |
| 2482 | Location right = locations->InAt(1); |
| 2483 | IfCondition if_cond = cond->GetCondition(); |
| 2484 | |
| 2485 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2486 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2487 | IfCondition true_high_cond = if_cond; |
| 2488 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2489 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2490 | |
| 2491 | // Set the conditions for the test, remembering that == needs to be |
| 2492 | // decided using the low words. |
| 2493 | switch (if_cond) { |
| 2494 | case kCondEQ: |
| 2495 | case kCondNE: |
| 2496 | // Nothing to do. |
| 2497 | break; |
| 2498 | case kCondLT: |
| 2499 | false_high_cond = kCondGT; |
| 2500 | break; |
| 2501 | case kCondLE: |
| 2502 | true_high_cond = kCondLT; |
| 2503 | break; |
| 2504 | case kCondGT: |
| 2505 | false_high_cond = kCondLT; |
| 2506 | break; |
| 2507 | case kCondGE: |
| 2508 | true_high_cond = kCondGT; |
| 2509 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2510 | case kCondB: |
| 2511 | false_high_cond = kCondA; |
| 2512 | break; |
| 2513 | case kCondBE: |
| 2514 | true_high_cond = kCondB; |
| 2515 | break; |
| 2516 | case kCondA: |
| 2517 | false_high_cond = kCondB; |
| 2518 | break; |
| 2519 | case kCondAE: |
| 2520 | true_high_cond = kCondA; |
| 2521 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2522 | } |
| 2523 | if (right.IsConstant()) { |
| 2524 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2525 | int32_t val_low = Low32Bits(value); |
| 2526 | int32_t val_high = High32Bits(value); |
| 2527 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2528 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2529 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2530 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2531 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2532 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2533 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2534 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2535 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2536 | } |
| 2537 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2538 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2539 | } else { |
| 2540 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2541 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2542 | |
| 2543 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2544 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2545 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2546 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2547 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2548 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2549 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2550 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2551 | } |
| 2552 | // Must be equal high, so compare the lows. |
| 2553 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2554 | } |
| 2555 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2556 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2557 | __ b(true_label, final_condition); |
| 2558 | } |
| 2559 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2560 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2561 | Label* true_target_in, |
| 2562 | Label* false_target_in) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2563 | if (CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2564 | Label* non_fallthrough_target; |
| 2565 | bool invert; |
| 2566 | |
| 2567 | if (true_target_in == nullptr) { |
| 2568 | DCHECK(false_target_in != nullptr); |
| 2569 | non_fallthrough_target = false_target_in; |
| 2570 | invert = true; |
| 2571 | } else { |
| 2572 | non_fallthrough_target = true_target_in; |
| 2573 | invert = false; |
| 2574 | } |
| 2575 | |
| 2576 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2577 | |
| 2578 | __ b(non_fallthrough_target, cond.first); |
| 2579 | |
| 2580 | if (false_target_in != nullptr && false_target_in != non_fallthrough_target) { |
| 2581 | __ b(false_target_in); |
| 2582 | } |
| 2583 | |
| 2584 | return; |
| 2585 | } |
| 2586 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2587 | // Generated branching requires both targets to be explicit. If either of the |
| 2588 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2589 | Label fallthrough_target; |
| 2590 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2591 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2592 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2593 | DCHECK_EQ(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 2594 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2595 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2596 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2597 | __ b(false_target); |
| 2598 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2599 | |
| 2600 | if (fallthrough_target.IsLinked()) { |
| 2601 | __ Bind(&fallthrough_target); |
| 2602 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2605 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2606 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2607 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2608 | Label* false_target) { |
| 2609 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2610 | |
| 2611 | if (true_target == nullptr && false_target == nullptr) { |
| 2612 | // Nothing to do. The code always falls through. |
| 2613 | return; |
| 2614 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2615 | // Constant condition, statically compared against "true" (integer value 1). |
| 2616 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2617 | if (true_target != nullptr) { |
| 2618 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2619 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2620 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2621 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2622 | if (false_target != nullptr) { |
| 2623 | __ b(false_target); |
| 2624 | } |
| 2625 | } |
| 2626 | return; |
| 2627 | } |
| 2628 | |
| 2629 | // The following code generates these patterns: |
| 2630 | // (1) true_target == nullptr && false_target != nullptr |
| 2631 | // - opposite condition true => branch to false_target |
| 2632 | // (2) true_target != nullptr && false_target == nullptr |
| 2633 | // - condition true => branch to true_target |
| 2634 | // (3) true_target != nullptr && false_target != nullptr |
| 2635 | // - condition true => branch to true_target |
| 2636 | // - branch to false_target |
| 2637 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2638 | // Condition has been materialized, compare the output to 0. |
| 2639 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2640 | DCHECK(cond_val.IsRegister()); |
| 2641 | if (true_target == nullptr) { |
| 2642 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2643 | } else { |
| 2644 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2645 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2646 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2647 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2648 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2649 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2650 | |
| 2651 | // If this is a long or FP comparison that has been folded into |
| 2652 | // the HCondition, generate the comparison directly. |
| 2653 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2654 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2655 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2656 | return; |
| 2657 | } |
| 2658 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2659 | Label* non_fallthrough_target; |
| 2660 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2661 | LocationSummary* locations = cond->GetLocations(); |
| 2662 | DCHECK(locations->InAt(0).IsRegister()); |
| 2663 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2664 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2665 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2666 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2667 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2668 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2669 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2670 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2671 | non_fallthrough_target = true_target; |
| 2672 | } |
| 2673 | |
| 2674 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2675 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2676 | if (arm_cond == EQ) { |
| 2677 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2678 | } else { |
| 2679 | DCHECK_EQ(arm_cond, NE); |
| 2680 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2681 | } |
| 2682 | } else { |
| 2683 | if (right.IsRegister()) { |
| 2684 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2685 | } else { |
| 2686 | DCHECK(right.IsConstant()); |
| 2687 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2688 | } |
| 2689 | |
| 2690 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2691 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2692 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2693 | |
| 2694 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2695 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2696 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2697 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2698 | } |
| 2699 | } |
| 2700 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2701 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2702 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2703 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2704 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2709 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2710 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2711 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2712 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2713 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2714 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2715 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2719 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2720 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2721 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2722 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2723 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2728 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2729 | GenerateTestAndBranch(deoptimize, |
| 2730 | /* condition_input_index */ 0, |
| 2731 | slow_path->GetEntryLabel(), |
| 2732 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2733 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2734 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2735 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2736 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2737 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2738 | locations->SetOut(Location::RequiresRegister()); |
| 2739 | } |
| 2740 | |
| 2741 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2742 | __ LoadFromOffset(kLoadWord, |
| 2743 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2744 | SP, |
| 2745 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2746 | } |
| 2747 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2748 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2749 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2750 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2751 | |
| 2752 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2753 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2754 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2755 | } else { |
| 2756 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2757 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2758 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2759 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2760 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2761 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2762 | // The code generator handles overlap with the values, but not with the condition. |
| 2763 | locations->SetOut(Location::SameAsFirstInput()); |
| 2764 | } else if (is_floating_point) { |
| 2765 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2766 | } else { |
| 2767 | if (!locations->InAt(1).IsConstant()) { |
| 2768 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2769 | } |
| 2770 | |
| 2771 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2772 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2776 | HInstruction* const condition = select->GetCondition(); |
| 2777 | const LocationSummary* const locations = select->GetLocations(); |
| 2778 | const Primitive::Type type = select->GetType(); |
| 2779 | const Location first = locations->InAt(0); |
| 2780 | const Location out = locations->Out(); |
| 2781 | const Location second = locations->InAt(1); |
| 2782 | Location src; |
| 2783 | |
| 2784 | if (condition->IsIntConstant()) { |
| 2785 | if (condition->AsIntConstant()->IsFalse()) { |
| 2786 | src = first; |
| 2787 | } else { |
| 2788 | src = second; |
| 2789 | } |
| 2790 | |
| 2791 | codegen_->MoveLocation(out, src, type); |
| 2792 | return; |
| 2793 | } |
| 2794 | |
| 2795 | if (!Primitive::IsFloatingPointType(type) && |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2796 | (IsBooleanValueOrMaterializedCondition(condition) || |
| 2797 | CanGenerateTest(condition->AsCondition(), codegen_->GetAssembler()))) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2798 | bool invert = false; |
| 2799 | |
| 2800 | if (out.Equals(second)) { |
| 2801 | src = first; |
| 2802 | invert = true; |
| 2803 | } else if (out.Equals(first)) { |
| 2804 | src = second; |
| 2805 | } else if (second.IsConstant()) { |
| 2806 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2807 | src = second; |
| 2808 | } else if (first.IsConstant()) { |
| 2809 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2810 | src = first; |
| 2811 | invert = true; |
| 2812 | } else { |
| 2813 | src = second; |
| 2814 | } |
| 2815 | |
| 2816 | if (CanGenerateConditionalMove(out, src)) { |
| 2817 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2818 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2819 | } |
| 2820 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2821 | std::pair<Condition, Condition> cond; |
| 2822 | |
| 2823 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2824 | __ CmpConstant(locations->InAt(2).AsRegister<Register>(), 0); |
| 2825 | cond = invert ? std::make_pair(EQ, NE) : std::make_pair(NE, EQ); |
| 2826 | } else { |
| 2827 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2828 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2829 | |
| 2830 | if (out.IsRegister()) { |
| 2831 | ShifterOperand operand; |
| 2832 | |
| 2833 | if (src.IsConstant()) { |
| 2834 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 2835 | } else { |
| 2836 | DCHECK(src.IsRegister()); |
| 2837 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 2838 | } |
| 2839 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2840 | __ it(cond.first); |
| 2841 | __ mov(out.AsRegister<Register>(), operand, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2842 | } else { |
| 2843 | DCHECK(out.IsRegisterPair()); |
| 2844 | |
| 2845 | ShifterOperand operand_high; |
| 2846 | ShifterOperand operand_low; |
| 2847 | |
| 2848 | if (src.IsConstant()) { |
| 2849 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 2850 | |
| 2851 | operand_high = ShifterOperand(High32Bits(value)); |
| 2852 | operand_low = ShifterOperand(Low32Bits(value)); |
| 2853 | } else { |
| 2854 | DCHECK(src.IsRegisterPair()); |
| 2855 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 2856 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 2857 | } |
| 2858 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2859 | __ it(cond.first); |
| 2860 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond.first); |
| 2861 | __ it(cond.first); |
| 2862 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond.first); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | return; |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | Label* false_target = nullptr; |
| 2870 | Label* true_target = nullptr; |
| 2871 | Label select_end; |
| 2872 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 2873 | |
| 2874 | if (out.Equals(second)) { |
| 2875 | true_target = target; |
| 2876 | src = first; |
| 2877 | } else { |
| 2878 | false_target = target; |
| 2879 | src = second; |
| 2880 | |
| 2881 | if (!out.Equals(first)) { |
| 2882 | codegen_->MoveLocation(out, first, type); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 2887 | codegen_->MoveLocation(out, src, type); |
| 2888 | |
| 2889 | if (select_end.IsLinked()) { |
| 2890 | __ Bind(&select_end); |
| 2891 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2894 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2895 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2896 | } |
| 2897 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2898 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2899 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | void CodeGeneratorARM::GenerateNop() { |
| 2903 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2906 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2907 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2908 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2909 | // Handle the long/FP comparisons made in instruction simplification. |
| 2910 | switch (cond->InputAt(0)->GetType()) { |
| 2911 | case Primitive::kPrimLong: |
| 2912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2913 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2914 | if (!cond->IsEmittedAtUseSite()) { |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2915 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2916 | } |
| 2917 | break; |
| 2918 | |
| 2919 | case Primitive::kPrimFloat: |
| 2920 | case Primitive::kPrimDouble: |
| 2921 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2922 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2923 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2924 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2925 | } |
| 2926 | break; |
| 2927 | |
| 2928 | default: |
| 2929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2930 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2931 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2932 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2933 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2934 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2937 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2938 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2939 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2940 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2941 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2942 | const Register out = cond->GetLocations()->Out().AsRegister<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2943 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2944 | if (ArmAssembler::IsLowRegister(out) && CanGenerateTest(cond, codegen_->GetAssembler())) { |
| 2945 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2946 | |
| 2947 | __ it(condition.first); |
| 2948 | __ mov(out, ShifterOperand(1), condition.first); |
| 2949 | __ it(condition.second); |
| 2950 | __ mov(out, ShifterOperand(0), condition.second); |
| 2951 | return; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | // Convert the jumps into the result. |
| 2955 | Label done_label; |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2956 | Label* const final_label = codegen_->GetFinalLabel(cond, &done_label); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2957 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2958 | if (cond->InputAt(0)->GetType() == Primitive::kPrimLong) { |
| 2959 | Label true_label, false_label; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2960 | |
Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2961 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2962 | |
| 2963 | // False case: result = 0. |
| 2964 | __ Bind(&false_label); |
| 2965 | __ LoadImmediate(out, 0); |
| 2966 | __ b(final_label); |
| 2967 | |
| 2968 | // True case: result = 1. |
| 2969 | __ Bind(&true_label); |
| 2970 | __ LoadImmediate(out, 1); |
| 2971 | } else { |
| 2972 | DCHECK(CanGenerateTest(cond, codegen_->GetAssembler())); |
| 2973 | |
| 2974 | const auto condition = GenerateTest(cond, false, codegen_); |
| 2975 | |
| 2976 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 2977 | __ b(final_label, condition.second); |
| 2978 | __ LoadImmediate(out, 1); |
| 2979 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2980 | |
| 2981 | if (done_label.IsLinked()) { |
| 2982 | __ Bind(&done_label); |
| 2983 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2987 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2991 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2995 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2999 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3003 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3007 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3011 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3015 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3019 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3023 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3027 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3031 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3034 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3035 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3039 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3043 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3047 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3051 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3055 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3059 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3063 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3066 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3067 | LocationSummary* locations = |
| 3068 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3069 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3072 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3073 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3076 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 3077 | LocationSummary* locations = |
| 3078 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3079 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3080 | } |
| 3081 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3082 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3083 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3086 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3087 | LocationSummary* locations = |
| 3088 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3089 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3090 | } |
| 3091 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3092 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3093 | // Will be generated at use site. |
| 3094 | } |
| 3095 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3096 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3097 | LocationSummary* locations = |
| 3098 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3099 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3100 | } |
| 3101 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3102 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3103 | // Will be generated at use site. |
| 3104 | } |
| 3105 | |
| 3106 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3107 | LocationSummary* locations = |
| 3108 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3109 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3110 | } |
| 3111 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3112 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3113 | // Will be generated at use site. |
| 3114 | } |
| 3115 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3116 | void LocationsBuilderARM::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3117 | constructor_fence->SetLocations(nullptr); |
| 3118 | } |
| 3119 | |
| 3120 | void InstructionCodeGeneratorARM::VisitConstructorFence( |
| 3121 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3122 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3123 | } |
| 3124 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3125 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3126 | memory_barrier->SetLocations(nullptr); |
| 3127 | } |
| 3128 | |
| 3129 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3130 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3131 | } |
| 3132 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3133 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3134 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3137 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3138 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3141 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3142 | LocationSummary* locations = |
| 3143 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3144 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3147 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3148 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3151 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3152 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3153 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3154 | // the method_idx. |
| 3155 | HandleInvoke(invoke); |
| 3156 | } |
| 3157 | |
| 3158 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3159 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3160 | } |
| 3161 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3162 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3163 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3164 | // art::PrepareForRegisterAllocation. |
| 3165 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3166 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3167 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3168 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3169 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3170 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3171 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3172 | return; |
| 3173 | } |
| 3174 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3175 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3176 | |
| 3177 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3178 | if (invoke->HasPcRelativeDexCache()) { |
| 3179 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3180 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3181 | } |
| 3182 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3183 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3184 | if (invoke->GetLocations()->Intrinsified()) { |
| 3185 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3186 | intrinsic.Dispatch(invoke); |
| 3187 | return true; |
| 3188 | } |
| 3189 | return false; |
| 3190 | } |
| 3191 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3192 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3193 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3194 | // art::PrepareForRegisterAllocation. |
| 3195 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3196 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3197 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3198 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3199 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3200 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3201 | LocationSummary* locations = invoke->GetLocations(); |
| 3202 | codegen_->GenerateStaticOrDirectCall( |
| 3203 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3204 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3205 | } |
| 3206 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3207 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3208 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3209 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3212 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3213 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3214 | if (intrinsic.TryDispatch(invoke)) { |
| 3215 | return; |
| 3216 | } |
| 3217 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3218 | HandleInvoke(invoke); |
| 3219 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3220 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3221 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3222 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3223 | return; |
| 3224 | } |
| 3225 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3226 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3227 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3228 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3231 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3232 | HandleInvoke(invoke); |
| 3233 | // Add the hidden argument. |
| 3234 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3235 | } |
| 3236 | |
| 3237 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3238 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3239 | LocationSummary* locations = invoke->GetLocations(); |
| 3240 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3241 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3242 | Location receiver = locations->InAt(0); |
| 3243 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3244 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3245 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3246 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3247 | DCHECK_EQ(R12, hidden_reg); |
| 3248 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3249 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3250 | if (receiver.IsStackSlot()) { |
| 3251 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3252 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3253 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3254 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3255 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3256 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3257 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3258 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3259 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3260 | // emit a read barrier for the previous class reference load. |
| 3261 | // However this is not required in practice, as this is an |
| 3262 | // intermediate/temporary reference and because the current |
| 3263 | // concurrent copying collector keeps the from-space memory |
| 3264 | // intact/accessible until the end of the marking phase (the |
| 3265 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3266 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3267 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3268 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3269 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3270 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3271 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3272 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3273 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3274 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3275 | // LR = temp->GetEntryPoint(); |
| 3276 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3277 | // LR(); |
| 3278 | __ blx(LR); |
| 3279 | DCHECK(!codegen_->IsLeafMethod()); |
| 3280 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3281 | } |
| 3282 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3283 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3284 | HandleInvoke(invoke); |
| 3285 | } |
| 3286 | |
| 3287 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3288 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3289 | } |
| 3290 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3291 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3292 | LocationSummary* locations = |
| 3293 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3294 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3295 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3296 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3297 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3298 | break; |
| 3299 | } |
| 3300 | case Primitive::kPrimLong: { |
| 3301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3302 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3303 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3304 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3305 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3306 | case Primitive::kPrimFloat: |
| 3307 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3308 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3309 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3310 | break; |
| 3311 | |
| 3312 | default: |
| 3313 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3318 | LocationSummary* locations = neg->GetLocations(); |
| 3319 | Location out = locations->Out(); |
| 3320 | Location in = locations->InAt(0); |
| 3321 | switch (neg->GetResultType()) { |
| 3322 | case Primitive::kPrimInt: |
| 3323 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3324 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3325 | break; |
| 3326 | |
| 3327 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3328 | DCHECK(in.IsRegisterPair()); |
| 3329 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3330 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3331 | in.AsRegisterPairLow<Register>(), |
| 3332 | ShifterOperand(0)); |
| 3333 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3334 | // instruction here, as it does not exist in the Thumb-2 |
| 3335 | // instruction set. We use the following approach |
| 3336 | // using SBC and SUB instead. |
| 3337 | // |
| 3338 | // out.hi = -C |
| 3339 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3340 | out.AsRegisterPairHigh<Register>(), |
| 3341 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3342 | // out.hi = out.hi - in.hi |
| 3343 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3344 | out.AsRegisterPairHigh<Register>(), |
| 3345 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3346 | break; |
| 3347 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3348 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3349 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3350 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3351 | break; |
| 3352 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3353 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3354 | DCHECK(in.IsFpuRegisterPair()); |
| 3355 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3356 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3357 | break; |
| 3358 | |
| 3359 | default: |
| 3360 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3361 | } |
| 3362 | } |
| 3363 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3364 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3365 | Primitive::Type result_type = conversion->GetResultType(); |
| 3366 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3367 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3368 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3369 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3370 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3371 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3372 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3373 | && result_type == Primitive::kPrimLong) |
| 3374 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3375 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3376 | : LocationSummary::kNoCall; |
| 3377 | LocationSummary* locations = |
| 3378 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3379 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3380 | // The Java language does not allow treating boolean as an integral type but |
| 3381 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3382 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3383 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3384 | case Primitive::kPrimByte: |
| 3385 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3386 | case Primitive::kPrimLong: |
| 3387 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3388 | case Primitive::kPrimBoolean: |
| 3389 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3390 | case Primitive::kPrimShort: |
| 3391 | case Primitive::kPrimInt: |
| 3392 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3393 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3394 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3395 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3396 | break; |
| 3397 | |
| 3398 | default: |
| 3399 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3400 | << " to " << result_type; |
| 3401 | } |
| 3402 | break; |
| 3403 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3404 | case Primitive::kPrimShort: |
| 3405 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3406 | case Primitive::kPrimLong: |
| 3407 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3408 | case Primitive::kPrimBoolean: |
| 3409 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3410 | case Primitive::kPrimByte: |
| 3411 | case Primitive::kPrimInt: |
| 3412 | case Primitive::kPrimChar: |
| 3413 | // Processing a Dex `int-to-short' instruction. |
| 3414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3415 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3416 | break; |
| 3417 | |
| 3418 | default: |
| 3419 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3420 | << " to " << result_type; |
| 3421 | } |
| 3422 | break; |
| 3423 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3424 | case Primitive::kPrimInt: |
| 3425 | switch (input_type) { |
| 3426 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3427 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3428 | locations->SetInAt(0, Location::Any()); |
| 3429 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3430 | break; |
| 3431 | |
| 3432 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3433 | // Processing a Dex `float-to-int' instruction. |
| 3434 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3435 | locations->SetOut(Location::RequiresRegister()); |
| 3436 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3437 | break; |
| 3438 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3439 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3440 | // Processing a Dex `double-to-int' instruction. |
| 3441 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3442 | locations->SetOut(Location::RequiresRegister()); |
| 3443 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3444 | break; |
| 3445 | |
| 3446 | default: |
| 3447 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3448 | << " to " << result_type; |
| 3449 | } |
| 3450 | break; |
| 3451 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3452 | case Primitive::kPrimLong: |
| 3453 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3454 | case Primitive::kPrimBoolean: |
| 3455 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3456 | case Primitive::kPrimByte: |
| 3457 | case Primitive::kPrimShort: |
| 3458 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3459 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3460 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3461 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3462 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3463 | break; |
| 3464 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3465 | case Primitive::kPrimFloat: { |
| 3466 | // Processing a Dex `float-to-long' instruction. |
| 3467 | InvokeRuntimeCallingConvention calling_convention; |
| 3468 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3469 | calling_convention.GetFpuRegisterAt(0))); |
| 3470 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3471 | break; |
| 3472 | } |
| 3473 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3474 | case Primitive::kPrimDouble: { |
| 3475 | // Processing a Dex `double-to-long' instruction. |
| 3476 | InvokeRuntimeCallingConvention calling_convention; |
| 3477 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3478 | calling_convention.GetFpuRegisterAt(0), |
| 3479 | calling_convention.GetFpuRegisterAt(1))); |
| 3480 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3481 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3482 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3483 | |
| 3484 | default: |
| 3485 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3486 | << " to " << result_type; |
| 3487 | } |
| 3488 | break; |
| 3489 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3490 | case Primitive::kPrimChar: |
| 3491 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3492 | case Primitive::kPrimLong: |
| 3493 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3494 | case Primitive::kPrimBoolean: |
| 3495 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3496 | case Primitive::kPrimByte: |
| 3497 | case Primitive::kPrimShort: |
| 3498 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3499 | // Processing a Dex `int-to-char' instruction. |
| 3500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3502 | break; |
| 3503 | |
| 3504 | default: |
| 3505 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3506 | << " to " << result_type; |
| 3507 | } |
| 3508 | break; |
| 3509 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3510 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3511 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3512 | case Primitive::kPrimBoolean: |
| 3513 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3514 | case Primitive::kPrimByte: |
| 3515 | case Primitive::kPrimShort: |
| 3516 | case Primitive::kPrimInt: |
| 3517 | case Primitive::kPrimChar: |
| 3518 | // Processing a Dex `int-to-float' instruction. |
| 3519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3520 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3521 | break; |
| 3522 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3523 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3524 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3525 | InvokeRuntimeCallingConvention calling_convention; |
| 3526 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3527 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3528 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3529 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3530 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3531 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3532 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3533 | // Processing a Dex `double-to-float' instruction. |
| 3534 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3535 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3536 | break; |
| 3537 | |
| 3538 | default: |
| 3539 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3540 | << " to " << result_type; |
| 3541 | }; |
| 3542 | break; |
| 3543 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3544 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3545 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3546 | case Primitive::kPrimBoolean: |
| 3547 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3548 | case Primitive::kPrimByte: |
| 3549 | case Primitive::kPrimShort: |
| 3550 | case Primitive::kPrimInt: |
| 3551 | case Primitive::kPrimChar: |
| 3552 | // Processing a Dex `int-to-double' instruction. |
| 3553 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3554 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3555 | break; |
| 3556 | |
| 3557 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3558 | // Processing a Dex `long-to-double' instruction. |
| 3559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3560 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3561 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3562 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3563 | break; |
| 3564 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3565 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3566 | // Processing a Dex `float-to-double' instruction. |
| 3567 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3568 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3569 | break; |
| 3570 | |
| 3571 | default: |
| 3572 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3573 | << " to " << result_type; |
| 3574 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3575 | break; |
| 3576 | |
| 3577 | default: |
| 3578 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3579 | << " to " << result_type; |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3584 | LocationSummary* locations = conversion->GetLocations(); |
| 3585 | Location out = locations->Out(); |
| 3586 | Location in = locations->InAt(0); |
| 3587 | Primitive::Type result_type = conversion->GetResultType(); |
| 3588 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3589 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3590 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3591 | case Primitive::kPrimByte: |
| 3592 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3593 | case Primitive::kPrimLong: |
| 3594 | // Type conversion from long to byte is a result of code transformations. |
| 3595 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3596 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3597 | case Primitive::kPrimBoolean: |
| 3598 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3599 | case Primitive::kPrimShort: |
| 3600 | case Primitive::kPrimInt: |
| 3601 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3602 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3604 | break; |
| 3605 | |
| 3606 | default: |
| 3607 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3608 | << " to " << result_type; |
| 3609 | } |
| 3610 | break; |
| 3611 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3612 | case Primitive::kPrimShort: |
| 3613 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3614 | case Primitive::kPrimLong: |
| 3615 | // Type conversion from long to short is a result of code transformations. |
| 3616 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3617 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3618 | case Primitive::kPrimBoolean: |
| 3619 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3620 | case Primitive::kPrimByte: |
| 3621 | case Primitive::kPrimInt: |
| 3622 | case Primitive::kPrimChar: |
| 3623 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3624 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3625 | break; |
| 3626 | |
| 3627 | default: |
| 3628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3629 | << " to " << result_type; |
| 3630 | } |
| 3631 | break; |
| 3632 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3633 | case Primitive::kPrimInt: |
| 3634 | switch (input_type) { |
| 3635 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3636 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3637 | DCHECK(out.IsRegister()); |
| 3638 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3639 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3640 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3641 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3642 | } else { |
| 3643 | DCHECK(in.IsConstant()); |
| 3644 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3645 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3646 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3647 | } |
| 3648 | break; |
| 3649 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimFloat: { |
| 3651 | // Processing a Dex `float-to-int' instruction. |
| 3652 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3653 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3654 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3655 | break; |
| 3656 | } |
| 3657 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3658 | case Primitive::kPrimDouble: { |
| 3659 | // Processing a Dex `double-to-int' instruction. |
| 3660 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3661 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3662 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3663 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3664 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3665 | |
| 3666 | default: |
| 3667 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3668 | << " to " << result_type; |
| 3669 | } |
| 3670 | break; |
| 3671 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3672 | case Primitive::kPrimLong: |
| 3673 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3674 | case Primitive::kPrimBoolean: |
| 3675 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3676 | case Primitive::kPrimByte: |
| 3677 | case Primitive::kPrimShort: |
| 3678 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3679 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3680 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3681 | DCHECK(out.IsRegisterPair()); |
| 3682 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3683 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3684 | // Sign extension. |
| 3685 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3686 | out.AsRegisterPairLow<Register>(), |
| 3687 | 31); |
| 3688 | break; |
| 3689 | |
| 3690 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3691 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3692 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3693 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3694 | break; |
| 3695 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3696 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3697 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3698 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3699 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3700 | break; |
| 3701 | |
| 3702 | default: |
| 3703 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3704 | << " to " << result_type; |
| 3705 | } |
| 3706 | break; |
| 3707 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3708 | case Primitive::kPrimChar: |
| 3709 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3710 | case Primitive::kPrimLong: |
| 3711 | // Type conversion from long to char is a result of code transformations. |
| 3712 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3713 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3714 | case Primitive::kPrimBoolean: |
| 3715 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3716 | case Primitive::kPrimByte: |
| 3717 | case Primitive::kPrimShort: |
| 3718 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3719 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3720 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3721 | break; |
| 3722 | |
| 3723 | default: |
| 3724 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3725 | << " to " << result_type; |
| 3726 | } |
| 3727 | break; |
| 3728 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3729 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3730 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3731 | case Primitive::kPrimBoolean: |
| 3732 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3733 | case Primitive::kPrimByte: |
| 3734 | case Primitive::kPrimShort: |
| 3735 | case Primitive::kPrimInt: |
| 3736 | case Primitive::kPrimChar: { |
| 3737 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3738 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3739 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3740 | break; |
| 3741 | } |
| 3742 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3743 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3744 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3745 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3746 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3747 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3748 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3749 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3750 | // Processing a Dex `double-to-float' instruction. |
| 3751 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3752 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | |
| 3755 | default: |
| 3756 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3757 | << " to " << result_type; |
| 3758 | }; |
| 3759 | break; |
| 3760 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3761 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3762 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3763 | case Primitive::kPrimBoolean: |
| 3764 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3765 | case Primitive::kPrimByte: |
| 3766 | case Primitive::kPrimShort: |
| 3767 | case Primitive::kPrimInt: |
| 3768 | case Primitive::kPrimChar: { |
| 3769 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3770 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3771 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3772 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3773 | break; |
| 3774 | } |
| 3775 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3776 | case Primitive::kPrimLong: { |
| 3777 | // Processing a Dex `long-to-double' instruction. |
| 3778 | Register low = in.AsRegisterPairLow<Register>(); |
| 3779 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3780 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3781 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3782 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3783 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3784 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3785 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3786 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3787 | // temp_d = int-to-double(high) |
| 3788 | __ vmovsr(temp_s, high); |
| 3789 | __ vcvtdi(temp_d, temp_s); |
| 3790 | // constant_d = k2Pow32EncodingForDouble |
| 3791 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3792 | // out_d = unsigned-to-double(low) |
| 3793 | __ vmovsr(out_s, low); |
| 3794 | __ vcvtdu(out_d, out_s); |
| 3795 | // out_d += temp_d * constant_d |
| 3796 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3797 | break; |
| 3798 | } |
| 3799 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3800 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3801 | // Processing a Dex `float-to-double' instruction. |
| 3802 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3803 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3804 | break; |
| 3805 | |
| 3806 | default: |
| 3807 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3808 | << " to " << result_type; |
| 3809 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | |
| 3812 | default: |
| 3813 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3814 | << " to " << result_type; |
| 3815 | } |
| 3816 | } |
| 3817 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3818 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3819 | LocationSummary* locations = |
| 3820 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3821 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3822 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3823 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3824 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3825 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3826 | break; |
| 3827 | } |
| 3828 | |
| 3829 | case Primitive::kPrimLong: { |
| 3830 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3831 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3832 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3833 | break; |
| 3834 | } |
| 3835 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3836 | case Primitive::kPrimFloat: |
| 3837 | case Primitive::kPrimDouble: { |
| 3838 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3839 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3840 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3841 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3842 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3843 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3844 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3845 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3846 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3850 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3851 | Location out = locations->Out(); |
| 3852 | Location first = locations->InAt(0); |
| 3853 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3854 | switch (add->GetResultType()) { |
| 3855 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3856 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3857 | __ add(out.AsRegister<Register>(), |
| 3858 | first.AsRegister<Register>(), |
| 3859 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3860 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3861 | __ AddConstant(out.AsRegister<Register>(), |
| 3862 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3863 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3864 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3865 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3866 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3867 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3868 | if (second.IsConstant()) { |
| 3869 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3870 | GenerateAddLongConst(out, first, value); |
| 3871 | } else { |
| 3872 | DCHECK(second.IsRegisterPair()); |
| 3873 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3874 | first.AsRegisterPairLow<Register>(), |
| 3875 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3876 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3877 | first.AsRegisterPairHigh<Register>(), |
| 3878 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3879 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3880 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3881 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3882 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3883 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3884 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3885 | first.AsFpuRegister<SRegister>(), |
| 3886 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3887 | break; |
| 3888 | |
| 3889 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3890 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3891 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3892 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3893 | break; |
| 3894 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3895 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3896 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3897 | } |
| 3898 | } |
| 3899 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3900 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3901 | LocationSummary* locations = |
| 3902 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3903 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3904 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3906 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3907 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3908 | break; |
| 3909 | } |
| 3910 | |
| 3911 | case Primitive::kPrimLong: { |
| 3912 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3913 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3914 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3915 | break; |
| 3916 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3917 | case Primitive::kPrimFloat: |
| 3918 | case Primitive::kPrimDouble: { |
| 3919 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3920 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3921 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3922 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3923 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3924 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3925 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3926 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3930 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3931 | Location out = locations->Out(); |
| 3932 | Location first = locations->InAt(0); |
| 3933 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3934 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3935 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3936 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3937 | __ sub(out.AsRegister<Register>(), |
| 3938 | first.AsRegister<Register>(), |
| 3939 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3940 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3941 | __ AddConstant(out.AsRegister<Register>(), |
| 3942 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3943 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3944 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3945 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3946 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3947 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3948 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3949 | if (second.IsConstant()) { |
| 3950 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3951 | GenerateAddLongConst(out, first, -value); |
| 3952 | } else { |
| 3953 | DCHECK(second.IsRegisterPair()); |
| 3954 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3955 | first.AsRegisterPairLow<Register>(), |
| 3956 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3957 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3958 | first.AsRegisterPairHigh<Register>(), |
| 3959 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3960 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3961 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3962 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3963 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3964 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3965 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3966 | first.AsFpuRegister<SRegister>(), |
| 3967 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3968 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3972 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3973 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3974 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3975 | break; |
| 3976 | } |
| 3977 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3978 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3979 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3980 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3984 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3985 | LocationSummary* locations = |
| 3986 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3987 | switch (mul->GetResultType()) { |
| 3988 | case Primitive::kPrimInt: |
| 3989 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3990 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3991 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3992 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| 3995 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3996 | case Primitive::kPrimFloat: |
| 3997 | case Primitive::kPrimDouble: { |
| 3998 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3999 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4000 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4001 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4002 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4003 | |
| 4004 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4005 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 4010 | LocationSummary* locations = mul->GetLocations(); |
| 4011 | Location out = locations->Out(); |
| 4012 | Location first = locations->InAt(0); |
| 4013 | Location second = locations->InAt(1); |
| 4014 | switch (mul->GetResultType()) { |
| 4015 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4016 | __ mul(out.AsRegister<Register>(), |
| 4017 | first.AsRegister<Register>(), |
| 4018 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4019 | break; |
| 4020 | } |
| 4021 | case Primitive::kPrimLong: { |
| 4022 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 4023 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 4024 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 4025 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 4026 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 4027 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 4028 | |
| 4029 | // Extra checks to protect caused by the existence of R1_R2. |
| 4030 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4031 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 4032 | DCHECK_NE(out_hi, in1_lo); |
| 4033 | DCHECK_NE(out_hi, in2_lo); |
| 4034 | |
| 4035 | // input: in1 - 64 bits, in2 - 64 bits |
| 4036 | // output: out |
| 4037 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4038 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4039 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4040 | |
| 4041 | // IP <- in1.lo * in2.hi |
| 4042 | __ mul(IP, in1_lo, in2_hi); |
| 4043 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4044 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 4045 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4046 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 4047 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 4048 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 4049 | break; |
| 4050 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4051 | |
| 4052 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4053 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 4054 | first.AsFpuRegister<SRegister>(), |
| 4055 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4056 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 4060 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4061 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4062 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4063 | break; |
| 4064 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4065 | |
| 4066 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 4067 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4071 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4072 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4073 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4074 | |
| 4075 | LocationSummary* locations = instruction->GetLocations(); |
| 4076 | Location second = locations->InAt(1); |
| 4077 | DCHECK(second.IsConstant()); |
| 4078 | |
| 4079 | Register out = locations->Out().AsRegister<Register>(); |
| 4080 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4081 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4082 | DCHECK(imm == 1 || imm == -1); |
| 4083 | |
| 4084 | if (instruction->IsRem()) { |
| 4085 | __ LoadImmediate(out, 0); |
| 4086 | } else { |
| 4087 | if (imm == 1) { |
| 4088 | __ Mov(out, dividend); |
| 4089 | } else { |
| 4090 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4091 | } |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4096 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4097 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4098 | |
| 4099 | LocationSummary* locations = instruction->GetLocations(); |
| 4100 | Location second = locations->InAt(1); |
| 4101 | DCHECK(second.IsConstant()); |
| 4102 | |
| 4103 | Register out = locations->Out().AsRegister<Register>(); |
| 4104 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4105 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4106 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4107 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4108 | int ctz_imm = CTZ(abs_imm); |
| 4109 | |
| 4110 | if (ctz_imm == 1) { |
| 4111 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4112 | } else { |
| 4113 | __ Asr(temp, dividend, 31); |
| 4114 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4115 | } |
| 4116 | __ add(out, temp, ShifterOperand(dividend)); |
| 4117 | |
| 4118 | if (instruction->IsDiv()) { |
| 4119 | __ Asr(out, out, ctz_imm); |
| 4120 | if (imm < 0) { |
| 4121 | __ rsb(out, out, ShifterOperand(0)); |
| 4122 | } |
| 4123 | } else { |
| 4124 | __ ubfx(out, out, 0, ctz_imm); |
| 4125 | __ sub(out, out, ShifterOperand(temp)); |
| 4126 | } |
| 4127 | } |
| 4128 | |
| 4129 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4130 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4131 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4132 | |
| 4133 | LocationSummary* locations = instruction->GetLocations(); |
| 4134 | Location second = locations->InAt(1); |
| 4135 | DCHECK(second.IsConstant()); |
| 4136 | |
| 4137 | Register out = locations->Out().AsRegister<Register>(); |
| 4138 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4139 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4140 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4141 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4142 | |
| 4143 | int64_t magic; |
| 4144 | int shift; |
| 4145 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4146 | |
| 4147 | __ LoadImmediate(temp1, magic); |
| 4148 | __ smull(temp2, temp1, dividend, temp1); |
| 4149 | |
| 4150 | if (imm > 0 && magic < 0) { |
| 4151 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4152 | } else if (imm < 0 && magic > 0) { |
| 4153 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4154 | } |
| 4155 | |
| 4156 | if (shift != 0) { |
| 4157 | __ Asr(temp1, temp1, shift); |
| 4158 | } |
| 4159 | |
| 4160 | if (instruction->IsDiv()) { |
| 4161 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4162 | } else { |
| 4163 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4164 | // TODO: Strength reduction for mls. |
| 4165 | __ LoadImmediate(temp2, imm); |
| 4166 | __ mls(out, temp1, temp2, dividend); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4171 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4172 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4173 | |
| 4174 | LocationSummary* locations = instruction->GetLocations(); |
| 4175 | Location second = locations->InAt(1); |
| 4176 | DCHECK(second.IsConstant()); |
| 4177 | |
| 4178 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4179 | if (imm == 0) { |
| 4180 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4181 | } else if (imm == 1 || imm == -1) { |
| 4182 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4183 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4184 | DivRemByPowerOfTwo(instruction); |
| 4185 | } else { |
| 4186 | DCHECK(imm <= -2 || imm >= 2); |
| 4187 | GenerateDivRemWithAnyConstant(instruction); |
| 4188 | } |
| 4189 | } |
| 4190 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4191 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4192 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4193 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4194 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4195 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4196 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4197 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4198 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4199 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4200 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4201 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4204 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4205 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4206 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4207 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4208 | if (div->InputAt(1)->IsConstant()) { |
| 4209 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4210 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4212 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4213 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4214 | // No temp register required. |
| 4215 | } else { |
| 4216 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4217 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4218 | locations->AddTemp(Location::RequiresRegister()); |
| 4219 | } |
| 4220 | } |
| 4221 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4223 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4224 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4225 | } else { |
| 4226 | InvokeRuntimeCallingConvention calling_convention; |
| 4227 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4228 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4229 | // 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] | 4230 | // we only need the former. |
| 4231 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4232 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4233 | break; |
| 4234 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4235 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4236 | InvokeRuntimeCallingConvention calling_convention; |
| 4237 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4238 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4239 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4240 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4241 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4242 | break; |
| 4243 | } |
| 4244 | case Primitive::kPrimFloat: |
| 4245 | case Primitive::kPrimDouble: { |
| 4246 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4247 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4248 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4249 | break; |
| 4250 | } |
| 4251 | |
| 4252 | default: |
| 4253 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4254 | } |
| 4255 | } |
| 4256 | |
| 4257 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4258 | LocationSummary* locations = div->GetLocations(); |
| 4259 | Location out = locations->Out(); |
| 4260 | Location first = locations->InAt(0); |
| 4261 | Location second = locations->InAt(1); |
| 4262 | |
| 4263 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4264 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4265 | if (second.IsConstant()) { |
| 4266 | GenerateDivRemConstantIntegral(div); |
| 4267 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4268 | __ sdiv(out.AsRegister<Register>(), |
| 4269 | first.AsRegister<Register>(), |
| 4270 | second.AsRegister<Register>()); |
| 4271 | } else { |
| 4272 | InvokeRuntimeCallingConvention calling_convention; |
| 4273 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4274 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4275 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4276 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4277 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4278 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4279 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4280 | break; |
| 4281 | } |
| 4282 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4283 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4284 | InvokeRuntimeCallingConvention calling_convention; |
| 4285 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4286 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4287 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4288 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4289 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4290 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4291 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4292 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4293 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4294 | break; |
| 4295 | } |
| 4296 | |
| 4297 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4298 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4299 | first.AsFpuRegister<SRegister>(), |
| 4300 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4301 | break; |
| 4302 | } |
| 4303 | |
| 4304 | case Primitive::kPrimDouble: { |
| 4305 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4306 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4307 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4308 | break; |
| 4309 | } |
| 4310 | |
| 4311 | default: |
| 4312 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4313 | } |
| 4314 | } |
| 4315 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4316 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4317 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4318 | |
| 4319 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4320 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4321 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4322 | // sdiv will be replaced by other instruction sequence. |
| 4323 | call_kind = LocationSummary::kNoCall; |
| 4324 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4325 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4326 | // Have hardware divide instruction for int, do it with three instructions. |
| 4327 | call_kind = LocationSummary::kNoCall; |
| 4328 | } |
| 4329 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4330 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4331 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4332 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4333 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4334 | if (rem->InputAt(1)->IsConstant()) { |
| 4335 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4336 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4337 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4338 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4339 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4340 | // No temp register required. |
| 4341 | } else { |
| 4342 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4343 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4344 | locations->AddTemp(Location::RequiresRegister()); |
| 4345 | } |
| 4346 | } |
| 4347 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4349 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4350 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4351 | locations->AddTemp(Location::RequiresRegister()); |
| 4352 | } else { |
| 4353 | InvokeRuntimeCallingConvention calling_convention; |
| 4354 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4355 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4356 | // 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] | 4357 | // we only need the latter. |
| 4358 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4359 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4360 | break; |
| 4361 | } |
| 4362 | case Primitive::kPrimLong: { |
| 4363 | InvokeRuntimeCallingConvention calling_convention; |
| 4364 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4365 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4366 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4367 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4368 | // The runtime helper puts the output in R2,R3. |
| 4369 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4370 | break; |
| 4371 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4372 | case Primitive::kPrimFloat: { |
| 4373 | InvokeRuntimeCallingConvention calling_convention; |
| 4374 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4375 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4376 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4377 | break; |
| 4378 | } |
| 4379 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4380 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4381 | InvokeRuntimeCallingConvention calling_convention; |
| 4382 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4383 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4384 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4385 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4386 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4387 | break; |
| 4388 | } |
| 4389 | |
| 4390 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4391 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4396 | LocationSummary* locations = rem->GetLocations(); |
| 4397 | Location out = locations->Out(); |
| 4398 | Location first = locations->InAt(0); |
| 4399 | Location second = locations->InAt(1); |
| 4400 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4401 | Primitive::Type type = rem->GetResultType(); |
| 4402 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4403 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4404 | if (second.IsConstant()) { |
| 4405 | GenerateDivRemConstantIntegral(rem); |
| 4406 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4407 | Register reg1 = first.AsRegister<Register>(); |
| 4408 | Register reg2 = second.AsRegister<Register>(); |
| 4409 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4410 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4411 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4412 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4413 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4414 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4415 | } else { |
| 4416 | InvokeRuntimeCallingConvention calling_convention; |
| 4417 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4418 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4419 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4420 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4421 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4422 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4423 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4424 | break; |
| 4425 | } |
| 4426 | |
| 4427 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4428 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4429 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4430 | break; |
| 4431 | } |
| 4432 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4433 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4434 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4435 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4436 | break; |
| 4437 | } |
| 4438 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4439 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4440 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4441 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4442 | break; |
| 4443 | } |
| 4444 | |
| 4445 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4446 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4447 | } |
| 4448 | } |
| 4449 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4450 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4451 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4452 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4456 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4457 | codegen_->AddSlowPath(slow_path); |
| 4458 | |
| 4459 | LocationSummary* locations = instruction->GetLocations(); |
| 4460 | Location value = locations->InAt(0); |
| 4461 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4462 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4463 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4464 | case Primitive::kPrimByte: |
| 4465 | case Primitive::kPrimChar: |
| 4466 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4467 | case Primitive::kPrimInt: { |
| 4468 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4469 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4470 | } else { |
| 4471 | DCHECK(value.IsConstant()) << value; |
| 4472 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4473 | __ b(slow_path->GetEntryLabel()); |
| 4474 | } |
| 4475 | } |
| 4476 | break; |
| 4477 | } |
| 4478 | case Primitive::kPrimLong: { |
| 4479 | if (value.IsRegisterPair()) { |
| 4480 | __ orrs(IP, |
| 4481 | value.AsRegisterPairLow<Register>(), |
| 4482 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4483 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4484 | } else { |
| 4485 | DCHECK(value.IsConstant()) << value; |
| 4486 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4487 | __ b(slow_path->GetEntryLabel()); |
| 4488 | } |
| 4489 | } |
| 4490 | break; |
| 4491 | default: |
| 4492 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4493 | } |
| 4494 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4497 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4498 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4499 | Location rhs = locations->InAt(1); |
| 4500 | Register out = locations->Out().AsRegister<Register>(); |
| 4501 | |
| 4502 | if (rhs.IsConstant()) { |
| 4503 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4504 | // so map all rotations to a +ve. equivalent in that range. |
| 4505 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4506 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4507 | if (rot) { |
| 4508 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4509 | // (e.g. left by 2 bits == right by 30.) |
| 4510 | __ Ror(out, in, rot); |
| 4511 | } else if (out != in) { |
| 4512 | __ Mov(out, in); |
| 4513 | } |
| 4514 | } else { |
| 4515 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4520 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4521 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4522 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4523 | void InstructionCodeGeneratorARM::HandleLongRotate(HRor* ror) { |
| 4524 | LocationSummary* locations = ror->GetLocations(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4525 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4526 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4527 | Location rhs = locations->InAt(1); |
| 4528 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4529 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4530 | |
| 4531 | if (rhs.IsConstant()) { |
| 4532 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4533 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4534 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4535 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4536 | // logic below to a simple pair of binary orr. |
| 4537 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4538 | if (rot >= kArmBitsPerWord) { |
| 4539 | rot -= kArmBitsPerWord; |
| 4540 | std::swap(in_reg_hi, in_reg_lo); |
| 4541 | } |
| 4542 | // Rotate, or mov to out for zero or word size rotations. |
| 4543 | if (rot != 0u) { |
| 4544 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4545 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4546 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4547 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4548 | } else { |
| 4549 | __ Mov(out_reg_lo, in_reg_lo); |
| 4550 | __ Mov(out_reg_hi, in_reg_hi); |
| 4551 | } |
| 4552 | } else { |
| 4553 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4554 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4555 | Label end; |
| 4556 | Label shift_by_32_plus_shift_right; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4557 | Label* final_label = codegen_->GetFinalLabel(ror, &end); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4558 | |
| 4559 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4560 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4561 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4562 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4563 | |
| 4564 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4565 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4566 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4567 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4568 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4569 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4570 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4571 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4572 | __ b(final_label); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4573 | |
| 4574 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4575 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4576 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4577 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4578 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4579 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4580 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4581 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4582 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4583 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4584 | if (end.IsLinked()) { |
| 4585 | __ Bind(&end); |
| 4586 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4587 | } |
| 4588 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4589 | |
| 4590 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4591 | LocationSummary* locations = |
| 4592 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4593 | switch (ror->GetResultType()) { |
| 4594 | case Primitive::kPrimInt: { |
| 4595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4596 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4597 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4598 | break; |
| 4599 | } |
| 4600 | case Primitive::kPrimLong: { |
| 4601 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4602 | if (ror->InputAt(1)->IsConstant()) { |
| 4603 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4604 | } else { |
| 4605 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4606 | locations->AddTemp(Location::RequiresRegister()); |
| 4607 | locations->AddTemp(Location::RequiresRegister()); |
| 4608 | } |
| 4609 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4610 | break; |
| 4611 | } |
| 4612 | default: |
| 4613 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4617 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4618 | LocationSummary* locations = ror->GetLocations(); |
| 4619 | Primitive::Type type = ror->GetResultType(); |
| 4620 | switch (type) { |
| 4621 | case Primitive::kPrimInt: { |
| 4622 | HandleIntegerRotate(locations); |
| 4623 | break; |
| 4624 | } |
| 4625 | case Primitive::kPrimLong: { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4626 | HandleLongRotate(ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4627 | break; |
| 4628 | } |
| 4629 | default: |
| 4630 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4631 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4632 | } |
| 4633 | } |
| 4634 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4635 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4636 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4637 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4638 | LocationSummary* locations = |
| 4639 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4640 | |
| 4641 | switch (op->GetResultType()) { |
| 4642 | case Primitive::kPrimInt: { |
| 4643 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4644 | if (op->InputAt(1)->IsConstant()) { |
| 4645 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4647 | } else { |
| 4648 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4649 | // Make the output overlap, as it will be used to hold the masked |
| 4650 | // second input. |
| 4651 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4652 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4653 | break; |
| 4654 | } |
| 4655 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4656 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4657 | if (op->InputAt(1)->IsConstant()) { |
| 4658 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4659 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4660 | // don't clash with high registers which the register allocator currently guarantees. |
| 4661 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4662 | } else { |
| 4663 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4664 | locations->AddTemp(Location::RequiresRegister()); |
| 4665 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4666 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | default: |
| 4670 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4675 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4676 | |
| 4677 | LocationSummary* locations = op->GetLocations(); |
| 4678 | Location out = locations->Out(); |
| 4679 | Location first = locations->InAt(0); |
| 4680 | Location second = locations->InAt(1); |
| 4681 | |
| 4682 | Primitive::Type type = op->GetResultType(); |
| 4683 | switch (type) { |
| 4684 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4685 | Register out_reg = out.AsRegister<Register>(); |
| 4686 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4687 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4688 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4689 | // 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] | 4690 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4691 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4692 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4693 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4694 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4695 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4696 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4697 | } |
| 4698 | } else { |
| 4699 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4700 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4701 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4702 | __ Mov(out_reg, first_reg); |
| 4703 | } else if (op->IsShl()) { |
| 4704 | __ Lsl(out_reg, first_reg, shift_value); |
| 4705 | } else if (op->IsShr()) { |
| 4706 | __ Asr(out_reg, first_reg, shift_value); |
| 4707 | } else { |
| 4708 | __ Lsr(out_reg, first_reg, shift_value); |
| 4709 | } |
| 4710 | } |
| 4711 | break; |
| 4712 | } |
| 4713 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4714 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4715 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4716 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4717 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4718 | Register low = first.AsRegisterPairLow<Register>(); |
| 4719 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4720 | if (second.IsRegister()) { |
| 4721 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4722 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4723 | Register second_reg = second.AsRegister<Register>(); |
| 4724 | |
| 4725 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4726 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4727 | // Shift the high part |
| 4728 | __ Lsl(o_h, high, o_l); |
| 4729 | // Shift the low part and `or` what overflew on the high part |
| 4730 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4731 | __ Lsr(temp, low, temp); |
| 4732 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4733 | // If the shift is > 32 bits, override the high part |
| 4734 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4735 | __ it(PL); |
| 4736 | __ Lsl(o_h, low, temp, PL); |
| 4737 | // Shift the low part |
| 4738 | __ Lsl(o_l, low, o_l); |
| 4739 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4740 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4741 | // Shift the low part |
| 4742 | __ Lsr(o_l, low, o_h); |
| 4743 | // Shift the high part and `or` what underflew on the low part |
| 4744 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4745 | __ Lsl(temp, high, temp); |
| 4746 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4747 | // If the shift is > 32 bits, override the low part |
| 4748 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4749 | __ it(PL); |
| 4750 | __ Asr(o_l, high, temp, PL); |
| 4751 | // Shift the high part |
| 4752 | __ Asr(o_h, high, o_h); |
| 4753 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4754 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4755 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4756 | __ Lsr(o_l, low, o_h); |
| 4757 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4758 | __ Lsl(temp, high, temp); |
| 4759 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4760 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4761 | __ it(PL); |
| 4762 | __ Lsr(o_l, high, temp, PL); |
| 4763 | __ Lsr(o_h, high, o_h); |
| 4764 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4765 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4766 | // Register allocator doesn't create partial overlap. |
| 4767 | DCHECK_NE(o_l, high); |
| 4768 | DCHECK_NE(o_h, low); |
| 4769 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4770 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4771 | if (shift_value > 32) { |
| 4772 | if (op->IsShl()) { |
| 4773 | __ Lsl(o_h, low, shift_value - 32); |
| 4774 | __ LoadImmediate(o_l, 0); |
| 4775 | } else if (op->IsShr()) { |
| 4776 | __ Asr(o_l, high, shift_value - 32); |
| 4777 | __ Asr(o_h, high, 31); |
| 4778 | } else { |
| 4779 | __ Lsr(o_l, high, shift_value - 32); |
| 4780 | __ LoadImmediate(o_h, 0); |
| 4781 | } |
| 4782 | } else if (shift_value == 32) { |
| 4783 | if (op->IsShl()) { |
| 4784 | __ mov(o_h, ShifterOperand(low)); |
| 4785 | __ LoadImmediate(o_l, 0); |
| 4786 | } else if (op->IsShr()) { |
| 4787 | __ mov(o_l, ShifterOperand(high)); |
| 4788 | __ Asr(o_h, high, 31); |
| 4789 | } else { |
| 4790 | __ mov(o_l, ShifterOperand(high)); |
| 4791 | __ LoadImmediate(o_h, 0); |
| 4792 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4793 | } else if (shift_value == 1) { |
| 4794 | if (op->IsShl()) { |
| 4795 | __ Lsls(o_l, low, 1); |
| 4796 | __ adc(o_h, high, ShifterOperand(high)); |
| 4797 | } else if (op->IsShr()) { |
| 4798 | __ Asrs(o_h, high, 1); |
| 4799 | __ Rrx(o_l, low); |
| 4800 | } else { |
| 4801 | __ Lsrs(o_h, high, 1); |
| 4802 | __ Rrx(o_l, low); |
| 4803 | } |
| 4804 | } else { |
| 4805 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4806 | if (op->IsShl()) { |
| 4807 | __ Lsl(o_h, high, shift_value); |
| 4808 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4809 | __ Lsl(o_l, low, shift_value); |
| 4810 | } else if (op->IsShr()) { |
| 4811 | __ Lsr(o_l, low, shift_value); |
| 4812 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4813 | __ Asr(o_h, high, shift_value); |
| 4814 | } else { |
| 4815 | __ Lsr(o_l, low, shift_value); |
| 4816 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4817 | __ Lsr(o_h, high, shift_value); |
| 4818 | } |
| 4819 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4820 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4821 | break; |
| 4822 | } |
| 4823 | default: |
| 4824 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4825 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4830 | HandleShift(shl); |
| 4831 | } |
| 4832 | |
| 4833 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4834 | HandleShift(shl); |
| 4835 | } |
| 4836 | |
| 4837 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4838 | HandleShift(shr); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4842 | HandleShift(shr); |
| 4843 | } |
| 4844 | |
| 4845 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4846 | HandleShift(ushr); |
| 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4850 | HandleShift(ushr); |
| 4851 | } |
| 4852 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4853 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4854 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4855 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4856 | if (instruction->IsStringAlloc()) { |
| 4857 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4858 | } else { |
| 4859 | InvokeRuntimeCallingConvention calling_convention; |
| 4860 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4861 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4862 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4866 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4867 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4868 | if (instruction->IsStringAlloc()) { |
| 4869 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4870 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4871 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4872 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4873 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4874 | __ blx(LR); |
| 4875 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4876 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4877 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4878 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4879 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4880 | } |
| 4881 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4882 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4883 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4884 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4885 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4886 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4887 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4888 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4892 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4893 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4894 | QuickEntrypointEnum entrypoint = |
| 4895 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4896 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4897 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4898 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4899 | } |
| 4900 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4901 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4902 | LocationSummary* locations = |
| 4903 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4904 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4905 | if (location.IsStackSlot()) { |
| 4906 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4907 | } else if (location.IsDoubleStackSlot()) { |
| 4908 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4909 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4910 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4911 | } |
| 4912 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4913 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4914 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4915 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4919 | LocationSummary* locations = |
| 4920 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4921 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4922 | } |
| 4923 | |
| 4924 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4925 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4926 | } |
| 4927 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4928 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4929 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4930 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4931 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4932 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4933 | } |
| 4934 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4935 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4936 | LocationSummary* locations = not_->GetLocations(); |
| 4937 | Location out = locations->Out(); |
| 4938 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4939 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4940 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4941 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4942 | break; |
| 4943 | |
| 4944 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4945 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4946 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4947 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4948 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4949 | break; |
| 4950 | |
| 4951 | default: |
| 4952 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4953 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4954 | } |
| 4955 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4956 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4957 | LocationSummary* locations = |
| 4958 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4960 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4961 | } |
| 4962 | |
| 4963 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4964 | LocationSummary* locations = bool_not->GetLocations(); |
| 4965 | Location out = locations->Out(); |
| 4966 | Location in = locations->InAt(0); |
| 4967 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4968 | } |
| 4969 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4970 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4971 | LocationSummary* locations = |
| 4972 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4973 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4974 | case Primitive::kPrimBoolean: |
| 4975 | case Primitive::kPrimByte: |
| 4976 | case Primitive::kPrimShort: |
| 4977 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4978 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4979 | case Primitive::kPrimLong: { |
| 4980 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4981 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4982 | // Output overlaps because it is written before doing the low comparison. |
| 4983 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4984 | break; |
| 4985 | } |
| 4986 | case Primitive::kPrimFloat: |
| 4987 | case Primitive::kPrimDouble: { |
| 4988 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4989 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4990 | locations->SetOut(Location::RequiresRegister()); |
| 4991 | break; |
| 4992 | } |
| 4993 | default: |
| 4994 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4995 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4999 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5000 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5001 | Location left = locations->InAt(0); |
| 5002 | Location right = locations->InAt(1); |
| 5003 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5004 | Label less, greater, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5005 | Label* final_label = codegen_->GetFinalLabel(compare, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5006 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5007 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5008 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 5009 | case Primitive::kPrimBoolean: |
| 5010 | case Primitive::kPrimByte: |
| 5011 | case Primitive::kPrimShort: |
| 5012 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5013 | case Primitive::kPrimInt: { |
| 5014 | __ LoadImmediate(out, 0); |
| 5015 | __ cmp(left.AsRegister<Register>(), |
| 5016 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 5017 | less_cond = LT; |
| 5018 | break; |
| 5019 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5020 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5021 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 5022 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5023 | __ b(&less, LT); |
| 5024 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5025 | // 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] | 5026 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5027 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 5028 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5029 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5030 | break; |
| 5031 | } |
| 5032 | case Primitive::kPrimFloat: |
| 5033 | case Primitive::kPrimDouble: { |
| 5034 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5035 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5036 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5037 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5041 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5042 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5043 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 5044 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5045 | __ b(final_label, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 5046 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5047 | |
| 5048 | __ Bind(&greater); |
| 5049 | __ LoadImmediate(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5050 | __ b(final_label); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 5051 | |
| 5052 | __ Bind(&less); |
| 5053 | __ LoadImmediate(out, -1); |
| 5054 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5055 | if (done.IsLinked()) { |
| 5056 | __ Bind(&done); |
| 5057 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5058 | } |
| 5059 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5060 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5061 | LocationSummary* locations = |
| 5062 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5063 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 5064 | locations->SetInAt(i, Location::Any()); |
| 5065 | } |
| 5066 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5069 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5070 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5073 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5074 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5075 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5076 | switch (kind) { |
| 5077 | case MemBarrierKind::kAnyStore: |
| 5078 | case MemBarrierKind::kLoadAny: |
| 5079 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5080 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5081 | break; |
| 5082 | } |
| 5083 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5084 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5085 | break; |
| 5086 | } |
| 5087 | default: |
| 5088 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5089 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5090 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5094 | uint32_t offset, |
| 5095 | Register out_lo, |
| 5096 | Register out_hi) { |
| 5097 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5098 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5099 | // `offset` into `out_lo` does not clutter `addr`. |
| 5100 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5101 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5102 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5103 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5104 | } |
| 5105 | __ ldrexd(out_lo, out_hi, addr); |
| 5106 | } |
| 5107 | |
| 5108 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5109 | uint32_t offset, |
| 5110 | Register value_lo, |
| 5111 | Register value_hi, |
| 5112 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5113 | Register temp2, |
| 5114 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5115 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5116 | if (offset != 0) { |
| 5117 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5118 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5119 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5120 | } |
| 5121 | __ Bind(&fail); |
| 5122 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5123 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5124 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5126 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5127 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5131 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5132 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5133 | LocationSummary* locations = |
| 5134 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5135 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5136 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5137 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5138 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5139 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5140 | } else { |
| 5141 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5142 | } |
| 5143 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5144 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5145 | bool generate_volatile = field_info.IsVolatile() |
| 5146 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5147 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5148 | bool needs_write_barrier = |
| 5149 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5150 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5151 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5152 | if (needs_write_barrier) { |
| 5153 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5154 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5155 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5156 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5157 | // - registers need to be consecutive |
| 5158 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5159 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5160 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5161 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5162 | |
| 5163 | locations->AddTemp(Location::RequiresRegister()); |
| 5164 | locations->AddTemp(Location::RequiresRegister()); |
| 5165 | if (field_type == Primitive::kPrimDouble) { |
| 5166 | // For doubles we need two more registers to copy the value. |
| 5167 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5168 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5169 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5170 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5171 | } |
| 5172 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5173 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5174 | const FieldInfo& field_info, |
| 5175 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5176 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5177 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5178 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5179 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5180 | Location value = locations->InAt(1); |
| 5181 | |
| 5182 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5183 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5185 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5186 | bool needs_write_barrier = |
| 5187 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5188 | |
| 5189 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5190 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5191 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5192 | |
| 5193 | switch (field_type) { |
| 5194 | case Primitive::kPrimBoolean: |
| 5195 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5196 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
| 5200 | case Primitive::kPrimShort: |
| 5201 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5202 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5203 | break; |
| 5204 | } |
| 5205 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5206 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5207 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5208 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5209 | // Note that in the case where `value` is a null reference, |
| 5210 | // we do not enter this block, as a null reference does not |
| 5211 | // need poisoning. |
| 5212 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5213 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5214 | __ Mov(temp, value.AsRegister<Register>()); |
| 5215 | __ PoisonHeapReference(temp); |
| 5216 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5217 | } else { |
| 5218 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5219 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5220 | break; |
| 5221 | } |
| 5222 | |
| 5223 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5224 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5225 | GenerateWideAtomicStore(base, offset, |
| 5226 | value.AsRegisterPairLow<Register>(), |
| 5227 | value.AsRegisterPairHigh<Register>(), |
| 5228 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5229 | locations->GetTemp(1).AsRegister<Register>(), |
| 5230 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5231 | } else { |
| 5232 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5233 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5234 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5235 | break; |
| 5236 | } |
| 5237 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5238 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5239 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5240 | break; |
| 5241 | } |
| 5242 | |
| 5243 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5244 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5245 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5246 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5247 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5248 | |
| 5249 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5250 | |
| 5251 | GenerateWideAtomicStore(base, offset, |
| 5252 | value_reg_lo, |
| 5253 | value_reg_hi, |
| 5254 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5255 | locations->GetTemp(3).AsRegister<Register>(), |
| 5256 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5257 | } else { |
| 5258 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5259 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5260 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5261 | break; |
| 5262 | } |
| 5263 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5264 | case Primitive::kPrimVoid: |
| 5265 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5266 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5267 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5268 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5269 | // Longs and doubles are handled in the switch. |
| 5270 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5271 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5272 | } |
| 5273 | |
| 5274 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5275 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5276 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5277 | codegen_->MarkGCCard( |
| 5278 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5279 | } |
| 5280 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5281 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5282 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5283 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5284 | } |
| 5285 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5286 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5287 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5288 | |
| 5289 | bool object_field_get_with_read_barrier = |
| 5290 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5291 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5292 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5293 | object_field_get_with_read_barrier ? |
| 5294 | LocationSummary::kCallOnSlowPath : |
| 5295 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5296 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5297 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5298 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5299 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5300 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5301 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5302 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5303 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5304 | // The output overlaps in case of volatile long: we don't want the |
| 5305 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5306 | // object's location. Likewise, in the case of an object field get |
| 5307 | // with read barriers enabled, we do not want the load to overwrite |
| 5308 | // the object's location, as we need it to emit the read barrier. |
| 5309 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5310 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5311 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5312 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5313 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5314 | } else { |
| 5315 | locations->SetOut(Location::RequiresRegister(), |
| 5316 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5317 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5318 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5319 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5320 | // - registers need to be consecutive |
| 5321 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5322 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5323 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5324 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5325 | locations->AddTemp(Location::RequiresRegister()); |
| 5326 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5327 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5328 | // We need a temporary register for the read barrier marking slow |
| 5329 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5330 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5331 | !Runtime::Current()->UseJitCompilation()) { |
| 5332 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5333 | // loads we need a temporary only if the offset is too big. |
| 5334 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| 5335 | locations->AddTemp(Location::RequiresRegister()); |
| 5336 | } |
| 5337 | // And we always need the reserved entrypoint register. |
| 5338 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5339 | } else { |
| 5340 | locations->AddTemp(Location::RequiresRegister()); |
| 5341 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5342 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5343 | } |
| 5344 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5345 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5346 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5347 | << input->GetType(); |
| 5348 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5349 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5350 | return Location::ConstantLocation(input->AsConstant()); |
| 5351 | } else { |
| 5352 | return Location::RequiresFpuRegister(); |
| 5353 | } |
| 5354 | } |
| 5355 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5356 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5357 | Opcode opcode) { |
| 5358 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5359 | if (constant->IsConstant() && |
| 5360 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5361 | return Location::ConstantLocation(constant->AsConstant()); |
| 5362 | } |
| 5363 | return Location::RequiresRegister(); |
| 5364 | } |
| 5365 | |
| 5366 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5367 | Opcode opcode) { |
| 5368 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5369 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5370 | Opcode high_opcode = opcode; |
| 5371 | SetCc low_set_cc = kCcDontCare; |
| 5372 | switch (opcode) { |
| 5373 | case SUB: |
| 5374 | // Flip the operation to an ADD. |
| 5375 | value = -value; |
| 5376 | opcode = ADD; |
| 5377 | FALLTHROUGH_INTENDED; |
| 5378 | case ADD: |
| 5379 | if (Low32Bits(value) == 0u) { |
| 5380 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5381 | } |
| 5382 | high_opcode = ADC; |
| 5383 | low_set_cc = kCcSet; |
| 5384 | break; |
| 5385 | default: |
| 5386 | break; |
| 5387 | } |
| 5388 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5389 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5390 | } else { |
| 5391 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5392 | } |
| 5393 | } |
| 5394 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5395 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5396 | Opcode opcode, |
| 5397 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5398 | ShifterOperand so; |
| 5399 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5400 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5401 | return true; |
| 5402 | } |
| 5403 | Opcode neg_opcode = kNoOperand; |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5404 | uint32_t neg_value = 0; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5405 | switch (opcode) { |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5406 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5407 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5408 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5409 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5410 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5411 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5412 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5413 | default: |
| 5414 | return false; |
| 5415 | } |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5416 | |
| 5417 | if (assembler->ShifterOperandCanHold(kNoRegister, |
| 5418 | kNoRegister, |
| 5419 | neg_opcode, |
| 5420 | neg_value, |
| 5421 | set_cc, |
| 5422 | &so)) { |
| 5423 | return true; |
| 5424 | } |
| 5425 | |
| 5426 | return opcode == AND && IsPowerOfTwo(value + 1); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5429 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5430 | const FieldInfo& field_info) { |
| 5431 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5432 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5433 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5434 | Location base_loc = locations->InAt(0); |
| 5435 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5436 | Location out = locations->Out(); |
| 5437 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5438 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5439 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5440 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5441 | |
| 5442 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5443 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5444 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5445 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5446 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5447 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5448 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5449 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5450 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5451 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5452 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5453 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5454 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5455 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5456 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5457 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5458 | |
| 5459 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5460 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5461 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5462 | |
| 5463 | case Primitive::kPrimNot: { |
| 5464 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5465 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5466 | Location temp_loc = locations->GetTemp(0); |
| 5467 | // Note that a potential implicit null check is handled in this |
| 5468 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5469 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5470 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5471 | if (is_volatile) { |
| 5472 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5473 | } |
| 5474 | } else { |
| 5475 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5476 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5477 | if (is_volatile) { |
| 5478 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5479 | } |
| 5480 | // If read barriers are enabled, emit read barriers other than |
| 5481 | // Baker's using a slow path (and also unpoison the loaded |
| 5482 | // reference, if heap poisoning is enabled). |
| 5483 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5484 | } |
| 5485 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5488 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5489 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5490 | GenerateWideAtomicLoad(base, offset, |
| 5491 | out.AsRegisterPairLow<Register>(), |
| 5492 | out.AsRegisterPairHigh<Register>()); |
| 5493 | } else { |
| 5494 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5495 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5496 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5497 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5498 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5499 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5500 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5501 | |
| 5502 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5503 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5504 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5505 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5506 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5507 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5508 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5509 | __ vmovdrr(out_reg, lo, hi); |
| 5510 | } else { |
| 5511 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5512 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5513 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5514 | break; |
| 5515 | } |
| 5516 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5517 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5518 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5519 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5520 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5521 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5522 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5523 | // Potential implicit null checks, in the case of reference or |
| 5524 | // double fields, are handled in the previous switch statement. |
| 5525 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5526 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5527 | } |
| 5528 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5529 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5530 | if (field_type == Primitive::kPrimNot) { |
| 5531 | // Memory barriers, in the case of references, are also handled |
| 5532 | // in the previous switch statement. |
| 5533 | } else { |
| 5534 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5535 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5536 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5540 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5541 | } |
| 5542 | |
| 5543 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5544 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5548 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5549 | } |
| 5550 | |
| 5551 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5552 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5553 | } |
| 5554 | |
| 5555 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5556 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5557 | } |
| 5558 | |
| 5559 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5560 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5561 | } |
| 5562 | |
| 5563 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5564 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5565 | } |
| 5566 | |
| 5567 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5568 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5569 | } |
| 5570 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5571 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5572 | HUnresolvedInstanceFieldGet* instruction) { |
| 5573 | FieldAccessCallingConventionARM calling_convention; |
| 5574 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5575 | instruction, instruction->GetFieldType(), calling_convention); |
| 5576 | } |
| 5577 | |
| 5578 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5579 | HUnresolvedInstanceFieldGet* instruction) { |
| 5580 | FieldAccessCallingConventionARM calling_convention; |
| 5581 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5582 | instruction->GetFieldType(), |
| 5583 | instruction->GetFieldIndex(), |
| 5584 | instruction->GetDexPc(), |
| 5585 | calling_convention); |
| 5586 | } |
| 5587 | |
| 5588 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5589 | HUnresolvedInstanceFieldSet* instruction) { |
| 5590 | FieldAccessCallingConventionARM calling_convention; |
| 5591 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5592 | instruction, instruction->GetFieldType(), calling_convention); |
| 5593 | } |
| 5594 | |
| 5595 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5596 | HUnresolvedInstanceFieldSet* instruction) { |
| 5597 | FieldAccessCallingConventionARM calling_convention; |
| 5598 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5599 | instruction->GetFieldType(), |
| 5600 | instruction->GetFieldIndex(), |
| 5601 | instruction->GetDexPc(), |
| 5602 | calling_convention); |
| 5603 | } |
| 5604 | |
| 5605 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5606 | HUnresolvedStaticFieldGet* instruction) { |
| 5607 | FieldAccessCallingConventionARM calling_convention; |
| 5608 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5609 | instruction, instruction->GetFieldType(), calling_convention); |
| 5610 | } |
| 5611 | |
| 5612 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5613 | HUnresolvedStaticFieldGet* instruction) { |
| 5614 | FieldAccessCallingConventionARM calling_convention; |
| 5615 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5616 | instruction->GetFieldType(), |
| 5617 | instruction->GetFieldIndex(), |
| 5618 | instruction->GetDexPc(), |
| 5619 | calling_convention); |
| 5620 | } |
| 5621 | |
| 5622 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5623 | HUnresolvedStaticFieldSet* instruction) { |
| 5624 | FieldAccessCallingConventionARM calling_convention; |
| 5625 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5626 | instruction, instruction->GetFieldType(), calling_convention); |
| 5627 | } |
| 5628 | |
| 5629 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5630 | HUnresolvedStaticFieldSet* instruction) { |
| 5631 | FieldAccessCallingConventionARM calling_convention; |
| 5632 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5633 | instruction->GetFieldType(), |
| 5634 | instruction->GetFieldIndex(), |
| 5635 | instruction->GetDexPc(), |
| 5636 | calling_convention); |
| 5637 | } |
| 5638 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5639 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5640 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5641 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5644 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5645 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5646 | return; |
| 5647 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5648 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5649 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5650 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5651 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5654 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5655 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5656 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5657 | |
| 5658 | LocationSummary* locations = instruction->GetLocations(); |
| 5659 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5660 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5661 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5662 | } |
| 5663 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5664 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5665 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5668 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5669 | switch (type) { |
| 5670 | case Primitive::kPrimNot: |
| 5671 | return kLoadWord; |
| 5672 | case Primitive::kPrimBoolean: |
| 5673 | return kLoadUnsignedByte; |
| 5674 | case Primitive::kPrimByte: |
| 5675 | return kLoadSignedByte; |
| 5676 | case Primitive::kPrimChar: |
| 5677 | return kLoadUnsignedHalfword; |
| 5678 | case Primitive::kPrimShort: |
| 5679 | return kLoadSignedHalfword; |
| 5680 | case Primitive::kPrimInt: |
| 5681 | return kLoadWord; |
| 5682 | case Primitive::kPrimLong: |
| 5683 | return kLoadWordPair; |
| 5684 | case Primitive::kPrimFloat: |
| 5685 | return kLoadSWord; |
| 5686 | case Primitive::kPrimDouble: |
| 5687 | return kLoadDWord; |
| 5688 | default: |
| 5689 | LOG(FATAL) << "Unreachable type " << type; |
| 5690 | UNREACHABLE(); |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5695 | switch (type) { |
| 5696 | case Primitive::kPrimNot: |
| 5697 | return kStoreWord; |
| 5698 | case Primitive::kPrimBoolean: |
| 5699 | case Primitive::kPrimByte: |
| 5700 | return kStoreByte; |
| 5701 | case Primitive::kPrimChar: |
| 5702 | case Primitive::kPrimShort: |
| 5703 | return kStoreHalfword; |
| 5704 | case Primitive::kPrimInt: |
| 5705 | return kStoreWord; |
| 5706 | case Primitive::kPrimLong: |
| 5707 | return kStoreWordPair; |
| 5708 | case Primitive::kPrimFloat: |
| 5709 | return kStoreSWord; |
| 5710 | case Primitive::kPrimDouble: |
| 5711 | return kStoreDWord; |
| 5712 | default: |
| 5713 | LOG(FATAL) << "Unreachable type " << type; |
| 5714 | UNREACHABLE(); |
| 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5719 | Location out_loc, |
| 5720 | Register base, |
| 5721 | Register reg_offset, |
| 5722 | Condition cond) { |
| 5723 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5724 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5725 | |
| 5726 | switch (type) { |
| 5727 | case Primitive::kPrimByte: |
| 5728 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5729 | break; |
| 5730 | case Primitive::kPrimBoolean: |
| 5731 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5732 | break; |
| 5733 | case Primitive::kPrimShort: |
| 5734 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5735 | break; |
| 5736 | case Primitive::kPrimChar: |
| 5737 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5738 | break; |
| 5739 | case Primitive::kPrimNot: |
| 5740 | case Primitive::kPrimInt: |
| 5741 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5742 | break; |
| 5743 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5744 | case Primitive::kPrimLong: |
| 5745 | case Primitive::kPrimFloat: |
| 5746 | case Primitive::kPrimDouble: |
| 5747 | default: |
| 5748 | LOG(FATAL) << "Unreachable type " << type; |
| 5749 | UNREACHABLE(); |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5754 | Location loc, |
| 5755 | Register base, |
| 5756 | Register reg_offset, |
| 5757 | Condition cond) { |
| 5758 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5759 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5760 | |
| 5761 | switch (type) { |
| 5762 | case Primitive::kPrimByte: |
| 5763 | case Primitive::kPrimBoolean: |
| 5764 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5765 | break; |
| 5766 | case Primitive::kPrimShort: |
| 5767 | case Primitive::kPrimChar: |
| 5768 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5769 | break; |
| 5770 | case Primitive::kPrimNot: |
| 5771 | case Primitive::kPrimInt: |
| 5772 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5773 | break; |
| 5774 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5775 | case Primitive::kPrimLong: |
| 5776 | case Primitive::kPrimFloat: |
| 5777 | case Primitive::kPrimDouble: |
| 5778 | default: |
| 5779 | LOG(FATAL) << "Unreachable type " << type; |
| 5780 | UNREACHABLE(); |
| 5781 | } |
| 5782 | } |
| 5783 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5784 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5785 | bool object_array_get_with_read_barrier = |
| 5786 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5787 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5788 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5789 | object_array_get_with_read_barrier ? |
| 5790 | LocationSummary::kCallOnSlowPath : |
| 5791 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5792 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5793 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5794 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5796 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5797 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5798 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5799 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5800 | // The output overlaps in the case of an object array get with |
| 5801 | // read barriers enabled: we do not want the move to overwrite the |
| 5802 | // array's location, as we need it to emit the read barrier. |
| 5803 | locations->SetOut( |
| 5804 | Location::RequiresRegister(), |
| 5805 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5806 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5807 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5808 | // We need a temporary register for the read barrier marking slow |
| 5809 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
| 5810 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 5811 | !Runtime::Current()->UseJitCompilation() && |
| 5812 | instruction->GetIndex()->IsConstant()) { |
| 5813 | // Array loads with constant index are treated as field loads. |
| 5814 | // If link-time thunks for the Baker read barrier are enabled, for AOT |
| 5815 | // constant index loads we need a temporary only if the offset is too big. |
| 5816 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 5817 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| 5818 | offset += index << Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 5819 | if (offset >= kReferenceLoadMinFarOffset) { |
| 5820 | locations->AddTemp(Location::RequiresRegister()); |
| 5821 | } |
| 5822 | // And we always need the reserved entrypoint register. |
| 5823 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5824 | } else if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 5825 | !Runtime::Current()->UseJitCompilation() && |
| 5826 | !instruction->GetIndex()->IsConstant()) { |
| 5827 | // We need a non-scratch temporary for the array data pointer. |
| 5828 | locations->AddTemp(Location::RequiresRegister()); |
| 5829 | // And we always need the reserved entrypoint register. |
| 5830 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 5831 | } else { |
| 5832 | locations->AddTemp(Location::RequiresRegister()); |
| 5833 | } |
| 5834 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5835 | // Also need a temporary for String compression feature. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5836 | locations->AddTemp(Location::RequiresRegister()); |
| 5837 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5841 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5842 | Location obj_loc = locations->InAt(0); |
| 5843 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5844 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5845 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5846 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5847 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5848 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5849 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5850 | HInstruction* array_instr = instruction->GetArray(); |
| 5851 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5852 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5853 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5854 | case Primitive::kPrimBoolean: |
| 5855 | case Primitive::kPrimByte: |
| 5856 | case Primitive::kPrimShort: |
| 5857 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5858 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5859 | Register length; |
| 5860 | if (maybe_compressed_char_at) { |
| 5861 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5862 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5863 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5864 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5865 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5866 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5867 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5868 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5869 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5870 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5871 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5872 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5873 | "Expecting 0=compressed, 1=uncompressed"); |
| 5874 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5875 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5876 | out_loc.AsRegister<Register>(), |
| 5877 | obj, |
| 5878 | data_offset + const_index); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5879 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5880 | __ Bind(&uncompressed_load); |
| 5881 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5882 | out_loc.AsRegister<Register>(), |
| 5883 | obj, |
| 5884 | data_offset + (const_index << 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5885 | if (done.IsLinked()) { |
| 5886 | __ Bind(&done); |
| 5887 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5888 | } else { |
| 5889 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5890 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5891 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5892 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5893 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5894 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5895 | Register temp = IP; |
| 5896 | |
| 5897 | if (has_intermediate_address) { |
| 5898 | // We do not need to compute the intermediate address from the array: the |
| 5899 | // input instruction has done it already. See the comment in |
| 5900 | // `TryExtractArrayAccessAddress()`. |
| 5901 | if (kIsDebugBuild) { |
| 5902 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5903 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5904 | } |
| 5905 | temp = obj; |
| 5906 | } else { |
| 5907 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5908 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5909 | if (maybe_compressed_char_at) { |
| 5910 | Label uncompressed_load, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5911 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5912 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5913 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5914 | "Expecting 0=compressed, 1=uncompressed"); |
| 5915 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5916 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5917 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5918 | __ b(final_label); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5919 | __ Bind(&uncompressed_load); |
| 5920 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5921 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5922 | if (done.IsLinked()) { |
| 5923 | __ Bind(&done); |
| 5924 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5925 | } else { |
| 5926 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5927 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5928 | } |
| 5929 | break; |
| 5930 | } |
| 5931 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5932 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5933 | // The read barrier instrumentation of object ArrayGet |
| 5934 | // instructions does not support the HIntermediateAddress |
| 5935 | // instruction. |
| 5936 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5937 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5938 | static_assert( |
| 5939 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5940 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5941 | // /* HeapReference<Object> */ out = |
| 5942 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5943 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5944 | Location temp = locations->GetTemp(0); |
| 5945 | // Note that a potential implicit null check is handled in this |
| 5946 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5947 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 5948 | if (index.IsConstant()) { |
| 5949 | // Array load with a constant index can be treated as a field load. |
| 5950 | data_offset += helpers::Int32ConstantFrom(index) << Primitive::ComponentSizeShift(type); |
| 5951 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 5952 | out_loc, |
| 5953 | obj, |
| 5954 | data_offset, |
| 5955 | locations->GetTemp(0), |
| 5956 | /* needs_null_check */ false); |
| 5957 | } else { |
| 5958 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5959 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ false); |
| 5960 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5961 | } else { |
| 5962 | Register out = out_loc.AsRegister<Register>(); |
| 5963 | if (index.IsConstant()) { |
| 5964 | size_t offset = |
| 5965 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5966 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5968 | // If read barriers are enabled, emit read barriers other than |
| 5969 | // Baker's using a slow path (and also unpoison the loaded |
| 5970 | // reference, if heap poisoning is enabled). |
| 5971 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5972 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5973 | Register temp = IP; |
| 5974 | |
| 5975 | if (has_intermediate_address) { |
| 5976 | // We do not need to compute the intermediate address from the array: the |
| 5977 | // input instruction has done it already. See the comment in |
| 5978 | // `TryExtractArrayAccessAddress()`. |
| 5979 | if (kIsDebugBuild) { |
| 5980 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5981 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5982 | } |
| 5983 | temp = obj; |
| 5984 | } else { |
| 5985 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5986 | } |
| 5987 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5988 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5989 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5990 | // If read barriers are enabled, emit read barriers other than |
| 5991 | // Baker's using a slow path (and also unpoison the loaded |
| 5992 | // reference, if heap poisoning is enabled). |
| 5993 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5994 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5995 | } |
| 5996 | } |
| 5997 | break; |
| 5998 | } |
| 5999 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6000 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6001 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6002 | size_t offset = |
| 6003 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6004 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6005 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6006 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6007 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6008 | } |
| 6009 | break; |
| 6010 | } |
| 6011 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6012 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6013 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6014 | if (index.IsConstant()) { |
| 6015 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6016 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6017 | } else { |
| 6018 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6019 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6020 | } |
| 6021 | break; |
| 6022 | } |
| 6023 | |
| 6024 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6025 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6026 | if (index.IsConstant()) { |
| 6027 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6028 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6029 | } else { |
| 6030 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6031 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6032 | } |
| 6033 | break; |
| 6034 | } |
| 6035 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6036 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6037 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6038 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6039 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6040 | |
| 6041 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6042 | // Potential implicit null checks, in the case of reference |
| 6043 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6044 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6045 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6046 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6050 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6051 | |
| 6052 | bool needs_write_barrier = |
| 6053 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6054 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6055 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6056 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6057 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 6058 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6059 | LocationSummary::kCallOnSlowPath : |
| 6060 | LocationSummary::kNoCall); |
| 6061 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6062 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6063 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 6064 | if (Primitive::IsFloatingPointType(value_type)) { |
| 6065 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6066 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6067 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6068 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6069 | if (needs_write_barrier) { |
| 6070 | // Temporary registers for the write barrier. |
| 6071 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 6072 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6073 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 6077 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6078 | Location array_loc = locations->InAt(0); |
| 6079 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6080 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6081 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6082 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6083 | bool needs_write_barrier = |
| 6084 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6085 | uint32_t data_offset = |
| 6086 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 6087 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6088 | HInstruction* array_instr = instruction->GetArray(); |
| 6089 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6090 | |
| 6091 | switch (value_type) { |
| 6092 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6093 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6094 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6095 | case Primitive::kPrimChar: |
| 6096 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6097 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6098 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 6099 | uint32_t full_offset = |
| 6100 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 6101 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 6102 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6103 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6104 | Register temp = IP; |
| 6105 | |
| 6106 | if (has_intermediate_address) { |
| 6107 | // We do not need to compute the intermediate address from the array: the |
| 6108 | // input instruction has done it already. See the comment in |
| 6109 | // `TryExtractArrayAccessAddress()`. |
| 6110 | if (kIsDebugBuild) { |
| 6111 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 6112 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 6113 | } |
| 6114 | temp = array; |
| 6115 | } else { |
| 6116 | __ add(temp, array, ShifterOperand(data_offset)); |
| 6117 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6118 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6119 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6120 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6121 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6122 | } |
| 6123 | break; |
| 6124 | } |
| 6125 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6126 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6127 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6128 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6129 | // See the comment in instruction_simplifier_shared.cc. |
| 6130 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6131 | |
| 6132 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 6133 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6134 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6135 | size_t offset = |
| 6136 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6137 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6138 | } else { |
| 6139 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6140 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6141 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6142 | value_loc, |
| 6143 | IP, |
| 6144 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6145 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 6146 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6147 | DCHECK(!needs_write_barrier); |
| 6148 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6149 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6150 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6151 | |
| 6152 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6153 | Location temp1_loc = locations->GetTemp(0); |
| 6154 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6155 | Location temp2_loc = locations->GetTemp(1); |
| 6156 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6157 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6158 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6159 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6160 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6161 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6162 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6163 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6164 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6165 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6166 | codegen_->AddSlowPath(slow_path); |
| 6167 | if (instruction->GetValueCanBeNull()) { |
| 6168 | Label non_zero; |
| 6169 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6170 | if (index.IsConstant()) { |
| 6171 | size_t offset = |
| 6172 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6173 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6174 | } else { |
| 6175 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6176 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6177 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6178 | value_loc, |
| 6179 | IP, |
| 6180 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6181 | } |
| 6182 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6183 | __ b(final_label); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6184 | __ Bind(&non_zero); |
| 6185 | } |
| 6186 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6187 | // Note that when read barriers are enabled, the type checks |
| 6188 | // are performed without read barriers. This is fine, even in |
| 6189 | // the case where a class object is in the from-space after |
| 6190 | // the flip, as a comparison involving such a type would not |
| 6191 | // produce a false positive; it may of course produce a false |
| 6192 | // negative, in which case we would take the ArraySet slow |
| 6193 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6194 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6195 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6196 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6197 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6198 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6199 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6200 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6201 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6202 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6203 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6204 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6205 | // nor `temp2`, as we are comparing two poisoned references. |
| 6206 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6207 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6208 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6209 | Label do_put; |
| 6210 | __ b(&do_put, EQ); |
| 6211 | // If heap poisoning is enabled, the `temp1` reference has |
| 6212 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6213 | __ MaybeUnpoisonHeapReference(temp1); |
| 6214 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6215 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6216 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6217 | // If heap poisoning is enabled, no need to unpoison |
| 6218 | // `temp1`, as we are comparing against null below. |
| 6219 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6220 | __ Bind(&do_put); |
| 6221 | } else { |
| 6222 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6223 | } |
| 6224 | } |
| 6225 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6226 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6227 | if (kPoisonHeapReferences) { |
| 6228 | // Note that in the case where `value` is a null reference, |
| 6229 | // we do not enter this block, as a null reference does not |
| 6230 | // need poisoning. |
| 6231 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6232 | __ Mov(temp1, value); |
| 6233 | __ PoisonHeapReference(temp1); |
| 6234 | source = temp1; |
| 6235 | } |
| 6236 | |
| 6237 | if (index.IsConstant()) { |
| 6238 | size_t offset = |
| 6239 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6240 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6241 | } else { |
| 6242 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6243 | |
| 6244 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6245 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6246 | Location::RegisterLocation(source), |
| 6247 | IP, |
| 6248 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6249 | } |
| 6250 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6251 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6252 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6253 | } |
| 6254 | |
| 6255 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6256 | |
| 6257 | if (done.IsLinked()) { |
| 6258 | __ Bind(&done); |
| 6259 | } |
| 6260 | |
| 6261 | if (slow_path != nullptr) { |
| 6262 | __ Bind(slow_path->GetExitLabel()); |
| 6263 | } |
| 6264 | |
| 6265 | break; |
| 6266 | } |
| 6267 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6268 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6269 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6270 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6271 | size_t offset = |
| 6272 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6273 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6274 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6275 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6276 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6277 | } |
| 6278 | break; |
| 6279 | } |
| 6280 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6281 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6282 | Location value = locations->InAt(2); |
| 6283 | DCHECK(value.IsFpuRegister()); |
| 6284 | if (index.IsConstant()) { |
| 6285 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6286 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6287 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6288 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6289 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6290 | } |
| 6291 | break; |
| 6292 | } |
| 6293 | |
| 6294 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6295 | Location value = locations->InAt(2); |
| 6296 | DCHECK(value.IsFpuRegisterPair()); |
| 6297 | if (index.IsConstant()) { |
| 6298 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6299 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6300 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6301 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6302 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6303 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6304 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6305 | break; |
| 6306 | } |
| 6307 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6308 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6309 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6310 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6311 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6312 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6313 | // Objects are handled in the switch. |
| 6314 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6315 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6316 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6317 | } |
| 6318 | |
| 6319 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6320 | LocationSummary* locations = |
| 6321 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6322 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6327 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6328 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6329 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6330 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6331 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6332 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6333 | // Mask out compression flag from String's array length. |
| 6334 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6335 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6336 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6337 | } |
| 6338 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6339 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6340 | LocationSummary* locations = |
| 6341 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6342 | |
| 6343 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6344 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6345 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6346 | } |
| 6347 | |
| 6348 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6349 | LocationSummary* locations = instruction->GetLocations(); |
| 6350 | Location out = locations->Out(); |
| 6351 | Location first = locations->InAt(0); |
| 6352 | Location second = locations->InAt(1); |
| 6353 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6354 | if (second.IsRegister()) { |
| 6355 | __ add(out.AsRegister<Register>(), |
| 6356 | first.AsRegister<Register>(), |
| 6357 | ShifterOperand(second.AsRegister<Register>())); |
| 6358 | } else { |
| 6359 | __ AddConstant(out.AsRegister<Register>(), |
| 6360 | first.AsRegister<Register>(), |
| 6361 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6362 | } |
| 6363 | } |
| 6364 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6365 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6366 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6367 | InvokeRuntimeCallingConvention calling_convention; |
| 6368 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6369 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6370 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6371 | |
| 6372 | HInstruction* index = instruction->InputAt(0); |
| 6373 | HInstruction* length = instruction->InputAt(1); |
| 6374 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6375 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6376 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6377 | // locations. |
| 6378 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6379 | locations->SetInAt(0, both_const |
| 6380 | ? Location::ConstantLocation(index->AsConstant()) |
| 6381 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6382 | locations->SetInAt(1, both_const |
| 6383 | ? Location::ConstantLocation(length->AsConstant()) |
| 6384 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6388 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6389 | Location index_loc = locations->InAt(0); |
| 6390 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6391 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6392 | if (length_loc.IsConstant()) { |
| 6393 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6394 | if (index_loc.IsConstant()) { |
| 6395 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6396 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6397 | if (index < 0 || index >= length) { |
| 6398 | SlowPathCodeARM* slow_path = |
| 6399 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6400 | codegen_->AddSlowPath(slow_path); |
| 6401 | __ b(slow_path->GetEntryLabel()); |
| 6402 | } else { |
| 6403 | // Some optimization after BCE may have generated this, and we should not |
| 6404 | // generate a bounds check if it is a valid range. |
| 6405 | } |
| 6406 | return; |
| 6407 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6408 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6409 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6410 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6411 | codegen_->AddSlowPath(slow_path); |
| 6412 | __ b(slow_path->GetEntryLabel(), HS); |
| 6413 | } else { |
| 6414 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6415 | if (index_loc.IsConstant()) { |
| 6416 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6417 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6418 | } else { |
| 6419 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6420 | } |
| 6421 | codegen_->AddSlowPath(slow_path); |
| 6422 | __ b(slow_path->GetEntryLabel(), LS); |
| 6423 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6424 | } |
| 6425 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6426 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6427 | Register card, |
| 6428 | Register object, |
| 6429 | Register value, |
| 6430 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6431 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6432 | if (can_be_null) { |
| 6433 | __ CompareAndBranchIfZero(value, &is_null); |
| 6434 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6435 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6436 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6437 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6438 | if (can_be_null) { |
| 6439 | __ Bind(&is_null); |
| 6440 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6441 | } |
| 6442 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6443 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6444 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6448 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6449 | } |
| 6450 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6451 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6452 | LocationSummary* locations = |
| 6453 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6454 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6455 | } |
| 6456 | |
| 6457 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6458 | HBasicBlock* block = instruction->GetBlock(); |
| 6459 | if (block->GetLoopInformation() != nullptr) { |
| 6460 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6461 | // The back edge will generate the suspend check. |
| 6462 | return; |
| 6463 | } |
| 6464 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6465 | // The goto will generate the suspend check. |
| 6466 | return; |
| 6467 | } |
| 6468 | GenerateSuspendCheck(instruction, nullptr); |
| 6469 | } |
| 6470 | |
| 6471 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6472 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6473 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6474 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6475 | if (slow_path == nullptr) { |
| 6476 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6477 | instruction->SetSlowPath(slow_path); |
| 6478 | codegen_->AddSlowPath(slow_path); |
| 6479 | if (successor != nullptr) { |
| 6480 | DCHECK(successor->IsLoopHeader()); |
| 6481 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6482 | } |
| 6483 | } else { |
| 6484 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6485 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6486 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6487 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6488 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6489 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6490 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6491 | __ Bind(slow_path->GetReturnLabel()); |
| 6492 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6493 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6494 | __ b(slow_path->GetEntryLabel()); |
| 6495 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6496 | } |
| 6497 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6498 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6499 | return codegen_->GetAssembler(); |
| 6500 | } |
| 6501 | |
| 6502 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6503 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6504 | Location source = move->GetSource(); |
| 6505 | Location destination = move->GetDestination(); |
| 6506 | |
| 6507 | if (source.IsRegister()) { |
| 6508 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6509 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6510 | } else if (destination.IsFpuRegister()) { |
| 6511 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6512 | } else { |
| 6513 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6514 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6515 | SP, destination.GetStackIndex()); |
| 6516 | } |
| 6517 | } else if (source.IsStackSlot()) { |
| 6518 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6519 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6520 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6521 | } else if (destination.IsFpuRegister()) { |
| 6522 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6523 | } else { |
| 6524 | DCHECK(destination.IsStackSlot()); |
| 6525 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6526 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6527 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6528 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6529 | if (destination.IsRegister()) { |
| 6530 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6531 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6532 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6533 | } else { |
| 6534 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6535 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6536 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6537 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6538 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6539 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6540 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6541 | } else if (destination.IsRegisterPair()) { |
| 6542 | DCHECK(ExpectedPairLayout(destination)); |
| 6543 | __ LoadFromOffset( |
| 6544 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6545 | } else { |
| 6546 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6547 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6548 | SP, |
| 6549 | source.GetStackIndex()); |
| 6550 | } |
| 6551 | } else if (source.IsRegisterPair()) { |
| 6552 | if (destination.IsRegisterPair()) { |
| 6553 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6554 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6555 | } else if (destination.IsFpuRegisterPair()) { |
| 6556 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6557 | source.AsRegisterPairLow<Register>(), |
| 6558 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6559 | } else { |
| 6560 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6561 | DCHECK(ExpectedPairLayout(source)); |
| 6562 | __ StoreToOffset( |
| 6563 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6564 | } |
| 6565 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6566 | if (destination.IsRegisterPair()) { |
| 6567 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6568 | destination.AsRegisterPairHigh<Register>(), |
| 6569 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6570 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6571 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6572 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6573 | } else { |
| 6574 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6575 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6576 | SP, |
| 6577 | destination.GetStackIndex()); |
| 6578 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6579 | } else { |
| 6580 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6581 | HConstant* constant = source.GetConstant(); |
| 6582 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6583 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6584 | if (destination.IsRegister()) { |
| 6585 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6586 | } else { |
| 6587 | DCHECK(destination.IsStackSlot()); |
| 6588 | __ LoadImmediate(IP, value); |
| 6589 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6590 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6591 | } else if (constant->IsLongConstant()) { |
| 6592 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6593 | if (destination.IsRegisterPair()) { |
| 6594 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6595 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6596 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6597 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6598 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6599 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6600 | __ LoadImmediate(IP, High32Bits(value)); |
| 6601 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6602 | } |
| 6603 | } else if (constant->IsDoubleConstant()) { |
| 6604 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6605 | if (destination.IsFpuRegisterPair()) { |
| 6606 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6607 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6608 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6609 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6610 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6611 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6612 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6613 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6614 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6615 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6616 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6617 | float value = constant->AsFloatConstant()->GetValue(); |
| 6618 | if (destination.IsFpuRegister()) { |
| 6619 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6620 | } else { |
| 6621 | DCHECK(destination.IsStackSlot()); |
| 6622 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6623 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6624 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6625 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6630 | __ Mov(IP, reg); |
| 6631 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6632 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6633 | } |
| 6634 | |
| 6635 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6636 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6637 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6638 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6639 | SP, mem1 + stack_offset); |
| 6640 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6641 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6642 | SP, mem2 + stack_offset); |
| 6643 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6644 | } |
| 6645 | |
| 6646 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6647 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6648 | Location source = move->GetSource(); |
| 6649 | Location destination = move->GetDestination(); |
| 6650 | |
| 6651 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6652 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6653 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6654 | __ Mov(IP, source.AsRegister<Register>()); |
| 6655 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6656 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6657 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6658 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6659 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6660 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6661 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6662 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6663 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6664 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6665 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6666 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6667 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6668 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6669 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6670 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6671 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6672 | destination.AsRegisterPairHigh<Register>(), |
| 6673 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6674 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6675 | Register low_reg = source.IsRegisterPair() |
| 6676 | ? source.AsRegisterPairLow<Register>() |
| 6677 | : destination.AsRegisterPairLow<Register>(); |
| 6678 | int mem = source.IsRegisterPair() |
| 6679 | ? destination.GetStackIndex() |
| 6680 | : source.GetStackIndex(); |
| 6681 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6682 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6683 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6684 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6685 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6686 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6687 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6688 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6689 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6690 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6691 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6692 | DRegister reg = source.IsFpuRegisterPair() |
| 6693 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6694 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6695 | int mem = source.IsFpuRegisterPair() |
| 6696 | ? destination.GetStackIndex() |
| 6697 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6698 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6699 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6700 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6701 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6702 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6703 | : destination.AsFpuRegister<SRegister>(); |
| 6704 | int mem = source.IsFpuRegister() |
| 6705 | ? destination.GetStackIndex() |
| 6706 | : source.GetStackIndex(); |
| 6707 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6708 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6709 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6710 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6711 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6712 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6713 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6714 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6715 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6720 | __ Push(static_cast<Register>(reg)); |
| 6721 | } |
| 6722 | |
| 6723 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6724 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6725 | } |
| 6726 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6727 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6728 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6729 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6730 | case HLoadClass::LoadKind::kInvalid: |
| 6731 | LOG(FATAL) << "UNREACHABLE"; |
| 6732 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6733 | case HLoadClass::LoadKind::kReferrersClass: |
| 6734 | break; |
| 6735 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6736 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6737 | break; |
| 6738 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6739 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6740 | break; |
| 6741 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6742 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6743 | case HLoadClass::LoadKind::kBssEntry: |
| 6744 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6745 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6746 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6747 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6748 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6749 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6750 | break; |
| 6751 | } |
| 6752 | return desired_class_load_kind; |
| 6753 | } |
| 6754 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6755 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6756 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6757 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6758 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6759 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6760 | cls, |
| 6761 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6762 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6763 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6764 | return; |
| 6765 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6766 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6767 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6768 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6769 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6770 | ? LocationSummary::kCallOnSlowPath |
| 6771 | : LocationSummary::kNoCall; |
| 6772 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6773 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6774 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6775 | } |
| 6776 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6777 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6778 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6779 | } |
| 6780 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6781 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6782 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6783 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6784 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6785 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6786 | locations->AddTemp(Location::RequiresRegister()); |
| 6787 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6788 | InvokeRuntimeCallingConvention calling_convention; |
| 6789 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6790 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6791 | // that the the kPrimNot result register is the same as the first argument register. |
| 6792 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6793 | } else { |
| 6794 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6795 | } |
| 6796 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6797 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6798 | if (load_kind == HLoadClass::LoadKind::kBssEntry || |
| 6799 | (load_kind == HLoadClass::LoadKind::kReferrersClass && |
| 6800 | !Runtime::Current()->UseJitCompilation())) { |
| 6801 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6802 | } |
| 6803 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6804 | } |
| 6805 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6806 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6807 | // move. |
| 6808 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6809 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6810 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6811 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6812 | return; |
| 6813 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6814 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6815 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6816 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6817 | Location out_loc = locations->Out(); |
| 6818 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6819 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6820 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6821 | ? kWithoutReadBarrier |
| 6822 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6823 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6824 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6825 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6826 | DCHECK(!cls->CanCallRuntime()); |
| 6827 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6828 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6829 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6830 | GenerateGcRootFieldLoad(cls, |
| 6831 | out_loc, |
| 6832 | current_method, |
| 6833 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6834 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6835 | break; |
| 6836 | } |
| 6837 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6838 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6839 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6840 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6841 | cls->GetTypeIndex())); |
| 6842 | break; |
| 6843 | } |
| 6844 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6845 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6846 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6847 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6848 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6849 | __ BindTrackedLabel(&labels->movw_label); |
| 6850 | __ movw(out, /* placeholder */ 0u); |
| 6851 | __ BindTrackedLabel(&labels->movt_label); |
| 6852 | __ movt(out, /* placeholder */ 0u); |
| 6853 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6854 | __ add(out, out, ShifterOperand(PC)); |
| 6855 | break; |
| 6856 | } |
| 6857 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6858 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6859 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6860 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6861 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6862 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6863 | break; |
| 6864 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6865 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6866 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6867 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6868 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6869 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6870 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6871 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6872 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6873 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6874 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6875 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6876 | __ add(temp, temp, ShifterOperand(PC)); |
| 6877 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6878 | generate_null_check = true; |
| 6879 | break; |
| 6880 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6881 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6882 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6883 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6884 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6885 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6886 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6887 | break; |
| 6888 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6889 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6890 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6891 | LOG(FATAL) << "UNREACHABLE"; |
| 6892 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6893 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6894 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6895 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6896 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6897 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6898 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6899 | codegen_->AddSlowPath(slow_path); |
| 6900 | if (generate_null_check) { |
| 6901 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6902 | } |
| 6903 | if (cls->MustGenerateClinitCheck()) { |
| 6904 | GenerateClassInitializationCheck(slow_path, out); |
| 6905 | } else { |
| 6906 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6907 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6912 | LocationSummary* locations = |
| 6913 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6914 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6915 | if (check->HasUses()) { |
| 6916 | locations->SetOut(Location::SameAsFirstInput()); |
| 6917 | } |
| 6918 | } |
| 6919 | |
| 6920 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6921 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6922 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6923 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6924 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6925 | GenerateClassInitializationCheck(slow_path, |
| 6926 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6927 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6928 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6929 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6930 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6931 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6932 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6933 | __ b(slow_path->GetEntryLabel(), LT); |
| 6934 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6935 | // properly. Therefore, we do a memory fence. |
| 6936 | __ dmb(ISH); |
| 6937 | __ Bind(slow_path->GetExitLabel()); |
| 6938 | } |
| 6939 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6940 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6941 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6942 | switch (desired_string_load_kind) { |
| 6943 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6944 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6945 | break; |
| 6946 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6947 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6948 | break; |
| 6949 | case HLoadString::LoadKind::kBootImageAddress: |
| 6950 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6951 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6952 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6953 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6954 | case HLoadString::LoadKind::kJitTableAddress: |
| 6955 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6956 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6957 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6958 | break; |
| 6959 | } |
| 6960 | return desired_string_load_kind; |
| 6961 | } |
| 6962 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6963 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6964 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6965 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6966 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6967 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6968 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6969 | } else { |
| 6970 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6971 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6972 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6973 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6974 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6975 | // 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] | 6976 | locations->AddTemp(Location::RequiresRegister()); |
| 6977 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6978 | InvokeRuntimeCallingConvention calling_convention; |
| 6979 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6980 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6981 | // that the the kPrimNot result register is the same as the first argument register. |
| 6982 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6983 | if (kUseBakerReadBarrier && kBakerReadBarrierLinkTimeThunksEnableForGcRoots) { |
| 6984 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 6985 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6986 | } else { |
| 6987 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6988 | } |
| 6989 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6990 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6993 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6994 | // move. |
| 6995 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6996 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6997 | Location out_loc = locations->Out(); |
| 6998 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6999 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7000 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7001 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7002 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7003 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7004 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 7005 | load->GetStringIndex())); |
| 7006 | return; // No dex cache slow path. |
| 7007 | } |
| 7008 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7009 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7010 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7011 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7012 | __ BindTrackedLabel(&labels->movw_label); |
| 7013 | __ movw(out, /* placeholder */ 0u); |
| 7014 | __ BindTrackedLabel(&labels->movt_label); |
| 7015 | __ movt(out, /* placeholder */ 0u); |
| 7016 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7017 | __ add(out, out, ShifterOperand(PC)); |
| 7018 | return; // No dex cache slow path. |
| 7019 | } |
| 7020 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7021 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 7022 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 7023 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7024 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7025 | return; // No dex cache slow path. |
| 7026 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7027 | case HLoadString::LoadKind::kBssEntry: { |
| 7028 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7029 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 7030 | ? locations->GetTemp(0).AsRegister<Register>() |
| 7031 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7032 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7033 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7034 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7035 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7036 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7037 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7038 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7039 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7040 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7041 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 7042 | codegen_->AddSlowPath(slow_path); |
| 7043 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7044 | __ Bind(slow_path->GetExitLabel()); |
| 7045 | return; |
| 7046 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7047 | case HLoadString::LoadKind::kJitTableAddress: { |
| 7048 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7049 | load->GetStringIndex(), |
| 7050 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7051 | // /* GcRoot<mirror::String> */ out = *out |
| 7052 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 7053 | return; |
| 7054 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7055 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 7056 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7057 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7058 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7059 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 7060 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 7061 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 7062 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7063 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 7064 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7065 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7068 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7069 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7070 | } |
| 7071 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7072 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 7073 | LocationSummary* locations = |
| 7074 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 7075 | locations->SetOut(Location::RequiresRegister()); |
| 7076 | } |
| 7077 | |
| 7078 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7079 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7080 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 7081 | } |
| 7082 | |
| 7083 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 7084 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 7085 | } |
| 7086 | |
| 7087 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7088 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 7089 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 7093 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7094 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7095 | InvokeRuntimeCallingConvention calling_convention; |
| 7096 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7097 | } |
| 7098 | |
| 7099 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7100 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7101 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7104 | // Temp is used for read barrier. |
| 7105 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7106 | if (kEmitCompilerReadBarrier && |
| 7107 | (kUseBakerReadBarrier || |
| 7108 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7109 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7110 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7111 | return 1; |
| 7112 | } |
| 7113 | return 0; |
| 7114 | } |
| 7115 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7116 | // 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] | 7117 | // interface pointer, one for loading the current interface. |
| 7118 | // The other checks have one temp for loading the object's class. |
| 7119 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7120 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7121 | return 3; |
| 7122 | } |
| 7123 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7124 | } |
| 7125 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7126 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7127 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7128 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7129 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7130 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7131 | case TypeCheckKind::kExactCheck: |
| 7132 | case TypeCheckKind::kAbstractClassCheck: |
| 7133 | case TypeCheckKind::kClassHierarchyCheck: |
| 7134 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7135 | call_kind = |
| 7136 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7137 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7138 | break; |
| 7139 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7140 | case TypeCheckKind::kUnresolvedCheck: |
| 7141 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7142 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7143 | break; |
| 7144 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7145 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7146 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7147 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 7148 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 7149 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7150 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7151 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7152 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7153 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7154 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7155 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 7156 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 7157 | codegen_->MaybeAddBakerCcEntrypointTempForFields(locations); |
| 7158 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7159 | } |
| 7160 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7161 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7162 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7163 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7164 | Location obj_loc = locations->InAt(0); |
| 7165 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7166 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7167 | Location out_loc = locations->Out(); |
| 7168 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7169 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7170 | DCHECK_LE(num_temps, 1u); |
| 7171 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7172 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7173 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7174 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7175 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7176 | Label done; |
| 7177 | Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7178 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7179 | |
| 7180 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7181 | // avoid null check if we know obj is not null. |
| 7182 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7183 | DCHECK_NE(out, obj); |
| 7184 | __ LoadImmediate(out, 0); |
| 7185 | __ CompareAndBranchIfZero(obj, final_label); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7186 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7187 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7188 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7189 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7190 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7191 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7192 | out_loc, |
| 7193 | obj_loc, |
| 7194 | class_offset, |
| 7195 | maybe_temp_loc, |
| 7196 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7197 | // Classes must be equal for the instanceof to succeed. |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7198 | __ cmp(out, ShifterOperand(cls)); |
| 7199 | // We speculatively set the result to false without changing the condition |
| 7200 | // flags, which allows us to avoid some branching later. |
| 7201 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7202 | |
| 7203 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7204 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7205 | // encoding can be used. |
| 7206 | if (ArmAssembler::IsLowRegister(out)) { |
| 7207 | __ it(EQ); |
| 7208 | __ mov(out, ShifterOperand(1), EQ); |
| 7209 | } else { |
| 7210 | __ b(final_label, NE); |
| 7211 | __ LoadImmediate(out, 1); |
| 7212 | } |
| 7213 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7214 | break; |
| 7215 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7216 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7217 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7218 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7219 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7220 | out_loc, |
| 7221 | obj_loc, |
| 7222 | class_offset, |
| 7223 | maybe_temp_loc, |
| 7224 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7225 | // If the class is abstract, we eagerly fetch the super class of the |
| 7226 | // object to avoid doing a comparison we know will fail. |
| 7227 | Label loop; |
| 7228 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7229 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7230 | GenerateReferenceLoadOneRegister(instruction, |
| 7231 | out_loc, |
| 7232 | super_offset, |
| 7233 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7234 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7235 | // 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] | 7236 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7237 | __ cmp(out, ShifterOperand(cls)); |
| 7238 | __ b(&loop, NE); |
| 7239 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7240 | break; |
| 7241 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7242 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7243 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7244 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7245 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7246 | out_loc, |
| 7247 | obj_loc, |
| 7248 | class_offset, |
| 7249 | maybe_temp_loc, |
| 7250 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7251 | // Walk over the class hierarchy to find a match. |
| 7252 | Label loop, success; |
| 7253 | __ Bind(&loop); |
| 7254 | __ cmp(out, ShifterOperand(cls)); |
| 7255 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7256 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7257 | GenerateReferenceLoadOneRegister(instruction, |
| 7258 | out_loc, |
| 7259 | super_offset, |
| 7260 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7261 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7262 | // This is essentially a null check, but it sets the condition flags to the |
| 7263 | // proper value for the code that follows the loop, i.e. not `EQ`. |
| 7264 | __ cmp(out, ShifterOperand(1)); |
| 7265 | __ b(&loop, HS); |
| 7266 | |
| 7267 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7268 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7269 | // encoding can be used. |
| 7270 | if (ArmAssembler::IsLowRegister(out)) { |
| 7271 | // If `out` is null, we use it for the result, and the condition flags |
| 7272 | // have already been set to `NE`, so the IT block that comes afterwards |
| 7273 | // (and which handles the successful case) turns into a NOP (instead of |
| 7274 | // overwriting `out`). |
| 7275 | __ Bind(&success); |
| 7276 | // There is only one branch to the `success` label (which is bound to this |
| 7277 | // IT block), and it has the same condition, `EQ`, so in that case the MOV |
| 7278 | // is executed. |
| 7279 | __ it(EQ); |
| 7280 | __ mov(out, ShifterOperand(1), EQ); |
| 7281 | } else { |
| 7282 | // 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] | 7283 | __ b(final_label); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7284 | __ Bind(&success); |
| 7285 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7286 | } |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7287 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7288 | break; |
| 7289 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7290 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7291 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7292 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7293 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7294 | out_loc, |
| 7295 | obj_loc, |
| 7296 | class_offset, |
| 7297 | maybe_temp_loc, |
| 7298 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7299 | // Do an exact check. |
| 7300 | Label exact_check; |
| 7301 | __ cmp(out, ShifterOperand(cls)); |
| 7302 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7303 | // 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] | 7304 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7305 | GenerateReferenceLoadOneRegister(instruction, |
| 7306 | out_loc, |
| 7307 | component_offset, |
| 7308 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7309 | kCompilerReadBarrierOption); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7310 | // 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] | 7311 | __ CompareAndBranchIfZero(out, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7312 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7313 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7314 | __ cmp(out, ShifterOperand(0)); |
| 7315 | // We speculatively set the result to false without changing the condition |
| 7316 | // flags, which allows us to avoid some branching later. |
| 7317 | __ mov(out, ShifterOperand(0), AL, kCcKeep); |
| 7318 | |
| 7319 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7320 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7321 | // encoding can be used. |
| 7322 | if (ArmAssembler::IsLowRegister(out)) { |
| 7323 | __ Bind(&exact_check); |
| 7324 | __ it(EQ); |
| 7325 | __ mov(out, ShifterOperand(1), EQ); |
| 7326 | } else { |
| 7327 | __ b(final_label, NE); |
| 7328 | __ Bind(&exact_check); |
| 7329 | __ LoadImmediate(out, 1); |
| 7330 | } |
| 7331 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7332 | break; |
| 7333 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7334 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7335 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7336 | // No read barrier since the slow path will retry upon failure. |
| 7337 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7338 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7339 | out_loc, |
| 7340 | obj_loc, |
| 7341 | class_offset, |
| 7342 | maybe_temp_loc, |
| 7343 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7344 | __ cmp(out, ShifterOperand(cls)); |
| 7345 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7346 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7347 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7348 | codegen_->AddSlowPath(slow_path); |
| 7349 | __ b(slow_path->GetEntryLabel(), NE); |
| 7350 | __ LoadImmediate(out, 1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7351 | break; |
| 7352 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7353 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7354 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7355 | case TypeCheckKind::kInterfaceCheck: { |
| 7356 | // 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] | 7357 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7358 | // cases. |
| 7359 | // |
| 7360 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7361 | // entry point without resorting to a type checking slow path |
| 7362 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7363 | // require to assign fixed registers for the inputs of this |
| 7364 | // HInstanceOf instruction (following the runtime calling |
| 7365 | // convention), which might be cluttered by the potential first |
| 7366 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7367 | // |
| 7368 | // TODO: Introduce a new runtime entry point taking the object |
| 7369 | // to test (instead of its class) as argument, and let it deal |
| 7370 | // with the read barrier issues. This will let us refactor this |
| 7371 | // case of the `switch` code as it was previously (with a direct |
| 7372 | // call to the runtime not using a type checking slow path). |
| 7373 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7374 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7375 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7376 | /* is_fatal */ false); |
| 7377 | codegen_->AddSlowPath(slow_path); |
| 7378 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7379 | break; |
| 7380 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7381 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7382 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7383 | if (done.IsLinked()) { |
| 7384 | __ Bind(&done); |
| 7385 | } |
| 7386 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7387 | if (slow_path != nullptr) { |
| 7388 | __ Bind(slow_path->GetExitLabel()); |
| 7389 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7390 | } |
| 7391 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7392 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7393 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7394 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7395 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7396 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7397 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7398 | case TypeCheckKind::kExactCheck: |
| 7399 | case TypeCheckKind::kAbstractClassCheck: |
| 7400 | case TypeCheckKind::kClassHierarchyCheck: |
| 7401 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7402 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7403 | LocationSummary::kCallOnSlowPath : |
| 7404 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7405 | break; |
| 7406 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7407 | case TypeCheckKind::kUnresolvedCheck: |
| 7408 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7409 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7410 | break; |
| 7411 | } |
| 7412 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7413 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7415 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7416 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7420 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7421 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7422 | Location obj_loc = locations->InAt(0); |
| 7423 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7424 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7425 | Location temp_loc = locations->GetTemp(0); |
| 7426 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7427 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7428 | DCHECK_LE(num_temps, 3u); |
| 7429 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7430 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7431 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7432 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7433 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7434 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7435 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7436 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7437 | const uint32_t object_array_data_offset = |
| 7438 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7439 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7440 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7441 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7442 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7443 | bool is_type_check_slow_path_fatal = false; |
| 7444 | if (!kEmitCompilerReadBarrier) { |
| 7445 | is_type_check_slow_path_fatal = |
| 7446 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7447 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7448 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7449 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7450 | !instruction->CanThrowIntoCatchBlock(); |
| 7451 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7452 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7453 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7454 | is_type_check_slow_path_fatal); |
| 7455 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7456 | |
| 7457 | Label done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7458 | Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7459 | // Avoid null check if we know obj is not null. |
| 7460 | if (instruction->MustDoNullCheck()) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7461 | __ CompareAndBranchIfZero(obj, final_label); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7462 | } |
| 7463 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7464 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7465 | case TypeCheckKind::kExactCheck: |
| 7466 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7467 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7468 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7469 | temp_loc, |
| 7470 | obj_loc, |
| 7471 | class_offset, |
| 7472 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7473 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7474 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7475 | __ cmp(temp, ShifterOperand(cls)); |
| 7476 | // Jump to slow path for throwing the exception or doing a |
| 7477 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7478 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7479 | break; |
| 7480 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7481 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7482 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7483 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7484 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7485 | temp_loc, |
| 7486 | obj_loc, |
| 7487 | class_offset, |
| 7488 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7489 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7490 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7491 | // If the class is abstract, we eagerly fetch the super class of the |
| 7492 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7493 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7494 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7495 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7496 | GenerateReferenceLoadOneRegister(instruction, |
| 7497 | temp_loc, |
| 7498 | super_offset, |
| 7499 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7500 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7501 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7502 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7503 | // exception. |
| 7504 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7505 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7506 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7507 | __ cmp(temp, ShifterOperand(cls)); |
| 7508 | __ b(&loop, NE); |
| 7509 | break; |
| 7510 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7511 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7512 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7513 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7514 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7515 | temp_loc, |
| 7516 | obj_loc, |
| 7517 | class_offset, |
| 7518 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7519 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7520 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7521 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7522 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7523 | __ Bind(&loop); |
| 7524 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7525 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7526 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7527 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7528 | GenerateReferenceLoadOneRegister(instruction, |
| 7529 | temp_loc, |
| 7530 | super_offset, |
| 7531 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7532 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7533 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7534 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7535 | // exception. |
| 7536 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7537 | // Otherwise, jump to the beginning of the loop. |
| 7538 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7539 | break; |
| 7540 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7541 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7542 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7543 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7544 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7545 | temp_loc, |
| 7546 | obj_loc, |
| 7547 | class_offset, |
| 7548 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7549 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7550 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7551 | // Do an exact check. |
| 7552 | __ cmp(temp, ShifterOperand(cls)); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7553 | __ b(final_label, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7554 | |
| 7555 | // 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] | 7556 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7557 | GenerateReferenceLoadOneRegister(instruction, |
| 7558 | temp_loc, |
| 7559 | component_offset, |
| 7560 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7561 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7562 | // If the component type is null, jump to the slow path to throw the exception. |
| 7563 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7564 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7565 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7566 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7567 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7568 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7569 | break; |
| 7570 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7571 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7572 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7573 | // 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] | 7574 | // We cannot directly call the CheckCast runtime entry point |
| 7575 | // without resorting to a type checking slow path here (i.e. by |
| 7576 | // calling InvokeRuntime directly), as it would require to |
| 7577 | // assign fixed registers for the inputs of this HInstanceOf |
| 7578 | // instruction (following the runtime calling convention), which |
| 7579 | // might be cluttered by the potential first read barrier |
| 7580 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7581 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7582 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7583 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7584 | |
| 7585 | case TypeCheckKind::kInterfaceCheck: { |
| 7586 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7587 | // positives by doing this. |
| 7588 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7589 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7590 | temp_loc, |
| 7591 | obj_loc, |
| 7592 | class_offset, |
| 7593 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7594 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7595 | |
| 7596 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7597 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7598 | temp_loc, |
| 7599 | temp_loc, |
| 7600 | iftable_offset, |
| 7601 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7602 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7603 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7604 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7605 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7606 | Label start_loop; |
| 7607 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7608 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7609 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7610 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7611 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7612 | // Go to next interface. |
| 7613 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7614 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7615 | maybe_temp2_loc.AsRegister<Register>(), |
| 7616 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7617 | // Compare the classes and continue the loop if they do not match. |
| 7618 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7619 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7620 | break; |
| 7621 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7622 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7623 | |
| 7624 | if (done.IsLinked()) { |
| 7625 | __ Bind(&done); |
| 7626 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7627 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7628 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7629 | } |
| 7630 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7631 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7632 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7633 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7634 | InvokeRuntimeCallingConvention calling_convention; |
| 7635 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7636 | } |
| 7637 | |
| 7638 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7639 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7640 | instruction, |
| 7641 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7642 | if (instruction->IsEnter()) { |
| 7643 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7644 | } else { |
| 7645 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7646 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7647 | } |
| 7648 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7649 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 7650 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 7651 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7652 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7653 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7654 | LocationSummary* locations = |
| 7655 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7656 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7657 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7658 | // 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] | 7659 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7660 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7661 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7662 | } |
| 7663 | |
| 7664 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7665 | HandleBitwiseOperation(instruction); |
| 7666 | } |
| 7667 | |
| 7668 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7669 | HandleBitwiseOperation(instruction); |
| 7670 | } |
| 7671 | |
| 7672 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7673 | HandleBitwiseOperation(instruction); |
| 7674 | } |
| 7675 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7676 | |
| 7677 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7678 | LocationSummary* locations = |
| 7679 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7680 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7681 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7682 | |
| 7683 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7684 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7685 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7686 | } |
| 7687 | |
| 7688 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7689 | LocationSummary* locations = instruction->GetLocations(); |
| 7690 | Location first = locations->InAt(0); |
| 7691 | Location second = locations->InAt(1); |
| 7692 | Location out = locations->Out(); |
| 7693 | |
| 7694 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7695 | Register first_reg = first.AsRegister<Register>(); |
| 7696 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7697 | Register out_reg = out.AsRegister<Register>(); |
| 7698 | |
| 7699 | switch (instruction->GetOpKind()) { |
| 7700 | case HInstruction::kAnd: |
| 7701 | __ bic(out_reg, first_reg, second_reg); |
| 7702 | break; |
| 7703 | case HInstruction::kOr: |
| 7704 | __ orn(out_reg, first_reg, second_reg); |
| 7705 | break; |
| 7706 | // There is no EON on arm. |
| 7707 | case HInstruction::kXor: |
| 7708 | default: |
| 7709 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7710 | UNREACHABLE(); |
| 7711 | } |
| 7712 | return; |
| 7713 | |
| 7714 | } else { |
| 7715 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7716 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7717 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7718 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7719 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7720 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7721 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7722 | |
| 7723 | switch (instruction->GetOpKind()) { |
| 7724 | case HInstruction::kAnd: |
| 7725 | __ bic(out_low, first_low, second_low); |
| 7726 | __ bic(out_high, first_high, second_high); |
| 7727 | break; |
| 7728 | case HInstruction::kOr: |
| 7729 | __ orn(out_low, first_low, second_low); |
| 7730 | __ orn(out_high, first_high, second_high); |
| 7731 | break; |
| 7732 | // There is no EON on arm. |
| 7733 | case HInstruction::kXor: |
| 7734 | default: |
| 7735 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7736 | UNREACHABLE(); |
| 7737 | } |
| 7738 | } |
| 7739 | } |
| 7740 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7741 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7742 | HDataProcWithShifterOp* instruction) { |
| 7743 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7744 | instruction->GetType() == Primitive::kPrimLong); |
| 7745 | LocationSummary* locations = |
| 7746 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7747 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7748 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7749 | |
| 7750 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7751 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7752 | locations->SetOut(Location::RequiresRegister(), |
| 7753 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7754 | } |
| 7755 | |
| 7756 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7757 | HDataProcWithShifterOp* instruction) { |
| 7758 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7759 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7760 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7761 | const Location left = locations->InAt(0); |
| 7762 | const Location right = locations->InAt(1); |
| 7763 | const Location out = locations->Out(); |
| 7764 | |
| 7765 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7766 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7767 | |
| 7768 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7769 | ? right.AsRegisterPairLow<Register>() |
| 7770 | : right.AsRegister<Register>(); |
| 7771 | |
| 7772 | GenerateDataProcInstruction(kind, |
| 7773 | out.AsRegister<Register>(), |
| 7774 | left.AsRegister<Register>(), |
| 7775 | ShifterOperand(second, |
| 7776 | ShiftFromOpKind(op_kind), |
| 7777 | instruction->GetShiftAmount()), |
| 7778 | codegen_); |
| 7779 | } else { |
| 7780 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7781 | |
| 7782 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7783 | const Register second = right.AsRegister<Register>(); |
| 7784 | |
| 7785 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7786 | GenerateDataProc(kind, |
| 7787 | out, |
| 7788 | left, |
| 7789 | ShifterOperand(second), |
| 7790 | ShifterOperand(second, ASR, 31), |
| 7791 | codegen_); |
| 7792 | } else { |
| 7793 | GenerateLongDataProc(instruction, codegen_); |
| 7794 | } |
| 7795 | } |
| 7796 | } |
| 7797 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7798 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7799 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7800 | if (value == 0xffffffffu) { |
| 7801 | if (out != first) { |
| 7802 | __ mov(out, ShifterOperand(first)); |
| 7803 | } |
| 7804 | return; |
| 7805 | } |
| 7806 | if (value == 0u) { |
| 7807 | __ mov(out, ShifterOperand(0)); |
| 7808 | return; |
| 7809 | } |
| 7810 | ShifterOperand so; |
| 7811 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7812 | __ and_(out, first, so); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7813 | } else if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7814 | __ bic(out, first, ShifterOperand(~value)); |
Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 7815 | } else { |
| 7816 | DCHECK(IsPowerOfTwo(value + 1)); |
| 7817 | __ ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7822 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7823 | if (value == 0u) { |
| 7824 | if (out != first) { |
| 7825 | __ mov(out, ShifterOperand(first)); |
| 7826 | } |
| 7827 | return; |
| 7828 | } |
| 7829 | if (value == 0xffffffffu) { |
| 7830 | __ mvn(out, ShifterOperand(0)); |
| 7831 | return; |
| 7832 | } |
| 7833 | ShifterOperand so; |
| 7834 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7835 | __ orr(out, first, so); |
| 7836 | } else { |
| 7837 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7838 | __ orn(out, first, ShifterOperand(~value)); |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7843 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7844 | if (value == 0u) { |
| 7845 | if (out != first) { |
| 7846 | __ mov(out, ShifterOperand(first)); |
| 7847 | } |
| 7848 | return; |
| 7849 | } |
| 7850 | __ eor(out, first, ShifterOperand(value)); |
| 7851 | } |
| 7852 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7853 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7854 | Location first, |
| 7855 | uint64_t value) { |
| 7856 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7857 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7858 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7859 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7860 | uint32_t value_low = Low32Bits(value); |
| 7861 | uint32_t value_high = High32Bits(value); |
| 7862 | if (value_low == 0u) { |
| 7863 | if (out_low != first_low) { |
| 7864 | __ mov(out_low, ShifterOperand(first_low)); |
| 7865 | } |
| 7866 | __ AddConstant(out_high, first_high, value_high); |
| 7867 | return; |
| 7868 | } |
| 7869 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7870 | ShifterOperand so; |
| 7871 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7872 | __ adc(out_high, first_high, so); |
| 7873 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7874 | __ sbc(out_high, first_high, so); |
| 7875 | } else { |
| 7876 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7877 | UNREACHABLE(); |
| 7878 | } |
| 7879 | } |
| 7880 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7881 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7882 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7883 | Location first = locations->InAt(0); |
| 7884 | Location second = locations->InAt(1); |
| 7885 | Location out = locations->Out(); |
| 7886 | |
| 7887 | if (second.IsConstant()) { |
| 7888 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7889 | uint32_t value_low = Low32Bits(value); |
| 7890 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7891 | Register first_reg = first.AsRegister<Register>(); |
| 7892 | Register out_reg = out.AsRegister<Register>(); |
| 7893 | if (instruction->IsAnd()) { |
| 7894 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7895 | } else if (instruction->IsOr()) { |
| 7896 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7897 | } else { |
| 7898 | DCHECK(instruction->IsXor()); |
| 7899 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7900 | } |
| 7901 | } else { |
| 7902 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7903 | uint32_t value_high = High32Bits(value); |
| 7904 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7905 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7906 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7907 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7908 | if (instruction->IsAnd()) { |
| 7909 | GenerateAndConst(out_low, first_low, value_low); |
| 7910 | GenerateAndConst(out_high, first_high, value_high); |
| 7911 | } else if (instruction->IsOr()) { |
| 7912 | GenerateOrrConst(out_low, first_low, value_low); |
| 7913 | GenerateOrrConst(out_high, first_high, value_high); |
| 7914 | } else { |
| 7915 | DCHECK(instruction->IsXor()); |
| 7916 | GenerateEorConst(out_low, first_low, value_low); |
| 7917 | GenerateEorConst(out_high, first_high, value_high); |
| 7918 | } |
| 7919 | } |
| 7920 | return; |
| 7921 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7922 | |
| 7923 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7924 | Register first_reg = first.AsRegister<Register>(); |
| 7925 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7926 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7927 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7928 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7929 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7930 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7931 | } else { |
| 7932 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7933 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7934 | } |
| 7935 | } else { |
| 7936 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7937 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7938 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7939 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7940 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7941 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7942 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7943 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7944 | __ and_(out_low, first_low, second_low); |
| 7945 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7946 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7947 | __ orr(out_low, first_low, second_low); |
| 7948 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7949 | } else { |
| 7950 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7951 | __ eor(out_low, first_low, second_low); |
| 7952 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7953 | } |
| 7954 | } |
| 7955 | } |
| 7956 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7957 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7958 | HInstruction* instruction, |
| 7959 | Location out, |
| 7960 | uint32_t offset, |
| 7961 | Location maybe_temp, |
| 7962 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7963 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7964 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7965 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7966 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7967 | if (kUseBakerReadBarrier) { |
| 7968 | // Load with fast path based Baker's read barrier. |
| 7969 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7970 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7971 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7972 | } else { |
| 7973 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7974 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7975 | // in the following move operation, as we will need it for the |
| 7976 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7977 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7978 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7979 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7980 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7981 | } |
| 7982 | } else { |
| 7983 | // Plain load with no read barrier. |
| 7984 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7985 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7986 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7987 | } |
| 7988 | } |
| 7989 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7990 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7991 | HInstruction* instruction, |
| 7992 | Location out, |
| 7993 | Location obj, |
| 7994 | uint32_t offset, |
| 7995 | Location maybe_temp, |
| 7996 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7997 | Register out_reg = out.AsRegister<Register>(); |
| 7998 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7999 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 8000 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8001 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8002 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8003 | // Load with fast path based Baker's read barrier. |
| 8004 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8005 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 8006 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8007 | } else { |
| 8008 | // Load with slow path based read barrier. |
| 8009 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8010 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8011 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8012 | } |
| 8013 | } else { |
| 8014 | // Plain load with no read barrier. |
| 8015 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8016 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8017 | __ MaybeUnpoisonHeapReference(out_reg); |
| 8018 | } |
| 8019 | } |
| 8020 | |
| 8021 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 8022 | Location root, |
| 8023 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8024 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8025 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8026 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 8027 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 8028 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8029 | if (kUseBakerReadBarrier) { |
| 8030 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8031 | // Baker's read barrier are used. |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8032 | if (kBakerReadBarrierLinkTimeThunksEnableForGcRoots && |
| 8033 | !Runtime::Current()->UseJitCompilation()) { |
| 8034 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8035 | // to decide whether to mark the loaded GC root or not. Instead, we |
| 8036 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8037 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8038 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8039 | // |
| 8040 | // We use link-time generated thunks for the slow path. That thunk |
| 8041 | // checks the reference and jumps to the entrypoint if needed. |
| 8042 | // |
| 8043 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8044 | // lr = &return_address; |
| 8045 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8046 | // if (temp != nullptr) { |
| 8047 | // goto gc_root_thunk<root_reg>(lr) |
| 8048 | // } |
| 8049 | // return_address: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8050 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8051 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8052 | uint32_t custom_data = |
| 8053 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierGcRootData(root_reg); |
| 8054 | Label* bne_label = codegen_->NewBakerReadBarrierPatch(custom_data); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8055 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8056 | // entrypoint_reg = |
| 8057 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8058 | DCHECK_EQ(IP, 12); |
| 8059 | const int32_t entry_point_offset = |
| 8060 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8061 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8062 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8063 | Label return_address; |
| 8064 | __ AdrCode(LR, &return_address); |
| 8065 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8066 | static_assert( |
| 8067 | BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_OFFSET == -8, |
| 8068 | "GC root LDR must be 2 32-bit instructions (8B) before the return address label."); |
| 8069 | // Currently the offset is always within range. If that changes, |
| 8070 | // we shall have to split the load the same way as for fields. |
| 8071 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8072 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8073 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8074 | EmitPlaceholderBne(codegen_, bne_label); |
| 8075 | __ Bind(&return_address); |
| 8076 | } else { |
| 8077 | // Note that we do not actually check the value of |
| 8078 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 8079 | // root or not. Instead, we load into `temp` the read barrier |
| 8080 | // mark entry point corresponding to register `root`. If `temp` |
| 8081 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 8082 | // versa. |
| 8083 | // |
| 8084 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8085 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8086 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8087 | // // Slow path. |
| 8088 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
| 8089 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8090 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8091 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 8092 | Location temp = Location::RegisterLocation(LR); |
| 8093 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 8094 | instruction, root, /* entrypoint */ temp); |
| 8095 | codegen_->AddSlowPath(slow_path); |
| 8096 | |
| 8097 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8098 | const int32_t entry_point_offset = |
| 8099 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 8100 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8101 | // threads are suspended or running a checkpoint. |
| 8102 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 8103 | |
| 8104 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8105 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8106 | static_assert( |
| 8107 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 8108 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 8109 | "have different sizes."); |
| 8110 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 8111 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 8112 | "have different sizes."); |
| 8113 | |
| 8114 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8115 | // checking GetIsGcMarking. |
| 8116 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8117 | __ Bind(slow_path->GetExitLabel()); |
| 8118 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8119 | } else { |
| 8120 | // GC root loaded through a slow path for read barriers other |
| 8121 | // than Baker's. |
| 8122 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8123 | __ AddConstant(root_reg, obj, offset); |
| 8124 | // /* mirror::Object* */ root = root->Read() |
| 8125 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 8126 | } |
| 8127 | } else { |
| 8128 | // Plain GC root load with no read barrier. |
| 8129 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8130 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8131 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8132 | // do not have to unpoison `root_reg` here. |
| 8133 | } |
| 8134 | } |
| 8135 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8136 | void CodeGeneratorARM::MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations) { |
| 8137 | DCHECK(kEmitCompilerReadBarrier); |
| 8138 | DCHECK(kUseBakerReadBarrier); |
| 8139 | if (kBakerReadBarrierLinkTimeThunksEnableForFields) { |
| 8140 | if (!Runtime::Current()->UseJitCompilation()) { |
| 8141 | locations->AddTemp(Location::RegisterLocation(kBakerCcEntrypointRegister)); |
| 8142 | } |
| 8143 | } |
| 8144 | } |
| 8145 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8146 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8147 | Location ref, |
| 8148 | Register obj, |
| 8149 | uint32_t offset, |
| 8150 | Location temp, |
| 8151 | bool needs_null_check) { |
| 8152 | DCHECK(kEmitCompilerReadBarrier); |
| 8153 | DCHECK(kUseBakerReadBarrier); |
| 8154 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8155 | if (kBakerReadBarrierLinkTimeThunksEnableForFields && |
| 8156 | !Runtime::Current()->UseJitCompilation()) { |
| 8157 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8158 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8159 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8160 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8161 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8162 | // |
| 8163 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8164 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8165 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8166 | // |
| 8167 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8168 | // lr = &gray_return_address; |
| 8169 | // if (temp != nullptr) { |
| 8170 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8171 | // } |
| 8172 | // not_gray_return_address: |
| 8173 | // // Original reference load. If the offset is too large to fit |
| 8174 | // // into LDR, we use an adjusted base register here. |
| 8175 | // GcRoot<mirror::Object> reference = *(obj+offset); |
| 8176 | // gray_return_address: |
| 8177 | |
| 8178 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8179 | Register base = obj; |
| 8180 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8181 | base = temp.AsRegister<Register>(); |
| 8182 | DCHECK_NE(base, kBakerCcEntrypointRegister); |
| 8183 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8184 | __ AddConstant(base, obj, offset & ~(kReferenceLoadMinFarOffset - 1u)); |
| 8185 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8186 | } |
| 8187 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8188 | uint32_t custom_data = |
| 8189 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierFieldData(base, obj); |
| 8190 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8191 | |
| 8192 | // entrypoint_reg = |
| 8193 | // Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 8194 | DCHECK_EQ(IP, 12); |
| 8195 | const int32_t entry_point_offset = |
| 8196 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8197 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8198 | |
| 8199 | Label return_address; |
| 8200 | __ AdrCode(LR, &return_address); |
| 8201 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8202 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8203 | EmitPlaceholderBne(this, bne_label); |
| 8204 | static_assert(BAKER_MARK_INTROSPECTION_FIELD_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 8205 | "Field LDR must be 1 32-bit instruction (4B) before the return address label; " |
| 8206 | " 2 32-bit instructions (8B) for heap poisoning."); |
| 8207 | Register ref_reg = ref.AsRegister<Register>(); |
| 8208 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8209 | __ LoadFromOffset(kLoadWord, ref_reg, base, offset); |
| 8210 | if (needs_null_check) { |
| 8211 | MaybeRecordImplicitNullCheck(instruction); |
| 8212 | } |
| 8213 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8214 | __ Bind(&return_address); |
| 8215 | return; |
| 8216 | } |
| 8217 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8218 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 8219 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8220 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8221 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8222 | 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] | 8223 | } |
| 8224 | |
| 8225 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8226 | Location ref, |
| 8227 | Register obj, |
| 8228 | uint32_t data_offset, |
| 8229 | Location index, |
| 8230 | Location temp, |
| 8231 | bool needs_null_check) { |
| 8232 | DCHECK(kEmitCompilerReadBarrier); |
| 8233 | DCHECK(kUseBakerReadBarrier); |
| 8234 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8235 | static_assert( |
| 8236 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8237 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8238 | ScaleFactor scale_factor = TIMES_4; |
| 8239 | |
| 8240 | if (kBakerReadBarrierLinkTimeThunksEnableForArrays && |
| 8241 | !Runtime::Current()->UseJitCompilation()) { |
| 8242 | // Note that we do not actually check the value of `GetIsGcMarking()` |
| 8243 | // to decide whether to mark the loaded reference or not. Instead, we |
| 8244 | // load into `temp` (actually kBakerCcEntrypointRegister) the read |
| 8245 | // barrier mark introspection entrypoint. If `temp` is null, it means |
| 8246 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8247 | // |
| 8248 | // We use link-time generated thunks for the slow path. That thunk checks |
| 8249 | // the holder and jumps to the entrypoint if needed. If the holder is not |
| 8250 | // gray, it creates a fake dependency and returns to the LDR instruction. |
| 8251 | // |
| 8252 | // temp = Thread::Current()->pReadBarrierMarkIntrospection |
| 8253 | // lr = &gray_return_address; |
| 8254 | // if (temp != nullptr) { |
| 8255 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8256 | // } |
| 8257 | // not_gray_return_address: |
| 8258 | // // Original reference load. If the offset is too large to fit |
| 8259 | // // into LDR, we use an adjusted base register here. |
| 8260 | // GcRoot<mirror::Object> reference = data[index]; |
| 8261 | // gray_return_address: |
| 8262 | |
| 8263 | DCHECK(index.IsValid()); |
| 8264 | Register index_reg = index.AsRegister<Register>(); |
| 8265 | Register ref_reg = ref.AsRegister<Register>(); |
| 8266 | Register data_reg = temp.AsRegister<Register>(); |
| 8267 | DCHECK_NE(data_reg, kBakerCcEntrypointRegister); |
| 8268 | |
| 8269 | CheckLastTempIsBakerCcEntrypointRegister(instruction); |
| 8270 | uint32_t custom_data = |
| 8271 | linker::Thumb2RelativePatcher::EncodeBakerReadBarrierArrayData(data_reg); |
| 8272 | Label* bne_label = NewBakerReadBarrierPatch(custom_data); |
| 8273 | |
| 8274 | // entrypoint_reg = |
| 8275 | // Thread::Current()->pReadBarrierMarkReg16, i.e. pReadBarrierMarkIntrospection. |
| 8276 | DCHECK_EQ(IP, 12); |
| 8277 | const int32_t entry_point_offset = |
| 8278 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(IP); |
| 8279 | __ LoadFromOffset(kLoadWord, kBakerCcEntrypointRegister, TR, entry_point_offset); |
| 8280 | __ AddConstant(data_reg, obj, data_offset); |
| 8281 | |
| 8282 | Label return_address; |
| 8283 | __ AdrCode(LR, &return_address); |
| 8284 | __ CmpConstant(kBakerCcEntrypointRegister, 0); |
| 8285 | ScopedForce32Bit force_32bit(down_cast<Thumb2Assembler*>(GetAssembler())); |
| 8286 | EmitPlaceholderBne(this, bne_label); |
| 8287 | static_assert(BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET == (kPoisonHeapReferences ? -8 : -4), |
| 8288 | "Array LDR must be 1 32-bit instruction (4B) before the return address label; " |
| 8289 | " 2 32-bit instructions (8B) for heap poisoning."); |
| 8290 | __ ldr(ref_reg, Address(data_reg, index_reg, LSL, scale_factor)); |
| 8291 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8292 | GetAssembler()->MaybeUnpoisonHeapReference(ref_reg); |
| 8293 | __ Bind(&return_address); |
| 8294 | return; |
| 8295 | } |
| 8296 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8297 | // /* HeapReference<Object> */ ref = |
| 8298 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 8299 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8300 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8301 | } |
| 8302 | |
| 8303 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8304 | Location ref, |
| 8305 | Register obj, |
| 8306 | uint32_t offset, |
| 8307 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8308 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8309 | Location temp, |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8310 | bool needs_null_check) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8311 | DCHECK(kEmitCompilerReadBarrier); |
| 8312 | DCHECK(kUseBakerReadBarrier); |
| 8313 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8314 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8315 | // whether we need to enter the slow path to mark the reference. |
| 8316 | // Then, in the slow path, check the gray bit in the lock word of |
| 8317 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 8318 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8319 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8320 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8321 | // instead, we load into `temp2` the read barrier mark entry point |
| 8322 | // corresponding to register `ref`. If `temp2` is null, it means |
| 8323 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8324 | // |
| 8325 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 8326 | // if (temp2 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8327 | // // Slow path. |
| 8328 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8329 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8330 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8331 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8332 | // if (is_gray) { |
| 8333 | // ref = temp2(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 8334 | // } |
| 8335 | // } else { |
| 8336 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8337 | // } |
| 8338 | |
| 8339 | Register temp_reg = temp.AsRegister<Register>(); |
| 8340 | |
| 8341 | // Slow path marking the object `ref` when the GC is marking. The |
| 8342 | // entrypoint will already be loaded in `temp2`. |
| 8343 | Location temp2 = Location::RegisterLocation(LR); |
| 8344 | SlowPathCodeARM* slow_path = |
| 8345 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 8346 | instruction, |
| 8347 | ref, |
| 8348 | obj, |
| 8349 | offset, |
| 8350 | index, |
| 8351 | scale_factor, |
| 8352 | needs_null_check, |
| 8353 | temp_reg, |
| 8354 | /* entrypoint */ temp2); |
| 8355 | AddSlowPath(slow_path); |
| 8356 | |
| 8357 | // temp2 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8358 | const int32_t entry_point_offset = |
| 8359 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8360 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8361 | // threads are suspended or running a checkpoint. |
| 8362 | __ LoadFromOffset(kLoadWord, temp2.AsRegister<Register>(), TR, entry_point_offset); |
| 8363 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8364 | // checking GetIsGcMarking. |
| 8365 | __ CompareAndBranchIfNonZero(temp2.AsRegister<Register>(), slow_path->GetEntryLabel()); |
| 8366 | // Fast path: the GC is not marking: just load the reference. |
| 8367 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
| 8368 | __ Bind(slow_path->GetExitLabel()); |
| 8369 | } |
| 8370 | |
| 8371 | void CodeGeneratorARM::UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 8372 | Location ref, |
| 8373 | Register obj, |
| 8374 | Location field_offset, |
| 8375 | Location temp, |
| 8376 | bool needs_null_check, |
| 8377 | Register temp2) { |
| 8378 | DCHECK(kEmitCompilerReadBarrier); |
| 8379 | DCHECK(kUseBakerReadBarrier); |
| 8380 | |
| 8381 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 8382 | // whether we need to enter the slow path to update the reference |
| 8383 | // field within `obj`. Then, in the slow path, check the gray bit |
| 8384 | // in the lock word of the reference's holder (`obj`) to decide |
| 8385 | // whether to mark `ref` and update the field or not. |
| 8386 | // |
| 8387 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8388 | // instead, we load into `temp3` the read barrier mark entry point |
| 8389 | // corresponding to register `ref`. If `temp3` is null, it means |
| 8390 | // that `GetIsGcMarking()` is false, and vice versa. |
| 8391 | // |
| 8392 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8393 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 8394 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8395 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 8396 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 8397 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 8398 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 8399 | // if (is_gray) { |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8400 | // old_ref = ref; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8401 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8402 | // compareAndSwapObject(obj, field_offset, old_ref, ref); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8403 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8404 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8405 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8406 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 8407 | |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8408 | // Slow path updating the object reference at address `obj + |
| 8409 | // field_offset` when the GC is marking. The entrypoint will already |
| 8410 | // be loaded in `temp3`. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8411 | Location temp3 = Location::RegisterLocation(LR); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8412 | SlowPathCodeARM* slow_path = |
| 8413 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 8414 | instruction, |
| 8415 | ref, |
| 8416 | obj, |
| 8417 | /* offset */ 0u, |
| 8418 | /* index */ field_offset, |
| 8419 | /* scale_factor */ ScaleFactor::TIMES_1, |
| 8420 | needs_null_check, |
| 8421 | temp_reg, |
| 8422 | temp2, |
| 8423 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8424 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8425 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8426 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8427 | const int32_t entry_point_offset = |
| 8428 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8429 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8430 | // threads are suspended or running a checkpoint. |
| 8431 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8432 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8433 | // checking GetIsGcMarking. |
| 8434 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 8435 | // Fast path: the GC is not marking: nothing to do (the field is |
| 8436 | // up-to-date, and we don't need to load the reference). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8437 | __ Bind(slow_path->GetExitLabel()); |
| 8438 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8439 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8440 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8441 | Location ref, |
| 8442 | Register obj, |
| 8443 | uint32_t offset, |
| 8444 | Location index, |
| 8445 | ScaleFactor scale_factor, |
| 8446 | bool needs_null_check) { |
| 8447 | Register ref_reg = ref.AsRegister<Register>(); |
| 8448 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8449 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8450 | // Load types involving an "index": ArrayGet, |
| 8451 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8452 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8453 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8454 | if (index.IsConstant()) { |
| 8455 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8456 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8457 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8458 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8459 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8460 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8461 | // intrinsics, which use a register pair as index ("long |
| 8462 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8463 | Register index_reg = index.IsRegisterPair() |
| 8464 | ? index.AsRegisterPairLow<Register>() |
| 8465 | : index.AsRegister<Register>(); |
| 8466 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8467 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8468 | } |
| 8469 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8470 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8471 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8472 | } |
| 8473 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8474 | if (needs_null_check) { |
| 8475 | MaybeRecordImplicitNullCheck(instruction); |
| 8476 | } |
| 8477 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8478 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8479 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8480 | } |
| 8481 | |
| 8482 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8483 | Location out, |
| 8484 | Location ref, |
| 8485 | Location obj, |
| 8486 | uint32_t offset, |
| 8487 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8488 | DCHECK(kEmitCompilerReadBarrier); |
| 8489 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8490 | // Insert a slow path based read barrier *after* the reference load. |
| 8491 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8492 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8493 | // reference will be carried out by the runtime within the slow |
| 8494 | // path. |
| 8495 | // |
| 8496 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8497 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8498 | // not used by the artReadBarrierSlow entry point. |
| 8499 | // |
| 8500 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8501 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8502 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8503 | AddSlowPath(slow_path); |
| 8504 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8505 | __ b(slow_path->GetEntryLabel()); |
| 8506 | __ Bind(slow_path->GetExitLabel()); |
| 8507 | } |
| 8508 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8509 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8510 | Location out, |
| 8511 | Location ref, |
| 8512 | Location obj, |
| 8513 | uint32_t offset, |
| 8514 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8515 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8516 | // Baker's read barriers shall be handled by the fast path |
| 8517 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8518 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8519 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8520 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8521 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8522 | } else if (kPoisonHeapReferences) { |
| 8523 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8524 | } |
| 8525 | } |
| 8526 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8527 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8528 | Location out, |
| 8529 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8530 | DCHECK(kEmitCompilerReadBarrier); |
| 8531 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8532 | // Insert a slow path based read barrier *after* the GC root load. |
| 8533 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8534 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8535 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8536 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8537 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8538 | AddSlowPath(slow_path); |
| 8539 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8540 | __ b(slow_path->GetEntryLabel()); |
| 8541 | __ Bind(slow_path->GetExitLabel()); |
| 8542 | } |
| 8543 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8544 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8545 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8546 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8547 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8548 | } |
| 8549 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8550 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8551 | Register temp) { |
| 8552 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8553 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8554 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8555 | return location.AsRegister<Register>(); |
| 8556 | } |
| 8557 | // For intrinsics we allow any location, so it may be on the stack. |
| 8558 | if (!location.IsRegister()) { |
| 8559 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8560 | return temp; |
| 8561 | } |
| 8562 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8563 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8564 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8565 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8566 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8567 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8568 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8569 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8570 | return temp; |
| 8571 | } |
| 8572 | return location.AsRegister<Register>(); |
| 8573 | } |
| 8574 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8575 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8576 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8577 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8578 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8579 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8580 | uint32_t offset = |
| 8581 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8582 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8583 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8584 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8585 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8586 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8587 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8588 | break; |
| 8589 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8590 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8591 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8592 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8593 | HArmDexCacheArraysBase* base = |
| 8594 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8595 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8596 | temp.AsRegister<Register>()); |
| 8597 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8598 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8599 | break; |
| 8600 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8601 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8602 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8603 | Register method_reg; |
| 8604 | Register reg = temp.AsRegister<Register>(); |
| 8605 | if (current_method.IsRegister()) { |
| 8606 | method_reg = current_method.AsRegister<Register>(); |
| 8607 | } else { |
| 8608 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8609 | DCHECK(!current_method.IsValid()); |
| 8610 | method_reg = reg; |
| 8611 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 8612 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8613 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8614 | __ LoadFromOffset(kLoadWord, |
| 8615 | reg, |
| 8616 | method_reg, |
| 8617 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 8618 | // temp = temp[index_in_cache]; |
| 8619 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8620 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8621 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 8622 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 8623 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8624 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8625 | return callee_method; |
| 8626 | } |
| 8627 | |
| 8628 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 8629 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8630 | |
| 8631 | switch (invoke->GetCodePtrLocation()) { |
| 8632 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8633 | __ bl(GetFrameEntryLabel()); |
| 8634 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8635 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8636 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8637 | __ LoadFromOffset( |
| 8638 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8639 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8640 | // LR() |
| 8641 | __ blx(LR); |
| 8642 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8643 | } |
| 8644 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8645 | DCHECK(!IsLeafMethod()); |
| 8646 | } |
| 8647 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8648 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8649 | Register temp = temp_location.AsRegister<Register>(); |
| 8650 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8651 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8652 | |
| 8653 | // Use the calling convention instead of the location of the receiver, as |
| 8654 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8655 | // slow path, the arguments have been moved to the right place, so here we are |
| 8656 | // guaranteed that the receiver is the first register of the calling convention. |
| 8657 | InvokeDexCallingConvention calling_convention; |
| 8658 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8659 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8660 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8661 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8662 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8663 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8664 | // emit a read barrier for the previous class reference load. |
| 8665 | // However this is not required in practice, as this is an |
| 8666 | // intermediate/temporary reference and because the current |
| 8667 | // concurrent copying collector keeps the from-space memory |
| 8668 | // intact/accessible until the end of the marking phase (the |
| 8669 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8670 | __ MaybeUnpoisonHeapReference(temp); |
| 8671 | // temp = temp->GetMethodAt(method_offset); |
| 8672 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8673 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8674 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8675 | // LR = temp->GetEntryPoint(); |
| 8676 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 8677 | // LR(); |
| 8678 | __ blx(LR); |
| 8679 | } |
| 8680 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8681 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8682 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8683 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8684 | } |
| 8685 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8686 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8687 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8688 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8689 | } |
| 8690 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8691 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 8692 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8693 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8694 | } |
| 8695 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8696 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 8697 | const DexFile& dex_file, uint32_t element_offset) { |
| 8698 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8699 | } |
| 8700 | |
| 8701 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 8702 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8703 | patches->emplace_back(dex_file, offset_or_index); |
| 8704 | return &patches->back(); |
| 8705 | } |
| 8706 | |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8707 | Label* CodeGeneratorARM::NewBakerReadBarrierPatch(uint32_t custom_data) { |
| 8708 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 8709 | return &baker_read_barrier_patches_.back().label; |
| 8710 | } |
| 8711 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8712 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8713 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8714 | return boot_image_string_patches_.GetOrCreate( |
| 8715 | StringReference(&dex_file, string_index), |
| 8716 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8717 | } |
| 8718 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8719 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8720 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8721 | return boot_image_type_patches_.GetOrCreate( |
| 8722 | TypeReference(&dex_file, type_index), |
| 8723 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8724 | } |
| 8725 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8726 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8727 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8728 | } |
| 8729 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8730 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8731 | dex::StringIndex string_index, |
| 8732 | Handle<mirror::String> handle) { |
| 8733 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8734 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8735 | return jit_string_patches_.GetOrCreate( |
| 8736 | StringReference(&dex_file, string_index), |
| 8737 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8738 | } |
| 8739 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8740 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8741 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8742 | Handle<mirror::Class> handle) { |
| 8743 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8744 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8745 | return jit_class_patches_.GetOrCreate( |
| 8746 | TypeReference(&dex_file, type_index), |
| 8747 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8748 | } |
| 8749 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8750 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8751 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 8752 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8753 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8754 | for (const PcRelativePatchInfo& info : infos) { |
| 8755 | const DexFile& dex_file = info.target_dex_file; |
| 8756 | size_t offset_or_index = info.offset_or_index; |
| 8757 | DCHECK(info.add_pc_label.IsBound()); |
| 8758 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 8759 | // Add MOVW patch. |
| 8760 | DCHECK(info.movw_label.IsBound()); |
| 8761 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 8762 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8763 | // Add MOVT patch. |
| 8764 | DCHECK(info.movt_label.IsBound()); |
| 8765 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 8766 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8767 | } |
| 8768 | } |
| 8769 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8770 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8771 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8772 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8773 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8774 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8775 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8776 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8777 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8778 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
| 8779 | baker_read_barrier_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8780 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8781 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8782 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8783 | for (const auto& entry : boot_image_string_patches_) { |
| 8784 | const StringReference& target_string = entry.first; |
| 8785 | Literal* literal = entry.second; |
| 8786 | DCHECK(literal->GetLabel()->IsBound()); |
| 8787 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8788 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8789 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8790 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8791 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8792 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8793 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8794 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8795 | linker_patches); |
| 8796 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8797 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8798 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8799 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8800 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8801 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8802 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8803 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8804 | for (const auto& entry : boot_image_type_patches_) { |
| 8805 | const TypeReference& target_type = entry.first; |
| 8806 | Literal* literal = entry.second; |
| 8807 | DCHECK(literal->GetLabel()->IsBound()); |
| 8808 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8809 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8810 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8811 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8812 | } |
Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8813 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 8814 | linker_patches->push_back(LinkerPatch::BakerReadBarrierBranchPatch(info.label.Position(), |
| 8815 | info.custom_data)); |
| 8816 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8817 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8818 | } |
| 8819 | |
| 8820 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 8821 | return map->GetOrCreate( |
| 8822 | value, |
| 8823 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8824 | } |
| 8825 | |
| 8826 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 8827 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8828 | return map->GetOrCreate( |
| 8829 | target_method, |
| 8830 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8831 | } |
| 8832 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8833 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8834 | LocationSummary* locations = |
| 8835 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8836 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8837 | Location::RequiresRegister()); |
| 8838 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8839 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8840 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8841 | } |
| 8842 | |
| 8843 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8844 | LocationSummary* locations = instr->GetLocations(); |
| 8845 | Register res = locations->Out().AsRegister<Register>(); |
| 8846 | Register accumulator = |
| 8847 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 8848 | Register mul_left = |
| 8849 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 8850 | Register mul_right = |
| 8851 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 8852 | |
| 8853 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8854 | __ mla(res, mul_left, mul_right, accumulator); |
| 8855 | } else { |
| 8856 | __ mls(res, mul_left, mul_right, accumulator); |
| 8857 | } |
| 8858 | } |
| 8859 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8860 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8861 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8862 | LOG(FATAL) << "Unreachable"; |
| 8863 | } |
| 8864 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8865 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8866 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8867 | LOG(FATAL) << "Unreachable"; |
| 8868 | } |
| 8869 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8870 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8871 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8872 | LocationSummary* locations = |
| 8873 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8874 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8875 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8876 | codegen_->GetAssembler()->IsThumb()) { |
| 8877 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8878 | if (switch_instr->GetStartValue() != 0) { |
| 8879 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8880 | } |
| 8881 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8882 | } |
| 8883 | |
| 8884 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8885 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8886 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8887 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8888 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8889 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8890 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8891 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8892 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8893 | Register temp_reg = IP; |
| 8894 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8895 | // the immediate, because IP is used as the destination register. For the other |
| 8896 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8897 | // and they can be encoded in the instruction without making use of IP register. |
| 8898 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8899 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8900 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8901 | // Jump to successors[0] if value == lower_bound. |
| 8902 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8903 | int32_t last_index = 0; |
| 8904 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8905 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8906 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8907 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8908 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8909 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8910 | } |
| 8911 | if (num_entries - last_index == 2) { |
| 8912 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8913 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8914 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8915 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8916 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8917 | // And the default for any other value. |
| 8918 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8919 | __ b(codegen_->GetLabelOf(default_block)); |
| 8920 | } |
| 8921 | } else { |
| 8922 | // Create a table lookup. |
| 8923 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8924 | |
| 8925 | // Materialize a pointer to the switch table |
| 8926 | std::vector<Label*> labels(num_entries); |
| 8927 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8928 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8929 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8930 | } |
| 8931 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8932 | |
| 8933 | // Remove the bias. |
| 8934 | Register key_reg; |
| 8935 | if (lower_bound != 0) { |
| 8936 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8937 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8938 | } else { |
| 8939 | key_reg = value_reg; |
| 8940 | } |
| 8941 | |
| 8942 | // Check whether the value is in the table, jump to default block if not. |
| 8943 | __ CmpConstant(key_reg, num_entries - 1); |
| 8944 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8945 | |
| 8946 | // Load the displacement from the table. |
| 8947 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8948 | |
| 8949 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8950 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8951 | } |
| 8952 | } |
| 8953 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8954 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8955 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8956 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8957 | } |
| 8958 | |
| 8959 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8960 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8961 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8962 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8963 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8964 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8965 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8966 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8967 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8968 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8969 | } |
| 8970 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8971 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8972 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8973 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8974 | return; |
| 8975 | } |
| 8976 | |
| 8977 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8978 | |
| 8979 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8980 | if (return_loc.Equals(trg)) { |
| 8981 | return; |
| 8982 | } |
| 8983 | |
| 8984 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8985 | // with the last branch. |
| 8986 | if (type == Primitive::kPrimLong) { |
| 8987 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8988 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8989 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8990 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8991 | } else if (type == Primitive::kPrimDouble) { |
| 8992 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8993 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8994 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8995 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8996 | } else { |
| 8997 | // Let the parallel move resolver take care of all of this. |
| 8998 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8999 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9000 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9001 | } |
| 9002 | } |
| 9003 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9004 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9005 | LocationSummary* locations = |
| 9006 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 9007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9008 | locations->SetOut(Location::RequiresRegister()); |
| 9009 | } |
| 9010 | |
| 9011 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 9012 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 9013 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9014 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9015 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9016 | __ LoadFromOffset(kLoadWord, |
| 9017 | locations->Out().AsRegister<Register>(), |
| 9018 | locations->InAt(0).AsRegister<Register>(), |
| 9019 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9020 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9021 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 9022 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 9023 | __ LoadFromOffset(kLoadWord, |
| 9024 | locations->Out().AsRegister<Register>(), |
| 9025 | locations->InAt(0).AsRegister<Register>(), |
| 9026 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9027 | __ LoadFromOffset(kLoadWord, |
| 9028 | locations->Out().AsRegister<Register>(), |
| 9029 | locations->Out().AsRegister<Register>(), |
| 9030 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9031 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 9032 | } |
| 9033 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9034 | static void PatchJitRootUse(uint8_t* code, |
| 9035 | const uint8_t* roots_data, |
| 9036 | Literal* literal, |
| 9037 | uint64_t index_in_table) { |
| 9038 | DCHECK(literal->GetLabel()->IsBound()); |
| 9039 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 9040 | uintptr_t address = |
| 9041 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9042 | uint8_t* data = code + literal_offset; |
| 9043 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9044 | } |
| 9045 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9046 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9047 | for (const auto& entry : jit_string_patches_) { |
| 9048 | const auto& it = jit_string_roots_.find(entry.first); |
| 9049 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 9050 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 9051 | } |
| 9052 | for (const auto& entry : jit_class_patches_) { |
| 9053 | const auto& it = jit_class_roots_.find(entry.first); |
| 9054 | DCHECK(it != jit_class_roots_.end()); |
| 9055 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 9056 | } |
| 9057 | } |
| 9058 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 9059 | #undef __ |
| 9060 | #undef QUICK_ENTRY_POINT |
| 9061 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 9062 | } // namespace arm |
| 9063 | } // namespace art |