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" |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 22 | #include "common_arm.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_arm.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | #include "utils/arm/assembler_arm.h" |
| 32 | #include "utils/arm/managed_register_arm.h" |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 33 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 34 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace arm { |
| 42 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 43 | static bool ExpectedPairLayout(Location location) { |
| 44 | // We expected this for both core and fpu register pairs. |
| 45 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 46 | } |
| 47 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 49 | static constexpr Register kMethodRegisterArgument = R0; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 50 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 51 | static constexpr Register kCoreAlwaysSpillRegister = R5; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 52 | static constexpr Register kCoreCalleeSaves[] = |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 53 | { R5, R6, R7, R8, R10, R11, LR }; |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 54 | static constexpr SRegister kFpuCalleeSaves[] = |
| 55 | { 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] | 56 | |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 57 | // D31 cannot be split into two S registers, and the register allocator only works on |
| 58 | // S registers. Therefore there is no need to block it. |
| 59 | static constexpr DRegister DTMP = D31; |
| 60 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 61 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 62 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 63 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 64 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 65 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 67 | static constexpr int kRegListThreshold = 4; |
| 68 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 69 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 70 | // for each live D registers they treat two corresponding S registers as live ones. |
| 71 | // |
| 72 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 73 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 74 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 75 | // - decreasing code size |
| 76 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 77 | // restored and then used in regular non SlowPath code as D register. |
| 78 | // |
| 79 | // For the following example (v means the S register is live): |
| 80 | // D names: | D0 | D1 | D2 | D4 | ... |
| 81 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 82 | // Live? | | v | v | v | v | v | v | | ... |
| 83 | // |
| 84 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 85 | // as D registers. |
| 86 | static size_t SaveContiguousSRegisterList(size_t first, |
| 87 | size_t last, |
| 88 | CodeGenerator* codegen, |
| 89 | size_t stack_offset) { |
| 90 | DCHECK_LE(first, last); |
| 91 | if ((first == last) && (first == 0)) { |
| 92 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first); |
| 93 | return stack_offset; |
| 94 | } |
| 95 | if (first % 2 == 1) { |
| 96 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, first++); |
| 97 | } |
| 98 | |
| 99 | bool save_last = false; |
| 100 | if (last % 2 == 0) { |
| 101 | save_last = true; |
| 102 | --last; |
| 103 | } |
| 104 | |
| 105 | if (first < last) { |
| 106 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 107 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 108 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 109 | |
| 110 | if (number_of_d_regs == 1) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 111 | __ StoreDToOffset(d_reg, SP, stack_offset); |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 112 | } else if (number_of_d_regs > 1) { |
| 113 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 114 | __ vstmiad(IP, d_reg, number_of_d_regs); |
| 115 | } |
| 116 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 117 | } |
| 118 | |
| 119 | if (save_last) { |
| 120 | stack_offset += codegen->SaveFloatingPointRegister(stack_offset, last + 1); |
| 121 | } |
| 122 | |
| 123 | return stack_offset; |
| 124 | } |
| 125 | |
| 126 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 127 | size_t last, |
| 128 | CodeGenerator* codegen, |
| 129 | size_t stack_offset) { |
| 130 | DCHECK_LE(first, last); |
| 131 | if ((first == last) && (first == 0)) { |
| 132 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first); |
| 133 | return stack_offset; |
| 134 | } |
| 135 | if (first % 2 == 1) { |
| 136 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, first++); |
| 137 | } |
| 138 | |
| 139 | bool restore_last = false; |
| 140 | if (last % 2 == 0) { |
| 141 | restore_last = true; |
| 142 | --last; |
| 143 | } |
| 144 | |
| 145 | if (first < last) { |
| 146 | DRegister d_reg = static_cast<DRegister>(first / 2); |
| 147 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 148 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 149 | if (number_of_d_regs == 1) { |
| 150 | __ LoadDFromOffset(d_reg, SP, stack_offset); |
| 151 | } else if (number_of_d_regs > 1) { |
| 152 | __ add(IP, SP, ShifterOperand(stack_offset)); |
| 153 | __ vldmiad(IP, d_reg, number_of_d_regs); |
| 154 | } |
| 155 | stack_offset += number_of_d_regs * kArmWordSize * 2; |
| 156 | } |
| 157 | |
| 158 | if (restore_last) { |
| 159 | stack_offset += codegen->RestoreFloatingPointRegister(stack_offset, last + 1); |
| 160 | } |
| 161 | |
| 162 | return stack_offset; |
| 163 | } |
| 164 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 165 | void SlowPathCodeARM::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 166 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 167 | size_t orig_offset = stack_offset; |
| 168 | |
| 169 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 170 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 171 | // If the register holds an object, update the stack mask. |
| 172 | if (locations->RegisterContainsObject(i)) { |
| 173 | locations->SetStackBit(stack_offset / kVRegSize); |
| 174 | } |
| 175 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 176 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 177 | saved_core_stack_offsets_[i] = stack_offset; |
| 178 | stack_offset += kArmWordSize; |
| 179 | } |
| 180 | |
| 181 | int reg_num = POPCOUNT(core_spills); |
| 182 | if (reg_num != 0) { |
| 183 | if (reg_num > kRegListThreshold) { |
| 184 | __ StoreList(RegList(core_spills), orig_offset); |
| 185 | } else { |
| 186 | stack_offset = orig_offset; |
| 187 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 188 | stack_offset += codegen->SaveCoreRegister(stack_offset, i); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 193 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 194 | orig_offset = stack_offset; |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 195 | for (uint32_t i : LowToHighBits(fp_spills)) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 196 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 197 | saved_fpu_stack_offsets_[i] = stack_offset; |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 198 | stack_offset += kArmWordSize; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 199 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 200 | |
| 201 | stack_offset = orig_offset; |
| 202 | while (fp_spills != 0u) { |
| 203 | uint32_t begin = CTZ(fp_spills); |
| 204 | uint32_t tmp = fp_spills + (1u << begin); |
| 205 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 206 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 207 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 208 | } |
| 209 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void SlowPathCodeARM::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 213 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 214 | size_t orig_offset = stack_offset; |
| 215 | |
| 216 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true); |
| 217 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 218 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 219 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 220 | stack_offset += kArmWordSize; |
| 221 | } |
| 222 | |
| 223 | int reg_num = POPCOUNT(core_spills); |
| 224 | if (reg_num != 0) { |
| 225 | if (reg_num > kRegListThreshold) { |
| 226 | __ LoadList(RegList(core_spills), orig_offset); |
| 227 | } else { |
| 228 | stack_offset = orig_offset; |
| 229 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 230 | stack_offset += codegen->RestoreCoreRegister(stack_offset, i); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 235 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false); |
| 236 | while (fp_spills != 0u) { |
| 237 | uint32_t begin = CTZ(fp_spills); |
| 238 | uint32_t tmp = fp_spills + (1u << begin); |
| 239 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 240 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 241 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 242 | } |
Artem Serov | d300d8f | 2016-07-15 14:00:56 +0100 | [diff] [blame] | 243 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | class NullCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 247 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 248 | explicit NullCheckSlowPathARM(HNullCheck* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 249 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 250 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 251 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 252 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 253 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 254 | // Live registers will be restored in the catch block if caught. |
| 255 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 256 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 257 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 258 | instruction_, |
| 259 | instruction_->GetDexPc(), |
| 260 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 261 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 264 | bool IsFatal() const OVERRIDE { return true; } |
| 265 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 266 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; } |
| 267 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 268 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 269 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM); |
| 270 | }; |
| 271 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 272 | class DivZeroCheckSlowPathARM : public SlowPathCodeARM { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 273 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 274 | explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : SlowPathCodeARM(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 275 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 276 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 277 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 279 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 280 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 283 | bool IsFatal() const OVERRIDE { return true; } |
| 284 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 285 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; } |
| 286 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 287 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 288 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM); |
| 289 | }; |
| 290 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 291 | class SuspendCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 292 | public: |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 293 | SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 294 | : SlowPathCodeARM(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 295 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 296 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 297 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 298 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 299 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 300 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 301 | if (successor_ == nullptr) { |
| 302 | __ b(GetReturnLabel()); |
| 303 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 304 | __ b(arm_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 305 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 308 | Label* GetReturnLabel() { |
| 309 | DCHECK(successor_ == nullptr); |
| 310 | return &return_label_; |
| 311 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 312 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 313 | HBasicBlock* GetSuccessor() const { |
| 314 | return successor_; |
| 315 | } |
| 316 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 317 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; } |
| 318 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 319 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 320 | // If not null, the block to branch to after the suspend check. |
| 321 | HBasicBlock* const successor_; |
| 322 | |
| 323 | // 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] | 324 | Label return_label_; |
| 325 | |
| 326 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM); |
| 327 | }; |
| 328 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 329 | class BoundsCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 330 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 331 | explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 332 | : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 333 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 334 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 335 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 336 | LocationSummary* locations = instruction_->GetLocations(); |
| 337 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 338 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 339 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 340 | // Live registers will be restored in the catch block if caught. |
| 341 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 342 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 343 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 344 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 345 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 346 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 349 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 350 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 352 | Primitive::kPrimInt); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 353 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 354 | ? kQuickThrowStringBounds |
| 355 | : kQuickThrowArrayBounds; |
| 356 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 358 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 361 | bool IsFatal() const OVERRIDE { return true; } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; } |
| 364 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 365 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 366 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM); |
| 367 | }; |
| 368 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 369 | class LoadClassSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 370 | public: |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 371 | LoadClassSlowPathARM(HLoadClass* cls, HInstruction* at, uint32_t dex_pc, bool do_clinit) |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 372 | : SlowPathCodeARM(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 373 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 374 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 375 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 376 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 377 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 378 | Location out = locations->Out(); |
| 379 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
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 | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 386 | // For HLoadClass/kBssEntry/kSaveEverything, make sure we preserve the address of the entry. |
| 387 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| 388 | bool is_load_class_bss_entry = |
| 389 | (cls_ == instruction_) && (cls_->GetLoadKind() == HLoadClass::LoadKind::kBssEntry); |
| 390 | Register entry_address = kNoRegister; |
| 391 | if (is_load_class_bss_entry && call_saves_everything_except_r0) { |
| 392 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 393 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
| 394 | // the kSaveEverything call. |
| 395 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 396 | entry_address = temp_is_r0 ? out.AsRegister<Register>() : temp; |
| 397 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 398 | if (temp_is_r0) { |
| 399 | __ mov(entry_address, ShifterOperand(temp)); |
| 400 | } |
| 401 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 402 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 403 | __ LoadImmediate(calling_convention.GetRegisterAt(0), type_index.index_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 404 | QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage |
| 405 | : kQuickInitializeType; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 406 | arm_codegen->InvokeRuntime(entrypoint, instruction_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 407 | if (do_clinit_) { |
| 408 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 409 | } else { |
| 410 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 411 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 412 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 413 | // For HLoadClass/kBssEntry, store the resolved Class to the BSS entry. |
| 414 | if (is_load_class_bss_entry) { |
| 415 | if (call_saves_everything_except_r0) { |
| 416 | // The class entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 417 | __ str(R0, Address(entry_address)); |
| 418 | } else { |
| 419 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
| 420 | Register temp = IP; |
| 421 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 422 | arm_codegen->NewTypeBssEntryPatch(cls_->GetDexFile(), type_index); |
| 423 | __ BindTrackedLabel(&labels->movw_label); |
| 424 | __ movw(temp, /* placeholder */ 0u); |
| 425 | __ BindTrackedLabel(&labels->movt_label); |
| 426 | __ movt(temp, /* placeholder */ 0u); |
| 427 | __ BindTrackedLabel(&labels->add_pc_label); |
| 428 | __ add(temp, temp, ShifterOperand(PC)); |
| 429 | __ str(R0, Address(temp)); |
| 430 | } |
| 431 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 432 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 433 | if (out.IsValid()) { |
| 434 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 435 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 436 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 438 | __ b(GetExitLabel()); |
| 439 | } |
| 440 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 441 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; } |
| 442 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 443 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 444 | // The class this slow path will load. |
| 445 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 446 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 447 | // The dex PC of `at_`. |
| 448 | const uint32_t dex_pc_; |
| 449 | |
| 450 | // Whether to initialize the class. |
| 451 | const bool do_clinit_; |
| 452 | |
| 453 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 454 | }; |
| 455 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 456 | class LoadStringSlowPathARM : public SlowPathCodeARM { |
| 457 | public: |
| 458 | explicit LoadStringSlowPathARM(HLoadString* instruction) : SlowPathCodeARM(instruction) {} |
| 459 | |
| 460 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 461 | DCHECK(instruction_->IsLoadString()); |
| 462 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 463 | LocationSummary* locations = instruction_->GetLocations(); |
| 464 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 465 | HLoadString* load = instruction_->AsLoadString(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 466 | const dex::StringIndex string_index = load->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 467 | Register out = locations->Out().AsRegister<Register>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 468 | constexpr bool call_saves_everything_except_r0 = (!kUseReadBarrier || kUseBakerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 469 | |
| 470 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 471 | __ Bind(GetEntryLabel()); |
| 472 | SaveLiveRegisters(codegen, locations); |
| 473 | |
| 474 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 475 | // In the unlucky case that the `temp` is R0, we preserve the address in `out` across |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 476 | // the kSaveEverything call. |
| 477 | Register entry_address = kNoRegister; |
| 478 | if (call_saves_everything_except_r0) { |
| 479 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 480 | bool temp_is_r0 = (temp == calling_convention.GetRegisterAt(0)); |
| 481 | entry_address = temp_is_r0 ? out : temp; |
| 482 | DCHECK_NE(entry_address, calling_convention.GetRegisterAt(0)); |
| 483 | if (temp_is_r0) { |
| 484 | __ mov(entry_address, ShifterOperand(temp)); |
| 485 | } |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 488 | __ LoadImmediate(calling_convention.GetRegisterAt(0), string_index.index_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 489 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 490 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 491 | |
| 492 | // Store the resolved String to the .bss entry. |
| 493 | if (call_saves_everything_except_r0) { |
| 494 | // The string entry address was preserved in `entry_address` thanks to kSaveEverything. |
| 495 | __ str(R0, Address(entry_address)); |
| 496 | } else { |
| 497 | // For non-Baker read barrier, we need to re-calculate the address of the string entry. |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 498 | Register temp = IP; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 499 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 500 | arm_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index); |
| 501 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 502 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 503 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 504 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 505 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 506 | __ add(temp, temp, ShifterOperand(PC)); |
| 507 | __ str(R0, Address(temp)); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 510 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 511 | RestoreLiveRegisters(codegen, locations); |
| 512 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 513 | __ b(GetExitLabel()); |
| 514 | } |
| 515 | |
| 516 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; } |
| 517 | |
| 518 | private: |
| 519 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM); |
| 520 | }; |
| 521 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 522 | class TypeCheckSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 523 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 524 | TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 525 | : SlowPathCodeARM(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 526 | |
Alexandre Rames | 67555f7 | 2014-11-18 10:55:16 +0000 | [diff] [blame] | 527 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 528 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 529 | DCHECK(instruction_->IsCheckCast() |
| 530 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 531 | |
| 532 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 533 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 534 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 535 | if (!is_fatal_) { |
| 536 | SaveLiveRegisters(codegen, locations); |
| 537 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 538 | |
| 539 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 540 | // move resolver. |
| 541 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 542 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 543 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 544 | Primitive::kPrimNot, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 545 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 546 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 547 | Primitive::kPrimNot); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 548 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 549 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 550 | instruction_, |
| 551 | instruction_->GetDexPc(), |
| 552 | this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 553 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 554 | arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0)); |
| 555 | } else { |
| 556 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 557 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 558 | instruction_, |
| 559 | instruction_->GetDexPc(), |
| 560 | this); |
| 561 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 562 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 563 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 564 | if (!is_fatal_) { |
| 565 | RestoreLiveRegisters(codegen, locations); |
| 566 | __ b(GetExitLabel()); |
| 567 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 570 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; } |
| 571 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 572 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 573 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 574 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 575 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 576 | |
| 577 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM); |
| 578 | }; |
| 579 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 580 | class DeoptimizationSlowPathARM : public SlowPathCodeARM { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 581 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 582 | explicit DeoptimizationSlowPathARM(HDeoptimize* instruction) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 583 | : SlowPathCodeARM(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 584 | |
| 585 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 586 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 587 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 588 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 589 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 592 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; } |
| 593 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 594 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 595 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM); |
| 596 | }; |
| 597 | |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 598 | class ArraySetSlowPathARM : public SlowPathCodeARM { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 599 | public: |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 600 | explicit ArraySetSlowPathARM(HInstruction* instruction) : SlowPathCodeARM(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 601 | |
| 602 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 603 | LocationSummary* locations = instruction_->GetLocations(); |
| 604 | __ Bind(GetEntryLabel()); |
| 605 | SaveLiveRegisters(codegen, locations); |
| 606 | |
| 607 | InvokeRuntimeCallingConvention calling_convention; |
| 608 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 609 | parallel_move.AddMove( |
| 610 | locations->InAt(0), |
| 611 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 612 | Primitive::kPrimNot, |
| 613 | nullptr); |
| 614 | parallel_move.AddMove( |
| 615 | locations->InAt(1), |
| 616 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 617 | Primitive::kPrimInt, |
| 618 | nullptr); |
| 619 | parallel_move.AddMove( |
| 620 | locations->InAt(2), |
| 621 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 622 | Primitive::kPrimNot, |
| 623 | nullptr); |
| 624 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 625 | |
| 626 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 627 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 628 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 629 | RestoreLiveRegisters(codegen, locations); |
| 630 | __ b(GetExitLabel()); |
| 631 | } |
| 632 | |
| 633 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; } |
| 634 | |
| 635 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 636 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM); |
| 637 | }; |
| 638 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 639 | // Abstract base class for read barrier slow paths marking a reference |
| 640 | // `ref`. |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 641 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 642 | // Argument `entrypoint` must be a register location holding the read |
| 643 | // barrier marking runtime entry point to be invoked. |
| 644 | class ReadBarrierMarkSlowPathBaseARM : public SlowPathCodeARM { |
| 645 | protected: |
| 646 | ReadBarrierMarkSlowPathBaseARM(HInstruction* instruction, Location ref, Location entrypoint) |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 647 | : SlowPathCodeARM(instruction), ref_(ref), entrypoint_(entrypoint) { |
| 648 | DCHECK(kEmitCompilerReadBarrier); |
| 649 | } |
| 650 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 651 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathBaseARM"; } |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 652 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 653 | // Generate assembly code calling the read barrier marking runtime |
| 654 | // entry point (ReadBarrierMarkRegX). |
| 655 | void GenerateReadBarrierMarkRuntimeCall(CodeGenerator* codegen) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 656 | Register ref_reg = ref_.AsRegister<Register>(); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 657 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 658 | // No need to save live registers; it's taken care of by the |
| 659 | // entrypoint. Also, there is no need to update the stack mask, |
| 660 | // as this runtime call will not trigger a garbage collection. |
| 661 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 662 | DCHECK_NE(ref_reg, SP); |
| 663 | DCHECK_NE(ref_reg, LR); |
| 664 | DCHECK_NE(ref_reg, PC); |
| 665 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 666 | // as a temporary, it cannot be the entry point's input/output. |
| 667 | DCHECK_NE(ref_reg, IP); |
| 668 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCoreRegisters) << ref_reg; |
| 669 | // "Compact" slow path, saving two moves. |
| 670 | // |
| 671 | // Instead of using the standard runtime calling convention (input |
| 672 | // and output in R0): |
| 673 | // |
| 674 | // R0 <- ref |
| 675 | // R0 <- ReadBarrierMark(R0) |
| 676 | // ref <- R0 |
| 677 | // |
| 678 | // we just use rX (the register containing `ref`) as input and output |
| 679 | // of a dedicated entrypoint: |
| 680 | // |
| 681 | // rX <- ReadBarrierMarkRegX(rX) |
| 682 | // |
| 683 | if (entrypoint_.IsValid()) { |
| 684 | arm_codegen->ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction_, this); |
| 685 | __ blx(entrypoint_.AsRegister<Register>()); |
| 686 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 687 | // Entrypoint is not already loaded, load from the thread. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 688 | int32_t entry_point_offset = |
| 689 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref_reg); |
| 690 | // This runtime call does not require a stack map. |
| 691 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 692 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | // The location (register) of the marked object reference. |
| 696 | const Location ref_; |
| 697 | |
| 698 | // The location of the entrypoint if it is already loaded. |
| 699 | const Location entrypoint_; |
| 700 | |
| 701 | private: |
| 702 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathBaseARM); |
| 703 | }; |
| 704 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 705 | // Slow path marking an object reference `ref` during a read |
| 706 | // barrier. The field `obj.field` in the object `obj` holding this |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 707 | // reference does not get updated by this slow path after marking. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 | // |
| 709 | // This means that after the execution of this slow path, `ref` will |
| 710 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 711 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 712 | // probably still be a from-space reference (unless it gets updated by |
| 713 | // another thread, or if another thread installed another object |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 714 | // reference (different from `ref`) in `obj.field`). |
| 715 | // |
| 716 | // If `entrypoint` is a valid location it is assumed to already be |
| 717 | // holding the entrypoint. The case where the entrypoint is passed in |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 718 | // is when the decision to mark is based on whether the GC is marking. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 719 | class ReadBarrierMarkSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 720 | public: |
| 721 | ReadBarrierMarkSlowPathARM(HInstruction* instruction, |
| 722 | Location ref, |
| 723 | Location entrypoint = Location::NoLocation()) |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 724 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint) { |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 725 | DCHECK(kEmitCompilerReadBarrier); |
| 726 | } |
| 727 | |
| 728 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM"; } |
| 729 | |
| 730 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 731 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 732 | DCHECK(locations->CanCall()); |
| 733 | if (kIsDebugBuild) { |
| 734 | Register ref_reg = ref_.AsRegister<Register>(); |
| 735 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 736 | } |
| 737 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 738 | << "Unexpected instruction in read barrier marking slow path: " |
| 739 | << instruction_->DebugName(); |
| 740 | |
| 741 | __ Bind(GetEntryLabel()); |
| 742 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 743 | __ b(GetExitLabel()); |
| 744 | } |
| 745 | |
| 746 | private: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 747 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM); |
| 748 | }; |
| 749 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 750 | // Slow path loading `obj`'s lock word, loading a reference from |
| 751 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 752 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 753 | // read barrier). The field `obj.field` in the object `obj` holding |
| 754 | // this reference does not get updated by this slow path after marking |
| 755 | // (see LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 756 | // below for that). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 757 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 758 | // This means that after the execution of this slow path, `ref` will |
| 759 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 760 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 761 | // probably still be a from-space reference (unless it gets updated by |
| 762 | // another thread, or if another thread installed another object |
| 763 | // reference (different from `ref`) in `obj.field`). |
| 764 | // |
| 765 | // Argument `entrypoint` must be a register location holding the read |
| 766 | // barrier marking runtime entry point to be invoked. |
| 767 | class LoadReferenceWithBakerReadBarrierSlowPathARM : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 768 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 769 | LoadReferenceWithBakerReadBarrierSlowPathARM(HInstruction* instruction, |
| 770 | Location ref, |
| 771 | Register obj, |
| 772 | uint32_t offset, |
| 773 | Location index, |
| 774 | ScaleFactor scale_factor, |
| 775 | bool needs_null_check, |
| 776 | Register temp, |
| 777 | Location entrypoint) |
| 778 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 779 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 780 | offset_(offset), |
| 781 | index_(index), |
| 782 | scale_factor_(scale_factor), |
| 783 | needs_null_check_(needs_null_check), |
| 784 | temp_(temp) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 785 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 786 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 789 | const char* GetDescription() const OVERRIDE { |
| 790 | return "LoadReferenceWithBakerReadBarrierSlowPathARM"; |
| 791 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 792 | |
| 793 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 794 | LocationSummary* locations = instruction_->GetLocations(); |
| 795 | Register ref_reg = ref_.AsRegister<Register>(); |
| 796 | DCHECK(locations->CanCall()); |
| 797 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 798 | DCHECK_NE(ref_reg, temp_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 799 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 800 | instruction_->IsStaticFieldGet() || |
| 801 | instruction_->IsArrayGet() || |
| 802 | instruction_->IsArraySet() || |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 803 | instruction_->IsInstanceOf() || |
| 804 | instruction_->IsCheckCast() || |
| 805 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 806 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| 807 | << "Unexpected instruction in read barrier marking slow path: " |
| 808 | << instruction_->DebugName(); |
| 809 | // The read barrier instrumentation of object ArrayGet |
| 810 | // instructions does not support the HIntermediateAddress |
| 811 | // instruction. |
| 812 | DCHECK(!(instruction_->IsArrayGet() && |
| 813 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 814 | |
| 815 | __ Bind(GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 816 | |
| 817 | // When using MaybeGenerateReadBarrierSlow, the read barrier call is |
| 818 | // inserted after the original load. However, in fast path based |
| 819 | // Baker's read barriers, we need to perform the load of |
| 820 | // mirror::Object::monitor_ *before* the original reference load. |
| 821 | // This load-load ordering is required by the read barrier. |
| 822 | // The fast path/slow path (for Baker's algorithm) should look like: |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 823 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 824 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 825 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 826 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 827 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 828 | // if (is_gray) { |
| 829 | // ref = entrypoint(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 830 | // } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 831 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 832 | // Note: the original implementation in ReadBarrier::Barrier is |
| 833 | // slightly more complex as it performs additional checks that we do |
| 834 | // not do here for performance reasons. |
| 835 | |
| 836 | // /* int32_t */ monitor = obj->monitor_ |
| 837 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 838 | __ LoadFromOffset(kLoadWord, temp_, obj_, monitor_offset); |
| 839 | if (needs_null_check_) { |
| 840 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 841 | } |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 842 | // /* LockWord */ lock_word = LockWord(monitor) |
| 843 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 844 | "art::LockWord and int32_t have different sizes."); |
| 845 | |
| 846 | // Introduce a dependency on the lock_word including the rb_state, |
| 847 | // which shall prevent load-load reordering without using |
| 848 | // a memory barrier (which would be more expensive). |
| 849 | // `obj` is unchanged by this operation, but its value now depends |
| 850 | // on `temp`. |
| 851 | __ add(obj_, obj_, ShifterOperand(temp_, LSR, 32)); |
| 852 | |
| 853 | // The actual reference load. |
| 854 | // A possible implicit null check has already been handled above. |
| 855 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 856 | arm_codegen->GenerateRawReferenceLoad( |
| 857 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 858 | |
| 859 | // Mark the object `ref` when `obj` is gray. |
| 860 | // |
| 861 | // if (rb_state == ReadBarrier::GrayState()) |
| 862 | // ref = ReadBarrier::Mark(ref); |
| 863 | // |
| 864 | // Given the numeric representation, it's enough to check the low bit of the |
| 865 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 866 | // which can be a 16-bit instruction unlike the TST immediate. |
| 867 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 868 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 869 | __ Lsrs(temp_, temp_, LockWord::kReadBarrierStateShift + 1); |
| 870 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 871 | GenerateReadBarrierMarkRuntimeCall(codegen); |
| 872 | |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 873 | __ b(GetExitLabel()); |
| 874 | } |
| 875 | |
| 876 | private: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 877 | // The register containing the object holding the marked object reference field. |
| 878 | Register obj_; |
| 879 | // The offset, index and scale factor to access the reference in `obj_`. |
| 880 | uint32_t offset_; |
| 881 | Location index_; |
| 882 | ScaleFactor scale_factor_; |
| 883 | // Is a null check required? |
| 884 | bool needs_null_check_; |
| 885 | // A temporary register used to hold the lock word of `obj_`. |
| 886 | Register temp_; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 887 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 888 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierSlowPathARM); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 889 | }; |
| 890 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 891 | // Slow path loading `obj`'s lock word, loading a reference from |
| 892 | // object `*(obj + offset + (index << scale_factor))` into `ref`, and |
| 893 | // marking `ref` if `obj` is gray according to the lock word (Baker |
| 894 | // read barrier). If needed, this slow path also atomically updates |
| 895 | // the field `obj.field` in the object `obj` holding this reference |
| 896 | // after marking (contrary to |
| 897 | // LoadReferenceWithBakerReadBarrierSlowPathARM above, which never |
| 898 | // tries to update `obj.field`). |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 899 | // |
| 900 | // This means that after the execution of this slow path, both `ref` |
| 901 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 902 | // hold the same to-space reference (unless another thread installed |
| 903 | // another object reference (different from `ref`) in `obj.field`). |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 904 | // |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 905 | // Argument `entrypoint` must be a register location holding the read |
| 906 | // barrier marking runtime entry point to be invoked. |
| 907 | class LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM |
| 908 | : public ReadBarrierMarkSlowPathBaseARM { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 909 | public: |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 910 | LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM(HInstruction* instruction, |
| 911 | Location ref, |
| 912 | Register obj, |
| 913 | uint32_t offset, |
| 914 | Location index, |
| 915 | ScaleFactor scale_factor, |
| 916 | bool needs_null_check, |
| 917 | Register temp1, |
| 918 | Register temp2, |
| 919 | Location entrypoint) |
| 920 | : ReadBarrierMarkSlowPathBaseARM(instruction, ref, entrypoint), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 921 | obj_(obj), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 922 | offset_(offset), |
| 923 | index_(index), |
| 924 | scale_factor_(scale_factor), |
| 925 | needs_null_check_(needs_null_check), |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 926 | temp1_(temp1), |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 927 | temp2_(temp2) { |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 928 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 929 | DCHECK(kUseBakerReadBarrier); |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 932 | const char* GetDescription() const OVERRIDE { |
| 933 | return "LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM"; |
| 934 | } |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 935 | |
| 936 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 937 | LocationSummary* locations = instruction_->GetLocations(); |
| 938 | Register ref_reg = ref_.AsRegister<Register>(); |
| 939 | DCHECK(locations->CanCall()); |
| 940 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 941 | DCHECK_NE(ref_reg, temp1_); |
| 942 | |
| 943 | // This slow path is only used by the UnsafeCASObject intrinsic at the moment. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 944 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 945 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 946 | << instruction_->DebugName(); |
| 947 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 948 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 949 | DCHECK_EQ(offset_, 0u); |
| 950 | DCHECK_EQ(scale_factor_, ScaleFactor::TIMES_1); |
| 951 | // The location of the offset of the marked reference field within `obj_`. |
| 952 | Location field_offset = index_; |
| 953 | DCHECK(field_offset.IsRegisterPair()) << field_offset; |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 954 | |
| 955 | __ Bind(GetEntryLabel()); |
| 956 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 957 | // /* int32_t */ monitor = obj->monitor_ |
| 958 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 959 | __ LoadFromOffset(kLoadWord, temp1_, obj_, monitor_offset); |
| 960 | if (needs_null_check_) { |
| 961 | codegen->MaybeRecordImplicitNullCheck(instruction_); |
| 962 | } |
| 963 | // /* LockWord */ lock_word = LockWord(monitor) |
| 964 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 965 | "art::LockWord and int32_t have different sizes."); |
| 966 | |
| 967 | // Introduce a dependency on the lock_word including the rb_state, |
| 968 | // which shall prevent load-load reordering without using |
| 969 | // a memory barrier (which would be more expensive). |
| 970 | // `obj` is unchanged by this operation, but its value now depends |
| 971 | // on `temp1`. |
| 972 | __ add(obj_, obj_, ShifterOperand(temp1_, LSR, 32)); |
| 973 | |
| 974 | // The actual reference load. |
| 975 | // A possible implicit null check has already been handled above. |
| 976 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 977 | arm_codegen->GenerateRawReferenceLoad( |
| 978 | instruction_, ref_, obj_, offset_, index_, scale_factor_, /* needs_null_check */ false); |
| 979 | |
| 980 | // Mark the object `ref` when `obj` is gray. |
| 981 | // |
| 982 | // if (rb_state == ReadBarrier::GrayState()) |
| 983 | // ref = ReadBarrier::Mark(ref); |
| 984 | // |
| 985 | // Given the numeric representation, it's enough to check the low bit of the |
| 986 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 987 | // which can be a 16-bit instruction unlike the TST immediate. |
| 988 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 989 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 990 | __ Lsrs(temp1_, temp1_, LockWord::kReadBarrierStateShift + 1); |
| 991 | __ b(GetExitLabel(), CC); // Carry flag is the last bit shifted out by LSRS. |
| 992 | |
| 993 | // Save the old value of the reference before marking it. |
Roland Levillain | 47b3ab2 | 2017-02-27 14:31:35 +0000 | [diff] [blame] | 994 | // Note that we cannot use IP to save the old reference, as IP is |
| 995 | // used internally by the ReadBarrierMarkRegX entry point, and we |
| 996 | // need the old reference after the call to that entry point. |
| 997 | DCHECK_NE(temp1_, IP); |
| 998 | __ Mov(temp1_, ref_reg); |
Roland Levillain | 27b1f9c | 2017-01-17 16:56:34 +0000 | [diff] [blame] | 999 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1000 | GenerateReadBarrierMarkRuntimeCall(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1001 | |
| 1002 | // If the new reference is different from the old reference, |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1003 | // update the field in the holder (`*(obj_ + field_offset)`). |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1004 | // |
| 1005 | // Note that this field could also hold a different object, if |
| 1006 | // another thread had concurrently changed it. In that case, the |
| 1007 | // LDREX/SUBS/ITNE sequence of instructions in the compare-and-set |
| 1008 | // (CAS) operation below would abort the CAS, leaving the field |
| 1009 | // as-is. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1010 | __ cmp(temp1_, ShifterOperand(ref_reg)); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1011 | __ b(GetExitLabel(), EQ); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1012 | |
| 1013 | // Update the the holder's field atomically. This may fail if |
| 1014 | // mutator updates before us, but it's OK. This is achieved |
| 1015 | // using a strong compare-and-set (CAS) operation with relaxed |
| 1016 | // memory synchronization ordering, where the expected value is |
| 1017 | // the old reference and the desired value is the new reference. |
| 1018 | |
| 1019 | // Convenience aliases. |
| 1020 | Register base = obj_; |
| 1021 | // The UnsafeCASObject intrinsic uses a register pair as field |
| 1022 | // offset ("long offset"), of which only the low part contains |
| 1023 | // data. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1024 | Register offset = field_offset.AsRegisterPairLow<Register>(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1025 | Register expected = temp1_; |
| 1026 | Register value = ref_reg; |
| 1027 | Register tmp_ptr = IP; // Pointer to actual memory. |
| 1028 | Register tmp = temp2_; // Value in memory. |
| 1029 | |
| 1030 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 1031 | |
| 1032 | if (kPoisonHeapReferences) { |
| 1033 | __ PoisonHeapReference(expected); |
| 1034 | if (value == expected) { |
| 1035 | // Do not poison `value`, as it is the same register as |
| 1036 | // `expected`, which has just been poisoned. |
| 1037 | } else { |
| 1038 | __ PoisonHeapReference(value); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | // do { |
| 1043 | // tmp = [r_ptr] - expected; |
| 1044 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1045 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1046 | Label loop_head, exit_loop; |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1047 | __ Bind(&loop_head); |
| 1048 | |
| 1049 | __ ldrex(tmp, tmp_ptr); |
| 1050 | |
| 1051 | __ subs(tmp, tmp, ShifterOperand(expected)); |
| 1052 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1053 | __ it(NE); |
| 1054 | __ clrex(NE); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1055 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1056 | __ b(&exit_loop, NE); |
| 1057 | |
| 1058 | __ strex(tmp, value, tmp_ptr); |
| 1059 | __ cmp(tmp, ShifterOperand(1)); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1060 | __ b(&loop_head, EQ); |
| 1061 | |
Roland Levillain | 24a4d11 | 2016-10-26 13:10:46 +0100 | [diff] [blame] | 1062 | __ Bind(&exit_loop); |
| 1063 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1064 | if (kPoisonHeapReferences) { |
| 1065 | __ UnpoisonHeapReference(expected); |
| 1066 | if (value == expected) { |
| 1067 | // Do not unpoison `value`, as it is the same register as |
| 1068 | // `expected`, which has just been unpoisoned. |
| 1069 | } else { |
| 1070 | __ UnpoisonHeapReference(value); |
| 1071 | } |
| 1072 | } |
| 1073 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1074 | __ b(GetExitLabel()); |
| 1075 | } |
| 1076 | |
| 1077 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1078 | // The register containing the object holding the marked object reference field. |
| 1079 | const Register obj_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1080 | // The offset, index and scale factor to access the reference in `obj_`. |
| 1081 | uint32_t offset_; |
| 1082 | Location index_; |
| 1083 | ScaleFactor scale_factor_; |
| 1084 | // Is a null check required? |
| 1085 | bool needs_null_check_; |
| 1086 | // A temporary register used to hold the lock word of `obj_`; and |
| 1087 | // also to hold the original reference value, when the reference is |
| 1088 | // marked. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1089 | const Register temp1_; |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1090 | // A temporary register used in the implementation of the CAS, to |
| 1091 | // update the object's reference field. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1092 | const Register temp2_; |
| 1093 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 1094 | DISALLOW_COPY_AND_ASSIGN(LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1095 | }; |
| 1096 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1097 | // Slow path generating a read barrier for a heap reference. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1098 | class ReadBarrierForHeapReferenceSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1099 | public: |
| 1100 | ReadBarrierForHeapReferenceSlowPathARM(HInstruction* instruction, |
| 1101 | Location out, |
| 1102 | Location ref, |
| 1103 | Location obj, |
| 1104 | uint32_t offset, |
| 1105 | Location index) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1106 | : SlowPathCodeARM(instruction), |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1107 | out_(out), |
| 1108 | ref_(ref), |
| 1109 | obj_(obj), |
| 1110 | offset_(offset), |
| 1111 | index_(index) { |
| 1112 | DCHECK(kEmitCompilerReadBarrier); |
| 1113 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 1114 | // has been overwritten by (or after) the heap object reference load |
| 1115 | // to be instrumented, e.g.: |
| 1116 | // |
| 1117 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1118 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1119 | // |
| 1120 | // In that case, we have lost the information about the original |
| 1121 | // object, and the emitted read barrier cannot work properly. |
| 1122 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 1123 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 1124 | } |
| 1125 | |
| 1126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1127 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1128 | LocationSummary* locations = instruction_->GetLocations(); |
| 1129 | Register reg_out = out_.AsRegister<Register>(); |
| 1130 | DCHECK(locations->CanCall()); |
| 1131 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1132 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 1133 | instruction_->IsStaticFieldGet() || |
| 1134 | instruction_->IsArrayGet() || |
| 1135 | instruction_->IsInstanceOf() || |
| 1136 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1137 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1138 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 1139 | << instruction_->DebugName(); |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 1140 | // The read barrier instrumentation of object ArrayGet |
| 1141 | // instructions does not support the HIntermediateAddress |
| 1142 | // instruction. |
| 1143 | DCHECK(!(instruction_->IsArrayGet() && |
| 1144 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1145 | |
| 1146 | __ Bind(GetEntryLabel()); |
| 1147 | SaveLiveRegisters(codegen, locations); |
| 1148 | |
| 1149 | // We may have to change the index's value, but as `index_` is a |
| 1150 | // constant member (like other "inputs" of this slow path), |
| 1151 | // introduce a copy of it, `index`. |
| 1152 | Location index = index_; |
| 1153 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1154 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1155 | if (instruction_->IsArrayGet()) { |
| 1156 | // Compute the actual memory offset and store it in `index`. |
| 1157 | Register index_reg = index_.AsRegister<Register>(); |
| 1158 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 1159 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 1160 | // We are about to change the value of `index_reg` (see the |
| 1161 | // calls to art::arm::Thumb2Assembler::Lsl and |
| 1162 | // art::arm::Thumb2Assembler::AddConstant below), but it has |
| 1163 | // not been saved by the previous call to |
| 1164 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 1165 | // callee-save register -- |
| 1166 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 1167 | // callee-save registers, as it has been designed with the |
| 1168 | // assumption that callee-save registers are supposed to be |
| 1169 | // handled by the called function. So, as a callee-save |
| 1170 | // register, `index_reg` _would_ eventually be saved onto |
| 1171 | // the stack, but it would be too late: we would have |
| 1172 | // changed its value earlier. Therefore, we manually save |
| 1173 | // it here into another freely available register, |
| 1174 | // `free_reg`, chosen of course among the caller-save |
| 1175 | // registers (as a callee-save `free_reg` register would |
| 1176 | // exhibit the same problem). |
| 1177 | // |
| 1178 | // Note we could have requested a temporary register from |
| 1179 | // the register allocator instead; but we prefer not to, as |
| 1180 | // this is a slow path, and we know we can find a |
| 1181 | // caller-save register that is available. |
| 1182 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 1183 | __ Mov(free_reg, index_reg); |
| 1184 | index_reg = free_reg; |
| 1185 | index = Location::RegisterLocation(index_reg); |
| 1186 | } else { |
| 1187 | // The initial register stored in `index_` has already been |
| 1188 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 1189 | // (as it is not a callee-save register), so we can freely |
| 1190 | // use it. |
| 1191 | } |
| 1192 | // Shifting the index value contained in `index_reg` by the scale |
| 1193 | // factor (2) cannot overflow in practice, as the runtime is |
| 1194 | // unable to allocate object arrays with a size larger than |
| 1195 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 1196 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 1197 | static_assert( |
| 1198 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 1199 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 1200 | __ AddConstant(index_reg, index_reg, offset_); |
| 1201 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1202 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 1203 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 1204 | // (as in the case of ArrayGet), as it is actually an offset |
| 1205 | // to an object field within an object. |
| 1206 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1207 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 1208 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 1209 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 1210 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 1211 | DCHECK_EQ(offset_, 0U); |
| 1212 | DCHECK(index_.IsRegisterPair()); |
| 1213 | // UnsafeGet's offset location is a register pair, the low |
| 1214 | // part contains the correct offset. |
| 1215 | index = index_.ToLow(); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | // We're moving two or three locations to locations that could |
| 1220 | // overlap, so we need a parallel move resolver. |
| 1221 | InvokeRuntimeCallingConvention calling_convention; |
| 1222 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 1223 | parallel_move.AddMove(ref_, |
| 1224 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 1225 | Primitive::kPrimNot, |
| 1226 | nullptr); |
| 1227 | parallel_move.AddMove(obj_, |
| 1228 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 1229 | Primitive::kPrimNot, |
| 1230 | nullptr); |
| 1231 | if (index.IsValid()) { |
| 1232 | parallel_move.AddMove(index, |
| 1233 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 1234 | Primitive::kPrimInt, |
| 1235 | nullptr); |
| 1236 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1237 | } else { |
| 1238 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 1239 | __ LoadImmediate(calling_convention.GetRegisterAt(2), offset_); |
| 1240 | } |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1241 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1242 | CheckEntrypointTypes< |
| 1243 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 1244 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1245 | |
| 1246 | RestoreLiveRegisters(codegen, locations); |
| 1247 | __ b(GetExitLabel()); |
| 1248 | } |
| 1249 | |
| 1250 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM"; } |
| 1251 | |
| 1252 | private: |
| 1253 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 1254 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 1255 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 1256 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 1257 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 1258 | return static_cast<Register>(i); |
| 1259 | } |
| 1260 | } |
| 1261 | // We shall never fail to find a free caller-save register, as |
| 1262 | // there are more than two core caller-save registers on ARM |
| 1263 | // (meaning it is possible to find one which is different from |
| 1264 | // `ref` and `obj`). |
| 1265 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 1266 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 1267 | UNREACHABLE(); |
| 1268 | } |
| 1269 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1270 | const Location out_; |
| 1271 | const Location ref_; |
| 1272 | const Location obj_; |
| 1273 | const uint32_t offset_; |
| 1274 | // An additional location containing an index to an array. |
| 1275 | // Only used for HArrayGet and the UnsafeGetObject & |
| 1276 | // UnsafeGetObjectVolatile intrinsics. |
| 1277 | const Location index_; |
| 1278 | |
| 1279 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM); |
| 1280 | }; |
| 1281 | |
| 1282 | // Slow path generating a read barrier for a GC root. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1283 | class ReadBarrierForRootSlowPathARM : public SlowPathCodeARM { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1284 | public: |
| 1285 | ReadBarrierForRootSlowPathARM(HInstruction* instruction, Location out, Location root) |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 1286 | : SlowPathCodeARM(instruction), out_(out), root_(root) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1287 | DCHECK(kEmitCompilerReadBarrier); |
| 1288 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1289 | |
| 1290 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 1291 | LocationSummary* locations = instruction_->GetLocations(); |
| 1292 | Register reg_out = out_.AsRegister<Register>(); |
| 1293 | DCHECK(locations->CanCall()); |
| 1294 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 1295 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 1296 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 1297 | << instruction_->DebugName(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1298 | |
| 1299 | __ Bind(GetEntryLabel()); |
| 1300 | SaveLiveRegisters(codegen, locations); |
| 1301 | |
| 1302 | InvokeRuntimeCallingConvention calling_convention; |
| 1303 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 1304 | arm_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1305 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1306 | instruction_, |
| 1307 | instruction_->GetDexPc(), |
| 1308 | this); |
| 1309 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 1310 | arm_codegen->Move32(out_, Location::RegisterLocation(R0)); |
| 1311 | |
| 1312 | RestoreLiveRegisters(codegen, locations); |
| 1313 | __ b(GetExitLabel()); |
| 1314 | } |
| 1315 | |
| 1316 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM"; } |
| 1317 | |
| 1318 | private: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 1319 | const Location out_; |
| 1320 | const Location root_; |
| 1321 | |
| 1322 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM); |
| 1323 | }; |
| 1324 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1325 | inline Condition ARMCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1326 | switch (cond) { |
| 1327 | case kCondEQ: return EQ; |
| 1328 | case kCondNE: return NE; |
| 1329 | case kCondLT: return LT; |
| 1330 | case kCondLE: return LE; |
| 1331 | case kCondGT: return GT; |
| 1332 | case kCondGE: return GE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1333 | case kCondB: return LO; |
| 1334 | case kCondBE: return LS; |
| 1335 | case kCondA: return HI; |
| 1336 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1337 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1338 | LOG(FATAL) << "Unreachable"; |
| 1339 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1342 | // Maps signed condition to unsigned condition. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1343 | inline Condition ARMUnsignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1344 | switch (cond) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1345 | case kCondEQ: return EQ; |
| 1346 | case kCondNE: return NE; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1347 | // Signed to unsigned. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1348 | case kCondLT: return LO; |
| 1349 | case kCondLE: return LS; |
| 1350 | case kCondGT: return HI; |
| 1351 | case kCondGE: return HS; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1352 | // Unsigned remain unchanged. |
| 1353 | case kCondB: return LO; |
| 1354 | case kCondBE: return LS; |
| 1355 | case kCondA: return HI; |
| 1356 | case kCondAE: return HS; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1357 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1358 | LOG(FATAL) << "Unreachable"; |
| 1359 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 1362 | inline Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 1363 | // The ARM condition codes can express all the necessary branches, see the |
| 1364 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 1365 | // There is no dex instruction or HIR that would need the missing conditions |
| 1366 | // "equal or unordered" or "not equal". |
| 1367 | switch (cond) { |
| 1368 | case kCondEQ: return EQ; |
| 1369 | case kCondNE: return NE /* unordered */; |
| 1370 | case kCondLT: return gt_bias ? CC : LT /* unordered */; |
| 1371 | case kCondLE: return gt_bias ? LS : LE /* unordered */; |
| 1372 | case kCondGT: return gt_bias ? HI /* unordered */ : GT; |
| 1373 | case kCondGE: return gt_bias ? CS /* unordered */ : GE; |
| 1374 | default: |
| 1375 | LOG(FATAL) << "UNREACHABLE"; |
| 1376 | UNREACHABLE(); |
| 1377 | } |
| 1378 | } |
| 1379 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1380 | inline Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1381 | switch (op_kind) { |
| 1382 | case HDataProcWithShifterOp::kASR: return ASR; |
| 1383 | case HDataProcWithShifterOp::kLSL: return LSL; |
| 1384 | case HDataProcWithShifterOp::kLSR: return LSR; |
| 1385 | default: |
| 1386 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1387 | UNREACHABLE(); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1392 | Register out, |
| 1393 | Register first, |
| 1394 | const ShifterOperand& second, |
| 1395 | CodeGeneratorARM* codegen) { |
| 1396 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1397 | const ShifterOperand in = kind == HInstruction::kAnd |
| 1398 | ? ShifterOperand(0) |
| 1399 | : ShifterOperand(first); |
| 1400 | |
| 1401 | __ mov(out, in); |
| 1402 | } else { |
| 1403 | switch (kind) { |
| 1404 | case HInstruction::kAdd: |
| 1405 | __ add(out, first, second); |
| 1406 | break; |
| 1407 | case HInstruction::kAnd: |
| 1408 | __ and_(out, first, second); |
| 1409 | break; |
| 1410 | case HInstruction::kOr: |
| 1411 | __ orr(out, first, second); |
| 1412 | break; |
| 1413 | case HInstruction::kSub: |
| 1414 | __ sub(out, first, second); |
| 1415 | break; |
| 1416 | case HInstruction::kXor: |
| 1417 | __ eor(out, first, second); |
| 1418 | break; |
| 1419 | default: |
| 1420 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1421 | UNREACHABLE(); |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1427 | const Location& out, |
| 1428 | const Location& first, |
| 1429 | const ShifterOperand& second_lo, |
| 1430 | const ShifterOperand& second_hi, |
| 1431 | CodeGeneratorARM* codegen) { |
| 1432 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1433 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1434 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1435 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1436 | |
| 1437 | if (kind == HInstruction::kAdd) { |
| 1438 | __ adds(out_lo, first_lo, second_lo); |
| 1439 | __ adc(out_hi, first_hi, second_hi); |
| 1440 | } else if (kind == HInstruction::kSub) { |
| 1441 | __ subs(out_lo, first_lo, second_lo); |
| 1442 | __ sbc(out_hi, first_hi, second_hi); |
| 1443 | } else { |
| 1444 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1445 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | static ShifterOperand GetShifterOperand(Register rm, Shift shift, uint32_t shift_imm) { |
| 1450 | return shift_imm == 0 ? ShifterOperand(rm) : ShifterOperand(rm, shift, shift_imm); |
| 1451 | } |
| 1452 | |
| 1453 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, CodeGeneratorARM* codegen) { |
| 1454 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 1455 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1456 | |
| 1457 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1458 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1459 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1460 | const Location first = locations->InAt(0); |
| 1461 | const Location second = locations->InAt(1); |
| 1462 | const Location out = locations->Out(); |
| 1463 | const Register first_hi = first.AsRegisterPairHigh<Register>(); |
| 1464 | const Register first_lo = first.AsRegisterPairLow<Register>(); |
| 1465 | const Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 1466 | const Register out_lo = out.AsRegisterPairLow<Register>(); |
| 1467 | const Register second_hi = second.AsRegisterPairHigh<Register>(); |
| 1468 | const Register second_lo = second.AsRegisterPairLow<Register>(); |
| 1469 | const Shift shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1470 | |
| 1471 | if (shift_value >= 32) { |
| 1472 | if (shift == LSL) { |
| 1473 | GenerateDataProcInstruction(kind, |
| 1474 | out_hi, |
| 1475 | first_hi, |
| 1476 | ShifterOperand(second_lo, LSL, shift_value - 32), |
| 1477 | codegen); |
| 1478 | GenerateDataProcInstruction(kind, |
| 1479 | out_lo, |
| 1480 | first_lo, |
| 1481 | ShifterOperand(0), |
| 1482 | codegen); |
| 1483 | } else if (shift == ASR) { |
| 1484 | GenerateDataProc(kind, |
| 1485 | out, |
| 1486 | first, |
| 1487 | GetShifterOperand(second_hi, ASR, shift_value - 32), |
| 1488 | ShifterOperand(second_hi, ASR, 31), |
| 1489 | codegen); |
| 1490 | } else { |
| 1491 | DCHECK_EQ(shift, LSR); |
| 1492 | GenerateDataProc(kind, |
| 1493 | out, |
| 1494 | first, |
| 1495 | GetShifterOperand(second_hi, LSR, shift_value - 32), |
| 1496 | ShifterOperand(0), |
| 1497 | codegen); |
| 1498 | } |
| 1499 | } else { |
| 1500 | DCHECK_GT(shift_value, 1U); |
| 1501 | DCHECK_LT(shift_value, 32U); |
| 1502 | |
| 1503 | if (shift == LSL) { |
| 1504 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1505 | // Location::kOutputOverlap; not applicable to other cases. |
| 1506 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1507 | GenerateDataProcInstruction(kind, |
| 1508 | out_hi, |
| 1509 | first_hi, |
| 1510 | ShifterOperand(second_hi, LSL, shift_value), |
| 1511 | codegen); |
| 1512 | GenerateDataProcInstruction(kind, |
| 1513 | out_hi, |
| 1514 | out_hi, |
| 1515 | ShifterOperand(second_lo, LSR, 32 - shift_value), |
| 1516 | codegen); |
| 1517 | GenerateDataProcInstruction(kind, |
| 1518 | out_lo, |
| 1519 | first_lo, |
| 1520 | ShifterOperand(second_lo, LSL, shift_value), |
| 1521 | codegen); |
| 1522 | } else { |
| 1523 | __ Lsl(IP, second_hi, shift_value); |
| 1524 | __ orr(IP, IP, ShifterOperand(second_lo, LSR, 32 - shift_value)); |
| 1525 | GenerateDataProc(kind, |
| 1526 | out, |
| 1527 | first, |
| 1528 | ShifterOperand(second_lo, LSL, shift_value), |
| 1529 | ShifterOperand(IP), |
| 1530 | codegen); |
| 1531 | } |
| 1532 | } else { |
| 1533 | DCHECK(shift == ASR || shift == LSR); |
| 1534 | |
| 1535 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1536 | // Location::kOutputOverlap; not applicable to other cases. |
| 1537 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1538 | GenerateDataProcInstruction(kind, |
| 1539 | out_lo, |
| 1540 | first_lo, |
| 1541 | ShifterOperand(second_lo, LSR, shift_value), |
| 1542 | codegen); |
| 1543 | GenerateDataProcInstruction(kind, |
| 1544 | out_lo, |
| 1545 | out_lo, |
| 1546 | ShifterOperand(second_hi, LSL, 32 - shift_value), |
| 1547 | codegen); |
| 1548 | GenerateDataProcInstruction(kind, |
| 1549 | out_hi, |
| 1550 | first_hi, |
| 1551 | ShifterOperand(second_hi, shift, shift_value), |
| 1552 | codegen); |
| 1553 | } else { |
| 1554 | __ Lsr(IP, second_lo, shift_value); |
| 1555 | __ orr(IP, IP, ShifterOperand(second_hi, LSL, 32 - shift_value)); |
| 1556 | GenerateDataProc(kind, |
| 1557 | out, |
| 1558 | first, |
| 1559 | ShifterOperand(IP), |
| 1560 | ShifterOperand(second_hi, shift, shift_value), |
| 1561 | codegen); |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1567 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARM* codegen) { |
| 1568 | Primitive::Type type = instruction->InputAt(0)->GetType(); |
| 1569 | Location lhs_loc = instruction->GetLocations()->InAt(0); |
| 1570 | Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1571 | if (rhs_loc.IsConstant()) { |
| 1572 | // 0.0 is the only immediate that can be encoded directly in |
| 1573 | // a VCMP instruction. |
| 1574 | // |
| 1575 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1576 | // specify that in a floating-point comparison, positive zero |
| 1577 | // and negative zero are considered equal, so we can use the |
| 1578 | // literal 0.0 for both cases here. |
| 1579 | // |
| 1580 | // Note however that some methods (Float.equal, Float.compare, |
| 1581 | // Float.compareTo, Double.equal, Double.compare, |
| 1582 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1583 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1584 | // -0.0. So if we ever translate calls to these methods into a |
| 1585 | // HCompare instruction, we must handle the -0.0 case with |
| 1586 | // care here. |
| 1587 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1588 | if (type == Primitive::kPrimFloat) { |
| 1589 | __ vcmpsz(lhs_loc.AsFpuRegister<SRegister>()); |
| 1590 | } else { |
| 1591 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1592 | __ vcmpdz(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1593 | } |
| 1594 | } else { |
| 1595 | if (type == Primitive::kPrimFloat) { |
| 1596 | __ vcmps(lhs_loc.AsFpuRegister<SRegister>(), rhs_loc.AsFpuRegister<SRegister>()); |
| 1597 | } else { |
| 1598 | DCHECK_EQ(type, Primitive::kPrimDouble); |
| 1599 | __ vcmpd(FromLowSToD(lhs_loc.AsFpuRegisterPairLow<SRegister>()), |
| 1600 | FromLowSToD(rhs_loc.AsFpuRegisterPairLow<SRegister>())); |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | static Condition GenerateLongTestConstant(HCondition* condition, |
| 1606 | bool invert, |
| 1607 | CodeGeneratorARM* codegen) { |
| 1608 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1609 | |
| 1610 | const LocationSummary* const locations = condition->GetLocations(); |
| 1611 | IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1612 | Condition ret = EQ; |
| 1613 | const Location left = locations->InAt(0); |
| 1614 | const Location right = locations->InAt(1); |
| 1615 | |
| 1616 | DCHECK(right.IsConstant()); |
| 1617 | |
| 1618 | const Register left_high = left.AsRegisterPairHigh<Register>(); |
| 1619 | const Register left_low = left.AsRegisterPairLow<Register>(); |
| 1620 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1621 | |
| 1622 | switch (cond) { |
| 1623 | case kCondEQ: |
| 1624 | case kCondNE: |
| 1625 | case kCondB: |
| 1626 | case kCondBE: |
| 1627 | case kCondA: |
| 1628 | case kCondAE: |
| 1629 | __ CmpConstant(left_high, High32Bits(value)); |
| 1630 | __ it(EQ); |
| 1631 | __ cmp(left_low, ShifterOperand(Low32Bits(value)), EQ); |
| 1632 | ret = ARMUnsignedCondition(cond); |
| 1633 | break; |
| 1634 | case kCondLE: |
| 1635 | case kCondGT: |
| 1636 | // Trivially true or false. |
| 1637 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1638 | __ cmp(left_low, ShifterOperand(left_low)); |
| 1639 | ret = cond == kCondLE ? EQ : NE; |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | if (cond == kCondLE) { |
| 1644 | cond = kCondLT; |
| 1645 | } else { |
| 1646 | DCHECK_EQ(cond, kCondGT); |
| 1647 | cond = kCondGE; |
| 1648 | } |
| 1649 | |
| 1650 | value++; |
| 1651 | FALLTHROUGH_INTENDED; |
| 1652 | case kCondGE: |
| 1653 | case kCondLT: |
| 1654 | __ CmpConstant(left_low, Low32Bits(value)); |
| 1655 | __ sbcs(IP, left_high, ShifterOperand(High32Bits(value))); |
| 1656 | ret = ARMCondition(cond); |
| 1657 | break; |
| 1658 | default: |
| 1659 | LOG(FATAL) << "Unreachable"; |
| 1660 | UNREACHABLE(); |
| 1661 | } |
| 1662 | |
| 1663 | return ret; |
| 1664 | } |
| 1665 | |
| 1666 | static Condition GenerateLongTest(HCondition* condition, |
| 1667 | bool invert, |
| 1668 | CodeGeneratorARM* codegen) { |
| 1669 | DCHECK_EQ(condition->GetLeft()->GetType(), Primitive::kPrimLong); |
| 1670 | |
| 1671 | const LocationSummary* const locations = condition->GetLocations(); |
| 1672 | IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1673 | Condition ret = EQ; |
| 1674 | Location left = locations->InAt(0); |
| 1675 | Location right = locations->InAt(1); |
| 1676 | |
| 1677 | DCHECK(right.IsRegisterPair()); |
| 1678 | |
| 1679 | switch (cond) { |
| 1680 | case kCondEQ: |
| 1681 | case kCondNE: |
| 1682 | case kCondB: |
| 1683 | case kCondBE: |
| 1684 | case kCondA: |
| 1685 | case kCondAE: |
| 1686 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 1687 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1688 | __ it(EQ); |
| 1689 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1690 | ShifterOperand(right.AsRegisterPairLow<Register>()), |
| 1691 | EQ); |
| 1692 | ret = ARMUnsignedCondition(cond); |
| 1693 | break; |
| 1694 | case kCondLE: |
| 1695 | case kCondGT: |
| 1696 | if (cond == kCondLE) { |
| 1697 | cond = kCondGE; |
| 1698 | } else { |
| 1699 | DCHECK_EQ(cond, kCondGT); |
| 1700 | cond = kCondLT; |
| 1701 | } |
| 1702 | |
| 1703 | std::swap(left, right); |
| 1704 | FALLTHROUGH_INTENDED; |
| 1705 | case kCondGE: |
| 1706 | case kCondLT: |
| 1707 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 1708 | ShifterOperand(right.AsRegisterPairLow<Register>())); |
| 1709 | __ sbcs(IP, |
| 1710 | left.AsRegisterPairHigh<Register>(), |
| 1711 | ShifterOperand(right.AsRegisterPairHigh<Register>())); |
| 1712 | ret = ARMCondition(cond); |
| 1713 | break; |
| 1714 | default: |
| 1715 | LOG(FATAL) << "Unreachable"; |
| 1716 | UNREACHABLE(); |
| 1717 | } |
| 1718 | |
| 1719 | return ret; |
| 1720 | } |
| 1721 | |
| 1722 | static Condition GenerateTest(HInstruction* instruction, |
| 1723 | Location loc, |
| 1724 | bool invert, |
| 1725 | CodeGeneratorARM* codegen) { |
| 1726 | DCHECK(!instruction->IsConstant()); |
| 1727 | |
| 1728 | Condition ret = invert ? EQ : NE; |
| 1729 | |
| 1730 | if (IsBooleanValueOrMaterializedCondition(instruction)) { |
| 1731 | __ CmpConstant(loc.AsRegister<Register>(), 0); |
| 1732 | } else { |
| 1733 | HCondition* const condition = instruction->AsCondition(); |
| 1734 | const LocationSummary* const locations = condition->GetLocations(); |
| 1735 | const Primitive::Type type = condition->GetLeft()->GetType(); |
| 1736 | const IfCondition cond = invert ? condition->GetOppositeCondition() : condition->GetCondition(); |
| 1737 | const Location right = locations->InAt(1); |
| 1738 | |
| 1739 | if (type == Primitive::kPrimLong) { |
| 1740 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1741 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1742 | : GenerateLongTest(condition, invert, codegen); |
| 1743 | } else if (Primitive::IsFloatingPointType(type)) { |
| 1744 | GenerateVcmp(condition, codegen); |
| 1745 | __ vmstat(); |
| 1746 | ret = ARMFPCondition(cond, condition->IsGtBias()); |
| 1747 | } else { |
| 1748 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1749 | |
| 1750 | const Register left = locations->InAt(0).AsRegister<Register>(); |
| 1751 | |
| 1752 | if (right.IsRegister()) { |
| 1753 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 1754 | } else { |
| 1755 | DCHECK(right.IsConstant()); |
| 1756 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 1757 | } |
| 1758 | |
| 1759 | ret = ARMCondition(cond); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | return ret; |
| 1764 | } |
| 1765 | |
| 1766 | static bool CanGenerateTest(HInstruction* condition, ArmAssembler* assembler) { |
| 1767 | if (!IsBooleanValueOrMaterializedCondition(condition)) { |
| 1768 | const HCondition* const cond = condition->AsCondition(); |
| 1769 | |
| 1770 | if (cond->GetLeft()->GetType() == Primitive::kPrimLong) { |
| 1771 | const LocationSummary* const locations = cond->GetLocations(); |
| 1772 | const IfCondition c = cond->GetCondition(); |
| 1773 | |
| 1774 | if (locations->InAt(1).IsConstant()) { |
| 1775 | const int64_t value = locations->InAt(1).GetConstant()->AsLongConstant()->GetValue(); |
| 1776 | ShifterOperand so; |
| 1777 | |
| 1778 | if (c < kCondLT || c > kCondGE) { |
| 1779 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1780 | // we check that the least significant half of the first input to be compared |
| 1781 | // is in a low register (the other half is read outside an IT block), and |
| 1782 | // the constant fits in an 8-bit unsigned integer, so that a 16-bit CMP |
| 1783 | // encoding can be used. |
| 1784 | if (!ArmAssembler::IsLowRegister(locations->InAt(0).AsRegisterPairLow<Register>()) || |
| 1785 | !IsUint<8>(Low32Bits(value))) { |
| 1786 | return false; |
| 1787 | } |
| 1788 | } else if (c == kCondLE || c == kCondGT) { |
| 1789 | if (value < std::numeric_limits<int64_t>::max() && |
| 1790 | !assembler->ShifterOperandCanHold(kNoRegister, |
| 1791 | kNoRegister, |
| 1792 | SBC, |
| 1793 | High32Bits(value + 1), |
| 1794 | kCcSet, |
| 1795 | &so)) { |
| 1796 | return false; |
| 1797 | } |
| 1798 | } else if (!assembler->ShifterOperandCanHold(kNoRegister, |
| 1799 | kNoRegister, |
| 1800 | SBC, |
| 1801 | High32Bits(value), |
| 1802 | kCcSet, |
| 1803 | &so)) { |
| 1804 | return false; |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | return true; |
| 1811 | } |
| 1812 | |
| 1813 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| 1814 | const Primitive::Type type = constant->GetType(); |
| 1815 | bool ret = false; |
| 1816 | |
| 1817 | DCHECK(Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) << type; |
| 1818 | |
| 1819 | if (type == Primitive::kPrimLong) { |
| 1820 | const uint64_t value = constant->AsLongConstant()->GetValueAsUint64(); |
| 1821 | |
| 1822 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1823 | } else { |
| 1824 | ret = IsUint<8>(CodeGenerator::GetInt32ValueOf(constant)); |
| 1825 | } |
| 1826 | |
| 1827 | return ret; |
| 1828 | } |
| 1829 | |
| 1830 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| 1831 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 1832 | |
| 1833 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1834 | return Location::ConstantLocation(constant->AsConstant()); |
| 1835 | } |
| 1836 | |
| 1837 | return Location::RequiresRegister(); |
| 1838 | } |
| 1839 | |
| 1840 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1841 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1842 | // we check that we are not dealing with floating-point output (there is no |
| 1843 | // 16-bit VMOV encoding). |
| 1844 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | // For constants, we also check that the output is in one or two low registers, |
| 1849 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1850 | // MOV encoding can be used. |
| 1851 | if (src.IsConstant()) { |
| 1852 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1853 | return false; |
| 1854 | } |
| 1855 | |
| 1856 | if (out.IsRegister()) { |
| 1857 | if (!ArmAssembler::IsLowRegister(out.AsRegister<Register>())) { |
| 1858 | return false; |
| 1859 | } |
| 1860 | } else { |
| 1861 | DCHECK(out.IsRegisterPair()); |
| 1862 | |
| 1863 | if (!ArmAssembler::IsLowRegister(out.AsRegisterPairHigh<Register>())) { |
| 1864 | return false; |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1872 | #undef __ |
| 1873 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 1874 | #define __ down_cast<ArmAssembler*>(GetAssembler())-> // NOLINT |
| 1875 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1876 | Label* CodeGeneratorARM::GetFinalLabel(HInstruction* instruction, Label* final_label) { |
| 1877 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
| 1878 | |
| 1879 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1880 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1881 | HInstruction* const next = instruction->GetNext(); |
| 1882 | |
| 1883 | // Avoid a branch to a branch. |
| 1884 | if (next->IsGoto() && (info == nullptr || |
| 1885 | !info->IsBackEdge(*block) || |
| 1886 | !info->HasSuspendCheck())) { |
| 1887 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1888 | } |
| 1889 | |
| 1890 | return final_label; |
| 1891 | } |
| 1892 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1893 | void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1894 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1898 | stream << SRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1901 | size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1902 | __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1903 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1904 | } |
| 1905 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1906 | size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1907 | __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index); |
| 1908 | return kArmWordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1909 | } |
| 1910 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 1911 | size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1912 | __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1913 | return kArmWordSize; |
| 1914 | } |
| 1915 | |
| 1916 | size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1917 | __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index); |
| 1918 | return kArmWordSize; |
| 1919 | } |
| 1920 | |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 1921 | CodeGeneratorARM::CodeGeneratorARM(HGraph* graph, |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 1922 | const ArmInstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1923 | const CompilerOptions& compiler_options, |
| 1924 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1925 | : CodeGenerator(graph, |
| 1926 | kNumberOfCoreRegisters, |
| 1927 | kNumberOfSRegisters, |
| 1928 | kNumberOfRegisterPairs, |
| 1929 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1930 | arraysize(kCoreCalleeSaves)), |
Nicolas Geoffray | 75d5b9b | 2015-10-05 07:40:35 +0000 | [diff] [blame] | 1931 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1932 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1933 | compiler_options, |
| 1934 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1935 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1936 | location_builder_(graph, this), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1937 | instruction_visitor_(graph, this), |
Nicolas Geoffray | 8d48673 | 2014-07-16 16:23:40 +0100 | [diff] [blame] | 1938 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1939 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1940 | isa_features_(isa_features), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1941 | uint32_literals_(std::less<uint32_t>(), |
| 1942 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1943 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1944 | boot_image_string_patches_(StringReferenceValueComparator(), |
| 1945 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1946 | pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1947 | boot_image_type_patches_(TypeReferenceValueComparator(), |
| 1948 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1949 | pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1950 | type_bss_entry_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 1951 | jit_string_patches_(StringReferenceValueComparator(), |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 1952 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1953 | jit_class_patches_(TypeReferenceValueComparator(), |
| 1954 | graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 1955 | // Always save the LR register to mimic Quick. |
| 1956 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1959 | void CodeGeneratorARM::Finalize(CodeAllocator* allocator) { |
| 1960 | // Ensure that we fix up branches and literal loads and emit the literal pool. |
| 1961 | __ FinalizeCode(); |
| 1962 | |
| 1963 | // Adjust native pc offsets in stack maps. |
| 1964 | 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] | 1965 | uint32_t old_position = |
| 1966 | stack_map_stream_.GetStackMap(i).native_pc_code_offset.Uint32Value(kThumb2); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1967 | uint32_t new_position = __ GetAdjustedPosition(old_position); |
| 1968 | stack_map_stream_.SetStackMapNativePcOffset(i, new_position); |
| 1969 | } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 1970 | // Adjust pc offsets for the disassembly information. |
| 1971 | if (disasm_info_ != nullptr) { |
| 1972 | GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval(); |
| 1973 | frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start); |
| 1974 | frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end); |
| 1975 | for (auto& it : *disasm_info_->GetInstructionIntervals()) { |
| 1976 | it.second.start = __ GetAdjustedPosition(it.second.start); |
| 1977 | it.second.end = __ GetAdjustedPosition(it.second.end); |
| 1978 | } |
| 1979 | for (auto& it : *disasm_info_->GetSlowPathIntervals()) { |
| 1980 | it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start); |
| 1981 | it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end); |
| 1982 | } |
| 1983 | } |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1984 | |
| 1985 | CodeGenerator::Finalize(allocator); |
| 1986 | } |
| 1987 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1988 | void CodeGeneratorARM::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1989 | // Stack register, LR and PC are always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1990 | blocked_core_registers_[SP] = true; |
| 1991 | blocked_core_registers_[LR] = true; |
| 1992 | blocked_core_registers_[PC] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1993 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1994 | // Reserve thread register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1995 | blocked_core_registers_[TR] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1996 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1997 | // Reserve temp register. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1998 | blocked_core_registers_[IP] = true; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 1999 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2000 | if (GetGraph()->IsDebuggable()) { |
Nicolas Geoffray | ecf680d | 2015-10-05 11:15:37 +0100 | [diff] [blame] | 2001 | // Stubs do not save callee-save floating point registers. If the graph |
| 2002 | // is debuggable, we need to deal with these registers differently. For |
| 2003 | // now, just block them. |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2004 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 2005 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 2006 | } |
| 2007 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2010 | InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2011 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2012 | assembler_(codegen->GetAssembler()), |
| 2013 | codegen_(codegen) {} |
| 2014 | |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2015 | void CodeGeneratorARM::ComputeSpillMask() { |
| 2016 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| 2017 | 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] | 2018 | // There is no easy instruction to restore just the PC on thumb2. We spill and |
| 2019 | // restore another arbitrary register. |
| 2020 | core_spill_mask_ |= (1 << kCoreAlwaysSpillRegister); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2021 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2022 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2023 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2024 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2025 | // but in the range. |
| 2026 | if (fpu_spill_mask_ != 0) { |
| 2027 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2028 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2029 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2030 | fpu_spill_mask_ |= (1 << i); |
| 2031 | } |
| 2032 | } |
| 2033 | } |
| 2034 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2035 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2036 | return dwarf::Reg::ArmCore(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | static dwarf::Reg DWARFReg(SRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2040 | return dwarf::Reg::ArmFp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2043 | void CodeGeneratorARM::GenerateFrameEntry() { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2044 | bool skip_overflow_check = |
| 2045 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2046 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2047 | __ Bind(&frame_entry_label_); |
| 2048 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2049 | if (HasEmptyFrame()) { |
| 2050 | return; |
| 2051 | } |
| 2052 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2053 | if (!skip_overflow_check) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 2054 | __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm))); |
| 2055 | __ LoadFromOffset(kLoadWord, IP, IP, 0); |
| 2056 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2057 | } |
| 2058 | |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2059 | __ PushList(core_spill_mask_); |
| 2060 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2061 | __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2062 | if (fpu_spill_mask_ != 0) { |
| 2063 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2064 | __ vpushs(start_register, POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2065 | __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 2066 | __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2067 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2068 | |
| 2069 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2070 | // Initialize should_deoptimize flag to 0. |
| 2071 | __ mov(IP, ShifterOperand(0)); |
| 2072 | __ StoreToOffset(kStoreWord, IP, SP, -kShouldDeoptimizeFlagSize); |
| 2073 | } |
| 2074 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2075 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2076 | __ AddConstant(SP, -adjust); |
| 2077 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2078 | |
| 2079 | // Save the current method if we need it. Note that we do not |
| 2080 | // do this in HCurrentMethod, as the instruction might have been removed |
| 2081 | // in the SSA graph. |
| 2082 | if (RequiresCurrentMethod()) { |
| 2083 | __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0); |
| 2084 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void CodeGeneratorARM::GenerateFrameExit() { |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2088 | if (HasEmptyFrame()) { |
| 2089 | __ bx(LR); |
| 2090 | return; |
| 2091 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2092 | __ cfi().RememberState(); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2093 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 2094 | __ AddConstant(SP, adjust); |
| 2095 | __ cfi().AdjustCFAOffset(-adjust); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2096 | if (fpu_spill_mask_ != 0) { |
| 2097 | SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_)); |
| 2098 | __ vpops(start_register, POPCOUNT(fpu_spill_mask_)); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2099 | __ cfi().AdjustCFAOffset(-static_cast<int>(kArmPointerSize) * POPCOUNT(fpu_spill_mask_)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 2100 | __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_); |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 2101 | } |
Andreas Gampe | 501fd63 | 2015-09-10 16:11:06 -0700 | [diff] [blame] | 2102 | // Pop LR into PC to return. |
| 2103 | DCHECK_NE(core_spill_mask_ & (1 << LR), 0U); |
| 2104 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC; |
| 2105 | __ PopList(pop_mask); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 2106 | __ cfi().RestoreState(); |
| 2107 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2110 | void CodeGeneratorARM::Bind(HBasicBlock* block) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 2111 | Label* label = GetLabelOf(block); |
| 2112 | __ BindTrackedLabel(label); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2115 | Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2116 | switch (type) { |
| 2117 | case Primitive::kPrimBoolean: |
| 2118 | case Primitive::kPrimByte: |
| 2119 | case Primitive::kPrimChar: |
| 2120 | case Primitive::kPrimShort: |
| 2121 | case Primitive::kPrimInt: |
| 2122 | case Primitive::kPrimNot: { |
| 2123 | uint32_t index = gp_index_++; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2124 | uint32_t stack_index = stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2125 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2126 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2127 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2128 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2129 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2130 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2131 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2132 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2133 | uint32_t index = gp_index_; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2134 | uint32_t stack_index = stack_index_; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2135 | gp_index_ += 2; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2136 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2137 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2138 | if (calling_convention.GetRegisterAt(index) == R1) { |
| 2139 | // Skip R1, and use R2_R3 instead. |
| 2140 | gp_index_++; |
| 2141 | index++; |
| 2142 | } |
| 2143 | } |
| 2144 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2145 | DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1, |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2146 | calling_convention.GetRegisterAt(index + 1)); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2147 | |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 2148 | return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index), |
Nicolas Geoffray | af2c65c | 2015-01-14 09:40:32 +0000 | [diff] [blame] | 2149 | calling_convention.GetRegisterAt(index + 1)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2150 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2151 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | case Primitive::kPrimFloat: { |
| 2156 | uint32_t stack_index = stack_index_++; |
| 2157 | if (float_index_ % 2 == 0) { |
| 2158 | float_index_ = std::max(double_index_, float_index_); |
| 2159 | } |
| 2160 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2161 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2162 | } else { |
| 2163 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | case Primitive::kPrimDouble: { |
| 2168 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2169 | uint32_t stack_index = stack_index_; |
| 2170 | stack_index_ += 2; |
| 2171 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2172 | uint32_t index = double_index_; |
| 2173 | double_index_ += 2; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2174 | Location result = Location::FpuRegisterPairLocation( |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2175 | calling_convention.GetFpuRegisterAt(index), |
| 2176 | calling_convention.GetFpuRegisterAt(index + 1)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2177 | DCHECK(ExpectedPairLayout(result)); |
| 2178 | return result; |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2179 | } else { |
| 2180 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2184 | case Primitive::kPrimVoid: |
| 2185 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2186 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2187 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2188 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2189 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 2190 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2191 | Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2192 | switch (type) { |
| 2193 | case Primitive::kPrimBoolean: |
| 2194 | case Primitive::kPrimByte: |
| 2195 | case Primitive::kPrimChar: |
| 2196 | case Primitive::kPrimShort: |
| 2197 | case Primitive::kPrimInt: |
| 2198 | case Primitive::kPrimNot: { |
| 2199 | return Location::RegisterLocation(R0); |
| 2200 | } |
| 2201 | |
| 2202 | case Primitive::kPrimFloat: { |
| 2203 | return Location::FpuRegisterLocation(S0); |
| 2204 | } |
| 2205 | |
| 2206 | case Primitive::kPrimLong: { |
| 2207 | return Location::RegisterPairLocation(R0, R1); |
| 2208 | } |
| 2209 | |
| 2210 | case Primitive::kPrimDouble: { |
| 2211 | return Location::FpuRegisterPairLocation(S0, S1); |
| 2212 | } |
| 2213 | |
| 2214 | case Primitive::kPrimVoid: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 2215 | return Location::NoLocation(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2216 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2217 | |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2218 | UNREACHABLE(); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2221 | Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const { |
| 2222 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2223 | } |
| 2224 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2225 | void CodeGeneratorARM::Move32(Location destination, Location source) { |
| 2226 | if (source.Equals(destination)) { |
| 2227 | return; |
| 2228 | } |
| 2229 | if (destination.IsRegister()) { |
| 2230 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2231 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2232 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2233 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2234 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2235 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2236 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2237 | } else if (destination.IsFpuRegister()) { |
| 2238 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2239 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2240 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2241 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2242 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2243 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2244 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2245 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2246 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2247 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2248 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2249 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2250 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2251 | } else { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 2252 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2253 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 2254 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | void CodeGeneratorARM::Move64(Location destination, Location source) { |
| 2260 | if (source.Equals(destination)) { |
| 2261 | return; |
| 2262 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2263 | if (destination.IsRegisterPair()) { |
| 2264 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2265 | EmitParallelMoves( |
| 2266 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 2267 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2268 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2269 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2270 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 2271 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2272 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2273 | UNIMPLEMENTED(FATAL); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2274 | } else if (source.IsFpuRegisterPair()) { |
| 2275 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 2276 | destination.AsRegisterPairHigh<Register>(), |
| 2277 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2278 | } else { |
| 2279 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 2280 | DCHECK(ExpectedPairLayout(destination)); |
| 2281 | __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(), |
| 2282 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2283 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2284 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2285 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2286 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2287 | SP, |
| 2288 | source.GetStackIndex()); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2289 | } else if (source.IsRegisterPair()) { |
| 2290 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 2291 | source.AsRegisterPairLow<Register>(), |
| 2292 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2293 | } else { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2294 | UNIMPLEMENTED(FATAL); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2295 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2296 | } else { |
| 2297 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2298 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2299 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2300 | if (source.AsRegisterPairLow<Register>() == R1) { |
| 2301 | DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2302 | __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex()); |
| 2303 | __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2304 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2305 | __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2306 | SP, destination.GetStackIndex()); |
| 2307 | } |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 2308 | } else if (source.IsFpuRegisterPair()) { |
| 2309 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 2310 | SP, |
| 2311 | destination.GetStackIndex()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2312 | } else { |
| 2313 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2314 | EmitParallelMoves( |
| 2315 | Location::StackSlot(source.GetStackIndex()), |
| 2316 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2317 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 2318 | Location::StackSlot(source.GetHighStackIndex(kArmWordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 2319 | Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)), |
| 2320 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2325 | void CodeGeneratorARM::MoveConstant(Location location, int32_t value) { |
| 2326 | DCHECK(location.IsRegister()); |
| 2327 | __ LoadImmediate(location.AsRegister<Register>(), value); |
| 2328 | } |
| 2329 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2330 | void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2331 | HParallelMove move(GetGraph()->GetArena()); |
| 2332 | move.AddMove(src, dst, dst_type, nullptr); |
| 2333 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2337 | if (location.IsRegister()) { |
| 2338 | locations->AddTemp(location); |
| 2339 | } else if (location.IsRegisterPair()) { |
| 2340 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 2341 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 2342 | } else { |
| 2343 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2344 | } |
| 2345 | } |
| 2346 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2347 | void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2348 | HInstruction* instruction, |
| 2349 | uint32_t dex_pc, |
| 2350 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 2351 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2352 | GenerateInvokeRuntime(GetThreadOffset<kArmPointerSize>(entrypoint).Int32Value()); |
Serban Constantinescu | da8ffec | 2016-03-09 12:02:11 +0000 | [diff] [blame] | 2353 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2354 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2355 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2356 | } |
| 2357 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2358 | void CodeGeneratorARM::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2359 | HInstruction* instruction, |
| 2360 | SlowPathCode* slow_path) { |
| 2361 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2362 | GenerateInvokeRuntime(entry_point_offset); |
| 2363 | } |
| 2364 | |
| 2365 | void CodeGeneratorARM::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 2366 | __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset); |
| 2367 | __ blx(LR); |
| 2368 | } |
| 2369 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2370 | void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2371 | DCHECK(!successor->IsExitBlock()); |
| 2372 | |
| 2373 | HBasicBlock* block = got->GetBlock(); |
| 2374 | HInstruction* previous = got->GetPrevious(); |
| 2375 | |
| 2376 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2377 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2378 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 2379 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2380 | return; |
| 2381 | } |
| 2382 | |
| 2383 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2384 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 2385 | } |
| 2386 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2387 | __ b(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2391 | void LocationsBuilderARM::VisitGoto(HGoto* got) { |
| 2392 | got->SetLocations(nullptr); |
| 2393 | } |
| 2394 | |
| 2395 | void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) { |
| 2396 | HandleGoto(got, got->GetSuccessor()); |
| 2397 | } |
| 2398 | |
| 2399 | void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2400 | try_boundary->SetLocations(nullptr); |
| 2401 | } |
| 2402 | |
| 2403 | void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2404 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2405 | if (!successor->IsExitBlock()) { |
| 2406 | HandleGoto(try_boundary, successor); |
| 2407 | } |
| 2408 | } |
| 2409 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2410 | void LocationsBuilderARM::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2411 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2414 | void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2417 | void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond, |
| 2418 | Label* true_label, |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2419 | Label* false_label ATTRIBUTE_UNUSED) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2420 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 2421 | __ b(true_label, ARMFPCondition(cond->GetCondition(), cond->IsGtBias())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond, |
| 2425 | Label* true_label, |
| 2426 | Label* false_label) { |
| 2427 | LocationSummary* locations = cond->GetLocations(); |
| 2428 | Location left = locations->InAt(0); |
| 2429 | Location right = locations->InAt(1); |
| 2430 | IfCondition if_cond = cond->GetCondition(); |
| 2431 | |
| 2432 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 2433 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 2434 | IfCondition true_high_cond = if_cond; |
| 2435 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2436 | Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2437 | |
| 2438 | // Set the conditions for the test, remembering that == needs to be |
| 2439 | // decided using the low words. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2440 | // TODO: consider avoiding jumps with temporary and CMP low+SBC high |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2441 | switch (if_cond) { |
| 2442 | case kCondEQ: |
| 2443 | case kCondNE: |
| 2444 | // Nothing to do. |
| 2445 | break; |
| 2446 | case kCondLT: |
| 2447 | false_high_cond = kCondGT; |
| 2448 | break; |
| 2449 | case kCondLE: |
| 2450 | true_high_cond = kCondLT; |
| 2451 | break; |
| 2452 | case kCondGT: |
| 2453 | false_high_cond = kCondLT; |
| 2454 | break; |
| 2455 | case kCondGE: |
| 2456 | true_high_cond = kCondGT; |
| 2457 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2458 | case kCondB: |
| 2459 | false_high_cond = kCondA; |
| 2460 | break; |
| 2461 | case kCondBE: |
| 2462 | true_high_cond = kCondB; |
| 2463 | break; |
| 2464 | case kCondA: |
| 2465 | false_high_cond = kCondB; |
| 2466 | break; |
| 2467 | case kCondAE: |
| 2468 | true_high_cond = kCondA; |
| 2469 | break; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2470 | } |
| 2471 | if (right.IsConstant()) { |
| 2472 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 2473 | int32_t val_low = Low32Bits(value); |
| 2474 | int32_t val_high = High32Bits(value); |
| 2475 | |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2476 | __ CmpConstant(left_high, val_high); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2477 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2478 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2479 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2480 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2481 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2482 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2483 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2484 | } |
| 2485 | // Must be equal high, so compare the lows. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2486 | __ CmpConstant(left_low, val_low); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2487 | } else { |
| 2488 | Register right_high = right.AsRegisterPairHigh<Register>(); |
| 2489 | Register right_low = right.AsRegisterPairLow<Register>(); |
| 2490 | |
| 2491 | __ cmp(left_high, ShifterOperand(right_high)); |
| 2492 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2493 | __ b(true_label, ARMCondition(true_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2494 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2495 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2496 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2497 | __ b(true_label, ARMCondition(true_high_cond)); |
| 2498 | __ b(false_label, ARMCondition(false_high_cond)); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2499 | } |
| 2500 | // Must be equal high, so compare the lows. |
| 2501 | __ cmp(left_low, ShifterOperand(right_low)); |
| 2502 | } |
| 2503 | // The last comparison might be unsigned. |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2504 | // TODO: optimize cases where this is always true/false |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2505 | __ b(true_label, final_condition); |
| 2506 | } |
| 2507 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2508 | void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HCondition* condition, |
| 2509 | Label* true_target_in, |
| 2510 | Label* false_target_in) { |
| 2511 | // Generated branching requires both targets to be explicit. If either of the |
| 2512 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 2513 | Label fallthrough_target; |
| 2514 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 2515 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 2516 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2517 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2518 | switch (type) { |
| 2519 | case Primitive::kPrimLong: |
| 2520 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 2521 | break; |
| 2522 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2523 | case Primitive::kPrimDouble: |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2524 | GenerateVcmp(condition, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2525 | GenerateFPJumps(condition, true_target, false_target); |
| 2526 | break; |
| 2527 | default: |
| 2528 | LOG(FATAL) << "Unexpected compare type " << type; |
| 2529 | } |
| 2530 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2531 | if (false_target != &fallthrough_target) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2532 | __ b(false_target); |
| 2533 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2534 | |
| 2535 | if (fallthrough_target.IsLinked()) { |
| 2536 | __ Bind(&fallthrough_target); |
| 2537 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2540 | void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2541 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2542 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2543 | Label* false_target) { |
| 2544 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2545 | |
| 2546 | if (true_target == nullptr && false_target == nullptr) { |
| 2547 | // Nothing to do. The code always falls through. |
| 2548 | return; |
| 2549 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2550 | // Constant condition, statically compared against "true" (integer value 1). |
| 2551 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2552 | if (true_target != nullptr) { |
| 2553 | __ b(true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2554 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2555 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2556 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2557 | if (false_target != nullptr) { |
| 2558 | __ b(false_target); |
| 2559 | } |
| 2560 | } |
| 2561 | return; |
| 2562 | } |
| 2563 | |
| 2564 | // The following code generates these patterns: |
| 2565 | // (1) true_target == nullptr && false_target != nullptr |
| 2566 | // - opposite condition true => branch to false_target |
| 2567 | // (2) true_target != nullptr && false_target == nullptr |
| 2568 | // - condition true => branch to true_target |
| 2569 | // (3) true_target != nullptr && false_target != nullptr |
| 2570 | // - condition true => branch to true_target |
| 2571 | // - branch to false_target |
| 2572 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2573 | // Condition has been materialized, compare the output to 0. |
| 2574 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2575 | DCHECK(cond_val.IsRegister()); |
| 2576 | if (true_target == nullptr) { |
| 2577 | __ CompareAndBranchIfZero(cond_val.AsRegister<Register>(), false_target); |
| 2578 | } else { |
| 2579 | __ CompareAndBranchIfNonZero(cond_val.AsRegister<Register>(), true_target); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2580 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2581 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2582 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2583 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 2584 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2585 | |
| 2586 | // If this is a long or FP comparison that has been folded into |
| 2587 | // the HCondition, generate the comparison directly. |
| 2588 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 2589 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 2590 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 2591 | return; |
| 2592 | } |
| 2593 | |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2594 | Label* non_fallthrough_target; |
| 2595 | Condition arm_cond; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2596 | LocationSummary* locations = cond->GetLocations(); |
| 2597 | DCHECK(locations->InAt(0).IsRegister()); |
| 2598 | Register left = locations->InAt(0).AsRegister<Register>(); |
| 2599 | Location right = locations->InAt(1); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2600 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2601 | if (true_target == nullptr) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2602 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2603 | non_fallthrough_target = false_target; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2604 | } else { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2605 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2606 | non_fallthrough_target = true_target; |
| 2607 | } |
| 2608 | |
| 2609 | if (right.IsConstant() && (arm_cond == NE || arm_cond == EQ) && |
| 2610 | CodeGenerator::GetInt32ValueOf(right.GetConstant()) == 0) { |
| 2611 | if (arm_cond == EQ) { |
| 2612 | __ CompareAndBranchIfZero(left, non_fallthrough_target); |
| 2613 | } else { |
| 2614 | DCHECK_EQ(arm_cond, NE); |
| 2615 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target); |
| 2616 | } |
| 2617 | } else { |
| 2618 | if (right.IsRegister()) { |
| 2619 | __ cmp(left, ShifterOperand(right.AsRegister<Register>())); |
| 2620 | } else { |
| 2621 | DCHECK(right.IsConstant()); |
| 2622 | __ CmpConstant(left, CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
| 2623 | } |
| 2624 | |
| 2625 | __ b(non_fallthrough_target, arm_cond); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2626 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2627 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2628 | |
| 2629 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2630 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2631 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2632 | __ b(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2636 | void LocationsBuilderARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2637 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 2638 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2644 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2645 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2646 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2647 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2648 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2649 | nullptr : codegen_->GetLabelOf(false_successor); |
| 2650 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2654 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2655 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 2656 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2657 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 2663 | SlowPathCodeARM* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2664 | GenerateTestAndBranch(deoptimize, |
| 2665 | /* condition_input_index */ 0, |
| 2666 | slow_path->GetEntryLabel(), |
| 2667 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2668 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2669 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2670 | void LocationsBuilderARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2671 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 2672 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2673 | locations->SetOut(Location::RequiresRegister()); |
| 2674 | } |
| 2675 | |
| 2676 | void InstructionCodeGeneratorARM::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2677 | __ LoadFromOffset(kLoadWord, |
| 2678 | flag->GetLocations()->Out().AsRegister<Register>(), |
| 2679 | SP, |
| 2680 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2681 | } |
| 2682 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2683 | void LocationsBuilderARM::VisitSelect(HSelect* select) { |
| 2684 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2685 | const bool is_floating_point = Primitive::IsFloatingPointType(select->GetType()); |
| 2686 | |
| 2687 | if (is_floating_point) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2688 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2689 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2690 | } else { |
| 2691 | locations->SetInAt(0, Location::RequiresRegister()); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2692 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2693 | } |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2694 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2695 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2696 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2697 | // The code generator handles overlap with the values, but not with the condition. |
| 2698 | locations->SetOut(Location::SameAsFirstInput()); |
| 2699 | } else if (is_floating_point) { |
| 2700 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2701 | } else { |
| 2702 | if (!locations->InAt(1).IsConstant()) { |
| 2703 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2704 | } |
| 2705 | |
| 2706 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2707 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | void InstructionCodeGeneratorARM::VisitSelect(HSelect* select) { |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2711 | HInstruction* const condition = select->GetCondition(); |
| 2712 | const LocationSummary* const locations = select->GetLocations(); |
| 2713 | const Primitive::Type type = select->GetType(); |
| 2714 | const Location first = locations->InAt(0); |
| 2715 | const Location out = locations->Out(); |
| 2716 | const Location second = locations->InAt(1); |
| 2717 | Location src; |
| 2718 | |
| 2719 | if (condition->IsIntConstant()) { |
| 2720 | if (condition->AsIntConstant()->IsFalse()) { |
| 2721 | src = first; |
| 2722 | } else { |
| 2723 | src = second; |
| 2724 | } |
| 2725 | |
| 2726 | codegen_->MoveLocation(out, src, type); |
| 2727 | return; |
| 2728 | } |
| 2729 | |
| 2730 | if (!Primitive::IsFloatingPointType(type) && |
| 2731 | CanGenerateTest(condition, codegen_->GetAssembler())) { |
| 2732 | bool invert = false; |
| 2733 | |
| 2734 | if (out.Equals(second)) { |
| 2735 | src = first; |
| 2736 | invert = true; |
| 2737 | } else if (out.Equals(first)) { |
| 2738 | src = second; |
| 2739 | } else if (second.IsConstant()) { |
| 2740 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2741 | src = second; |
| 2742 | } else if (first.IsConstant()) { |
| 2743 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2744 | src = first; |
| 2745 | invert = true; |
| 2746 | } else { |
| 2747 | src = second; |
| 2748 | } |
| 2749 | |
| 2750 | if (CanGenerateConditionalMove(out, src)) { |
| 2751 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2752 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2753 | } |
| 2754 | |
| 2755 | const Condition cond = GenerateTest(condition, locations->InAt(2), invert, codegen_); |
| 2756 | |
| 2757 | if (out.IsRegister()) { |
| 2758 | ShifterOperand operand; |
| 2759 | |
| 2760 | if (src.IsConstant()) { |
| 2761 | operand = ShifterOperand(CodeGenerator::GetInt32ValueOf(src.GetConstant())); |
| 2762 | } else { |
| 2763 | DCHECK(src.IsRegister()); |
| 2764 | operand = ShifterOperand(src.AsRegister<Register>()); |
| 2765 | } |
| 2766 | |
| 2767 | __ it(cond); |
| 2768 | __ mov(out.AsRegister<Register>(), operand, cond); |
| 2769 | } else { |
| 2770 | DCHECK(out.IsRegisterPair()); |
| 2771 | |
| 2772 | ShifterOperand operand_high; |
| 2773 | ShifterOperand operand_low; |
| 2774 | |
| 2775 | if (src.IsConstant()) { |
| 2776 | const int64_t value = src.GetConstant()->AsLongConstant()->GetValue(); |
| 2777 | |
| 2778 | operand_high = ShifterOperand(High32Bits(value)); |
| 2779 | operand_low = ShifterOperand(Low32Bits(value)); |
| 2780 | } else { |
| 2781 | DCHECK(src.IsRegisterPair()); |
| 2782 | operand_high = ShifterOperand(src.AsRegisterPairHigh<Register>()); |
| 2783 | operand_low = ShifterOperand(src.AsRegisterPairLow<Register>()); |
| 2784 | } |
| 2785 | |
| 2786 | __ it(cond); |
| 2787 | __ mov(out.AsRegisterPairLow<Register>(), operand_low, cond); |
| 2788 | __ it(cond); |
| 2789 | __ mov(out.AsRegisterPairHigh<Register>(), operand_high, cond); |
| 2790 | } |
| 2791 | |
| 2792 | return; |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | Label* false_target = nullptr; |
| 2797 | Label* true_target = nullptr; |
| 2798 | Label select_end; |
| 2799 | Label* target = codegen_->GetFinalLabel(select, &select_end); |
| 2800 | |
| 2801 | if (out.Equals(second)) { |
| 2802 | true_target = target; |
| 2803 | src = first; |
| 2804 | } else { |
| 2805 | false_target = target; |
| 2806 | src = second; |
| 2807 | |
| 2808 | if (!out.Equals(first)) { |
| 2809 | codegen_->MoveLocation(out, first, type); |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | GenerateTestAndBranch(select, 2, true_target, false_target); |
| 2814 | codegen_->MoveLocation(out, src, type); |
| 2815 | |
| 2816 | if (select_end.IsLinked()) { |
| 2817 | __ Bind(&select_end); |
| 2818 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2821 | void LocationsBuilderARM::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 2822 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 2823 | } |
| 2824 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2825 | void InstructionCodeGeneratorARM::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2826 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | void CodeGeneratorARM::GenerateNop() { |
| 2830 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2831 | } |
| 2832 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2833 | void LocationsBuilderARM::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2834 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 2835 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2836 | // Handle the long/FP comparisons made in instruction simplification. |
| 2837 | switch (cond->InputAt(0)->GetType()) { |
| 2838 | case Primitive::kPrimLong: |
| 2839 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2840 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2841 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2842 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2843 | } |
| 2844 | break; |
| 2845 | |
| 2846 | case Primitive::kPrimFloat: |
| 2847 | case Primitive::kPrimDouble: |
| 2848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 2849 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2850 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2851 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2852 | } |
| 2853 | break; |
| 2854 | |
| 2855 | default: |
| 2856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2857 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2858 | if (!cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2859 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2860 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2861 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2864 | void InstructionCodeGeneratorARM::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2865 | if (cond->IsEmittedAtUseSite()) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2866 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2867 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2868 | |
| 2869 | LocationSummary* locations = cond->GetLocations(); |
| 2870 | Location left = locations->InAt(0); |
| 2871 | Location right = locations->InAt(1); |
| 2872 | Register out = locations->Out().AsRegister<Register>(); |
| 2873 | Label true_label, false_label; |
| 2874 | |
| 2875 | switch (cond->InputAt(0)->GetType()) { |
| 2876 | default: { |
| 2877 | // Integer case. |
| 2878 | if (right.IsRegister()) { |
| 2879 | __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>())); |
| 2880 | } else { |
| 2881 | DCHECK(right.IsConstant()); |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 2882 | __ CmpConstant(left.AsRegister<Register>(), |
| 2883 | CodeGenerator::GetInt32ValueOf(right.GetConstant())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2884 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2885 | __ it(ARMCondition(cond->GetCondition()), kItElse); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2886 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2887 | ARMCondition(cond->GetCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2888 | __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0), |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2889 | ARMCondition(cond->GetOppositeCondition())); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2890 | return; |
| 2891 | } |
| 2892 | case Primitive::kPrimLong: |
| 2893 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 2894 | break; |
| 2895 | case Primitive::kPrimFloat: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2896 | case Primitive::kPrimDouble: |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2897 | GenerateVcmp(cond, codegen_); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2898 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | // Convert the jumps into the result. |
| 2903 | Label done_label; |
| 2904 | |
| 2905 | // False case: result = 0. |
| 2906 | __ Bind(&false_label); |
| 2907 | __ LoadImmediate(out, 0); |
| 2908 | __ b(&done_label); |
| 2909 | |
| 2910 | // True case: result = 1. |
| 2911 | __ Bind(&true_label); |
| 2912 | __ LoadImmediate(out, 1); |
| 2913 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | void LocationsBuilderARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2917 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2921 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2925 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2929 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | void LocationsBuilderARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2933 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2937 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2941 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2945 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2949 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2953 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2957 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2961 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2964 | void LocationsBuilderARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2965 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2969 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2973 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2977 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | void LocationsBuilderARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2981 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2985 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2989 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2993 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2996 | void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2997 | LocationSummary* locations = |
| 2998 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2999 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3002 | void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 3003 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3006 | void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) { |
| 3007 | LocationSummary* locations = |
| 3008 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3009 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3010 | } |
| 3011 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3012 | void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3013 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3014 | } |
| 3015 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3016 | void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3017 | LocationSummary* locations = |
| 3018 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3019 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3020 | } |
| 3021 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3022 | void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3023 | // Will be generated at use site. |
| 3024 | } |
| 3025 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3026 | void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) { |
| 3027 | LocationSummary* locations = |
| 3028 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3029 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3030 | } |
| 3031 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3032 | void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3033 | // Will be generated at use site. |
| 3034 | } |
| 3035 | |
| 3036 | void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3037 | LocationSummary* locations = |
| 3038 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 3039 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3040 | } |
| 3041 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3042 | void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3043 | // Will be generated at use site. |
| 3044 | } |
| 3045 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3046 | void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3047 | memory_barrier->SetLocations(nullptr); |
| 3048 | } |
| 3049 | |
| 3050 | void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 3051 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 3052 | } |
| 3053 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3054 | void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3055 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3058 | void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3059 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3062 | void LocationsBuilderARM::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3063 | LocationSummary* locations = |
| 3064 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3065 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3068 | void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3069 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3072 | void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3073 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3074 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3075 | // the method_idx. |
| 3076 | HandleInvoke(invoke); |
| 3077 | } |
| 3078 | |
| 3079 | void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3080 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 3081 | } |
| 3082 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3083 | void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3084 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3085 | // art::PrepareForRegisterAllocation. |
| 3086 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3087 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3088 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3089 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3090 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
| 3091 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
| 3092 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3093 | return; |
| 3094 | } |
| 3095 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3096 | HandleInvoke(invoke); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 3097 | |
| 3098 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 3099 | if (invoke->HasPcRelativeDexCache()) { |
| 3100 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
| 3101 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3102 | } |
| 3103 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3104 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) { |
| 3105 | if (invoke->GetLocations()->Intrinsified()) { |
| 3106 | IntrinsicCodeGeneratorARM intrinsic(codegen); |
| 3107 | intrinsic.Dispatch(invoke); |
| 3108 | return true; |
| 3109 | } |
| 3110 | return false; |
| 3111 | } |
| 3112 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3113 | void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 3114 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3115 | // art::PrepareForRegisterAllocation. |
| 3116 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3117 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3118 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3119 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3120 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3121 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3122 | LocationSummary* locations = invoke->GetLocations(); |
| 3123 | codegen_->GenerateStaticOrDirectCall( |
| 3124 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 3125 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3128 | void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 3129 | InvokeDexCallingConventionVisitorARM calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 3130 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3133 | void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 3134 | IntrinsicLocationsBuilderARM intrinsic(codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3135 | if (intrinsic.TryDispatch(invoke)) { |
| 3136 | return; |
| 3137 | } |
| 3138 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3139 | HandleInvoke(invoke); |
| 3140 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3141 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3142 | void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 3143 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 3144 | return; |
| 3145 | } |
| 3146 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3147 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3148 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3149 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3152 | void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3153 | HandleInvoke(invoke); |
| 3154 | // Add the hidden argument. |
| 3155 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12)); |
| 3156 | } |
| 3157 | |
| 3158 | void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3159 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3160 | LocationSummary* locations = invoke->GetLocations(); |
| 3161 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3162 | Register hidden_reg = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3163 | Location receiver = locations->InAt(0); |
| 3164 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3165 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3166 | // Set the hidden argument. This is safe to do this here, as R12 |
| 3167 | // won't be modified thereafter, before the `blx` (call) instruction. |
| 3168 | DCHECK_EQ(R12, hidden_reg); |
| 3169 | __ LoadImmediate(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3170 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3171 | if (receiver.IsStackSlot()) { |
| 3172 | __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3173 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3174 | __ LoadFromOffset(kLoadWord, temp, temp, class_offset); |
| 3175 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3176 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3177 | __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3178 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3179 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3180 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3181 | // emit a read barrier for the previous class reference load. |
| 3182 | // However this is not required in practice, as this is an |
| 3183 | // intermediate/temporary reference and because the current |
| 3184 | // concurrent copying collector keeps the from-space memory |
| 3185 | // intact/accessible until the end of the marking phase (the |
| 3186 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3187 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3188 | __ LoadFromOffset(kLoadWord, temp, temp, |
| 3189 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 3190 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3191 | invoke->GetImtIndex(), kArmPointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3192 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3193 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 3194 | uint32_t entry_point = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3195 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3196 | // LR = temp->GetEntryPoint(); |
| 3197 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 3198 | // LR(); |
| 3199 | __ blx(LR); |
| 3200 | DCHECK(!codegen_->IsLeafMethod()); |
| 3201 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 3202 | } |
| 3203 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3204 | void LocationsBuilderARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3205 | HandleInvoke(invoke); |
| 3206 | } |
| 3207 | |
| 3208 | void InstructionCodeGeneratorARM::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3209 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 3210 | } |
| 3211 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3212 | void LocationsBuilderARM::VisitNeg(HNeg* neg) { |
| 3213 | LocationSummary* locations = |
| 3214 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 3215 | switch (neg->GetResultType()) { |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3216 | case Primitive::kPrimInt: { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3217 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3218 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3219 | break; |
| 3220 | } |
| 3221 | case Primitive::kPrimLong: { |
| 3222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3223 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3224 | break; |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3225 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3226 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3227 | case Primitive::kPrimFloat: |
| 3228 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3229 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3230 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3231 | break; |
| 3232 | |
| 3233 | default: |
| 3234 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) { |
| 3239 | LocationSummary* locations = neg->GetLocations(); |
| 3240 | Location out = locations->Out(); |
| 3241 | Location in = locations->InAt(0); |
| 3242 | switch (neg->GetResultType()) { |
| 3243 | case Primitive::kPrimInt: |
| 3244 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3245 | __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3246 | break; |
| 3247 | |
| 3248 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 3249 | DCHECK(in.IsRegisterPair()); |
| 3250 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3251 | __ rsbs(out.AsRegisterPairLow<Register>(), |
| 3252 | in.AsRegisterPairLow<Register>(), |
| 3253 | ShifterOperand(0)); |
| 3254 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3255 | // instruction here, as it does not exist in the Thumb-2 |
| 3256 | // instruction set. We use the following approach |
| 3257 | // using SBC and SUB instead. |
| 3258 | // |
| 3259 | // out.hi = -C |
| 3260 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3261 | out.AsRegisterPairHigh<Register>(), |
| 3262 | ShifterOperand(out.AsRegisterPairHigh<Register>())); |
| 3263 | // out.hi = out.hi - in.hi |
| 3264 | __ sub(out.AsRegisterPairHigh<Register>(), |
| 3265 | out.AsRegisterPairHigh<Register>(), |
| 3266 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
| 3267 | break; |
| 3268 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3269 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3270 | DCHECK(in.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3271 | __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3272 | break; |
| 3273 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3274 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 3275 | DCHECK(in.IsFpuRegisterPair()); |
| 3276 | __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3277 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3278 | break; |
| 3279 | |
| 3280 | default: |
| 3281 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3282 | } |
| 3283 | } |
| 3284 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3285 | void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3286 | Primitive::Type result_type = conversion->GetResultType(); |
| 3287 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3288 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3289 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3290 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3291 | // rely on a call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3292 | LocationSummary::CallKind call_kind = |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3293 | (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 3294 | && result_type == Primitive::kPrimLong) |
| 3295 | || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat)) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3296 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3297 | : LocationSummary::kNoCall; |
| 3298 | LocationSummary* locations = |
| 3299 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 3300 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 3301 | // The Java language does not allow treating boolean as an integral type but |
| 3302 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3303 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3304 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3305 | case Primitive::kPrimByte: |
| 3306 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3307 | case Primitive::kPrimLong: |
| 3308 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3309 | case Primitive::kPrimBoolean: |
| 3310 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3311 | case Primitive::kPrimShort: |
| 3312 | case Primitive::kPrimInt: |
| 3313 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3314 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3315 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3317 | break; |
| 3318 | |
| 3319 | default: |
| 3320 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3321 | << " to " << result_type; |
| 3322 | } |
| 3323 | break; |
| 3324 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3325 | case Primitive::kPrimShort: |
| 3326 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3327 | case Primitive::kPrimLong: |
| 3328 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3329 | case Primitive::kPrimBoolean: |
| 3330 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3331 | case Primitive::kPrimByte: |
| 3332 | case Primitive::kPrimInt: |
| 3333 | case Primitive::kPrimChar: |
| 3334 | // Processing a Dex `int-to-short' instruction. |
| 3335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3337 | break; |
| 3338 | |
| 3339 | default: |
| 3340 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3341 | << " to " << result_type; |
| 3342 | } |
| 3343 | break; |
| 3344 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3345 | case Primitive::kPrimInt: |
| 3346 | switch (input_type) { |
| 3347 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3348 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3349 | locations->SetInAt(0, Location::Any()); |
| 3350 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3351 | break; |
| 3352 | |
| 3353 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3354 | // Processing a Dex `float-to-int' instruction. |
| 3355 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3356 | locations->SetOut(Location::RequiresRegister()); |
| 3357 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3358 | break; |
| 3359 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3360 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3361 | // Processing a Dex `double-to-int' instruction. |
| 3362 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3363 | locations->SetOut(Location::RequiresRegister()); |
| 3364 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3365 | break; |
| 3366 | |
| 3367 | default: |
| 3368 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3369 | << " to " << result_type; |
| 3370 | } |
| 3371 | break; |
| 3372 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3373 | case Primitive::kPrimLong: |
| 3374 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3375 | case Primitive::kPrimBoolean: |
| 3376 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3377 | case Primitive::kPrimByte: |
| 3378 | case Primitive::kPrimShort: |
| 3379 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3380 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3381 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3382 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3383 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3384 | break; |
| 3385 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3386 | case Primitive::kPrimFloat: { |
| 3387 | // Processing a Dex `float-to-long' instruction. |
| 3388 | InvokeRuntimeCallingConvention calling_convention; |
| 3389 | locations->SetInAt(0, Location::FpuRegisterLocation( |
| 3390 | calling_convention.GetFpuRegisterAt(0))); |
| 3391 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
| 3392 | break; |
| 3393 | } |
| 3394 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3395 | case Primitive::kPrimDouble: { |
| 3396 | // Processing a Dex `double-to-long' instruction. |
| 3397 | InvokeRuntimeCallingConvention calling_convention; |
| 3398 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 3399 | calling_convention.GetFpuRegisterAt(0), |
| 3400 | calling_convention.GetFpuRegisterAt(1))); |
| 3401 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3402 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3403 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3404 | |
| 3405 | default: |
| 3406 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3407 | << " to " << result_type; |
| 3408 | } |
| 3409 | break; |
| 3410 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3411 | case Primitive::kPrimChar: |
| 3412 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3413 | case Primitive::kPrimLong: |
| 3414 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3415 | case Primitive::kPrimBoolean: |
| 3416 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3417 | case Primitive::kPrimByte: |
| 3418 | case Primitive::kPrimShort: |
| 3419 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3420 | // Processing a Dex `int-to-char' instruction. |
| 3421 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3422 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3423 | break; |
| 3424 | |
| 3425 | default: |
| 3426 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3427 | << " to " << result_type; |
| 3428 | } |
| 3429 | break; |
| 3430 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3431 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3432 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3433 | case Primitive::kPrimBoolean: |
| 3434 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3435 | case Primitive::kPrimByte: |
| 3436 | case Primitive::kPrimShort: |
| 3437 | case Primitive::kPrimInt: |
| 3438 | case Primitive::kPrimChar: |
| 3439 | // Processing a Dex `int-to-float' instruction. |
| 3440 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3441 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3442 | break; |
| 3443 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3444 | case Primitive::kPrimLong: { |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3445 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3446 | InvokeRuntimeCallingConvention calling_convention; |
| 3447 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3448 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3449 | locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3450 | break; |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3451 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3452 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3453 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3454 | // Processing a Dex `double-to-float' instruction. |
| 3455 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3456 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3457 | break; |
| 3458 | |
| 3459 | default: |
| 3460 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3461 | << " to " << result_type; |
| 3462 | }; |
| 3463 | break; |
| 3464 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3465 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3466 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3467 | case Primitive::kPrimBoolean: |
| 3468 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3469 | case Primitive::kPrimByte: |
| 3470 | case Primitive::kPrimShort: |
| 3471 | case Primitive::kPrimInt: |
| 3472 | case Primitive::kPrimChar: |
| 3473 | // Processing a Dex `int-to-double' instruction. |
| 3474 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3475 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3476 | break; |
| 3477 | |
| 3478 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3479 | // Processing a Dex `long-to-double' instruction. |
| 3480 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3481 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3482 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3483 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3484 | break; |
| 3485 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3486 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3487 | // Processing a Dex `float-to-double' instruction. |
| 3488 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3489 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3490 | break; |
| 3491 | |
| 3492 | default: |
| 3493 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3494 | << " to " << result_type; |
| 3495 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3496 | break; |
| 3497 | |
| 3498 | default: |
| 3499 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3500 | << " to " << result_type; |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) { |
| 3505 | LocationSummary* locations = conversion->GetLocations(); |
| 3506 | Location out = locations->Out(); |
| 3507 | Location in = locations->InAt(0); |
| 3508 | Primitive::Type result_type = conversion->GetResultType(); |
| 3509 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 3510 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3511 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3512 | case Primitive::kPrimByte: |
| 3513 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3514 | case Primitive::kPrimLong: |
| 3515 | // Type conversion from long to byte is a result of code transformations. |
| 3516 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 8); |
| 3517 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3518 | case Primitive::kPrimBoolean: |
| 3519 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3520 | case Primitive::kPrimShort: |
| 3521 | case Primitive::kPrimInt: |
| 3522 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3523 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3524 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3525 | break; |
| 3526 | |
| 3527 | default: |
| 3528 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3529 | << " to " << result_type; |
| 3530 | } |
| 3531 | break; |
| 3532 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3533 | case Primitive::kPrimShort: |
| 3534 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3535 | case Primitive::kPrimLong: |
| 3536 | // Type conversion from long to short is a result of code transformations. |
| 3537 | __ sbfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3538 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3539 | case Primitive::kPrimBoolean: |
| 3540 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3541 | case Primitive::kPrimByte: |
| 3542 | case Primitive::kPrimInt: |
| 3543 | case Primitive::kPrimChar: |
| 3544 | // Processing a Dex `int-to-short' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3545 | __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3546 | break; |
| 3547 | |
| 3548 | default: |
| 3549 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3550 | << " to " << result_type; |
| 3551 | } |
| 3552 | break; |
| 3553 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3554 | case Primitive::kPrimInt: |
| 3555 | switch (input_type) { |
| 3556 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3557 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3558 | DCHECK(out.IsRegister()); |
| 3559 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3560 | __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3561 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3562 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3563 | } else { |
| 3564 | DCHECK(in.IsConstant()); |
| 3565 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3566 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3567 | __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value)); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3568 | } |
| 3569 | break; |
| 3570 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3571 | case Primitive::kPrimFloat: { |
| 3572 | // Processing a Dex `float-to-int' instruction. |
| 3573 | SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3574 | __ vcvtis(temp, in.AsFpuRegister<SRegister>()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3575 | __ vmovrs(out.AsRegister<Register>(), temp); |
| 3576 | break; |
| 3577 | } |
| 3578 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3579 | case Primitive::kPrimDouble: { |
| 3580 | // Processing a Dex `double-to-int' instruction. |
| 3581 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Vladimir Marko | 8c5d310 | 2016-07-07 12:07:44 +0100 | [diff] [blame] | 3582 | __ vcvtid(temp_s, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3583 | __ vmovrs(out.AsRegister<Register>(), temp_s); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3584 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3585 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3586 | |
| 3587 | default: |
| 3588 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3589 | << " to " << result_type; |
| 3590 | } |
| 3591 | break; |
| 3592 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3593 | case Primitive::kPrimLong: |
| 3594 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3595 | case Primitive::kPrimBoolean: |
| 3596 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3597 | case Primitive::kPrimByte: |
| 3598 | case Primitive::kPrimShort: |
| 3599 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 3600 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3601 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3602 | DCHECK(out.IsRegisterPair()); |
| 3603 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3604 | __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3605 | // Sign extension. |
| 3606 | __ Asr(out.AsRegisterPairHigh<Register>(), |
| 3607 | out.AsRegisterPairLow<Register>(), |
| 3608 | 31); |
| 3609 | break; |
| 3610 | |
| 3611 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3612 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3613 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3614 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3617 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3618 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3619 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3620 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | |
| 3623 | default: |
| 3624 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3625 | << " to " << result_type; |
| 3626 | } |
| 3627 | break; |
| 3628 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3629 | case Primitive::kPrimChar: |
| 3630 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3631 | case Primitive::kPrimLong: |
| 3632 | // Type conversion from long to char is a result of code transformations. |
| 3633 | __ ubfx(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>(), 0, 16); |
| 3634 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3635 | case Primitive::kPrimBoolean: |
| 3636 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3637 | case Primitive::kPrimByte: |
| 3638 | case Primitive::kPrimShort: |
| 3639 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3640 | // Processing a Dex `int-to-char' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3641 | __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 3642 | break; |
| 3643 | |
| 3644 | default: |
| 3645 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3646 | << " to " << result_type; |
| 3647 | } |
| 3648 | break; |
| 3649 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3651 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3652 | case Primitive::kPrimBoolean: |
| 3653 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3654 | case Primitive::kPrimByte: |
| 3655 | case Primitive::kPrimShort: |
| 3656 | case Primitive::kPrimInt: |
| 3657 | case Primitive::kPrimChar: { |
| 3658 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3659 | __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>()); |
| 3660 | __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3661 | break; |
| 3662 | } |
| 3663 | |
Roland Levillain | 5b3ee56 | 2015-04-14 16:02:41 +0100 | [diff] [blame] | 3664 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3665 | // Processing a Dex `long-to-float' instruction. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 3666 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3667 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3668 | break; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3669 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3670 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3671 | // Processing a Dex `double-to-float' instruction. |
| 3672 | __ vcvtsd(out.AsFpuRegister<SRegister>(), |
| 3673 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3674 | break; |
| 3675 | |
| 3676 | default: |
| 3677 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3678 | << " to " << result_type; |
| 3679 | }; |
| 3680 | break; |
| 3681 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3682 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3683 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3684 | case Primitive::kPrimBoolean: |
| 3685 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3686 | case Primitive::kPrimByte: |
| 3687 | case Primitive::kPrimShort: |
| 3688 | case Primitive::kPrimInt: |
| 3689 | case Primitive::kPrimChar: { |
| 3690 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3691 | __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3692 | __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3693 | out.AsFpuRegisterPairLow<SRegister>()); |
| 3694 | break; |
| 3695 | } |
| 3696 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3697 | case Primitive::kPrimLong: { |
| 3698 | // Processing a Dex `long-to-double' instruction. |
| 3699 | Register low = in.AsRegisterPairLow<Register>(); |
| 3700 | Register high = in.AsRegisterPairHigh<Register>(); |
| 3701 | SRegister out_s = out.AsFpuRegisterPairLow<SRegister>(); |
| 3702 | DRegister out_d = FromLowSToD(out_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3703 | SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3704 | DRegister temp_d = FromLowSToD(temp_s); |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3705 | SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>(); |
| 3706 | DRegister constant_d = FromLowSToD(constant_s); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3707 | |
Roland Levillain | 682393c | 2015-04-14 15:57:52 +0100 | [diff] [blame] | 3708 | // temp_d = int-to-double(high) |
| 3709 | __ vmovsr(temp_s, high); |
| 3710 | __ vcvtdi(temp_d, temp_s); |
| 3711 | // constant_d = k2Pow32EncodingForDouble |
| 3712 | __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| 3713 | // out_d = unsigned-to-double(low) |
| 3714 | __ vmovsr(out_s, low); |
| 3715 | __ vcvtdu(out_d, out_s); |
| 3716 | // out_d += temp_d * constant_d |
| 3717 | __ vmlad(out_d, temp_d, constant_d); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3718 | break; |
| 3719 | } |
| 3720 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3721 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3722 | // Processing a Dex `float-to-double' instruction. |
| 3723 | __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3724 | in.AsFpuRegister<SRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3725 | break; |
| 3726 | |
| 3727 | default: |
| 3728 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3729 | << " to " << result_type; |
| 3730 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3731 | break; |
| 3732 | |
| 3733 | default: |
| 3734 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3735 | << " to " << result_type; |
| 3736 | } |
| 3737 | } |
| 3738 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3739 | void LocationsBuilderARM::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3740 | LocationSummary* locations = |
| 3741 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3742 | switch (add->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3743 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3744 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3745 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3746 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3747 | break; |
| 3748 | } |
| 3749 | |
| 3750 | case Primitive::kPrimLong: { |
| 3751 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3752 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3753 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3754 | break; |
| 3755 | } |
| 3756 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3757 | case Primitive::kPrimFloat: |
| 3758 | case Primitive::kPrimDouble: { |
| 3759 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3760 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3761 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3762 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3763 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3764 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3765 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3766 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3767 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) { |
| 3771 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3772 | Location out = locations->Out(); |
| 3773 | Location first = locations->InAt(0); |
| 3774 | Location second = locations->InAt(1); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3775 | switch (add->GetResultType()) { |
| 3776 | case Primitive::kPrimInt: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3777 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3778 | __ add(out.AsRegister<Register>(), |
| 3779 | first.AsRegister<Register>(), |
| 3780 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3781 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3782 | __ AddConstant(out.AsRegister<Register>(), |
| 3783 | first.AsRegister<Register>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3784 | second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3785 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3786 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3787 | |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3788 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3789 | if (second.IsConstant()) { |
| 3790 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3791 | GenerateAddLongConst(out, first, value); |
| 3792 | } else { |
| 3793 | DCHECK(second.IsRegisterPair()); |
| 3794 | __ adds(out.AsRegisterPairLow<Register>(), |
| 3795 | first.AsRegisterPairLow<Register>(), |
| 3796 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3797 | __ adc(out.AsRegisterPairHigh<Register>(), |
| 3798 | first.AsRegisterPairHigh<Register>(), |
| 3799 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3800 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3801 | break; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3802 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3803 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3804 | case Primitive::kPrimFloat: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3805 | __ vadds(out.AsFpuRegister<SRegister>(), |
| 3806 | first.AsFpuRegister<SRegister>(), |
| 3807 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3808 | break; |
| 3809 | |
| 3810 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3811 | __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3812 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3813 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3814 | break; |
| 3815 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3816 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3817 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3821 | void LocationsBuilderARM::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3822 | LocationSummary* locations = |
| 3823 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3824 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3825 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3827 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 3828 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3829 | break; |
| 3830 | } |
| 3831 | |
| 3832 | case Primitive::kPrimLong: { |
| 3833 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3834 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 3835 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3836 | break; |
| 3837 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3838 | case Primitive::kPrimFloat: |
| 3839 | case Primitive::kPrimDouble: { |
| 3840 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3841 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3842 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3843 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3844 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3845 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3846 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3847 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | void InstructionCodeGeneratorARM::VisitSub(HSub* sub) { |
| 3851 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3852 | Location out = locations->Out(); |
| 3853 | Location first = locations->InAt(0); |
| 3854 | Location second = locations->InAt(1); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3855 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3856 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3857 | if (second.IsRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3858 | __ sub(out.AsRegister<Register>(), |
| 3859 | first.AsRegister<Register>(), |
| 3860 | ShifterOperand(second.AsRegister<Register>())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3861 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3862 | __ AddConstant(out.AsRegister<Register>(), |
| 3863 | first.AsRegister<Register>(), |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3864 | -second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3865 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3866 | break; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3867 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3868 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3869 | case Primitive::kPrimLong: { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 3870 | if (second.IsConstant()) { |
| 3871 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3872 | GenerateAddLongConst(out, first, -value); |
| 3873 | } else { |
| 3874 | DCHECK(second.IsRegisterPair()); |
| 3875 | __ subs(out.AsRegisterPairLow<Register>(), |
| 3876 | first.AsRegisterPairLow<Register>(), |
| 3877 | ShifterOperand(second.AsRegisterPairLow<Register>())); |
| 3878 | __ sbc(out.AsRegisterPairHigh<Register>(), |
| 3879 | first.AsRegisterPairHigh<Register>(), |
| 3880 | ShifterOperand(second.AsRegisterPairHigh<Register>())); |
| 3881 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3882 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3883 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3884 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3885 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3886 | __ vsubs(out.AsFpuRegister<SRegister>(), |
| 3887 | first.AsFpuRegister<SRegister>(), |
| 3888 | second.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3889 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3893 | __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3894 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3895 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| 3898 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3899 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3900 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3901 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3905 | void LocationsBuilderARM::VisitMul(HMul* mul) { |
| 3906 | LocationSummary* locations = |
| 3907 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3908 | switch (mul->GetResultType()) { |
| 3909 | case Primitive::kPrimInt: |
| 3910 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3911 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3912 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3913 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3914 | break; |
| 3915 | } |
| 3916 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3917 | case Primitive::kPrimFloat: |
| 3918 | case Primitive::kPrimDouble: { |
| 3919 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3920 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3921 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3922 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3923 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3924 | |
| 3925 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3926 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | void InstructionCodeGeneratorARM::VisitMul(HMul* mul) { |
| 3931 | LocationSummary* locations = mul->GetLocations(); |
| 3932 | Location out = locations->Out(); |
| 3933 | Location first = locations->InAt(0); |
| 3934 | Location second = locations->InAt(1); |
| 3935 | switch (mul->GetResultType()) { |
| 3936 | case Primitive::kPrimInt: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3937 | __ mul(out.AsRegister<Register>(), |
| 3938 | first.AsRegister<Register>(), |
| 3939 | second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3940 | break; |
| 3941 | } |
| 3942 | case Primitive::kPrimLong: { |
| 3943 | Register out_hi = out.AsRegisterPairHigh<Register>(); |
| 3944 | Register out_lo = out.AsRegisterPairLow<Register>(); |
| 3945 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3946 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 3947 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3948 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3949 | |
| 3950 | // Extra checks to protect caused by the existence of R1_R2. |
| 3951 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 3952 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| 3953 | DCHECK_NE(out_hi, in1_lo); |
| 3954 | DCHECK_NE(out_hi, in2_lo); |
| 3955 | |
| 3956 | // input: in1 - 64 bits, in2 - 64 bits |
| 3957 | // output: out |
| 3958 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3959 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3960 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 3961 | |
| 3962 | // IP <- in1.lo * in2.hi |
| 3963 | __ mul(IP, in1_lo, in2_hi); |
| 3964 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3965 | __ mla(out_hi, in1_hi, in2_lo, IP); |
| 3966 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 3967 | __ umull(out_lo, IP, in1_lo, in2_lo); |
| 3968 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3969 | __ add(out_hi, out_hi, ShifterOperand(IP)); |
| 3970 | break; |
| 3971 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3972 | |
| 3973 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3974 | __ vmuls(out.AsFpuRegister<SRegister>(), |
| 3975 | first.AsFpuRegister<SRegister>(), |
| 3976 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3977 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 1ba0f59 | 2014-10-27 15:14:55 +0000 | [diff] [blame] | 3981 | __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 3982 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 3983 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3984 | break; |
| 3985 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3986 | |
| 3987 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3988 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 3992 | void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3993 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3994 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 3995 | |
| 3996 | LocationSummary* locations = instruction->GetLocations(); |
| 3997 | Location second = locations->InAt(1); |
| 3998 | DCHECK(second.IsConstant()); |
| 3999 | |
| 4000 | Register out = locations->Out().AsRegister<Register>(); |
| 4001 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4002 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4003 | DCHECK(imm == 1 || imm == -1); |
| 4004 | |
| 4005 | if (instruction->IsRem()) { |
| 4006 | __ LoadImmediate(out, 0); |
| 4007 | } else { |
| 4008 | if (imm == 1) { |
| 4009 | __ Mov(out, dividend); |
| 4010 | } else { |
| 4011 | __ rsb(out, dividend, ShifterOperand(0)); |
| 4012 | } |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4017 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4018 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4019 | |
| 4020 | LocationSummary* locations = instruction->GetLocations(); |
| 4021 | Location second = locations->InAt(1); |
| 4022 | DCHECK(second.IsConstant()); |
| 4023 | |
| 4024 | Register out = locations->Out().AsRegister<Register>(); |
| 4025 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4026 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4027 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4028 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4029 | int ctz_imm = CTZ(abs_imm); |
| 4030 | |
| 4031 | if (ctz_imm == 1) { |
| 4032 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4033 | } else { |
| 4034 | __ Asr(temp, dividend, 31); |
| 4035 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4036 | } |
| 4037 | __ add(out, temp, ShifterOperand(dividend)); |
| 4038 | |
| 4039 | if (instruction->IsDiv()) { |
| 4040 | __ Asr(out, out, ctz_imm); |
| 4041 | if (imm < 0) { |
| 4042 | __ rsb(out, out, ShifterOperand(0)); |
| 4043 | } |
| 4044 | } else { |
| 4045 | __ ubfx(out, out, 0, ctz_imm); |
| 4046 | __ sub(out, out, ShifterOperand(temp)); |
| 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4051 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4052 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4053 | |
| 4054 | LocationSummary* locations = instruction->GetLocations(); |
| 4055 | Location second = locations->InAt(1); |
| 4056 | DCHECK(second.IsConstant()); |
| 4057 | |
| 4058 | Register out = locations->Out().AsRegister<Register>(); |
| 4059 | Register dividend = locations->InAt(0).AsRegister<Register>(); |
| 4060 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 4061 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 4062 | int64_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4063 | |
| 4064 | int64_t magic; |
| 4065 | int shift; |
| 4066 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 4067 | |
| 4068 | __ LoadImmediate(temp1, magic); |
| 4069 | __ smull(temp2, temp1, dividend, temp1); |
| 4070 | |
| 4071 | if (imm > 0 && magic < 0) { |
| 4072 | __ add(temp1, temp1, ShifterOperand(dividend)); |
| 4073 | } else if (imm < 0 && magic > 0) { |
| 4074 | __ sub(temp1, temp1, ShifterOperand(dividend)); |
| 4075 | } |
| 4076 | |
| 4077 | if (shift != 0) { |
| 4078 | __ Asr(temp1, temp1, shift); |
| 4079 | } |
| 4080 | |
| 4081 | if (instruction->IsDiv()) { |
| 4082 | __ sub(out, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4083 | } else { |
| 4084 | __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31)); |
| 4085 | // TODO: Strength reduction for mls. |
| 4086 | __ LoadImmediate(temp2, imm); |
| 4087 | __ mls(out, temp1, temp2, dividend); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) { |
| 4092 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4093 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt); |
| 4094 | |
| 4095 | LocationSummary* locations = instruction->GetLocations(); |
| 4096 | Location second = locations->InAt(1); |
| 4097 | DCHECK(second.IsConstant()); |
| 4098 | |
| 4099 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4100 | if (imm == 0) { |
| 4101 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4102 | } else if (imm == 1 || imm == -1) { |
| 4103 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4104 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4105 | DivRemByPowerOfTwo(instruction); |
| 4106 | } else { |
| 4107 | DCHECK(imm <= -2 || imm >= 2); |
| 4108 | GenerateDivRemWithAnyConstant(instruction); |
| 4109 | } |
| 4110 | } |
| 4111 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4112 | void LocationsBuilderARM::VisitDiv(HDiv* div) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4113 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4114 | if (div->GetResultType() == Primitive::kPrimLong) { |
| 4115 | // pLdiv runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4116 | call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4117 | } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) { |
| 4118 | // sdiv will be replaced by other instruction sequence. |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4119 | } else if (div->GetResultType() == Primitive::kPrimInt && |
| 4120 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4121 | // pIdivmod runtime call. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4122 | call_kind = LocationSummary::kCallOnMainOnly; |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4125 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 4126 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4127 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4128 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4129 | if (div->InputAt(1)->IsConstant()) { |
| 4130 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4131 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4132 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4133 | int32_t value = div->InputAt(1)->AsIntConstant()->GetValue(); |
| 4134 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4135 | // No temp register required. |
| 4136 | } else { |
| 4137 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4138 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4139 | locations->AddTemp(Location::RequiresRegister()); |
| 4140 | } |
| 4141 | } |
| 4142 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4143 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4144 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4145 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4146 | } else { |
| 4147 | InvokeRuntimeCallingConvention calling_convention; |
| 4148 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4149 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4150 | // 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] | 4151 | // we only need the former. |
| 4152 | locations->SetOut(Location::RegisterLocation(R0)); |
| 4153 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4154 | break; |
| 4155 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4156 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4157 | InvokeRuntimeCallingConvention calling_convention; |
| 4158 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4159 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4160 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4161 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4162 | locations->SetOut(Location::RegisterPairLocation(R0, R1)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4163 | break; |
| 4164 | } |
| 4165 | case Primitive::kPrimFloat: |
| 4166 | case Primitive::kPrimDouble: { |
| 4167 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4168 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4169 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4170 | break; |
| 4171 | } |
| 4172 | |
| 4173 | default: |
| 4174 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) { |
| 4179 | LocationSummary* locations = div->GetLocations(); |
| 4180 | Location out = locations->Out(); |
| 4181 | Location first = locations->InAt(0); |
| 4182 | Location second = locations->InAt(1); |
| 4183 | |
| 4184 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4185 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4186 | if (second.IsConstant()) { |
| 4187 | GenerateDivRemConstantIntegral(div); |
| 4188 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4189 | __ sdiv(out.AsRegister<Register>(), |
| 4190 | first.AsRegister<Register>(), |
| 4191 | second.AsRegister<Register>()); |
| 4192 | } else { |
| 4193 | InvokeRuntimeCallingConvention calling_convention; |
| 4194 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4195 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4196 | DCHECK_EQ(R0, out.AsRegister<Register>()); |
| 4197 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4198 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4199 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4200 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4201 | break; |
| 4202 | } |
| 4203 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4204 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4205 | InvokeRuntimeCallingConvention calling_convention; |
| 4206 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 4207 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 4208 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 4209 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 4210 | DCHECK_EQ(R0, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 4211 | DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4212 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4213 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4214 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4215 | break; |
| 4216 | } |
| 4217 | |
| 4218 | case Primitive::kPrimFloat: { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4219 | __ vdivs(out.AsFpuRegister<SRegister>(), |
| 4220 | first.AsFpuRegister<SRegister>(), |
| 4221 | second.AsFpuRegister<SRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | } |
| 4224 | |
| 4225 | case Primitive::kPrimDouble: { |
| 4226 | __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 4227 | FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()), |
| 4228 | FromLowSToD(second.AsFpuRegisterPairLow<SRegister>())); |
| 4229 | break; |
| 4230 | } |
| 4231 | |
| 4232 | default: |
| 4233 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4234 | } |
| 4235 | } |
| 4236 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4237 | void LocationsBuilderARM::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4238 | Primitive::Type type = rem->GetResultType(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4239 | |
| 4240 | // Most remainders are implemented in the runtime. |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4241 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4242 | if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) { |
| 4243 | // sdiv will be replaced by other instruction sequence. |
| 4244 | call_kind = LocationSummary::kNoCall; |
| 4245 | } else if ((rem->GetResultType() == Primitive::kPrimInt) |
| 4246 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4247 | // Have hardware divide instruction for int, do it with three instructions. |
| 4248 | call_kind = LocationSummary::kNoCall; |
| 4249 | } |
| 4250 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4251 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 4252 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4253 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4254 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4255 | if (rem->InputAt(1)->IsConstant()) { |
| 4256 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 4257 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4259 | int32_t value = rem->InputAt(1)->AsIntConstant()->GetValue(); |
| 4260 | if (value == 1 || value == 0 || value == -1) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4261 | // No temp register required. |
| 4262 | } else { |
| 4263 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 4264 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4265 | locations->AddTemp(Location::RequiresRegister()); |
| 4266 | } |
| 4267 | } |
| 4268 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4269 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4270 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4271 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4272 | locations->AddTemp(Location::RequiresRegister()); |
| 4273 | } else { |
| 4274 | InvokeRuntimeCallingConvention calling_convention; |
| 4275 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4276 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4277 | // 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] | 4278 | // we only need the latter. |
| 4279 | locations->SetOut(Location::RegisterLocation(R1)); |
| 4280 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4281 | break; |
| 4282 | } |
| 4283 | case Primitive::kPrimLong: { |
| 4284 | InvokeRuntimeCallingConvention calling_convention; |
| 4285 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 4286 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4287 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 4288 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4289 | // The runtime helper puts the output in R2,R3. |
| 4290 | locations->SetOut(Location::RegisterPairLocation(R2, R3)); |
| 4291 | break; |
| 4292 | } |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4293 | case Primitive::kPrimFloat: { |
| 4294 | InvokeRuntimeCallingConvention calling_convention; |
| 4295 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 4296 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 4297 | locations->SetOut(Location::FpuRegisterLocation(S0)); |
| 4298 | break; |
| 4299 | } |
| 4300 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4301 | case Primitive::kPrimDouble: { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4302 | InvokeRuntimeCallingConvention calling_convention; |
| 4303 | locations->SetInAt(0, Location::FpuRegisterPairLocation( |
| 4304 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4305 | locations->SetInAt(1, Location::FpuRegisterPairLocation( |
| 4306 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4307 | locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4308 | break; |
| 4309 | } |
| 4310 | |
| 4311 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4312 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | void InstructionCodeGeneratorARM::VisitRem(HRem* rem) { |
| 4317 | LocationSummary* locations = rem->GetLocations(); |
| 4318 | Location out = locations->Out(); |
| 4319 | Location first = locations->InAt(0); |
| 4320 | Location second = locations->InAt(1); |
| 4321 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4322 | Primitive::Type type = rem->GetResultType(); |
| 4323 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4324 | case Primitive::kPrimInt: { |
Zheng Xu | c666710 | 2015-05-15 16:08:45 +0800 | [diff] [blame] | 4325 | if (second.IsConstant()) { |
| 4326 | GenerateDivRemConstantIntegral(rem); |
| 4327 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4328 | Register reg1 = first.AsRegister<Register>(); |
| 4329 | Register reg2 = second.AsRegister<Register>(); |
| 4330 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4331 | |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4332 | // temp = reg1 / reg2 (integer division) |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4333 | // dest = reg1 - temp * reg2 |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4334 | __ sdiv(temp, reg1, reg2); |
Vladimir Marko | 73cf0fb | 2015-07-30 15:07:22 +0100 | [diff] [blame] | 4335 | __ mls(out.AsRegister<Register>(), temp, reg2, reg1); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4336 | } else { |
| 4337 | InvokeRuntimeCallingConvention calling_convention; |
| 4338 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>()); |
| 4339 | DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>()); |
| 4340 | DCHECK_EQ(R1, out.AsRegister<Register>()); |
| 4341 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4342 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4343 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
Andreas Gampe | b51cdb3 | 2015-03-29 17:32:48 -0700 | [diff] [blame] | 4344 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4345 | break; |
| 4346 | } |
| 4347 | |
| 4348 | case Primitive::kPrimLong: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4349 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4350 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4351 | break; |
| 4352 | } |
| 4353 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4354 | case Primitive::kPrimFloat: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4355 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4356 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4357 | break; |
| 4358 | } |
| 4359 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4360 | case Primitive::kPrimDouble: { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4361 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4362 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | |
| 4366 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4367 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4371 | void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4372 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4373 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 4377 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4378 | codegen_->AddSlowPath(slow_path); |
| 4379 | |
| 4380 | LocationSummary* locations = instruction->GetLocations(); |
| 4381 | Location value = locations->InAt(0); |
| 4382 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4383 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 4384 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4385 | case Primitive::kPrimByte: |
| 4386 | case Primitive::kPrimChar: |
| 4387 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4388 | case Primitive::kPrimInt: { |
| 4389 | if (value.IsRegister()) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 4390 | __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4391 | } else { |
| 4392 | DCHECK(value.IsConstant()) << value; |
| 4393 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 4394 | __ b(slow_path->GetEntryLabel()); |
| 4395 | } |
| 4396 | } |
| 4397 | break; |
| 4398 | } |
| 4399 | case Primitive::kPrimLong: { |
| 4400 | if (value.IsRegisterPair()) { |
| 4401 | __ orrs(IP, |
| 4402 | value.AsRegisterPairLow<Register>(), |
| 4403 | ShifterOperand(value.AsRegisterPairHigh<Register>())); |
| 4404 | __ b(slow_path->GetEntryLabel(), EQ); |
| 4405 | } else { |
| 4406 | DCHECK(value.IsConstant()) << value; |
| 4407 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 4408 | __ b(slow_path->GetEntryLabel()); |
| 4409 | } |
| 4410 | } |
| 4411 | break; |
| 4412 | default: |
| 4413 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4414 | } |
| 4415 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4418 | void InstructionCodeGeneratorARM::HandleIntegerRotate(LocationSummary* locations) { |
| 4419 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 4420 | Location rhs = locations->InAt(1); |
| 4421 | Register out = locations->Out().AsRegister<Register>(); |
| 4422 | |
| 4423 | if (rhs.IsConstant()) { |
| 4424 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4425 | // so map all rotations to a +ve. equivalent in that range. |
| 4426 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4427 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4428 | if (rot) { |
| 4429 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4430 | // (e.g. left by 2 bits == right by 30.) |
| 4431 | __ Ror(out, in, rot); |
| 4432 | } else if (out != in) { |
| 4433 | __ Mov(out, in); |
| 4434 | } |
| 4435 | } else { |
| 4436 | __ Ror(out, in, rhs.AsRegister<Register>()); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4441 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4442 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4443 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4444 | void InstructionCodeGeneratorARM::HandleLongRotate(LocationSummary* locations) { |
| 4445 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 4446 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 4447 | Location rhs = locations->InAt(1); |
| 4448 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 4449 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 4450 | |
| 4451 | if (rhs.IsConstant()) { |
| 4452 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4453 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4454 | rot &= kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4455 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4456 | // logic below to a simple pair of binary orr. |
| 4457 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4458 | if (rot >= kArmBitsPerWord) { |
| 4459 | rot -= kArmBitsPerWord; |
| 4460 | std::swap(in_reg_hi, in_reg_lo); |
| 4461 | } |
| 4462 | // Rotate, or mov to out for zero or word size rotations. |
| 4463 | if (rot != 0u) { |
| 4464 | __ Lsr(out_reg_hi, in_reg_hi, rot); |
| 4465 | __ orr(out_reg_hi, out_reg_hi, ShifterOperand(in_reg_lo, arm::LSL, kArmBitsPerWord - rot)); |
| 4466 | __ Lsr(out_reg_lo, in_reg_lo, rot); |
| 4467 | __ orr(out_reg_lo, out_reg_lo, ShifterOperand(in_reg_hi, arm::LSL, kArmBitsPerWord - rot)); |
| 4468 | } else { |
| 4469 | __ Mov(out_reg_lo, in_reg_lo); |
| 4470 | __ Mov(out_reg_hi, in_reg_hi); |
| 4471 | } |
| 4472 | } else { |
| 4473 | Register shift_right = locations->GetTemp(0).AsRegister<Register>(); |
| 4474 | Register shift_left = locations->GetTemp(1).AsRegister<Register>(); |
| 4475 | Label end; |
| 4476 | Label shift_by_32_plus_shift_right; |
| 4477 | |
| 4478 | __ and_(shift_right, rhs.AsRegister<Register>(), ShifterOperand(0x1F)); |
| 4479 | __ Lsrs(shift_left, rhs.AsRegister<Register>(), 6); |
| 4480 | __ rsb(shift_left, shift_right, ShifterOperand(kArmBitsPerWord), AL, kCcKeep); |
| 4481 | __ b(&shift_by_32_plus_shift_right, CC); |
| 4482 | |
| 4483 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4484 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4485 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4486 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4487 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4488 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4489 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4490 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_left)); |
| 4491 | __ b(&end); |
| 4492 | |
| 4493 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4494 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4495 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4496 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4497 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4498 | __ add(out_reg_hi, out_reg_hi, ShifterOperand(out_reg_lo)); |
| 4499 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4500 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4501 | __ add(out_reg_lo, out_reg_lo, ShifterOperand(shift_right)); |
| 4502 | |
| 4503 | __ Bind(&end); |
| 4504 | } |
| 4505 | } |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4506 | |
| 4507 | void LocationsBuilderARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4508 | LocationSummary* locations = |
| 4509 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 4510 | switch (ror->GetResultType()) { |
| 4511 | case Primitive::kPrimInt: { |
| 4512 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4513 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4514 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4515 | break; |
| 4516 | } |
| 4517 | case Primitive::kPrimLong: { |
| 4518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4519 | if (ror->InputAt(1)->IsConstant()) { |
| 4520 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4521 | } else { |
| 4522 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4523 | locations->AddTemp(Location::RequiresRegister()); |
| 4524 | locations->AddTemp(Location::RequiresRegister()); |
| 4525 | } |
| 4526 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4527 | break; |
| 4528 | } |
| 4529 | default: |
| 4530 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4531 | } |
| 4532 | } |
| 4533 | |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4534 | void InstructionCodeGeneratorARM::VisitRor(HRor* ror) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4535 | LocationSummary* locations = ror->GetLocations(); |
| 4536 | Primitive::Type type = ror->GetResultType(); |
| 4537 | switch (type) { |
| 4538 | case Primitive::kPrimInt: { |
| 4539 | HandleIntegerRotate(locations); |
| 4540 | break; |
| 4541 | } |
| 4542 | case Primitive::kPrimLong: { |
| 4543 | HandleLongRotate(locations); |
| 4544 | break; |
| 4545 | } |
| 4546 | default: |
| 4547 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4548 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4552 | void LocationsBuilderARM::HandleShift(HBinaryOperation* op) { |
| 4553 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4554 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4555 | LocationSummary* locations = |
| 4556 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4557 | |
| 4558 | switch (op->GetResultType()) { |
| 4559 | case Primitive::kPrimInt: { |
| 4560 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4561 | if (op->InputAt(1)->IsConstant()) { |
| 4562 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4564 | } else { |
| 4565 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4566 | // Make the output overlap, as it will be used to hold the masked |
| 4567 | // second input. |
| 4568 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4569 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4570 | break; |
| 4571 | } |
| 4572 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4573 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4574 | if (op->InputAt(1)->IsConstant()) { |
| 4575 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4576 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4577 | // don't clash with high registers which the register allocator currently guarantees. |
| 4578 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4579 | } else { |
| 4580 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4581 | locations->AddTemp(Location::RequiresRegister()); |
| 4582 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4583 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4584 | break; |
| 4585 | } |
| 4586 | default: |
| 4587 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) { |
| 4592 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4593 | |
| 4594 | LocationSummary* locations = op->GetLocations(); |
| 4595 | Location out = locations->Out(); |
| 4596 | Location first = locations->InAt(0); |
| 4597 | Location second = locations->InAt(1); |
| 4598 | |
| 4599 | Primitive::Type type = op->GetResultType(); |
| 4600 | switch (type) { |
| 4601 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4602 | Register out_reg = out.AsRegister<Register>(); |
| 4603 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4604 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4605 | Register second_reg = second.AsRegister<Register>(); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4606 | // 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] | 4607 | __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftDistance)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4608 | if (op->IsShl()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4609 | __ Lsl(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4610 | } else if (op->IsShr()) { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4611 | __ Asr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4612 | } else { |
Nicolas Geoffray | a4f3581 | 2015-06-22 23:12:45 +0100 | [diff] [blame] | 4613 | __ Lsr(out_reg, first_reg, out_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4614 | } |
| 4615 | } else { |
| 4616 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4617 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4618 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4619 | __ Mov(out_reg, first_reg); |
| 4620 | } else if (op->IsShl()) { |
| 4621 | __ Lsl(out_reg, first_reg, shift_value); |
| 4622 | } else if (op->IsShr()) { |
| 4623 | __ Asr(out_reg, first_reg, shift_value); |
| 4624 | } else { |
| 4625 | __ Lsr(out_reg, first_reg, shift_value); |
| 4626 | } |
| 4627 | } |
| 4628 | break; |
| 4629 | } |
| 4630 | case Primitive::kPrimLong: { |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4631 | Register o_h = out.AsRegisterPairHigh<Register>(); |
| 4632 | Register o_l = out.AsRegisterPairLow<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4633 | |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4634 | Register high = first.AsRegisterPairHigh<Register>(); |
| 4635 | Register low = first.AsRegisterPairLow<Register>(); |
| 4636 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4637 | if (second.IsRegister()) { |
| 4638 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Guillaume "Vermeille" Sanchez | fd18f5a | 2015-03-11 14:57:40 +0000 | [diff] [blame] | 4639 | |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4640 | Register second_reg = second.AsRegister<Register>(); |
| 4641 | |
| 4642 | if (op->IsShl()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4643 | __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4644 | // Shift the high part |
| 4645 | __ Lsl(o_h, high, o_l); |
| 4646 | // Shift the low part and `or` what overflew on the high part |
| 4647 | __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4648 | __ Lsr(temp, low, temp); |
| 4649 | __ orr(o_h, o_h, ShifterOperand(temp)); |
| 4650 | // If the shift is > 32 bits, override the high part |
| 4651 | __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord)); |
| 4652 | __ it(PL); |
| 4653 | __ Lsl(o_h, low, temp, PL); |
| 4654 | // Shift the low part |
| 4655 | __ Lsl(o_l, low, o_l); |
| 4656 | } else if (op->IsShr()) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4657 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4658 | // Shift the low part |
| 4659 | __ Lsr(o_l, low, o_h); |
| 4660 | // Shift the high part and `or` what underflew on the low part |
| 4661 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4662 | __ Lsl(temp, high, temp); |
| 4663 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4664 | // If the shift is > 32 bits, override the low part |
| 4665 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4666 | __ it(PL); |
| 4667 | __ Asr(o_l, high, temp, PL); |
| 4668 | // Shift the high part |
| 4669 | __ Asr(o_h, high, o_h); |
| 4670 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4671 | __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftDistance)); |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4672 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 4673 | __ Lsr(o_l, low, o_h); |
| 4674 | __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4675 | __ Lsl(temp, high, temp); |
| 4676 | __ orr(o_l, o_l, ShifterOperand(temp)); |
| 4677 | __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord)); |
| 4678 | __ it(PL); |
| 4679 | __ Lsr(o_l, high, temp, PL); |
| 4680 | __ Lsr(o_h, high, o_h); |
| 4681 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4682 | } else { |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4683 | // Register allocator doesn't create partial overlap. |
| 4684 | DCHECK_NE(o_l, high); |
| 4685 | DCHECK_NE(o_h, low); |
| 4686 | int32_t cst = second.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4687 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4688 | if (shift_value > 32) { |
| 4689 | if (op->IsShl()) { |
| 4690 | __ Lsl(o_h, low, shift_value - 32); |
| 4691 | __ LoadImmediate(o_l, 0); |
| 4692 | } else if (op->IsShr()) { |
| 4693 | __ Asr(o_l, high, shift_value - 32); |
| 4694 | __ Asr(o_h, high, 31); |
| 4695 | } else { |
| 4696 | __ Lsr(o_l, high, shift_value - 32); |
| 4697 | __ LoadImmediate(o_h, 0); |
| 4698 | } |
| 4699 | } else if (shift_value == 32) { |
| 4700 | if (op->IsShl()) { |
| 4701 | __ mov(o_h, ShifterOperand(low)); |
| 4702 | __ LoadImmediate(o_l, 0); |
| 4703 | } else if (op->IsShr()) { |
| 4704 | __ mov(o_l, ShifterOperand(high)); |
| 4705 | __ Asr(o_h, high, 31); |
| 4706 | } else { |
| 4707 | __ mov(o_l, ShifterOperand(high)); |
| 4708 | __ LoadImmediate(o_h, 0); |
| 4709 | } |
Vladimir Marko | f9d741e | 2015-11-20 15:08:11 +0000 | [diff] [blame] | 4710 | } else if (shift_value == 1) { |
| 4711 | if (op->IsShl()) { |
| 4712 | __ Lsls(o_l, low, 1); |
| 4713 | __ adc(o_h, high, ShifterOperand(high)); |
| 4714 | } else if (op->IsShr()) { |
| 4715 | __ Asrs(o_h, high, 1); |
| 4716 | __ Rrx(o_l, low); |
| 4717 | } else { |
| 4718 | __ Lsrs(o_h, high, 1); |
| 4719 | __ Rrx(o_l, low); |
| 4720 | } |
| 4721 | } else { |
| 4722 | DCHECK(2 <= shift_value && shift_value < 32) << shift_value; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4723 | if (op->IsShl()) { |
| 4724 | __ Lsl(o_h, high, shift_value); |
| 4725 | __ orr(o_h, o_h, ShifterOperand(low, LSR, 32 - shift_value)); |
| 4726 | __ Lsl(o_l, low, shift_value); |
| 4727 | } else if (op->IsShr()) { |
| 4728 | __ Lsr(o_l, low, shift_value); |
| 4729 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4730 | __ Asr(o_h, high, shift_value); |
| 4731 | } else { |
| 4732 | __ Lsr(o_l, low, shift_value); |
| 4733 | __ orr(o_l, o_l, ShifterOperand(high, LSL, 32 - shift_value)); |
| 4734 | __ Lsr(o_h, high, shift_value); |
| 4735 | } |
| 4736 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4737 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4738 | break; |
| 4739 | } |
| 4740 | default: |
| 4741 | LOG(FATAL) << "Unexpected operation type " << type; |
Vladimir Marko | 33ad10e | 2015-11-10 19:31:26 +0000 | [diff] [blame] | 4742 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | void LocationsBuilderARM::VisitShl(HShl* shl) { |
| 4747 | HandleShift(shl); |
| 4748 | } |
| 4749 | |
| 4750 | void InstructionCodeGeneratorARM::VisitShl(HShl* shl) { |
| 4751 | HandleShift(shl); |
| 4752 | } |
| 4753 | |
| 4754 | void LocationsBuilderARM::VisitShr(HShr* shr) { |
| 4755 | HandleShift(shr); |
| 4756 | } |
| 4757 | |
| 4758 | void InstructionCodeGeneratorARM::VisitShr(HShr* shr) { |
| 4759 | HandleShift(shr); |
| 4760 | } |
| 4761 | |
| 4762 | void LocationsBuilderARM::VisitUShr(HUShr* ushr) { |
| 4763 | HandleShift(ushr); |
| 4764 | } |
| 4765 | |
| 4766 | void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) { |
| 4767 | HandleShift(ushr); |
| 4768 | } |
| 4769 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4770 | void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4771 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4772 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4773 | if (instruction->IsStringAlloc()) { |
| 4774 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4775 | } else { |
| 4776 | InvokeRuntimeCallingConvention calling_convention; |
| 4777 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4778 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4779 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4783 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4784 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4785 | if (instruction->IsStringAlloc()) { |
| 4786 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4787 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4788 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4789 | __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString)); |
| 4790 | __ LoadFromOffset(kLoadWord, LR, temp, code_offset.Int32Value()); |
| 4791 | __ blx(LR); |
| 4792 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4793 | } else { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 4794 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4795 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4796 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4797 | } |
| 4798 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4799 | void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) { |
| 4800 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4801 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4802 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4803 | locations->SetOut(Location::RegisterLocation(R0)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4804 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4805 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4809 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4810 | // of poisoning the reference. |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4811 | QuickEntrypointEnum entrypoint = |
| 4812 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4813 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4814 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4815 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4816 | } |
| 4817 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4818 | void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4819 | LocationSummary* locations = |
| 4820 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4821 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4822 | if (location.IsStackSlot()) { |
| 4823 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4824 | } else if (location.IsDoubleStackSlot()) { |
| 4825 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4826 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4827 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4828 | } |
| 4829 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4830 | void InstructionCodeGeneratorARM::VisitParameterValue( |
| 4831 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 4832 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4836 | LocationSummary* locations = |
| 4837 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4838 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4839 | } |
| 4840 | |
| 4841 | void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4842 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4845 | void LocationsBuilderARM::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4846 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4847 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4848 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4849 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4850 | } |
| 4851 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4852 | void InstructionCodeGeneratorARM::VisitNot(HNot* not_) { |
| 4853 | LocationSummary* locations = not_->GetLocations(); |
| 4854 | Location out = locations->Out(); |
| 4855 | Location in = locations->InAt(0); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4856 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4857 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4858 | __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4859 | break; |
| 4860 | |
| 4861 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4862 | __ mvn(out.AsRegisterPairLow<Register>(), |
| 4863 | ShifterOperand(in.AsRegisterPairLow<Register>())); |
| 4864 | __ mvn(out.AsRegisterPairHigh<Register>(), |
| 4865 | ShifterOperand(in.AsRegisterPairHigh<Register>())); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4866 | break; |
| 4867 | |
| 4868 | default: |
| 4869 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4870 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4873 | void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4874 | LocationSummary* locations = |
| 4875 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4876 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4877 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4878 | } |
| 4879 | |
| 4880 | void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4881 | LocationSummary* locations = bool_not->GetLocations(); |
| 4882 | Location out = locations->Out(); |
| 4883 | Location in = locations->InAt(0); |
| 4884 | __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1)); |
| 4885 | } |
| 4886 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4887 | void LocationsBuilderARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4888 | LocationSummary* locations = |
| 4889 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4890 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4891 | case Primitive::kPrimBoolean: |
| 4892 | case Primitive::kPrimByte: |
| 4893 | case Primitive::kPrimShort: |
| 4894 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4895 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4896 | case Primitive::kPrimLong: { |
| 4897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4898 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 4899 | // Output overlaps because it is written before doing the low comparison. |
| 4900 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4901 | break; |
| 4902 | } |
| 4903 | case Primitive::kPrimFloat: |
| 4904 | case Primitive::kPrimDouble: { |
| 4905 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 4906 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4907 | locations->SetOut(Location::RequiresRegister()); |
| 4908 | break; |
| 4909 | } |
| 4910 | default: |
| 4911 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4912 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4916 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4917 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4918 | Location left = locations->InAt(0); |
| 4919 | Location right = locations->InAt(1); |
| 4920 | |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 4921 | Label less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4922 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4923 | Condition less_cond; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4924 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4925 | case Primitive::kPrimBoolean: |
| 4926 | case Primitive::kPrimByte: |
| 4927 | case Primitive::kPrimShort: |
| 4928 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4929 | case Primitive::kPrimInt: { |
| 4930 | __ LoadImmediate(out, 0); |
| 4931 | __ cmp(left.AsRegister<Register>(), |
| 4932 | ShifterOperand(right.AsRegister<Register>())); // Signed compare. |
| 4933 | less_cond = LT; |
| 4934 | break; |
| 4935 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4936 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4937 | __ cmp(left.AsRegisterPairHigh<Register>(), |
| 4938 | ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare. |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4939 | __ b(&less, LT); |
| 4940 | __ b(&greater, GT); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 4941 | // 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] | 4942 | __ LoadImmediate(out, 0); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4943 | __ cmp(left.AsRegisterPairLow<Register>(), |
| 4944 | ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4945 | less_cond = LO; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4946 | break; |
| 4947 | } |
| 4948 | case Primitive::kPrimFloat: |
| 4949 | case Primitive::kPrimDouble: { |
| 4950 | __ LoadImmediate(out, 0); |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 4951 | GenerateVcmp(compare, codegen_); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4952 | __ vmstat(); // transfer FP status register to ARM APSR. |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4953 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4954 | break; |
| 4955 | } |
| 4956 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4957 | LOG(FATAL) << "Unexpected compare type " << type; |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4958 | UNREACHABLE(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4959 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4960 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4961 | __ b(&done, EQ); |
Vladimir Marko | d6e069b | 2016-01-18 11:11:01 +0000 | [diff] [blame] | 4962 | __ b(&less, less_cond); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4963 | |
| 4964 | __ Bind(&greater); |
| 4965 | __ LoadImmediate(out, 1); |
| 4966 | __ b(&done); |
| 4967 | |
| 4968 | __ Bind(&less); |
| 4969 | __ LoadImmediate(out, -1); |
| 4970 | |
| 4971 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4974 | void LocationsBuilderARM::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4975 | LocationSummary* locations = |
| 4976 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4977 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4978 | locations->SetInAt(i, Location::Any()); |
| 4979 | } |
| 4980 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4981 | } |
| 4982 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4983 | void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4984 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4985 | } |
| 4986 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 4987 | void CodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4988 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 4989 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4990 | switch (kind) { |
| 4991 | case MemBarrierKind::kAnyStore: |
| 4992 | case MemBarrierKind::kLoadAny: |
| 4993 | case MemBarrierKind::kAnyAny: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4994 | flavor = DmbOptions::ISH; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4995 | break; |
| 4996 | } |
| 4997 | case MemBarrierKind::kStoreStore: { |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 4998 | flavor = DmbOptions::ISHST; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4999 | break; |
| 5000 | } |
| 5001 | default: |
| 5002 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5003 | } |
Kenny Root | 1d8199d | 2015-06-02 11:01:10 -0700 | [diff] [blame] | 5004 | __ dmb(flavor); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr, |
| 5008 | uint32_t offset, |
| 5009 | Register out_lo, |
| 5010 | Register out_hi) { |
| 5011 | if (offset != 0) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5012 | // Ensure `out_lo` is different from `addr`, so that loading |
| 5013 | // `offset` into `out_lo` does not clutter `addr`. |
| 5014 | DCHECK_NE(out_lo, addr); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5015 | __ LoadImmediate(out_lo, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5016 | __ add(IP, addr, ShifterOperand(out_lo)); |
| 5017 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5018 | } |
| 5019 | __ ldrexd(out_lo, out_hi, addr); |
| 5020 | } |
| 5021 | |
| 5022 | void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr, |
| 5023 | uint32_t offset, |
| 5024 | Register value_lo, |
| 5025 | Register value_hi, |
| 5026 | Register temp1, |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5027 | Register temp2, |
| 5028 | HInstruction* instruction) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 5029 | Label fail; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5030 | if (offset != 0) { |
| 5031 | __ LoadImmediate(temp1, offset); |
Nicolas Geoffray | bdcedd3 | 2015-01-09 08:48:29 +0000 | [diff] [blame] | 5032 | __ add(IP, addr, ShifterOperand(temp1)); |
| 5033 | addr = IP; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5034 | } |
| 5035 | __ Bind(&fail); |
| 5036 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5037 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5038 | __ ldrexd(temp1, temp2, addr); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5039 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5040 | __ strexd(temp1, value_lo, value_hi, addr); |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5041 | __ CompareAndBranchIfNonZero(temp1, &fail); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5045 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5046 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5047 | LocationSummary* locations = |
| 5048 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5049 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5050 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5051 | Primitive::Type field_type = field_info.GetFieldType(); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5052 | if (Primitive::IsFloatingPointType(field_type)) { |
| 5053 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5054 | } else { |
| 5055 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5056 | } |
| 5057 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble; |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5059 | bool generate_volatile = field_info.IsVolatile() |
| 5060 | && is_wide |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5061 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5062 | bool needs_write_barrier = |
| 5063 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5064 | // Temporary registers for the write barrier. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5065 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5066 | if (needs_write_barrier) { |
| 5067 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5068 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5069 | } else if (generate_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5070 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5071 | // - registers need to be consecutive |
| 5072 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5073 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5074 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5075 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5076 | |
| 5077 | locations->AddTemp(Location::RequiresRegister()); |
| 5078 | locations->AddTemp(Location::RequiresRegister()); |
| 5079 | if (field_type == Primitive::kPrimDouble) { |
| 5080 | // For doubles we need two more registers to copy the value. |
| 5081 | locations->AddTemp(Location::RegisterLocation(R2)); |
| 5082 | locations->AddTemp(Location::RegisterLocation(R3)); |
| 5083 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5084 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5085 | } |
| 5086 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5087 | void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5088 | const FieldInfo& field_info, |
| 5089 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5090 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5091 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5092 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5093 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 5094 | Location value = locations->InAt(1); |
| 5095 | |
| 5096 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5097 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5098 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5099 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5100 | bool needs_write_barrier = |
| 5101 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5102 | |
| 5103 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5104 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5105 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5106 | |
| 5107 | switch (field_type) { |
| 5108 | case Primitive::kPrimBoolean: |
| 5109 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5110 | __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5111 | break; |
| 5112 | } |
| 5113 | |
| 5114 | case Primitive::kPrimShort: |
| 5115 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5116 | __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5117 | break; |
| 5118 | } |
| 5119 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5120 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5121 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5122 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5123 | // Note that in the case where `value` is a null reference, |
| 5124 | // we do not enter this block, as a null reference does not |
| 5125 | // need poisoning. |
| 5126 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 5127 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5128 | __ Mov(temp, value.AsRegister<Register>()); |
| 5129 | __ PoisonHeapReference(temp); |
| 5130 | __ StoreToOffset(kStoreWord, temp, base, offset); |
| 5131 | } else { |
| 5132 | __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset); |
| 5133 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5134 | break; |
| 5135 | } |
| 5136 | |
| 5137 | case Primitive::kPrimLong: { |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5138 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5139 | GenerateWideAtomicStore(base, offset, |
| 5140 | value.AsRegisterPairLow<Register>(), |
| 5141 | value.AsRegisterPairHigh<Register>(), |
| 5142 | locations->GetTemp(0).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5143 | locations->GetTemp(1).AsRegister<Register>(), |
| 5144 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5145 | } else { |
| 5146 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5147 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5148 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5149 | break; |
| 5150 | } |
| 5151 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5152 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5153 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5154 | break; |
| 5155 | } |
| 5156 | |
| 5157 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5158 | DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5159 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5160 | Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5161 | Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5162 | |
| 5163 | __ vmovrrd(value_reg_lo, value_reg_hi, value_reg); |
| 5164 | |
| 5165 | GenerateWideAtomicStore(base, offset, |
| 5166 | value_reg_lo, |
| 5167 | value_reg_hi, |
| 5168 | locations->GetTemp(2).AsRegister<Register>(), |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5169 | locations->GetTemp(3).AsRegister<Register>(), |
| 5170 | instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5171 | } else { |
| 5172 | __ StoreDToOffset(value_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5173 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5174 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5175 | break; |
| 5176 | } |
| 5177 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5178 | case Primitive::kPrimVoid: |
| 5179 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5180 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5181 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5182 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5183 | // Longs and doubles are handled in the switch. |
| 5184 | if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) { |
| 5185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5186 | } |
| 5187 | |
| 5188 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5189 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 5190 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5191 | codegen_->MarkGCCard( |
| 5192 | temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5195 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5196 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5197 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5200 | void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 5201 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5202 | |
| 5203 | bool object_field_get_with_read_barrier = |
| 5204 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5205 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5206 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5207 | object_field_get_with_read_barrier ? |
| 5208 | LocationSummary::kCallOnSlowPath : |
| 5209 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5210 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5211 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5212 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5213 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5214 | |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5215 | bool volatile_for_double = field_info.IsVolatile() |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5216 | && (field_info.GetFieldType() == Primitive::kPrimDouble) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5217 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5218 | // The output overlaps in case of volatile long: we don't want the |
| 5219 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5220 | // object's location. Likewise, in the case of an object field get |
| 5221 | // with read barriers enabled, we do not want the load to overwrite |
| 5222 | // the object's location, as we need it to emit the read barrier. |
| 5223 | bool overlap = (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) || |
| 5224 | object_field_get_with_read_barrier; |
Nicolas Geoffray | acc0b8e | 2015-04-20 12:39:57 +0100 | [diff] [blame] | 5225 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5226 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5227 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5228 | } else { |
| 5229 | locations->SetOut(Location::RequiresRegister(), |
| 5230 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5231 | } |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 5232 | if (volatile_for_double) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5233 | // ARM encoding have some additional constraints for ldrexd/strexd: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5234 | // - registers need to be consecutive |
| 5235 | // - the first register should be even but not R14. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5236 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5237 | // revisit this if we ever enable ARM encoding. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5238 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5239 | locations->AddTemp(Location::RequiresRegister()); |
| 5240 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5241 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5242 | // We need a temporary register for the read barrier marking slow |
| 5243 | // path in CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier. |
| 5244 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5245 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
Vladimir Marko | 37dd80d | 2016-08-01 17:41:45 +0100 | [diff] [blame] | 5248 | Location LocationsBuilderARM::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| 5249 | DCHECK(input->GetType() == Primitive::kPrimDouble || input->GetType() == Primitive::kPrimFloat) |
| 5250 | << input->GetType(); |
| 5251 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5252 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5253 | return Location::ConstantLocation(input->AsConstant()); |
| 5254 | } else { |
| 5255 | return Location::RequiresFpuRegister(); |
| 5256 | } |
| 5257 | } |
| 5258 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5259 | Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5260 | Opcode opcode) { |
| 5261 | DCHECK(!Primitive::IsFloatingPointType(constant->GetType())); |
| 5262 | if (constant->IsConstant() && |
| 5263 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5264 | return Location::ConstantLocation(constant->AsConstant()); |
| 5265 | } |
| 5266 | return Location::RequiresRegister(); |
| 5267 | } |
| 5268 | |
| 5269 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst, |
| 5270 | Opcode opcode) { |
| 5271 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5272 | if (Primitive::Is64BitType(input_cst->GetType())) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5273 | Opcode high_opcode = opcode; |
| 5274 | SetCc low_set_cc = kCcDontCare; |
| 5275 | switch (opcode) { |
| 5276 | case SUB: |
| 5277 | // Flip the operation to an ADD. |
| 5278 | value = -value; |
| 5279 | opcode = ADD; |
| 5280 | FALLTHROUGH_INTENDED; |
| 5281 | case ADD: |
| 5282 | if (Low32Bits(value) == 0u) { |
| 5283 | return CanEncodeConstantAsImmediate(High32Bits(value), opcode, kCcDontCare); |
| 5284 | } |
| 5285 | high_opcode = ADC; |
| 5286 | low_set_cc = kCcSet; |
| 5287 | break; |
| 5288 | default: |
| 5289 | break; |
| 5290 | } |
| 5291 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode, low_set_cc) && |
| 5292 | CanEncodeConstantAsImmediate(High32Bits(value), high_opcode, kCcDontCare); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5293 | } else { |
| 5294 | return CanEncodeConstantAsImmediate(Low32Bits(value), opcode); |
| 5295 | } |
| 5296 | } |
| 5297 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5298 | bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, |
| 5299 | Opcode opcode, |
| 5300 | SetCc set_cc) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5301 | ShifterOperand so; |
| 5302 | ArmAssembler* assembler = codegen_->GetAssembler(); |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5303 | if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, set_cc, &so)) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5304 | return true; |
| 5305 | } |
| 5306 | Opcode neg_opcode = kNoOperand; |
| 5307 | switch (opcode) { |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5308 | case AND: neg_opcode = BIC; value = ~value; break; |
| 5309 | case ORR: neg_opcode = ORN; value = ~value; break; |
| 5310 | case ADD: neg_opcode = SUB; value = -value; break; |
| 5311 | case ADC: neg_opcode = SBC; value = ~value; break; |
| 5312 | case SUB: neg_opcode = ADD; value = -value; break; |
| 5313 | case SBC: neg_opcode = ADC; value = ~value; break; |
Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5314 | case MOV: neg_opcode = MVN; value = ~value; break; |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5315 | default: |
| 5316 | return false; |
| 5317 | } |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 5318 | return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, value, set_cc, &so); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 5319 | } |
| 5320 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5321 | void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction, |
| 5322 | const FieldInfo& field_info) { |
| 5323 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5324 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5325 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5326 | Location base_loc = locations->InAt(0); |
| 5327 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5328 | Location out = locations->Out(); |
| 5329 | bool is_volatile = field_info.IsVolatile(); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5330 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5331 | Primitive::Type field_type = field_info.GetFieldType(); |
| 5332 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5333 | |
| 5334 | switch (field_type) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5335 | case Primitive::kPrimBoolean: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5336 | __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5337 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5338 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5339 | case Primitive::kPrimByte: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5340 | __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5341 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5342 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5343 | case Primitive::kPrimShort: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5344 | __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5345 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5346 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5347 | case Primitive::kPrimChar: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5348 | __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5349 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5350 | |
| 5351 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5352 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5353 | break; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5354 | |
| 5355 | case Primitive::kPrimNot: { |
| 5356 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5357 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5358 | Location temp_loc = locations->GetTemp(0); |
| 5359 | // Note that a potential implicit null check is handled in this |
| 5360 | // CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier call. |
| 5361 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 5362 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 5363 | if (is_volatile) { |
| 5364 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5365 | } |
| 5366 | } else { |
| 5367 | __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset); |
| 5368 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5369 | if (is_volatile) { |
| 5370 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5371 | } |
| 5372 | // If read barriers are enabled, emit read barriers other than |
| 5373 | // Baker's using a slow path (and also unpoison the loaded |
| 5374 | // reference, if heap poisoning is enabled). |
| 5375 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 5376 | } |
| 5377 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5378 | } |
| 5379 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5380 | case Primitive::kPrimLong: |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5381 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5382 | GenerateWideAtomicLoad(base, offset, |
| 5383 | out.AsRegisterPairLow<Register>(), |
| 5384 | out.AsRegisterPairHigh<Register>()); |
| 5385 | } else { |
| 5386 | __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset); |
| 5387 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5388 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5389 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5390 | case Primitive::kPrimFloat: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5391 | __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5392 | break; |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5393 | |
| 5394 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5395 | DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()); |
Calin Juravle | 3416601 | 2014-12-19 17:22:29 +0000 | [diff] [blame] | 5396 | if (is_volatile && !atomic_ldrd_strd) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5397 | Register lo = locations->GetTemp(0).AsRegister<Register>(); |
| 5398 | Register hi = locations->GetTemp(1).AsRegister<Register>(); |
| 5399 | GenerateWideAtomicLoad(base, offset, lo, hi); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5400 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5401 | __ vmovdrr(out_reg, lo, hi); |
| 5402 | } else { |
| 5403 | __ LoadDFromOffset(out_reg, base, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5404 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5405 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5406 | break; |
| 5407 | } |
| 5408 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5409 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5410 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5411 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5412 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5413 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5414 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimDouble) { |
| 5415 | // Potential implicit null checks, in the case of reference or |
| 5416 | // double fields, are handled in the previous switch statement. |
| 5417 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5418 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5419 | } |
| 5420 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5421 | if (is_volatile) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5422 | if (field_type == Primitive::kPrimNot) { |
| 5423 | // Memory barriers, in the case of references, are also handled |
| 5424 | // in the previous switch statement. |
| 5425 | } else { |
| 5426 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5427 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5428 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5432 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5433 | } |
| 5434 | |
| 5435 | void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5436 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5440 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5441 | } |
| 5442 | |
| 5443 | void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5444 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5445 | } |
| 5446 | |
| 5447 | void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5448 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5449 | } |
| 5450 | |
| 5451 | void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5452 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5453 | } |
| 5454 | |
| 5455 | void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5456 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5457 | } |
| 5458 | |
| 5459 | void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5460 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5461 | } |
| 5462 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5463 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet( |
| 5464 | HUnresolvedInstanceFieldGet* instruction) { |
| 5465 | FieldAccessCallingConventionARM calling_convention; |
| 5466 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5467 | instruction, instruction->GetFieldType(), calling_convention); |
| 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet( |
| 5471 | HUnresolvedInstanceFieldGet* instruction) { |
| 5472 | FieldAccessCallingConventionARM calling_convention; |
| 5473 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5474 | instruction->GetFieldType(), |
| 5475 | instruction->GetFieldIndex(), |
| 5476 | instruction->GetDexPc(), |
| 5477 | calling_convention); |
| 5478 | } |
| 5479 | |
| 5480 | void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet( |
| 5481 | HUnresolvedInstanceFieldSet* instruction) { |
| 5482 | FieldAccessCallingConventionARM calling_convention; |
| 5483 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5484 | instruction, instruction->GetFieldType(), calling_convention); |
| 5485 | } |
| 5486 | |
| 5487 | void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet( |
| 5488 | HUnresolvedInstanceFieldSet* instruction) { |
| 5489 | FieldAccessCallingConventionARM calling_convention; |
| 5490 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5491 | instruction->GetFieldType(), |
| 5492 | instruction->GetFieldIndex(), |
| 5493 | instruction->GetDexPc(), |
| 5494 | calling_convention); |
| 5495 | } |
| 5496 | |
| 5497 | void LocationsBuilderARM::VisitUnresolvedStaticFieldGet( |
| 5498 | HUnresolvedStaticFieldGet* instruction) { |
| 5499 | FieldAccessCallingConventionARM calling_convention; |
| 5500 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5501 | instruction, instruction->GetFieldType(), calling_convention); |
| 5502 | } |
| 5503 | |
| 5504 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet( |
| 5505 | HUnresolvedStaticFieldGet* instruction) { |
| 5506 | FieldAccessCallingConventionARM calling_convention; |
| 5507 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5508 | instruction->GetFieldType(), |
| 5509 | instruction->GetFieldIndex(), |
| 5510 | instruction->GetDexPc(), |
| 5511 | calling_convention); |
| 5512 | } |
| 5513 | |
| 5514 | void LocationsBuilderARM::VisitUnresolvedStaticFieldSet( |
| 5515 | HUnresolvedStaticFieldSet* instruction) { |
| 5516 | FieldAccessCallingConventionARM calling_convention; |
| 5517 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5518 | instruction, instruction->GetFieldType(), calling_convention); |
| 5519 | } |
| 5520 | |
| 5521 | void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet( |
| 5522 | HUnresolvedStaticFieldSet* instruction) { |
| 5523 | FieldAccessCallingConventionARM calling_convention; |
| 5524 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5525 | instruction->GetFieldType(), |
| 5526 | instruction->GetFieldIndex(), |
| 5527 | instruction->GetDexPc(), |
| 5528 | calling_convention); |
| 5529 | } |
| 5530 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5531 | void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5532 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5533 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5534 | } |
| 5535 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5536 | void CodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5537 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5538 | return; |
| 5539 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5540 | Location obj = instruction->GetLocations()->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5541 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5542 | __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5543 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5546 | void CodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 5547 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5548 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5549 | |
| 5550 | LocationSummary* locations = instruction->GetLocations(); |
| 5551 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5552 | |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 5553 | __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5554 | } |
| 5555 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5556 | void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5557 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5558 | } |
| 5559 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5560 | static LoadOperandType GetLoadOperandType(Primitive::Type type) { |
| 5561 | switch (type) { |
| 5562 | case Primitive::kPrimNot: |
| 5563 | return kLoadWord; |
| 5564 | case Primitive::kPrimBoolean: |
| 5565 | return kLoadUnsignedByte; |
| 5566 | case Primitive::kPrimByte: |
| 5567 | return kLoadSignedByte; |
| 5568 | case Primitive::kPrimChar: |
| 5569 | return kLoadUnsignedHalfword; |
| 5570 | case Primitive::kPrimShort: |
| 5571 | return kLoadSignedHalfword; |
| 5572 | case Primitive::kPrimInt: |
| 5573 | return kLoadWord; |
| 5574 | case Primitive::kPrimLong: |
| 5575 | return kLoadWordPair; |
| 5576 | case Primitive::kPrimFloat: |
| 5577 | return kLoadSWord; |
| 5578 | case Primitive::kPrimDouble: |
| 5579 | return kLoadDWord; |
| 5580 | default: |
| 5581 | LOG(FATAL) << "Unreachable type " << type; |
| 5582 | UNREACHABLE(); |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | static StoreOperandType GetStoreOperandType(Primitive::Type type) { |
| 5587 | switch (type) { |
| 5588 | case Primitive::kPrimNot: |
| 5589 | return kStoreWord; |
| 5590 | case Primitive::kPrimBoolean: |
| 5591 | case Primitive::kPrimByte: |
| 5592 | return kStoreByte; |
| 5593 | case Primitive::kPrimChar: |
| 5594 | case Primitive::kPrimShort: |
| 5595 | return kStoreHalfword; |
| 5596 | case Primitive::kPrimInt: |
| 5597 | return kStoreWord; |
| 5598 | case Primitive::kPrimLong: |
| 5599 | return kStoreWordPair; |
| 5600 | case Primitive::kPrimFloat: |
| 5601 | return kStoreSWord; |
| 5602 | case Primitive::kPrimDouble: |
| 5603 | return kStoreDWord; |
| 5604 | default: |
| 5605 | LOG(FATAL) << "Unreachable type " << type; |
| 5606 | UNREACHABLE(); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | void CodeGeneratorARM::LoadFromShiftedRegOffset(Primitive::Type type, |
| 5611 | Location out_loc, |
| 5612 | Register base, |
| 5613 | Register reg_offset, |
| 5614 | Condition cond) { |
| 5615 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5616 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5617 | |
| 5618 | switch (type) { |
| 5619 | case Primitive::kPrimByte: |
| 5620 | __ ldrsb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5621 | break; |
| 5622 | case Primitive::kPrimBoolean: |
| 5623 | __ ldrb(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5624 | break; |
| 5625 | case Primitive::kPrimShort: |
| 5626 | __ ldrsh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5627 | break; |
| 5628 | case Primitive::kPrimChar: |
| 5629 | __ ldrh(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5630 | break; |
| 5631 | case Primitive::kPrimNot: |
| 5632 | case Primitive::kPrimInt: |
| 5633 | __ ldr(out_loc.AsRegister<Register>(), mem_address, cond); |
| 5634 | break; |
| 5635 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| 5636 | case Primitive::kPrimLong: |
| 5637 | case Primitive::kPrimFloat: |
| 5638 | case Primitive::kPrimDouble: |
| 5639 | default: |
| 5640 | LOG(FATAL) << "Unreachable type " << type; |
| 5641 | UNREACHABLE(); |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | void CodeGeneratorARM::StoreToShiftedRegOffset(Primitive::Type type, |
| 5646 | Location loc, |
| 5647 | Register base, |
| 5648 | Register reg_offset, |
| 5649 | Condition cond) { |
| 5650 | uint32_t shift_count = Primitive::ComponentSizeShift(type); |
| 5651 | Address mem_address(base, reg_offset, Shift::LSL, shift_count); |
| 5652 | |
| 5653 | switch (type) { |
| 5654 | case Primitive::kPrimByte: |
| 5655 | case Primitive::kPrimBoolean: |
| 5656 | __ strb(loc.AsRegister<Register>(), mem_address, cond); |
| 5657 | break; |
| 5658 | case Primitive::kPrimShort: |
| 5659 | case Primitive::kPrimChar: |
| 5660 | __ strh(loc.AsRegister<Register>(), mem_address, cond); |
| 5661 | break; |
| 5662 | case Primitive::kPrimNot: |
| 5663 | case Primitive::kPrimInt: |
| 5664 | __ str(loc.AsRegister<Register>(), mem_address, cond); |
| 5665 | break; |
| 5666 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| 5667 | case Primitive::kPrimLong: |
| 5668 | case Primitive::kPrimFloat: |
| 5669 | case Primitive::kPrimDouble: |
| 5670 | default: |
| 5671 | LOG(FATAL) << "Unreachable type " << type; |
| 5672 | UNREACHABLE(); |
| 5673 | } |
| 5674 | } |
| 5675 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5676 | void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5677 | bool object_array_get_with_read_barrier = |
| 5678 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5679 | LocationSummary* locations = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5680 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5681 | object_array_get_with_read_barrier ? |
| 5682 | LocationSummary::kCallOnSlowPath : |
| 5683 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5684 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5685 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5686 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5687 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5688 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5689 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5690 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5691 | } else { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5692 | // The output overlaps in the case of an object array get with |
| 5693 | // read barriers enabled: we do not want the move to overwrite the |
| 5694 | // array's location, as we need it to emit the read barrier. |
| 5695 | locations->SetOut( |
| 5696 | Location::RequiresRegister(), |
| 5697 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5698 | } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5699 | // We need a temporary register for the read barrier marking slow |
| 5700 | // path in CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5701 | // Also need for String compression feature. |
| 5702 | if ((object_array_get_with_read_barrier && kUseBakerReadBarrier) |
| 5703 | || (mirror::kUseStringCompression && instruction->IsStringCharAt())) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5704 | locations->AddTemp(Location::RequiresRegister()); |
| 5705 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) { |
| 5709 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5710 | Location obj_loc = locations->InAt(0); |
| 5711 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5712 | Location index = locations->InAt(1); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5713 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5714 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5715 | Primitive::Type type = instruction->GetType(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5716 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 5717 | instruction->IsStringCharAt(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5718 | HInstruction* array_instr = instruction->GetArray(); |
| 5719 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5720 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5721 | switch (type) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5722 | case Primitive::kPrimBoolean: |
| 5723 | case Primitive::kPrimByte: |
| 5724 | case Primitive::kPrimShort: |
| 5725 | case Primitive::kPrimChar: |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5726 | case Primitive::kPrimInt: { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5727 | Register length; |
| 5728 | if (maybe_compressed_char_at) { |
| 5729 | length = locations->GetTemp(0).AsRegister<Register>(); |
| 5730 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5731 | __ LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 5732 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5733 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5734 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5735 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5736 | if (maybe_compressed_char_at) { |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5737 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5738 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5739 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5740 | "Expecting 0=compressed, 1=uncompressed"); |
| 5741 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5742 | __ LoadFromOffset(kLoadUnsignedByte, |
| 5743 | out_loc.AsRegister<Register>(), |
| 5744 | obj, |
| 5745 | data_offset + const_index); |
| 5746 | __ b(&done); |
| 5747 | __ Bind(&uncompressed_load); |
| 5748 | __ LoadFromOffset(GetLoadOperandType(Primitive::kPrimChar), |
| 5749 | out_loc.AsRegister<Register>(), |
| 5750 | obj, |
| 5751 | data_offset + (const_index << 1)); |
| 5752 | __ Bind(&done); |
| 5753 | } else { |
| 5754 | uint32_t full_offset = data_offset + (const_index << Primitive::ComponentSizeShift(type)); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5755 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5756 | LoadOperandType load_type = GetLoadOperandType(type); |
| 5757 | __ LoadFromOffset(load_type, out_loc.AsRegister<Register>(), obj, full_offset); |
| 5758 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5759 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5760 | Register temp = IP; |
| 5761 | |
| 5762 | if (has_intermediate_address) { |
| 5763 | // We do not need to compute the intermediate address from the array: the |
| 5764 | // input instruction has done it already. See the comment in |
| 5765 | // `TryExtractArrayAccessAddress()`. |
| 5766 | if (kIsDebugBuild) { |
| 5767 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5768 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5769 | } |
| 5770 | temp = obj; |
| 5771 | } else { |
| 5772 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5773 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5774 | if (maybe_compressed_char_at) { |
| 5775 | Label uncompressed_load, done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5776 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 5777 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5778 | "Expecting 0=compressed, 1=uncompressed"); |
| 5779 | __ b(&uncompressed_load, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5780 | __ ldrb(out_loc.AsRegister<Register>(), |
| 5781 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 0)); |
| 5782 | __ b(&done); |
| 5783 | __ Bind(&uncompressed_load); |
| 5784 | __ ldrh(out_loc.AsRegister<Register>(), |
| 5785 | Address(temp, index.AsRegister<Register>(), Shift::LSL, 1)); |
| 5786 | __ Bind(&done); |
| 5787 | } else { |
| 5788 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
| 5789 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5790 | } |
| 5791 | break; |
| 5792 | } |
| 5793 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5794 | case Primitive::kPrimNot: { |
Roland Levillain | 19c5419 | 2016-11-04 13:44:09 +0000 | [diff] [blame] | 5795 | // The read barrier instrumentation of object ArrayGet |
| 5796 | // instructions does not support the HIntermediateAddress |
| 5797 | // instruction. |
| 5798 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 5799 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5800 | static_assert( |
| 5801 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5802 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5803 | // /* HeapReference<Object> */ out = |
| 5804 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5805 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5806 | Location temp = locations->GetTemp(0); |
| 5807 | // Note that a potential implicit null check is handled in this |
| 5808 | // CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier call. |
| 5809 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5810 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5811 | } else { |
| 5812 | Register out = out_loc.AsRegister<Register>(); |
| 5813 | if (index.IsConstant()) { |
| 5814 | size_t offset = |
| 5815 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5816 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
| 5817 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5818 | // If read barriers are enabled, emit read barriers other than |
| 5819 | // Baker's using a slow path (and also unpoison the loaded |
| 5820 | // reference, if heap poisoning is enabled). |
| 5821 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5822 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5823 | Register temp = IP; |
| 5824 | |
| 5825 | if (has_intermediate_address) { |
| 5826 | // We do not need to compute the intermediate address from the array: the |
| 5827 | // input instruction has done it already. See the comment in |
| 5828 | // `TryExtractArrayAccessAddress()`. |
| 5829 | if (kIsDebugBuild) { |
| 5830 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5831 | DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), data_offset); |
| 5832 | } |
| 5833 | temp = obj; |
| 5834 | } else { |
| 5835 | __ add(temp, obj, ShifterOperand(data_offset)); |
| 5836 | } |
| 5837 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, index.AsRegister<Register>()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5838 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5839 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5840 | // If read barriers are enabled, emit read barriers other than |
| 5841 | // Baker's using a slow path (and also unpoison the loaded |
| 5842 | // reference, if heap poisoning is enabled). |
| 5843 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5844 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5845 | } |
| 5846 | } |
| 5847 | break; |
| 5848 | } |
| 5849 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5850 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5851 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5852 | size_t offset = |
| 5853 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5854 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), obj, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5855 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5856 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5857 | __ LoadFromOffset(kLoadWordPair, out_loc.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5858 | } |
| 5859 | break; |
| 5860 | } |
| 5861 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5862 | case Primitive::kPrimFloat: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5863 | SRegister out = out_loc.AsFpuRegister<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5864 | if (index.IsConstant()) { |
| 5865 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5866 | __ LoadSFromOffset(out, obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5867 | } else { |
| 5868 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5869 | __ LoadSFromOffset(out, IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5870 | } |
| 5871 | break; |
| 5872 | } |
| 5873 | |
| 5874 | case Primitive::kPrimDouble: { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5875 | SRegister out = out_loc.AsFpuRegisterPairLow<SRegister>(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5876 | if (index.IsConstant()) { |
| 5877 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5878 | __ LoadDFromOffset(FromLowSToD(out), obj, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5879 | } else { |
| 5880 | __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5881 | __ LoadDFromOffset(FromLowSToD(out), IP, data_offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 5882 | } |
| 5883 | break; |
| 5884 | } |
| 5885 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5886 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5887 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5888 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5889 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5890 | |
| 5891 | if (type == Primitive::kPrimNot) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5892 | // Potential implicit null checks, in the case of reference |
| 5893 | // arrays, are handled in the previous switch statement. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 5894 | } else if (!maybe_compressed_char_at) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5895 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5896 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5900 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5901 | |
| 5902 | bool needs_write_barrier = |
| 5903 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5904 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5905 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5906 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5907 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5908 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5909 | LocationSummary::kCallOnSlowPath : |
| 5910 | LocationSummary::kNoCall); |
| 5911 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5912 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5913 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5914 | if (Primitive::IsFloatingPointType(value_type)) { |
| 5915 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5916 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5917 | locations->SetInAt(2, Location::RequiresRegister()); |
| 5918 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5919 | if (needs_write_barrier) { |
| 5920 | // Temporary registers for the write barrier. |
| 5921 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5922 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5923 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) { |
| 5927 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5928 | Location array_loc = locations->InAt(0); |
| 5929 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5930 | Location index = locations->InAt(1); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5931 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5932 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5933 | bool needs_write_barrier = |
| 5934 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5935 | uint32_t data_offset = |
| 5936 | mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value(); |
| 5937 | Location value_loc = locations->InAt(2); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5938 | HInstruction* array_instr = instruction->GetArray(); |
| 5939 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5940 | |
| 5941 | switch (value_type) { |
| 5942 | case Primitive::kPrimBoolean: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5943 | case Primitive::kPrimByte: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5944 | case Primitive::kPrimShort: |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5945 | case Primitive::kPrimChar: |
| 5946 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5947 | if (index.IsConstant()) { |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5948 | int32_t const_index = index.GetConstant()->AsIntConstant()->GetValue(); |
| 5949 | uint32_t full_offset = |
| 5950 | data_offset + (const_index << Primitive::ComponentSizeShift(value_type)); |
| 5951 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| 5952 | __ StoreToOffset(store_type, value_loc.AsRegister<Register>(), array, full_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5953 | } else { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5954 | Register temp = IP; |
| 5955 | |
| 5956 | if (has_intermediate_address) { |
| 5957 | // We do not need to compute the intermediate address from the array: the |
| 5958 | // input instruction has done it already. See the comment in |
| 5959 | // `TryExtractArrayAccessAddress()`. |
| 5960 | if (kIsDebugBuild) { |
| 5961 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| 5962 | DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == data_offset); |
| 5963 | } |
| 5964 | temp = array; |
| 5965 | } else { |
| 5966 | __ add(temp, array, ShifterOperand(data_offset)); |
| 5967 | } |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5968 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5969 | value_loc, |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5970 | temp, |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5971 | index.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5972 | } |
| 5973 | break; |
| 5974 | } |
| 5975 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5976 | case Primitive::kPrimNot: { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5977 | Register value = value_loc.AsRegister<Register>(); |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 5978 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 5979 | // See the comment in instruction_simplifier_shared.cc. |
| 5980 | DCHECK(!has_intermediate_address); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5981 | |
| 5982 | if (instruction->InputAt(2)->IsNullConstant()) { |
| 5983 | // Just setting null. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5984 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5985 | size_t offset = |
| 5986 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5987 | __ StoreToOffset(kStoreWord, value, array, offset); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5988 | } else { |
| 5989 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 5990 | __ add(IP, array, ShifterOperand(data_offset)); |
| 5991 | codegen_->StoreToShiftedRegOffset(value_type, |
| 5992 | value_loc, |
| 5993 | IP, |
| 5994 | index.AsRegister<Register>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5995 | } |
Roland Levillain | 1407ee7 | 2016-01-08 15:56:19 +0000 | [diff] [blame] | 5996 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 5997 | DCHECK(!needs_write_barrier); |
| 5998 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5999 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6000 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6001 | |
| 6002 | DCHECK(needs_write_barrier); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6003 | Location temp1_loc = locations->GetTemp(0); |
| 6004 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 6005 | Location temp2_loc = locations->GetTemp(1); |
| 6006 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6007 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6008 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6009 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6010 | Label done; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6011 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6012 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6013 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6014 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction); |
| 6015 | codegen_->AddSlowPath(slow_path); |
| 6016 | if (instruction->GetValueCanBeNull()) { |
| 6017 | Label non_zero; |
| 6018 | __ CompareAndBranchIfNonZero(value, &non_zero); |
| 6019 | if (index.IsConstant()) { |
| 6020 | size_t offset = |
| 6021 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6022 | __ StoreToOffset(kStoreWord, value, array, offset); |
| 6023 | } else { |
| 6024 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6025 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6026 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6027 | value_loc, |
| 6028 | IP, |
| 6029 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6030 | } |
| 6031 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6032 | __ b(&done); |
| 6033 | __ Bind(&non_zero); |
| 6034 | } |
| 6035 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6036 | // Note that when read barriers are enabled, the type checks |
| 6037 | // are performed without read barriers. This is fine, even in |
| 6038 | // the case where a class object is in the from-space after |
| 6039 | // the flip, as a comparison involving such a type would not |
| 6040 | // produce a false positive; it may of course produce a false |
| 6041 | // negative, in which case we would take the ArraySet slow |
| 6042 | // path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6043 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6044 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6045 | __ LoadFromOffset(kLoadWord, temp1, array, class_offset); |
| 6046 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6047 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6048 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6049 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6050 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6051 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6052 | __ LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6053 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6054 | // nor `temp2`, as we are comparing two poisoned references. |
| 6055 | __ cmp(temp1, ShifterOperand(temp2)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 6056 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6057 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 6058 | Label do_put; |
| 6059 | __ b(&do_put, EQ); |
| 6060 | // If heap poisoning is enabled, the `temp1` reference has |
| 6061 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6062 | __ MaybeUnpoisonHeapReference(temp1); |
| 6063 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 6064 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6065 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6066 | // If heap poisoning is enabled, no need to unpoison |
| 6067 | // `temp1`, as we are comparing against null below. |
| 6068 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 6069 | __ Bind(&do_put); |
| 6070 | } else { |
| 6071 | __ b(slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6072 | } |
| 6073 | } |
| 6074 | |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6075 | Register source = value; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6076 | if (kPoisonHeapReferences) { |
| 6077 | // Note that in the case where `value` is a null reference, |
| 6078 | // we do not enter this block, as a null reference does not |
| 6079 | // need poisoning. |
| 6080 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 6081 | __ Mov(temp1, value); |
| 6082 | __ PoisonHeapReference(temp1); |
| 6083 | source = temp1; |
| 6084 | } |
| 6085 | |
| 6086 | if (index.IsConstant()) { |
| 6087 | size_t offset = |
| 6088 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 6089 | __ StoreToOffset(kStoreWord, source, array, offset); |
| 6090 | } else { |
| 6091 | DCHECK(index.IsRegister()) << index; |
Artem Serov | 6c91679 | 2016-07-11 14:02:34 +0100 | [diff] [blame] | 6092 | |
| 6093 | __ add(IP, array, ShifterOperand(data_offset)); |
| 6094 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6095 | Location::RegisterLocation(source), |
| 6096 | IP, |
| 6097 | index.AsRegister<Register>()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6098 | } |
| 6099 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6100 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6101 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6102 | } |
| 6103 | |
| 6104 | codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull()); |
| 6105 | |
| 6106 | if (done.IsLinked()) { |
| 6107 | __ Bind(&done); |
| 6108 | } |
| 6109 | |
| 6110 | if (slow_path != nullptr) { |
| 6111 | __ Bind(slow_path->GetExitLabel()); |
| 6112 | } |
| 6113 | |
| 6114 | break; |
| 6115 | } |
| 6116 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6117 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6118 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6119 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6120 | size_t offset = |
| 6121 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6122 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6123 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6124 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 6125 | __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6126 | } |
| 6127 | break; |
| 6128 | } |
| 6129 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6130 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6131 | Location value = locations->InAt(2); |
| 6132 | DCHECK(value.IsFpuRegister()); |
| 6133 | if (index.IsConstant()) { |
| 6134 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6135 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6136 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6137 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6138 | __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset); |
| 6139 | } |
| 6140 | break; |
| 6141 | } |
| 6142 | |
| 6143 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6144 | Location value = locations->InAt(2); |
| 6145 | DCHECK(value.IsFpuRegisterPair()); |
| 6146 | if (index.IsConstant()) { |
| 6147 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6148 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6149 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6150 | __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8)); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6151 | __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset); |
| 6152 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6153 | |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6154 | break; |
| 6155 | } |
| 6156 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6157 | case Primitive::kPrimVoid: |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6158 | LOG(FATAL) << "Unreachable type " << value_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6159 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6160 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6161 | |
Roland Levillain | 80e6709 | 2016-01-08 16:04:55 +0000 | [diff] [blame] | 6162 | // Objects are handled in the switch. |
| 6163 | if (value_type != Primitive::kPrimNot) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6164 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6165 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6169 | LocationSummary* locations = |
| 6170 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6171 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6172 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) { |
| 6176 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6177 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6178 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 6179 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6180 | __ LoadFromOffset(kLoadWord, out, obj, offset); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6182 | // Mask out compression flag from String's array length. |
| 6183 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6184 | __ Lsr(out, out, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 6185 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6186 | } |
| 6187 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6188 | void LocationsBuilderARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6189 | LocationSummary* locations = |
| 6190 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6191 | |
| 6192 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6193 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6194 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6195 | } |
| 6196 | |
| 6197 | void InstructionCodeGeneratorARM::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6198 | LocationSummary* locations = instruction->GetLocations(); |
| 6199 | Location out = locations->Out(); |
| 6200 | Location first = locations->InAt(0); |
| 6201 | Location second = locations->InAt(1); |
| 6202 | |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 6203 | if (second.IsRegister()) { |
| 6204 | __ add(out.AsRegister<Register>(), |
| 6205 | first.AsRegister<Register>(), |
| 6206 | ShifterOperand(second.AsRegister<Register>())); |
| 6207 | } else { |
| 6208 | __ AddConstant(out.AsRegister<Register>(), |
| 6209 | first.AsRegister<Register>(), |
| 6210 | second.GetConstant()->AsIntConstant()->GetValue()); |
| 6211 | } |
| 6212 | } |
| 6213 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6214 | void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6215 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6216 | InvokeRuntimeCallingConvention calling_convention; |
| 6217 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6218 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 6219 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame^] | 6220 | |
| 6221 | HInstruction* index = instruction->InputAt(0); |
| 6222 | HInstruction* length = instruction->InputAt(1); |
| 6223 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6224 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6225 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6226 | // locations. |
| 6227 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6228 | locations->SetInAt(0, both_const |
| 6229 | ? Location::ConstantLocation(index->AsConstant()) |
| 6230 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6231 | locations->SetInAt(1, both_const |
| 6232 | ? Location::ConstantLocation(length->AsConstant()) |
| 6233 | : ArmEncodableConstantOrRegister(length, CMP)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6237 | LocationSummary* locations = instruction->GetLocations(); |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame^] | 6238 | Location index_loc = locations->InAt(0); |
| 6239 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6240 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame^] | 6241 | if (length_loc.IsConstant()) { |
| 6242 | int32_t length = helpers::Int32ConstantFrom(length_loc); |
| 6243 | if (index_loc.IsConstant()) { |
| 6244 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6245 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6246 | if (index < 0 || index >= length) { |
| 6247 | SlowPathCodeARM* slow_path = |
| 6248 | new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6249 | codegen_->AddSlowPath(slow_path); |
| 6250 | __ b(slow_path->GetEntryLabel()); |
| 6251 | } else { |
| 6252 | // Some optimization after BCE may have generated this, and we should not |
| 6253 | // generate a bounds check if it is a valid range. |
| 6254 | } |
| 6255 | return; |
| 6256 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6257 | |
Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame^] | 6258 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6259 | __ cmp(index_loc.AsRegister<Register>(), ShifterOperand(length)); |
| 6260 | codegen_->AddSlowPath(slow_path); |
| 6261 | __ b(slow_path->GetEntryLabel(), HS); |
| 6262 | } else { |
| 6263 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction); |
| 6264 | if (index_loc.IsConstant()) { |
| 6265 | int32_t index = helpers::Int32ConstantFrom(index_loc); |
| 6266 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index)); |
| 6267 | } else { |
| 6268 | __ cmp(length_loc.AsRegister<Register>(), ShifterOperand(index_loc.AsRegister<Register>())); |
| 6269 | } |
| 6270 | codegen_->AddSlowPath(slow_path); |
| 6271 | __ b(slow_path->GetEntryLabel(), LS); |
| 6272 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6273 | } |
| 6274 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6275 | void CodeGeneratorARM::MarkGCCard(Register temp, |
| 6276 | Register card, |
| 6277 | Register object, |
| 6278 | Register value, |
| 6279 | bool can_be_null) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 6280 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6281 | if (can_be_null) { |
| 6282 | __ CompareAndBranchIfZero(value, &is_null); |
| 6283 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6284 | __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6285 | __ Lsr(temp, object, gc::accounting::CardTable::kCardShift); |
| 6286 | __ strb(card, Address(card, temp)); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6287 | if (can_be_null) { |
| 6288 | __ Bind(&is_null); |
| 6289 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6290 | } |
| 6291 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6292 | void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6293 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6297 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6298 | } |
| 6299 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6300 | void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6301 | LocationSummary* locations = |
| 6302 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6303 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6307 | HBasicBlock* block = instruction->GetBlock(); |
| 6308 | if (block->GetLoopInformation() != nullptr) { |
| 6309 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6310 | // The back edge will generate the suspend check. |
| 6311 | return; |
| 6312 | } |
| 6313 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6314 | // The goto will generate the suspend check. |
| 6315 | return; |
| 6316 | } |
| 6317 | GenerateSuspendCheck(instruction, nullptr); |
| 6318 | } |
| 6319 | |
| 6320 | void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6321 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6322 | SuspendCheckSlowPathARM* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6323 | down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath()); |
| 6324 | if (slow_path == nullptr) { |
| 6325 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor); |
| 6326 | instruction->SetSlowPath(slow_path); |
| 6327 | codegen_->AddSlowPath(slow_path); |
| 6328 | if (successor != nullptr) { |
| 6329 | DCHECK(successor->IsLoopHeader()); |
| 6330 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 6331 | } |
| 6332 | } else { |
| 6333 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6334 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6335 | |
Nicolas Geoffray | 44b819e | 2014-11-06 12:00:54 +0000 | [diff] [blame] | 6336 | __ LoadFromOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6337 | kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6338 | if (successor == nullptr) { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6339 | __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6340 | __ Bind(slow_path->GetReturnLabel()); |
| 6341 | } else { |
Nicolas Geoffray | 2bcb431 | 2015-07-01 12:22:56 +0100 | [diff] [blame] | 6342 | __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6343 | __ b(slow_path->GetEntryLabel()); |
| 6344 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6345 | } |
| 6346 | |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6347 | ArmAssembler* ParallelMoveResolverARM::GetAssembler() const { |
| 6348 | return codegen_->GetAssembler(); |
| 6349 | } |
| 6350 | |
| 6351 | void ParallelMoveResolverARM::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6352 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6353 | Location source = move->GetSource(); |
| 6354 | Location destination = move->GetDestination(); |
| 6355 | |
| 6356 | if (source.IsRegister()) { |
| 6357 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6358 | __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6359 | } else if (destination.IsFpuRegister()) { |
| 6360 | __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6361 | } else { |
| 6362 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6363 | __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6364 | SP, destination.GetStackIndex()); |
| 6365 | } |
| 6366 | } else if (source.IsStackSlot()) { |
| 6367 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6368 | __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6369 | SP, source.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6370 | } else if (destination.IsFpuRegister()) { |
| 6371 | __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6372 | } else { |
| 6373 | DCHECK(destination.IsStackSlot()); |
| 6374 | __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex()); |
| 6375 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6376 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6377 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6378 | if (destination.IsRegister()) { |
| 6379 | __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>()); |
| 6380 | } else if (destination.IsFpuRegister()) { |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6381 | __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6382 | } else { |
| 6383 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6384 | __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex()); |
| 6385 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6386 | } else if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6387 | if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6388 | __ LoadDFromOffset(DTMP, SP, source.GetStackIndex()); |
| 6389 | __ StoreDToOffset(DTMP, SP, destination.GetStackIndex()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6390 | } else if (destination.IsRegisterPair()) { |
| 6391 | DCHECK(ExpectedPairLayout(destination)); |
| 6392 | __ LoadFromOffset( |
| 6393 | kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex()); |
| 6394 | } else { |
| 6395 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6396 | __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6397 | SP, |
| 6398 | source.GetStackIndex()); |
| 6399 | } |
| 6400 | } else if (source.IsRegisterPair()) { |
| 6401 | if (destination.IsRegisterPair()) { |
| 6402 | __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 6403 | __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6404 | } else if (destination.IsFpuRegisterPair()) { |
| 6405 | __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6406 | source.AsRegisterPairLow<Register>(), |
| 6407 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6408 | } else { |
| 6409 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6410 | DCHECK(ExpectedPairLayout(source)); |
| 6411 | __ StoreToOffset( |
| 6412 | kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex()); |
| 6413 | } |
| 6414 | } else if (source.IsFpuRegisterPair()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6415 | if (destination.IsRegisterPair()) { |
| 6416 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6417 | destination.AsRegisterPairHigh<Register>(), |
| 6418 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6419 | } else if (destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6420 | __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), |
| 6421 | FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())); |
| 6422 | } else { |
| 6423 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6424 | __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()), |
| 6425 | SP, |
| 6426 | destination.GetStackIndex()); |
| 6427 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6428 | } else { |
| 6429 | DCHECK(source.IsConstant()) << source; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6430 | HConstant* constant = source.GetConstant(); |
| 6431 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6432 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6433 | if (destination.IsRegister()) { |
| 6434 | __ LoadImmediate(destination.AsRegister<Register>(), value); |
| 6435 | } else { |
| 6436 | DCHECK(destination.IsStackSlot()); |
| 6437 | __ LoadImmediate(IP, value); |
| 6438 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6439 | } |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6440 | } else if (constant->IsLongConstant()) { |
| 6441 | int64_t value = constant->AsLongConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6442 | if (destination.IsRegisterPair()) { |
| 6443 | __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value)); |
| 6444 | __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value)); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6445 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6446 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6447 | __ LoadImmediate(IP, Low32Bits(value)); |
| 6448 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6449 | __ LoadImmediate(IP, High32Bits(value)); |
| 6450 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6451 | } |
| 6452 | } else if (constant->IsDoubleConstant()) { |
| 6453 | double value = constant->AsDoubleConstant()->GetValue(); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6454 | if (destination.IsFpuRegisterPair()) { |
| 6455 | __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6456 | } else { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6457 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6458 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6459 | __ LoadImmediate(IP, Low32Bits(int_value)); |
| 6460 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6461 | __ LoadImmediate(IP, High32Bits(int_value)); |
| 6462 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize)); |
| 6463 | } |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6464 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 6465 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6466 | float value = constant->AsFloatConstant()->GetValue(); |
| 6467 | if (destination.IsFpuRegister()) { |
| 6468 | __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value); |
| 6469 | } else { |
| 6470 | DCHECK(destination.IsStackSlot()); |
| 6471 | __ LoadImmediate(IP, bit_cast<int32_t, float>(value)); |
| 6472 | __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex()); |
| 6473 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6474 | } |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | void ParallelMoveResolverARM::Exchange(Register reg, int mem) { |
| 6479 | __ Mov(IP, reg); |
| 6480 | __ LoadFromOffset(kLoadWord, reg, SP, mem); |
| 6481 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
| 6482 | } |
| 6483 | |
| 6484 | void ParallelMoveResolverARM::Exchange(int mem1, int mem2) { |
| 6485 | ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters()); |
| 6486 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6487 | __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6488 | SP, mem1 + stack_offset); |
| 6489 | __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset); |
| 6490 | __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()), |
| 6491 | SP, mem2 + stack_offset); |
| 6492 | __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset); |
| 6493 | } |
| 6494 | |
| 6495 | void ParallelMoveResolverARM::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6496 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6497 | Location source = move->GetSource(); |
| 6498 | Location destination = move->GetDestination(); |
| 6499 | |
| 6500 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6501 | DCHECK_NE(source.AsRegister<Register>(), IP); |
| 6502 | DCHECK_NE(destination.AsRegister<Register>(), IP); |
| 6503 | __ Mov(IP, source.AsRegister<Register>()); |
| 6504 | __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 6505 | __ Mov(destination.AsRegister<Register>(), IP); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6506 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6507 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6508 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6509 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6510 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 6511 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6512 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6513 | __ vmovrs(IP, source.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6514 | __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>()); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6515 | __ vmovsr(destination.AsFpuRegister<SRegister>(), IP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6516 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6517 | __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6518 | __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6519 | __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6520 | __ vmovrrd(destination.AsRegisterPairLow<Register>(), |
| 6521 | destination.AsRegisterPairHigh<Register>(), |
| 6522 | DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6523 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6524 | Register low_reg = source.IsRegisterPair() |
| 6525 | ? source.AsRegisterPairLow<Register>() |
| 6526 | : destination.AsRegisterPairLow<Register>(); |
| 6527 | int mem = source.IsRegisterPair() |
| 6528 | ? destination.GetStackIndex() |
| 6529 | : source.GetStackIndex(); |
| 6530 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6531 | __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1)); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6532 | __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6533 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6534 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6535 | DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()); |
| 6536 | DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6537 | __ vmovd(DTMP, first); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6538 | __ vmovd(first, second); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6539 | __ vmovd(second, DTMP); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6540 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| 6541 | DRegister reg = source.IsFpuRegisterPair() |
| 6542 | ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()) |
| 6543 | : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()); |
| 6544 | int mem = source.IsFpuRegisterPair() |
| 6545 | ? destination.GetStackIndex() |
| 6546 | : source.GetStackIndex(); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6547 | __ vmovd(DTMP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6548 | __ LoadDFromOffset(reg, SP, mem); |
Nicolas Geoffray | ffe8a57 | 2015-02-11 01:10:39 +0000 | [diff] [blame] | 6549 | __ StoreDToOffset(DTMP, SP, mem); |
Nicolas Geoffray | 840e546 | 2015-01-07 16:01:24 +0000 | [diff] [blame] | 6550 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| 6551 | SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>() |
| 6552 | : destination.AsFpuRegister<SRegister>(); |
| 6553 | int mem = source.IsFpuRegister() |
| 6554 | ? destination.GetStackIndex() |
| 6555 | : source.GetStackIndex(); |
| 6556 | |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6557 | __ vmovrs(IP, reg); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6558 | __ LoadSFromOffset(reg, SP, mem); |
Nicolas Geoffray | a8eef82 | 2015-01-16 11:14:27 +0000 | [diff] [blame] | 6559 | __ StoreToOffset(kStoreWord, IP, SP, mem); |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6560 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6561 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| 6562 | Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize)); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6563 | } else { |
Nicolas Geoffray | 53f1262 | 2015-01-13 18:04:41 +0000 | [diff] [blame] | 6564 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | void ParallelMoveResolverARM::SpillScratch(int reg) { |
| 6569 | __ Push(static_cast<Register>(reg)); |
| 6570 | } |
| 6571 | |
| 6572 | void ParallelMoveResolverARM::RestoreScratch(int reg) { |
| 6573 | __ Pop(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6574 | } |
| 6575 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6576 | HLoadClass::LoadKind CodeGeneratorARM::GetSupportedLoadClassKind( |
| 6577 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6578 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6579 | case HLoadClass::LoadKind::kInvalid: |
| 6580 | LOG(FATAL) << "UNREACHABLE"; |
| 6581 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6582 | case HLoadClass::LoadKind::kReferrersClass: |
| 6583 | break; |
| 6584 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 6585 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6586 | break; |
| 6587 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 6588 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6589 | break; |
| 6590 | case HLoadClass::LoadKind::kBootImageAddress: |
| 6591 | break; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6592 | case HLoadClass::LoadKind::kBssEntry: |
| 6593 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 6594 | break; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6595 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6596 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6597 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6598 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 6599 | break; |
| 6600 | } |
| 6601 | return desired_class_load_kind; |
| 6602 | } |
| 6603 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6604 | void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6605 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6606 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6607 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6608 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6609 | cls, |
| 6610 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6611 | Location::RegisterLocation(R0)); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6612 | DCHECK_EQ(calling_convention.GetRegisterAt(0), R0); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6613 | return; |
| 6614 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6615 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6616 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6617 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6618 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6619 | ? LocationSummary::kCallOnSlowPath |
| 6620 | : LocationSummary::kNoCall; |
| 6621 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6622 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6623 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6624 | } |
| 6625 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6626 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6628 | } |
| 6629 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6630 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6631 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6632 | // Rely on the type resolution or initialization and marking to save everything we need. |
| 6633 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6634 | // to the custom calling convention) or by marking, so we request a different temp. |
| 6635 | locations->AddTemp(Location::RequiresRegister()); |
| 6636 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6637 | InvokeRuntimeCallingConvention calling_convention; |
| 6638 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6639 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6640 | // that the the kPrimNot result register is the same as the first argument register. |
| 6641 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6642 | } else { |
| 6643 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6644 | } |
| 6645 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6646 | } |
| 6647 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6648 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6649 | // move. |
| 6650 | void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6651 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6652 | if (load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 6653 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6654 | return; |
| 6655 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6656 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6657 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6658 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6659 | Location out_loc = locations->Out(); |
| 6660 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6661 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6662 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6663 | ? kWithoutReadBarrier |
| 6664 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6665 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6666 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6667 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6668 | DCHECK(!cls->CanCallRuntime()); |
| 6669 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6670 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6671 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6672 | GenerateGcRootFieldLoad(cls, |
| 6673 | out_loc, |
| 6674 | current_method, |
| 6675 | ArtMethod::DeclaringClassOffset().Int32Value(), |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6676 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6677 | break; |
| 6678 | } |
| 6679 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6680 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6681 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6682 | __ LoadLiteral(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(), |
| 6683 | cls->GetTypeIndex())); |
| 6684 | break; |
| 6685 | } |
| 6686 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6687 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6688 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6689 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 6690 | codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| 6691 | __ BindTrackedLabel(&labels->movw_label); |
| 6692 | __ movw(out, /* placeholder */ 0u); |
| 6693 | __ BindTrackedLabel(&labels->movt_label); |
| 6694 | __ movt(out, /* placeholder */ 0u); |
| 6695 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6696 | __ add(out, out, ShifterOperand(PC)); |
| 6697 | break; |
| 6698 | } |
| 6699 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6700 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6701 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6702 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 6703 | DCHECK_NE(address, 0u); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6704 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6705 | break; |
| 6706 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6707 | case HLoadClass::LoadKind::kBssEntry: { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6708 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6709 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6710 | : out; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6711 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 6712 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6713 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6714 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6715 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6716 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6717 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6718 | __ add(temp, temp, ShifterOperand(PC)); |
| 6719 | GenerateGcRootFieldLoad(cls, out_loc, temp, /* offset */ 0, read_barrier_option); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6720 | generate_null_check = true; |
| 6721 | break; |
| 6722 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6723 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6724 | __ LoadLiteral(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 6725 | cls->GetTypeIndex(), |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6726 | cls->GetClass())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6727 | // /* GcRoot<mirror::Class> */ out = *out |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6728 | GenerateGcRootFieldLoad(cls, out_loc, out, /* offset */ 0, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6729 | break; |
| 6730 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6731 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6732 | case HLoadClass::LoadKind::kInvalid: |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6733 | LOG(FATAL) << "UNREACHABLE"; |
| 6734 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6735 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6736 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6737 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6738 | DCHECK(cls->CanCallRuntime()); |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6739 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6740 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6741 | codegen_->AddSlowPath(slow_path); |
| 6742 | if (generate_null_check) { |
| 6743 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6744 | } |
| 6745 | if (cls->MustGenerateClinitCheck()) { |
| 6746 | GenerateClassInitializationCheck(slow_path, out); |
| 6747 | } else { |
| 6748 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6749 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6750 | } |
| 6751 | } |
| 6752 | |
| 6753 | void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) { |
| 6754 | LocationSummary* locations = |
| 6755 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6757 | if (check->HasUses()) { |
| 6758 | locations->SetOut(Location::SameAsFirstInput()); |
| 6759 | } |
| 6760 | } |
| 6761 | |
| 6762 | void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6763 | // We assume the class is not null. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6764 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6765 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6767 | GenerateClassInitializationCheck(slow_path, |
| 6768 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6769 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6770 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6771 | void InstructionCodeGeneratorARM::GenerateClassInitializationCheck( |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 6772 | SlowPathCodeARM* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6773 | __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value()); |
| 6774 | __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized)); |
| 6775 | __ b(slow_path->GetEntryLabel(), LT); |
| 6776 | // Even if the initialized flag is set, we may be in a situation where caches are not synced |
| 6777 | // properly. Therefore, we do a memory fence. |
| 6778 | __ dmb(ISH); |
| 6779 | __ Bind(slow_path->GetExitLabel()); |
| 6780 | } |
| 6781 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6782 | HLoadString::LoadKind CodeGeneratorARM::GetSupportedLoadStringKind( |
| 6783 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6784 | switch (desired_string_load_kind) { |
| 6785 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6786 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6787 | break; |
| 6788 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6789 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6790 | break; |
| 6791 | case HLoadString::LoadKind::kBootImageAddress: |
| 6792 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6793 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6794 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6795 | break; |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6796 | case HLoadString::LoadKind::kJitTableAddress: |
| 6797 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6798 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6799 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6800 | break; |
| 6801 | } |
| 6802 | return desired_string_load_kind; |
| 6803 | } |
| 6804 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6805 | void LocationsBuilderARM::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6806 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6807 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6808 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6809 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6810 | locations->SetOut(Location::RegisterLocation(R0)); |
| 6811 | } else { |
| 6812 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6813 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 6814 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6815 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| 6816 | // Note that IP may be clobbered by saving/restoring the live register (only one thanks |
| 6817 | // to the custom calling convention) or by marking, so we request a different temp. |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6818 | locations->AddTemp(Location::RequiresRegister()); |
| 6819 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6820 | InvokeRuntimeCallingConvention calling_convention; |
| 6821 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6822 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 6823 | // that the the kPrimNot result register is the same as the first argument register. |
| 6824 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6825 | } else { |
| 6826 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6827 | } |
| 6828 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6829 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6830 | } |
| 6831 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6832 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6833 | // move. |
| 6834 | void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6835 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6836 | Location out_loc = locations->Out(); |
| 6837 | Register out = out_loc.AsRegister<Register>(); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6838 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6839 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6840 | switch (load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6841 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6842 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6843 | __ LoadLiteral(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(), |
| 6844 | load->GetStringIndex())); |
| 6845 | return; // No dex cache slow path. |
| 6846 | } |
| 6847 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6848 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6849 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6850 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6851 | __ BindTrackedLabel(&labels->movw_label); |
| 6852 | __ movw(out, /* placeholder */ 0u); |
| 6853 | __ BindTrackedLabel(&labels->movt_label); |
| 6854 | __ movt(out, /* placeholder */ 0u); |
| 6855 | __ BindTrackedLabel(&labels->add_pc_label); |
| 6856 | __ add(out, out, ShifterOperand(PC)); |
| 6857 | return; // No dex cache slow path. |
| 6858 | } |
| 6859 | case HLoadString::LoadKind::kBootImageAddress: { |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6860 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6861 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6862 | DCHECK_NE(address, 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6863 | __ LoadLiteral(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 6864 | return; // No dex cache slow path. |
| 6865 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6866 | case HLoadString::LoadKind::kBssEntry: { |
| 6867 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6868 | Register temp = (!kUseReadBarrier || kUseBakerReadBarrier) |
| 6869 | ? locations->GetTemp(0).AsRegister<Register>() |
| 6870 | : out; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6871 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6872 | codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6873 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6874 | __ movw(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6875 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6876 | __ movt(temp, /* placeholder */ 0u); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6877 | __ BindTrackedLabel(&labels->add_pc_label); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6878 | __ add(temp, temp, ShifterOperand(PC)); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6879 | GenerateGcRootFieldLoad(load, out_loc, temp, /* offset */ 0, kCompilerReadBarrierOption); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6880 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load); |
| 6881 | codegen_->AddSlowPath(slow_path); |
| 6882 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 6883 | __ Bind(slow_path->GetExitLabel()); |
| 6884 | return; |
| 6885 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6886 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6887 | __ LoadLiteral(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6888 | load->GetStringIndex(), |
| 6889 | load->GetString())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6890 | // /* GcRoot<mirror::String> */ out = *out |
| 6891 | GenerateGcRootFieldLoad(load, out_loc, out, /* offset */ 0, kCompilerReadBarrierOption); |
| 6892 | return; |
| 6893 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6894 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6895 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6896 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6897 | |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6898 | // TODO: Consider re-adding the compiler code to do string dex cache lookup again. |
| 6899 | DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod); |
| 6900 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6901 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6902 | __ LoadImmediate(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
Christina Wadsworth | d8ec6db | 2016-08-30 17:19:14 -0700 | [diff] [blame] | 6903 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6904 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6905 | } |
| 6906 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6907 | static int32_t GetExceptionTlsOffset() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6908 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6909 | } |
| 6910 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6911 | void LocationsBuilderARM::VisitLoadException(HLoadException* load) { |
| 6912 | LocationSummary* locations = |
| 6913 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6914 | locations->SetOut(Location::RequiresRegister()); |
| 6915 | } |
| 6916 | |
| 6917 | void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6918 | Register out = load->GetLocations()->Out().AsRegister<Register>(); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6919 | __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset()); |
| 6920 | } |
| 6921 | |
| 6922 | void LocationsBuilderARM::VisitClearException(HClearException* clear) { |
| 6923 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6924 | } |
| 6925 | |
| 6926 | void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6927 | __ LoadImmediate(IP, 0); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6928 | __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset()); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | void LocationsBuilderARM::VisitThrow(HThrow* instruction) { |
| 6932 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6933 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6934 | InvokeRuntimeCallingConvention calling_convention; |
| 6935 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6936 | } |
| 6937 | |
| 6938 | void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 6939 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6940 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6941 | } |
| 6942 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6943 | // Temp is used for read barrier. |
| 6944 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6945 | if (kEmitCompilerReadBarrier && |
| 6946 | (kUseBakerReadBarrier || |
| 6947 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6948 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6949 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6950 | return 1; |
| 6951 | } |
| 6952 | return 0; |
| 6953 | } |
| 6954 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6955 | // 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] | 6956 | // interface pointer, one for loading the current interface. |
| 6957 | // The other checks have one temp for loading the object's class. |
| 6958 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6959 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6960 | return 3; |
| 6961 | } |
| 6962 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6963 | } |
| 6964 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6965 | void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6966 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6967 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6968 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6969 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6970 | case TypeCheckKind::kExactCheck: |
| 6971 | case TypeCheckKind::kAbstractClassCheck: |
| 6972 | case TypeCheckKind::kClassHierarchyCheck: |
| 6973 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6974 | call_kind = |
| 6975 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6976 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6977 | break; |
| 6978 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6979 | case TypeCheckKind::kUnresolvedCheck: |
| 6980 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6981 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6982 | break; |
| 6983 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6984 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6985 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6986 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6987 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6988 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 6989 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6990 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6991 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 6992 | // Note that TypeCheckSlowPathARM uses this register too. |
| 6993 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6994 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6995 | } |
| 6996 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6997 | void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6998 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6999 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7000 | Location obj_loc = locations->InAt(0); |
| 7001 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7002 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7003 | Location out_loc = locations->Out(); |
| 7004 | Register out = out_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7005 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7006 | DCHECK_LE(num_temps, 1u); |
| 7007 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7008 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7009 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7010 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7011 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 7012 | Label done, zero; |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7013 | SlowPathCodeARM* slow_path = nullptr; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7014 | |
| 7015 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7016 | // avoid null check if we know obj is not null. |
| 7017 | if (instruction->MustDoNullCheck()) { |
Nicolas Geoffray | d56376c | 2015-05-21 12:32:34 +0000 | [diff] [blame] | 7018 | __ CompareAndBranchIfZero(obj, &zero); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7019 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7020 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7021 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7022 | case TypeCheckKind::kExactCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7023 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7024 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7025 | out_loc, |
| 7026 | obj_loc, |
| 7027 | class_offset, |
| 7028 | maybe_temp_loc, |
| 7029 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7030 | __ cmp(out, ShifterOperand(cls)); |
| 7031 | // Classes must be equal for the instanceof to succeed. |
| 7032 | __ b(&zero, NE); |
| 7033 | __ LoadImmediate(out, 1); |
| 7034 | __ b(&done); |
| 7035 | break; |
| 7036 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7037 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7038 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7039 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7040 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7041 | out_loc, |
| 7042 | obj_loc, |
| 7043 | class_offset, |
| 7044 | maybe_temp_loc, |
| 7045 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7046 | // If the class is abstract, we eagerly fetch the super class of the |
| 7047 | // object to avoid doing a comparison we know will fail. |
| 7048 | Label loop; |
| 7049 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7050 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7051 | GenerateReferenceLoadOneRegister(instruction, |
| 7052 | out_loc, |
| 7053 | super_offset, |
| 7054 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7055 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7056 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7057 | __ CompareAndBranchIfZero(out, &done); |
| 7058 | __ cmp(out, ShifterOperand(cls)); |
| 7059 | __ b(&loop, NE); |
| 7060 | __ LoadImmediate(out, 1); |
| 7061 | if (zero.IsLinked()) { |
| 7062 | __ b(&done); |
| 7063 | } |
| 7064 | break; |
| 7065 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7066 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7067 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7068 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7069 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7070 | out_loc, |
| 7071 | obj_loc, |
| 7072 | class_offset, |
| 7073 | maybe_temp_loc, |
| 7074 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7075 | // Walk over the class hierarchy to find a match. |
| 7076 | Label loop, success; |
| 7077 | __ Bind(&loop); |
| 7078 | __ cmp(out, ShifterOperand(cls)); |
| 7079 | __ b(&success, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7080 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7081 | GenerateReferenceLoadOneRegister(instruction, |
| 7082 | out_loc, |
| 7083 | super_offset, |
| 7084 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7085 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7086 | __ CompareAndBranchIfNonZero(out, &loop); |
| 7087 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7088 | __ b(&done); |
| 7089 | __ Bind(&success); |
| 7090 | __ LoadImmediate(out, 1); |
| 7091 | if (zero.IsLinked()) { |
| 7092 | __ b(&done); |
| 7093 | } |
| 7094 | break; |
| 7095 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7096 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7097 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7098 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7099 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7100 | out_loc, |
| 7101 | obj_loc, |
| 7102 | class_offset, |
| 7103 | maybe_temp_loc, |
| 7104 | kCompilerReadBarrierOption); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7105 | // Do an exact check. |
| 7106 | Label exact_check; |
| 7107 | __ cmp(out, ShifterOperand(cls)); |
| 7108 | __ b(&exact_check, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7109 | // 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] | 7110 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7111 | GenerateReferenceLoadOneRegister(instruction, |
| 7112 | out_loc, |
| 7113 | component_offset, |
| 7114 | maybe_temp_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7115 | kCompilerReadBarrierOption); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7116 | // If `out` is null, we use it for the result, and jump to `done`. |
| 7117 | __ CompareAndBranchIfZero(out, &done); |
| 7118 | __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7119 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 7120 | __ CompareAndBranchIfNonZero(out, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7121 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7122 | __ LoadImmediate(out, 1); |
| 7123 | __ b(&done); |
| 7124 | break; |
| 7125 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7126 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7127 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7128 | // No read barrier since the slow path will retry upon failure. |
| 7129 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7130 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7131 | out_loc, |
| 7132 | obj_loc, |
| 7133 | class_offset, |
| 7134 | maybe_temp_loc, |
| 7135 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7136 | __ cmp(out, ShifterOperand(cls)); |
| 7137 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7138 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7139 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7140 | codegen_->AddSlowPath(slow_path); |
| 7141 | __ b(slow_path->GetEntryLabel(), NE); |
| 7142 | __ LoadImmediate(out, 1); |
| 7143 | if (zero.IsLinked()) { |
| 7144 | __ b(&done); |
| 7145 | } |
| 7146 | break; |
| 7147 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7148 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7149 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7150 | case TypeCheckKind::kInterfaceCheck: { |
| 7151 | // 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] | 7152 | // into the slow path for the unresolved and interface check |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7153 | // cases. |
| 7154 | // |
| 7155 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7156 | // entry point without resorting to a type checking slow path |
| 7157 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7158 | // require to assign fixed registers for the inputs of this |
| 7159 | // HInstanceOf instruction (following the runtime calling |
| 7160 | // convention), which might be cluttered by the potential first |
| 7161 | // read barrier emission at the beginning of this method. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7162 | // |
| 7163 | // TODO: Introduce a new runtime entry point taking the object |
| 7164 | // to test (instead of its class) as argument, and let it deal |
| 7165 | // with the read barrier issues. This will let us refactor this |
| 7166 | // case of the `switch` code as it was previously (with a direct |
| 7167 | // call to the runtime not using a type checking slow path). |
| 7168 | // This should also be beneficial for the other cases above. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7169 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 7170 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7171 | /* is_fatal */ false); |
| 7172 | codegen_->AddSlowPath(slow_path); |
| 7173 | __ b(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7174 | if (zero.IsLinked()) { |
| 7175 | __ b(&done); |
| 7176 | } |
| 7177 | break; |
| 7178 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7179 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7180 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7181 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7182 | __ Bind(&zero); |
| 7183 | __ LoadImmediate(out, 0); |
| 7184 | } |
| 7185 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7186 | if (done.IsLinked()) { |
| 7187 | __ Bind(&done); |
| 7188 | } |
| 7189 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7190 | if (slow_path != nullptr) { |
| 7191 | __ Bind(slow_path->GetExitLabel()); |
| 7192 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7193 | } |
| 7194 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7195 | void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7196 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7197 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 7198 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7199 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7200 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7201 | case TypeCheckKind::kExactCheck: |
| 7202 | case TypeCheckKind::kAbstractClassCheck: |
| 7203 | case TypeCheckKind::kClassHierarchyCheck: |
| 7204 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7205 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 7206 | LocationSummary::kCallOnSlowPath : |
| 7207 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7208 | break; |
| 7209 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7210 | case TypeCheckKind::kUnresolvedCheck: |
| 7211 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7212 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7213 | break; |
| 7214 | } |
| 7215 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7216 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 7217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7218 | locations->SetInAt(1, Location::RequiresRegister()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7219 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7223 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7224 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7225 | Location obj_loc = locations->InAt(0); |
| 7226 | Register obj = obj_loc.AsRegister<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7227 | Register cls = locations->InAt(1).AsRegister<Register>(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7228 | Location temp_loc = locations->GetTemp(0); |
| 7229 | Register temp = temp_loc.AsRegister<Register>(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7230 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7231 | DCHECK_LE(num_temps, 3u); |
| 7232 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7233 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7234 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7235 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7236 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7237 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7238 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7239 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7240 | const uint32_t object_array_data_offset = |
| 7241 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7242 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7243 | // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases |
| 7244 | // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding |
| 7245 | // read barriers is done for performance and code size reasons. |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7246 | bool is_type_check_slow_path_fatal = false; |
| 7247 | if (!kEmitCompilerReadBarrier) { |
| 7248 | is_type_check_slow_path_fatal = |
| 7249 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 7250 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7251 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7252 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 7253 | !instruction->CanThrowIntoCatchBlock(); |
| 7254 | } |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 7255 | SlowPathCodeARM* type_check_slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7256 | new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction, |
| 7257 | is_type_check_slow_path_fatal); |
| 7258 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7259 | |
| 7260 | Label done; |
| 7261 | // Avoid null check if we know obj is not null. |
| 7262 | if (instruction->MustDoNullCheck()) { |
| 7263 | __ CompareAndBranchIfZero(obj, &done); |
| 7264 | } |
| 7265 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7266 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7267 | case TypeCheckKind::kExactCheck: |
| 7268 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7269 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7270 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7271 | temp_loc, |
| 7272 | obj_loc, |
| 7273 | class_offset, |
| 7274 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7275 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7276 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7277 | __ cmp(temp, ShifterOperand(cls)); |
| 7278 | // Jump to slow path for throwing the exception or doing a |
| 7279 | // more involved array check. |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7280 | __ b(type_check_slow_path->GetEntryLabel(), NE); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7281 | break; |
| 7282 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7283 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7284 | case TypeCheckKind::kAbstractClassCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7285 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7286 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7287 | temp_loc, |
| 7288 | obj_loc, |
| 7289 | class_offset, |
| 7290 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7291 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7292 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7293 | // If the class is abstract, we eagerly fetch the super class of the |
| 7294 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7295 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7296 | __ Bind(&loop); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7297 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7298 | GenerateReferenceLoadOneRegister(instruction, |
| 7299 | temp_loc, |
| 7300 | super_offset, |
| 7301 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7302 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7303 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7304 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7305 | // exception. |
| 7306 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7307 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7308 | // Otherwise, compare the classes. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7309 | __ cmp(temp, ShifterOperand(cls)); |
| 7310 | __ b(&loop, NE); |
| 7311 | break; |
| 7312 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7314 | case TypeCheckKind::kClassHierarchyCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7315 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7316 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7317 | temp_loc, |
| 7318 | obj_loc, |
| 7319 | class_offset, |
| 7320 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7321 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7323 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7324 | Label loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7325 | __ Bind(&loop); |
| 7326 | __ cmp(temp, ShifterOperand(cls)); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7327 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7328 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7329 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7330 | GenerateReferenceLoadOneRegister(instruction, |
| 7331 | temp_loc, |
| 7332 | super_offset, |
| 7333 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7334 | kWithoutReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7335 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7336 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7337 | // exception. |
| 7338 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7339 | // Otherwise, jump to the beginning of the loop. |
| 7340 | __ b(&loop); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7341 | break; |
| 7342 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7343 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7344 | case TypeCheckKind::kArrayObjectCheck: { |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7345 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7346 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7347 | temp_loc, |
| 7348 | obj_loc, |
| 7349 | class_offset, |
| 7350 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7351 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7352 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7353 | // Do an exact check. |
| 7354 | __ cmp(temp, ShifterOperand(cls)); |
| 7355 | __ b(&done, EQ); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7356 | |
| 7357 | // 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] | 7358 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7359 | GenerateReferenceLoadOneRegister(instruction, |
| 7360 | temp_loc, |
| 7361 | component_offset, |
| 7362 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7363 | kWithoutReadBarrier); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7364 | // If the component type is null, jump to the slow path to throw the exception. |
| 7365 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| 7366 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7367 | // to further check that this component type is not a primitive type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7368 | __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7369 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for art::Primitive::kPrimNot"); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7370 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7371 | break; |
| 7372 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7373 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7374 | case TypeCheckKind::kUnresolvedCheck: |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7375 | // 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] | 7376 | // We cannot directly call the CheckCast runtime entry point |
| 7377 | // without resorting to a type checking slow path here (i.e. by |
| 7378 | // calling InvokeRuntime directly), as it would require to |
| 7379 | // assign fixed registers for the inputs of this HInstanceOf |
| 7380 | // instruction (following the runtime calling convention), which |
| 7381 | // might be cluttered by the potential first read barrier |
| 7382 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7383 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7384 | __ b(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7385 | break; |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7386 | |
| 7387 | case TypeCheckKind::kInterfaceCheck: { |
| 7388 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7389 | // positives by doing this. |
| 7390 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7391 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7392 | temp_loc, |
| 7393 | obj_loc, |
| 7394 | class_offset, |
| 7395 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7396 | kWithoutReadBarrier); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7397 | |
| 7398 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7399 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7400 | temp_loc, |
| 7401 | temp_loc, |
| 7402 | iftable_offset, |
| 7403 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7404 | kWithoutReadBarrier); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7405 | // Iftable is never null. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7406 | __ ldr(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7407 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7408 | Label start_loop; |
| 7409 | __ Bind(&start_loop); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7410 | __ CompareAndBranchIfZero(maybe_temp2_loc.AsRegister<Register>(), |
| 7411 | type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7412 | __ ldr(maybe_temp3_loc.AsRegister<Register>(), Address(temp, object_array_data_offset)); |
| 7413 | __ MaybeUnpoisonHeapReference(maybe_temp3_loc.AsRegister<Register>()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7414 | // Go to next interface. |
| 7415 | __ add(temp, temp, ShifterOperand(2 * kHeapReferenceSize)); |
| 7416 | __ sub(maybe_temp2_loc.AsRegister<Register>(), |
| 7417 | maybe_temp2_loc.AsRegister<Register>(), |
| 7418 | ShifterOperand(2)); |
Mathieu Chartier | afbcdaf | 2016-11-14 10:50:29 -0800 | [diff] [blame] | 7419 | // Compare the classes and continue the loop if they do not match. |
| 7420 | __ cmp(cls, ShifterOperand(maybe_temp3_loc.AsRegister<Register>())); |
| 7421 | __ b(&start_loop, NE); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7422 | break; |
| 7423 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7424 | } |
| 7425 | __ Bind(&done); |
| 7426 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 7427 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7428 | } |
| 7429 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7430 | void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 7431 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 7432 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7433 | InvokeRuntimeCallingConvention calling_convention; |
| 7434 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7435 | } |
| 7436 | |
| 7437 | void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 7438 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 7439 | instruction, |
| 7440 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7441 | if (instruction->IsEnter()) { |
| 7442 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7443 | } else { |
| 7444 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7445 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7446 | } |
| 7447 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7448 | void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); } |
| 7449 | void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); } |
| 7450 | void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7451 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7452 | void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7453 | LocationSummary* locations = |
| 7454 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7455 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7456 | || instruction->GetResultType() == Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7457 | // 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] | 7458 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7459 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
Nicolas Geoffray | 829280c | 2015-01-28 10:20:37 +0000 | [diff] [blame] | 7460 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7461 | } |
| 7462 | |
| 7463 | void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) { |
| 7464 | HandleBitwiseOperation(instruction); |
| 7465 | } |
| 7466 | |
| 7467 | void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) { |
| 7468 | HandleBitwiseOperation(instruction); |
| 7469 | } |
| 7470 | |
| 7471 | void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) { |
| 7472 | HandleBitwiseOperation(instruction); |
| 7473 | } |
| 7474 | |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 7475 | |
| 7476 | void LocationsBuilderARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7477 | LocationSummary* locations = |
| 7478 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7479 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 7480 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 7481 | |
| 7482 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7483 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7484 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7485 | } |
| 7486 | |
| 7487 | void InstructionCodeGeneratorARM::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 7488 | LocationSummary* locations = instruction->GetLocations(); |
| 7489 | Location first = locations->InAt(0); |
| 7490 | Location second = locations->InAt(1); |
| 7491 | Location out = locations->Out(); |
| 7492 | |
| 7493 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7494 | Register first_reg = first.AsRegister<Register>(); |
| 7495 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7496 | Register out_reg = out.AsRegister<Register>(); |
| 7497 | |
| 7498 | switch (instruction->GetOpKind()) { |
| 7499 | case HInstruction::kAnd: |
| 7500 | __ bic(out_reg, first_reg, second_reg); |
| 7501 | break; |
| 7502 | case HInstruction::kOr: |
| 7503 | __ orn(out_reg, first_reg, second_reg); |
| 7504 | break; |
| 7505 | // There is no EON on arm. |
| 7506 | case HInstruction::kXor: |
| 7507 | default: |
| 7508 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7509 | UNREACHABLE(); |
| 7510 | } |
| 7511 | return; |
| 7512 | |
| 7513 | } else { |
| 7514 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7515 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7516 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7517 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7518 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7519 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7520 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7521 | |
| 7522 | switch (instruction->GetOpKind()) { |
| 7523 | case HInstruction::kAnd: |
| 7524 | __ bic(out_low, first_low, second_low); |
| 7525 | __ bic(out_high, first_high, second_high); |
| 7526 | break; |
| 7527 | case HInstruction::kOr: |
| 7528 | __ orn(out_low, first_low, second_low); |
| 7529 | __ orn(out_high, first_high, second_high); |
| 7530 | break; |
| 7531 | // There is no EON on arm. |
| 7532 | case HInstruction::kXor: |
| 7533 | default: |
| 7534 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 7535 | UNREACHABLE(); |
| 7536 | } |
| 7537 | } |
| 7538 | } |
| 7539 | |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 7540 | void LocationsBuilderARM::VisitDataProcWithShifterOp( |
| 7541 | HDataProcWithShifterOp* instruction) { |
| 7542 | DCHECK(instruction->GetType() == Primitive::kPrimInt || |
| 7543 | instruction->GetType() == Primitive::kPrimLong); |
| 7544 | LocationSummary* locations = |
| 7545 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 7546 | const bool overlap = instruction->GetType() == Primitive::kPrimLong && |
| 7547 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 7548 | |
| 7549 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7550 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7551 | locations->SetOut(Location::RequiresRegister(), |
| 7552 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 7553 | } |
| 7554 | |
| 7555 | void InstructionCodeGeneratorARM::VisitDataProcWithShifterOp( |
| 7556 | HDataProcWithShifterOp* instruction) { |
| 7557 | const LocationSummary* const locations = instruction->GetLocations(); |
| 7558 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 7559 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 7560 | const Location left = locations->InAt(0); |
| 7561 | const Location right = locations->InAt(1); |
| 7562 | const Location out = locations->Out(); |
| 7563 | |
| 7564 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 7565 | DCHECK(!HDataProcWithShifterOp::IsExtensionOp(op_kind)); |
| 7566 | |
| 7567 | const Register second = instruction->InputAt(1)->GetType() == Primitive::kPrimLong |
| 7568 | ? right.AsRegisterPairLow<Register>() |
| 7569 | : right.AsRegister<Register>(); |
| 7570 | |
| 7571 | GenerateDataProcInstruction(kind, |
| 7572 | out.AsRegister<Register>(), |
| 7573 | left.AsRegister<Register>(), |
| 7574 | ShifterOperand(second, |
| 7575 | ShiftFromOpKind(op_kind), |
| 7576 | instruction->GetShiftAmount()), |
| 7577 | codegen_); |
| 7578 | } else { |
| 7579 | DCHECK_EQ(instruction->GetType(), Primitive::kPrimLong); |
| 7580 | |
| 7581 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 7582 | const Register second = right.AsRegister<Register>(); |
| 7583 | |
| 7584 | DCHECK_NE(out.AsRegisterPairLow<Register>(), second); |
| 7585 | GenerateDataProc(kind, |
| 7586 | out, |
| 7587 | left, |
| 7588 | ShifterOperand(second), |
| 7589 | ShifterOperand(second, ASR, 31), |
| 7590 | codegen_); |
| 7591 | } else { |
| 7592 | GenerateLongDataProc(instruction, codegen_); |
| 7593 | } |
| 7594 | } |
| 7595 | } |
| 7596 | |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7597 | void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) { |
| 7598 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 7599 | if (value == 0xffffffffu) { |
| 7600 | if (out != first) { |
| 7601 | __ mov(out, ShifterOperand(first)); |
| 7602 | } |
| 7603 | return; |
| 7604 | } |
| 7605 | if (value == 0u) { |
| 7606 | __ mov(out, ShifterOperand(0)); |
| 7607 | return; |
| 7608 | } |
| 7609 | ShifterOperand so; |
| 7610 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) { |
| 7611 | __ and_(out, first, so); |
| 7612 | } else { |
| 7613 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so)); |
| 7614 | __ bic(out, first, ShifterOperand(~value)); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) { |
| 7619 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 7620 | if (value == 0u) { |
| 7621 | if (out != first) { |
| 7622 | __ mov(out, ShifterOperand(first)); |
| 7623 | } |
| 7624 | return; |
| 7625 | } |
| 7626 | if (value == 0xffffffffu) { |
| 7627 | __ mvn(out, ShifterOperand(0)); |
| 7628 | return; |
| 7629 | } |
| 7630 | ShifterOperand so; |
| 7631 | if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) { |
| 7632 | __ orr(out, first, so); |
| 7633 | } else { |
| 7634 | DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so)); |
| 7635 | __ orn(out, first, ShifterOperand(~value)); |
| 7636 | } |
| 7637 | } |
| 7638 | |
| 7639 | void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) { |
| 7640 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 7641 | if (value == 0u) { |
| 7642 | if (out != first) { |
| 7643 | __ mov(out, ShifterOperand(first)); |
| 7644 | } |
| 7645 | return; |
| 7646 | } |
| 7647 | __ eor(out, first, ShifterOperand(value)); |
| 7648 | } |
| 7649 | |
Vladimir Marko | 59751a7 | 2016-08-05 14:37:27 +0100 | [diff] [blame] | 7650 | void InstructionCodeGeneratorARM::GenerateAddLongConst(Location out, |
| 7651 | Location first, |
| 7652 | uint64_t value) { |
| 7653 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7654 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7655 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7656 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7657 | uint32_t value_low = Low32Bits(value); |
| 7658 | uint32_t value_high = High32Bits(value); |
| 7659 | if (value_low == 0u) { |
| 7660 | if (out_low != first_low) { |
| 7661 | __ mov(out_low, ShifterOperand(first_low)); |
| 7662 | } |
| 7663 | __ AddConstant(out_high, first_high, value_high); |
| 7664 | return; |
| 7665 | } |
| 7666 | __ AddConstantSetFlags(out_low, first_low, value_low); |
| 7667 | ShifterOperand so; |
| 7668 | if (__ ShifterOperandCanHold(out_high, first_high, ADC, value_high, kCcDontCare, &so)) { |
| 7669 | __ adc(out_high, first_high, so); |
| 7670 | } else if (__ ShifterOperandCanHold(out_low, first_low, SBC, ~value_high, kCcDontCare, &so)) { |
| 7671 | __ sbc(out_high, first_high, so); |
| 7672 | } else { |
| 7673 | LOG(FATAL) << "Unexpected constant " << value_high; |
| 7674 | UNREACHABLE(); |
| 7675 | } |
| 7676 | } |
| 7677 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7678 | void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7679 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7680 | Location first = locations->InAt(0); |
| 7681 | Location second = locations->InAt(1); |
| 7682 | Location out = locations->Out(); |
| 7683 | |
| 7684 | if (second.IsConstant()) { |
| 7685 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 7686 | uint32_t value_low = Low32Bits(value); |
| 7687 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 7688 | Register first_reg = first.AsRegister<Register>(); |
| 7689 | Register out_reg = out.AsRegister<Register>(); |
| 7690 | if (instruction->IsAnd()) { |
| 7691 | GenerateAndConst(out_reg, first_reg, value_low); |
| 7692 | } else if (instruction->IsOr()) { |
| 7693 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 7694 | } else { |
| 7695 | DCHECK(instruction->IsXor()); |
| 7696 | GenerateEorConst(out_reg, first_reg, value_low); |
| 7697 | } |
| 7698 | } else { |
| 7699 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 7700 | uint32_t value_high = High32Bits(value); |
| 7701 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7702 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7703 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7704 | Register out_high = out.AsRegisterPairHigh<Register>(); |
| 7705 | if (instruction->IsAnd()) { |
| 7706 | GenerateAndConst(out_low, first_low, value_low); |
| 7707 | GenerateAndConst(out_high, first_high, value_high); |
| 7708 | } else if (instruction->IsOr()) { |
| 7709 | GenerateOrrConst(out_low, first_low, value_low); |
| 7710 | GenerateOrrConst(out_high, first_high, value_high); |
| 7711 | } else { |
| 7712 | DCHECK(instruction->IsXor()); |
| 7713 | GenerateEorConst(out_low, first_low, value_low); |
| 7714 | GenerateEorConst(out_high, first_high, value_high); |
| 7715 | } |
| 7716 | } |
| 7717 | return; |
| 7718 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7719 | |
| 7720 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7721 | Register first_reg = first.AsRegister<Register>(); |
| 7722 | ShifterOperand second_reg(second.AsRegister<Register>()); |
| 7723 | Register out_reg = out.AsRegister<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7724 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7725 | __ and_(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7726 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7727 | __ orr(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7728 | } else { |
| 7729 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7730 | __ eor(out_reg, first_reg, second_reg); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7731 | } |
| 7732 | } else { |
| 7733 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7734 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 7735 | Register first_high = first.AsRegisterPairHigh<Register>(); |
| 7736 | ShifterOperand second_low(second.AsRegisterPairLow<Register>()); |
| 7737 | ShifterOperand second_high(second.AsRegisterPairHigh<Register>()); |
| 7738 | Register out_low = out.AsRegisterPairLow<Register>(); |
| 7739 | Register out_high = out.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7740 | if (instruction->IsAnd()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7741 | __ and_(out_low, first_low, second_low); |
| 7742 | __ and_(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7743 | } else if (instruction->IsOr()) { |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7744 | __ orr(out_low, first_low, second_low); |
| 7745 | __ orr(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7746 | } else { |
| 7747 | DCHECK(instruction->IsXor()); |
Vladimir Marko | d2b4ca2 | 2015-09-14 15:13:26 +0100 | [diff] [blame] | 7748 | __ eor(out_low, first_low, second_low); |
| 7749 | __ eor(out_high, first_high, second_high); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7750 | } |
| 7751 | } |
| 7752 | } |
| 7753 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7754 | void InstructionCodeGeneratorARM::GenerateReferenceLoadOneRegister( |
| 7755 | HInstruction* instruction, |
| 7756 | Location out, |
| 7757 | uint32_t offset, |
| 7758 | Location maybe_temp, |
| 7759 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7760 | Register out_reg = out.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7761 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7762 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7763 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7764 | if (kUseBakerReadBarrier) { |
| 7765 | // Load with fast path based Baker's read barrier. |
| 7766 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7767 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7768 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7769 | } else { |
| 7770 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7771 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7772 | // in the following move operation, as we will need it for the |
| 7773 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7774 | __ Mov(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7775 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7776 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7777 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7778 | } |
| 7779 | } else { |
| 7780 | // Plain load with no read barrier. |
| 7781 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7782 | __ LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 7783 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7784 | } |
| 7785 | } |
| 7786 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7787 | void InstructionCodeGeneratorARM::GenerateReferenceLoadTwoRegisters( |
| 7788 | HInstruction* instruction, |
| 7789 | Location out, |
| 7790 | Location obj, |
| 7791 | uint32_t offset, |
| 7792 | Location maybe_temp, |
| 7793 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7794 | Register out_reg = out.AsRegister<Register>(); |
| 7795 | Register obj_reg = obj.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7796 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7797 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7798 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7799 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7800 | // Load with fast path based Baker's read barrier. |
| 7801 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7802 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7803 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7804 | } else { |
| 7805 | // Load with slow path based read barrier. |
| 7806 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7807 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7808 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7809 | } |
| 7810 | } else { |
| 7811 | // Plain load with no read barrier. |
| 7812 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7813 | __ LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 7814 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7815 | } |
| 7816 | } |
| 7817 | |
| 7818 | void InstructionCodeGeneratorARM::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 7819 | Location root, |
| 7820 | Register obj, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7821 | uint32_t offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7822 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7823 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7824 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7825 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7826 | if (kUseBakerReadBarrier) { |
| 7827 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7828 | // Baker's read barrier are used. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7829 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7830 | // Note that we do not actually check the value of |
| 7831 | // `GetIsGcMarking()` to decide whether to mark the loaded GC |
| 7832 | // root or not. Instead, we load into `temp` the read barrier |
| 7833 | // mark entry point corresponding to register `root`. If `temp` |
| 7834 | // is null, it means that `GetIsGcMarking()` is false, and vice |
| 7835 | // versa. |
| 7836 | // |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7837 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7838 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 7839 | // if (temp != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 7840 | // // Slow path. |
| 7841 | // root = temp(root); // root = ReadBarrier::Mark(root); // Runtime entry point call. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7842 | // } |
| 7843 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7844 | // Slow path marking the GC root `root`. The entrypoint will already be loaded in `temp`. |
| 7845 | Location temp = Location::RegisterLocation(LR); |
| 7846 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM( |
| 7847 | instruction, root, /* entrypoint */ temp); |
| 7848 | codegen_->AddSlowPath(slow_path); |
| 7849 | |
| 7850 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7851 | const int32_t entry_point_offset = |
| 7852 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(root.reg()); |
| 7853 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 7854 | // threads are suspended or running a checkpoint. |
| 7855 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, entry_point_offset); |
| 7856 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7857 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7858 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7859 | static_assert( |
| 7860 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7861 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7862 | "have different sizes."); |
| 7863 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7864 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7865 | "have different sizes."); |
| 7866 | |
Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 7867 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 7868 | // checking GetIsGcMarking. |
| 7869 | __ CompareAndBranchIfNonZero(temp.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7870 | __ Bind(slow_path->GetExitLabel()); |
| 7871 | } else { |
| 7872 | // GC root loaded through a slow path for read barriers other |
| 7873 | // than Baker's. |
| 7874 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 7875 | __ AddConstant(root_reg, obj, offset); |
| 7876 | // /* mirror::Object* */ root = root->Read() |
| 7877 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7878 | } |
| 7879 | } else { |
| 7880 | // Plain GC root load with no read barrier. |
| 7881 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 7882 | __ LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 7883 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7884 | // do not have to unpoison `root_reg` here. |
| 7885 | } |
| 7886 | } |
| 7887 | |
| 7888 | void CodeGeneratorARM::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7889 | Location ref, |
| 7890 | Register obj, |
| 7891 | uint32_t offset, |
| 7892 | Location temp, |
| 7893 | bool needs_null_check) { |
| 7894 | DCHECK(kEmitCompilerReadBarrier); |
| 7895 | DCHECK(kUseBakerReadBarrier); |
| 7896 | |
| 7897 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7898 | Location no_index = Location::NoLocation(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7899 | ScaleFactor no_scale_factor = TIMES_1; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7900 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7901 | 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] | 7902 | } |
| 7903 | |
| 7904 | void CodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7905 | Location ref, |
| 7906 | Register obj, |
| 7907 | uint32_t data_offset, |
| 7908 | Location index, |
| 7909 | Location temp, |
| 7910 | bool needs_null_check) { |
| 7911 | DCHECK(kEmitCompilerReadBarrier); |
| 7912 | DCHECK(kUseBakerReadBarrier); |
| 7913 | |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7914 | static_assert( |
| 7915 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7916 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7917 | // /* HeapReference<Object> */ ref = |
| 7918 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7919 | ScaleFactor scale_factor = TIMES_4; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7920 | GenerateReferenceLoadWithBakerReadBarrier( |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7921 | instruction, ref, obj, data_offset, index, scale_factor, temp, needs_null_check); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7922 | } |
| 7923 | |
| 7924 | void CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7925 | Location ref, |
| 7926 | Register obj, |
| 7927 | uint32_t offset, |
| 7928 | Location index, |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 7929 | ScaleFactor scale_factor, |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7930 | Location temp, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7931 | bool needs_null_check, |
| 7932 | bool always_update_field, |
| 7933 | Register* temp2) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7934 | DCHECK(kEmitCompilerReadBarrier); |
| 7935 | DCHECK(kUseBakerReadBarrier); |
| 7936 | |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 7937 | // Query `art::Thread::Current()->GetIsGcMarking()` to decide |
| 7938 | // whether we need to enter the slow path to mark the reference. |
| 7939 | // Then, in the slow path, check the gray bit in the lock word of |
| 7940 | // the reference's holder (`obj`) to decide whether to mark `ref` or |
| 7941 | // not. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7942 | // |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7943 | // Note that we do not actually check the value of `GetIsGcMarking()`; |
| 7944 | // instead, we load into `temp3` the read barrier mark entry point |
| 7945 | // corresponding to register `ref`. If `temp3` is null, it means |
| 7946 | // that `GetIsGcMarking()` is false, and vice versa. |
| 7947 | // |
| 7948 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7949 | // if (temp3 != nullptr) { // <=> Thread::Current()->GetIsGcMarking() |
| 7950 | // // Slow path. |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 7951 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7952 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7953 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
| 7954 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 7955 | // if (is_gray) { |
| 7956 | // ref = temp3(ref); // ref = ReadBarrier::Mark(ref); // Runtime entry point call. |
| 7957 | // } |
| 7958 | // } else { |
| 7959 | // HeapReference<mirror::Object> ref = *src; // Original reference load. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7960 | // } |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7961 | |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 7962 | Register temp_reg = temp.AsRegister<Register>(); |
Roland Levillain | 1372c9f | 2017-01-13 11:47:39 +0000 | [diff] [blame] | 7963 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7964 | // Slow path marking the object `ref` when the GC is marking. The |
| 7965 | // entrypoint will already be loaded in `temp3`. |
| 7966 | Location temp3 = Location::RegisterLocation(LR); |
| 7967 | SlowPathCodeARM* slow_path; |
| 7968 | if (always_update_field) { |
| 7969 | DCHECK(temp2 != nullptr); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 7970 | // LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM only |
| 7971 | // supports address of the form `obj + field_offset`, where `obj` |
| 7972 | // is a register and `field_offset` is a register pair (of which |
| 7973 | // only the lower half is used). Thus `offset` and `scale_factor` |
| 7974 | // above are expected to be null in this code path. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7975 | DCHECK_EQ(offset, 0u); |
| 7976 | DCHECK_EQ(scale_factor, ScaleFactor::TIMES_1); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 7977 | Location field_offset = index; |
| 7978 | slow_path = |
| 7979 | new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierAndUpdateFieldSlowPathARM( |
| 7980 | instruction, |
| 7981 | ref, |
| 7982 | obj, |
| 7983 | offset, |
| 7984 | /* index */ field_offset, |
| 7985 | scale_factor, |
| 7986 | needs_null_check, |
| 7987 | temp_reg, |
| 7988 | *temp2, |
| 7989 | /* entrypoint */ temp3); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 7990 | } else { |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 7991 | slow_path = new (GetGraph()->GetArena()) LoadReferenceWithBakerReadBarrierSlowPathARM( |
| 7992 | instruction, |
| 7993 | ref, |
| 7994 | obj, |
| 7995 | offset, |
| 7996 | index, |
| 7997 | scale_factor, |
| 7998 | needs_null_check, |
| 7999 | temp_reg, |
| 8000 | /* entrypoint */ temp3); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8001 | } |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8002 | AddSlowPath(slow_path); |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8003 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8004 | // temp3 = Thread::Current()->pReadBarrierMarkReg ## ref.reg() |
| 8005 | const int32_t entry_point_offset = |
| 8006 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ref.reg()); |
| 8007 | // Loading the entrypoint does not require a load acquire since it is only changed when |
| 8008 | // threads are suspended or running a checkpoint. |
| 8009 | __ LoadFromOffset(kLoadWord, temp3.AsRegister<Register>(), TR, entry_point_offset); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8010 | // The entrypoint is null when the GC is not marking, this prevents one load compared to |
| 8011 | // checking GetIsGcMarking. |
| 8012 | __ CompareAndBranchIfNonZero(temp3.AsRegister<Register>(), slow_path->GetEntryLabel()); |
Roland Levillain | 54f869e | 2017-03-06 13:54:11 +0000 | [diff] [blame] | 8013 | // Fast path: just load the reference. |
| 8014 | GenerateRawReferenceLoad(instruction, ref, obj, offset, index, scale_factor, needs_null_check); |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8015 | __ Bind(slow_path->GetExitLabel()); |
| 8016 | } |
Roland Levillain | 35345a5 | 2017-02-27 14:32:08 +0000 | [diff] [blame] | 8017 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8018 | void CodeGeneratorARM::GenerateRawReferenceLoad(HInstruction* instruction, |
| 8019 | Location ref, |
| 8020 | Register obj, |
| 8021 | uint32_t offset, |
| 8022 | Location index, |
| 8023 | ScaleFactor scale_factor, |
| 8024 | bool needs_null_check) { |
| 8025 | Register ref_reg = ref.AsRegister<Register>(); |
| 8026 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8027 | if (index.IsValid()) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8028 | // Load types involving an "index": ArrayGet, |
| 8029 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8030 | // intrinsics. |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8031 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset + (index << scale_factor)) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8032 | if (index.IsConstant()) { |
| 8033 | size_t computed_offset = |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8034 | (index.GetConstant()->AsIntConstant()->GetValue() << scale_factor) + offset; |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8035 | __ LoadFromOffset(kLoadWord, ref_reg, obj, computed_offset); |
| 8036 | } else { |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8037 | // Handle the special case of the |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 8038 | // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject |
| 8039 | // intrinsics, which use a register pair as index ("long |
| 8040 | // offset"), of which only the low part contains data. |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 8041 | Register index_reg = index.IsRegisterPair() |
| 8042 | ? index.AsRegisterPairLow<Register>() |
| 8043 | : index.AsRegister<Register>(); |
| 8044 | __ add(IP, obj, ShifterOperand(index_reg, LSL, scale_factor)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8045 | __ LoadFromOffset(kLoadWord, ref_reg, IP, offset); |
| 8046 | } |
| 8047 | } else { |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8048 | // /* HeapReference<mirror::Object> */ ref = *(obj + offset) |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8049 | __ LoadFromOffset(kLoadWord, ref_reg, obj, offset); |
| 8050 | } |
| 8051 | |
Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8052 | if (needs_null_check) { |
| 8053 | MaybeRecordImplicitNullCheck(instruction); |
| 8054 | } |
| 8055 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8056 | // Object* ref = ref_addr->AsMirrorPtr() |
| 8057 | __ MaybeUnpoisonHeapReference(ref_reg); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | void CodeGeneratorARM::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8061 | Location out, |
| 8062 | Location ref, |
| 8063 | Location obj, |
| 8064 | uint32_t offset, |
| 8065 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8066 | DCHECK(kEmitCompilerReadBarrier); |
| 8067 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8068 | // Insert a slow path based read barrier *after* the reference load. |
| 8069 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8070 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8071 | // reference will be carried out by the runtime within the slow |
| 8072 | // path. |
| 8073 | // |
| 8074 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8075 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8076 | // not used by the artReadBarrierSlow entry point. |
| 8077 | // |
| 8078 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8079 | SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8080 | ReadBarrierForHeapReferenceSlowPathARM(instruction, out, ref, obj, offset, index); |
| 8081 | AddSlowPath(slow_path); |
| 8082 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8083 | __ b(slow_path->GetEntryLabel()); |
| 8084 | __ Bind(slow_path->GetExitLabel()); |
| 8085 | } |
| 8086 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8087 | void CodeGeneratorARM::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 8088 | Location out, |
| 8089 | Location ref, |
| 8090 | Location obj, |
| 8091 | uint32_t offset, |
| 8092 | Location index) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8093 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8094 | // Baker's read barriers shall be handled by the fast path |
| 8095 | // (CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier). |
| 8096 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8097 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8098 | // by the runtime within the slow path. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8099 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8100 | } else if (kPoisonHeapReferences) { |
| 8101 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 8102 | } |
| 8103 | } |
| 8104 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8105 | void CodeGeneratorARM::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8106 | Location out, |
| 8107 | Location root) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8108 | DCHECK(kEmitCompilerReadBarrier); |
| 8109 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8110 | // Insert a slow path based read barrier *after* the GC root load. |
| 8111 | // |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8112 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8113 | // not need to do anything special for this here. |
Artem Serov | f4d6aee | 2016-07-11 10:41:45 +0100 | [diff] [blame] | 8114 | SlowPathCodeARM* slow_path = |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8115 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM(instruction, out, root); |
| 8116 | AddSlowPath(slow_path); |
| 8117 | |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8118 | __ b(slow_path->GetEntryLabel()); |
| 8119 | __ Bind(slow_path->GetExitLabel()); |
| 8120 | } |
| 8121 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8122 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch( |
| 8123 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 8124 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8125 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 8126 | } |
| 8127 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8128 | Register CodeGeneratorARM::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 8129 | Register temp) { |
| 8130 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8131 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8132 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8133 | return location.AsRegister<Register>(); |
| 8134 | } |
| 8135 | // For intrinsics we allow any location, so it may be on the stack. |
| 8136 | if (!location.IsRegister()) { |
| 8137 | __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex()); |
| 8138 | return temp; |
| 8139 | } |
| 8140 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8141 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8142 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8143 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8144 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8145 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8146 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 8147 | __ LoadFromOffset(kLoadWord, temp, SP, stack_offset); |
| 8148 | return temp; |
| 8149 | } |
| 8150 | return location.AsRegister<Register>(); |
| 8151 | } |
| 8152 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8153 | Location CodeGeneratorARM::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 8154 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8155 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 8156 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8157 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8158 | uint32_t offset = |
| 8159 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8160 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8161 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, offset); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8162 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 8163 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8164 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8165 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8166 | break; |
| 8167 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 8168 | __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress()); |
| 8169 | break; |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8170 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 8171 | HArmDexCacheArraysBase* base = |
| 8172 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsArmDexCacheArraysBase(); |
| 8173 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 8174 | temp.AsRegister<Register>()); |
| 8175 | int32_t offset = invoke->GetDexCacheArrayOffset() - base->GetElementOffset(); |
| 8176 | __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset); |
| 8177 | break; |
| 8178 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8179 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 8180 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8181 | Register method_reg; |
| 8182 | Register reg = temp.AsRegister<Register>(); |
| 8183 | if (current_method.IsRegister()) { |
| 8184 | method_reg = current_method.AsRegister<Register>(); |
| 8185 | } else { |
| 8186 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 8187 | DCHECK(!current_method.IsValid()); |
| 8188 | method_reg = reg; |
| 8189 | __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset); |
| 8190 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8191 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
| 8192 | __ LoadFromOffset(kLoadWord, |
| 8193 | reg, |
| 8194 | method_reg, |
| 8195 | ArtMethod::DexCacheResolvedMethodsOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 8196 | // temp = temp[index_in_cache]; |
| 8197 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 8198 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8199 | __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache)); |
| 8200 | break; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 8201 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8202 | } |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 8203 | return callee_method; |
| 8204 | } |
| 8205 | |
| 8206 | void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 8207 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8208 | |
| 8209 | switch (invoke->GetCodePtrLocation()) { |
| 8210 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 8211 | __ bl(GetFrameEntryLabel()); |
| 8212 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8213 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8214 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8215 | __ LoadFromOffset( |
| 8216 | kLoadWord, LR, callee_method.AsRegister<Register>(), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8217 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8218 | // LR() |
| 8219 | __ blx(LR); |
| 8220 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8221 | } |
| 8222 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 8223 | DCHECK(!IsLeafMethod()); |
| 8224 | } |
| 8225 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8226 | void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) { |
| 8227 | Register temp = temp_location.AsRegister<Register>(); |
| 8228 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8229 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8230 | |
| 8231 | // Use the calling convention instead of the location of the receiver, as |
| 8232 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8233 | // slow path, the arguments have been moved to the right place, so here we are |
| 8234 | // guaranteed that the receiver is the first register of the calling convention. |
| 8235 | InvokeDexCallingConvention calling_convention; |
| 8236 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8237 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8238 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 8239 | __ LoadFromOffset(kLoadWord, temp, receiver, class_offset); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8240 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 8241 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8242 | // emit a read barrier for the previous class reference load. |
| 8243 | // However this is not required in practice, as this is an |
| 8244 | // intermediate/temporary reference and because the current |
| 8245 | // concurrent copying collector keeps the from-space memory |
| 8246 | // intact/accessible until the end of the marking phase (the |
| 8247 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8248 | __ MaybeUnpoisonHeapReference(temp); |
| 8249 | // temp = temp->GetMethodAt(method_offset); |
| 8250 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 8251 | kArmPointerSize).Int32Value(); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 8252 | __ LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8253 | // LR = temp->GetEntryPoint(); |
| 8254 | __ LoadFromOffset(kLoadWord, LR, temp, entry_point); |
| 8255 | // LR(); |
| 8256 | __ blx(LR); |
| 8257 | } |
| 8258 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8259 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeStringPatch( |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8260 | const DexFile& dex_file, dex::StringIndex string_index) { |
| 8261 | return NewPcRelativePatch(dex_file, string_index.index_, &pc_relative_string_patches_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8262 | } |
| 8263 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8264 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeTypePatch( |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8265 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8266 | return NewPcRelativePatch(dex_file, type_index.index_, &pc_relative_type_patches_); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8267 | } |
| 8268 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8269 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewTypeBssEntryPatch( |
| 8270 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| 8271 | return NewPcRelativePatch(dex_file, type_index.index_, &type_bss_entry_patches_); |
| 8272 | } |
| 8273 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8274 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativeDexCacheArrayPatch( |
| 8275 | const DexFile& dex_file, uint32_t element_offset) { |
| 8276 | return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_); |
| 8277 | } |
| 8278 | |
| 8279 | CodeGeneratorARM::PcRelativePatchInfo* CodeGeneratorARM::NewPcRelativePatch( |
| 8280 | const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| 8281 | patches->emplace_back(dex_file, offset_or_index); |
| 8282 | return &patches->back(); |
| 8283 | } |
| 8284 | |
| 8285 | Literal* CodeGeneratorARM::DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8286 | dex::StringIndex string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8287 | return boot_image_string_patches_.GetOrCreate( |
| 8288 | StringReference(&dex_file, string_index), |
| 8289 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8290 | } |
| 8291 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8292 | Literal* CodeGeneratorARM::DeduplicateBootImageTypeLiteral(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8293 | dex::TypeIndex type_index) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8294 | return boot_image_type_patches_.GetOrCreate( |
| 8295 | TypeReference(&dex_file, type_index), |
| 8296 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8297 | } |
| 8298 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8299 | Literal* CodeGeneratorARM::DeduplicateBootImageAddressLiteral(uint32_t address) { |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8300 | return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), &uint32_literals_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8301 | } |
| 8302 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8303 | Literal* CodeGeneratorARM::DeduplicateJitStringLiteral(const DexFile& dex_file, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 8304 | dex::StringIndex string_index, |
| 8305 | Handle<mirror::String> handle) { |
| 8306 | jit_string_roots_.Overwrite(StringReference(&dex_file, string_index), |
| 8307 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8308 | return jit_string_patches_.GetOrCreate( |
| 8309 | StringReference(&dex_file, string_index), |
| 8310 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8311 | } |
| 8312 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8313 | Literal* CodeGeneratorARM::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 8314 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 8315 | Handle<mirror::Class> handle) { |
| 8316 | jit_class_roots_.Overwrite(TypeReference(&dex_file, type_index), |
| 8317 | reinterpret_cast64<uint64_t>(handle.GetReference())); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8318 | return jit_class_patches_.GetOrCreate( |
| 8319 | TypeReference(&dex_file, type_index), |
| 8320 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
| 8321 | } |
| 8322 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8323 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 8324 | inline void CodeGeneratorARM::EmitPcRelativeLinkerPatches( |
| 8325 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| 8326 | ArenaVector<LinkerPatch>* linker_patches) { |
| 8327 | for (const PcRelativePatchInfo& info : infos) { |
| 8328 | const DexFile& dex_file = info.target_dex_file; |
| 8329 | size_t offset_or_index = info.offset_or_index; |
| 8330 | DCHECK(info.add_pc_label.IsBound()); |
| 8331 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.Position()); |
| 8332 | // Add MOVW patch. |
| 8333 | DCHECK(info.movw_label.IsBound()); |
| 8334 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.Position()); |
| 8335 | linker_patches->push_back(Factory(movw_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8336 | // Add MOVT patch. |
| 8337 | DCHECK(info.movt_label.IsBound()); |
| 8338 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.Position()); |
| 8339 | linker_patches->push_back(Factory(movt_offset, &dex_file, add_pc_offset, offset_or_index)); |
| 8340 | } |
| 8341 | } |
| 8342 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8343 | void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 8344 | DCHECK(linker_patches->empty()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8345 | size_t size = |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8346 | /* MOVW+MOVT for each entry */ 2u * pc_relative_dex_cache_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8347 | boot_image_string_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8348 | /* MOVW+MOVT for each entry */ 2u * pc_relative_string_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8349 | boot_image_type_patches_.size() + |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8350 | /* MOVW+MOVT for each entry */ 2u * pc_relative_type_patches_.size() + |
Richard Uhler | c52f303 | 2017-03-02 13:45:45 +0000 | [diff] [blame] | 8351 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8352 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8353 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 8354 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8355 | for (const auto& entry : boot_image_string_patches_) { |
| 8356 | const StringReference& target_string = entry.first; |
| 8357 | Literal* literal = entry.second; |
| 8358 | DCHECK(literal->GetLabel()->IsBound()); |
| 8359 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8360 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 8361 | target_string.dex_file, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 8362 | target_string.string_index.index_)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8363 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8364 | if (!GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8365 | DCHECK(pc_relative_type_patches_.empty()); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8366 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_, |
| 8367 | linker_patches); |
| 8368 | } else { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 8369 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_, |
| 8370 | linker_patches); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 8371 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_, |
| 8372 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8373 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8374 | EmitPcRelativeLinkerPatches<LinkerPatch::TypeBssEntryPatch>(type_bss_entry_patches_, |
| 8375 | linker_patches); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8376 | for (const auto& entry : boot_image_type_patches_) { |
| 8377 | const TypeReference& target_type = entry.first; |
| 8378 | Literal* literal = entry.second; |
| 8379 | DCHECK(literal->GetLabel()->IsBound()); |
| 8380 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8381 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 8382 | target_type.dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 8383 | target_type.type_index.index_)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 8384 | } |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8385 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8386 | } |
| 8387 | |
| 8388 | Literal* CodeGeneratorARM::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) { |
| 8389 | return map->GetOrCreate( |
| 8390 | value, |
| 8391 | [this, value]() { return __ NewLiteral<uint32_t>(value); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8392 | } |
| 8393 | |
| 8394 | Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method, |
| 8395 | MethodToLiteralMap* map) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8396 | return map->GetOrCreate( |
| 8397 | target_method, |
| 8398 | [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); }); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 8399 | } |
| 8400 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 8401 | void LocationsBuilderARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8402 | LocationSummary* locations = |
| 8403 | new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall); |
| 8404 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 8405 | Location::RequiresRegister()); |
| 8406 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 8407 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 8408 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8409 | } |
| 8410 | |
| 8411 | void InstructionCodeGeneratorARM::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 8412 | LocationSummary* locations = instr->GetLocations(); |
| 8413 | Register res = locations->Out().AsRegister<Register>(); |
| 8414 | Register accumulator = |
| 8415 | locations->InAt(HMultiplyAccumulate::kInputAccumulatorIndex).AsRegister<Register>(); |
| 8416 | Register mul_left = |
| 8417 | locations->InAt(HMultiplyAccumulate::kInputMulLeftIndex).AsRegister<Register>(); |
| 8418 | Register mul_right = |
| 8419 | locations->InAt(HMultiplyAccumulate::kInputMulRightIndex).AsRegister<Register>(); |
| 8420 | |
| 8421 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 8422 | __ mla(res, mul_left, mul_right, accumulator); |
| 8423 | } else { |
| 8424 | __ mls(res, mul_left, mul_right, accumulator); |
| 8425 | } |
| 8426 | } |
| 8427 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8428 | void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8429 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8430 | LOG(FATAL) << "Unreachable"; |
| 8431 | } |
| 8432 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 8433 | void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8434 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 8435 | LOG(FATAL) << "Unreachable"; |
| 8436 | } |
| 8437 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8438 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 8439 | void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8440 | LocationSummary* locations = |
| 8441 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 8442 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8443 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8444 | codegen_->GetAssembler()->IsThumb()) { |
| 8445 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 8446 | if (switch_instr->GetStartValue() != 0) { |
| 8447 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 8448 | } |
| 8449 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8450 | } |
| 8451 | |
| 8452 | void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 8453 | int32_t lower_bound = switch_instr->GetStartValue(); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8454 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8455 | LocationSummary* locations = switch_instr->GetLocations(); |
| 8456 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 8457 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 8458 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8459 | if (num_entries <= kPackedSwitchCompareJumpThreshold || !codegen_->GetAssembler()->IsThumb()) { |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8460 | // Create a series of compare/jumps. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8461 | Register temp_reg = IP; |
| 8462 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 8463 | // the immediate, because IP is used as the destination register. For the other |
| 8464 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 8465 | // and they can be encoded in the instruction without making use of IP register. |
| 8466 | __ AddConstantSetFlags(temp_reg, value_reg, -lower_bound); |
| 8467 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8468 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8469 | // Jump to successors[0] if value == lower_bound. |
| 8470 | __ b(codegen_->GetLabelOf(successors[0]), EQ); |
| 8471 | int32_t last_index = 0; |
| 8472 | for (; num_entries - last_index > 2; last_index += 2) { |
| 8473 | __ AddConstantSetFlags(temp_reg, temp_reg, -2); |
| 8474 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 8475 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), LO); |
| 8476 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 8477 | __ b(codegen_->GetLabelOf(successors[last_index + 2]), EQ); |
| 8478 | } |
| 8479 | if (num_entries - last_index == 2) { |
| 8480 | // The last missing case_value. |
Vladimir Marko | ac6ac10 | 2015-12-17 12:14:00 +0000 | [diff] [blame] | 8481 | __ CmpConstant(temp_reg, 1); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8482 | __ b(codegen_->GetLabelOf(successors[last_index + 1]), EQ); |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8483 | } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8484 | |
Andreas Gampe | 7cffc3b | 2015-10-19 21:31:53 -0700 | [diff] [blame] | 8485 | // And the default for any other value. |
| 8486 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 8487 | __ b(codegen_->GetLabelOf(default_block)); |
| 8488 | } |
| 8489 | } else { |
| 8490 | // Create a table lookup. |
| 8491 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 8492 | |
| 8493 | // Materialize a pointer to the switch table |
| 8494 | std::vector<Label*> labels(num_entries); |
| 8495 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 8496 | for (uint32_t i = 0; i < num_entries; i++) { |
| 8497 | labels[i] = codegen_->GetLabelOf(successors[i]); |
| 8498 | } |
| 8499 | JumpTable* table = __ CreateJumpTable(std::move(labels), temp_reg); |
| 8500 | |
| 8501 | // Remove the bias. |
| 8502 | Register key_reg; |
| 8503 | if (lower_bound != 0) { |
| 8504 | key_reg = locations->GetTemp(1).AsRegister<Register>(); |
| 8505 | __ AddConstant(key_reg, value_reg, -lower_bound); |
| 8506 | } else { |
| 8507 | key_reg = value_reg; |
| 8508 | } |
| 8509 | |
| 8510 | // Check whether the value is in the table, jump to default block if not. |
| 8511 | __ CmpConstant(key_reg, num_entries - 1); |
| 8512 | __ b(codegen_->GetLabelOf(default_block), Condition::HI); |
| 8513 | |
| 8514 | // Load the displacement from the table. |
| 8515 | __ ldr(temp_reg, Address(temp_reg, key_reg, Shift::LSL, 2)); |
| 8516 | |
| 8517 | // Dispatch is a direct add to the PC (for Thumb2). |
| 8518 | __ EmitJumpTableDispatch(table, temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8519 | } |
| 8520 | } |
| 8521 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8522 | void LocationsBuilderARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8523 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base); |
| 8524 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8525 | } |
| 8526 | |
| 8527 | void InstructionCodeGeneratorARM::VisitArmDexCacheArraysBase(HArmDexCacheArraysBase* base) { |
| 8528 | Register base_reg = base->GetLocations()->Out().AsRegister<Register>(); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8529 | CodeGeneratorARM::PcRelativePatchInfo* labels = |
| 8530 | codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset()); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8531 | __ BindTrackedLabel(&labels->movw_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8532 | __ movw(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8533 | __ BindTrackedLabel(&labels->movt_label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 8534 | __ movt(base_reg, /* placeholder */ 0u); |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 8535 | __ BindTrackedLabel(&labels->add_pc_label); |
| 8536 | __ add(base_reg, base_reg, ShifterOperand(PC)); |
| 8537 | } |
| 8538 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8539 | void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 8540 | if (!trg.IsValid()) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 8541 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8542 | return; |
| 8543 | } |
| 8544 | |
| 8545 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 8546 | |
| 8547 | Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type); |
| 8548 | if (return_loc.Equals(trg)) { |
| 8549 | return; |
| 8550 | } |
| 8551 | |
| 8552 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 8553 | // with the last branch. |
| 8554 | if (type == Primitive::kPrimLong) { |
| 8555 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8556 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr); |
| 8557 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr); |
| 8558 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8559 | } else if (type == Primitive::kPrimDouble) { |
| 8560 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8561 | parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr); |
| 8562 | parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr); |
| 8563 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8564 | } else { |
| 8565 | // Let the parallel move resolver take care of all of this. |
| 8566 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 8567 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 8568 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 8569 | } |
| 8570 | } |
| 8571 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8572 | void LocationsBuilderARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8573 | LocationSummary* locations = |
| 8574 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 8575 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8576 | locations->SetOut(Location::RequiresRegister()); |
| 8577 | } |
| 8578 | |
| 8579 | void InstructionCodeGeneratorARM::VisitClassTableGet(HClassTableGet* instruction) { |
| 8580 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 8581 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8582 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8583 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8584 | __ LoadFromOffset(kLoadWord, |
| 8585 | locations->Out().AsRegister<Register>(), |
| 8586 | locations->InAt(0).AsRegister<Register>(), |
| 8587 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8588 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8589 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 8590 | instruction->GetIndex(), kArmPointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 8591 | __ LoadFromOffset(kLoadWord, |
| 8592 | locations->Out().AsRegister<Register>(), |
| 8593 | locations->InAt(0).AsRegister<Register>(), |
| 8594 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 8595 | __ LoadFromOffset(kLoadWord, |
| 8596 | locations->Out().AsRegister<Register>(), |
| 8597 | locations->Out().AsRegister<Register>(), |
| 8598 | method_offset); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8599 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 8600 | } |
| 8601 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8602 | static void PatchJitRootUse(uint8_t* code, |
| 8603 | const uint8_t* roots_data, |
| 8604 | Literal* literal, |
| 8605 | uint64_t index_in_table) { |
| 8606 | DCHECK(literal->GetLabel()->IsBound()); |
| 8607 | uint32_t literal_offset = literal->GetLabel()->Position(); |
| 8608 | uintptr_t address = |
| 8609 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 8610 | uint8_t* data = code + literal_offset; |
| 8611 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 8612 | } |
| 8613 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8614 | void CodeGeneratorARM::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 8615 | for (const auto& entry : jit_string_patches_) { |
| 8616 | const auto& it = jit_string_roots_.find(entry.first); |
| 8617 | DCHECK(it != jit_string_roots_.end()); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8618 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
| 8619 | } |
| 8620 | for (const auto& entry : jit_class_patches_) { |
| 8621 | const auto& it = jit_class_roots_.find(entry.first); |
| 8622 | DCHECK(it != jit_class_roots_.end()); |
| 8623 | PatchJitRootUse(code, roots_data, entry.second, it->second); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8624 | } |
| 8625 | } |
| 8626 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8627 | #undef __ |
| 8628 | #undef QUICK_ENTRY_POINT |
| 8629 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8630 | } // namespace arm |
| 8631 | } // namespace art |