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 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 30 | #include "utils/arm/assembler_arm.h" |
| 31 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 32 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 33 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace arm { |
| 41 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 42 | static bool ExpectedPairLayout(Location location) { |
| 43 | // We expected this for both core and fpu register pairs. |
| 44 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 45 | } |
| 46 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 50 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 52 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 53 | static constexpr SRegister kFpuCalleeSaves[] = |
| 54 | { 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] | 55 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 56 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 57 | // S registers. Therefore there is no need to block it. |
| 58 | static constexpr DRegister DTMP = D31; |
| 59 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 60 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 61 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 62 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 63 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 64 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 66 | static constexpr int kRegListThreshold = 4; |
| 67 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 68 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 69 | // for each live D registers they treat two corresponding S registers as live ones. |
| 70 | // |
| 71 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 72 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 73 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 74 | // - decreasing code size |
| 75 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 76 | // restored and then used in regular non SlowPath code as D register. |
| 77 | // |
| 78 | // For the following example (v means the S register is live): |
| 79 | // D names: | D0 | D1 | D2 | D4 | ... |
| 80 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 81 | // Live? | | v | v | v | v | v | v | | ... |
| 82 | // |
| 83 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 84 | // as D registers. |
| 85 | static size_t SaveContiguousSRegisterList(size_t first, |
| 86 | size_t last, |
| 87 | CodeGenerator* codegen, |
| 88 | size_t stack_offset) { |
| 89 | DCHECK_LE(first, last); |
| 90 | if ((first == last) && (first == 0)) { |
| 91 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 92 | return stack_offset; |
| 93 | } |
| 94 | if (first % 2 == 1) { |
| 95 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 96 | } |
| 97 | |
| 98 | bool save_last = false; |
| 99 | if (last % 2 == 0) { |
| 100 | save_last = true; |
| 101 | --last; |
| 102 | } |
| 103 | |
| 104 | if (first < last) { |
| 105 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 106 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 107 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 108 | |
| 109 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 110 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 111 | } else if (number_of_d_regs > 1) { |
| 112 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 113 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 114 | } |
| 115 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 116 | } |
| 117 | |
| 118 | if (save_last) { |
| 119 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 120 | } |
| 121 | |
| 122 | return stack_offset; |
| 123 | } |
| 124 | |
| 125 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 126 | size_t last, |
| 127 | CodeGenerator* codegen, |
| 128 | size_t stack_offset) { |
| 129 | DCHECK_LE(first, last); |
| 130 | if ((first == last) && (first == 0)) { |
| 131 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 132 | return stack_offset; |
| 133 | } |
| 134 | if (first % 2 == 1) { |
| 135 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 136 | } |
| 137 | |
| 138 | bool restore_last = false; |
| 139 | if (last % 2 == 0) { |
| 140 | restore_last = true; |
| 141 | --last; |
| 142 | } |
| 143 | |
| 144 | if (first < last) { |
| 145 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 146 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 147 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 148 | if (number_of_d_regs == 1) { |
| 149 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 150 | } else if (number_of_d_regs > 1) { |
| 151 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 152 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 153 | } |
| 154 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 155 | } |
| 156 | |
| 157 | if (restore_last) { |
| 158 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 159 | } |
| 160 | |
| 161 | return stack_offset; |
| 162 | } |
| 163 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 164 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 165 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 166 | size_t orig_offset = stack_offset; |
| 167 | |
| 168 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 169 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 170 | // If the register holds an object, update the stack mask. |
| 171 | if (locations->RegisterContainsObject(i)) { |
| 172 | locations->SetStackBit(stack_offset / kVRegSize); |
| 173 | } |
| 174 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 175 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 176 | saved_core_stack_offsets_[i] = stack_offset; |
| 177 | stack_offset += kArmWordSize; |
| 178 | } |
| 179 | |
| 180 | int reg_num = POPCOUNT(core_spills); |
| 181 | if (reg_num != 0) { |
| 182 | if (reg_num > kRegListThreshold) { |
| 183 | __ StoreList(RegList(core_spills), orig_offset); |
| 184 | } else { |
| 185 | stack_offset = orig_offset; |
| 186 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 187 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 192 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 193 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 194 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 195 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 196 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 197 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 198 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 199 | |
| 200 | stack_offset = orig_offset; |
| 201 | while (fp_spills != 0u) { |
| 202 | uint32_t begin = CTZ(fp_spills); |
| 203 | uint32_t tmp = fp_spills + (1u << begin); |
| 204 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 205 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 206 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 207 | } |
| 208 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 212 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 213 | size_t orig_offset = stack_offset; |
| 214 | |
| 215 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 216 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 217 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 218 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 219 | stack_offset += kArmWordSize; |
| 220 | } |
| 221 | |
| 222 | int reg_num = POPCOUNT(core_spills); |
| 223 | if (reg_num != 0) { |
| 224 | if (reg_num > kRegListThreshold) { |
| 225 | __ LoadList(RegList(core_spills), orig_offset); |
| 226 | } else { |
| 227 | stack_offset = orig_offset; |
| 228 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 229 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 234 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 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 = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 241 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 242 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 246 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 247 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 248 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 249 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 251 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 252 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 253 | // Live registers will be restored in the catch block if caught. |
| 254 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 255 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 256 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 257 | instruction_, |
| 258 | instruction_->GetDexPc(), |
| 259 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 260 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 263 | bool IsFatal() const OVERRIDE { return true; } |
| 264 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 265 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 266 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 267 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 269 | }; |
| 270 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 271 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 272 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 273 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 274 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 275 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 276 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 277 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 278 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 279 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 282 | bool IsFatal() const OVERRIDE { return true; } |
| 283 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 284 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 285 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 286 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 288 | }; |
| 289 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 290 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 291 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 292 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 293 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 296 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 297 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 298 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 299 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 300 | if (successor_ == nullptr) { |
| 301 | __ b(GetReturnLabel()); |
| 302 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 303 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 304 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 307 | Label* GetReturnLabel() { |
| 308 | DCHECK(successor_ == nullptr); |
| 309 | return &return_label_; |
| 310 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 311 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 312 | HBasicBlock* GetSuccessor() const { |
| 313 | return successor_; |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 317 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 319 | // If not null, the block to branch to after the suspend check. |
| 320 | HBasicBlock* const successor_; |
| 321 | |
| 322 | // 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] | 323 | Label return_label_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 326 | }; |
| 327 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 328 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 329 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 330 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 331 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 332 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 334 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | LocationSummary* locations = instruction_->GetLocations(); |
| 336 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 337 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 338 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 339 | // Live registers will be restored in the catch block if caught. |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 341 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 352 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 353 | ? kQuickThrowStringBounds |
| 354 | : kQuickThrowArrayBounds; |
| 355 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 356 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 360 | bool IsFatal() const OVERRIDE { return true; } |
| 361 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 362 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 366 | }; |
| 367 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 368 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 369 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 370 | LoadClassSlowPathARM(HLoadClass* cls, |
| 371 | HInstruction* at, |
| 372 | uint32_t dex_pc, |
| 373 | bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 374 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 375 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 376 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 377 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 378 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 379 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 380 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 381 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 382 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 383 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 385 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 386 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 387 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 388 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 389 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 390 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 391 | if (do_clinit_) { |
| 392 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 393 | } else { |
| 394 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 395 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 396 | |
| 397 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 398 | Location out = locations->Out(); |
| 399 | if (out.IsValid()) { |
| 400 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 401 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 402 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 403 | RestoreLiveRegisters(codegen, locations); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 404 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 405 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 406 | if (cls_ == instruction_ && cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry) { |
| 407 | DCHECK(out.IsValid()); |
| 408 | // TODO: Change art_quick_initialize_type/art_quick_initialize_static_storage to |
| 409 | // kSaveEverything and use a temporary for the .bss entry address in the fast path, |
| 410 | // so that we can avoid another calculation here. |
| 411 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 412 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 413 | __ BindTrackedLabel(&labels->movw_label); |
| 414 | __ movw(IP, /* placeholder */ 0u); |
| 415 | __ BindTrackedLabel(&labels->movt_label); |
| 416 | __ movt(IP, /* placeholder */ 0u); |
| 417 | __ BindTrackedLabel(&labels->add_pc_label); |
| 418 | __ add(IP, IP, ShifterOperand(PC)); |
| 419 | __ str(locations->Out().AsRegister<Register>(), Address(IP)); |
| 420 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 421 | __ b(GetExitLabel()); |
| 422 | } |
| 423 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 424 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 425 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 426 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 427 | // The class this slow path will load. |
| 428 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 429 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 430 | // The dex PC of `at_`. |
| 431 | const uint32_t dex_pc_; |
| 432 | |
| 433 | // Whether to initialize the class. |
| 434 | const bool do_clinit_; |
| 435 | |
| 436 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 437 | }; |
| 438 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 439 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 440 | public: |
| 441 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 442 | |
| 443 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 444 | LocationSummary* locations = instruction_->GetLocations(); |
| 445 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 446 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 447 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 448 | Register out = locations->Out().AsRegister<Register>(); |
| 449 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 450 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 451 | |
| 452 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 453 | __ Bind(GetEntryLabel()); |
| 454 | SaveLiveRegisters(codegen, locations); |
| 455 | |
| 456 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 457 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 458 | // the kSaveEverything call (or use `out` for the address after non-kSaveEverything call). |
| 459 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 460 | Register entry_address = temp_is_r0 ? out : temp; |
| 461 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 462 | if (call_saves_everything_except_r0 && temp_is_r0) { |
| 463 | __ mov(entry_address, ShifterOperand(temp)); |
| 464 | } |
| 465 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 466 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 467 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 468 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 469 | |
| 470 | // Store the resolved String to the .bss entry. |
| 471 | if (call_saves_everything_except_r0) { |
| 472 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 473 | __ str(R0, Address(entry_address)); |
| 474 | } else { |
| 475 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 476 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 477 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 478 | __ BindTrackedLabel(&labels->movw_label); |
| 479 | __ movw(entry_address, /* placeholder */ 0u); |
| 480 | __ BindTrackedLabel(&labels->movt_label); |
| 481 | __ movt(entry_address, /* placeholder */ 0u); |
| 482 | __ BindTrackedLabel(&labels->add_pc_label); |
| 483 | __ add(entry_address, entry_address, ShifterOperand(PC)); |
| 484 | __ str(R0, Address(entry_address)); |
| 485 | } |
| 486 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 487 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 488 | RestoreLiveRegisters(codegen, locations); |
| 489 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 490 | __ b(GetExitLabel()); |
| 491 | } |
| 492 | |
| 493 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 494 | |
| 495 | private: |
| 496 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 497 | }; |
| 498 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 499 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 500 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 501 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 502 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 503 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 504 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 505 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 506 | DCHECK(instruction_->IsCheckCast() |
| 507 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 508 | |
| 509 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 510 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 511 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 512 | if (!is_fatal_) { |
| 513 | SaveLiveRegisters(codegen, locations); |
| 514 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 515 | |
| 516 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 517 | // move resolver. |
| 518 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 519 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 520 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 521 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 522 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 523 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 524 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 525 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 526 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 527 | instruction_, |
| 528 | instruction_->GetDexPc(), |
| 529 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 530 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 531 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 532 | } else { |
| 533 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 534 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 535 | instruction_, |
| 536 | instruction_->GetDexPc(), |
| 537 | this); |
| 538 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 539 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 540 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 541 | if (!is_fatal_) { |
| 542 | RestoreLiveRegisters(codegen, locations); |
| 543 | __ b(GetExitLabel()); |
| 544 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 547 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 548 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 549 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 550 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 551 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 552 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 553 | |
| 554 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 555 | }; |
| 556 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 557 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 558 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 559 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 560 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 561 | |
| 562 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 563 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 564 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 565 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 566 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 569 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 570 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 571 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 572 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 573 | }; |
| 574 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 575 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 576 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 577 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 578 | |
| 579 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 580 | LocationSummary* locations = instruction_->GetLocations(); |
| 581 | __ Bind(GetEntryLabel()); |
| 582 | SaveLiveRegisters(codegen, locations); |
| 583 | |
| 584 | InvokeRuntimeCallingConvention calling_convention; |
| 585 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 586 | parallel_move.AddMove( |
| 587 | locations->InAt(0), |
| 588 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 589 | Primitive::kPrimNot, |
| 590 | nullptr); |
| 591 | parallel_move.AddMove( |
| 592 | locations->InAt(1), |
| 593 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 594 | Primitive::kPrimInt, |
| 595 | nullptr); |
| 596 | parallel_move.AddMove( |
| 597 | locations->InAt(2), |
| 598 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 599 | Primitive::kPrimNot, |
| 600 | nullptr); |
| 601 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 602 | |
| 603 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 604 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 605 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 606 | RestoreLiveRegisters(codegen, locations); |
| 607 | __ b(GetExitLabel()); |
| 608 | } |
| 609 | |
| 610 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 611 | |
| 612 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 613 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 614 | }; |
| 615 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 616 | // Slow path marking an object reference `ref` during a read |
| 617 | // barrier. The field `obj.field` in the object `obj` holding this |
| 618 | // reference does not get updated by this slow path after marking (see |
| 619 | // ReadBarrierMarkAndUpdateFieldSlowPathARM below for that). |
| 620 | // |
| 621 | // This means that after the execution of this slow path, `ref` will |
| 622 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 623 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 624 | // probably still be a from-space reference (unless it gets updated by |
| 625 | // another thread, or if another thread installed another object |
| 626 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame^] | 627 | // |
| 628 | // If `entrypoint` is a valid location it is assumed to already be |
| 629 | // holding the entrypoint. The case where the entrypoint is passed in |
| 630 | // is for the GcRoot read barrier. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 631 | class ReadBarrierMarkSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 632 | public: |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 633 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 634 | Location ref, |
| 635 | Location entrypoint = Location::NoLocation()) |
| 636 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 637 | DCHECK(kEmitCompilerReadBarrier); |
| 638 | } |
| 639 | |
| 640 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 641 | |
| 642 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 643 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 644 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 645 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 646 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 647 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 648 | instruction_->IsStaticFieldGet() || |
| 649 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 650 | instruction_->IsArraySet() || |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 651 | instruction_->IsLoadClass() || |
| 652 | instruction_->IsLoadString() || |
| 653 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 654 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 655 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 656 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 657 | << "Unexpected instruction in read barrier marking slow path: " |
| 658 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 659 | // The read barrier instrumentation of object ArrayGet |
| 660 | // instructions does not support the HIntermediateAddress |
| 661 | // instruction. |
| 662 | DCHECK(!(instruction_->IsArrayGet() && |
| 663 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 664 | |
| 665 | __ Bind(GetEntryLabel()); |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 666 | // No need to save live registers; it's taken care of by the |
| 667 | // entrypoint. Also, there is no need to update the stack mask, |
| 668 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 669 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 670 | DCHECK_NE(ref_reg, SP); |
| 671 | DCHECK_NE(ref_reg, LR); |
| 672 | DCHECK_NE(ref_reg, PC); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 673 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 674 | // as a temporary, it cannot be the entry point's input/output. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 675 | DCHECK_NE(ref_reg, IP); |
| 676 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 677 | // "Compact" slow path, saving two moves. |
| 678 | // |
| 679 | // Instead of using the standard runtime calling convention (input |
| 680 | // and output in R0): |
| 681 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 682 | // R0 <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 683 | // R0 <- ReadBarrierMark(R0) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 684 | // ref <- R0 |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 685 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 686 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 687 | // of a dedicated entrypoint: |
| 688 | // |
| 689 | // rX <- ReadBarrierMarkRegX(rX) |
| 690 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 691 | if (entrypoint_.IsValid()) { |
| 692 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 693 | __ blx(entrypoint_.AsRegister<Register>()); |
| 694 | } else { |
| 695 | int32_t entry_point_offset = |
| 696 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 697 | // This runtime call does not require a stack map. |
| 698 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 699 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 700 | __ b(GetExitLabel()); |
| 701 | } |
| 702 | |
| 703 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 704 | // The location (register) of the marked object reference. |
| 705 | const Location ref_; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 706 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 707 | // The location of the entrypoint if already loaded. |
| 708 | const Location entrypoint_; |
| 709 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 710 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 711 | }; |
| 712 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 713 | // Slow path marking an object reference `ref` during a read barrier, |
| 714 | // and if needed, atomically updating the field `obj.field` in the |
| 715 | // object `obj` holding this reference after marking (contrary to |
| 716 | // ReadBarrierMarkSlowPathARM above, which never tries to update |
| 717 | // `obj.field`). |
| 718 | // |
| 719 | // This means that after the execution of this slow path, both `ref` |
| 720 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 721 | // hold the same to-space reference (unless another thread installed |
| 722 | // another object reference (different from `ref`) in `obj.field`). |
| 723 | class ReadBarrierMarkAndUpdateFieldSlowPathARM : public SlowPathCodeARM { |
| 724 | public: |
| 725 | ReadBarrierMarkAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 726 | Location ref, |
| 727 | Register obj, |
| 728 | Location field_offset, |
| 729 | Register temp1, |
| 730 | Register temp2) |
| 731 | : SlowPathCodeARM(instruction), |
| 732 | ref_(ref), |
| 733 | obj_(obj), |
| 734 | field_offset_(field_offset), |
| 735 | temp1_(temp1), |
| 736 | temp2_(temp2) { |
| 737 | DCHECK(kEmitCompilerReadBarrier); |
| 738 | } |
| 739 | |
| 740 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkAndUpdateFieldSlowPathARM"; } |
| 741 | |
| 742 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 743 | LocationSummary* locations = instruction_->GetLocations(); |
| 744 | Register ref_reg = ref_.AsRegister<Register>(); |
| 745 | DCHECK(locations->CanCall()); |
| 746 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 747 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 748 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 749 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 750 | << instruction_->DebugName(); |
| 751 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 752 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 753 | DCHECK(field_offset_.IsRegisterPair()) << field_offset_; |
| 754 | |
| 755 | __ Bind(GetEntryLabel()); |
| 756 | |
| 757 | // Save the old reference. |
| 758 | // Note that we cannot use IP to save the old reference, as IP is |
| 759 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 760 | // need the old reference after the call to that entry point. |
| 761 | DCHECK_NE(temp1_, IP); |
| 762 | __ Mov(temp1_, ref_reg); |
| 763 | |
| 764 | // No need to save live registers; it's taken care of by the |
| 765 | // entrypoint. Also, there is no need to update the stack mask, |
| 766 | // as this runtime call will not trigger a garbage collection. |
| 767 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 768 | DCHECK_NE(ref_reg, SP); |
| 769 | DCHECK_NE(ref_reg, LR); |
| 770 | DCHECK_NE(ref_reg, PC); |
| 771 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 772 | // as a temporary, it cannot be the entry point's input/output. |
| 773 | DCHECK_NE(ref_reg, IP); |
| 774 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 775 | // "Compact" slow path, saving two moves. |
| 776 | // |
| 777 | // Instead of using the standard runtime calling convention (input |
| 778 | // and output in R0): |
| 779 | // |
| 780 | // R0 <- ref |
| 781 | // R0 <- ReadBarrierMark(R0) |
| 782 | // ref <- R0 |
| 783 | // |
| 784 | // we just use rX (the register containing `ref`) as input and output |
| 785 | // of a dedicated entrypoint: |
| 786 | // |
| 787 | // rX <- ReadBarrierMarkRegX(rX) |
| 788 | // |
| 789 | int32_t entry_point_offset = |
| 790 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 791 | // This runtime call does not require a stack map. |
| 792 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 793 | |
| 794 | // If the new reference is different from the old reference, |
| 795 | // update the field in the holder (`*(obj_ + field_offset_)`). |
| 796 | // |
| 797 | // Note that this field could also hold a different object, if |
| 798 | // another thread had concurrently changed it. In that case, the |
| 799 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 800 | // (CAS) operation below would abort the CAS, leaving the field |
| 801 | // as-is. |
| 802 | Label done; |
| 803 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
| 804 | __ b(&done, EQ); |
| 805 | |
| 806 | // Update the the holder's field atomically. This may fail if |
| 807 | // mutator updates before us, but it's OK. This is achieved |
| 808 | // using a strong compare-and-set (CAS) operation with relaxed |
| 809 | // memory synchronization ordering, where the expected value is |
| 810 | // the old reference and the desired value is the new reference. |
| 811 | |
| 812 | // Convenience aliases. |
| 813 | Register base = obj_; |
| 814 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 815 | // offset ("long offset"), of which only the low part contains |
| 816 | // data. |
| 817 | Register offset = field_offset_.AsRegisterPairLow<Register>(); |
| 818 | Register expected = temp1_; |
| 819 | Register value = ref_reg; |
| 820 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 821 | Register tmp = temp2_; // Value in memory. |
| 822 | |
| 823 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 824 | |
| 825 | if (kPoisonHeapReferences) { |
| 826 | __ PoisonHeapReference(expected); |
| 827 | if (value == expected) { |
| 828 | // Do not poison `value`, as it is the same register as |
| 829 | // `expected`, which has just been poisoned. |
| 830 | } else { |
| 831 | __ PoisonHeapReference(value); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | // do { |
| 836 | // tmp = [r_ptr] - expected; |
| 837 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 838 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 839 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 840 | __ Bind(&loop_head); |
| 841 | |
| 842 | __ ldrex(tmp, tmp_ptr); |
| 843 | |
| 844 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 845 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 846 | __ it(NE); |
| 847 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 848 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 849 | __ b(&exit_loop, NE); |
| 850 | |
| 851 | __ strex(tmp, value, tmp_ptr); |
| 852 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 853 | __ b(&loop_head, EQ); |
| 854 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 855 | __ Bind(&exit_loop); |
| 856 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 857 | if (kPoisonHeapReferences) { |
| 858 | __ UnpoisonHeapReference(expected); |
| 859 | if (value == expected) { |
| 860 | // Do not unpoison `value`, as it is the same register as |
| 861 | // `expected`, which has just been unpoisoned. |
| 862 | } else { |
| 863 | __ UnpoisonHeapReference(value); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | __ Bind(&done); |
| 868 | __ b(GetExitLabel()); |
| 869 | } |
| 870 | |
| 871 | private: |
| 872 | // The location (register) of the marked object reference. |
| 873 | const Location ref_; |
| 874 | // The register containing the object holding the marked object reference field. |
| 875 | const Register obj_; |
| 876 | // The location of the offset of the marked reference field within `obj_`. |
| 877 | Location field_offset_; |
| 878 | |
| 879 | const Register temp1_; |
| 880 | const Register temp2_; |
| 881 | |
| 882 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM); |
| 883 | }; |
| 884 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 885 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 886 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 887 | public: |
| 888 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 889 | Location out, |
| 890 | Location ref, |
| 891 | Location obj, |
| 892 | uint32_t offset, |
| 893 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 894 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 895 | out_(out), |
| 896 | ref_(ref), |
| 897 | obj_(obj), |
| 898 | offset_(offset), |
| 899 | index_(index) { |
| 900 | DCHECK(kEmitCompilerReadBarrier); |
| 901 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 902 | // has been overwritten by (or after) the heap object reference load |
| 903 | // to be instrumented, e.g.: |
| 904 | // |
| 905 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 906 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 907 | // |
| 908 | // In that case, we have lost the information about the original |
| 909 | // object, and the emitted read barrier cannot work properly. |
| 910 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 911 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 912 | } |
| 913 | |
| 914 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 915 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 916 | LocationSummary* locations = instruction_->GetLocations(); |
| 917 | Register reg_out = out_.AsRegister<Register>(); |
| 918 | DCHECK(locations->CanCall()); |
| 919 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 920 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 921 | instruction_->IsStaticFieldGet() || |
| 922 | instruction_->IsArrayGet() || |
| 923 | instruction_->IsInstanceOf() || |
| 924 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 925 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 926 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 927 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 928 | // The read barrier instrumentation of object ArrayGet |
| 929 | // instructions does not support the HIntermediateAddress |
| 930 | // instruction. |
| 931 | DCHECK(!(instruction_->IsArrayGet() && |
| 932 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 933 | |
| 934 | __ Bind(GetEntryLabel()); |
| 935 | SaveLiveRegisters(codegen, locations); |
| 936 | |
| 937 | // We may have to change the index's value, but as `index_` is a |
| 938 | // constant member (like other "inputs" of this slow path), |
| 939 | // introduce a copy of it, `index`. |
| 940 | Location index = index_; |
| 941 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 942 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 943 | if (instruction_->IsArrayGet()) { |
| 944 | // Compute the actual memory offset and store it in `index`. |
| 945 | Register index_reg = index_.AsRegister<Register>(); |
| 946 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 947 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 948 | // We are about to change the value of `index_reg` (see the |
| 949 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 950 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 951 | // not been saved by the previous call to |
| 952 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 953 | // callee-save register -- |
| 954 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 955 | // callee-save registers, as it has been designed with the |
| 956 | // assumption that callee-save registers are supposed to be |
| 957 | // handled by the called function. So, as a callee-save |
| 958 | // register, `index_reg` _would_ eventually be saved onto |
| 959 | // the stack, but it would be too late: we would have |
| 960 | // changed its value earlier. Therefore, we manually save |
| 961 | // it here into another freely available register, |
| 962 | // `free_reg`, chosen of course among the caller-save |
| 963 | // registers (as a callee-save `free_reg` register would |
| 964 | // exhibit the same problem). |
| 965 | // |
| 966 | // Note we could have requested a temporary register from |
| 967 | // the register allocator instead; but we prefer not to, as |
| 968 | // this is a slow path, and we know we can find a |
| 969 | // caller-save register that is available. |
| 970 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 971 | __ Mov(free_reg, index_reg); |
| 972 | index_reg = free_reg; |
| 973 | index = Location::RegisterLocation(index_reg); |
| 974 | } else { |
| 975 | // The initial register stored in `index_` has already been |
| 976 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 977 | // (as it is not a callee-save register), so we can freely |
| 978 | // use it. |
| 979 | } |
| 980 | // Shifting the index value contained in `index_reg` by the scale |
| 981 | // factor (2) cannot overflow in practice, as the runtime is |
| 982 | // unable to allocate object arrays with a size larger than |
| 983 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 984 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 985 | static_assert( |
| 986 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 987 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 988 | __ AddConstant(index_reg, index_reg, offset_); |
| 989 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 990 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 991 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 992 | // (as in the case of ArrayGet), as it is actually an offset |
| 993 | // to an object field within an object. |
| 994 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 995 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 996 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 997 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 998 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 999 | DCHECK_EQ(offset_, 0U); |
| 1000 | DCHECK(index_.IsRegisterPair()); |
| 1001 | // UnsafeGet's offset location is a register pair, the low |
| 1002 | // part contains the correct offset. |
| 1003 | index = index_.ToLow(); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | // We're moving two or three locations to locations that could |
| 1008 | // overlap, so we need a parallel move resolver. |
| 1009 | InvokeRuntimeCallingConvention calling_convention; |
| 1010 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1011 | parallel_move.AddMove(ref_, |
| 1012 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1013 | Primitive::kPrimNot, |
| 1014 | nullptr); |
| 1015 | parallel_move.AddMove(obj_, |
| 1016 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1017 | Primitive::kPrimNot, |
| 1018 | nullptr); |
| 1019 | if (index.IsValid()) { |
| 1020 | parallel_move.AddMove(index, |
| 1021 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1022 | Primitive::kPrimInt, |
| 1023 | nullptr); |
| 1024 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1025 | } else { |
| 1026 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1027 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1028 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1029 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1030 | CheckEntrypointTypes< |
| 1031 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1032 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1033 | |
| 1034 | RestoreLiveRegisters(codegen, locations); |
| 1035 | __ b(GetExitLabel()); |
| 1036 | } |
| 1037 | |
| 1038 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1039 | |
| 1040 | private: |
| 1041 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1042 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1043 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1044 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1045 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1046 | return static_cast<Register>(i); |
| 1047 | } |
| 1048 | } |
| 1049 | // We shall never fail to find a free caller-save register, as |
| 1050 | // there are more than two core caller-save registers on ARM |
| 1051 | // (meaning it is possible to find one which is different from |
| 1052 | // `ref` and `obj`). |
| 1053 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1054 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1055 | UNREACHABLE(); |
| 1056 | } |
| 1057 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1058 | const Location out_; |
| 1059 | const Location ref_; |
| 1060 | const Location obj_; |
| 1061 | const uint32_t offset_; |
| 1062 | // An additional location containing an index to an array. |
| 1063 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1064 | // UnsafeGetObjectVolatile intrinsics. |
| 1065 | const Location index_; |
| 1066 | |
| 1067 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1068 | }; |
| 1069 | |
| 1070 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1071 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1072 | public: |
| 1073 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1074 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1075 | DCHECK(kEmitCompilerReadBarrier); |
| 1076 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1077 | |
| 1078 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1079 | LocationSummary* locations = instruction_->GetLocations(); |
| 1080 | Register reg_out = out_.AsRegister<Register>(); |
| 1081 | DCHECK(locations->CanCall()); |
| 1082 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1083 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1084 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1085 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1086 | |
| 1087 | __ Bind(GetEntryLabel()); |
| 1088 | SaveLiveRegisters(codegen, locations); |
| 1089 | |
| 1090 | InvokeRuntimeCallingConvention calling_convention; |
| 1091 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1092 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1093 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1094 | instruction_, |
| 1095 | instruction_->GetDexPc(), |
| 1096 | this); |
| 1097 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1098 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1099 | |
| 1100 | RestoreLiveRegisters(codegen, locations); |
| 1101 | __ b(GetExitLabel()); |
| 1102 | } |
| 1103 | |
| 1104 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1105 | |
| 1106 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1107 | const Location out_; |
| 1108 | const Location root_; |
| 1109 | |
| 1110 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1111 | }; |
| 1112 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1113 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 1114 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1115 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1116 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1117 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1118 | switch (cond) { |
| 1119 | case kCondEQ: return EQ; |
| 1120 | case kCondNE: return NE; |
| 1121 | case kCondLT: return LT; |
| 1122 | case kCondLE: return LE; |
| 1123 | case kCondGT: return GT; |
| 1124 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1125 | case kCondB: return LO; |
| 1126 | case kCondBE: return LS; |
| 1127 | case kCondA: return HI; |
| 1128 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1129 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1130 | LOG(FATAL) << "Unreachable"; |
| 1131 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1134 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1135 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1136 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1137 | case kCondEQ: return EQ; |
| 1138 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1139 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1140 | case kCondLT: return LO; |
| 1141 | case kCondLE: return LS; |
| 1142 | case kCondGT: return HI; |
| 1143 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1144 | // Unsigned remain unchanged. |
| 1145 | case kCondB: return LO; |
| 1146 | case kCondBE: return LS; |
| 1147 | case kCondA: return HI; |
| 1148 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1149 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1150 | LOG(FATAL) << "Unreachable"; |
| 1151 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1154 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1155 | // The ARM condition codes can express all the necessary branches, see the |
| 1156 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1157 | // There is no dex instruction or HIR that would need the missing conditions |
| 1158 | // "equal or unordered" or "not equal". |
| 1159 | switch (cond) { |
| 1160 | case kCondEQ: return EQ; |
| 1161 | case kCondNE: return NE /* unordered */; |
| 1162 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1163 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1164 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1165 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1166 | default: |
| 1167 | LOG(FATAL) << "UNREACHABLE"; |
| 1168 | UNREACHABLE(); |
| 1169 | } |
| 1170 | } |
| 1171 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1172 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1173 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1177 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1180 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1181 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1182 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1183 | } |
| 1184 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1185 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1186 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1187 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1188 | } |
| 1189 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1190 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1191 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1192 | return kArmWordSize; |
| 1193 | } |
| 1194 | |
| 1195 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1196 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1197 | return kArmWordSize; |
| 1198 | } |
| 1199 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1200 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1201 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1202 | const CompilerOptions& compiler_options, |
| 1203 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1204 | : CodeGenerator(graph, |
| 1205 | kNumberOfCoreRegisters, |
| 1206 | kNumberOfSRegisters, |
| 1207 | kNumberOfRegisterPairs, |
| 1208 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1209 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1210 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1211 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1212 | compiler_options, |
| 1213 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1214 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1215 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1216 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1217 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1218 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1219 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1220 | uint32_literals_(std::less<uint32_t>(), |
| 1221 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1222 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1223 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1224 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1225 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1226 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1227 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1228 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1229 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1230 | boot_image_address_patches_(std::less<uint32_t>(), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1231 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1232 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1233 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1234 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1235 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1236 | // Always save the LR register to mimic Quick. |
| 1237 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1240 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1241 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1242 | __ FinalizeCode(); |
| 1243 | |
| 1244 | // Adjust native pc offsets in stack maps. |
| 1245 | 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] | 1246 | uint32_t old_position = |
| 1247 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1248 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1249 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1250 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1251 | // Adjust pc offsets for the disassembly information. |
| 1252 | if (disasm_info_ != nullptr) { |
| 1253 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1254 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1255 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1256 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1257 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1258 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1259 | } |
| 1260 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1261 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1262 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1263 | } |
| 1264 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1265 | |
| 1266 | CodeGenerator::Finalize(allocator); |
| 1267 | } |
| 1268 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1269 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1270 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1271 | blocked_core_registers_[SP] = true; |
| 1272 | blocked_core_registers_[LR] = true; |
| 1273 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1274 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1275 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1276 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1277 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1278 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1279 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1280 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1281 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 1282 | // Stubs do not save callee-save floating point registers. If the graph |
| 1283 | // is debuggable, we need to deal with these registers differently. For |
| 1284 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1285 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1286 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 1287 | } |
| 1288 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1291 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1292 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1293 | assembler_(codegen->GetAssembler()), |
| 1294 | codegen_(codegen) {} |
| 1295 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1296 | void CodeGeneratorARM::ComputeSpillMask() { |
| 1297 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 1298 | 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] | 1299 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 1300 | // restore another arbitrary register. |
| 1301 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1302 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 1303 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 1304 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 1305 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 1306 | // but in the range. |
| 1307 | if (fpu_spill_mask_ != 0) { |
| 1308 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 1309 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 1310 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 1311 | fpu_spill_mask_ |= (1 << i); |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1316 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1317 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1321 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1324 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1325 | bool skip_overflow_check = |
| 1326 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1327 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1328 | __ Bind(&frame_entry_label_); |
| 1329 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1330 | if (HasEmptyFrame()) { |
| 1331 | return; |
| 1332 | } |
| 1333 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1334 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1335 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 1336 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 1337 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1340 | __ PushList(core_spill_mask_); |
| 1341 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 1342 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1343 | if (fpu_spill_mask_ != 0) { |
| 1344 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1345 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1346 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1347 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1348 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1349 | |
| 1350 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1351 | // Initialize should_deoptimize flag to 0. |
| 1352 | __ mov(IP, ShifterOperand(0)); |
| 1353 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 1354 | } |
| 1355 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1356 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1357 | __ AddConstant(SP, -adjust); |
| 1358 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1359 | |
| 1360 | // Save the current method if we need it. Note that we do not |
| 1361 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1362 | // in the SSA graph. |
| 1363 | if (RequiresCurrentMethod()) { |
| 1364 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 1365 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1369 | if (HasEmptyFrame()) { |
| 1370 | __ bx(LR); |
| 1371 | return; |
| 1372 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1373 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1374 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 1375 | __ AddConstant(SP, adjust); |
| 1376 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1377 | if (fpu_spill_mask_ != 0) { |
| 1378 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 1379 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1380 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1381 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1382 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1383 | // Pop LR into PC to return. |
| 1384 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 1385 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 1386 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1387 | __ cfi().RestoreState(); |
| 1388 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1391 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 1392 | Label* label = GetLabelOf(block); |
| 1393 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1396 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1397 | switch (type) { |
| 1398 | case Primitive::kPrimBoolean: |
| 1399 | case Primitive::kPrimByte: |
| 1400 | case Primitive::kPrimChar: |
| 1401 | case Primitive::kPrimShort: |
| 1402 | case Primitive::kPrimInt: |
| 1403 | case Primitive::kPrimNot: { |
| 1404 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1405 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1406 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1407 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1408 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1409 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1410 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1411 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1412 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1413 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1414 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1415 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1416 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1417 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1418 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1419 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 1420 | // Skip R1, and use R2_R3 instead. |
| 1421 | gp_index_++; |
| 1422 | index++; |
| 1423 | } |
| 1424 | } |
| 1425 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 1426 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1427 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1428 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 1429 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 1430 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1431 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1432 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | case Primitive::kPrimFloat: { |
| 1437 | uint32_t stack_index = stack_index_++; |
| 1438 | if (float_index_ % 2 == 0) { |
| 1439 | float_index_ = std::max(double_index_, float_index_); |
| 1440 | } |
| 1441 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 1442 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 1443 | } else { |
| 1444 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | case Primitive::kPrimDouble: { |
| 1449 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 1450 | uint32_t stack_index = stack_index_; |
| 1451 | stack_index_ += 2; |
| 1452 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 1453 | uint32_t index = double_index_; |
| 1454 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1455 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1456 | calling_convention.GetFpuRegisterAt(index), |
| 1457 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1458 | DCHECK(ExpectedPairLayout(result)); |
| 1459 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1460 | } else { |
| 1461 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1462 | } |
| 1463 | } |
| 1464 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1465 | case Primitive::kPrimVoid: |
| 1466 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1467 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1468 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1469 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1470 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1471 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1472 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1473 | switch (type) { |
| 1474 | case Primitive::kPrimBoolean: |
| 1475 | case Primitive::kPrimByte: |
| 1476 | case Primitive::kPrimChar: |
| 1477 | case Primitive::kPrimShort: |
| 1478 | case Primitive::kPrimInt: |
| 1479 | case Primitive::kPrimNot: { |
| 1480 | return Location::RegisterLocation(R0); |
| 1481 | } |
| 1482 | |
| 1483 | case Primitive::kPrimFloat: { |
| 1484 | return Location::FpuRegisterLocation(S0); |
| 1485 | } |
| 1486 | |
| 1487 | case Primitive::kPrimLong: { |
| 1488 | return Location::RegisterPairLocation(R0, R1); |
| 1489 | } |
| 1490 | |
| 1491 | case Primitive::kPrimDouble: { |
| 1492 | return Location::FpuRegisterPairLocation(S0, S1); |
| 1493 | } |
| 1494 | |
| 1495 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1496 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1497 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1498 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1499 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1502 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 1503 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1504 | } |
| 1505 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1506 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 1507 | if (source.Equals(destination)) { |
| 1508 | return; |
| 1509 | } |
| 1510 | if (destination.IsRegister()) { |
| 1511 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1512 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1513 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1514 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1515 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1516 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1517 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1518 | } else if (destination.IsFpuRegister()) { |
| 1519 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1520 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1521 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1522 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1523 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1524 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1525 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1526 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1527 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1528 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1529 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1530 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1531 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1532 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1533 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1534 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 1535 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 1541 | if (source.Equals(destination)) { |
| 1542 | return; |
| 1543 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1544 | if (destination.IsRegisterPair()) { |
| 1545 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1546 | EmitParallelMoves( |
| 1547 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1548 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1549 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1550 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1551 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1552 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1553 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1554 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1555 | } else if (source.IsFpuRegisterPair()) { |
| 1556 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 1557 | destination.AsRegisterPairHigh<Register>(), |
| 1558 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1559 | } else { |
| 1560 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 1561 | DCHECK(ExpectedPairLayout(destination)); |
| 1562 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 1563 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1564 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1565 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1566 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1567 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1568 | SP, |
| 1569 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1570 | } else if (source.IsRegisterPair()) { |
| 1571 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 1572 | source.AsRegisterPairLow<Register>(), |
| 1573 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1574 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1575 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1576 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1577 | } else { |
| 1578 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1579 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1580 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1581 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 1582 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1583 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 1584 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1585 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1586 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1587 | SP, destination.GetStackIndex()); |
| 1588 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 1589 | } else if (source.IsFpuRegisterPair()) { |
| 1590 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 1591 | SP, |
| 1592 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1593 | } else { |
| 1594 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1595 | EmitParallelMoves( |
| 1596 | Location::StackSlot(source.GetStackIndex()), |
| 1597 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1598 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1599 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1600 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 1601 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1606 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 1607 | DCHECK(location.IsRegister()); |
| 1608 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 1609 | } |
| 1610 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1611 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1612 | HParallelMove move(GetGraph()->GetArena()); |
| 1613 | move.AddMove(src, dst, dst_type, nullptr); |
| 1614 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1618 | if (location.IsRegister()) { |
| 1619 | locations->AddTemp(location); |
| 1620 | } else if (location.IsRegisterPair()) { |
| 1621 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1622 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1623 | } else { |
| 1624 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1625 | } |
| 1626 | } |
| 1627 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1628 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1629 | HInstruction* instruction, |
| 1630 | uint32_t dex_pc, |
| 1631 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1632 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1633 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 1634 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1635 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1636 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1639 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1640 | HInstruction* instruction, |
| 1641 | SlowPathCode* slow_path) { |
| 1642 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1643 | GenerateInvokeRuntime(entry_point_offset); |
| 1644 | } |
| 1645 | |
| 1646 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1647 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 1648 | __ blx(LR); |
| 1649 | } |
| 1650 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1651 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1652 | DCHECK(!successor->IsExitBlock()); |
| 1653 | |
| 1654 | HBasicBlock* block = got->GetBlock(); |
| 1655 | HInstruction* previous = got->GetPrevious(); |
| 1656 | |
| 1657 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1658 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1659 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 1660 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1661 | return; |
| 1662 | } |
| 1663 | |
| 1664 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1665 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1666 | } |
| 1667 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1668 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1672 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 1673 | got->SetLocations(nullptr); |
| 1674 | } |
| 1675 | |
| 1676 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 1677 | HandleGoto(got, got->GetSuccessor()); |
| 1678 | } |
| 1679 | |
| 1680 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1681 | try_boundary->SetLocations(nullptr); |
| 1682 | } |
| 1683 | |
| 1684 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1685 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1686 | if (!successor->IsExitBlock()) { |
| 1687 | HandleGoto(try_boundary, successor); |
| 1688 | } |
| 1689 | } |
| 1690 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1691 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1692 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1695 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1698 | void InstructionCodeGeneratorARM::GenerateVcmp(HInstruction* instruction) { |
| 1699 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1700 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1701 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1702 | if (rhs_loc.IsConstant()) { |
| 1703 | // 0.0 is the only immediate that can be encoded directly in |
| 1704 | // a VCMP instruction. |
| 1705 | // |
| 1706 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1707 | // specify that in a floating-point comparison, positive zero |
| 1708 | // and negative zero are considered equal, so we can use the |
| 1709 | // literal 0.0 for both cases here. |
| 1710 | // |
| 1711 | // Note however that some methods (Float.equal, Float.compare, |
| 1712 | // Float.compareTo, Double.equal, Double.compare, |
| 1713 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1714 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1715 | // -0.0. So if we ever translate calls to these methods into a |
| 1716 | // HCompare instruction, we must handle the -0.0 case with |
| 1717 | // care here. |
| 1718 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1719 | if (type == Primitive::kPrimFloat) { |
| 1720 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1721 | } else { |
| 1722 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1723 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1724 | } |
| 1725 | } else { |
| 1726 | if (type == Primitive::kPrimFloat) { |
| 1727 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1728 | } else { |
| 1729 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1730 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1731 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1736 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 1737 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1738 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1739 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1740 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 1744 | Label* true_label, |
| 1745 | Label* false_label) { |
| 1746 | LocationSummary* locations = cond->GetLocations(); |
| 1747 | Location left = locations->InAt(0); |
| 1748 | Location right = locations->InAt(1); |
| 1749 | IfCondition if_cond = cond->GetCondition(); |
| 1750 | |
| 1751 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1752 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 1753 | IfCondition true_high_cond = if_cond; |
| 1754 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1755 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1756 | |
| 1757 | // Set the conditions for the test, remembering that == needs to be |
| 1758 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1759 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1760 | switch (if_cond) { |
| 1761 | case kCondEQ: |
| 1762 | case kCondNE: |
| 1763 | // Nothing to do. |
| 1764 | break; |
| 1765 | case kCondLT: |
| 1766 | false_high_cond = kCondGT; |
| 1767 | break; |
| 1768 | case kCondLE: |
| 1769 | true_high_cond = kCondLT; |
| 1770 | break; |
| 1771 | case kCondGT: |
| 1772 | false_high_cond = kCondLT; |
| 1773 | break; |
| 1774 | case kCondGE: |
| 1775 | true_high_cond = kCondGT; |
| 1776 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1777 | case kCondB: |
| 1778 | false_high_cond = kCondA; |
| 1779 | break; |
| 1780 | case kCondBE: |
| 1781 | true_high_cond = kCondB; |
| 1782 | break; |
| 1783 | case kCondA: |
| 1784 | false_high_cond = kCondB; |
| 1785 | break; |
| 1786 | case kCondAE: |
| 1787 | true_high_cond = kCondA; |
| 1788 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1789 | } |
| 1790 | if (right.IsConstant()) { |
| 1791 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1792 | int32_t val_low = Low32Bits(value); |
| 1793 | int32_t val_high = High32Bits(value); |
| 1794 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1795 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1796 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1798 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1800 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1801 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1802 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1803 | } |
| 1804 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1805 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1806 | } else { |
| 1807 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 1808 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 1809 | |
| 1810 | __ cmp(left_high, ShifterOperand(right_high)); |
| 1811 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1812 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1813 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1814 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1815 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1816 | __ b(true_label, ARMCondition(true_high_cond)); |
| 1817 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1818 | } |
| 1819 | // Must be equal high, so compare the lows. |
| 1820 | __ cmp(left_low, ShifterOperand(right_low)); |
| 1821 | } |
| 1822 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1824 | __ b(true_label, final_condition); |
| 1825 | } |
| 1826 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1827 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 1828 | Label* true_target_in, |
| 1829 | Label* false_target_in) { |
| 1830 | // Generated branching requires both targets to be explicit. If either of the |
| 1831 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1832 | Label fallthrough_target; |
| 1833 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1834 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1835 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1836 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1837 | switch (type) { |
| 1838 | case Primitive::kPrimLong: |
| 1839 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1840 | break; |
| 1841 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1842 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 1843 | GenerateVcmp(condition); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1844 | GenerateFPJumps(condition, true_target, false_target); |
| 1845 | break; |
| 1846 | default: |
| 1847 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1848 | } |
| 1849 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1850 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1851 | __ b(false_target); |
| 1852 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1853 | |
| 1854 | if (fallthrough_target.IsLinked()) { |
| 1855 | __ Bind(&fallthrough_target); |
| 1856 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1859 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1860 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1861 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1862 | Label* false_target) { |
| 1863 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1864 | |
| 1865 | if (true_target == nullptr && false_target == nullptr) { |
| 1866 | // Nothing to do. The code always falls through. |
| 1867 | return; |
| 1868 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1869 | // Constant condition, statically compared against "true" (integer value 1). |
| 1870 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1871 | if (true_target != nullptr) { |
| 1872 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1873 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1874 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1875 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1876 | if (false_target != nullptr) { |
| 1877 | __ b(false_target); |
| 1878 | } |
| 1879 | } |
| 1880 | return; |
| 1881 | } |
| 1882 | |
| 1883 | // The following code generates these patterns: |
| 1884 | // (1) true_target == nullptr && false_target != nullptr |
| 1885 | // - opposite condition true => branch to false_target |
| 1886 | // (2) true_target != nullptr && false_target == nullptr |
| 1887 | // - condition true => branch to true_target |
| 1888 | // (3) true_target != nullptr && false_target != nullptr |
| 1889 | // - condition true => branch to true_target |
| 1890 | // - branch to false_target |
| 1891 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1892 | // Condition has been materialized, compare the output to 0. |
| 1893 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 1894 | DCHECK(cond_val.IsRegister()); |
| 1895 | if (true_target == nullptr) { |
| 1896 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 1897 | } else { |
| 1898 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1899 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1900 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1901 | // Condition has not been materialized. Use its inputs as the comparison and |
| 1902 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1903 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1904 | |
| 1905 | // If this is a long or FP comparison that has been folded into |
| 1906 | // the HCondition, generate the comparison directly. |
| 1907 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1908 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1909 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1910 | return; |
| 1911 | } |
| 1912 | |
| 1913 | LocationSummary* locations = cond->GetLocations(); |
| 1914 | DCHECK(locations->InAt(0).IsRegister()); |
| 1915 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 1916 | Location right = locations->InAt(1); |
| 1917 | if (right.IsRegister()) { |
| 1918 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1919 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1920 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 1921 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1922 | } |
| 1923 | if (true_target == nullptr) { |
| 1924 | __ b(false_target, ARMCondition(condition->GetOppositeCondition())); |
| 1925 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1926 | __ b(true_target, ARMCondition(condition->GetCondition())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1927 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1928 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1929 | |
| 1930 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1931 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1932 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1933 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1934 | } |
| 1935 | } |
| 1936 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1937 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1938 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1939 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1940 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1945 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1946 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1947 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1948 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1949 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1950 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1951 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1955 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1956 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1957 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1958 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1964 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1965 | GenerateTestAndBranch(deoptimize, |
| 1966 | /* condition_input_index */ 0, |
| 1967 | slow_path->GetEntryLabel(), |
| 1968 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1969 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1970 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1971 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1972 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1973 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1974 | locations->SetOut(Location::RequiresRegister()); |
| 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1978 | __ LoadFromOffset(kLoadWord, |
| 1979 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 1980 | SP, |
| 1981 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 1982 | } |
| 1983 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1984 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 1985 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1986 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1987 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1988 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1989 | } else { |
| 1990 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1991 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1992 | } |
| 1993 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1994 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1995 | } |
| 1996 | locations->SetOut(Location::SameAsFirstInput()); |
| 1997 | } |
| 1998 | |
| 1999 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
| 2000 | LocationSummary* locations = select->GetLocations(); |
| 2001 | Label false_target; |
| 2002 | GenerateTestAndBranch(select, |
| 2003 | /* condition_input_index */ 2, |
| 2004 | /* true_target */ nullptr, |
| 2005 | &false_target); |
| 2006 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2007 | __ Bind(&false_target); |
| 2008 | } |
| 2009 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2010 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2011 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2012 | } |
| 2013 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2014 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2015 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void CodeGeneratorARM::GenerateNop() { |
| 2019 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2022 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2023 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2024 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2025 | // Handle the long/FP comparisons made in instruction simplification. |
| 2026 | switch (cond->InputAt(0)->GetType()) { |
| 2027 | case Primitive::kPrimLong: |
| 2028 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2029 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2030 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2031 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2032 | } |
| 2033 | break; |
| 2034 | |
| 2035 | case Primitive::kPrimFloat: |
| 2036 | case Primitive::kPrimDouble: |
| 2037 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2038 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2039 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2040 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2041 | } |
| 2042 | break; |
| 2043 | |
| 2044 | default: |
| 2045 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2046 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2047 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2048 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2049 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2050 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2053 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2054 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2055 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2056 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2057 | |
| 2058 | LocationSummary* locations = cond->GetLocations(); |
| 2059 | Location left = locations->InAt(0); |
| 2060 | Location right = locations->InAt(1); |
| 2061 | Register out = locations->Out().AsRegister<Register>(); |
| 2062 | Label true_label, false_label; |
| 2063 | |
| 2064 | switch (cond->InputAt(0)->GetType()) { |
| 2065 | default: { |
| 2066 | // Integer case. |
| 2067 | if (right.IsRegister()) { |
| 2068 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2069 | } else { |
| 2070 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2071 | __ CmpConstant(left.AsRegister<Register>(), |
| 2072 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2073 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2074 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2075 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2076 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2077 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2078 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2079 | return; |
| 2080 | } |
| 2081 | case Primitive::kPrimLong: |
| 2082 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2083 | break; |
| 2084 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2085 | case Primitive::kPrimDouble: |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2086 | GenerateVcmp(cond); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2087 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2088 | break; |
| 2089 | } |
| 2090 | |
| 2091 | // Convert the jumps into the result. |
| 2092 | Label done_label; |
| 2093 | |
| 2094 | // False case: result = 0. |
| 2095 | __ Bind(&false_label); |
| 2096 | __ LoadImmediate(out, 0); |
| 2097 | __ b(&done_label); |
| 2098 | |
| 2099 | // True case: result = 1. |
| 2100 | __ Bind(&true_label); |
| 2101 | __ LoadImmediate(out, 1); |
| 2102 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2106 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2110 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2114 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2118 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2122 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2126 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2130 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2134 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2138 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2142 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2146 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2150 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2153 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2154 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2158 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2162 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2166 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2170 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2174 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2178 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2182 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2185 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2186 | LocationSummary* locations = |
| 2187 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2188 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2191 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2192 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2195 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 2196 | LocationSummary* locations = |
| 2197 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2198 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2199 | } |
| 2200 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2201 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2202 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2205 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2206 | LocationSummary* locations = |
| 2207 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2208 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2211 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2212 | // Will be generated at use site. |
| 2213 | } |
| 2214 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2215 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 2216 | LocationSummary* locations = |
| 2217 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2218 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2219 | } |
| 2220 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2221 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2222 | // Will be generated at use site. |
| 2223 | } |
| 2224 | |
| 2225 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2226 | LocationSummary* locations = |
| 2227 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2228 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2229 | } |
| 2230 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2231 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2232 | // Will be generated at use site. |
| 2233 | } |
| 2234 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2235 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2236 | memory_barrier->SetLocations(nullptr); |
| 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 2240 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2243 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2244 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2247 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2248 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2251 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2252 | LocationSummary* locations = |
| 2253 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2254 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2257 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2258 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2261 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2262 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2263 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2264 | // the method_idx. |
| 2265 | HandleInvoke(invoke); |
| 2266 | } |
| 2267 | |
| 2268 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2269 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2270 | } |
| 2271 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2272 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2273 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2274 | // art::PrepareForRegisterAllocation. |
| 2275 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2276 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2277 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2278 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2279 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 2280 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 2281 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2282 | return; |
| 2283 | } |
| 2284 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2285 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2286 | |
| 2287 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2288 | if (invoke->HasPcRelativeDexCache()) { |
| 2289 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 2290 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2291 | } |
| 2292 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2293 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 2294 | if (invoke->GetLocations()->Intrinsified()) { |
| 2295 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 2296 | intrinsic.Dispatch(invoke); |
| 2297 | return true; |
| 2298 | } |
| 2299 | return false; |
| 2300 | } |
| 2301 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2302 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2303 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2304 | // art::PrepareForRegisterAllocation. |
| 2305 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2306 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2307 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2308 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2309 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2310 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2311 | LocationSummary* locations = invoke->GetLocations(); |
| 2312 | codegen_->GenerateStaticOrDirectCall( |
| 2313 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2314 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2317 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2318 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2319 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2322 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 2323 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2324 | if (intrinsic.TryDispatch(invoke)) { |
| 2325 | return; |
| 2326 | } |
| 2327 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2328 | HandleInvoke(invoke); |
| 2329 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2330 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2331 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2332 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2333 | return; |
| 2334 | } |
| 2335 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2336 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2337 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2338 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2339 | } |
| 2340 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2341 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2342 | HandleInvoke(invoke); |
| 2343 | // Add the hidden argument. |
| 2344 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 2345 | } |
| 2346 | |
| 2347 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2348 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2349 | LocationSummary* locations = invoke->GetLocations(); |
| 2350 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2351 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2352 | Location receiver = locations->InAt(0); |
| 2353 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2354 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2355 | // Set the hidden argument. This is safe to do this here, as R12 |
| 2356 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 2357 | DCHECK_EQ(R12, hidden_reg); |
| 2358 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2359 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2360 | if (receiver.IsStackSlot()) { |
| 2361 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2362 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2363 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 2364 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2365 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2366 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2367 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2368 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2369 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2370 | // emit a read barrier for the previous class reference load. |
| 2371 | // However this is not required in practice, as this is an |
| 2372 | // intermediate/temporary reference and because the current |
| 2373 | // concurrent copying collector keeps the from-space memory |
| 2374 | // intact/accessible until the end of the marking phase (the |
| 2375 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2376 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2377 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 2378 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 2379 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2380 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2381 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2382 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2383 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2384 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2385 | // LR = temp->GetEntryPoint(); |
| 2386 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 2387 | // LR(); |
| 2388 | __ blx(LR); |
| 2389 | DCHECK(!codegen_->IsLeafMethod()); |
| 2390 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2391 | } |
| 2392 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2393 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2394 | HandleInvoke(invoke); |
| 2395 | } |
| 2396 | |
| 2397 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2398 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2399 | } |
| 2400 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2401 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 2402 | LocationSummary* locations = |
| 2403 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2404 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2406 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2407 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2408 | break; |
| 2409 | } |
| 2410 | case Primitive::kPrimLong: { |
| 2411 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2412 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2413 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2414 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2415 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2416 | case Primitive::kPrimFloat: |
| 2417 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2418 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2419 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2420 | break; |
| 2421 | |
| 2422 | default: |
| 2423 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 2428 | LocationSummary* locations = neg->GetLocations(); |
| 2429 | Location out = locations->Out(); |
| 2430 | Location in = locations->InAt(0); |
| 2431 | switch (neg->GetResultType()) { |
| 2432 | case Primitive::kPrimInt: |
| 2433 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2434 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2435 | break; |
| 2436 | |
| 2437 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2438 | DCHECK(in.IsRegisterPair()); |
| 2439 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 2440 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 2441 | in.AsRegisterPairLow<Register>(), |
| 2442 | ShifterOperand(0)); |
| 2443 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 2444 | // instruction here, as it does not exist in the Thumb-2 |
| 2445 | // instruction set. We use the following approach |
| 2446 | // using SBC and SUB instead. |
| 2447 | // |
| 2448 | // out.hi = -C |
| 2449 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 2450 | out.AsRegisterPairHigh<Register>(), |
| 2451 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 2452 | // out.hi = out.hi - in.hi |
| 2453 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 2454 | out.AsRegisterPairHigh<Register>(), |
| 2455 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 2456 | break; |
| 2457 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2459 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2460 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2463 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2464 | DCHECK(in.IsFpuRegisterPair()); |
| 2465 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2466 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2467 | break; |
| 2468 | |
| 2469 | default: |
| 2470 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2471 | } |
| 2472 | } |
| 2473 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2474 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2475 | Primitive::Type result_type = conversion->GetResultType(); |
| 2476 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2477 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2478 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2479 | // The float-to-long, double-to-long and long-to-float type conversions |
| 2480 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2481 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2482 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2483 | && result_type == Primitive::kPrimLong) |
| 2484 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2485 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2486 | : LocationSummary::kNoCall; |
| 2487 | LocationSummary* locations = |
| 2488 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2489 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2490 | // The Java language does not allow treating boolean as an integral type but |
| 2491 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2492 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2493 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimByte: |
| 2495 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimLong: |
| 2497 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimBoolean: |
| 2499 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2500 | case Primitive::kPrimShort: |
| 2501 | case Primitive::kPrimInt: |
| 2502 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2503 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2505 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2506 | break; |
| 2507 | |
| 2508 | default: |
| 2509 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2510 | << " to " << result_type; |
| 2511 | } |
| 2512 | break; |
| 2513 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimShort: |
| 2515 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimLong: |
| 2517 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2518 | case Primitive::kPrimBoolean: |
| 2519 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimByte: |
| 2521 | case Primitive::kPrimInt: |
| 2522 | case Primitive::kPrimChar: |
| 2523 | // Processing a Dex `int-to-short' instruction. |
| 2524 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2525 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2526 | break; |
| 2527 | |
| 2528 | default: |
| 2529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2530 | << " to " << result_type; |
| 2531 | } |
| 2532 | break; |
| 2533 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimInt: |
| 2535 | switch (input_type) { |
| 2536 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2537 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2538 | locations->SetInAt(0, Location::Any()); |
| 2539 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2540 | break; |
| 2541 | |
| 2542 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2543 | // Processing a Dex `float-to-int' instruction. |
| 2544 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2545 | locations->SetOut(Location::RequiresRegister()); |
| 2546 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2547 | break; |
| 2548 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2549 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2550 | // Processing a Dex `double-to-int' instruction. |
| 2551 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2552 | locations->SetOut(Location::RequiresRegister()); |
| 2553 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | default: |
| 2557 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2558 | << " to " << result_type; |
| 2559 | } |
| 2560 | break; |
| 2561 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimLong: |
| 2563 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimBoolean: |
| 2565 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2566 | case Primitive::kPrimByte: |
| 2567 | case Primitive::kPrimShort: |
| 2568 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2570 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2571 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2572 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2573 | break; |
| 2574 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimFloat: { |
| 2576 | // Processing a Dex `float-to-long' instruction. |
| 2577 | InvokeRuntimeCallingConvention calling_convention; |
| 2578 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 2579 | calling_convention.GetFpuRegisterAt(0))); |
| 2580 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 2581 | break; |
| 2582 | } |
| 2583 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2584 | case Primitive::kPrimDouble: { |
| 2585 | // Processing a Dex `double-to-long' instruction. |
| 2586 | InvokeRuntimeCallingConvention calling_convention; |
| 2587 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 2588 | calling_convention.GetFpuRegisterAt(0), |
| 2589 | calling_convention.GetFpuRegisterAt(1))); |
| 2590 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2591 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2592 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2593 | |
| 2594 | default: |
| 2595 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2596 | << " to " << result_type; |
| 2597 | } |
| 2598 | break; |
| 2599 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimChar: |
| 2601 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimLong: |
| 2603 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimBoolean: |
| 2605 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimByte: |
| 2607 | case Primitive::kPrimShort: |
| 2608 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2609 | // Processing a Dex `int-to-char' instruction. |
| 2610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2611 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2612 | break; |
| 2613 | |
| 2614 | default: |
| 2615 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2616 | << " to " << result_type; |
| 2617 | } |
| 2618 | break; |
| 2619 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2620 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2621 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimBoolean: |
| 2623 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimByte: |
| 2625 | case Primitive::kPrimShort: |
| 2626 | case Primitive::kPrimInt: |
| 2627 | case Primitive::kPrimChar: |
| 2628 | // Processing a Dex `int-to-float' instruction. |
| 2629 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2630 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2631 | break; |
| 2632 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2633 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2634 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2635 | InvokeRuntimeCallingConvention calling_convention; |
| 2636 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2637 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2638 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2639 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2640 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2641 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2643 | // Processing a Dex `double-to-float' instruction. |
| 2644 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2645 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2646 | break; |
| 2647 | |
| 2648 | default: |
| 2649 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2650 | << " to " << result_type; |
| 2651 | }; |
| 2652 | break; |
| 2653 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2654 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2655 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2656 | case Primitive::kPrimBoolean: |
| 2657 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimByte: |
| 2659 | case Primitive::kPrimShort: |
| 2660 | case Primitive::kPrimInt: |
| 2661 | case Primitive::kPrimChar: |
| 2662 | // Processing a Dex `int-to-double' instruction. |
| 2663 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2664 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2665 | break; |
| 2666 | |
| 2667 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2668 | // Processing a Dex `long-to-double' instruction. |
| 2669 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2670 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2671 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2672 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2673 | break; |
| 2674 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2676 | // Processing a Dex `float-to-double' instruction. |
| 2677 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2678 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | break; |
| 2680 | |
| 2681 | default: |
| 2682 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2683 | << " to " << result_type; |
| 2684 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | |
| 2687 | default: |
| 2688 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2689 | << " to " << result_type; |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 2694 | LocationSummary* locations = conversion->GetLocations(); |
| 2695 | Location out = locations->Out(); |
| 2696 | Location in = locations->InAt(0); |
| 2697 | Primitive::Type result_type = conversion->GetResultType(); |
| 2698 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2699 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2700 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2701 | case Primitive::kPrimByte: |
| 2702 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2703 | case Primitive::kPrimLong: |
| 2704 | // Type conversion from long to byte is a result of code transformations. |
| 2705 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 2706 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2707 | case Primitive::kPrimBoolean: |
| 2708 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2709 | case Primitive::kPrimShort: |
| 2710 | case Primitive::kPrimInt: |
| 2711 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2712 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2713 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2714 | break; |
| 2715 | |
| 2716 | default: |
| 2717 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2718 | << " to " << result_type; |
| 2719 | } |
| 2720 | break; |
| 2721 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimShort: |
| 2723 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2724 | case Primitive::kPrimLong: |
| 2725 | // Type conversion from long to short is a result of code transformations. |
| 2726 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2727 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2728 | case Primitive::kPrimBoolean: |
| 2729 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimByte: |
| 2731 | case Primitive::kPrimInt: |
| 2732 | case Primitive::kPrimChar: |
| 2733 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2734 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2735 | break; |
| 2736 | |
| 2737 | default: |
| 2738 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2739 | << " to " << result_type; |
| 2740 | } |
| 2741 | break; |
| 2742 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimInt: |
| 2744 | switch (input_type) { |
| 2745 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2746 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2747 | DCHECK(out.IsRegister()); |
| 2748 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2749 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2750 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2751 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2752 | } else { |
| 2753 | DCHECK(in.IsConstant()); |
| 2754 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2755 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2756 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2757 | } |
| 2758 | break; |
| 2759 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2760 | case Primitive::kPrimFloat: { |
| 2761 | // Processing a Dex `float-to-int' instruction. |
| 2762 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2763 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2764 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 2765 | break; |
| 2766 | } |
| 2767 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2768 | case Primitive::kPrimDouble: { |
| 2769 | // Processing a Dex `double-to-int' instruction. |
| 2770 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 2771 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2772 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2773 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2774 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2775 | |
| 2776 | default: |
| 2777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2778 | << " to " << result_type; |
| 2779 | } |
| 2780 | break; |
| 2781 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2782 | case Primitive::kPrimLong: |
| 2783 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2784 | case Primitive::kPrimBoolean: |
| 2785 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2786 | case Primitive::kPrimByte: |
| 2787 | case Primitive::kPrimShort: |
| 2788 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2789 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2790 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2791 | DCHECK(out.IsRegisterPair()); |
| 2792 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2793 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2794 | // Sign extension. |
| 2795 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 2796 | out.AsRegisterPairLow<Register>(), |
| 2797 | 31); |
| 2798 | break; |
| 2799 | |
| 2800 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2801 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2802 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2803 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2806 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2807 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2808 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2809 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | |
| 2812 | default: |
| 2813 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2814 | << " to " << result_type; |
| 2815 | } |
| 2816 | break; |
| 2817 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2818 | case Primitive::kPrimChar: |
| 2819 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2820 | case Primitive::kPrimLong: |
| 2821 | // Type conversion from long to char is a result of code transformations. |
| 2822 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 2823 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2824 | case Primitive::kPrimBoolean: |
| 2825 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2826 | case Primitive::kPrimByte: |
| 2827 | case Primitive::kPrimShort: |
| 2828 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2829 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2830 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | |
| 2833 | default: |
| 2834 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2835 | << " to " << result_type; |
| 2836 | } |
| 2837 | break; |
| 2838 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2839 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2840 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2841 | case Primitive::kPrimBoolean: |
| 2842 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2843 | case Primitive::kPrimByte: |
| 2844 | case Primitive::kPrimShort: |
| 2845 | case Primitive::kPrimInt: |
| 2846 | case Primitive::kPrimChar: { |
| 2847 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2848 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 2849 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2850 | break; |
| 2851 | } |
| 2852 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 2853 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2854 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2855 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2856 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2857 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2858 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2859 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2860 | // Processing a Dex `double-to-float' instruction. |
| 2861 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 2862 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | |
| 2865 | default: |
| 2866 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2867 | << " to " << result_type; |
| 2868 | }; |
| 2869 | break; |
| 2870 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2871 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2872 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2873 | case Primitive::kPrimBoolean: |
| 2874 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2875 | case Primitive::kPrimByte: |
| 2876 | case Primitive::kPrimShort: |
| 2877 | case Primitive::kPrimInt: |
| 2878 | case Primitive::kPrimChar: { |
| 2879 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2880 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2881 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2882 | out.AsFpuRegisterPairLow<SRegister>()); |
| 2883 | break; |
| 2884 | } |
| 2885 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2886 | case Primitive::kPrimLong: { |
| 2887 | // Processing a Dex `long-to-double' instruction. |
| 2888 | Register low = in.AsRegisterPairLow<Register>(); |
| 2889 | Register high = in.AsRegisterPairHigh<Register>(); |
| 2890 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 2891 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2892 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2893 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2894 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 2895 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2896 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 2897 | // temp_d = int-to-double(high) |
| 2898 | __ vmovsr(temp_s, high); |
| 2899 | __ vcvtdi(temp_d, temp_s); |
| 2900 | // constant_d = k2Pow32EncodingForDouble |
| 2901 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 2902 | // out_d = unsigned-to-double(low) |
| 2903 | __ vmovsr(out_s, low); |
| 2904 | __ vcvtdu(out_d, out_s); |
| 2905 | // out_d += temp_d * constant_d |
| 2906 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2907 | break; |
| 2908 | } |
| 2909 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2910 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2911 | // Processing a Dex `float-to-double' instruction. |
| 2912 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 2913 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2914 | break; |
| 2915 | |
| 2916 | default: |
| 2917 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2918 | << " to " << result_type; |
| 2919 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | |
| 2922 | default: |
| 2923 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2924 | << " to " << result_type; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2928 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2929 | LocationSummary* locations = |
| 2930 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2931 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2932 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2934 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2935 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2936 | break; |
| 2937 | } |
| 2938 | |
| 2939 | case Primitive::kPrimLong: { |
| 2940 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2941 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 2942 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| 2945 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2946 | case Primitive::kPrimFloat: |
| 2947 | case Primitive::kPrimDouble: { |
| 2948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2949 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2950 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2951 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2952 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2953 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2954 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2955 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2956 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 2960 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2961 | Location out = locations->Out(); |
| 2962 | Location first = locations->InAt(0); |
| 2963 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2964 | switch (add->GetResultType()) { |
| 2965 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2966 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2967 | __ add(out.AsRegister<Register>(), |
| 2968 | first.AsRegister<Register>(), |
| 2969 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2970 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2971 | __ AddConstant(out.AsRegister<Register>(), |
| 2972 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2973 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2974 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2975 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2976 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2977 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 2978 | if (second.IsConstant()) { |
| 2979 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 2980 | GenerateAddLongConst(out, first, value); |
| 2981 | } else { |
| 2982 | DCHECK(second.IsRegisterPair()); |
| 2983 | __ adds(out.AsRegisterPairLow<Register>(), |
| 2984 | first.AsRegisterPairLow<Register>(), |
| 2985 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 2986 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 2987 | first.AsRegisterPairHigh<Register>(), |
| 2988 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 2989 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2990 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2991 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2992 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2993 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2994 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 2995 | first.AsFpuRegister<SRegister>(), |
| 2996 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2997 | break; |
| 2998 | |
| 2999 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3000 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3001 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3002 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3003 | break; |
| 3004 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3005 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3006 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3010 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3011 | LocationSummary* locations = |
| 3012 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3013 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3014 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3016 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3017 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3018 | break; |
| 3019 | } |
| 3020 | |
| 3021 | case Primitive::kPrimLong: { |
| 3022 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3023 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3024 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3025 | break; |
| 3026 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3027 | case Primitive::kPrimFloat: |
| 3028 | case Primitive::kPrimDouble: { |
| 3029 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3030 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3031 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3032 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3033 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3034 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3035 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3036 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3040 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3041 | Location out = locations->Out(); |
| 3042 | Location first = locations->InAt(0); |
| 3043 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3044 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3045 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3046 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3047 | __ sub(out.AsRegister<Register>(), |
| 3048 | first.AsRegister<Register>(), |
| 3049 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3050 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3051 | __ AddConstant(out.AsRegister<Register>(), |
| 3052 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3053 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3054 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3055 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3056 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3057 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3058 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3059 | if (second.IsConstant()) { |
| 3060 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3061 | GenerateAddLongConst(out, first, -value); |
| 3062 | } else { |
| 3063 | DCHECK(second.IsRegisterPair()); |
| 3064 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3065 | first.AsRegisterPairLow<Register>(), |
| 3066 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3067 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3068 | first.AsRegisterPairHigh<Register>(), |
| 3069 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3070 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3071 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3073 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3074 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3075 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3076 | first.AsFpuRegister<SRegister>(), |
| 3077 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3078 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3082 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3083 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3084 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3085 | break; |
| 3086 | } |
| 3087 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3088 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3089 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3090 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3094 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3095 | LocationSummary* locations = |
| 3096 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3097 | switch (mul->GetResultType()) { |
| 3098 | case Primitive::kPrimInt: |
| 3099 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3101 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3102 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3103 | break; |
| 3104 | } |
| 3105 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3106 | case Primitive::kPrimFloat: |
| 3107 | case Primitive::kPrimDouble: { |
| 3108 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3109 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3110 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3111 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3112 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3113 | |
| 3114 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3115 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3120 | LocationSummary* locations = mul->GetLocations(); |
| 3121 | Location out = locations->Out(); |
| 3122 | Location first = locations->InAt(0); |
| 3123 | Location second = locations->InAt(1); |
| 3124 | switch (mul->GetResultType()) { |
| 3125 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3126 | __ mul(out.AsRegister<Register>(), |
| 3127 | first.AsRegister<Register>(), |
| 3128 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3129 | break; |
| 3130 | } |
| 3131 | case Primitive::kPrimLong: { |
| 3132 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3133 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3134 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3135 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3136 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3137 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3138 | |
| 3139 | // Extra checks to protect caused by the existence of R1_R2. |
| 3140 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3141 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3142 | DCHECK_NE(out_hi, in1_lo); |
| 3143 | DCHECK_NE(out_hi, in2_lo); |
| 3144 | |
| 3145 | // input: in1 - 64 bits, in2 - 64 bits |
| 3146 | // output: out |
| 3147 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3148 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3149 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3150 | |
| 3151 | // IP <- in1.lo * in2.hi |
| 3152 | __ mul(IP, in1_lo, in2_hi); |
| 3153 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3154 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3155 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3156 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3157 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3158 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3159 | break; |
| 3160 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3161 | |
| 3162 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3163 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3164 | first.AsFpuRegister<SRegister>(), |
| 3165 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3166 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3170 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3171 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3172 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3173 | break; |
| 3174 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3175 | |
| 3176 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3177 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3178 | } |
| 3179 | } |
| 3180 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3181 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3182 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3183 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3184 | |
| 3185 | LocationSummary* locations = instruction->GetLocations(); |
| 3186 | Location second = locations->InAt(1); |
| 3187 | DCHECK(second.IsConstant()); |
| 3188 | |
| 3189 | Register out = locations->Out().AsRegister<Register>(); |
| 3190 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3191 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3192 | DCHECK(imm == 1 || imm == -1); |
| 3193 | |
| 3194 | if (instruction->IsRem()) { |
| 3195 | __ LoadImmediate(out, 0); |
| 3196 | } else { |
| 3197 | if (imm == 1) { |
| 3198 | __ Mov(out, dividend); |
| 3199 | } else { |
| 3200 | __ rsb(out, dividend, ShifterOperand(0)); |
| 3201 | } |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 3206 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3207 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3208 | |
| 3209 | LocationSummary* locations = instruction->GetLocations(); |
| 3210 | Location second = locations->InAt(1); |
| 3211 | DCHECK(second.IsConstant()); |
| 3212 | |
| 3213 | Register out = locations->Out().AsRegister<Register>(); |
| 3214 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3215 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3216 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3217 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3218 | int ctz_imm = CTZ(abs_imm); |
| 3219 | |
| 3220 | if (ctz_imm == 1) { |
| 3221 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 3222 | } else { |
| 3223 | __ Asr(temp, dividend, 31); |
| 3224 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 3225 | } |
| 3226 | __ add(out, temp, ShifterOperand(dividend)); |
| 3227 | |
| 3228 | if (instruction->IsDiv()) { |
| 3229 | __ Asr(out, out, ctz_imm); |
| 3230 | if (imm < 0) { |
| 3231 | __ rsb(out, out, ShifterOperand(0)); |
| 3232 | } |
| 3233 | } else { |
| 3234 | __ ubfx(out, out, 0, ctz_imm); |
| 3235 | __ sub(out, out, ShifterOperand(temp)); |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3240 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3241 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3242 | |
| 3243 | LocationSummary* locations = instruction->GetLocations(); |
| 3244 | Location second = locations->InAt(1); |
| 3245 | DCHECK(second.IsConstant()); |
| 3246 | |
| 3247 | Register out = locations->Out().AsRegister<Register>(); |
| 3248 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 3249 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 3250 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 3251 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3252 | |
| 3253 | int64_t magic; |
| 3254 | int shift; |
| 3255 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3256 | |
| 3257 | __ LoadImmediate(temp1, magic); |
| 3258 | __ smull(temp2, temp1, dividend, temp1); |
| 3259 | |
| 3260 | if (imm > 0 && magic < 0) { |
| 3261 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 3262 | } else if (imm < 0 && magic > 0) { |
| 3263 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 3264 | } |
| 3265 | |
| 3266 | if (shift != 0) { |
| 3267 | __ Asr(temp1, temp1, shift); |
| 3268 | } |
| 3269 | |
| 3270 | if (instruction->IsDiv()) { |
| 3271 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3272 | } else { |
| 3273 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 3274 | // TODO: Strength reduction for mls. |
| 3275 | __ LoadImmediate(temp2, imm); |
| 3276 | __ mls(out, temp1, temp2, dividend); |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 3281 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3282 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3283 | |
| 3284 | LocationSummary* locations = instruction->GetLocations(); |
| 3285 | Location second = locations->InAt(1); |
| 3286 | DCHECK(second.IsConstant()); |
| 3287 | |
| 3288 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3289 | if (imm == 0) { |
| 3290 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3291 | } else if (imm == 1 || imm == -1) { |
| 3292 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3293 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3294 | DivRemByPowerOfTwo(instruction); |
| 3295 | } else { |
| 3296 | DCHECK(imm <= -2 || imm >= 2); |
| 3297 | GenerateDivRemWithAnyConstant(instruction); |
| 3298 | } |
| 3299 | } |
| 3300 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3301 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3302 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 3303 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 3304 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3305 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3306 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 3307 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3308 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 3309 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 3310 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3311 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3314 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3315 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3316 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3317 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3318 | if (div->InputAt(1)->IsConstant()) { |
| 3319 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3320 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3321 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3322 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 3323 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3324 | // No temp register required. |
| 3325 | } else { |
| 3326 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3327 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3328 | locations->AddTemp(Location::RequiresRegister()); |
| 3329 | } |
| 3330 | } |
| 3331 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3333 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3334 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3335 | } else { |
| 3336 | InvokeRuntimeCallingConvention calling_convention; |
| 3337 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3338 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3339 | // 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] | 3340 | // we only need the former. |
| 3341 | locations->SetOut(Location::RegisterLocation(R0)); |
| 3342 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3343 | break; |
| 3344 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3345 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3346 | InvokeRuntimeCallingConvention calling_convention; |
| 3347 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3348 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3349 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3350 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3351 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3352 | break; |
| 3353 | } |
| 3354 | case Primitive::kPrimFloat: |
| 3355 | case Primitive::kPrimDouble: { |
| 3356 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3357 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3358 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3359 | break; |
| 3360 | } |
| 3361 | |
| 3362 | default: |
| 3363 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 3368 | LocationSummary* locations = div->GetLocations(); |
| 3369 | Location out = locations->Out(); |
| 3370 | Location first = locations->InAt(0); |
| 3371 | Location second = locations->InAt(1); |
| 3372 | |
| 3373 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3374 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3375 | if (second.IsConstant()) { |
| 3376 | GenerateDivRemConstantIntegral(div); |
| 3377 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3378 | __ sdiv(out.AsRegister<Register>(), |
| 3379 | first.AsRegister<Register>(), |
| 3380 | second.AsRegister<Register>()); |
| 3381 | } else { |
| 3382 | InvokeRuntimeCallingConvention calling_convention; |
| 3383 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3384 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3385 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 3386 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3387 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3388 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3389 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3390 | break; |
| 3391 | } |
| 3392 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3393 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3394 | InvokeRuntimeCallingConvention calling_convention; |
| 3395 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3396 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3397 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3398 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3399 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3400 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3401 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3402 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3403 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3404 | break; |
| 3405 | } |
| 3406 | |
| 3407 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3408 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 3409 | first.AsFpuRegister<SRegister>(), |
| 3410 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | } |
| 3413 | |
| 3414 | case Primitive::kPrimDouble: { |
| 3415 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3416 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3417 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 3418 | break; |
| 3419 | } |
| 3420 | |
| 3421 | default: |
| 3422 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3423 | } |
| 3424 | } |
| 3425 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3426 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3427 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3428 | |
| 3429 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3430 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3431 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 3432 | // sdiv will be replaced by other instruction sequence. |
| 3433 | call_kind = LocationSummary::kNoCall; |
| 3434 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 3435 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3436 | // Have hardware divide instruction for int, do it with three instructions. |
| 3437 | call_kind = LocationSummary::kNoCall; |
| 3438 | } |
| 3439 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3440 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 3441 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3442 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3444 | if (rem->InputAt(1)->IsConstant()) { |
| 3445 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3446 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3447 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3448 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 3449 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3450 | // No temp register required. |
| 3451 | } else { |
| 3452 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3453 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3454 | locations->AddTemp(Location::RequiresRegister()); |
| 3455 | } |
| 3456 | } |
| 3457 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3458 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3459 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3460 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3461 | locations->AddTemp(Location::RequiresRegister()); |
| 3462 | } else { |
| 3463 | InvokeRuntimeCallingConvention calling_convention; |
| 3464 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3465 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 3466 | // 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] | 3467 | // we only need the latter. |
| 3468 | locations->SetOut(Location::RegisterLocation(R1)); |
| 3469 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3470 | break; |
| 3471 | } |
| 3472 | case Primitive::kPrimLong: { |
| 3473 | InvokeRuntimeCallingConvention calling_convention; |
| 3474 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3475 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3476 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3477 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3478 | // The runtime helper puts the output in R2,R3. |
| 3479 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 3480 | break; |
| 3481 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3482 | case Primitive::kPrimFloat: { |
| 3483 | InvokeRuntimeCallingConvention calling_convention; |
| 3484 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 3485 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 3486 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 3487 | break; |
| 3488 | } |
| 3489 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3490 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3491 | InvokeRuntimeCallingConvention calling_convention; |
| 3492 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3493 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 3494 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 3495 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 3496 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3501 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 3506 | LocationSummary* locations = rem->GetLocations(); |
| 3507 | Location out = locations->Out(); |
| 3508 | Location first = locations->InAt(0); |
| 3509 | Location second = locations->InAt(1); |
| 3510 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3511 | Primitive::Type type = rem->GetResultType(); |
| 3512 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3513 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3514 | if (second.IsConstant()) { |
| 3515 | GenerateDivRemConstantIntegral(rem); |
| 3516 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3517 | Register reg1 = first.AsRegister<Register>(); |
| 3518 | Register reg2 = second.AsRegister<Register>(); |
| 3519 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3520 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3521 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3522 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3523 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 3524 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3525 | } else { |
| 3526 | InvokeRuntimeCallingConvention calling_convention; |
| 3527 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 3528 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 3529 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 3530 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3531 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3532 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 3533 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | break; |
| 3535 | } |
| 3536 | |
| 3537 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3538 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3539 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3540 | break; |
| 3541 | } |
| 3542 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3543 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3544 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3545 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3546 | break; |
| 3547 | } |
| 3548 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3549 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3550 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3551 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3552 | break; |
| 3553 | } |
| 3554 | |
| 3555 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3556 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3557 | } |
| 3558 | } |
| 3559 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3560 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3561 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3562 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 3566 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3567 | codegen_->AddSlowPath(slow_path); |
| 3568 | |
| 3569 | LocationSummary* locations = instruction->GetLocations(); |
| 3570 | Location value = locations->InAt(0); |
| 3571 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3572 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3573 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3574 | case Primitive::kPrimByte: |
| 3575 | case Primitive::kPrimChar: |
| 3576 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3577 | case Primitive::kPrimInt: { |
| 3578 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 3579 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3580 | } else { |
| 3581 | DCHECK(value.IsConstant()) << value; |
| 3582 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3583 | __ b(slow_path->GetEntryLabel()); |
| 3584 | } |
| 3585 | } |
| 3586 | break; |
| 3587 | } |
| 3588 | case Primitive::kPrimLong: { |
| 3589 | if (value.IsRegisterPair()) { |
| 3590 | __ orrs(IP, |
| 3591 | value.AsRegisterPairLow<Register>(), |
| 3592 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 3593 | __ b(slow_path->GetEntryLabel(), EQ); |
| 3594 | } else { |
| 3595 | DCHECK(value.IsConstant()) << value; |
| 3596 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3597 | __ b(slow_path->GetEntryLabel()); |
| 3598 | } |
| 3599 | } |
| 3600 | break; |
| 3601 | default: |
| 3602 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3603 | } |
| 3604 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3605 | } |
| 3606 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3607 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 3608 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3609 | Location rhs = locations->InAt(1); |
| 3610 | Register out = locations->Out().AsRegister<Register>(); |
| 3611 | |
| 3612 | if (rhs.IsConstant()) { |
| 3613 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 3614 | // so map all rotations to a +ve. equivalent in that range. |
| 3615 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 3616 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 3617 | if (rot) { |
| 3618 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 3619 | // (e.g. left by 2 bits == right by 30.) |
| 3620 | __ Ror(out, in, rot); |
| 3621 | } else if (out != in) { |
| 3622 | __ Mov(out, in); |
| 3623 | } |
| 3624 | } else { |
| 3625 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 3630 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 3631 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 3632 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 3633 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 3634 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 3635 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 3636 | Location rhs = locations->InAt(1); |
| 3637 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 3638 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 3639 | |
| 3640 | if (rhs.IsConstant()) { |
| 3641 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 3642 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3643 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3644 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 3645 | // logic below to a simple pair of binary orr. |
| 3646 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 3647 | if (rot >= kArmBitsPerWord) { |
| 3648 | rot -= kArmBitsPerWord; |
| 3649 | std::swap(in_reg_hi, in_reg_lo); |
| 3650 | } |
| 3651 | // Rotate, or mov to out for zero or word size rotations. |
| 3652 | if (rot != 0u) { |
| 3653 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 3654 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 3655 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 3656 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 3657 | } else { |
| 3658 | __ Mov(out_reg_lo, in_reg_lo); |
| 3659 | __ Mov(out_reg_hi, in_reg_hi); |
| 3660 | } |
| 3661 | } else { |
| 3662 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 3663 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 3664 | Label end; |
| 3665 | Label shift_by_32_plus_shift_right; |
| 3666 | |
| 3667 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 3668 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 3669 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 3670 | __ b(&shift_by_32_plus_shift_right, CC); |
| 3671 | |
| 3672 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 3673 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 3674 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 3675 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3676 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3677 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3678 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 3679 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 3680 | __ b(&end); |
| 3681 | |
| 3682 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 3683 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 3684 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 3685 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 3686 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 3687 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 3688 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 3689 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 3690 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 3691 | |
| 3692 | __ Bind(&end); |
| 3693 | } |
| 3694 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3695 | |
| 3696 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3697 | LocationSummary* locations = |
| 3698 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3699 | switch (ror->GetResultType()) { |
| 3700 | case Primitive::kPrimInt: { |
| 3701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3702 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 3703 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3704 | break; |
| 3705 | } |
| 3706 | case Primitive::kPrimLong: { |
| 3707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3708 | if (ror->InputAt(1)->IsConstant()) { |
| 3709 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 3710 | } else { |
| 3711 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3712 | locations->AddTemp(Location::RequiresRegister()); |
| 3713 | locations->AddTemp(Location::RequiresRegister()); |
| 3714 | } |
| 3715 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3716 | break; |
| 3717 | } |
| 3718 | default: |
| 3719 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3720 | } |
| 3721 | } |
| 3722 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 3723 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3724 | LocationSummary* locations = ror->GetLocations(); |
| 3725 | Primitive::Type type = ror->GetResultType(); |
| 3726 | switch (type) { |
| 3727 | case Primitive::kPrimInt: { |
| 3728 | HandleIntegerRotate(locations); |
| 3729 | break; |
| 3730 | } |
| 3731 | case Primitive::kPrimLong: { |
| 3732 | HandleLongRotate(locations); |
| 3733 | break; |
| 3734 | } |
| 3735 | default: |
| 3736 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3737 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3738 | } |
| 3739 | } |
| 3740 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3741 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 3742 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3743 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3744 | LocationSummary* locations = |
| 3745 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3746 | |
| 3747 | switch (op->GetResultType()) { |
| 3748 | case Primitive::kPrimInt: { |
| 3749 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3750 | if (op->InputAt(1)->IsConstant()) { |
| 3751 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3752 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3753 | } else { |
| 3754 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3755 | // Make the output overlap, as it will be used to hold the masked |
| 3756 | // second input. |
| 3757 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3758 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| 3761 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3762 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3763 | if (op->InputAt(1)->IsConstant()) { |
| 3764 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 3765 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 3766 | // don't clash with high registers which the register allocator currently guarantees. |
| 3767 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3768 | } else { |
| 3769 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3770 | locations->AddTemp(Location::RequiresRegister()); |
| 3771 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3772 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | default: |
| 3776 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 3781 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3782 | |
| 3783 | LocationSummary* locations = op->GetLocations(); |
| 3784 | Location out = locations->Out(); |
| 3785 | Location first = locations->InAt(0); |
| 3786 | Location second = locations->InAt(1); |
| 3787 | |
| 3788 | Primitive::Type type = op->GetResultType(); |
| 3789 | switch (type) { |
| 3790 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3791 | Register out_reg = out.AsRegister<Register>(); |
| 3792 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3793 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3794 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3795 | // 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] | 3796 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3797 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3798 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3799 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3800 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 3802 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3803 | } |
| 3804 | } else { |
| 3805 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3806 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3807 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3808 | __ Mov(out_reg, first_reg); |
| 3809 | } else if (op->IsShl()) { |
| 3810 | __ Lsl(out_reg, first_reg, shift_value); |
| 3811 | } else if (op->IsShr()) { |
| 3812 | __ Asr(out_reg, first_reg, shift_value); |
| 3813 | } else { |
| 3814 | __ Lsr(out_reg, first_reg, shift_value); |
| 3815 | } |
| 3816 | } |
| 3817 | break; |
| 3818 | } |
| 3819 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3820 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 3821 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3822 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3823 | Register high = first.AsRegisterPairHigh<Register>(); |
| 3824 | Register low = first.AsRegisterPairLow<Register>(); |
| 3825 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3826 | if (second.IsRegister()) { |
| 3827 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 3828 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3829 | Register second_reg = second.AsRegister<Register>(); |
| 3830 | |
| 3831 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3832 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3833 | // Shift the high part |
| 3834 | __ Lsl(o_h, high, o_l); |
| 3835 | // Shift the low part and `or` what overflew on the high part |
| 3836 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3837 | __ Lsr(temp, low, temp); |
| 3838 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 3839 | // If the shift is > 32 bits, override the high part |
| 3840 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 3841 | __ it(PL); |
| 3842 | __ Lsl(o_h, low, temp, PL); |
| 3843 | // Shift the low part |
| 3844 | __ Lsl(o_l, low, o_l); |
| 3845 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3846 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3847 | // Shift the low part |
| 3848 | __ Lsr(o_l, low, o_h); |
| 3849 | // Shift the high part and `or` what underflew on the low part |
| 3850 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3851 | __ Lsl(temp, high, temp); |
| 3852 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3853 | // If the shift is > 32 bits, override the low part |
| 3854 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3855 | __ it(PL); |
| 3856 | __ Asr(o_l, high, temp, PL); |
| 3857 | // Shift the high part |
| 3858 | __ Asr(o_h, high, o_h); |
| 3859 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3860 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3861 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 3862 | __ Lsr(o_l, low, o_h); |
| 3863 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3864 | __ Lsl(temp, high, temp); |
| 3865 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 3866 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 3867 | __ it(PL); |
| 3868 | __ Lsr(o_l, high, temp, PL); |
| 3869 | __ Lsr(o_h, high, o_h); |
| 3870 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3871 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3872 | // Register allocator doesn't create partial overlap. |
| 3873 | DCHECK_NE(o_l, high); |
| 3874 | DCHECK_NE(o_h, low); |
| 3875 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3876 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3877 | if (shift_value > 32) { |
| 3878 | if (op->IsShl()) { |
| 3879 | __ Lsl(o_h, low, shift_value - 32); |
| 3880 | __ LoadImmediate(o_l, 0); |
| 3881 | } else if (op->IsShr()) { |
| 3882 | __ Asr(o_l, high, shift_value - 32); |
| 3883 | __ Asr(o_h, high, 31); |
| 3884 | } else { |
| 3885 | __ Lsr(o_l, high, shift_value - 32); |
| 3886 | __ LoadImmediate(o_h, 0); |
| 3887 | } |
| 3888 | } else if (shift_value == 32) { |
| 3889 | if (op->IsShl()) { |
| 3890 | __ mov(o_h, ShifterOperand(low)); |
| 3891 | __ LoadImmediate(o_l, 0); |
| 3892 | } else if (op->IsShr()) { |
| 3893 | __ mov(o_l, ShifterOperand(high)); |
| 3894 | __ Asr(o_h, high, 31); |
| 3895 | } else { |
| 3896 | __ mov(o_l, ShifterOperand(high)); |
| 3897 | __ LoadImmediate(o_h, 0); |
| 3898 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 3899 | } else if (shift_value == 1) { |
| 3900 | if (op->IsShl()) { |
| 3901 | __ Lsls(o_l, low, 1); |
| 3902 | __ adc(o_h, high, ShifterOperand(high)); |
| 3903 | } else if (op->IsShr()) { |
| 3904 | __ Asrs(o_h, high, 1); |
| 3905 | __ Rrx(o_l, low); |
| 3906 | } else { |
| 3907 | __ Lsrs(o_h, high, 1); |
| 3908 | __ Rrx(o_l, low); |
| 3909 | } |
| 3910 | } else { |
| 3911 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3912 | if (op->IsShl()) { |
| 3913 | __ Lsl(o_h, high, shift_value); |
| 3914 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 3915 | __ Lsl(o_l, low, shift_value); |
| 3916 | } else if (op->IsShr()) { |
| 3917 | __ Lsr(o_l, low, shift_value); |
| 3918 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3919 | __ Asr(o_h, high, shift_value); |
| 3920 | } else { |
| 3921 | __ Lsr(o_l, low, shift_value); |
| 3922 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 3923 | __ Lsr(o_h, high, shift_value); |
| 3924 | } |
| 3925 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3926 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3927 | break; |
| 3928 | } |
| 3929 | default: |
| 3930 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 3931 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 3936 | HandleShift(shl); |
| 3937 | } |
| 3938 | |
| 3939 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 3940 | HandleShift(shl); |
| 3941 | } |
| 3942 | |
| 3943 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 3944 | HandleShift(shr); |
| 3945 | } |
| 3946 | |
| 3947 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 3948 | HandleShift(shr); |
| 3949 | } |
| 3950 | |
| 3951 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 3952 | HandleShift(ushr); |
| 3953 | } |
| 3954 | |
| 3955 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 3956 | HandleShift(ushr); |
| 3957 | } |
| 3958 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3959 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3960 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3961 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3962 | if (instruction->IsStringAlloc()) { |
| 3963 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3964 | } else { |
| 3965 | InvokeRuntimeCallingConvention calling_convention; |
| 3966 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3967 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3968 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3972 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3973 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3974 | if (instruction->IsStringAlloc()) { |
| 3975 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3976 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3977 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3978 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 3979 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 3980 | __ blx(LR); |
| 3981 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3982 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3983 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 3984 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3985 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3986 | } |
| 3987 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3988 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 3989 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3990 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3991 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3992 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 3993 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3994 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3998 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3999 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4000 | QuickEntrypointEnum entrypoint = |
| 4001 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4002 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4003 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4004 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4005 | } |
| 4006 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4007 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4008 | LocationSummary* locations = |
| 4009 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4010 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4011 | if (location.IsStackSlot()) { |
| 4012 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4013 | } else if (location.IsDoubleStackSlot()) { |
| 4014 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4015 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4016 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4019 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4020 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4021 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4025 | LocationSummary* locations = |
| 4026 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4027 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4028 | } |
| 4029 | |
| 4030 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4031 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4034 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4035 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4037 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4038 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4041 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4042 | LocationSummary* locations = not_->GetLocations(); |
| 4043 | Location out = locations->Out(); |
| 4044 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4045 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4046 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4047 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4048 | break; |
| 4049 | |
| 4050 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4051 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4052 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4053 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4054 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4055 | break; |
| 4056 | |
| 4057 | default: |
| 4058 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4059 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4060 | } |
| 4061 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4062 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4063 | LocationSummary* locations = |
| 4064 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4067 | } |
| 4068 | |
| 4069 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4070 | LocationSummary* locations = bool_not->GetLocations(); |
| 4071 | Location out = locations->Out(); |
| 4072 | Location in = locations->InAt(0); |
| 4073 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4074 | } |
| 4075 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4076 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4077 | LocationSummary* locations = |
| 4078 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4079 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4080 | case Primitive::kPrimBoolean: |
| 4081 | case Primitive::kPrimByte: |
| 4082 | case Primitive::kPrimShort: |
| 4083 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4084 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4085 | case Primitive::kPrimLong: { |
| 4086 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4087 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4088 | // Output overlaps because it is written before doing the low comparison. |
| 4089 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4090 | break; |
| 4091 | } |
| 4092 | case Primitive::kPrimFloat: |
| 4093 | case Primitive::kPrimDouble: { |
| 4094 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4095 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4096 | locations->SetOut(Location::RequiresRegister()); |
| 4097 | break; |
| 4098 | } |
| 4099 | default: |
| 4100 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4101 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4105 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4106 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4107 | Location left = locations->InAt(0); |
| 4108 | Location right = locations->InAt(1); |
| 4109 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4110 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4111 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4112 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4113 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4114 | case Primitive::kPrimBoolean: |
| 4115 | case Primitive::kPrimByte: |
| 4116 | case Primitive::kPrimShort: |
| 4117 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4118 | case Primitive::kPrimInt: { |
| 4119 | __ LoadImmediate(out, 0); |
| 4120 | __ cmp(left.AsRegister<Register>(), |
| 4121 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4122 | less_cond = LT; |
| 4123 | break; |
| 4124 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4125 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4126 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4127 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4128 | __ b(&less, LT); |
| 4129 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4130 | // 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] | 4131 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4132 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4133 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4134 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4135 | break; |
| 4136 | } |
| 4137 | case Primitive::kPrimFloat: |
| 4138 | case Primitive::kPrimDouble: { |
| 4139 | __ LoadImmediate(out, 0); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4140 | GenerateVcmp(compare); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4141 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4142 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4143 | break; |
| 4144 | } |
| 4145 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4146 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4147 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4148 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4149 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4150 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4151 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4152 | |
| 4153 | __ Bind(&greater); |
| 4154 | __ LoadImmediate(out, 1); |
| 4155 | __ b(&done); |
| 4156 | |
| 4157 | __ Bind(&less); |
| 4158 | __ LoadImmediate(out, -1); |
| 4159 | |
| 4160 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4163 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4164 | LocationSummary* locations = |
| 4165 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4166 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4167 | locations->SetInAt(i, Location::Any()); |
| 4168 | } |
| 4169 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4170 | } |
| 4171 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4172 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4173 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4174 | } |
| 4175 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4176 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4177 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4178 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | switch (kind) { |
| 4180 | case MemBarrierKind::kAnyStore: |
| 4181 | case MemBarrierKind::kLoadAny: |
| 4182 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4183 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4184 | break; |
| 4185 | } |
| 4186 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4187 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4188 | break; |
| 4189 | } |
| 4190 | default: |
| 4191 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 4192 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4193 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 4197 | uint32_t offset, |
| 4198 | Register out_lo, |
| 4199 | Register out_hi) { |
| 4200 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4201 | // Ensure `out_lo` is different from `addr`, so that loading |
| 4202 | // `offset` into `out_lo` does not clutter `addr`. |
| 4203 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4205 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 4206 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4207 | } |
| 4208 | __ ldrexd(out_lo, out_hi, addr); |
| 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 4212 | uint32_t offset, |
| 4213 | Register value_lo, |
| 4214 | Register value_hi, |
| 4215 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4216 | Register temp2, |
| 4217 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4218 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4219 | if (offset != 0) { |
| 4220 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 4221 | __ add(IP, addr, ShifterOperand(temp1)); |
| 4222 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4223 | } |
| 4224 | __ Bind(&fail); |
| 4225 | // We need a load followed by store. (The address used in a STREX instruction must |
| 4226 | // be the same as the address in the most recently executed LDREX instruction.) |
| 4227 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4228 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4229 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4230 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4234 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4235 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4236 | LocationSummary* locations = |
| 4237 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4238 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4239 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4240 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4241 | if (Primitive::IsFloatingPointType(field_type)) { |
| 4242 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4243 | } else { |
| 4244 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4245 | } |
| 4246 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4248 | bool generate_volatile = field_info.IsVolatile() |
| 4249 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4250 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4251 | bool needs_write_barrier = |
| 4252 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4253 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4254 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4255 | if (needs_write_barrier) { |
| 4256 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4257 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4258 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4259 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4260 | // - registers need to be consecutive |
| 4261 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4262 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4263 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4264 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4265 | |
| 4266 | locations->AddTemp(Location::RequiresRegister()); |
| 4267 | locations->AddTemp(Location::RequiresRegister()); |
| 4268 | if (field_type == Primitive::kPrimDouble) { |
| 4269 | // For doubles we need two more registers to copy the value. |
| 4270 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 4271 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 4272 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4273 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4274 | } |
| 4275 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4276 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4277 | const FieldInfo& field_info, |
| 4278 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4279 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4280 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4281 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4283 | Location value = locations->InAt(1); |
| 4284 | |
| 4285 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4286 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4287 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4288 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4289 | bool needs_write_barrier = |
| 4290 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4291 | |
| 4292 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4293 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4294 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4295 | |
| 4296 | switch (field_type) { |
| 4297 | case Primitive::kPrimBoolean: |
| 4298 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4299 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4300 | break; |
| 4301 | } |
| 4302 | |
| 4303 | case Primitive::kPrimShort: |
| 4304 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4305 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4306 | break; |
| 4307 | } |
| 4308 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4309 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4310 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4311 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4312 | // Note that in the case where `value` is a null reference, |
| 4313 | // we do not enter this block, as a null reference does not |
| 4314 | // need poisoning. |
| 4315 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4316 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4317 | __ Mov(temp, value.AsRegister<Register>()); |
| 4318 | __ PoisonHeapReference(temp); |
| 4319 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 4320 | } else { |
| 4321 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 4322 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4323 | break; |
| 4324 | } |
| 4325 | |
| 4326 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4327 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4328 | GenerateWideAtomicStore(base, offset, |
| 4329 | value.AsRegisterPairLow<Register>(), |
| 4330 | value.AsRegisterPairHigh<Register>(), |
| 4331 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4332 | locations->GetTemp(1).AsRegister<Register>(), |
| 4333 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4334 | } else { |
| 4335 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4336 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4337 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4338 | break; |
| 4339 | } |
| 4340 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4341 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4342 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4343 | break; |
| 4344 | } |
| 4345 | |
| 4346 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4347 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4348 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4349 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4350 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4351 | |
| 4352 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 4353 | |
| 4354 | GenerateWideAtomicStore(base, offset, |
| 4355 | value_reg_lo, |
| 4356 | value_reg_hi, |
| 4357 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4358 | locations->GetTemp(3).AsRegister<Register>(), |
| 4359 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4360 | } else { |
| 4361 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4363 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4364 | break; |
| 4365 | } |
| 4366 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4367 | case Primitive::kPrimVoid: |
| 4368 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4369 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4370 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4371 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4372 | // Longs and doubles are handled in the switch. |
| 4373 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 4374 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4375 | } |
| 4376 | |
| 4377 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4378 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4379 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4380 | codegen_->MarkGCCard( |
| 4381 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4384 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4385 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4386 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4387 | } |
| 4388 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4389 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4390 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4391 | |
| 4392 | bool object_field_get_with_read_barrier = |
| 4393 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4394 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4395 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4396 | object_field_get_with_read_barrier ? |
| 4397 | LocationSummary::kCallOnSlowPath : |
| 4398 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4399 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4400 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4401 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4402 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4403 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4404 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4405 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4406 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4407 | // The output overlaps in case of volatile long: we don't want the |
| 4408 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 4409 | // object's location. Likewise, in the case of an object field get |
| 4410 | // with read barriers enabled, we do not want the load to overwrite |
| 4411 | // the object's location, as we need it to emit the read barrier. |
| 4412 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 4413 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 4414 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4415 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4416 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4417 | } else { |
| 4418 | locations->SetOut(Location::RequiresRegister(), |
| 4419 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 4420 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4421 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4422 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4423 | // - registers need to be consecutive |
| 4424 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4425 | // We don't test for ARM yet, and the assertion makes sure that we |
| 4426 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4427 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 4428 | locations->AddTemp(Location::RequiresRegister()); |
| 4429 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4430 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4431 | // We need a temporary register for the read barrier marking slow |
| 4432 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 4433 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4434 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4435 | } |
| 4436 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4437 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 4438 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 4439 | << input->GetType(); |
| 4440 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 4441 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 4442 | return Location::ConstantLocation(input->AsConstant()); |
| 4443 | } else { |
| 4444 | return Location::RequiresFpuRegister(); |
| 4445 | } |
| 4446 | } |
| 4447 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4448 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 4449 | Opcode opcode) { |
| 4450 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 4451 | if (constant->IsConstant() && |
| 4452 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 4453 | return Location::ConstantLocation(constant->AsConstant()); |
| 4454 | } |
| 4455 | return Location::RequiresRegister(); |
| 4456 | } |
| 4457 | |
| 4458 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 4459 | Opcode opcode) { |
| 4460 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 4461 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4462 | Opcode high_opcode = opcode; |
| 4463 | SetCc low_set_cc = kCcDontCare; |
| 4464 | switch (opcode) { |
| 4465 | case SUB: |
| 4466 | // Flip the operation to an ADD. |
| 4467 | value = -value; |
| 4468 | opcode = ADD; |
| 4469 | FALLTHROUGH_INTENDED; |
| 4470 | case ADD: |
| 4471 | if (Low32Bits(value) == 0u) { |
| 4472 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 4473 | } |
| 4474 | high_opcode = ADC; |
| 4475 | low_set_cc = kCcSet; |
| 4476 | break; |
| 4477 | default: |
| 4478 | break; |
| 4479 | } |
| 4480 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 4481 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4482 | } else { |
| 4483 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 4484 | } |
| 4485 | } |
| 4486 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4487 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 4488 | Opcode opcode, |
| 4489 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4490 | ShifterOperand so; |
| 4491 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4492 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4493 | return true; |
| 4494 | } |
| 4495 | Opcode neg_opcode = kNoOperand; |
| 4496 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4497 | case AND: neg_opcode = BIC; value = ~value; break; |
| 4498 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 4499 | case ADD: neg_opcode = SUB; value = -value; break; |
| 4500 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 4501 | case SUB: neg_opcode = ADD; value = -value; break; |
| 4502 | case SBC: neg_opcode = ADC; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4503 | default: |
| 4504 | return false; |
| 4505 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 4506 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 4507 | } |
| 4508 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4509 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 4510 | const FieldInfo& field_info) { |
| 4511 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4512 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4513 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4514 | Location base_loc = locations->InAt(0); |
| 4515 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4516 | Location out = locations->Out(); |
| 4517 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4518 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4519 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4520 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4521 | |
| 4522 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4523 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4524 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4525 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4526 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4527 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4529 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4530 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4531 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4533 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4534 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4535 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4536 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4537 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4538 | |
| 4539 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4541 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4542 | |
| 4543 | case Primitive::kPrimNot: { |
| 4544 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4545 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4546 | Location temp_loc = locations->GetTemp(0); |
| 4547 | // Note that a potential implicit null check is handled in this |
| 4548 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 4549 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4550 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4551 | if (is_volatile) { |
| 4552 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4553 | } |
| 4554 | } else { |
| 4555 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 4556 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4557 | if (is_volatile) { |
| 4558 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4559 | } |
| 4560 | // If read barriers are enabled, emit read barriers other than |
| 4561 | // Baker's using a slow path (and also unpoison the loaded |
| 4562 | // reference, if heap poisoning is enabled). |
| 4563 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4564 | } |
| 4565 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4568 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4569 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4570 | GenerateWideAtomicLoad(base, offset, |
| 4571 | out.AsRegisterPairLow<Register>(), |
| 4572 | out.AsRegisterPairHigh<Register>()); |
| 4573 | } else { |
| 4574 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 4575 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4576 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4577 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4578 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4579 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4580 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4581 | |
| 4582 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 4584 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4585 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 4586 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 4587 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4588 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4589 | __ vmovdrr(out_reg, lo, hi); |
| 4590 | } else { |
| 4591 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4592 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4594 | break; |
| 4595 | } |
| 4596 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4597 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4599 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4600 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4601 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4602 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 4603 | // Potential implicit null checks, in the case of reference or |
| 4604 | // double fields, are handled in the previous switch statement. |
| 4605 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4606 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4607 | } |
| 4608 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4609 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4610 | if (field_type == Primitive::kPrimNot) { |
| 4611 | // Memory barriers, in the case of references, are also handled |
| 4612 | // in the previous switch statement. |
| 4613 | } else { |
| 4614 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4615 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4616 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4620 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4621 | } |
| 4622 | |
| 4623 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4624 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4628 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4629 | } |
| 4630 | |
| 4631 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4632 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4633 | } |
| 4634 | |
| 4635 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4636 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4637 | } |
| 4638 | |
| 4639 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4640 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4641 | } |
| 4642 | |
| 4643 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4644 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4645 | } |
| 4646 | |
| 4647 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4648 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4651 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 4652 | HUnresolvedInstanceFieldGet* instruction) { |
| 4653 | FieldAccessCallingConventionARM calling_convention; |
| 4654 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4655 | instruction, instruction->GetFieldType(), calling_convention); |
| 4656 | } |
| 4657 | |
| 4658 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 4659 | HUnresolvedInstanceFieldGet* instruction) { |
| 4660 | FieldAccessCallingConventionARM calling_convention; |
| 4661 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4662 | instruction->GetFieldType(), |
| 4663 | instruction->GetFieldIndex(), |
| 4664 | instruction->GetDexPc(), |
| 4665 | calling_convention); |
| 4666 | } |
| 4667 | |
| 4668 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 4669 | HUnresolvedInstanceFieldSet* instruction) { |
| 4670 | FieldAccessCallingConventionARM calling_convention; |
| 4671 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4672 | instruction, instruction->GetFieldType(), calling_convention); |
| 4673 | } |
| 4674 | |
| 4675 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 4676 | HUnresolvedInstanceFieldSet* instruction) { |
| 4677 | FieldAccessCallingConventionARM calling_convention; |
| 4678 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4679 | instruction->GetFieldType(), |
| 4680 | instruction->GetFieldIndex(), |
| 4681 | instruction->GetDexPc(), |
| 4682 | calling_convention); |
| 4683 | } |
| 4684 | |
| 4685 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 4686 | HUnresolvedStaticFieldGet* instruction) { |
| 4687 | FieldAccessCallingConventionARM calling_convention; |
| 4688 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4689 | instruction, instruction->GetFieldType(), calling_convention); |
| 4690 | } |
| 4691 | |
| 4692 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 4693 | HUnresolvedStaticFieldGet* instruction) { |
| 4694 | FieldAccessCallingConventionARM calling_convention; |
| 4695 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4696 | instruction->GetFieldType(), |
| 4697 | instruction->GetFieldIndex(), |
| 4698 | instruction->GetDexPc(), |
| 4699 | calling_convention); |
| 4700 | } |
| 4701 | |
| 4702 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 4703 | HUnresolvedStaticFieldSet* instruction) { |
| 4704 | FieldAccessCallingConventionARM calling_convention; |
| 4705 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4706 | instruction, instruction->GetFieldType(), calling_convention); |
| 4707 | } |
| 4708 | |
| 4709 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 4710 | HUnresolvedStaticFieldSet* instruction) { |
| 4711 | FieldAccessCallingConventionARM calling_convention; |
| 4712 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4713 | instruction->GetFieldType(), |
| 4714 | instruction->GetFieldIndex(), |
| 4715 | instruction->GetDexPc(), |
| 4716 | calling_convention); |
| 4717 | } |
| 4718 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4719 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4720 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4721 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4722 | } |
| 4723 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4724 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4725 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4726 | return; |
| 4727 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4728 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4729 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4730 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4731 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4734 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4735 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4736 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4737 | |
| 4738 | LocationSummary* locations = instruction->GetLocations(); |
| 4739 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4740 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4741 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4742 | } |
| 4743 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4744 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4745 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4748 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 4749 | switch (type) { |
| 4750 | case Primitive::kPrimNot: |
| 4751 | return kLoadWord; |
| 4752 | case Primitive::kPrimBoolean: |
| 4753 | return kLoadUnsignedByte; |
| 4754 | case Primitive::kPrimByte: |
| 4755 | return kLoadSignedByte; |
| 4756 | case Primitive::kPrimChar: |
| 4757 | return kLoadUnsignedHalfword; |
| 4758 | case Primitive::kPrimShort: |
| 4759 | return kLoadSignedHalfword; |
| 4760 | case Primitive::kPrimInt: |
| 4761 | return kLoadWord; |
| 4762 | case Primitive::kPrimLong: |
| 4763 | return kLoadWordPair; |
| 4764 | case Primitive::kPrimFloat: |
| 4765 | return kLoadSWord; |
| 4766 | case Primitive::kPrimDouble: |
| 4767 | return kLoadDWord; |
| 4768 | default: |
| 4769 | LOG(FATAL) << "Unreachable type " << type; |
| 4770 | UNREACHABLE(); |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 4775 | switch (type) { |
| 4776 | case Primitive::kPrimNot: |
| 4777 | return kStoreWord; |
| 4778 | case Primitive::kPrimBoolean: |
| 4779 | case Primitive::kPrimByte: |
| 4780 | return kStoreByte; |
| 4781 | case Primitive::kPrimChar: |
| 4782 | case Primitive::kPrimShort: |
| 4783 | return kStoreHalfword; |
| 4784 | case Primitive::kPrimInt: |
| 4785 | return kStoreWord; |
| 4786 | case Primitive::kPrimLong: |
| 4787 | return kStoreWordPair; |
| 4788 | case Primitive::kPrimFloat: |
| 4789 | return kStoreSWord; |
| 4790 | case Primitive::kPrimDouble: |
| 4791 | return kStoreDWord; |
| 4792 | default: |
| 4793 | LOG(FATAL) << "Unreachable type " << type; |
| 4794 | UNREACHABLE(); |
| 4795 | } |
| 4796 | } |
| 4797 | |
| 4798 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 4799 | Location out_loc, |
| 4800 | Register base, |
| 4801 | Register reg_offset, |
| 4802 | Condition cond) { |
| 4803 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4804 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4805 | |
| 4806 | switch (type) { |
| 4807 | case Primitive::kPrimByte: |
| 4808 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4809 | break; |
| 4810 | case Primitive::kPrimBoolean: |
| 4811 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4812 | break; |
| 4813 | case Primitive::kPrimShort: |
| 4814 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4815 | break; |
| 4816 | case Primitive::kPrimChar: |
| 4817 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4818 | break; |
| 4819 | case Primitive::kPrimNot: |
| 4820 | case Primitive::kPrimInt: |
| 4821 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 4822 | break; |
| 4823 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 4824 | case Primitive::kPrimLong: |
| 4825 | case Primitive::kPrimFloat: |
| 4826 | case Primitive::kPrimDouble: |
| 4827 | default: |
| 4828 | LOG(FATAL) << "Unreachable type " << type; |
| 4829 | UNREACHABLE(); |
| 4830 | } |
| 4831 | } |
| 4832 | |
| 4833 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 4834 | Location loc, |
| 4835 | Register base, |
| 4836 | Register reg_offset, |
| 4837 | Condition cond) { |
| 4838 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 4839 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 4840 | |
| 4841 | switch (type) { |
| 4842 | case Primitive::kPrimByte: |
| 4843 | case Primitive::kPrimBoolean: |
| 4844 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 4845 | break; |
| 4846 | case Primitive::kPrimShort: |
| 4847 | case Primitive::kPrimChar: |
| 4848 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 4849 | break; |
| 4850 | case Primitive::kPrimNot: |
| 4851 | case Primitive::kPrimInt: |
| 4852 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 4853 | break; |
| 4854 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 4855 | case Primitive::kPrimLong: |
| 4856 | case Primitive::kPrimFloat: |
| 4857 | case Primitive::kPrimDouble: |
| 4858 | default: |
| 4859 | LOG(FATAL) << "Unreachable type " << type; |
| 4860 | UNREACHABLE(); |
| 4861 | } |
| 4862 | } |
| 4863 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4864 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4865 | bool object_array_get_with_read_barrier = |
| 4866 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4867 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4868 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4869 | object_array_get_with_read_barrier ? |
| 4870 | LocationSummary::kCallOnSlowPath : |
| 4871 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4872 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4873 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4874 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4875 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4876 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4877 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4878 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4879 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4880 | // The output overlaps in the case of an object array get with |
| 4881 | // read barriers enabled: we do not want the move to overwrite the |
| 4882 | // array's location, as we need it to emit the read barrier. |
| 4883 | locations->SetOut( |
| 4884 | Location::RequiresRegister(), |
| 4885 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4886 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4887 | // We need a temporary register for the read barrier marking slow |
| 4888 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4889 | // Also need for String compression feature. |
| 4890 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 4891 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4892 | locations->AddTemp(Location::RequiresRegister()); |
| 4893 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 4897 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 4898 | Location obj_loc = locations->InAt(0); |
| 4899 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4900 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4901 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4902 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4903 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4904 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 4905 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4906 | HInstruction* array_instr = instruction->GetArray(); |
| 4907 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4908 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4909 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4910 | case Primitive::kPrimBoolean: |
| 4911 | case Primitive::kPrimByte: |
| 4912 | case Primitive::kPrimShort: |
| 4913 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4914 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4915 | Register length; |
| 4916 | if (maybe_compressed_char_at) { |
| 4917 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 4918 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4919 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 4920 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4921 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4922 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4923 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4924 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4925 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4926 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4927 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4928 | "Expecting 0=compressed, 1=uncompressed"); |
| 4929 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4930 | __ LoadFromOffset(kLoadUnsignedByte, |
| 4931 | out_loc.AsRegister<Register>(), |
| 4932 | obj, |
| 4933 | data_offset + const_index); |
| 4934 | __ b(&done); |
| 4935 | __ Bind(&uncompressed_load); |
| 4936 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 4937 | out_loc.AsRegister<Register>(), |
| 4938 | obj, |
| 4939 | data_offset + (const_index << 1)); |
| 4940 | __ Bind(&done); |
| 4941 | } else { |
| 4942 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 4943 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4944 | LoadOperandType load_type = GetLoadOperandType(type); |
| 4945 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 4946 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4947 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 4948 | Register temp = IP; |
| 4949 | |
| 4950 | if (has_intermediate_address) { |
| 4951 | // We do not need to compute the intermediate address from the array: the |
| 4952 | // input instruction has done it already. See the comment in |
| 4953 | // `TryExtractArrayAccessAddress()`. |
| 4954 | if (kIsDebugBuild) { |
| 4955 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 4956 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 4957 | } |
| 4958 | temp = obj; |
| 4959 | } else { |
| 4960 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 4961 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4962 | if (maybe_compressed_char_at) { |
| 4963 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4964 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 4965 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4966 | "Expecting 0=compressed, 1=uncompressed"); |
| 4967 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 4968 | __ ldrb(out_loc.AsRegister<Register>(), |
| 4969 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 4970 | __ b(&done); |
| 4971 | __ Bind(&uncompressed_load); |
| 4972 | __ ldrh(out_loc.AsRegister<Register>(), |
| 4973 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 4974 | __ Bind(&done); |
| 4975 | } else { |
| 4976 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 4977 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4978 | } |
| 4979 | break; |
| 4980 | } |
| 4981 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4982 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 4983 | // The read barrier instrumentation of object ArrayGet |
| 4984 | // instructions does not support the HIntermediateAddress |
| 4985 | // instruction. |
| 4986 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 4987 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4988 | static_assert( |
| 4989 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4990 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4991 | // /* HeapReference<Object> */ out = |
| 4992 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4993 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4994 | Location temp = locations->GetTemp(0); |
| 4995 | // Note that a potential implicit null check is handled in this |
| 4996 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 4997 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4998 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4999 | } else { |
| 5000 | Register out = out_loc.AsRegister<Register>(); |
| 5001 | if (index.IsConstant()) { |
| 5002 | size_t offset = |
| 5003 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5004 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5006 | // If read barriers are enabled, emit read barriers other than |
| 5007 | // Baker's using a slow path (and also unpoison the loaded |
| 5008 | // reference, if heap poisoning is enabled). |
| 5009 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5010 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5011 | Register temp = IP; |
| 5012 | |
| 5013 | if (has_intermediate_address) { |
| 5014 | // We do not need to compute the intermediate address from the array: the |
| 5015 | // input instruction has done it already. See the comment in |
| 5016 | // `TryExtractArrayAccessAddress()`. |
| 5017 | if (kIsDebugBuild) { |
| 5018 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5019 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5020 | } |
| 5021 | temp = obj; |
| 5022 | } else { |
| 5023 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5024 | } |
| 5025 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5026 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5028 | // If read barriers are enabled, emit read barriers other than |
| 5029 | // Baker's using a slow path (and also unpoison the loaded |
| 5030 | // reference, if heap poisoning is enabled). |
| 5031 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5032 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5033 | } |
| 5034 | } |
| 5035 | break; |
| 5036 | } |
| 5037 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5039 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5040 | size_t offset = |
| 5041 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5042 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5043 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5044 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5045 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5046 | } |
| 5047 | break; |
| 5048 | } |
| 5049 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5050 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5051 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5052 | if (index.IsConstant()) { |
| 5053 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5054 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5055 | } else { |
| 5056 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5057 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5058 | } |
| 5059 | break; |
| 5060 | } |
| 5061 | |
| 5062 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5063 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5064 | if (index.IsConstant()) { |
| 5065 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5066 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5067 | } else { |
| 5068 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5069 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5070 | } |
| 5071 | break; |
| 5072 | } |
| 5073 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5075 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5076 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5077 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5078 | |
| 5079 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5080 | // Potential implicit null checks, in the case of reference |
| 5081 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5082 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5083 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5084 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5088 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5089 | |
| 5090 | bool needs_write_barrier = |
| 5091 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5092 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5093 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5094 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5095 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5096 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5097 | LocationSummary::kCallOnSlowPath : |
| 5098 | LocationSummary::kNoCall); |
| 5099 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5101 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5102 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5103 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5105 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5106 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5107 | if (needs_write_barrier) { |
| 5108 | // Temporary registers for the write barrier. |
| 5109 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5110 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5115 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5116 | Location array_loc = locations->InAt(0); |
| 5117 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5118 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5119 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5120 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5121 | bool needs_write_barrier = |
| 5122 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5123 | uint32_t data_offset = |
| 5124 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5125 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5126 | HInstruction* array_instr = instruction->GetArray(); |
| 5127 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5128 | |
| 5129 | switch (value_type) { |
| 5130 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5131 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5133 | case Primitive::kPrimChar: |
| 5134 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5135 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5136 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5137 | uint32_t full_offset = |
| 5138 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5139 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5140 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5142 | Register temp = IP; |
| 5143 | |
| 5144 | if (has_intermediate_address) { |
| 5145 | // We do not need to compute the intermediate address from the array: the |
| 5146 | // input instruction has done it already. See the comment in |
| 5147 | // `TryExtractArrayAccessAddress()`. |
| 5148 | if (kIsDebugBuild) { |
| 5149 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5150 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5151 | } |
| 5152 | temp = array; |
| 5153 | } else { |
| 5154 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5155 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5156 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5157 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5158 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5159 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5160 | } |
| 5161 | break; |
| 5162 | } |
| 5163 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5165 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5166 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5167 | // See the comment in instruction_simplifier_shared.cc. |
| 5168 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5169 | |
| 5170 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5171 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5172 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5173 | size_t offset = |
| 5174 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5175 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5176 | } else { |
| 5177 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5178 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5179 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5180 | value_loc, |
| 5181 | IP, |
| 5182 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5183 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5184 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5185 | DCHECK(!needs_write_barrier); |
| 5186 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5187 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5188 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5189 | |
| 5190 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5191 | Location temp1_loc = locations->GetTemp(0); |
| 5192 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 5193 | Location temp2_loc = locations->GetTemp(1); |
| 5194 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5195 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5196 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5197 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5198 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5199 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5200 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5201 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5202 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 5203 | codegen_->AddSlowPath(slow_path); |
| 5204 | if (instruction->GetValueCanBeNull()) { |
| 5205 | Label non_zero; |
| 5206 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 5207 | if (index.IsConstant()) { |
| 5208 | size_t offset = |
| 5209 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5210 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 5211 | } else { |
| 5212 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5213 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5214 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5215 | value_loc, |
| 5216 | IP, |
| 5217 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5218 | } |
| 5219 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5220 | __ b(&done); |
| 5221 | __ Bind(&non_zero); |
| 5222 | } |
| 5223 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5224 | // Note that when read barriers are enabled, the type checks |
| 5225 | // are performed without read barriers. This is fine, even in |
| 5226 | // the case where a class object is in the from-space after |
| 5227 | // the flip, as a comparison involving such a type would not |
| 5228 | // produce a false positive; it may of course produce a false |
| 5229 | // negative, in which case we would take the ArraySet slow |
| 5230 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5231 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5232 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 5233 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 5234 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5235 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5236 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5237 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 5238 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 5239 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 5240 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 5241 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 5242 | // nor `temp2`, as we are comparing two poisoned references. |
| 5243 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5244 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5245 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5246 | Label do_put; |
| 5247 | __ b(&do_put, EQ); |
| 5248 | // If heap poisoning is enabled, the `temp1` reference has |
| 5249 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5250 | __ MaybeUnpoisonHeapReference(temp1); |
| 5251 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5252 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 5253 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 5254 | // If heap poisoning is enabled, no need to unpoison |
| 5255 | // `temp1`, as we are comparing against null below. |
| 5256 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 5257 | __ Bind(&do_put); |
| 5258 | } else { |
| 5259 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | } |
| 5261 | } |
| 5262 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5263 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5264 | if (kPoisonHeapReferences) { |
| 5265 | // Note that in the case where `value` is a null reference, |
| 5266 | // we do not enter this block, as a null reference does not |
| 5267 | // need poisoning. |
| 5268 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 5269 | __ Mov(temp1, value); |
| 5270 | __ PoisonHeapReference(temp1); |
| 5271 | source = temp1; |
| 5272 | } |
| 5273 | |
| 5274 | if (index.IsConstant()) { |
| 5275 | size_t offset = |
| 5276 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5277 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 5278 | } else { |
| 5279 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5280 | |
| 5281 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5282 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5283 | Location::RegisterLocation(source), |
| 5284 | IP, |
| 5285 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5286 | } |
| 5287 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5288 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5289 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5290 | } |
| 5291 | |
| 5292 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 5293 | |
| 5294 | if (done.IsLinked()) { |
| 5295 | __ Bind(&done); |
| 5296 | } |
| 5297 | |
| 5298 | if (slow_path != nullptr) { |
| 5299 | __ Bind(slow_path->GetExitLabel()); |
| 5300 | } |
| 5301 | |
| 5302 | break; |
| 5303 | } |
| 5304 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5306 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5307 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5308 | size_t offset = |
| 5309 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5310 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5311 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5312 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5313 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5314 | } |
| 5315 | break; |
| 5316 | } |
| 5317 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5318 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5319 | Location value = locations->InAt(2); |
| 5320 | DCHECK(value.IsFpuRegister()); |
| 5321 | if (index.IsConstant()) { |
| 5322 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5323 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5324 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5325 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5326 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 5327 | } |
| 5328 | break; |
| 5329 | } |
| 5330 | |
| 5331 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5332 | Location value = locations->InAt(2); |
| 5333 | DCHECK(value.IsFpuRegisterPair()); |
| 5334 | if (index.IsConstant()) { |
| 5335 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5336 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5337 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5338 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5339 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 5340 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5341 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5342 | break; |
| 5343 | } |
| 5344 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5345 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5346 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5347 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5348 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5349 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 5350 | // Objects are handled in the switch. |
| 5351 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5353 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5357 | LocationSummary* locations = |
| 5358 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5359 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5360 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 5364 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5365 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5366 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5367 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5369 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5370 | // Mask out compression flag from String's array length. |
| 5371 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5372 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5373 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | } |
| 5375 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5376 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5377 | LocationSummary* locations = |
| 5378 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5379 | |
| 5380 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5381 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 5382 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5383 | } |
| 5384 | |
| 5385 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 5386 | LocationSummary* locations = instruction->GetLocations(); |
| 5387 | Location out = locations->Out(); |
| 5388 | Location first = locations->InAt(0); |
| 5389 | Location second = locations->InAt(1); |
| 5390 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5391 | if (second.IsRegister()) { |
| 5392 | __ add(out.AsRegister<Register>(), |
| 5393 | first.AsRegister<Register>(), |
| 5394 | ShifterOperand(second.AsRegister<Register>())); |
| 5395 | } else { |
| 5396 | __ AddConstant(out.AsRegister<Register>(), |
| 5397 | first.AsRegister<Register>(), |
| 5398 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 5399 | } |
| 5400 | } |
| 5401 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5402 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5403 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5404 | InvokeRuntimeCallingConvention calling_convention; |
| 5405 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5406 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5407 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5409 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5413 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5414 | SlowPathCodeARM* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5415 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5416 | codegen_->AddSlowPath(slow_path); |
| 5417 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5418 | Register index = locations->InAt(0).AsRegister<Register>(); |
| 5419 | Register length = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5420 | |
| 5421 | __ cmp(index, ShifterOperand(length)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 5422 | __ b(slow_path->GetEntryLabel(), HS); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5423 | } |
| 5424 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5425 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 5426 | Register card, |
| 5427 | Register object, |
| 5428 | Register value, |
| 5429 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5430 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5431 | if (can_be_null) { |
| 5432 | __ CompareAndBranchIfZero(value, &is_null); |
| 5433 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5434 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 5436 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5437 | if (can_be_null) { |
| 5438 | __ Bind(&is_null); |
| 5439 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5442 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5443 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5447 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5448 | } |
| 5449 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5450 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5451 | LocationSummary* locations = |
| 5452 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5453 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5457 | HBasicBlock* block = instruction->GetBlock(); |
| 5458 | if (block->GetLoopInformation() != nullptr) { |
| 5459 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5460 | // The back edge will generate the suspend check. |
| 5461 | return; |
| 5462 | } |
| 5463 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5464 | // The goto will generate the suspend check. |
| 5465 | return; |
| 5466 | } |
| 5467 | GenerateSuspendCheck(instruction, nullptr); |
| 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5471 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5472 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5473 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 5474 | if (slow_path == nullptr) { |
| 5475 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 5476 | instruction->SetSlowPath(slow_path); |
| 5477 | codegen_->AddSlowPath(slow_path); |
| 5478 | if (successor != nullptr) { |
| 5479 | DCHECK(successor->IsLoopHeader()); |
| 5480 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5481 | } |
| 5482 | } else { |
| 5483 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5484 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5485 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 5486 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5487 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5488 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5489 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5490 | __ Bind(slow_path->GetReturnLabel()); |
| 5491 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5492 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5493 | __ b(slow_path->GetEntryLabel()); |
| 5494 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5495 | } |
| 5496 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5497 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 5498 | return codegen_->GetAssembler(); |
| 5499 | } |
| 5500 | |
| 5501 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5502 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5503 | Location source = move->GetSource(); |
| 5504 | Location destination = move->GetDestination(); |
| 5505 | |
| 5506 | if (source.IsRegister()) { |
| 5507 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5508 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5509 | } else if (destination.IsFpuRegister()) { |
| 5510 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5511 | } else { |
| 5512 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5513 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5514 | SP, destination.GetStackIndex()); |
| 5515 | } |
| 5516 | } else if (source.IsStackSlot()) { |
| 5517 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5518 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5519 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5520 | } else if (destination.IsFpuRegister()) { |
| 5521 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5522 | } else { |
| 5523 | DCHECK(destination.IsStackSlot()); |
| 5524 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 5525 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5526 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5527 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5528 | if (destination.IsRegister()) { |
| 5529 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 5530 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5531 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5532 | } else { |
| 5533 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5534 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 5535 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5536 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5537 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5538 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 5539 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5540 | } else if (destination.IsRegisterPair()) { |
| 5541 | DCHECK(ExpectedPairLayout(destination)); |
| 5542 | __ LoadFromOffset( |
| 5543 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 5544 | } else { |
| 5545 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 5546 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5547 | SP, |
| 5548 | source.GetStackIndex()); |
| 5549 | } |
| 5550 | } else if (source.IsRegisterPair()) { |
| 5551 | if (destination.IsRegisterPair()) { |
| 5552 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 5553 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5554 | } else if (destination.IsFpuRegisterPair()) { |
| 5555 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5556 | source.AsRegisterPairLow<Register>(), |
| 5557 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5558 | } else { |
| 5559 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5560 | DCHECK(ExpectedPairLayout(source)); |
| 5561 | __ StoreToOffset( |
| 5562 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 5563 | } |
| 5564 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5565 | if (destination.IsRegisterPair()) { |
| 5566 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5567 | destination.AsRegisterPairHigh<Register>(), |
| 5568 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5569 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5570 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 5571 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 5572 | } else { |
| 5573 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5574 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 5575 | SP, |
| 5576 | destination.GetStackIndex()); |
| 5577 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5578 | } else { |
| 5579 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5580 | HConstant* constant = source.GetConstant(); |
| 5581 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5582 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5583 | if (destination.IsRegister()) { |
| 5584 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 5585 | } else { |
| 5586 | DCHECK(destination.IsStackSlot()); |
| 5587 | __ LoadImmediate(IP, value); |
| 5588 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5589 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5590 | } else if (constant->IsLongConstant()) { |
| 5591 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5592 | if (destination.IsRegisterPair()) { |
| 5593 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 5594 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5595 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5596 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5597 | __ LoadImmediate(IP, Low32Bits(value)); |
| 5598 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5599 | __ LoadImmediate(IP, High32Bits(value)); |
| 5600 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5601 | } |
| 5602 | } else if (constant->IsDoubleConstant()) { |
| 5603 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5604 | if (destination.IsFpuRegisterPair()) { |
| 5605 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5606 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5607 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5608 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5609 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 5610 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5611 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 5612 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 5613 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5614 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 5615 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5616 | float value = constant->AsFloatConstant()->GetValue(); |
| 5617 | if (destination.IsFpuRegister()) { |
| 5618 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 5619 | } else { |
| 5620 | DCHECK(destination.IsStackSlot()); |
| 5621 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 5622 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 5623 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5624 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5625 | } |
| 5626 | } |
| 5627 | |
| 5628 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 5629 | __ Mov(IP, reg); |
| 5630 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 5631 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 5632 | } |
| 5633 | |
| 5634 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 5635 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 5636 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 5637 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5638 | SP, mem1 + stack_offset); |
| 5639 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 5640 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 5641 | SP, mem2 + stack_offset); |
| 5642 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 5643 | } |
| 5644 | |
| 5645 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5646 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5647 | Location source = move->GetSource(); |
| 5648 | Location destination = move->GetDestination(); |
| 5649 | |
| 5650 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5651 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 5652 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 5653 | __ Mov(IP, source.AsRegister<Register>()); |
| 5654 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5655 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5656 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5657 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5658 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5659 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5660 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5661 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5662 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5663 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5664 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5665 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5666 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5667 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5668 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5669 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5670 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 5671 | destination.AsRegisterPairHigh<Register>(), |
| 5672 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5673 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5674 | Register low_reg = source.IsRegisterPair() |
| 5675 | ? source.AsRegisterPairLow<Register>() |
| 5676 | : destination.AsRegisterPairLow<Register>(); |
| 5677 | int mem = source.IsRegisterPair() |
| 5678 | ? destination.GetStackIndex() |
| 5679 | : source.GetStackIndex(); |
| 5680 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5681 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5682 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5683 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5684 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5685 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 5686 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5687 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5688 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5689 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5690 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 5691 | DRegister reg = source.IsFpuRegisterPair() |
| 5692 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 5693 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 5694 | int mem = source.IsFpuRegisterPair() |
| 5695 | ? destination.GetStackIndex() |
| 5696 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5697 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5698 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 5699 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5700 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 5701 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 5702 | : destination.AsFpuRegister<SRegister>(); |
| 5703 | int mem = source.IsFpuRegister() |
| 5704 | ? destination.GetStackIndex() |
| 5705 | : source.GetStackIndex(); |
| 5706 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5707 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5708 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 5709 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5710 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5711 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 5712 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5713 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 5714 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 5719 | __ Push(static_cast<Register>(reg)); |
| 5720 | } |
| 5721 | |
| 5722 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 5723 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5724 | } |
| 5725 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5726 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 5727 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5728 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5729 | case HLoadClass::LoadKind::kInvalid: |
| 5730 | LOG(FATAL) << "UNREACHABLE"; |
| 5731 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5732 | case HLoadClass::LoadKind::kReferrersClass: |
| 5733 | break; |
| 5734 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5735 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5736 | break; |
| 5737 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5738 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5739 | break; |
| 5740 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5741 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5742 | case HLoadClass::LoadKind::kBssEntry: |
| 5743 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5744 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5745 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5746 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5747 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5748 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5749 | break; |
| 5750 | } |
| 5751 | return desired_class_load_kind; |
| 5752 | } |
| 5753 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5754 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5755 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5756 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5757 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5758 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5759 | cls, |
| 5760 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5761 | Location::RegisterLocation(R0)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5762 | return; |
| 5763 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5764 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5765 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5766 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5767 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5768 | ? LocationSummary::kCallOnSlowPath |
| 5769 | : LocationSummary::kNoCall; |
| 5770 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5771 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5772 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5775 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5776 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5777 | } |
| 5778 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5779 | } |
| 5780 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5781 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5782 | // move. |
| 5783 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5784 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5785 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5786 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5787 | return; |
| 5788 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5789 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5790 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5791 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5792 | Location out_loc = locations->Out(); |
| 5793 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5794 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5795 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5796 | ? kWithoutReadBarrier |
| 5797 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5798 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5799 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5800 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5801 | DCHECK(!cls->CanCallRuntime()); |
| 5802 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5803 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5804 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5805 | GenerateGcRootFieldLoad(cls, |
| 5806 | out_loc, |
| 5807 | current_method, |
| 5808 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5809 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5810 | break; |
| 5811 | } |
| 5812 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5813 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5814 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5815 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 5816 | cls->GetTypeIndex())); |
| 5817 | break; |
| 5818 | } |
| 5819 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5820 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5821 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5822 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 5823 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 5824 | __ BindTrackedLabel(&labels->movw_label); |
| 5825 | __ movw(out, /* placeholder */ 0u); |
| 5826 | __ BindTrackedLabel(&labels->movt_label); |
| 5827 | __ movt(out, /* placeholder */ 0u); |
| 5828 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5829 | __ add(out, out, ShifterOperand(PC)); |
| 5830 | break; |
| 5831 | } |
| 5832 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5833 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5834 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5835 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5836 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5837 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5838 | break; |
| 5839 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5840 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5841 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5842 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5843 | __ BindTrackedLabel(&labels->movw_label); |
| 5844 | __ movw(out, /* placeholder */ 0u); |
| 5845 | __ BindTrackedLabel(&labels->movt_label); |
| 5846 | __ movt(out, /* placeholder */ 0u); |
| 5847 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5848 | __ add(out, out, ShifterOperand(PC)); |
| 5849 | GenerateGcRootFieldLoad(cls, out_loc, out, 0, kCompilerReadBarrierOption); |
| 5850 | generate_null_check = true; |
| 5851 | break; |
| 5852 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5853 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5854 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 5855 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5856 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5857 | // /* GcRoot<mirror::Class> */ out = *out |
| 5858 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5859 | break; |
| 5860 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5861 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5862 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5863 | LOG(FATAL) << "UNREACHABLE"; |
| 5864 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5865 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5866 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5867 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5868 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5869 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5870 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5871 | codegen_->AddSlowPath(slow_path); |
| 5872 | if (generate_null_check) { |
| 5873 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 5874 | } |
| 5875 | if (cls->MustGenerateClinitCheck()) { |
| 5876 | GenerateClassInitializationCheck(slow_path, out); |
| 5877 | } else { |
| 5878 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5879 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 5884 | LocationSummary* locations = |
| 5885 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5886 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5887 | if (check->HasUses()) { |
| 5888 | locations->SetOut(Location::SameAsFirstInput()); |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5893 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5894 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5895 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5896 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5897 | GenerateClassInitializationCheck(slow_path, |
| 5898 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5899 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5900 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5901 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5902 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5903 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 5904 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 5905 | __ b(slow_path->GetEntryLabel(), LT); |
| 5906 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 5907 | // properly. Therefore, we do a memory fence. |
| 5908 | __ dmb(ISH); |
| 5909 | __ Bind(slow_path->GetExitLabel()); |
| 5910 | } |
| 5911 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5912 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 5913 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5914 | switch (desired_string_load_kind) { |
| 5915 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5916 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5917 | break; |
| 5918 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5919 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5920 | break; |
| 5921 | case HLoadString::LoadKind::kBootImageAddress: |
| 5922 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5923 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5924 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5925 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5926 | case HLoadString::LoadKind::kJitTableAddress: |
| 5927 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5928 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5929 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5930 | break; |
| 5931 | } |
| 5932 | return desired_string_load_kind; |
| 5933 | } |
| 5934 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5935 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5936 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5937 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5938 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5939 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5940 | locations->SetOut(Location::RegisterLocation(R0)); |
| 5941 | } else { |
| 5942 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5943 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 5944 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5945 | // Rely on the pResolveString and/or marking to save everything, including temps. |
| 5946 | // Note that IP may theoretically be clobbered by saving/restoring the live register |
| 5947 | // (only one thanks to the custom calling convention), so we request a different temp. |
| 5948 | locations->AddTemp(Location::RequiresRegister()); |
| 5949 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5950 | InvokeRuntimeCallingConvention calling_convention; |
| 5951 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5952 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 5953 | // that the the kPrimNot result register is the same as the first argument register. |
| 5954 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5955 | } else { |
| 5956 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5957 | } |
| 5958 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5959 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5962 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5963 | // move. |
| 5964 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5965 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5966 | Location out_loc = locations->Out(); |
| 5967 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5968 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5969 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 5970 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5971 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5972 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5973 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 5974 | load->GetStringIndex())); |
| 5975 | return; // No dex cache slow path. |
| 5976 | } |
| 5977 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5978 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5979 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5980 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5981 | __ BindTrackedLabel(&labels->movw_label); |
| 5982 | __ movw(out, /* placeholder */ 0u); |
| 5983 | __ BindTrackedLabel(&labels->movt_label); |
| 5984 | __ movt(out, /* placeholder */ 0u); |
| 5985 | __ BindTrackedLabel(&labels->add_pc_label); |
| 5986 | __ add(out, out, ShifterOperand(PC)); |
| 5987 | return; // No dex cache slow path. |
| 5988 | } |
| 5989 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 5990 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5991 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 5992 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5993 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 5994 | return; // No dex cache slow path. |
| 5995 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5996 | case HLoadString::LoadKind::kBssEntry: { |
| 5997 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5998 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5999 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6000 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6001 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6002 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6003 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6004 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6005 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6006 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6007 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6008 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6009 | codegen_->AddSlowPath(slow_path); |
| 6010 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6011 | __ Bind(slow_path->GetExitLabel()); |
| 6012 | return; |
| 6013 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6014 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6015 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6016 | load->GetStringIndex(), |
| 6017 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6018 | // /* GcRoot<mirror::String> */ out = *out |
| 6019 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6020 | return; |
| 6021 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6022 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6023 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6024 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6025 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6026 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6027 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6028 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6029 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6030 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6031 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6032 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6035 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6036 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6037 | } |
| 6038 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6039 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6040 | LocationSummary* locations = |
| 6041 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6042 | locations->SetOut(Location::RequiresRegister()); |
| 6043 | } |
| 6044 | |
| 6045 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6046 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6047 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6048 | } |
| 6049 | |
| 6050 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6051 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6052 | } |
| 6053 | |
| 6054 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6055 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6056 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6060 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6061 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6062 | InvokeRuntimeCallingConvention calling_convention; |
| 6063 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6064 | } |
| 6065 | |
| 6066 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6067 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6068 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6071 | // Temp is used for read barrier. |
| 6072 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6073 | if (kEmitCompilerReadBarrier && |
| 6074 | (kUseBakerReadBarrier || |
| 6075 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6076 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6077 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6078 | return 1; |
| 6079 | } |
| 6080 | return 0; |
| 6081 | } |
| 6082 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6083 | // 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] | 6084 | // interface pointer, one for loading the current interface. |
| 6085 | // The other checks have one temp for loading the object's class. |
| 6086 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6087 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6088 | return 3; |
| 6089 | } |
| 6090 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6091 | } |
| 6092 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6093 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6094 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6095 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6096 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6097 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6098 | case TypeCheckKind::kExactCheck: |
| 6099 | case TypeCheckKind::kAbstractClassCheck: |
| 6100 | case TypeCheckKind::kClassHierarchyCheck: |
| 6101 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6102 | call_kind = |
| 6103 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6104 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6105 | break; |
| 6106 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6107 | case TypeCheckKind::kUnresolvedCheck: |
| 6108 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6110 | break; |
| 6111 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6112 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6113 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6114 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6115 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6116 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6117 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6118 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6119 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6120 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6121 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6122 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6125 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6126 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6127 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6128 | Location obj_loc = locations->InAt(0); |
| 6129 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6130 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6131 | Location out_loc = locations->Out(); |
| 6132 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6133 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6134 | DCHECK_LE(num_temps, 1u); |
| 6135 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6136 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6137 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6138 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6139 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6140 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6141 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6142 | |
| 6143 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6144 | // avoid null check if we know obj is not null. |
| 6145 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 6146 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6147 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6148 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6149 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6150 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6151 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6152 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6153 | out_loc, |
| 6154 | obj_loc, |
| 6155 | class_offset, |
| 6156 | maybe_temp_loc, |
| 6157 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ cmp(out, ShifterOperand(cls)); |
| 6159 | // Classes must be equal for the instanceof to succeed. |
| 6160 | __ b(&zero, NE); |
| 6161 | __ LoadImmediate(out, 1); |
| 6162 | __ b(&done); |
| 6163 | break; |
| 6164 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6165 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6166 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6167 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6168 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6169 | out_loc, |
| 6170 | obj_loc, |
| 6171 | class_offset, |
| 6172 | maybe_temp_loc, |
| 6173 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6174 | // If the class is abstract, we eagerly fetch the super class of the |
| 6175 | // object to avoid doing a comparison we know will fail. |
| 6176 | Label loop; |
| 6177 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6178 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6179 | GenerateReferenceLoadOneRegister(instruction, |
| 6180 | out_loc, |
| 6181 | super_offset, |
| 6182 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6183 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6185 | __ CompareAndBranchIfZero(out, &done); |
| 6186 | __ cmp(out, ShifterOperand(cls)); |
| 6187 | __ b(&loop, NE); |
| 6188 | __ LoadImmediate(out, 1); |
| 6189 | if (zero.IsLinked()) { |
| 6190 | __ b(&done); |
| 6191 | } |
| 6192 | break; |
| 6193 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6194 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6195 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6196 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6198 | out_loc, |
| 6199 | obj_loc, |
| 6200 | class_offset, |
| 6201 | maybe_temp_loc, |
| 6202 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | // Walk over the class hierarchy to find a match. |
| 6204 | Label loop, success; |
| 6205 | __ Bind(&loop); |
| 6206 | __ cmp(out, ShifterOperand(cls)); |
| 6207 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6208 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6209 | GenerateReferenceLoadOneRegister(instruction, |
| 6210 | out_loc, |
| 6211 | super_offset, |
| 6212 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6213 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6214 | __ CompareAndBranchIfNonZero(out, &loop); |
| 6215 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6216 | __ b(&done); |
| 6217 | __ Bind(&success); |
| 6218 | __ LoadImmediate(out, 1); |
| 6219 | if (zero.IsLinked()) { |
| 6220 | __ b(&done); |
| 6221 | } |
| 6222 | break; |
| 6223 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6224 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6225 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6226 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6227 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6228 | out_loc, |
| 6229 | obj_loc, |
| 6230 | class_offset, |
| 6231 | maybe_temp_loc, |
| 6232 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6233 | // Do an exact check. |
| 6234 | Label exact_check; |
| 6235 | __ cmp(out, ShifterOperand(cls)); |
| 6236 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6237 | // 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] | 6238 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6239 | GenerateReferenceLoadOneRegister(instruction, |
| 6240 | out_loc, |
| 6241 | component_offset, |
| 6242 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6243 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6244 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6245 | __ CompareAndBranchIfZero(out, &done); |
| 6246 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 6247 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 6248 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6249 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6250 | __ LoadImmediate(out, 1); |
| 6251 | __ b(&done); |
| 6252 | break; |
| 6253 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6254 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6255 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6256 | // No read barrier since the slow path will retry upon failure. |
| 6257 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6258 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6259 | out_loc, |
| 6260 | obj_loc, |
| 6261 | class_offset, |
| 6262 | maybe_temp_loc, |
| 6263 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6264 | __ cmp(out, ShifterOperand(cls)); |
| 6265 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6266 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6267 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6268 | codegen_->AddSlowPath(slow_path); |
| 6269 | __ b(slow_path->GetEntryLabel(), NE); |
| 6270 | __ LoadImmediate(out, 1); |
| 6271 | if (zero.IsLinked()) { |
| 6272 | __ b(&done); |
| 6273 | } |
| 6274 | break; |
| 6275 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6276 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6277 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6278 | case TypeCheckKind::kInterfaceCheck: { |
| 6279 | // 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] | 6280 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6281 | // cases. |
| 6282 | // |
| 6283 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6284 | // entry point without resorting to a type checking slow path |
| 6285 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6286 | // require to assign fixed registers for the inputs of this |
| 6287 | // HInstanceOf instruction (following the runtime calling |
| 6288 | // convention), which might be cluttered by the potential first |
| 6289 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6290 | // |
| 6291 | // TODO: Introduce a new runtime entry point taking the object |
| 6292 | // to test (instead of its class) as argument, and let it deal |
| 6293 | // with the read barrier issues. This will let us refactor this |
| 6294 | // case of the `switch` code as it was previously (with a direct |
| 6295 | // call to the runtime not using a type checking slow path). |
| 6296 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6297 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6298 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6299 | /* is_fatal */ false); |
| 6300 | codegen_->AddSlowPath(slow_path); |
| 6301 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6302 | if (zero.IsLinked()) { |
| 6303 | __ b(&done); |
| 6304 | } |
| 6305 | break; |
| 6306 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6307 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6308 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6309 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6310 | __ Bind(&zero); |
| 6311 | __ LoadImmediate(out, 0); |
| 6312 | } |
| 6313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6314 | if (done.IsLinked()) { |
| 6315 | __ Bind(&done); |
| 6316 | } |
| 6317 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6318 | if (slow_path != nullptr) { |
| 6319 | __ Bind(slow_path->GetExitLabel()); |
| 6320 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6321 | } |
| 6322 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6323 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6324 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6325 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6326 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6327 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6328 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | case TypeCheckKind::kExactCheck: |
| 6330 | case TypeCheckKind::kAbstractClassCheck: |
| 6331 | case TypeCheckKind::kClassHierarchyCheck: |
| 6332 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6333 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6334 | LocationSummary::kCallOnSlowPath : |
| 6335 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6336 | break; |
| 6337 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6338 | case TypeCheckKind::kUnresolvedCheck: |
| 6339 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6340 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6341 | break; |
| 6342 | } |
| 6343 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6344 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6346 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6347 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6351 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6352 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6353 | Location obj_loc = locations->InAt(0); |
| 6354 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6355 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6356 | Location temp_loc = locations->GetTemp(0); |
| 6357 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6358 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6359 | DCHECK_LE(num_temps, 3u); |
| 6360 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 6361 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 6362 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6363 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6364 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6365 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6366 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6367 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6368 | const uint32_t object_array_data_offset = |
| 6369 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6370 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6371 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 6372 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 6373 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6374 | bool is_type_check_slow_path_fatal = false; |
| 6375 | if (!kEmitCompilerReadBarrier) { |
| 6376 | is_type_check_slow_path_fatal = |
| 6377 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6378 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6379 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6380 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6381 | !instruction->CanThrowIntoCatchBlock(); |
| 6382 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6383 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6384 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 6385 | is_type_check_slow_path_fatal); |
| 6386 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 | |
| 6388 | Label done; |
| 6389 | // Avoid null check if we know obj is not null. |
| 6390 | if (instruction->MustDoNullCheck()) { |
| 6391 | __ CompareAndBranchIfZero(obj, &done); |
| 6392 | } |
| 6393 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6394 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6395 | case TypeCheckKind::kExactCheck: |
| 6396 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6397 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6398 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6399 | temp_loc, |
| 6400 | obj_loc, |
| 6401 | class_offset, |
| 6402 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6403 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6404 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6405 | __ cmp(temp, ShifterOperand(cls)); |
| 6406 | // Jump to slow path for throwing the exception or doing a |
| 6407 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6408 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6409 | break; |
| 6410 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6411 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6412 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6413 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6414 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6415 | temp_loc, |
| 6416 | obj_loc, |
| 6417 | class_offset, |
| 6418 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6419 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6420 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6421 | // If the class is abstract, we eagerly fetch the super class of the |
| 6422 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6423 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6424 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6425 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6426 | GenerateReferenceLoadOneRegister(instruction, |
| 6427 | temp_loc, |
| 6428 | super_offset, |
| 6429 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6430 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6431 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6432 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6433 | // exception. |
| 6434 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6435 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6436 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6437 | __ cmp(temp, ShifterOperand(cls)); |
| 6438 | __ b(&loop, NE); |
| 6439 | break; |
| 6440 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6441 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6442 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6443 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6444 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6445 | temp_loc, |
| 6446 | obj_loc, |
| 6447 | class_offset, |
| 6448 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6449 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6450 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6451 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6452 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6453 | __ Bind(&loop); |
| 6454 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6455 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6456 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6457 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6458 | GenerateReferenceLoadOneRegister(instruction, |
| 6459 | temp_loc, |
| 6460 | super_offset, |
| 6461 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6462 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6463 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6464 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6465 | // exception. |
| 6466 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6467 | // Otherwise, jump to the beginning of the loop. |
| 6468 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6469 | break; |
| 6470 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6471 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6472 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6473 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6474 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6475 | temp_loc, |
| 6476 | obj_loc, |
| 6477 | class_offset, |
| 6478 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6479 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6480 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6481 | // Do an exact check. |
| 6482 | __ cmp(temp, ShifterOperand(cls)); |
| 6483 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6484 | |
| 6485 | // 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] | 6486 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6487 | GenerateReferenceLoadOneRegister(instruction, |
| 6488 | temp_loc, |
| 6489 | component_offset, |
| 6490 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6491 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6492 | // If the component type is null, jump to the slow path to throw the exception. |
| 6493 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 6494 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 6495 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6496 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6497 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6498 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6499 | break; |
| 6500 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6501 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6502 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6503 | // 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] | 6504 | // We cannot directly call the CheckCast runtime entry point |
| 6505 | // without resorting to a type checking slow path here (i.e. by |
| 6506 | // calling InvokeRuntime directly), as it would require to |
| 6507 | // assign fixed registers for the inputs of this HInstanceOf |
| 6508 | // instruction (following the runtime calling convention), which |
| 6509 | // might be cluttered by the potential first read barrier |
| 6510 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6511 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6512 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6513 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6514 | |
| 6515 | case TypeCheckKind::kInterfaceCheck: { |
| 6516 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 6517 | // positives by doing this. |
| 6518 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6519 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6520 | temp_loc, |
| 6521 | obj_loc, |
| 6522 | class_offset, |
| 6523 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6524 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6525 | |
| 6526 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6527 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6528 | temp_loc, |
| 6529 | temp_loc, |
| 6530 | iftable_offset, |
| 6531 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6532 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6533 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6534 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 6535 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6536 | Label start_loop; |
| 6537 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6538 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 6539 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6540 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 6541 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6542 | // Go to next interface. |
| 6543 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 6544 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 6545 | maybe_temp2_loc.AsRegister<Register>(), |
| 6546 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 6547 | // Compare the classes and continue the loop if they do not match. |
| 6548 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 6549 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6550 | break; |
| 6551 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6552 | } |
| 6553 | __ Bind(&done); |
| 6554 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6555 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6556 | } |
| 6557 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6558 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6559 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6560 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6561 | InvokeRuntimeCallingConvention calling_convention; |
| 6562 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6563 | } |
| 6564 | |
| 6565 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6566 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 6567 | instruction, |
| 6568 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6569 | if (instruction->IsEnter()) { |
| 6570 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6571 | } else { |
| 6572 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6573 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6576 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 6577 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 6578 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6579 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6580 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6581 | LocationSummary* locations = |
| 6582 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6583 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6584 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6585 | // 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] | 6586 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6587 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 6588 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 6592 | HandleBitwiseOperation(instruction); |
| 6593 | } |
| 6594 | |
| 6595 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 6596 | HandleBitwiseOperation(instruction); |
| 6597 | } |
| 6598 | |
| 6599 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 6600 | HandleBitwiseOperation(instruction); |
| 6601 | } |
| 6602 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 6603 | |
| 6604 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6605 | LocationSummary* locations = |
| 6606 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6607 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6608 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6609 | |
| 6610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6611 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6613 | } |
| 6614 | |
| 6615 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 6616 | LocationSummary* locations = instruction->GetLocations(); |
| 6617 | Location first = locations->InAt(0); |
| 6618 | Location second = locations->InAt(1); |
| 6619 | Location out = locations->Out(); |
| 6620 | |
| 6621 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6622 | Register first_reg = first.AsRegister<Register>(); |
| 6623 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6624 | Register out_reg = out.AsRegister<Register>(); |
| 6625 | |
| 6626 | switch (instruction->GetOpKind()) { |
| 6627 | case HInstruction::kAnd: |
| 6628 | __ bic(out_reg, first_reg, second_reg); |
| 6629 | break; |
| 6630 | case HInstruction::kOr: |
| 6631 | __ orn(out_reg, first_reg, second_reg); |
| 6632 | break; |
| 6633 | // There is no EON on arm. |
| 6634 | case HInstruction::kXor: |
| 6635 | default: |
| 6636 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6637 | UNREACHABLE(); |
| 6638 | } |
| 6639 | return; |
| 6640 | |
| 6641 | } else { |
| 6642 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6643 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6644 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6645 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6646 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6647 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6648 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6649 | |
| 6650 | switch (instruction->GetOpKind()) { |
| 6651 | case HInstruction::kAnd: |
| 6652 | __ bic(out_low, first_low, second_low); |
| 6653 | __ bic(out_high, first_high, second_high); |
| 6654 | break; |
| 6655 | case HInstruction::kOr: |
| 6656 | __ orn(out_low, first_low, second_low); |
| 6657 | __ orn(out_high, first_high, second_high); |
| 6658 | break; |
| 6659 | // There is no EON on arm. |
| 6660 | case HInstruction::kXor: |
| 6661 | default: |
| 6662 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 6663 | UNREACHABLE(); |
| 6664 | } |
| 6665 | } |
| 6666 | } |
| 6667 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6668 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 6669 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 6670 | if (value == 0xffffffffu) { |
| 6671 | if (out != first) { |
| 6672 | __ mov(out, ShifterOperand(first)); |
| 6673 | } |
| 6674 | return; |
| 6675 | } |
| 6676 | if (value == 0u) { |
| 6677 | __ mov(out, ShifterOperand(0)); |
| 6678 | return; |
| 6679 | } |
| 6680 | ShifterOperand so; |
| 6681 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 6682 | __ and_(out, first, so); |
| 6683 | } else { |
| 6684 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 6685 | __ bic(out, first, ShifterOperand(~value)); |
| 6686 | } |
| 6687 | } |
| 6688 | |
| 6689 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 6690 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 6691 | if (value == 0u) { |
| 6692 | if (out != first) { |
| 6693 | __ mov(out, ShifterOperand(first)); |
| 6694 | } |
| 6695 | return; |
| 6696 | } |
| 6697 | if (value == 0xffffffffu) { |
| 6698 | __ mvn(out, ShifterOperand(0)); |
| 6699 | return; |
| 6700 | } |
| 6701 | ShifterOperand so; |
| 6702 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 6703 | __ orr(out, first, so); |
| 6704 | } else { |
| 6705 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 6706 | __ orn(out, first, ShifterOperand(~value)); |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 6711 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 6712 | if (value == 0u) { |
| 6713 | if (out != first) { |
| 6714 | __ mov(out, ShifterOperand(first)); |
| 6715 | } |
| 6716 | return; |
| 6717 | } |
| 6718 | __ eor(out, first, ShifterOperand(value)); |
| 6719 | } |
| 6720 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 6721 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 6722 | Location first, |
| 6723 | uint64_t value) { |
| 6724 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6725 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6726 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6727 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6728 | uint32_t value_low = Low32Bits(value); |
| 6729 | uint32_t value_high = High32Bits(value); |
| 6730 | if (value_low == 0u) { |
| 6731 | if (out_low != first_low) { |
| 6732 | __ mov(out_low, ShifterOperand(first_low)); |
| 6733 | } |
| 6734 | __ AddConstant(out_high, first_high, value_high); |
| 6735 | return; |
| 6736 | } |
| 6737 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 6738 | ShifterOperand so; |
| 6739 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 6740 | __ adc(out_high, first_high, so); |
| 6741 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 6742 | __ sbc(out_high, first_high, so); |
| 6743 | } else { |
| 6744 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 6745 | UNREACHABLE(); |
| 6746 | } |
| 6747 | } |
| 6748 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6749 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6750 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6751 | Location first = locations->InAt(0); |
| 6752 | Location second = locations->InAt(1); |
| 6753 | Location out = locations->Out(); |
| 6754 | |
| 6755 | if (second.IsConstant()) { |
| 6756 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 6757 | uint32_t value_low = Low32Bits(value); |
| 6758 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6759 | Register first_reg = first.AsRegister<Register>(); |
| 6760 | Register out_reg = out.AsRegister<Register>(); |
| 6761 | if (instruction->IsAnd()) { |
| 6762 | GenerateAndConst(out_reg, first_reg, value_low); |
| 6763 | } else if (instruction->IsOr()) { |
| 6764 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 6765 | } else { |
| 6766 | DCHECK(instruction->IsXor()); |
| 6767 | GenerateEorConst(out_reg, first_reg, value_low); |
| 6768 | } |
| 6769 | } else { |
| 6770 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6771 | uint32_t value_high = High32Bits(value); |
| 6772 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6773 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6774 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6775 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 6776 | if (instruction->IsAnd()) { |
| 6777 | GenerateAndConst(out_low, first_low, value_low); |
| 6778 | GenerateAndConst(out_high, first_high, value_high); |
| 6779 | } else if (instruction->IsOr()) { |
| 6780 | GenerateOrrConst(out_low, first_low, value_low); |
| 6781 | GenerateOrrConst(out_high, first_high, value_high); |
| 6782 | } else { |
| 6783 | DCHECK(instruction->IsXor()); |
| 6784 | GenerateEorConst(out_low, first_low, value_low); |
| 6785 | GenerateEorConst(out_high, first_high, value_high); |
| 6786 | } |
| 6787 | } |
| 6788 | return; |
| 6789 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6790 | |
| 6791 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6792 | Register first_reg = first.AsRegister<Register>(); |
| 6793 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 6794 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6795 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6796 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6797 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6798 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6799 | } else { |
| 6800 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6801 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6802 | } |
| 6803 | } else { |
| 6804 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6805 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6806 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 6807 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 6808 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 6809 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 6810 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6811 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6812 | __ and_(out_low, first_low, second_low); |
| 6813 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6814 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6815 | __ orr(out_low, first_low, second_low); |
| 6816 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6817 | } else { |
| 6818 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 6819 | __ eor(out_low, first_low, second_low); |
| 6820 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6821 | } |
| 6822 | } |
| 6823 | } |
| 6824 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6825 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 6826 | HInstruction* instruction, |
| 6827 | Location out, |
| 6828 | uint32_t offset, |
| 6829 | Location maybe_temp, |
| 6830 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6831 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6832 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6833 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6834 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6835 | if (kUseBakerReadBarrier) { |
| 6836 | // Load with fast path based Baker's read barrier. |
| 6837 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6838 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6839 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6840 | } else { |
| 6841 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6842 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6843 | // in the following move operation, as we will need it for the |
| 6844 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6845 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6846 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6847 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6848 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6849 | } |
| 6850 | } else { |
| 6851 | // Plain load with no read barrier. |
| 6852 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6853 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 6854 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6855 | } |
| 6856 | } |
| 6857 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6858 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 6859 | HInstruction* instruction, |
| 6860 | Location out, |
| 6861 | Location obj, |
| 6862 | uint32_t offset, |
| 6863 | Location maybe_temp, |
| 6864 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6865 | Register out_reg = out.AsRegister<Register>(); |
| 6866 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6867 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6868 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6869 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6870 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6871 | // Load with fast path based Baker's read barrier. |
| 6872 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6873 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6874 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6875 | } else { |
| 6876 | // Load with slow path based read barrier. |
| 6877 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6878 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6879 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6880 | } |
| 6881 | } else { |
| 6882 | // Plain load with no read barrier. |
| 6883 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6884 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 6885 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6886 | } |
| 6887 | } |
| 6888 | |
| 6889 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6890 | Location root, |
| 6891 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6892 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6893 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6894 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6895 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6896 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6897 | if (kUseBakerReadBarrier) { |
| 6898 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6899 | // Baker's read barrier are used: |
| 6900 | // |
| 6901 | // root = obj.field; |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6902 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6903 | // if (temp != null) { |
| 6904 | // root = temp(root) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6905 | // } |
| 6906 | |
| 6907 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6908 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6909 | static_assert( |
| 6910 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6911 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6912 | "have different sizes."); |
| 6913 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6914 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6915 | "have different sizes."); |
| 6916 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6917 | // Slow path marking the GC root `root`. |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6918 | Location temp = Location::RegisterLocation(LR); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6919 | SlowPathCodeARM* slow_path = |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6920 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 6921 | instruction, |
| 6922 | root, |
| 6923 | /*entrypoint*/ temp); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6924 | codegen_->AddSlowPath(slow_path); |
| 6925 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 6926 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6927 | const int32_t entry_point_offset = |
| 6928 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 6929 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 6930 | // threads are suspended or running a checkpoint. |
| 6931 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 6932 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 6933 | // checking GetIsGcMarking. |
| 6934 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6935 | __ Bind(slow_path->GetExitLabel()); |
| 6936 | } else { |
| 6937 | // GC root loaded through a slow path for read barriers other |
| 6938 | // than Baker's. |
| 6939 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6940 | __ AddConstant(root_reg, obj, offset); |
| 6941 | // /* mirror::Object* */ root = root->Read() |
| 6942 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6943 | } |
| 6944 | } else { |
| 6945 | // Plain GC root load with no read barrier. |
| 6946 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6947 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 6948 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6949 | // do not have to unpoison `root_reg` here. |
| 6950 | } |
| 6951 | } |
| 6952 | |
| 6953 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6954 | Location ref, |
| 6955 | Register obj, |
| 6956 | uint32_t offset, |
| 6957 | Location temp, |
| 6958 | bool needs_null_check) { |
| 6959 | DCHECK(kEmitCompilerReadBarrier); |
| 6960 | DCHECK(kUseBakerReadBarrier); |
| 6961 | |
| 6962 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6963 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6964 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6965 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6966 | 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] | 6967 | } |
| 6968 | |
| 6969 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6970 | Location ref, |
| 6971 | Register obj, |
| 6972 | uint32_t data_offset, |
| 6973 | Location index, |
| 6974 | Location temp, |
| 6975 | bool needs_null_check) { |
| 6976 | DCHECK(kEmitCompilerReadBarrier); |
| 6977 | DCHECK(kUseBakerReadBarrier); |
| 6978 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6979 | static_assert( |
| 6980 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6981 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6982 | // /* HeapReference<Object> */ ref = |
| 6983 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6984 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6985 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6986 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6990 | Location ref, |
| 6991 | Register obj, |
| 6992 | uint32_t offset, |
| 6993 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 6994 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6995 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6996 | bool needs_null_check, |
| 6997 | bool always_update_field, |
| 6998 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6999 | DCHECK(kEmitCompilerReadBarrier); |
| 7000 | DCHECK(kUseBakerReadBarrier); |
| 7001 | |
| 7002 | // In slow path based read barriers, the read barrier call is |
| 7003 | // inserted after the original load. However, in fast path based |
| 7004 | // Baker's read barriers, we need to perform the load of |
| 7005 | // mirror::Object::monitor_ *before* the original reference load. |
| 7006 | // This load-load ordering is required by the read barrier. |
| 7007 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7008 | // |
| 7009 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7010 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7011 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7012 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7013 | // if (is_gray) { |
| 7014 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7015 | // } |
| 7016 | // |
| 7017 | // Note: the original implementation in ReadBarrier::Barrier is |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7018 | // slightly more complex as it performs additional checks that we do |
| 7019 | // not do here for performance reasons. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7020 | |
| 7021 | Register ref_reg = ref.AsRegister<Register>(); |
| 7022 | Register temp_reg = temp.AsRegister<Register>(); |
| 7023 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7024 | |
| 7025 | // /* int32_t */ monitor = obj->monitor_ |
| 7026 | __ LoadFromOffset(kLoadWord, temp_reg, obj, monitor_offset); |
| 7027 | if (needs_null_check) { |
| 7028 | MaybeRecordImplicitNullCheck(instruction); |
| 7029 | } |
| 7030 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7031 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7032 | "art::LockWord and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7033 | |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7034 | // Introduce a dependency on the lock_word including the rb_state, |
| 7035 | // which shall prevent load-load reordering without using |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7036 | // a memory barrier (which would be more expensive). |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 7037 | // `obj` is unchanged by this operation, but its value now depends |
| 7038 | // on `temp_reg`. |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7039 | __ add(obj, obj, ShifterOperand(temp_reg, LSR, 32)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7040 | |
| 7041 | // The actual reference load. |
| 7042 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7043 | // Load types involving an "index": ArrayGet, |
| 7044 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7045 | // intrinsics. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7046 | // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7047 | if (index.IsConstant()) { |
| 7048 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7049 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7050 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 7051 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7052 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7053 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 7054 | // intrinsics, which use a register pair as index ("long |
| 7055 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7056 | Register index_reg = index.IsRegisterPair() |
| 7057 | ? index.AsRegisterPairLow<Register>() |
| 7058 | : index.AsRegister<Register>(); |
| 7059 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7060 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 7061 | } |
| 7062 | } else { |
| 7063 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7064 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 7065 | } |
| 7066 | |
| 7067 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7068 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7069 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7070 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7071 | SlowPathCodeARM* slow_path; |
| 7072 | if (always_update_field) { |
| 7073 | DCHECK(temp2 != nullptr); |
| 7074 | // ReadBarrierMarkAndUpdateFieldSlowPathARM only supports address |
| 7075 | // of the form `obj + field_offset`, where `obj` is a register and |
| 7076 | // `field_offset` is a register pair (of which only the lower half |
| 7077 | // is used). Thus `offset` and `scale_factor` above are expected |
| 7078 | // to be null in this code path. |
| 7079 | DCHECK_EQ(offset, 0u); |
| 7080 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
| 7081 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM( |
| 7082 | instruction, ref, obj, /* field_offset */ index, temp_reg, *temp2); |
| 7083 | } else { |
| 7084 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM(instruction, ref); |
| 7085 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7086 | AddSlowPath(slow_path); |
| 7087 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7088 | // if (rb_state == ReadBarrier::GrayState()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7089 | // ref = ReadBarrier::Mark(ref); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7090 | // Given the numeric representation, it's enough to check the low bit of the |
| 7091 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 7092 | // which can be a 16-bit instruction unlike the TST immediate. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7093 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7094 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 194bcfe | 2016-07-11 15:52:00 +0100 | [diff] [blame] | 7095 | __ Lsrs(temp_reg, temp_reg, LockWord::kReadBarrierStateShift + 1); |
| 7096 | __ b(slow_path->GetEntryLabel(), CS); // Carry flag is the last bit shifted out by LSRS. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7097 | __ Bind(slow_path->GetExitLabel()); |
| 7098 | } |
| 7099 | |
| 7100 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7101 | Location out, |
| 7102 | Location ref, |
| 7103 | Location obj, |
| 7104 | uint32_t offset, |
| 7105 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7106 | DCHECK(kEmitCompilerReadBarrier); |
| 7107 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7108 | // Insert a slow path based read barrier *after* the reference load. |
| 7109 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7110 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7111 | // reference will be carried out by the runtime within the slow |
| 7112 | // path. |
| 7113 | // |
| 7114 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7115 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7116 | // not used by the artReadBarrierSlow entry point. |
| 7117 | // |
| 7118 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7119 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7120 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 7121 | AddSlowPath(slow_path); |
| 7122 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7123 | __ b(slow_path->GetEntryLabel()); |
| 7124 | __ Bind(slow_path->GetExitLabel()); |
| 7125 | } |
| 7126 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7127 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7128 | Location out, |
| 7129 | Location ref, |
| 7130 | Location obj, |
| 7131 | uint32_t offset, |
| 7132 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7133 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7134 | // Baker's read barriers shall be handled by the fast path |
| 7135 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 7136 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7137 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7138 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7139 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7140 | } else if (kPoisonHeapReferences) { |
| 7141 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7142 | } |
| 7143 | } |
| 7144 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7145 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7146 | Location out, |
| 7147 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7148 | DCHECK(kEmitCompilerReadBarrier); |
| 7149 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7150 | // Insert a slow path based read barrier *after* the GC root load. |
| 7151 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7152 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7153 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7154 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7155 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 7156 | AddSlowPath(slow_path); |
| 7157 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7158 | __ b(slow_path->GetEntryLabel()); |
| 7159 | __ Bind(slow_path->GetExitLabel()); |
| 7160 | } |
| 7161 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7162 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 7163 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 7164 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 7165 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 7166 | } |
| 7167 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7168 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 7169 | Register temp) { |
| 7170 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 7171 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 7172 | if (!invoke->GetLocations()->Intrinsified()) { |
| 7173 | return location.AsRegister<Register>(); |
| 7174 | } |
| 7175 | // For intrinsics we allow any location, so it may be on the stack. |
| 7176 | if (!location.IsRegister()) { |
| 7177 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 7178 | return temp; |
| 7179 | } |
| 7180 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 7181 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 7182 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 7183 | // simple and more robust approach rather that trying to determine if that's the case. |
| 7184 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7185 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7186 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 7187 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 7188 | return temp; |
| 7189 | } |
| 7190 | return location.AsRegister<Register>(); |
| 7191 | } |
| 7192 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7193 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 7194 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7195 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 7196 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7197 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 7198 | uint32_t offset = |
| 7199 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7200 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7201 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7202 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 7203 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7204 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7205 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7206 | break; |
| 7207 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 7208 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 7209 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7210 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 7211 | HArmDexCacheArraysBase* base = |
| 7212 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 7213 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 7214 | temp.AsRegister<Register>()); |
| 7215 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 7216 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 7217 | break; |
| 7218 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7219 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 7220 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7221 | Register method_reg; |
| 7222 | Register reg = temp.AsRegister<Register>(); |
| 7223 | if (current_method.IsRegister()) { |
| 7224 | method_reg = current_method.AsRegister<Register>(); |
| 7225 | } else { |
| 7226 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 7227 | DCHECK(!current_method.IsValid()); |
| 7228 | method_reg = reg; |
| 7229 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 7230 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7231 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 7232 | __ LoadFromOffset(kLoadWord, |
| 7233 | reg, |
| 7234 | method_reg, |
| 7235 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 7236 | // temp = temp[index_in_cache]; |
| 7237 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 7238 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7239 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 7240 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 7241 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7242 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 7243 | return callee_method; |
| 7244 | } |
| 7245 | |
| 7246 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 7247 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7248 | |
| 7249 | switch (invoke->GetCodePtrLocation()) { |
| 7250 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 7251 | __ bl(GetFrameEntryLabel()); |
| 7252 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7253 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 7254 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 7255 | __ LoadFromOffset( |
| 7256 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7257 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7258 | // LR() |
| 7259 | __ blx(LR); |
| 7260 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7261 | } |
| 7262 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 7263 | DCHECK(!IsLeafMethod()); |
| 7264 | } |
| 7265 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7266 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 7267 | Register temp = temp_location.AsRegister<Register>(); |
| 7268 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 7269 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7270 | |
| 7271 | // Use the calling convention instead of the location of the receiver, as |
| 7272 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 7273 | // slow path, the arguments have been moved to the right place, so here we are |
| 7274 | // guaranteed that the receiver is the first register of the calling convention. |
| 7275 | InvokeDexCallingConvention calling_convention; |
| 7276 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7277 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7278 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 7279 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7280 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7281 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 7282 | // emit a read barrier for the previous class reference load. |
| 7283 | // However this is not required in practice, as this is an |
| 7284 | // intermediate/temporary reference and because the current |
| 7285 | // concurrent copying collector keeps the from-space memory |
| 7286 | // intact/accessible until the end of the marking phase (the |
| 7287 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7288 | __ MaybeUnpoisonHeapReference(temp); |
| 7289 | // temp = temp->GetMethodAt(method_offset); |
| 7290 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 7291 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 7292 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 7293 | // LR = temp->GetEntryPoint(); |
| 7294 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 7295 | // LR(); |
| 7296 | __ blx(LR); |
| 7297 | } |
| 7298 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7299 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7300 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 7301 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7302 | } |
| 7303 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7304 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7305 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7306 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7307 | } |
| 7308 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7309 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 7310 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 7311 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 7312 | } |
| 7313 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7314 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 7315 | const DexFile& dex_file, uint32_t element_offset) { |
| 7316 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 7317 | } |
| 7318 | |
| 7319 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 7320 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 7321 | patches->emplace_back(dex_file, offset_or_index); |
| 7322 | return &patches->back(); |
| 7323 | } |
| 7324 | |
| 7325 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7326 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7327 | return boot_image_string_patches_.GetOrCreate( |
| 7328 | StringReference(&dex_file, string_index), |
| 7329 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7330 | } |
| 7331 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7332 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7333 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7334 | return boot_image_type_patches_.GetOrCreate( |
| 7335 | TypeReference(&dex_file, type_index), |
| 7336 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7337 | } |
| 7338 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7339 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| 7340 | bool needs_patch = GetCompilerOptions().GetIncludePatchInformation(); |
| 7341 | Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_; |
| 7342 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map); |
| 7343 | } |
| 7344 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7345 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7346 | dex::StringIndex string_index, |
| 7347 | Handle<mirror::String> handle) { |
| 7348 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 7349 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7350 | return jit_string_patches_.GetOrCreate( |
| 7351 | StringReference(&dex_file, string_index), |
| 7352 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7353 | } |
| 7354 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7355 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 7356 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7357 | Handle<mirror::Class> handle) { |
| 7358 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 7359 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7360 | return jit_class_patches_.GetOrCreate( |
| 7361 | TypeReference(&dex_file, type_index), |
| 7362 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 7363 | } |
| 7364 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7365 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 7366 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 7367 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 7368 | ArenaVector<LinkerPatch>* linker_patches) { |
| 7369 | for (const PcRelativePatchInfo& info : infos) { |
| 7370 | const DexFile& dex_file = info.target_dex_file; |
| 7371 | size_t offset_or_index = info.offset_or_index; |
| 7372 | DCHECK(info.add_pc_label.IsBound()); |
| 7373 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 7374 | // Add MOVW patch. |
| 7375 | DCHECK(info.movw_label.IsBound()); |
| 7376 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 7377 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7378 | // Add MOVT patch. |
| 7379 | DCHECK(info.movt_label.IsBound()); |
| 7380 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 7381 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 7382 | } |
| 7383 | } |
| 7384 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7385 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 7386 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7387 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7388 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7389 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7390 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7391 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7392 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7393 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7394 | boot_image_address_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7395 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7396 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 7397 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7398 | for (const auto& entry : boot_image_string_patches_) { |
| 7399 | const StringReference& target_string = entry.first; |
| 7400 | Literal* literal = entry.second; |
| 7401 | DCHECK(literal->GetLabel()->IsBound()); |
| 7402 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7403 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 7404 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7405 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7406 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7407 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7408 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7409 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 7410 | linker_patches); |
| 7411 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7412 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 7413 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 7414 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 7415 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7416 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7417 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 7418 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7419 | for (const auto& entry : boot_image_type_patches_) { |
| 7420 | const TypeReference& target_type = entry.first; |
| 7421 | Literal* literal = entry.second; |
| 7422 | DCHECK(literal->GetLabel()->IsBound()); |
| 7423 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7424 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 7425 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 7426 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 7427 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7428 | for (const auto& entry : boot_image_address_patches_) { |
| 7429 | DCHECK(GetCompilerOptions().GetIncludePatchInformation()); |
| 7430 | Literal* literal = entry.second; |
| 7431 | DCHECK(literal->GetLabel()->IsBound()); |
| 7432 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7433 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 7434 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7435 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7436 | } |
| 7437 | |
| 7438 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 7439 | return map->GetOrCreate( |
| 7440 | value, |
| 7441 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7442 | } |
| 7443 | |
| 7444 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 7445 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7446 | return map->GetOrCreate( |
| 7447 | target_method, |
| 7448 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 7449 | } |
| 7450 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7451 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7452 | LocationSummary* locations = |
| 7453 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 7454 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 7455 | Location::RequiresRegister()); |
| 7456 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 7457 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 7458 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7459 | } |
| 7460 | |
| 7461 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 7462 | LocationSummary* locations = instr->GetLocations(); |
| 7463 | Register res = locations->Out().AsRegister<Register>(); |
| 7464 | Register accumulator = |
| 7465 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 7466 | Register mul_left = |
| 7467 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 7468 | Register mul_right = |
| 7469 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 7470 | |
| 7471 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 7472 | __ mla(res, mul_left, mul_right, accumulator); |
| 7473 | } else { |
| 7474 | __ mls(res, mul_left, mul_right, accumulator); |
| 7475 | } |
| 7476 | } |
| 7477 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7478 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7479 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7480 | LOG(FATAL) << "Unreachable"; |
| 7481 | } |
| 7482 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7483 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7484 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7485 | LOG(FATAL) << "Unreachable"; |
| 7486 | } |
| 7487 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7488 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7489 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7490 | LocationSummary* locations = |
| 7491 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7492 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7493 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7494 | codegen_->GetAssembler()->IsThumb()) { |
| 7495 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 7496 | if (switch_instr->GetStartValue() != 0) { |
| 7497 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 7498 | } |
| 7499 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7503 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7504 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7505 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7506 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7507 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7508 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7509 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7510 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7511 | Register temp_reg = IP; |
| 7512 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 7513 | // the immediate, because IP is used as the destination register. For the other |
| 7514 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 7515 | // and they can be encoded in the instruction without making use of IP register. |
| 7516 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 7517 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7518 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7519 | // Jump to successors[0] if value == lower_bound. |
| 7520 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 7521 | int32_t last_index = 0; |
| 7522 | for (; num_entries - last_index > 2; last_index += 2) { |
| 7523 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 7524 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 7525 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 7526 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 7527 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 7528 | } |
| 7529 | if (num_entries - last_index == 2) { |
| 7530 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 7531 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7532 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7533 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7534 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 7535 | // And the default for any other value. |
| 7536 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7537 | __ b(codegen_->GetLabelOf(default_block)); |
| 7538 | } |
| 7539 | } else { |
| 7540 | // Create a table lookup. |
| 7541 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7542 | |
| 7543 | // Materialize a pointer to the switch table |
| 7544 | std::vector<Label*> labels(num_entries); |
| 7545 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7546 | for (uint32_t i = 0; i < num_entries; i++) { |
| 7547 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 7548 | } |
| 7549 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 7550 | |
| 7551 | // Remove the bias. |
| 7552 | Register key_reg; |
| 7553 | if (lower_bound != 0) { |
| 7554 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 7555 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 7556 | } else { |
| 7557 | key_reg = value_reg; |
| 7558 | } |
| 7559 | |
| 7560 | // Check whether the value is in the table, jump to default block if not. |
| 7561 | __ CmpConstant(key_reg, num_entries - 1); |
| 7562 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 7563 | |
| 7564 | // Load the displacement from the table. |
| 7565 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 7566 | |
| 7567 | // Dispatch is a direct add to the PC (for Thumb2). |
| 7568 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7569 | } |
| 7570 | } |
| 7571 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7572 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7573 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 7574 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7575 | } |
| 7576 | |
| 7577 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 7578 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7579 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 7580 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7581 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7582 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7583 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7584 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 7585 | __ BindTrackedLabel(&labels->add_pc_label); |
| 7586 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 7587 | } |
| 7588 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7589 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7590 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7591 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7592 | return; |
| 7593 | } |
| 7594 | |
| 7595 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7596 | |
| 7597 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 7598 | if (return_loc.Equals(trg)) { |
| 7599 | return; |
| 7600 | } |
| 7601 | |
| 7602 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7603 | // with the last branch. |
| 7604 | if (type == Primitive::kPrimLong) { |
| 7605 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7606 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 7607 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7608 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7609 | } else if (type == Primitive::kPrimDouble) { |
| 7610 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7611 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 7612 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 7613 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7614 | } else { |
| 7615 | // Let the parallel move resolver take care of all of this. |
| 7616 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7617 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7618 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7619 | } |
| 7620 | } |
| 7621 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7622 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7623 | LocationSummary* locations = |
| 7624 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7625 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7626 | locations->SetOut(Location::RequiresRegister()); |
| 7627 | } |
| 7628 | |
| 7629 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 7630 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7631 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7632 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7633 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7634 | __ LoadFromOffset(kLoadWord, |
| 7635 | locations->Out().AsRegister<Register>(), |
| 7636 | locations->InAt(0).AsRegister<Register>(), |
| 7637 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7638 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7639 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 7640 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 7641 | __ LoadFromOffset(kLoadWord, |
| 7642 | locations->Out().AsRegister<Register>(), |
| 7643 | locations->InAt(0).AsRegister<Register>(), |
| 7644 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 7645 | __ LoadFromOffset(kLoadWord, |
| 7646 | locations->Out().AsRegister<Register>(), |
| 7647 | locations->Out().AsRegister<Register>(), |
| 7648 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7649 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 7650 | } |
| 7651 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7652 | static void PatchJitRootUse(uint8_t* code, |
| 7653 | const uint8_t* roots_data, |
| 7654 | Literal* literal, |
| 7655 | uint64_t index_in_table) { |
| 7656 | DCHECK(literal->GetLabel()->IsBound()); |
| 7657 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 7658 | uintptr_t address = |
| 7659 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7660 | uint8_t* data = code + literal_offset; |
| 7661 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 7662 | } |
| 7663 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7664 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7665 | for (const auto& entry : jit_string_patches_) { |
| 7666 | const auto& it = jit_string_roots_.find(entry.first); |
| 7667 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7668 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 7669 | } |
| 7670 | for (const auto& entry : jit_class_patches_) { |
| 7671 | const auto& it = jit_class_roots_.find(entry.first); |
| 7672 | DCHECK(it != jit_class_roots_.end()); |
| 7673 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7674 | } |
| 7675 | } |
| 7676 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7677 | #undef __ |
| 7678 | #undef QUICK_ENTRY_POINT |
| 7679 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7680 | } // namespace arm |
| 7681 | } // namespace art |